Disable all code related to libXp
[oweals/cde.git] / cde / programs / dtmail / MotifApp / MenuBar.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $TOG: MenuBar.C /main/6 1997/06/03 16:12:28 mgreess $ */
24 /*
25  *+SNOTICE
26  *
27  *      RESTRICTED CONFIDENTIAL INFORMATION:
28  *      
29  *      The information in this document is subject to special
30  *      restrictions in a confidential disclosure agreement bertween
31  *      HP, IBM, Sun, USL, SCO and Univel.  Do not distribute this
32  *      document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
33  *      Sun's specific written approval.  This documment and all copies
34  *      and derivative works thereof must be returned or destroyed at
35  *      Sun's request.
36  *
37  *      Copyright 1993, 1994, 1995 Sun Microsystems, Inc.  All rights reserved.
38  *
39  *+ENOTICE
40  */
41 ///////////////////////////////////////////////////////////////////////////////
42 //////////////////////////////////////////////////////////////////////////////
43 //         This example code is from the book:
44 //
45 //           Object-Oriented Programming with C++ and OSF/Motif
46 //         by
47 //           Douglas Young
48 //           Prentice Hall, 1992
49 //           ISBN 0-13-630252-1 
50 //
51 //         Copyright 1991 by Prentice Hall
52 //         All Rights Reserved
53 //
54 //  Permission to use, copy, modify, and distribute this software for 
55 //  any purpose except publication and without fee is hereby granted, provided 
56 //  that the above copyright notice appear in all copies of the software.
57 ///////////////////////////////////////////////////////////////////////////////
58 //////////////////////////////////////////////////////////////////////////////
59
60
61 //////////////////////////////////////////////////////////
62 // MenuBar.C: A menu bar whose panes support items
63 //            that execute Cmd's
64 //////////////////////////////////////////////////////////
65
66 ////////////////////////////////////////////////////////////
67 // MODIFIED TO SUPPORT SUBMENUS - not described in Book
68 ///////////////////////////////////////////////////////////
69
70
71 #include "Application.h"
72 #include "MenuBar.h"
73 #include "Cmd.h"
74 #include "CmdList.h"
75 #include "ToggleButtonInterface.h"
76 #include "ButtonInterface.h"
77 #include "Help.hh"
78 #include <Xm/RowColumn.h>
79 #include <Xm/CascadeB.h>
80 #include <Xm/Separator.h>
81 #include <Xm/PushB.h>
82 #include <Xm/Label.h>
83
84
85 extern "C" {
86 extern XtPointer _XmStringUngenerate (
87                                 XmString string,
88                                 XmStringTag tag,
89                                 XmTextType tag_type,
90                                 XmTextType output_type);
91 }
92
93 MenuBar::MenuBar ( Widget parent, char *name, unsigned char type ) 
94 : UIComponent ( name )
95 {
96     // Base widget is a Motif menu bar widget
97     
98     if(parent == NULL)
99         return;
100
101     if( type == XmMENU_POPUP) {
102         Arg args[1];
103         int i = 0;
104
105         XtSetArg(args[i], XmNwhichButton, theApplication->bMenuButton()); i++;
106         _w = XmCreatePopupMenu( parent, _name, args, i );
107 //        XtVaSetValues(_w, XmNwhichButton, theApplication->bMenuButton(), NULL);
108     } else {
109         type = XmMENU_BAR; // Force it to menu bar
110         _w = XmCreateMenuBar ( parent, _name, NULL, 0 );
111     }
112
113     printHelpId("_w", _w);
114     /* install callback */
115     // XtAddCallback(_w, XmNhelpCallback, HelpCB, helpId);
116     
117     installDestroyHandler();
118 }
119 Widget MenuBar::addCommands ( Widget *menuBarCascade, CmdList *list, Boolean help, unsigned char type )
120 {
121     return( createPulldown ( _w, list, menuBarCascade, help, type ) );
122 }
123
124 Widget MenuBar::addCommands ( CmdList *list, Boolean help, unsigned char type )
125 {
126     return( createPulldown ( _w, list, help, type ) );
127 }
128
129 Widget 
130 MenuBar::createPulldown ( 
131         Widget parent, 
132         CmdList *list, 
133         Widget *cascade, 
134         Boolean help ,
135         unsigned char type)
136 {
137     int    i;
138     Widget pulldown;
139     Arg  args2[2];
140     char * helpId;
141     XmString label_str;
142
143     if(type != XmMENU_POPUP)
144         type = XmMENU_BAR;
145     
146     // Create a pulldown menu pane for this list of commands
147     
148     if( type == XmMENU_BAR) {
149                 pulldown = XmCreatePulldownMenu( parent,
150                                 (char *) list->name(), NULL, 0 );
151                 label_str = XmStringCreateLocalized(list->getLabel());
152                 XtVaSetValues(pulldown,
153                               XmNlabelString, label_str,
154                               NULL);
155                 printHelpId("pulldown", pulldown);
156                 /* install callback */
157                 // XtAddCallback(pulldown, XmNhelpCallback, HelpCB, helpId);
158
159                 
160                 // Each entry in the menu bar must have a cascade button
161                 // from which the user can pull down the pane
162
163                 if (cascade != NULL && *cascade != NULL)
164                         XtVaSetValues (*cascade, XmNsubMenuId, pulldown, 
165                                        XmNlabelString, label_str,
166                                        NULL);
167                 else {
168
169                         XtSetArg(args2[0], XmNsubMenuId, pulldown);
170                         *cascade = XtCreateWidget ( list->name(), 
171                                        xmCascadeButtonWidgetClass,
172                                        parent, 
173                                        args2, 1);
174                         XtVaSetValues(*cascade,
175                                       XmNlabelString, label_str,
176                                       NULL);
177                         if (help) {
178                                 XtSetArg (args2[0], XmNmenuHelpWidget, *cascade);
179                                 XtSetValues (parent, args2, 1);
180                         }
181                         
182                         XtManageChild ( *cascade );
183                         printHelpId("cascade", *cascade);
184                         /* install callback */
185
186
187                         // Install callbacks for each of the 
188                         // pulldown menus so we can get
189                         // On Item help for them.
190
191                         helpId = XtName(*cascade);
192                         if (helpId == "Mailbox") {
193                                 XtAddCallback(*cascade, XmNhelpCallback, 
194                                 HelpCB, (void *)DTMAILCONTAINERMENUID);
195                         } else if (helpId == "Edit") {
196                                 XtAddCallback(*cascade, XmNhelpCallback, 
197                                         HelpCB, (void *)DTMAILEDITMENUID);
198                         } else if (helpId == "Message") {
199                                 XtAddCallback(*cascade, XmNhelpCallback, 
200                                         HelpCB, (void *)DTMAILMESSAGEMENUID);
201                         } else if (helpId == "Attachments") {
202                                 XtAddCallback(*cascade, XmNhelpCallback, 
203                                         HelpCB, (void *)DTMAILATTACHMENUID);
204                         } else if (helpId == "View") {
205                                 XtAddCallback(*cascade, XmNhelpCallback, 
206                                         HelpCB, (void *)DTMAILVIEWMENUID);
207                         } else if (helpId == "Compose") {
208                                 XtAddCallback(*cascade, XmNhelpCallback, 
209                                         HelpCB, (void *)DTMAILCOMPOSEMENUID);
210                         }
211                 }
212      } else
213                 pulldown = _w;
214         
215         
216     
217     // Loop through the cmdList, creating a menu 
218     // entry for each command. 
219     Widget *head_wl, *wl;
220     Cardinal num_wl = 0;
221     head_wl = wl = new Widget[ list->size() ];
222     
223     for ( i = 0; i < list->size(); i++)
224     {
225
226         if(!strcmp((*list)[i]->className(), "CmdList")) {
227             Widget pane = createPulldown(pulldown, 
228                 (CmdList*) (*list)[i], FALSE, XmMENU_BAR);
229             ((CmdList *)(*list)[i])->setPaneWidget(pane);
230             label_str = XmStringCreateLocalized(((CmdList *)(*list)[i])->getLabel());
231             XtVaSetValues(pane, 
232                           XmNlabelString, label_str,
233                           NULL);
234         } else {
235             if ( !strcmp((*list)[i]->className(),"SeparatorCmd")) {
236                 *(wl++) = XtCreateWidget ( (*list)[i]->name(),
237                                           xmSeparatorWidgetClass,
238                                           pulldown,
239                                           NULL, 0);
240             } else if (!strcmp((*list)[i]->className(),"ToggleButtonCmd")) {
241                 CmdInterface *ci;
242                 ci = new ToggleButtonInterface(pulldown, (*list)[i] );
243                 *(wl++) = ci->baseWidget();
244             } else if(!strcmp((*list)[i]->className(),"LabelCmd")) {
245                 label_str = XmStringCreateLocalized((*list)[i]->getLabel());
246
247                 *(wl++) = XtVaCreateWidget ( (*list)[i]->name(),
248                                         xmLabelWidgetClass,
249                                         pulldown,
250                                         XmNlabelString, label_str,
251                                         NULL);
252             } else {
253                 CmdInterface *ci;
254                 ci  = new ButtonInterface ( pulldown, (*list)[i] );
255                 *(wl++) = ci->baseWidget();
256             }
257
258             num_wl++;
259         }
260     }
261
262     XtManageChildren ( head_wl, num_wl );
263     delete head_wl;
264
265     return(pulldown);
266 }
267
268 Widget 
269 MenuBar::createPulldown ( 
270         Widget parent, 
271         CmdList *list, 
272         Boolean help ,
273         unsigned char type)
274 {
275     int    i;
276     Widget pulldown, cascade;
277     Arg  args2[2];
278     char * helpId;
279     XmString label_str;
280
281     if(type != XmMENU_POPUP)
282         type = XmMENU_BAR;
283     
284     // Create a pulldown menu pane for this list of commands
285     
286     if( type == XmMENU_BAR) {
287                 pulldown = XmCreatePulldownMenu( parent,
288                                 (char *) list->name(), NULL, 0 );
289                 label_str = XmStringCreateLocalized(list->getLabel());
290                 XtVaSetValues(pulldown,
291                               XmNlabelString, label_str,
292                               NULL);
293                 printHelpId("pulldown", pulldown);
294                 /* install callback */
295                 // XtAddCallback(pulldown, XmNhelpCallback, HelpCB, helpId);
296
297                 
298                 // Each entry in the menu bar must have a cascade button
299                 // from which the user can pull down the pane
300
301                 XtSetArg(args2[0], XmNsubMenuId, pulldown);
302                 cascade = XtCreateWidget ( list->name(), 
303                                xmCascadeButtonWidgetClass,
304                                parent, 
305                                args2, 1);
306                 XtVaSetValues(cascade,
307                               XmNlabelString, label_str,
308                               NULL);
309                 if (help) {
310                         XtSetArg (args2[0], XmNmenuHelpWidget, cascade);
311                         XtSetValues (parent, args2, 1);
312                 }
313                 
314                 XtManageChild ( cascade );
315                 printHelpId("cascade", cascade);
316                 /* install callback */
317
318
319                 // Install callbacks for each of the 
320                 // pulldown menus so we can get
321                 // On Item help for them.
322
323                 helpId = XtName(cascade);
324                 if (helpId == "Mailbox") {
325                         XtAddCallback(cascade, XmNhelpCallback, 
326                                 HelpCB, (void *)DTMAILCONTAINERMENUID);
327                 } else if (helpId == "Edit") {
328                         XtAddCallback(cascade, XmNhelpCallback, 
329                                 HelpCB, (void *)DTMAILEDITMENUID);
330                 } else if (helpId == "Message") {
331                         XtAddCallback(cascade, XmNhelpCallback, 
332                                 HelpCB, (void *)DTMAILMESSAGEMENUID);
333                 } else if (helpId == "Attachments") {
334                         XtAddCallback(cascade, XmNhelpCallback, 
335                                 HelpCB, (void *)DTMAILATTACHMENUID);
336                 } else if (helpId == "View") {
337                         XtAddCallback(cascade, XmNhelpCallback, 
338                                 HelpCB, (void *)DTMAILVIEWMENUID);
339                 } else if (helpId == "Compose") {
340                         XtAddCallback(cascade, XmNhelpCallback, 
341                                 HelpCB, (void *)DTMAILCOMPOSEMENUID);
342                 }
343      } else
344                 pulldown = _w;
345         
346         
347     
348     // Loop through the cmdList, creating a menu 
349     // entry for each command. 
350     
351     for ( i = 0; i < list->size(); i++)
352     {
353
354         if(!strcmp((*list)[i]->className(), "CmdList")) {
355             Widget pane = createPulldown(pulldown, 
356                         (CmdList*) (*list)[i], FALSE, XmMENU_BAR);
357             ((CmdList *)(*list)[i])->setPaneWidget(pane);
358             label_str = XmStringCreateLocalized((*list)[i]->getLabel());
359             XtVaSetValues(pane, 
360                           XmNlabelString, label_str,
361                           NULL);
362         } else {
363             if ( !strcmp((*list)[i]->className(),"SeparatorCmd")) {
364                 XtCreateManagedWidget ( (*list)[i]->name(),
365                                           xmSeparatorWidgetClass,
366                                           pulldown,
367                                           NULL, 0);
368             } else if (!strcmp((*list)[i]->className(),"ToggleButtonCmd")) {
369                 CmdInterface *ci;
370                 ci = new ToggleButtonInterface(pulldown, (*list)[i]);
371                 ci->manage();
372             } else if(!strcmp((*list)[i]->className(),"LabelCmd")) {
373                 Widget  _i18n;
374                 Arg _args[1];
375                 XmString xms;
376                 
377                 _i18n = XtCreateManagedWidget(
378                                         (*list)[i]->name(),
379                                         xmLabelWidgetClass,
380                                         pulldown,
381                                         NULL, 0
382                                         );
383
384                 xms = XmStringCreateLocalized((char*) (*list)[i]->getLabel());
385                 XtSetArg( _args[0], XmNlabelString, xms );
386                 XtSetValues( _i18n, _args, 1 );
387                 XmStringFree(xms);
388             } else {
389                 CmdInterface *ci;
390                 ci  = new ButtonInterface ( pulldown, (*list)[i] );
391                 ci->manage();
392             }
393         }
394     }
395     return(pulldown);
396 }
397
398 // SR - Added to handle dynamic menus
399
400 Widget
401 MenuBar::addCommands(
402     Widget pulldown,
403     CmdList *new_list
404 )
405 {
406     // if(isValidMenuPane(pulldown) == FALSE)
407     //  return NULL;
408
409     int    i;
410     XtArgVal num_children;
411     WidgetList children;
412     Boolean haveNoSeparator;
413     int newItemIndex, numPBUnmanaged, tmpPBUnmanaged;
414
415     XtVaGetValues(pulldown,
416         XmNnumChildren, &num_children,
417         NULL);
418     
419     children = (WidgetList)XtMalloc(sizeof(Widget) * num_children);
420     
421     XtVaGetValues(pulldown,
422         XmNchildren, &children,
423         NULL);
424
425     // Handle the creation or management of the Separator.
426
427     haveNoSeparator = TRUE;
428     numPBUnmanaged = 0;
429     
430     for (i=0; (i < num_children); i++) {
431         Widget wid = (Widget) children[i];
432         if (XtIsSubclass(wid, xmSeparatorWidgetClass)) {
433             XtManageChild(wid);
434             haveNoSeparator = FALSE;
435         }
436         else if (XtIsSubclass(wid, xmPushButtonWidgetClass)) {
437             if (!XtIsManaged(wid)) { // If widget is unmanaged
438                 numPBUnmanaged++;
439             }
440         }
441     }
442     if (haveNoSeparator) {
443         XtCreateManagedWidget ("Separator",
444                 xmSeparatorWidgetClass,
445                 pulldown,
446                 NULL, 0);
447         haveNoSeparator = FALSE;
448     }
449     
450     // Now handle the pushButton case
451
452     newItemIndex = 0;
453     tmpPBUnmanaged = 0;
454
455     // Loop through the cmdList, creating a menu 
456     // entry for each command. 
457         
458     for (newItemIndex = 0; newItemIndex < new_list->size(); newItemIndex++) {
459
460         tmpPBUnmanaged = numPBUnmanaged;
461
462         if (numPBUnmanaged > 0) { // If there exists unmanaged PBs
463             for (i = 0; 
464                  (i < num_children) && 
465                  (tmpPBUnmanaged == numPBUnmanaged); 
466                  i++) {
467
468                 Widget wid = (Widget) children[i];
469                 
470                 if (XtIsSubclass(wid, xmPushButtonWidgetClass)) {
471                     if (!XtIsManaged(wid)) { 
472                         // If widget is unmanaged
473                         // Set its label to be the newItemIndex widget's.
474                         // Manage it.
475                         // Bump up newItemIndex
476                         XtVaSetValues(wid,
477                             XmNlabelString, XmStringCreateLocalized(
478                                 (char *) (*new_list)[newItemIndex]->getLabel()),
479                             NULL);
480                         XtManageChild(wid);
481                         numPBUnmanaged--;
482                     }
483                 }
484             }
485         }
486         else {          // No unmanaged push buttons available
487             CmdInterface *ci;
488             ci  = new ButtonInterface ( 
489                 pulldown, (*new_list)[newItemIndex] 
490             );
491             ci->manage();
492         }
493     }
494
495     return(pulldown);
496 }
497
498 void
499 MenuBar::removeOnlyCommands(
500     Widget pulldown,
501     CmdList *redundant_list
502 )
503 {
504     // if(isValidMenuPane(pulldown) == FALSE)
505     //  return;
506
507     int    i, j;
508     XtArgVal num_children;
509     WidgetList children;
510     
511     XtVaGetValues(pulldown,
512         XmNnumChildren, &num_children,
513         NULL);
514     
515     children = (WidgetList)XtMalloc(sizeof(Widget) * num_children);
516     
517     XtVaGetValues(pulldown,
518         XmNchildren, &children,
519         NULL);
520      
521     // Loop through widget list.  Destroy those widgets that map to those
522     // in the redundant list.
523
524     for (i=0; i<num_children; i++) {
525
526         Widget wid = (Widget) children[i];
527
528         if (XtIsSubclass(wid, xmPushButtonWidgetClass)) {
529
530             for (j=0; j<redundant_list->size(); j++) {
531                 char name[200];
532                 ButtonInterface::mapName((*redundant_list)[j]->name(), name);
533                 if (strcmp(XtName(wid), name) == 0) {
534                     // The redundant item has been found.
535                     XtUnmanageChild(wid);
536                 }
537             }
538         }
539     }
540 }
541 void
542 MenuBar::removeCommands(
543     Widget pulldown,
544     CmdList *redundant_list
545 )
546 {
547     // if(isValidMenuPane(pulldown) == FALSE)
548     //  return;
549
550     int    i, j;
551     XtArgVal num_children;
552     WidgetList children;
553     
554     XtVaGetValues(pulldown,
555         XmNnumChildren, &num_children,
556         NULL);
557     
558     children = (WidgetList)XtMalloc(sizeof(Widget) * num_children);
559     
560     XtVaGetValues(pulldown,
561         XmNchildren, &children,
562         NULL);
563      
564     // Loop through widget list.  Destroy those widgets that map to those
565     // in the redundant list.
566
567     for (i=0; i<num_children; i++) {
568
569         Widget wid = (Widget) children[i];
570
571         if (XtIsSubclass(wid, xmSeparatorWidgetClass)) {
572             XtUnmanageChild(wid);
573         }
574         else if (XtIsSubclass(wid, xmPushButtonWidgetClass)) {
575
576             for (j=0; j<redundant_list->size(); j++) {
577                 XmString str=NULL;
578                 String label=NULL;
579                 XtVaGetValues(wid, XmNlabelString, &str, NULL);
580                 if (str == NULL) continue;
581                 label = NULL;
582                 label = (char *) _XmStringUngenerate(
583                                         str, NULL,
584                                         XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT);
585                 XmStringFree(str);
586                 if (label == NULL) continue;
587                 if (strcmp(label, (*redundant_list)[j]->getLabel()) == 0) {
588                     // The redundant item has been found.
589                     XtUnmanageChild(wid);
590                 }
591                 XtFree(label);
592             }
593         }
594     }
595 }
596
597 void
598 MenuBar::addCommand(
599     Widget pulldown,
600     Cmd *cmd
601 )
602 {
603     // if(isValidMenuPane(pulldown) == FALSE)
604     //  return;
605
606     CmdInterface *ci;
607     ci  = new ButtonInterface ( pulldown, cmd);
608     ci->manage();
609 }
610
611 void
612 MenuBar::changeLabel(
613     Widget pulldown,
614     int index,
615     char * name
616 )
617 {
618     // if(isValidMenuPane(pulldown) == FALSE)
619     //  return;
620
621     int managed_widgets, i;
622     XtArgVal num_children;
623     WidgetList children;
624     XmString label;
625     Widget wid;
626
627     XtVaGetValues(pulldown,
628         XmNnumChildren, &num_children,
629         NULL);
630
631     children = (WidgetList)XtMalloc(sizeof(Widget) * num_children);
632
633     XtVaGetValues(pulldown,
634         XmNchildren, &children,
635         NULL);
636     
637     // Some widgets may be unmanaged, so find the real index
638     for (managed_widgets=0, i=0; 
639                 managed_widgets <= index && i < num_children; i++) {
640         wid = (Widget) children[i];
641         if (XtIsManaged(wid)) managed_widgets++;
642     }
643     if (--i >= num_children) return;
644
645     wid = (Widget) children[i];
646
647     label = XmStringCreateLocalized(name);
648
649     XtVaSetValues(wid,
650         XmNlabelString, label,
651         NULL);
652     XmStringFree(label);
653 }
654
655 void
656 MenuBar::changeLabel(Widget pulldown,
657                      const char * button_name,
658                      const char * label)
659 {
660     // if(isValidMenuPane(pulldown) == FALSE)
661     //  return;
662
663     // Locate the appropriate widget in the list.
664     //
665     XtArgVal num_children;
666     char wid_name[200];
667     XmString label_string = XmStringCreateLocalized((char *)label);
668
669     ButtonInterface::mapName(button_name, wid_name);
670
671     XtVaGetValues(pulldown,
672                   XmNnumChildren, &num_children,
673                   NULL);
674
675     Widget * children = new Widget[num_children];
676     XtVaGetValues(pulldown,
677                   XmNchildren, &children,
678                   NULL);
679
680     for (int wid = 0; wid < num_children; wid++) {
681         if (strcmp(XtName(children[wid]), wid_name) == 0) {
682             if (XtIsManaged(children[wid]))
683                  XtVaSetValues(children[wid],
684                           XmNlabelString, label_string,
685                           NULL);
686         }
687     }
688
689     XmStringFree(label_string);
690 }
691     
692 void
693 MenuBar::rotateLabels(
694     Widget pulldown,
695     int startindex,
696     int endindex
697 )
698 {
699     // if(isValidMenuPane(pulldown) == FALSE)
700     //  return;
701
702     int    num_managed_wids=0, i, j, num_to_change;
703     XtArgVal num_children;
704     WidgetList children;
705     XmString label, endlabel;
706     Widget prevwid, wid;
707
708     if (startindex < 0 || endindex < 0)
709         return;
710
711     XtVaGetValues(pulldown,
712         XmNnumChildren, &num_children,
713         NULL);
714
715     if (startindex >= num_children || endindex >= num_children)
716         return;
717     
718     num_to_change = endindex - startindex;
719     if (num_children < num_to_change || num_to_change == 0) 
720         return;
721
722     children = (WidgetList)XtMalloc(sizeof(Widget) * num_children);
723
724     XtVaGetValues(pulldown,
725         XmNchildren, &children,
726         NULL);
727
728     // Some of the widgets may be unmanaged: find the first managed widget
729     for (i = startindex; i < num_children; i++) {
730         if (XtIsManaged(children[i]))
731                 break;
732         startindex++;
733     }
734
735     if (startindex == num_children) 
736         return;
737
738     // Find the real endindex
739     endindex = startindex+1;
740     while (endindex < num_children) {
741         if (XtIsManaged(children[endindex])) 
742                 num_managed_wids++;
743         if (num_managed_wids == num_to_change)
744                 // We have found the endindex at this point
745                 break;
746         endindex++;
747     } 
748  
749     if (endindex == num_children) 
750         return;
751
752     wid = (Widget) children[endindex];
753     XtVaGetValues(wid,
754         XmNlabelString, &label,
755         NULL);
756     endlabel = XmStringCopy(label);
757
758     j = i = endindex; 
759     while (i > startindex) {
760
761         do {
762                 if (--j < startindex) break;
763                 prevwid = (Widget) children[j];
764         } while (!XtIsManaged(prevwid));
765
766         XtVaGetValues(prevwid,
767                 XmNlabelString, &label,
768                 NULL);
769
770         XtVaSetValues(wid,
771                 XmNlabelString, label,
772                 NULL);
773
774         i = j;
775
776         wid = (Widget) children[i];
777     }
778
779     wid = (Widget) children[startindex];
780     XtVaSetValues(wid,
781         XmNlabelString, endlabel,
782         NULL);
783     
784     XmStringFree(endlabel);
785 }
786
787 #ifdef DEAD_WOOD
788 Boolean
789 MenuBar::isValidMenuPane(Widget w)
790 {
791         Boolean retval = FALSE;
792         Widget parent = w;
793
794         while(parent && parent != _w)
795                 parent = XtParent(parent);
796
797         if(parent == _w)
798                 retval = TRUE;
799
800         return retval;
801 }
802 #endif /* DEAD_WOOD */
803
804 void
805 MenuBar::removeCommand(
806     Widget pulldown,
807     int index
808 )
809 {
810     //if(isValidMenuPane(pulldown) == FALSE)
811     //   return;
812
813     int   managed_widgets, i;
814     XtArgVal num_children;
815     WidgetList children;
816
817     XtVaGetValues(pulldown,
818         XmNnumChildren, &num_children,
819         NULL);
820
821     children = (WidgetList)XtMalloc(sizeof(Widget) * num_children);
822
823     XtVaGetValues(pulldown,
824         XmNchildren, &children,
825         NULL);
826
827     // Some widgets may be unmanaged, so find the real index
828     for (managed_widgets=0, i=0;
829                 managed_widgets <= index && i < num_children; i++) {
830         Widget wid = (Widget) children[i];
831         if (XtIsManaged(wid)) managed_widgets++;
832     }
833
834     if (--i < num_children)
835         XtUnmanageChild(children[i]);
836 }