root/oldXMenu/AddSel.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. XMenuAddSelection

     1 /* Copyright    Massachusetts Institute of Technology    1985   */
     2 
     3 /*
     4 
     5 Copyright 1985, 1986, 1987 by the Massachusetts Institute of Technology
     6 
     7 Permission to use, copy, modify, and distribute this
     8 software and its documentation for any purpose and without
     9 fee is hereby granted, provided that the above copyright
    10 notice appear in all copies and that both that copyright
    11 notice and this permission notice appear in supporting
    12 documentation, and that the name of M.I.T. not be used in
    13 advertising or publicity pertaining to distribution of the
    14 software without specific, written prior permission.
    15 M.I.T. makes no representations about the suitability of
    16 this software for any purpose.  It is provided "as is"
    17 without express or implied warranty.
    18 
    19 */
    20 
    21 
    22 
    23 
    24 /*
    25  * XMenu:       MIT Project Athena, X Window system menu package
    26  *
    27  *      XMenuAddSelection - Adds a selection to an XMenu object.
    28  *
    29  *      Author:         Tony Della Fera, DEC
    30  *                      August, 1985
    31  *
    32  */
    33 
    34 #include "XMenuInt.h"
    35 #include <string.h>
    36 
    37 int
    38 XMenuAddSelection(Display *display, register XMenu *menu, register int p_num, char *data, char *label, int active, char const *help)
    39 
    40                                 /* Menu object to be modified. */
    41                                 /* Pane number to be modified. */
    42                                 /* Data value. */
    43                                 /* Selection label. */
    44                                 /* Make selection active? */
    45                                 /* Help string */
    46 {
    47     register XMPane *pane;      /* Pane containing the new selection. */
    48     register XMSelect *sel;     /* Newly created selection. */
    49 
    50 
    51     int label_length;           /* Label length in characters. */
    52     int label_width;            /* Label width in pixels. */
    53 
    54     /*
    55      * Check for NULL pointers!
    56      */
    57     if (label == NULL) {
    58         _XMErrorCode = XME_ARG_BOUNDS;
    59         return(XM_FAILURE);
    60     }
    61     /*
    62      * Find the right pane.
    63      */
    64     pane = _XMGetPanePtr(menu, p_num);
    65     if (pane == NULL) return(XM_FAILURE);
    66 
    67     /*
    68      * Calloc the XMSelect structure.
    69      */
    70     sel = (XMSelect *)calloc(1, sizeof(XMSelect));
    71     if (sel == NULL) {
    72         _XMErrorCode = XME_CALLOC;
    73         return(XM_FAILURE);
    74     }
    75     /*
    76      * Determine label size.
    77      */
    78     label_length = strlen(label);
    79     label_width = XTextWidth(menu->s_fnt_info, label, label_length);
    80 
    81     /*
    82      * Fill the XMSelect structure.
    83      */
    84     if (!strcmp (label, "--") || !strcmp (label, "---"))
    85       {
    86         sel->type = SEPARATOR;
    87         sel->active = 0;
    88       }
    89     else
    90       {
    91         sel->type = SELECTION;
    92         sel->active = active;
    93       }
    94 
    95     sel->serial = -1;
    96     sel->label = label;
    97     sel->label_width = label_width;
    98     sel->label_length = label_length;
    99     sel->data = data;
   100     sel->parent_p = pane;
   101     sel->help_string = help;
   102 
   103     /*
   104      * Insert the selection at the end of the selection list.
   105      */
   106     emacs_insque(sel, pane->s_list->prev);
   107 
   108     /*
   109      * Update the selection count.
   110      */
   111     pane->s_count++;
   112 
   113     /*
   114      * Schedule a recompute.
   115      */
   116     menu->recompute = 1;
   117 
   118     /*
   119      * Return the selection number just added.
   120      */
   121     _XMErrorCode = XME_NO_ERROR;
   122     return((pane->s_count - 1));
   123 }

/* [<][>][^][v][top][bottom][index][help] */