root/oldXMenu/InsSel.c

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

DEFINITIONS

This source file includes following definitions.
  1. XMenuInsertSelection

     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  *      XMenuInsertSelection - Inserts a selection into an XMenu object
    28  *
    29  *      Author:         Tony Della Fera, DEC
    30  *                      20-Nov-85
    31  *
    32  */
    33 
    34 #include "XMenuInt.h"
    35 #include <string.h>
    36 
    37 int
    38 XMenuInsertSelection(register XMenu *menu, register int p_num, register int s_num, char *data, char *label, int active)
    39                                 /* Menu object to be modified. */
    40                                 /* Pane number to be modified. */
    41                                 /* Selection number of new selection. */
    42                                 /* Data value. */
    43                                 /* Selection label. */
    44                                 /* Make selection active? */
    45 {
    46     register XMPane *p_ptr;     /* XMPane pointer. */
    47     register XMSelect *s_ptr;   /* XMSelect pointer. */
    48 
    49     XMSelect *sel;              /* Newly created selection. */
    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     /*
    63      * Find the right pane.
    64      */
    65     p_ptr = _XMGetPanePtr(menu, p_num);
    66     if (p_ptr == NULL) return(XM_FAILURE);
    67 
    68     /*
    69      * Find the selection number one less than the one specified since that
    70      * is the selection after which the insertion will occur.
    71      */
    72     s_ptr = _XMGetSelectionPtr(p_ptr, (s_num - 1));
    73     if (s_ptr == NULL) return(XM_FAILURE);
    74 
    75     /*
    76      * Calloc the XMSelect structure.
    77      */
    78     sel = (XMSelect *)calloc(1, sizeof(XMSelect));
    79     if (sel == NULL) {
    80         _XMErrorCode = XME_CALLOC;
    81         return(XM_FAILURE);
    82     }
    83 
    84     /*
    85      * Determine label size.
    86      */
    87     label_length = strlen(label);
    88     label_width = XTextWidth(menu->s_fnt_info, label, label_length);
    89 
    90 
    91     /*
    92      * Fill the XMSelect structure.
    93      */
    94     if (!strcmp (label, "--") || !strcmp (label, "---"))
    95       {
    96         sel->type = SEPARATOR;
    97         sel->active = 0;
    98       }
    99     else
   100       {
   101         sel->type = SELECTION;
   102         sel->active = active;
   103       }
   104 
   105     sel->active = active;
   106     sel->serial = -1;
   107     sel->label = label;
   108     sel->label_width = label_width;
   109     sel->label_length = label_length;
   110     sel->data = data;
   111     sel->parent_p = p_ptr;
   112 
   113     /*
   114      * Insert the selection after the selection with the selection
   115      * number one less than the desired number for the new selection.
   116      */
   117     emacs_insque(sel, s_ptr);
   118 
   119     /*
   120      * Update the selection count.
   121      */
   122     p_ptr->s_count++;
   123 
   124     /*
   125      * Schedule a recompute.
   126      */
   127     menu->recompute = 1;
   128 
   129     /*
   130      * Return the selection number just inserted.
   131      */
   132     _XMErrorCode = XME_NO_ERROR;
   133     return(s_num);
   134 }

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