1 /* vibmenus.c
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information (NCBI)
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government do not place any restriction on its use or reproduction.
13 * We would, however, appreciate having the NCBI and the author cited in
14 * any work or product based on this material
15 *
16 * Although all reasonable efforts have been taken to ensure the accuracy
17 * and reliability of the software and data, the NLM and the U.S.
18 * Government do not and cannot warrant the performance or results that
19 * may be obtained by using this software or data. The NLM and the U.S.
20 * Government disclaim all warranties, express or implied, including
21 * warranties of performance, merchantability or fitness for any particular
22 * purpose.
23 *
24 * ===========================================================================
25 *
26 * File Name: vibmenus.c
27 *
28 * Author: Jonathan Kans
29 *
30 * Version Creation Date: 7/1/91
31 *
32 * $Revision: 6.31 $
33 *
34 * File Description:
35 * Vibrant menu functions
36 *
37 * Modifications:
38 * --------------------------------------------------------------------------
39 *
40 * ==========================================================================
41 */
42
43 #include <vibtypes.h>
44 #include <vibprocs.h>
45 #include <vibincld.h>
46
47 #ifdef WIN_MAC
48 # if !defined(OS_UNIX_DARWIN)
49 # include "MoreCarbonAccessors.h"
50 # endif
51 # define Nlm_MenuTool MenuRef
52 # define Nlm_PopupTool Nlm_Handle
53 # define Nlm_ItemTool Nlm_Handle
54 #endif
55
56 #ifdef WIN_MSWIN
57 # include <windows.h>
58 # define Nlm_MenuTool HMENU
59 # define Nlm_PopupTool HWND
60 # define Nlm_ItemTool Nlm_Handle
61 #endif
62
63 #ifdef WIN_MOTIF
64 # define Nlm_MenuTool Widget
65 # define Nlm_PopupTool Widget
66 # define Nlm_ItemTool Widget
67 # define POPUP_LOCATION_ADJUSTMENT -2
68 #endif
69
70 typedef struct Nlm_menudata {
71 Nlm_MenuTool handle;
72 Nlm_PrompT prompt;
73 Nlm_Int2 menuTag;
74 Nlm_PopupTool popup;
75 } Nlm_MenuData;
76
77 typedef struct Nlm_menurec {
78 Nlm_GraphicRec graphicR;
79 Nlm_MenuData menu;
80 } Nlm_MenuRec, PNTR Nlm_MenPtr;
81
82 typedef struct Nlm_itemdata {
83 Nlm_MenU subMenu;
84 Nlm_Int2 firstItem;
85 Nlm_ItemTool handle;
86 } Nlm_ItemData;
87
88 typedef struct Nlm_itemrec {
89 Nlm_GraphicRec graphicR;
90 Nlm_ItemData item;
91 } Nlm_ItemRec, PNTR Nlm_ItmPtr;
92
93 typedef struct Nlm_choicedata {
94 Nlm_Int2 numItems;
95 Nlm_Boolean isAPopupList;
96 Nlm_Int2 popupValue;
97 Nlm_ItemTool PNTR handles;
98 } Nlm_ChoiceData;
99
100 typedef struct Nlm_choicerec {
101 Nlm_ItemRec itemR;
102 Nlm_ChoiceData choice;
103 } Nlm_ChoiceRec, PNTR Nlm_ChsPtr;
104
105 typedef struct Nlm_menubardata {
106 Nlm_MenuTool handle;
107 Nlm_Boolean notJustSubMenu;
108 } Nlm_MenuBarData;
109
110 typedef struct Nlm_menubarrec {
111 Nlm_BoxRec boxR;
112 Nlm_MenuBarData menubar;
113 } Nlm_MenuBarRec, PNTR Nlm_MbrPtr;
114
115 static Nlm_GphPrcsPtr gphprcsptr = NULL;
116
117 #ifdef WIN_MAC
118 static Nlm_GphPrcsPtr desktopMenuBarProcs;
119 static Nlm_GphPrcsPtr desktopPulldownProcs;
120 #endif
121 static Nlm_GphPrcsPtr windowMenuBarProcs;
122 static Nlm_GphPrcsPtr windowPulldownProcs;
123 static Nlm_GphPrcsPtr popupProcs;
124 static Nlm_GphPrcsPtr subMenuProcs;
125 static Nlm_GphPrcsPtr subItemProcs;
126 static Nlm_GphPrcsPtr commandItemProcs;
127 static Nlm_GphPrcsPtr statusItemProcs;
128 static Nlm_GphPrcsPtr choiceGroupProcs;
129 static Nlm_GphPrcsPtr choiceItemProcs;
130 static Nlm_GphPrcsPtr macPopListProcs;
131 static Nlm_GphPrcsPtr msPopListProcs;
132 static Nlm_GphPrcsPtr popUpChoiceProcs;
133 static Nlm_GphPrcsPtr daProcs;
134
135 static Nlm_MenU recentMenu = NULL;
136 static Nlm_MenuData recentMenuData;
137
138 static Nlm_IteM recentItem = NULL;
139 static Nlm_ItemData recentItemData;
140
141 static Nlm_ChoicE recentChoice = NULL;
142 static Nlm_ChoiceData recentChoiceData;
143
144 static Nlm_MenuBaR recentMenuBar = NULL;
145 static Nlm_MenuBarData recentMenuBarData;
146
147 static Nlm_Int2 nextMenuNum = 1;
148
149 #ifdef WIN_MAC
150 static Nlm_Int2 currentItemNum = 0;
151 static Nlm_Int2 currentMenuNum = 0;
152 static Nlm_Int2 currentMenuTag = 0;
153 #endif
154
155 #ifdef WIN_MSWIN
156 static Nlm_Int2 currentItemID = 0;
157 static WNDPROC lpfnNewPopupProc = NULL;
158 static WNDPROC lpfnOldPopupProc = NULL;
159 static Nlm_Boolean handlechar;
160 #endif
161
162 #ifdef WIN_MOTIF
163 static Widget choiceWidget = NULL;
164 #endif
165
Nlm_HasAquaMenuLayout(void)166 extern Nlm_Boolean Nlm_HasAquaMenuLayout (void)
167
168 {
169 #if TARGET_API_MAC_CARBON
170 SInt32 result;
171
172 return (Boolean) (Gestalt (gestaltMenuMgrAttr, &result) == noErr) && ((result & gestaltMenuMgrAquaLayoutMask) != 0);
173 #else
174 return FALSE;
175 #endif
176 }
177
Nlm_LoadMenuData(Nlm_MenU m,Nlm_MenuTool hdl,Nlm_PrompT ppt,Nlm_Int2 tag,Nlm_PopupTool pup)178 static void Nlm_LoadMenuData (Nlm_MenU m, Nlm_MenuTool hdl,
179 Nlm_PrompT ppt, Nlm_Int2 tag,
180 Nlm_PopupTool pup)
181
182 {
183 Nlm_MenuData PNTR mdptr;
184 Nlm_MenPtr mp;
185
186 if (m != NULL) {
187 mp = (Nlm_MenPtr) Nlm_HandLock (m);
188 mdptr = &(mp->menu);
189 mdptr->handle = hdl;
190 mdptr->prompt = ppt;
191 mdptr->menuTag = tag;
192 mdptr->popup = pup;
193 Nlm_HandUnlock (m);
194 recentMenu = NULL;
195 }
196 }
197
198
Nlm_GetMenuData(Nlm_MenU m,Nlm_MenuData * mdata)199 static void Nlm_GetMenuData (Nlm_MenU m, Nlm_MenuData * mdata)
200
201 {
202 Nlm_MenPtr mp;
203
204 if (m != NULL && mdata != NULL) {
205 if (m == recentMenu && NLM_RISKY) {
206 *mdata = recentMenuData;
207 } else {
208 mp = (Nlm_MenPtr) Nlm_HandLock (m);
209 *mdata = mp->menu;
210 Nlm_HandUnlock (m);
211 recentMenu = m;
212 recentMenuData = *mdata;
213 }
214 }
215 }
216
Nlm_LoadItemData(Nlm_IteM i,Nlm_MenU sub,Nlm_Int2 frst,Nlm_ItemTool hdl)217 static void Nlm_LoadItemData (Nlm_IteM i, Nlm_MenU sub,
218 Nlm_Int2 frst, Nlm_ItemTool hdl)
219
220 {
221 Nlm_ItemData PNTR idptr;
222 Nlm_ItmPtr ip;
223
224 if (i != NULL) {
225 ip = (Nlm_ItmPtr) Nlm_HandLock (i);
226 idptr = &(ip->item);
227 idptr->subMenu = sub;
228 idptr->firstItem = frst;
229 idptr->handle = hdl;
230 Nlm_HandUnlock (i);
231 recentItem = NULL;
232 }
233 }
234
235
Nlm_SetItemData(Nlm_IteM i,Nlm_ItemData * idata)236 static void Nlm_SetItemData (Nlm_IteM i, Nlm_ItemData * idata)
237 {
238 Nlm_ItmPtr ip;
239
240 if (i != NULL && idata != NULL) {
241 ip = (Nlm_ItmPtr) Nlm_HandLock (i);
242 ip->item = *idata;
243 Nlm_HandUnlock (i);
244 recentItem = i;
245 recentItemData = *idata;
246 }
247 }
248
249
Nlm_GetItemData(Nlm_IteM i,Nlm_ItemData * idata)250 static void Nlm_GetItemData (Nlm_IteM i, Nlm_ItemData * idata)
251
252 {
253 Nlm_ItmPtr ip;
254
255 if (i != NULL && idata != NULL) {
256 if (i == recentItem && NLM_RISKY) {
257 *idata = recentItemData;
258 } else {
259 ip = (Nlm_ItmPtr) Nlm_HandLock (i);
260 *idata = ip->item;
261 Nlm_HandUnlock (i);
262 recentItem = i;
263 recentItemData = *idata;
264 }
265 }
266 }
267
Nlm_LoadChoiceData(Nlm_ChoicE c,Nlm_Int2 num,Nlm_Boolean plist,Nlm_Int2 pval,Nlm_ItemTool PNTR hdls)268 static void Nlm_LoadChoiceData (Nlm_ChoicE c, Nlm_Int2 num,
269 Nlm_Boolean plist, Nlm_Int2 pval,
270 Nlm_ItemTool PNTR hdls)
271
272 {
273 Nlm_ChoiceData PNTR cdptr;
274 Nlm_ChsPtr cp;
275
276 if (c != NULL) {
277 cp = (Nlm_ChsPtr) Nlm_HandLock (c);
278 cdptr = &(cp->choice);
279 cdptr->numItems = num;
280 cdptr->isAPopupList = plist;
281 cdptr->popupValue = pval;
282 cdptr->handles = hdls;
283 Nlm_HandUnlock (c);
284 recentChoice = NULL;
285 }
286 }
287
Nlm_SetChoiceData(Nlm_ChoicE c,Nlm_ChoiceData * cdata)288 static void Nlm_SetChoiceData (Nlm_ChoicE c, Nlm_ChoiceData * cdata)
289
290 {
291 Nlm_ChsPtr cp;
292
293 if (c != NULL && cdata != NULL) {
294 cp = (Nlm_ChsPtr) Nlm_HandLock (c);
295 cp->choice = *cdata;
296 Nlm_HandUnlock (c);
297 recentChoice = c;
298 recentChoiceData = *cdata;
299 }
300 }
301
Nlm_GetChoiceData(Nlm_ChoicE c,Nlm_ChoiceData * cdata)302 static void Nlm_GetChoiceData (Nlm_ChoicE c, Nlm_ChoiceData * cdata)
303
304 {
305 Nlm_ChsPtr cp;
306
307 if (c != NULL && cdata != NULL) {
308 if (c == recentChoice && NLM_RISKY) {
309 *cdata = recentChoiceData;
310 } else {
311 cp = (Nlm_ChsPtr) Nlm_HandLock (c);
312 *cdata = cp->choice;
313 Nlm_HandUnlock (c);
314 recentChoice = c;
315 recentChoiceData = *cdata;
316 }
317 }
318 }
319
320 #ifndef WIN_MAC
Nlm_LoadMenuBarData(Nlm_MenuBaR mb,Nlm_MenuTool hdl)321 static void Nlm_LoadMenuBarData (Nlm_MenuBaR mb, Nlm_MenuTool hdl)
322
323 {
324 Nlm_MenuBarData PNTR mbptr;
325 Nlm_MbrPtr mbp;
326
327 if (mb != NULL) {
328 mbp = (Nlm_MbrPtr) Nlm_HandLock (mb);
329 mbptr = &(mbp->menubar);
330 mbptr->handle = hdl;
331 Nlm_HandUnlock (mb);
332 recentMenuBar = NULL;
333 }
334 }
335 #endif
336
337 #ifdef WIN_MAC
Nlm_SetMenuBarData(Nlm_MenuBaR mb,Nlm_MenuBarData * mbdata)338 static void Nlm_SetMenuBarData (Nlm_MenuBaR mb, Nlm_MenuBarData * mbdata)
339 {
340 Nlm_MbrPtr mbp;
341
342 if (mb != NULL && mbdata != NULL) {
343 mbp = (Nlm_MbrPtr) Nlm_HandLock (mb);
344 mbp->menubar = *mbdata;
345 Nlm_HandUnlock (mb);
346 recentMenuBar = mb;
347 recentMenuBarData = *mbdata;
348 }
349 }
350 #endif
351
Nlm_GetMenuBarData(Nlm_MenuBaR mb,Nlm_MenuBarData * mbdata)352 static void Nlm_GetMenuBarData (Nlm_MenuBaR mb, Nlm_MenuBarData * mbdata)
353
354 {
355 Nlm_MbrPtr mbp;
356
357 if (mb != NULL && mbdata != NULL) {
358 if (mb == recentMenuBar && NLM_RISKY) {
359 *mbdata = recentMenuBarData;
360 } else {
361 mbp = (Nlm_MbrPtr) Nlm_HandLock (mb);
362 *mbdata = mbp->menubar;
363 Nlm_HandUnlock (mb);
364 recentMenuBar = mb;
365 recentMenuBarData = *mbdata;
366 }
367 }
368 }
369
Nlm_GetMenuHandle(Nlm_MenU m)370 static Nlm_MenuTool Nlm_GetMenuHandle (Nlm_MenU m)
371
372 {
373 Nlm_MenuData mdata;
374
375 Nlm_GetMenuData (m, &mdata);
376 return mdata.handle;
377 }
378
Nlm_GetMenuPrompt(Nlm_MenU m)379 static Nlm_PrompT Nlm_GetMenuPrompt (Nlm_MenU m)
380
381 {
382 Nlm_MenuData mdata;
383
384 Nlm_GetMenuData (m, &mdata);
385 return mdata.prompt;
386 }
387
388 #ifdef WIN_MAC
Nlm_GetMenuTag(Nlm_MenU m)389 static Nlm_Int2 Nlm_GetMenuTag (Nlm_MenU m)
390 {
391 Nlm_MenuData mdata;
392
393 Nlm_GetMenuData (m, &mdata);
394 return mdata.menuTag;
395 }
396 #endif
397
398 #ifndef WIN_MAC
Nlm_GetMenuPopup(Nlm_MenU m)399 static Nlm_PopupTool Nlm_GetMenuPopup (Nlm_MenU m)
400 {
401 Nlm_MenuData mdata;
402
403 Nlm_GetMenuData (m, &mdata);
404 return mdata.popup;
405 }
406 #endif
407
Nlm_SetSubMenu(Nlm_IteM i,Nlm_MenU sub)408 static void Nlm_SetSubMenu (Nlm_IteM i, Nlm_MenU sub)
409 {
410 Nlm_ItemData idata;
411
412 Nlm_GetItemData (i, &idata);
413 idata.subMenu = sub;
414 Nlm_SetItemData (i, &idata);
415 }
416
417
Nlm_GetSubMenu(Nlm_IteM i)418 static Nlm_MenU Nlm_GetSubMenu (Nlm_IteM i)
419
420 {
421 Nlm_ItemData idata;
422
423 Nlm_GetItemData (i, &idata);
424 return idata.subMenu;
425 }
426
Nlm_GetFirstItem(Nlm_IteM i)427 static Nlm_Int2 Nlm_GetFirstItem (Nlm_IteM i)
428
429 {
430 Nlm_ItemData idata;
431
432 Nlm_GetItemData (i, &idata);
433 return idata.firstItem;
434 }
435
Nlm_GetItemHandle(Nlm_IteM i)436 static Nlm_ItemTool Nlm_GetItemHandle (Nlm_IteM i)
437
438 {
439 Nlm_ItemData idata;
440
441 Nlm_GetItemData (i, &idata);
442 return idata.handle;
443 }
444
445
446 #ifdef WIN_MSWIN
Nlm_GetChildPosition(Nlm_GraphiC child)447 static Nlm_Int2 Nlm_GetChildPosition(Nlm_GraphiC child)
448 {
449 Nlm_Int2 pos = 1;
450 Nlm_GraphiC parent = Nlm_GetParent( child );
451 Nlm_GraphiC next_child;
452 for (next_child = Nlm_GetChild( parent );
453 next_child != NULL && next_child != child;
454 next_child = Nlm_GetNext( next_child ), pos++) continue;
455 return (Nlm_Int2)(next_child == NULL ? 0 : pos);
456 }
457 #endif
458
459
Nlm_SetNumItems(Nlm_ChoicE c,Nlm_Int2 num)460 static void Nlm_SetNumItems (Nlm_ChoicE c, Nlm_Int2 num)
461
462 {
463 Nlm_ChoiceData cdata;
464
465 Nlm_GetChoiceData (c, &cdata);
466 cdata.numItems = num;
467 Nlm_SetChoiceData (c, &cdata);
468 }
469
Nlm_GetNumItems(Nlm_ChoicE c)470 static Nlm_Int2 Nlm_GetNumItems (Nlm_ChoicE c)
471
472 {
473 Nlm_ChoiceData cdata;
474
475 Nlm_GetChoiceData (c, &cdata);
476 return cdata.numItems;
477 }
478
Nlm_IsItAPopupList(Nlm_ChoicE c)479 static Nlm_Boolean Nlm_IsItAPopupList (Nlm_ChoicE c)
480
481 {
482 Nlm_ChoiceData cdata;
483
484 Nlm_GetChoiceData (c, &cdata);
485 return cdata.isAPopupList;
486 }
487
488 #ifdef WIN_MOTIF
Nlm_SetPopupValue(Nlm_ChoicE c,Nlm_Int2 pval)489 static void Nlm_SetPopupValue (Nlm_ChoicE c, Nlm_Int2 pval)
490
491 {
492 Nlm_ChoiceData cdata;
493
494 Nlm_GetChoiceData (c, &cdata);
495 cdata.popupValue = pval;
496 Nlm_SetChoiceData (c, &cdata);
497 }
498 #endif
499
500 #ifdef WIN_MOTIF
Nlm_GetPopupValue(Nlm_ChoicE c)501 static Nlm_Int2 Nlm_GetPopupValue (Nlm_ChoicE c)
502
503 {
504 Nlm_ChoiceData cdata;
505
506 Nlm_GetChoiceData (c, &cdata);
507 return cdata.popupValue;
508 }
509 #endif
510
511 #ifdef WIN_MOTIF
Nlm_SetChoiceHandles(Nlm_ChoicE c,Nlm_ItemTool PNTR hdls)512 static void Nlm_SetChoiceHandles (Nlm_ChoicE c, Nlm_ItemTool PNTR hdls)
513
514 {
515 Nlm_ChoiceData cdata;
516
517 Nlm_GetChoiceData (c, &cdata);
518 cdata.handles = hdls;
519 Nlm_SetChoiceData (c, &cdata);
520 }
521 #endif
522
Nlm_GetChoiceHandles(Nlm_ChoicE c)523 static Nlm_ItemTool PNTR Nlm_GetChoiceHandles (Nlm_ChoicE c)
524
525 {
526 Nlm_ChoiceData cdata;
527
528 Nlm_GetChoiceData (c, &cdata);
529 return cdata.handles;
530 }
531
532 #ifndef WIN_MAC
Nlm_GetMenuBarHandle(Nlm_MenuBaR mb)533 static Nlm_MenuTool Nlm_GetMenuBarHandle (Nlm_MenuBaR mb)
534
535 {
536 Nlm_MenuBarData mbdata;
537
538 Nlm_GetMenuBarData (mb, &mbdata);
539 return mbdata.handle;
540 }
541 #endif
542
543
544 #ifdef WIN_MSWIN
Nlm_ItemToID(Nlm_MenU m,Nlm_Int2 index)545 static Nlm_Int2 Nlm_ItemToID (Nlm_MenU m, Nlm_Int2 index)
546 {
547 Nlm_Int2 rsult = 0;
548 Nlm_MenuTool h;
549
550 if (m != NULL && index > 0) {
551 h = Nlm_GetMenuHandle (m);
552 rsult = GetMenuItemID (h, index - 1);
553 }
554
555 return rsult;
556 }
557 #endif
558
559
Nlm_IsMenuItemChecked(Nlm_MenU m,Nlm_ItemTool itool,Nlm_Int2 item)560 static Nlm_Boolean Nlm_IsMenuItemChecked (Nlm_MenU m, Nlm_ItemTool itool, Nlm_Int2 item)
561
562 {
563 Nlm_MenuTool h;
564 #ifdef WIN_MAC
565 Nlm_Char mark;
566 Nlm_Int2 temp;
567 #endif
568 #ifdef WIN_MSWIN
569 Nlm_Int2 id;
570 #endif
571
572 h = Nlm_GetMenuHandle (m);
573 #ifdef WIN_MAC
574 GetItemMark (h, item, &temp);
575 mark = (Nlm_Char) temp;
576 return (mark != '\0');
577 #endif
578 #ifdef WIN_MSWIN
579 id = GetMenuItemID (h, item - 1);
580 return (Nlm_Boolean) ((LOBYTE (GetMenuState (h, id, MF_BYCOMMAND)) & MF_CHECKED) != 0);
581 #endif
582 #ifdef WIN_MOTIF
583 return (Nlm_Boolean) (XmToggleButtonGetState (itool) != FALSE);
584 #endif
585 }
586
Nlm_CheckMenuItem(Nlm_MenU m,Nlm_ItemTool itool,Nlm_Int2 item,Nlm_Boolean check)587 static void Nlm_CheckMenuItem (Nlm_MenU m, Nlm_ItemTool itool,
588 Nlm_Int2 item, Nlm_Boolean check)
589
590 {
591 Nlm_MenuTool h;
592 #ifdef WIN_MAC
593 Nlm_Char ch;
594 #endif
595 #ifdef WIN_MSWIN
596 Nlm_Int2 id;
597 #endif
598
599 h = Nlm_GetMenuHandle (m);
600 #ifdef WIN_MAC
601 if (check) {
602 ch = '\22';
603 }
604 else {
605 ch = '\0';
606 }
607 SetItemMark (h, item, ch);
608 #endif
609 #ifdef WIN_MSWIN
610 id = GetMenuItemID (h, item - 1);
611 if (check) {
612 CheckMenuItem (h, id, MF_CHECKED);
613 } else {
614 CheckMenuItem (h, id, MF_UNCHECKED);
615 }
616 #endif
617 #ifdef WIN_MOTIF
618 XmToggleButtonSetState (itool, (Boolean) check, FALSE);
619 #endif
620 }
621
622 #ifdef WIN_MAC
Nlm_DeskAccProc(Nlm_ChoicE c)623 static void Nlm_DeskAccProc (Nlm_ChoicE c)
624
625 {
626 #if TARGET_API_MAC_CARBON >= 1
627 /* Carbon will create, fill, and handle everything in the Apple menu */
628 return;
629 #else
630 Nlm_MenuTool h;
631 Nlm_MenU m;
632 Nlm_Char temp [256];
633
634 m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) c);
635 h = Nlm_GetMenuHandle (m);
636 GetMenuItemText (h, currentItemNum, (StringPtr) temp);
637 OpenDeskAcc ((StringPtr) temp);
638 #endif
639 }
640 #endif
641
Nlm_ActivateInnerMenus(Nlm_MenU m)642 static void Nlm_ActivateInnerMenus (Nlm_MenU m)
643
644 {
645 Nlm_IteM i;
646 Nlm_MenU s;
647 #ifdef WIN_MAC
648 Nlm_MenuTool h;
649 #endif
650
651 i = (Nlm_IteM) Nlm_GetChild ((Nlm_GraphiC) m);
652 while (i != NULL) {
653 s = Nlm_GetSubMenu (i);
654 if (s != NULL) {
655 if (Nlm_GetEnabled ((Nlm_GraphiC) s)) {
656 Nlm_DoEnable ((Nlm_GraphiC) i, FALSE, FALSE);
657 #ifdef WIN_MAC
658 h = Nlm_GetMenuHandle (s);
659 InsertMenu (h, -1);
660 #endif
661 Nlm_ActivateInnerMenus (s);
662 }
663 }
664 i = (Nlm_IteM) Nlm_GetNext ((Nlm_GraphiC) i);
665 }
666 }
667
Nlm_DeactivateInnerMenus(Nlm_MenU m)668 static void Nlm_DeactivateInnerMenus (Nlm_MenU m)
669
670 {
671 Nlm_IteM i;
672 Nlm_MenU s;
673 #ifdef WIN_MAC
674 Nlm_Int2 tag;
675 #endif
676
677 i = (Nlm_IteM) Nlm_GetChild ((Nlm_GraphiC) m);
678 while (i != NULL) {
679 s = Nlm_GetSubMenu (i);
680 if (s != NULL) {
681 Nlm_DoDisable ((Nlm_GraphiC) i, FALSE, FALSE);
682 #ifdef WIN_MAC
683 tag = Nlm_GetMenuTag (s);
684 DeleteMenu (tag);
685 #endif
686 Nlm_DeactivateInnerMenus (s);
687 }
688 i = (Nlm_IteM) Nlm_GetNext ((Nlm_GraphiC) i);
689 }
690 }
691
692 static Nlm_ItmActnProc itemAction = NULL;
693
Nlm_SetMenuAction(Nlm_ItmActnProc actn)694 extern void Nlm_SetMenuAction (Nlm_ItmActnProc actn)
695
696 {
697 itemAction = actn;
698 }
699
700 #ifdef WIN_MAC
Nlm_DesktopMenuBarClick(Nlm_GraphiC mb,Nlm_PoinT pt)701 static Nlm_Boolean Nlm_DesktopMenuBarClick (Nlm_GraphiC mb, Nlm_PoinT pt)
702
703 {
704 Nlm_Int4 choice;
705 Nlm_PoinT global;
706 Nlm_MenU m;
707 Nlm_MenU n;
708 Nlm_Boolean notInGraphic;
709 Nlm_PointTool ptool;
710 Nlm_Boolean rsult;
711 Nlm_Int2 windowLoc;
712 Nlm_WindowTool wptr;
713
714 rsult = FALSE;
715 currentMenuNum = 0;
716 currentItemNum = 0;
717 global = pt;
718 Nlm_LocalToGlobal (&global);
719 Nlm_PoinTToPointTool (global, &ptool);
720 windowLoc = FindWindow (ptool, &wptr);
721 if (windowLoc == inMenuBar) {
722 choice = MenuSelect (ptool);
723 currentMenuNum = HiWord (choice);
724 currentItemNum = LoWord (choice);
725 m = (Nlm_MenU) Nlm_GetChild (mb);
726 notInGraphic = TRUE;
727 while (m != NULL && notInGraphic) {
728 n = (Nlm_MenU) Nlm_GetNext ((Nlm_GraphiC) m);
729 currentMenuTag = Nlm_GetMenuTag (m);
730 if (Nlm_GetEnabled ((Nlm_GraphiC) m) && Nlm_GetVisible ((Nlm_GraphiC) m) &&
731 Nlm_DoClick ((Nlm_GraphiC) m, pt)) {
732 notInGraphic = FALSE;
733 }
734 m = n;
735 }
736 rsult = TRUE;
737 }
738 return rsult;
739 }
740
Nlm_WindowMenuBarClick(Nlm_GraphiC mb,Nlm_PoinT pt)741 static Nlm_Boolean Nlm_WindowMenuBarClick (Nlm_GraphiC mb, Nlm_PoinT pt)
742
743 {
744 Nlm_MenU m;
745 Nlm_MenU n;
746 Nlm_Boolean notInside;
747
748 m = (Nlm_MenU) Nlm_GetChild (mb);
749 notInside = TRUE;
750 while (m != NULL && notInside) {
751 n = (Nlm_MenU) Nlm_GetNext ((Nlm_GraphiC) m);
752 currentMenuTag = Nlm_GetMenuTag (m);
753 if (Nlm_GetVisible ((Nlm_GraphiC) m) && Nlm_DoClick ((Nlm_GraphiC) m, pt)) {
754 notInside = FALSE;
755 }
756 m = n;
757 }
758 return (! notInside);
759 }
760
Nlm_DesktopMenuClick(Nlm_GraphiC m,Nlm_PoinT pt)761 static Nlm_Boolean Nlm_DesktopMenuClick (Nlm_GraphiC m, Nlm_PoinT pt)
762
763 {
764 Nlm_IteM i;
765 Nlm_Boolean notInMenu;
766 Nlm_IteM n;
767 Nlm_Boolean rsult;
768 Nlm_Int2 tag;
769
770 rsult = FALSE;
771 tag = Nlm_GetMenuTag ((Nlm_MenU) m);
772 if (currentMenuNum > 0 && currentMenuNum == tag) {
773 i = (Nlm_IteM) Nlm_GetChild (m);
774 notInMenu = TRUE;
775 while (i != NULL && notInMenu) {
776 n = (Nlm_IteM) Nlm_GetNext ((Nlm_GraphiC) i);
777 if (Nlm_GetEnabled ((Nlm_GraphiC) i) && Nlm_GetVisible ((Nlm_GraphiC) i) &&
778 Nlm_DoClick ((Nlm_GraphiC) i, pt)) {
779 notInMenu = FALSE;
780 }
781 i = n;
782 }
783 HiliteMenu (0);
784 currentMenuNum = 0;
785 rsult = TRUE;
786 }
787 return rsult;
788 }
789
Nlm_PopupAPopupList(Nlm_GraphiC m,Nlm_PoinT pt,Nlm_RectPtr r,Nlm_PoinT pop,Nlm_Int2 item)790 static void Nlm_PopupAPopupList (Nlm_GraphiC m, Nlm_PoinT pt,
791 Nlm_RectPtr r, Nlm_PoinT pop,
792 Nlm_Int2 item)
793
794 {
795 Nlm_Int4 choice;
796 Nlm_MenuTool h;
797 Nlm_IteM i;
798 Nlm_IteM n;
799 Nlm_WindoW newwindow;
800 Nlm_Boolean notInMenu;
801 Nlm_WindoW oldwindow;
802
803 oldwindow = Nlm_CurrentWindow ();
804 newwindow = Nlm_GetParentWindow (m);
805 Nlm_InvertRect (r);
806 h = Nlm_GetMenuHandle ((Nlm_MenU) m);
807 choice = PopUpMenuSelect (h, pop.y, pop.x, item);
808 currentMenuNum = HiWord (choice);
809 currentItemNum = LoWord (choice);
810 currentMenuTag = Nlm_GetMenuTag ((Nlm_MenU) m);
811 i = (Nlm_IteM) Nlm_GetChild (m);
812 notInMenu = TRUE;
813 while (i != NULL && notInMenu) {
814 n = (Nlm_IteM) Nlm_GetNext ((Nlm_GraphiC) i);
815 if (Nlm_GetEnabled ((Nlm_GraphiC) i) && Nlm_GetVisible ((Nlm_GraphiC) i) &&
816 Nlm_DoClick ((Nlm_GraphiC) i, pt)) {
817 notInMenu = FALSE;
818 }
819 i = n;
820 }
821 currentMenuNum = 0;
822 Nlm_UseWindow (newwindow);
823 Nlm_EraseRect (r);
824 Nlm_InvalRect (r);
825 Nlm_Update ();
826 Nlm_UseWindow (oldwindow);
827 }
828
Nlm_PopupClick(Nlm_GraphiC m,Nlm_PoinT pt)829 static Nlm_Boolean Nlm_PopupClick (Nlm_GraphiC m, Nlm_PoinT pt)
830
831 {
832 Nlm_MenuTool h;
833 Nlm_PrompT p;
834 Nlm_PoinT pop;
835 Nlm_RecT r;
836 Nlm_Boolean rsult;
837 Nlm_Int2 tag;
838
839 rsult = FALSE;
840 p = Nlm_GetMenuPrompt ((Nlm_MenU) m);
841 Nlm_GetRect ((Nlm_GraphiC) p, &r);
842 if (Nlm_PtInRect (pt, &r)) {
843 h = Nlm_GetMenuHandle ((Nlm_MenU) m);
844 InsertMenu (h, -1);
845 currentMenuNum = 0;
846 currentItemNum = 0;
847 pop.x = r.left;
848 pop.y = r.bottom + 1;
849 Nlm_LocalToGlobal (&pop);
850 Nlm_PopupAPopupList (m, pt, &r, pop, 0);
851 tag = Nlm_GetMenuTag ((Nlm_MenU) m);
852 DeleteMenu (tag);
853 rsult = TRUE;
854 }
855 return rsult;
856 }
857
Nlm_PulldownClick(Nlm_GraphiC m,Nlm_PoinT pt)858 static Nlm_Boolean Nlm_PulldownClick (Nlm_GraphiC m, Nlm_PoinT pt)
859
860 {
861 Nlm_MenuTool h;
862 Nlm_PoinT pop;
863 Nlm_RecT r;
864 Nlm_Boolean rsult;
865 Nlm_Int2 tag;
866
867 rsult = FALSE;
868 Nlm_GetRect (m, &r);
869 Nlm_InsetRect (&r, 0, 2);
870 if (Nlm_PtInRect (pt, &r)) {
871 h = Nlm_GetMenuHandle ((Nlm_MenU) m);
872 InsertMenu (h, -1);
873 currentMenuNum = 0;
874 currentItemNum = 0;
875 Nlm_GetRect (m, &r);
876 Nlm_InsetRect (&r, -6, 0);
877 r.top++;
878 pop.x = r.left + 1;
879 pop.y = r.bottom;
880 Nlm_LocalToGlobal (&pop);
881 Nlm_PopupAPopupList (m, pt, &r, pop, 0);
882 tag = Nlm_GetMenuTag ((Nlm_MenU) m);
883 DeleteMenu (tag);
884 rsult = TRUE;
885 }
886 return rsult;
887 }
888
Nlm_MacPopListClick(Nlm_GraphiC m,Nlm_PoinT pt)889 static Nlm_Boolean Nlm_MacPopListClick (Nlm_GraphiC m, Nlm_PoinT pt)
890
891 {
892 Nlm_ChoicE c;
893 Nlm_MenuTool h;
894 Nlm_Int2 item;
895 Nlm_PoinT pop;
896 Nlm_RecT r;
897 Nlm_Boolean rsult;
898 Nlm_Int2 tag;
899
900 rsult = FALSE;
901 Nlm_GetRect (m, &r);
902 Nlm_InsetRect (&r, 2, 3);
903 if (Nlm_PtInRect (pt, &r)) {
904 h = Nlm_GetMenuHandle ((Nlm_MenU) m);
905 InsertMenu (h, -1);
906 currentMenuNum = 0;
907 currentItemNum = 0;
908 item = 0;
909 c = (Nlm_ChoicE) Nlm_GetChild (m);
910 if (c != NULL) {
911 item = Nlm_DoGetValue ((Nlm_GraphiC) c);
912 }
913 Nlm_GetRect (m, &r);
914 pop.x = r.left + 1;
915 pop.y = r.top + 1;
916 Nlm_UpsetRect (&r, 1, 1, 2, 2);
917 Nlm_LocalToGlobal (&pop);
918 Nlm_PopupAPopupList (m, pt, &r, pop, item);
919 tag = Nlm_GetMenuTag ((Nlm_MenU) m);
920 DeleteMenu (tag);
921 rsult = TRUE;
922 }
923 return rsult;
924 }
925
Nlm_MSPopListClick(Nlm_GraphiC m,Nlm_PoinT pt)926 static Nlm_Boolean Nlm_MSPopListClick (Nlm_GraphiC m, Nlm_PoinT pt)
927
928 {
929 Nlm_MenuTool h;
930 Nlm_PoinT pop;
931 Nlm_RecT r;
932 Nlm_Boolean rsult;
933 Nlm_Int2 tag;
934
935 rsult = FALSE;
936 Nlm_GetRect (m, &r);
937 Nlm_InsetRect (&r, 2, 2);
938 if (Nlm_PtInRect (pt, &r)) {
939 h = Nlm_GetMenuHandle ((Nlm_MenU) m);
940 InsertMenu (h, -1);
941 currentMenuNum = 0;
942 currentItemNum = 0;
943 Nlm_GetRect (m, &r);
944 pop.x = r.left + 1;
945 pop.y = r.bottom - 1;
946 Nlm_UpsetRect (&r, 1, 1, 2, 2);
947 Nlm_LocalToGlobal (&pop);
948 Nlm_PopupAPopupList (m, pt, &r, pop, 0);
949 tag = Nlm_GetMenuTag ((Nlm_MenU) m);
950 DeleteMenu (tag);
951 rsult = TRUE;
952 }
953 return rsult;
954 }
955
Nlm_SubItemClick(Nlm_GraphiC i,Nlm_PoinT pt)956 static Nlm_Boolean Nlm_SubItemClick (Nlm_GraphiC i, Nlm_PoinT pt)
957
958 {
959 Nlm_IteM c;
960 Nlm_IteM n;
961 Nlm_Boolean notInMenu;
962 Nlm_Int2 oldMenuTag;
963 Nlm_Boolean rsult;
964 Nlm_MenU s;
965
966 rsult = FALSE;
967 s = Nlm_GetSubMenu ((Nlm_IteM) i);
968 if (s != NULL) {
969 oldMenuTag = currentMenuTag;
970 currentMenuTag = Nlm_GetMenuTag (s);
971 c = (Nlm_IteM) Nlm_GetChild ((Nlm_GraphiC) s);
972 notInMenu = TRUE;
973 while (c != NULL && notInMenu) {
974 n = (Nlm_IteM) Nlm_GetNext ((Nlm_GraphiC) c);
975 if (Nlm_GetEnabled ((Nlm_GraphiC) c) && Nlm_GetVisible ((Nlm_GraphiC) c) &&
976 Nlm_DoClick ((Nlm_GraphiC) c, pt)) {
977 notInMenu = FALSE;
978 }
979 c = n;
980 }
981 currentMenuTag = oldMenuTag;
982 rsult = (! notInMenu);
983 }
984 return rsult;
985 }
986
Nlm_CommItemClick(Nlm_GraphiC i,Nlm_PoinT pt)987 static Nlm_Boolean Nlm_CommItemClick (Nlm_GraphiC i, Nlm_PoinT pt)
988
989 {
990 Nlm_Int2 index;
991 Nlm_Boolean rsult;
992
993 rsult = FALSE;
994 index = Nlm_GetFirstItem ((Nlm_IteM) i);
995 if (currentItemNum == index && currentMenuTag == currentMenuNum) {
996 Nlm_DoAction (i);
997 if (itemAction != NULL) {
998 itemAction ((Nlm_IteM) i);
999 }
1000 rsult = TRUE;
1001 }
1002 return rsult;
1003 }
1004
Nlm_StatItemClick(Nlm_GraphiC i,Nlm_PoinT pt)1005 static Nlm_Boolean Nlm_StatItemClick (Nlm_GraphiC i, Nlm_PoinT pt)
1006
1007 {
1008 Nlm_Int2 index;
1009 Nlm_Boolean rsult;
1010 Nlm_Boolean val;
1011
1012 rsult = FALSE;
1013 index = Nlm_GetFirstItem ((Nlm_IteM) i);
1014 if (currentItemNum == index && currentMenuTag == currentMenuNum) {
1015 val = Nlm_DoGetStatus (i, 0);
1016 Nlm_DoSetStatus (i, 0, (! val), FALSE);
1017 Nlm_DoAction (i);
1018 rsult = TRUE;
1019 }
1020 return rsult;
1021 }
1022
Nlm_ChoiceGroupClick(Nlm_GraphiC c,Nlm_PoinT pt)1023 static Nlm_Boolean Nlm_ChoiceGroupClick (Nlm_GraphiC c, Nlm_PoinT pt)
1024
1025 {
1026 Nlm_Int2 first;
1027 Nlm_Int2 num;
1028 Nlm_Boolean rsult;
1029 Nlm_Int2 val;
1030
1031 rsult = FALSE;
1032 first = Nlm_GetFirstItem ((Nlm_IteM) c);
1033 num = Nlm_GetNumItems ((Nlm_ChoicE) c);
1034 val = Nlm_DoGetValue (c);
1035 if (currentItemNum >= first && currentItemNum < first + num &&
1036 currentMenuTag == currentMenuNum) {
1037 if (val != currentItemNum - first + 1) {
1038 Nlm_DoSetValue (c, currentItemNum - first + 1, FALSE);
1039 Nlm_DoAction (c);
1040 }
1041 rsult = TRUE;
1042 }
1043 return rsult;
1044 }
1045
Nlm_PopupChoiceGroupClick(Nlm_GraphiC c,Nlm_PoinT pt)1046 static Nlm_Boolean Nlm_PopupChoiceGroupClick (Nlm_GraphiC c, Nlm_PoinT pt)
1047
1048 {
1049 return Nlm_ChoiceGroupClick (c, pt);
1050 }
1051
Nlm_DAClick(Nlm_GraphiC c,Nlm_PoinT pt)1052 static Nlm_Boolean Nlm_DAClick (Nlm_GraphiC c, Nlm_PoinT pt)
1053
1054 {
1055 Nlm_Int2 first;
1056 Nlm_Int2 num;
1057 Nlm_Boolean rsult;
1058
1059 rsult = FALSE;
1060 first = Nlm_GetFirstItem ((Nlm_IteM) c);
1061 num = Nlm_GetNumItems ((Nlm_ChoicE) c);
1062 if (currentItemNum >= first && currentItemNum < first + num &&
1063 currentMenuTag == currentMenuNum) {
1064 Nlm_DeskAccProc ((Nlm_ChoicE) c);
1065 rsult = TRUE;
1066 }
1067 return rsult;
1068 }
1069 #endif
1070
1071 #ifdef WIN_MSWIN
Nlm_WindowMenuBarCommand(Nlm_GraphiC mb)1072 static Nlm_Boolean Nlm_WindowMenuBarCommand (Nlm_GraphiC mb)
1073
1074 {
1075 Nlm_MenU m;
1076 Nlm_MenU n;
1077 Nlm_Boolean notInside;
1078
1079 notInside = TRUE;
1080 currentItemID = Nlm_currentId;
1081 m = (Nlm_MenU) Nlm_GetChild (mb);
1082 while (m != NULL && notInside) {
1083 n = (Nlm_MenU) Nlm_GetNext ((Nlm_GraphiC) m);
1084 if (Nlm_GetVisible ((Nlm_GraphiC) m) && Nlm_DoCommand ((Nlm_GraphiC) m)) {
1085 notInside = FALSE;
1086 }
1087 m = n;
1088 }
1089 return (Nlm_Boolean) (! notInside);
1090 }
1091
Nlm_PulldownCommand(Nlm_GraphiC m)1092 static Nlm_Boolean Nlm_PulldownCommand (Nlm_GraphiC m)
1093
1094 {
1095 Nlm_IteM i;
1096 Nlm_IteM n;
1097 Nlm_Boolean notInside;
1098
1099
1100 notInside = TRUE;
1101 i = (Nlm_IteM) Nlm_GetChild (m);
1102 while (i != NULL && notInside) {
1103 n = (Nlm_IteM) Nlm_GetNext ((Nlm_GraphiC) i);
1104 if (Nlm_GetEnabled ((Nlm_GraphiC) i) && Nlm_GetVisible ((Nlm_GraphiC) i) &&
1105 Nlm_DoCommand ((Nlm_GraphiC) i)) {
1106 notInside = FALSE;
1107 }
1108 i = n;
1109 }
1110 return (Nlm_Boolean) (! notInside);
1111 }
1112
Nlm_MSPopListCommand(Nlm_GraphiC m)1113 static Nlm_Boolean Nlm_MSPopListCommand (Nlm_GraphiC m)
1114
1115 {
1116 Nlm_ChoicE c;
1117 Nlm_Boolean rsult;
1118
1119 if (Nlm_currentCode == CBN_SELCHANGE) {
1120 c = (Nlm_ChoicE) Nlm_GetChild (m);
1121 Nlm_DoAction ((Nlm_GraphiC) c);
1122 }
1123 rsult = TRUE;
1124 return rsult;
1125 }
1126
Nlm_MacPopListCommand(Nlm_GraphiC m)1127 static Nlm_Boolean Nlm_MacPopListCommand (Nlm_GraphiC m)
1128
1129 {
1130 Nlm_Boolean rsult;
1131
1132 rsult = Nlm_MSPopListCommand (m);
1133 return rsult;
1134 }
1135
Nlm_SubItemCommand(Nlm_GraphiC prnt)1136 static Nlm_Boolean Nlm_SubItemCommand (Nlm_GraphiC prnt)
1137
1138 {
1139 Nlm_IteM i;
1140 Nlm_MenU m;
1141 Nlm_IteM n;
1142 Nlm_Boolean notInside;
1143
1144
1145 notInside = TRUE;
1146 m = Nlm_GetSubMenu ((Nlm_IteM) prnt);
1147 i = (Nlm_IteM) Nlm_GetChild ((Nlm_GraphiC) m);
1148 while (i != NULL && notInside) {
1149 n = (Nlm_IteM) Nlm_GetNext ((Nlm_GraphiC) i);
1150 if (Nlm_GetEnabled ((Nlm_GraphiC) i) && Nlm_GetVisible ((Nlm_GraphiC) i) &&
1151 Nlm_DoCommand ((Nlm_GraphiC) i)) {
1152 notInside = FALSE;
1153 }
1154 i = n;
1155 }
1156 return (Nlm_Boolean) (! notInside);
1157 }
1158
Nlm_CommItemCommand(Nlm_GraphiC i)1159 static Nlm_Boolean Nlm_CommItemCommand (Nlm_GraphiC i)
1160
1161 {
1162 Nlm_Int2 id;
1163 Nlm_Int2 index;
1164 Nlm_MenU m;
1165 Nlm_Boolean rsult;
1166
1167 rsult = FALSE;
1168 index = Nlm_GetFirstItem ((Nlm_IteM) i);
1169 m = (Nlm_MenU) Nlm_GetParent (i);
1170 id = Nlm_ItemToID (m, index);
1171 if (currentItemID == id) {
1172 Nlm_DoAction (i);
1173 if (itemAction != NULL) {
1174 itemAction ((Nlm_IteM) i);
1175 }
1176 rsult = TRUE;
1177 }
1178 return rsult;
1179 }
1180
Nlm_StatItemCommand(Nlm_GraphiC i)1181 static Nlm_Boolean Nlm_StatItemCommand (Nlm_GraphiC i)
1182
1183 {
1184 Nlm_Int2 id;
1185 Nlm_Int2 index;
1186 Nlm_MenU m;
1187 Nlm_Boolean rsult;
1188
1189 rsult = FALSE;
1190 index = Nlm_GetFirstItem ((Nlm_IteM) i);
1191 m = (Nlm_MenU) Nlm_GetParent (i);
1192 id = Nlm_ItemToID (m, index);
1193 if (currentItemID == id) {
1194 if (Nlm_DoGetStatus (i, 0)) {
1195 Nlm_DoSetStatus (i, 0, FALSE, FALSE);
1196 } else {
1197 Nlm_DoSetStatus (i, 0, TRUE, FALSE);
1198 }
1199 Nlm_DoAction (i);
1200 rsult = TRUE;
1201 }
1202 return rsult;
1203 }
1204
Nlm_ChoiceGroupCommand(Nlm_GraphiC c)1205 static Nlm_Boolean Nlm_ChoiceGroupCommand (Nlm_GraphiC c)
1206
1207 {
1208 Nlm_Int2 first;
1209 Nlm_Int2 id;
1210 Nlm_Int2 index;
1211 Nlm_MenU m;
1212 Nlm_Int2 num;
1213 Nlm_Boolean rsult;
1214 Nlm_Int2 val;
1215
1216 rsult = FALSE;
1217 first = Nlm_GetFirstItem ((Nlm_IteM) c);
1218 num = Nlm_GetNumItems ((Nlm_ChoicE) c);
1219 val = Nlm_DoGetValue (c);
1220 index = first;
1221 m = (Nlm_MenU) Nlm_GetParent (c);
1222 while (num > 0) {
1223 id = Nlm_ItemToID (m, index);
1224 if (currentItemID == id) {
1225 if (val != index - first + 1) {
1226 Nlm_DoSetValue (c, (Nlm_Int2)(index - first + 1), FALSE);
1227 Nlm_DoAction (c);
1228 }
1229 num = 0;
1230 rsult = TRUE;
1231 } else {
1232 index++;
1233 num--;
1234 }
1235 }
1236 return rsult;
1237 }
1238 #endif
1239
1240 #ifdef WIN_MOTIF
Nlm_CommItemCallback(Nlm_GraphiC i)1241 static void Nlm_CommItemCallback (Nlm_GraphiC i)
1242
1243 {
1244 Nlm_DoAction (i);
1245 if (itemAction != NULL) {
1246 itemAction ((Nlm_IteM) i);
1247 }
1248 }
1249
Nlm_StatItemCallback(Nlm_GraphiC i)1250 static void Nlm_StatItemCallback (Nlm_GraphiC i)
1251
1252 {
1253 Nlm_DoAction (i);
1254 }
1255
Nlm_ChoiceGroupCallback(Nlm_GraphiC c)1256 static void Nlm_ChoiceGroupCallback (Nlm_GraphiC c)
1257
1258 {
1259 Nlm_ItemTool PNTR hdls;
1260 Nlm_Int2 i;
1261 Nlm_Int2 j;
1262 Nlm_Int2 num;
1263
1264 hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
1265 num = Nlm_GetNumItems ((Nlm_ChoicE) c);
1266 if (hdls != NULL && num > 0) {
1267 i = 0;
1268 while (i < num && hdls [i] != (Nlm_ItemTool) choiceWidget) {
1269 i++;
1270 }
1271 if (i < num) {
1272 if (XmToggleButtonGetState (hdls [i]) == FALSE) {
1273 XmToggleButtonSetState (hdls [i], TRUE, FALSE);
1274 } else {
1275 for (j = 0; j < num; j++) {
1276 if (j != i) {
1277 XmToggleButtonSetState (hdls [j], FALSE, FALSE);
1278 }
1279 }
1280 Nlm_DoAction (c);
1281 }
1282 }
1283 }
1284 }
1285
Nlm_PopupChoiceCallback(Nlm_GraphiC c)1286 static void Nlm_PopupChoiceCallback (Nlm_GraphiC c)
1287
1288 {
1289 Nlm_ItemTool PNTR hdls;
1290 Nlm_Int2 i;
1291 Nlm_Int2 num;
1292 Nlm_Int2 val;
1293
1294 hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
1295 num = Nlm_GetNumItems ((Nlm_ChoicE) c);
1296 if (hdls != NULL && num > 0) {
1297 i = 0;
1298 while (i < num && hdls [i] != (Nlm_ItemTool) choiceWidget) {
1299 i++;
1300 }
1301 if (i < num) {
1302 i++;
1303 val = Nlm_GetPopupValue ((Nlm_ChoicE) c);
1304 if (i != val) {
1305 Nlm_SetPopupValue ((Nlm_ChoicE) c, i);
1306 XtUnmanageChild (hdls [63]);
1307 Nlm_DoAction (c);
1308 }
1309 }
1310 }
1311 }
1312 #endif
1313
1314 #ifdef WIN_MAC
Nlm_DesktopMenuBarKey(Nlm_GraphiC mb,Nlm_Char ch)1315 static Nlm_Boolean Nlm_DesktopMenuBarKey (Nlm_GraphiC mb, Nlm_Char ch)
1316
1317 {
1318 Nlm_Int4 choice;
1319 Nlm_MenU m;
1320 Nlm_MenuBarData mbdata;
1321 Nlm_MenU n;
1322 Nlm_Boolean notInside;
1323 Nlm_Boolean rsult;
1324
1325 rsult = FALSE;
1326 currentMenuNum = 0;
1327 currentItemNum = 0;
1328 if (Nlm_cmmdKey) {
1329 Nlm_GetMenuBarData ((Nlm_MenuBaR) mb, &mbdata);
1330 if (mbdata.notJustSubMenu) {
1331 choice = MenuKey (ch);
1332 currentMenuNum = HiWord (choice);
1333 currentItemNum = LoWord (choice);
1334 m = (Nlm_MenU) Nlm_GetChild (mb);
1335 notInside = TRUE;
1336 while (m != NULL && notInside) {
1337 n = (Nlm_MenU) Nlm_GetNext ((Nlm_GraphiC) m);
1338 currentMenuTag = Nlm_GetMenuTag (m);
1339 if (Nlm_GetEnabled ((Nlm_GraphiC) m) && Nlm_GetVisible ((Nlm_GraphiC) m) &&
1340 Nlm_DoKey ((Nlm_GraphiC) m, ch)) {
1341 notInside = FALSE;
1342 }
1343 m = n;
1344 }
1345 rsult = TRUE;
1346 }
1347 }
1348 return rsult;
1349 }
1350
Nlm_DesktopMenuKey(Nlm_GraphiC m,Nlm_Char ch)1351 static Nlm_Boolean Nlm_DesktopMenuKey (Nlm_GraphiC m, Nlm_Char ch)
1352
1353 {
1354 Nlm_IteM i;
1355 Nlm_IteM n;
1356 Nlm_Boolean notInMenu;
1357 Nlm_Boolean rsult;
1358 Nlm_Int2 tag;
1359
1360 rsult = FALSE;
1361 tag = Nlm_GetMenuTag ((Nlm_MenU) m);
1362 if (currentMenuNum > 0 && currentMenuNum == tag) {
1363 i = (Nlm_IteM) Nlm_GetChild (m);
1364 notInMenu = TRUE;
1365 while (i != NULL && notInMenu) {
1366 n = (Nlm_IteM) Nlm_GetNext ((Nlm_GraphiC) i);
1367 if (Nlm_GetEnabled ((Nlm_GraphiC) i) && Nlm_GetVisible ((Nlm_GraphiC) i) &&
1368 Nlm_DoKey ((Nlm_GraphiC) i, ch)) {
1369 notInMenu = FALSE;
1370 }
1371 i = n;
1372 }
1373 HiliteMenu (0);
1374 currentMenuNum = 0;
1375 rsult = TRUE;
1376 }
1377 return rsult;
1378 }
1379
Nlm_SubMenuKey(Nlm_GraphiC m,Nlm_Char ch)1380 static Nlm_Boolean Nlm_SubMenuKey (Nlm_GraphiC m, Nlm_Char ch)
1381
1382 {
1383 Nlm_IteM i;
1384 Nlm_Boolean rsult;
1385
1386 rsult = FALSE;
1387 i = (Nlm_IteM) Nlm_GetParent (m);
1388 if (i != NULL) {
1389 rsult = Nlm_DesktopMenuKey (m, ch);
1390 }
1391 return rsult;
1392 }
1393
Nlm_PopupKey(Nlm_GraphiC m,Nlm_Char ch)1394 static Nlm_Boolean Nlm_PopupKey (Nlm_GraphiC m, Nlm_Char ch)
1395
1396 {
1397 Nlm_Int4 choice;
1398 Nlm_MenuTool h;
1399 Nlm_IteM i;
1400 Nlm_IteM n;
1401 Nlm_Boolean notInMenu;
1402 Nlm_RecT r;
1403 Nlm_Boolean rsult;
1404 Nlm_Int2 tag;
1405
1406 rsult = FALSE;
1407 if (Nlm_cmmdKey) {
1408 tag = Nlm_GetMenuTag ((Nlm_MenU) m);
1409 h = Nlm_GetMenuHandle ((Nlm_MenU) m);
1410 InsertMenu (h, -1);
1411 currentMenuNum = 0;
1412 currentItemNum = 0;
1413 choice = MenuKey (ch);
1414 currentMenuNum = HiWord (choice);
1415 currentItemNum = LoWord (choice);
1416 if (currentMenuNum > 0 && currentMenuNum == tag) {
1417 Nlm_GetRect (m, &r);
1418 Nlm_InvertRect (&r);
1419 i = (Nlm_IteM) Nlm_GetChild (m);
1420 notInMenu = TRUE;
1421 while (i != NULL && notInMenu) {
1422 n = (Nlm_IteM) Nlm_GetNext ((Nlm_GraphiC) i);
1423 if (Nlm_GetEnabled ((Nlm_GraphiC) i) && Nlm_GetVisible ((Nlm_GraphiC) i) &&
1424 Nlm_DoKey ((Nlm_GraphiC) i, ch)) {
1425 notInMenu = FALSE;
1426 }
1427 i = n;
1428 }
1429 currentMenuNum = 0;
1430 DeleteMenu (tag);
1431 Nlm_DoDraw (m);
1432 rsult = TRUE;
1433 } else {
1434 currentMenuNum = 0;
1435 DeleteMenu (tag);
1436 }
1437 }
1438 return rsult;
1439 }
1440
Nlm_CommItemKey(Nlm_GraphiC i,Nlm_Char ch)1441 static Nlm_Boolean Nlm_CommItemKey (Nlm_GraphiC i, Nlm_Char ch)
1442
1443 {
1444 Nlm_Int2 index;
1445 Nlm_Boolean rsult;
1446
1447 rsult = FALSE;
1448 index = Nlm_GetFirstItem ((Nlm_IteM) i);
1449 if (currentItemNum == index) {
1450 Nlm_DoAction (i);
1451 if (itemAction != NULL) {
1452 itemAction ((Nlm_IteM) i);
1453 }
1454 rsult = TRUE;
1455 }
1456 return rsult;
1457 }
1458
Nlm_StatItemKey(Nlm_GraphiC i,Nlm_Char ch)1459 static Nlm_Boolean Nlm_StatItemKey (Nlm_GraphiC i, Nlm_Char ch)
1460
1461 {
1462 Nlm_MenuTool h;
1463 Nlm_Int2 index;
1464 Nlm_MenU m;
1465 Nlm_Char mark;
1466 Nlm_Boolean rsult;
1467 Nlm_Int2 temp;
1468
1469 rsult = FALSE;
1470 index = Nlm_GetFirstItem ((Nlm_IteM) i);
1471 if (currentItemNum == index) {
1472 m = (Nlm_MenU) Nlm_GetParent (i);
1473 h = Nlm_GetMenuHandle (m);
1474 GetItemMark (h, currentItemNum, &temp);
1475 mark = (Nlm_Char) temp;
1476 Nlm_CheckMenuItem (m, NULL, currentItemNum, (mark == '\0'));
1477 Nlm_DoAction (i);
1478 rsult = TRUE;
1479 }
1480 return rsult;
1481 }
1482
Nlm_ChoiceGroupKey(Nlm_GraphiC c,Nlm_Char ch)1483 static Nlm_Boolean Nlm_ChoiceGroupKey (Nlm_GraphiC c, Nlm_Char ch)
1484
1485 {
1486 Nlm_Int2 first;
1487 Nlm_Int2 num;
1488 Nlm_Boolean rsult;
1489 Nlm_Int2 val;
1490
1491 rsult = FALSE;
1492 first = Nlm_GetFirstItem ((Nlm_IteM) c);
1493 num = Nlm_GetNumItems ((Nlm_ChoicE) c);
1494 val = Nlm_DoGetValue (c);
1495 if (currentItemNum >= first && currentItemNum < first + num) {
1496 if (val != currentItemNum - first + 1) {
1497 Nlm_DoSetValue (c, currentItemNum - first + 1, FALSE);
1498 Nlm_DoAction (c);
1499 rsult = TRUE;
1500 }
1501 }
1502 return rsult;
1503 }
1504
Nlm_DAKey(Nlm_GraphiC c,Nlm_Char ch)1505 static Nlm_Boolean Nlm_DAKey (Nlm_GraphiC c, Nlm_Char ch)
1506
1507 {
1508 Nlm_Int2 first;
1509 Nlm_Int2 num;
1510 Nlm_Boolean rsult;
1511
1512 rsult = FALSE;
1513 first = Nlm_GetFirstItem ((Nlm_IteM) c);
1514 num = Nlm_GetNumItems ((Nlm_ChoicE) c);
1515 if (currentItemNum >= first && currentItemNum < first + num) {
1516 Nlm_DeskAccProc ((Nlm_ChoicE) c);
1517 rsult = TRUE;
1518 }
1519 return rsult;
1520 }
1521 #endif
1522
1523 #ifdef WIN_MAC
Nlm_DrawWindowMenuBar(Nlm_GraphiC mb)1524 static void Nlm_DrawWindowMenuBar (Nlm_GraphiC mb)
1525
1526 {
1527 Nlm_MenU m;
1528 Nlm_RecT r;
1529 Nlm_WindowTool wptr;
1530 Rect bounds;
1531
1532 wptr = Nlm_ParentWindowPtr (mb);
1533 GetWindowPortBounds(wptr, &bounds);
1534 Nlm_RectToolToRecT (&bounds, &r);
1535 r.top = 19;
1536 r.bottom = 21;
1537 if (Nlm_RectInRgn (&r, Nlm_updateRgn)) {
1538 Nlm_MoveTo (0, 20);
1539 Nlm_LineTo (r.right, 20);
1540 }
1541 m = (Nlm_MenU) Nlm_GetChild (mb);
1542 while (m != NULL) {
1543 Nlm_DoDraw ((Nlm_GraphiC) m);
1544 m = (Nlm_MenU) Nlm_GetNext ((Nlm_GraphiC) m);
1545 }
1546 }
1547
Nlm_DrawDesktopMenu(Nlm_GraphiC m)1548 static void Nlm_DrawDesktopMenu (Nlm_GraphiC m)
1549
1550 {
1551 DrawMenuBar ();
1552 }
1553
Nlm_DrawWindowMenu(Nlm_GraphiC m)1554 static void Nlm_DrawWindowMenu (Nlm_GraphiC m)
1555
1556 {
1557 Nlm_PrompT p;
1558 Nlm_RecT r;
1559
1560 if (Nlm_GetVisible (m) && Nlm_GetAllParentsVisible (m)) {
1561 Nlm_GetRect (m, &r);
1562 if (Nlm_RectInRgn (&r, Nlm_updateRgn)) {
1563 p = Nlm_GetMenuPrompt ((Nlm_MenU) m);
1564 if (p != NULL) {
1565 Nlm_DoDraw ((Nlm_GraphiC) p);
1566 Nlm_SelectFont (Nlm_systemFont);
1567 }
1568 }
1569 }
1570 }
1571
Nlm_DrawPopup(Nlm_GraphiC m)1572 static void Nlm_DrawPopup (Nlm_GraphiC m)
1573
1574 {
1575 Nlm_PrompT p;
1576 Nlm_RecT r;
1577
1578 if (Nlm_GetVisible (m) && Nlm_GetAllParentsVisible (m)) {
1579 Nlm_GetRect (m, &r);
1580 if (Nlm_RectInRgn (&r, Nlm_updateRgn)) {
1581 p = Nlm_GetMenuPrompt ((Nlm_MenU) m);
1582 if (p != NULL) {
1583 Nlm_GetRect ((Nlm_GraphiC) p, &r);
1584 Nlm_InsetRect (&r, -1, -1);
1585 Nlm_FrameRect (&r);
1586 Nlm_OffsetRect (&r, 1, 1);
1587 Nlm_FrameRect (&r);
1588 Nlm_DoDraw ((Nlm_GraphiC) p);
1589 Nlm_SelectFont (Nlm_systemFont);
1590 }
1591 }
1592 }
1593 }
1594
Nlm_DrawPopList(Nlm_GraphiC m)1595 static void Nlm_DrawPopList (Nlm_GraphiC m)
1596
1597 {
1598 Nlm_ChoicE c;
1599 Nlm_RecT pr;
1600 Nlm_RecT r;
1601 Nlm_Char temp [256];
1602 Nlm_Int2 value;
1603
1604 if (Nlm_GetVisible (m) && Nlm_GetAllParentsVisible (m)) {
1605 Nlm_GetRect (m, &r);
1606 if (Nlm_RectInRgn (&r, Nlm_updateRgn)) {
1607 Nlm_SelectFont (Nlm_systemFont);
1608 Nlm_UpsetRect (&r, 1, 1, 2, 2);
1609 pr = r;
1610 Nlm_InsetRect (&r, -1, -1);
1611 Nlm_FrameRect (&r);
1612 Nlm_OffsetRect (&r, 1, 1);
1613 Nlm_FrameRect (&r);
1614 Nlm_EraseRect (&pr);
1615 c = (Nlm_ChoicE) Nlm_GetChild (m);
1616 if (c != NULL) {
1617 value = Nlm_DoGetValue ((Nlm_GraphiC) c);
1618 if (value > 0) {
1619 Nlm_DoGetTitle ((Nlm_GraphiC) c, value, temp, sizeof (temp));
1620 pr.left += 13;
1621 Nlm_DrawString (&pr, temp, 'l', FALSE);
1622 }
1623 }
1624 }
1625 }
1626 }
1627 #endif
1628
1629
Nlm_ShowWindowMenuBar(Nlm_GraphiC mb,Nlm_Boolean setFlag,Nlm_Boolean savePort)1630 static void Nlm_ShowWindowMenuBar (Nlm_GraphiC mb, Nlm_Boolean setFlag, Nlm_Boolean savePort)
1631
1632 {
1633 Nlm_WindoW tempPort;
1634 #ifdef WIN_MSWIN
1635 Nlm_WindowTool wptr;
1636 #endif
1637 #ifdef WIN_MOTIF
1638 Nlm_MenuTool h;
1639 #endif
1640
1641 tempPort = Nlm_SavePortIfNeeded (mb, savePort);
1642 Nlm_SetVisible (mb, TRUE);
1643 #ifdef WIN_MAC
1644 #ifdef WIN_MAC_QUARTZ
1645 Nlm_SetGraphicNeedsDisplay (mb);
1646 #else
1647 Nlm_DoDraw (mb);
1648 #endif
1649 #endif
1650 #ifdef WIN_MSWIN
1651 wptr = Nlm_ParentWindowPtr (mb);
1652 DrawMenuBar (wptr);
1653 #endif
1654 #ifdef WIN_MOTIF
1655 h = Nlm_GetMenuBarHandle ((Nlm_MenuBaR) mb);
1656 XtManageChild (h);
1657 #endif
1658
1659 Nlm_RestorePort (tempPort);
1660 }
1661
1662
1663 #ifdef WIN_MAC
Nlm_ShowDesktopMenu(Nlm_GraphiC m,Nlm_Boolean setFlag,Nlm_Boolean savePort)1664 static void Nlm_ShowDesktopMenu (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
1665
1666 {
1667 Nlm_MenuTool h;
1668 Nlm_WindoW tempPort;
1669
1670 tempPort = Nlm_SavePortIfNeeded (m, savePort);
1671 Nlm_SetVisible (m, TRUE);
1672 h = Nlm_GetMenuHandle ((Nlm_MenU) m);
1673 InsertMenu (h, 0);
1674 Nlm_ActivateInnerMenus ((Nlm_MenU) m);
1675 Nlm_DoDraw (m);
1676 Nlm_RestorePort (tempPort);
1677 }
1678 #endif
1679
Nlm_ShowPopup(Nlm_GraphiC m,Nlm_Boolean setFlag,Nlm_Boolean savePort)1680 static void Nlm_ShowPopup (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
1681
1682 {
1683 Nlm_PrompT p;
1684 Nlm_WindoW tempPort;
1685 #ifdef WIN_MSWIN
1686 Nlm_WindowTool wptr;
1687 #endif
1688
1689 if (setFlag) {
1690 Nlm_SetVisible (m, TRUE);
1691 }
1692 if (Nlm_GetVisible (m) && Nlm_AllParentsButWindowVisible (m)) {
1693 tempPort = Nlm_SavePortIfNeeded (m, savePort);
1694 p = Nlm_GetMenuPrompt ((Nlm_MenU) m);
1695 if (p != NULL) {
1696 Nlm_DoShow ((Nlm_GraphiC) p, TRUE, FALSE);
1697 }
1698 #ifdef WIN_MAC
1699 Nlm_DoDraw (m);
1700 #endif
1701 #ifdef WIN_MSWIN
1702 wptr = Nlm_ParentWindowPtr (m);
1703 DrawMenuBar (wptr);
1704 #endif
1705 #ifdef WIN_MOTIF
1706 #endif
1707 Nlm_RestorePort (tempPort);
1708 }
1709 }
1710
Nlm_ShowPopListMenu(Nlm_GraphiC m,Nlm_Boolean setFlag,Nlm_Boolean savePort)1711 static void Nlm_ShowPopListMenu (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
1712
1713 {
1714 Nlm_WindoW tempPort;
1715 #ifdef WIN_MSWIN
1716 Nlm_PopupTool u;
1717 #endif
1718 #ifdef WIN_MOTIF
1719 Nlm_PopupTool u;
1720 #endif
1721
1722 if (setFlag) {
1723 Nlm_SetVisible (m, TRUE);
1724 }
1725 if (Nlm_GetVisible (m) && Nlm_AllParentsButWindowVisible (m)) {
1726 tempPort = Nlm_SavePortIfNeeded (m, savePort);
1727 #ifdef WIN_MAC
1728 Nlm_DoDraw (m);
1729 #endif
1730 #ifdef WIN_MSWIN
1731 u = Nlm_GetMenuPopup ((Nlm_MenU) m);
1732 if (u != NULL) {
1733 ShowWindow (u, SW_SHOW);
1734 UpdateWindow (u);
1735 }
1736 #endif
1737 #ifdef WIN_MOTIF
1738 u = Nlm_GetMenuPopup ((Nlm_MenU) m);
1739 XtManageChild (u);
1740 #endif
1741 Nlm_RestorePort (tempPort);
1742 }
1743 }
1744
Nlm_ShowPopListChoice(Nlm_GraphiC c,Nlm_Boolean setFlag,Nlm_Boolean savePort)1745 static void Nlm_ShowPopListChoice (Nlm_GraphiC c, Nlm_Boolean setFlag, Nlm_Boolean savePort)
1746
1747 {
1748 Nlm_MenU m;
1749
1750 if (setFlag) {
1751 Nlm_SetVisible (c, TRUE);
1752 }
1753 m = (Nlm_MenU) Nlm_GetParent (c);
1754 Nlm_DoShow ((Nlm_GraphiC) m, setFlag, savePort);
1755 }
1756
1757 #ifdef WIN_MAC
Nlm_HideDesktopMenu(Nlm_GraphiC m,Nlm_Boolean setFlag,Nlm_Boolean savePort)1758 static void Nlm_HideDesktopMenu (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
1759
1760 {
1761 Nlm_Int2 tag;
1762 Nlm_WindoW tempPort;
1763
1764 tempPort = Nlm_SavePortIfNeeded (m, savePort);
1765 Nlm_SetVisible (m, FALSE);
1766 tag = Nlm_GetMenuTag ((Nlm_MenU) m);
1767 DeleteMenu (tag);
1768 Nlm_DeactivateInnerMenus ((Nlm_MenU) m);
1769 Nlm_DoDraw (m);
1770 Nlm_RestorePort (tempPort);
1771 }
1772 #endif
1773
Nlm_HidePulldown(Nlm_GraphiC m,Nlm_Boolean setFlag,Nlm_Boolean savePort)1774 static void Nlm_HidePulldown (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
1775
1776 {
1777 #ifdef WIN_MAC
1778 Nlm_RecT r;
1779 Nlm_WindoW tempPort;
1780
1781 tempPort = Nlm_SavePortIfNeeded (m, savePort);
1782 Nlm_SetVisible (m, FALSE);
1783 #ifndef WIN_MAC_QUARTZ
1784 Nlm_GetRect (m, &r);
1785 Nlm_EraseRect (&r);
1786 Nlm_ValidRect (&r);
1787 #endif
1788 Nlm_RestorePort (tempPort);
1789 #endif
1790 }
1791
Nlm_HidePopup(Nlm_GraphiC m,Nlm_Boolean setFlag,Nlm_Boolean savePort)1792 static void Nlm_HidePopup (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
1793
1794 {
1795 #ifdef WIN_MAC
1796 Nlm_RecT r;
1797 Nlm_WindoW tempPort;
1798
1799 if (setFlag) {
1800 Nlm_SetVisible (m, FALSE);
1801 }
1802 if (Nlm_GetAllParentsVisible (m)) {
1803 tempPort = Nlm_SavePortIfNeeded (m, savePort);
1804 Nlm_GetRect (m, &r);
1805 /*
1806 Nlm_InsetRect (&r, -2, -2);
1807 Nlm_OffsetRect (&r, 1, 1);
1808 */
1809 Nlm_InsetRect (&r, -1, -1);
1810 Nlm_EraseRect (&r);
1811 Nlm_ValidRect (&r);
1812 Nlm_RestorePort (tempPort);
1813 }
1814 #endif
1815 }
1816
Nlm_HidePopListMenu(Nlm_GraphiC m,Nlm_Boolean setFlag,Nlm_Boolean savePort)1817 static void Nlm_HidePopListMenu (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
1818
1819 {
1820 Nlm_WindoW tempPort;
1821 #ifdef WIN_MAC
1822 Nlm_RecT r;
1823 #endif
1824 #ifdef WIN_MSWIN
1825 Nlm_PopupTool u;
1826 #endif
1827 #ifdef WIN_MOTIF
1828 Nlm_PopupTool u;
1829 #endif
1830
1831 if (setFlag) {
1832 Nlm_SetVisible (m, FALSE);
1833 }
1834 tempPort = Nlm_SavePortIfNeeded (m, savePort);
1835 #ifdef WIN_MAC
1836 if (Nlm_GetAllParentsVisible (m)) {
1837 Nlm_GetRect (m, &r);
1838 /*
1839 Nlm_InsetRect (&r, -2, -2);
1840 Nlm_OffsetRect (&r, 1, 1);
1841 */
1842 Nlm_InsetRect (&r, -1, -1);
1843 Nlm_EraseRect (&r);
1844 Nlm_ValidRect (&r);
1845 }
1846 #endif
1847 #ifdef WIN_MSWIN
1848 u = Nlm_GetMenuPopup ((Nlm_MenU) m);
1849 if (u != NULL) {
1850 ShowWindow (u, SW_HIDE);
1851 UpdateWindow (u);
1852 }
1853 #endif
1854 #ifdef WIN_MOTIF
1855 u = Nlm_GetMenuPopup ((Nlm_MenU) m);
1856 XtUnmanageChild (u);
1857 #endif
1858 Nlm_RestorePort (tempPort);
1859 }
1860
1861
Nlm_HidePopListChoice(Nlm_GraphiC c,Nlm_Boolean setFlag,Nlm_Boolean savePort)1862 static void Nlm_HidePopListChoice(Nlm_GraphiC c, Nlm_Boolean setFlag,
1863 Nlm_Boolean savePort)
1864 {
1865 if ( setFlag )
1866 Nlm_SetVisible(c, FALSE);
1867
1868 Nlm_DoHide(Nlm_GetParent( c ), setFlag, savePort);
1869 }
1870
1871
1872 #ifdef WIN_MAC
Nlm_EnableDesktopMenu(Nlm_GraphiC m,Nlm_Boolean setFlag,Nlm_Boolean savePort)1873 static void Nlm_EnableDesktopMenu (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
1874
1875 {
1876 Nlm_MenuTool h;
1877 Nlm_WindoW tempPort;
1878
1879 tempPort = Nlm_SavePortIfNeeded (m, savePort);
1880 Nlm_SetEnabled (m, TRUE);
1881 h = Nlm_GetMenuHandle ((Nlm_MenU) m);
1882 EnableMenuItem (h, 0);
1883 if (Nlm_GetVisible (m)) {
1884 DrawMenuBar ();
1885 }
1886 Nlm_RestorePort (tempPort);
1887 }
1888 #endif
1889
1890
Nlm_EnablePulldown(Nlm_GraphiC m,Nlm_Boolean setFlag,Nlm_Boolean savePort)1891 static void Nlm_EnablePulldown (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
1892 {
1893 #ifdef WIN_MAC
1894 Nlm_MenuTool h;
1895 Nlm_PrompT p;
1896
1897 if (setFlag) {
1898 Nlm_SetEnabled (m, TRUE);
1899 }
1900 if (Nlm_GetEnabled (m) && Nlm_GetAllParentsEnabled (m)) {
1901 if (Nlm_GetVisible (m) && Nlm_GetAllParentsVisible (m)) {
1902 Nlm_WindoW tempPort = Nlm_SavePortIfNeeded (m, savePort);
1903 h = Nlm_GetMenuHandle ((Nlm_MenU) m);
1904 EnableMenuItem (h, 0);
1905 Nlm_DoDraw (m);
1906 p = Nlm_GetMenuPrompt ((Nlm_MenU) m);
1907 Nlm_DoEnable ((Nlm_GraphiC) p, TRUE, FALSE);
1908 Nlm_RestorePort (tempPort);
1909 }
1910 }
1911
1912 #else
1913
1914 if ( setFlag )
1915 Nlm_SetEnabled(m, TRUE);
1916
1917 if (Nlm_GetEnabled( m ) && Nlm_GetAllParentsEnabled( m ))
1918 {
1919 Nlm_WindoW tempPort = Nlm_SavePortIfNeeded (m, savePort);
1920 #ifdef WIN_MSWIN
1921 Nlm_GraphiC g = Nlm_GetChild( m );
1922 while (g != NULL) {
1923 Nlm_DoEnable(g, FALSE, FALSE);
1924 g = Nlm_GetNext( g );
1925 }
1926 DrawMenuBar( Nlm_ParentWindowPtr(m) );
1927 #endif
1928 #ifdef WIN_MOTIF
1929 Nlm_PopupTool u = Nlm_GetMenuPopup( (Nlm_MenU)m );
1930 if (u != NULL)
1931 XtVaSetValues(u, XmNsensitive, TRUE, NULL);
1932 #endif
1933 Nlm_RestorePort( tempPort );
1934 }
1935 #endif
1936 }
1937
1938
Nlm_EnablePopup(Nlm_GraphiC m,Nlm_Boolean setFlag,Nlm_Boolean savePort)1939 static void Nlm_EnablePopup (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
1940
1941 {
1942 #ifdef WIN_MAC
1943 Nlm_MenuTool h;
1944 Nlm_WindoW tempPort;
1945
1946 if (setFlag) {
1947 Nlm_SetEnabled (m, TRUE);
1948 }
1949 if (Nlm_GetEnabled (m) && Nlm_GetAllParentsEnabled (m)) {
1950 if (Nlm_GetVisible (m) && Nlm_GetAllParentsVisible (m)) {
1951 tempPort = Nlm_SavePortIfNeeded (m, savePort);
1952 h = Nlm_GetMenuHandle ((Nlm_MenU) m);
1953 EnableMenuItem (h, 0);
1954 Nlm_DoDraw (m);
1955 Nlm_RestorePort (tempPort);
1956 }
1957 }
1958 #endif
1959 }
1960
Nlm_EnablePopList(Nlm_GraphiC m,Nlm_Boolean setFlag,Nlm_Boolean savePort)1961 static void Nlm_EnablePopList (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
1962
1963 {
1964 Nlm_WindoW tempPort;
1965 #ifdef WIN_MAC
1966 Nlm_MenuTool h;
1967 #endif
1968 #ifdef WIN_MSWIN
1969 Nlm_PopupTool u;
1970 #endif
1971 #ifdef WIN_MOTIF
1972 Nlm_PopupTool c;
1973 #endif
1974
1975 if (setFlag) {
1976 Nlm_SetEnabled (m, TRUE);
1977 }
1978 if (Nlm_GetEnabled (m) && Nlm_GetAllParentsEnabled (m)) {
1979 tempPort = Nlm_SavePortIfNeeded (m, savePort);
1980 #ifdef WIN_MAC
1981 h = Nlm_GetMenuHandle ((Nlm_MenU) m);
1982 EnableMenuItem (h, 0);
1983 if (Nlm_GetVisible (m) && Nlm_GetAllParentsVisible (m)) {
1984 Nlm_DoDraw (m);
1985 }
1986 #endif
1987 #ifdef WIN_MSWIN
1988 u = Nlm_GetMenuPopup ((Nlm_MenU) m);
1989 if (u != NULL) {
1990 EnableWindow (u, TRUE);
1991 }
1992 #endif
1993 #ifdef WIN_MOTIF
1994 c = Nlm_GetMenuPopup ((Nlm_MenU) m);
1995 XtSetSensitive(XmOptionButtonGadget(c), TRUE);
1996 XtVaSetValues(c, XmNpopupEnabled, TRUE, NULL);
1997 #endif
1998 Nlm_RestorePort (tempPort);
1999 }
2000 }
2001
Nlm_EnableMenuItem(Nlm_GraphiC i,Nlm_Boolean setFlag,Nlm_Boolean savePort)2002 static void Nlm_EnableMenuItem (Nlm_GraphiC i, Nlm_Boolean setFlag, Nlm_Boolean savePort)
2003
2004 {
2005 Nlm_MenuTool h;
2006 Nlm_Int2 itm;
2007 Nlm_MenU m;
2008 Nlm_WindoW tempPort;
2009 #ifdef WIN_MSWIN
2010 Nlm_Int2 id;
2011 #endif
2012 #ifdef WIN_MOTIF
2013 Nlm_ItemTool itool;
2014 #endif
2015
2016 tempPort = Nlm_SavePortIfNeeded (i, savePort);
2017 Nlm_SetEnabled (i, TRUE);
2018 m = (Nlm_MenU) Nlm_GetParent (i);
2019 h = Nlm_GetMenuHandle (m);
2020 itm = Nlm_GetFirstItem ((Nlm_IteM) i);
2021 #ifdef WIN_MAC
2022 EnableMenuItem (h, itm);
2023 #endif
2024 #ifdef WIN_MSWIN
2025 id = Nlm_ItemToID (m, itm);
2026 EnableMenuItem (h, id, MF_ENABLED);
2027 #endif
2028 #ifdef WIN_MOTIF
2029 itool = Nlm_GetItemHandle ((Nlm_IteM) i);
2030 if ( !XtIsSensitive( itool ) )
2031 XtSetSensitive(itool, TRUE);
2032 #endif
2033 Nlm_RestorePort (tempPort);
2034 }
2035
2036
Nlm_EnableSubMenu(Nlm_GraphiC m,Nlm_Boolean setFlag,Nlm_Boolean savePort)2037 static void Nlm_EnableSubMenu (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
2038 {
2039 Nlm_WindoW tempPort = Nlm_SavePortIfNeeded(m, savePort);
2040 Nlm_IteM i = (Nlm_IteM)Nlm_GetParent( m );
2041
2042 Nlm_SetEnabled (m, TRUE);
2043
2044 if (i != NULL)
2045 {
2046 #ifdef WIN_MAC
2047 Nlm_MenuTool h;
2048 Nlm_EnableMenuItem ((Nlm_GraphiC) i, FALSE, FALSE);
2049 h = Nlm_GetMenuHandle ((Nlm_MenU) m);
2050 InsertMenu (h, -1);
2051 #endif
2052 #ifdef WIN_MSWIN
2053 Nlm_MenU prnt = (Nlm_MenU)Nlm_GetParent( (Nlm_GraphiC)i );
2054 Nlm_MenuTool prnt_h = Nlm_GetMenuHandle( prnt );
2055 Nlm_Int2 pos = Nlm_GetChildPosition( (Nlm_GraphiC)i );
2056 EnableMenuItem(prnt_h, pos-1, MF_BYPOSITION|MF_ENABLED);
2057 #endif
2058 #ifdef WIN_MOTIF
2059 Nlm_PopupTool pop = Nlm_GetMenuPopup ((Nlm_MenU) m);
2060 XtVaSetValues (pop, XmNsensitive, TRUE, NULL);
2061 #endif
2062 Nlm_ActivateInnerMenus ((Nlm_MenU) m);
2063 }
2064
2065 Nlm_RestorePort( tempPort );
2066 }
2067
2068
Nlm_EnableChoice(Nlm_GraphiC c,Nlm_Boolean setFlag,Nlm_Boolean savePort)2069 static void Nlm_EnableChoice (Nlm_GraphiC c, Nlm_Boolean setFlag, Nlm_Boolean savePort)
2070
2071 {
2072 Nlm_MenuTool h;
2073 Nlm_Int2 itm;
2074 Nlm_MenU m;
2075 Nlm_Int2 num;
2076 Nlm_WindoW tempPort;
2077 #ifdef WIN_MSWIN
2078 Nlm_Int2 id;
2079 #endif
2080 #ifdef WIN_MOTIF
2081 Nlm_ItemTool PNTR hdls;
2082 #endif
2083
2084 tempPort = Nlm_SavePortIfNeeded (c, savePort);
2085 Nlm_SetEnabled (c, TRUE);
2086 m = (Nlm_MenU) Nlm_GetParent (c);
2087 itm = Nlm_GetFirstItem ((Nlm_IteM) c);
2088 num = Nlm_GetNumItems ((Nlm_ChoicE) c);
2089 h = Nlm_GetMenuHandle (m);
2090 while (num > 0) {
2091 #ifdef WIN_MAC
2092 EnableMenuItem (h, itm);
2093 #endif
2094 #ifdef WIN_MSWIN
2095 if (! Nlm_IsItAPopupList ((Nlm_ChoicE) c)) {
2096 id = Nlm_ItemToID (m, itm);
2097 EnableMenuItem (h, id, MF_ENABLED);
2098 }
2099 #endif
2100 #ifdef WIN_MOTIF
2101 hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
2102 XtVaSetValues (hdls [num - 1], XmNsensitive, TRUE, NULL);
2103 #endif
2104 itm++;
2105 num--;
2106 }
2107 Nlm_RestorePort (tempPort);
2108 }
2109
2110
Nlm_EnablePopListChoice(Nlm_GraphiC c,Nlm_Boolean setFlag,Nlm_Boolean savePort)2111 static void Nlm_EnablePopListChoice(Nlm_GraphiC c, Nlm_Boolean setFlag,
2112 Nlm_Boolean savePort)
2113 {
2114 Nlm_EnableChoice(c, setFlag, savePort);
2115 Nlm_DoEnable(Nlm_GetParent(c), setFlag, savePort);
2116 }
2117
2118
Nlm_EnableChoiceGroup(Nlm_GraphiC c,Nlm_Boolean setFlag,Nlm_Boolean savePort)2119 static void Nlm_EnableChoiceGroup (Nlm_GraphiC c, Nlm_Boolean setFlag, Nlm_Boolean savePort)
2120
2121 {
2122 Nlm_MenuTool h;
2123 Nlm_Int2 itm;
2124 Nlm_MenU m;
2125 Nlm_Int2 num;
2126 Nlm_WindoW tempPort;
2127 #ifdef WIN_MSWIN
2128 Nlm_Int2 id;
2129 #endif
2130 #ifdef WIN_MOTIF
2131 Nlm_ItemTool PNTR hdls;
2132 #endif
2133
2134 tempPort = Nlm_SavePortIfNeeded (c, savePort);
2135 Nlm_SetEnabled (c, TRUE);
2136 m = (Nlm_MenU) Nlm_GetParent (c);
2137 itm = Nlm_GetFirstItem ((Nlm_IteM) c);
2138 num = Nlm_GetNumItems ((Nlm_ChoicE) c);
2139 h = Nlm_GetMenuHandle (m);
2140 while (num > 0) {
2141 #ifdef WIN_MAC
2142 EnableMenuItem (h, itm);
2143 #endif
2144 #ifdef WIN_MSWIN
2145 if (! Nlm_IsItAPopupList ((Nlm_ChoicE) c)) {
2146 id = Nlm_ItemToID (m, itm);
2147 EnableMenuItem (h, id, MF_ENABLED);
2148 }
2149 #endif
2150 #ifdef WIN_MOTIF
2151 hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
2152 XtVaSetValues (hdls [num - 1], XmNsensitive, TRUE, NULL);
2153 #endif
2154 itm++;
2155 num--;
2156 }
2157 Nlm_RestorePort (tempPort);
2158 }
2159
Nlm_EnableChoiceItem(Nlm_GraphiC i,Nlm_Boolean setFlag,Nlm_Boolean savePort)2160 static void Nlm_EnableChoiceItem (Nlm_GraphiC i, Nlm_Boolean setFlag, Nlm_Boolean savePort)
2161
2162 {
2163 Nlm_ChoicE c;
2164 Nlm_MenuTool h;
2165 Nlm_Int2 index;
2166 Nlm_Int2 itm;
2167 Nlm_MenU m;
2168 Nlm_WindoW tempPort;
2169 #ifdef WIN_MSWIN
2170 Nlm_Int2 id;
2171 #endif
2172 #ifdef WIN_MOTIF
2173 Nlm_ItemTool PNTR hdls;
2174 #endif
2175
2176 tempPort = Nlm_SavePortIfNeeded (i, savePort);
2177 Nlm_SetEnabled (i, TRUE);
2178 c = (Nlm_ChoicE) Nlm_GetParent (i);
2179 index = Nlm_GetFirstItem ((Nlm_IteM) i);
2180 if (index > 0 && index <= Nlm_GetNumItems ((Nlm_ChoicE) c)) {
2181 m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) c);
2182 h = Nlm_GetMenuHandle (m);
2183 itm = (Nlm_Int2)(Nlm_GetFirstItem( (Nlm_IteM)c ) + index - 1);
2184 #ifdef WIN_MAC
2185 EnableMenuItem (h, itm);
2186 #endif
2187 #ifdef WIN_MSWIN
2188 if (! Nlm_IsItAPopupList ((Nlm_ChoicE) c)) {
2189 id = Nlm_ItemToID (m, itm);
2190 EnableMenuItem (h, id, MF_ENABLED);
2191 }
2192 #endif
2193 #ifdef WIN_MOTIF
2194 hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
2195 XtVaSetValues (hdls [index - 1], XmNsensitive, TRUE, NULL);
2196 #endif
2197 }
2198 Nlm_RestorePort (tempPort);
2199 }
2200
2201 #ifdef WIN_MAC
Nlm_DisableDesktopMenu(Nlm_GraphiC m,Nlm_Boolean setFlag,Nlm_Boolean savePort)2202 static void Nlm_DisableDesktopMenu (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
2203
2204 {
2205 Nlm_MenuTool h;
2206 Nlm_WindoW tempPort;
2207
2208 tempPort = Nlm_SavePortIfNeeded (m, savePort);
2209 Nlm_SetEnabled (m, FALSE);
2210 h = Nlm_GetMenuHandle ((Nlm_MenU) m);
2211 DisableMenuItem (h, 0);
2212 if (Nlm_GetVisible (m)) {
2213 DrawMenuBar ();
2214 }
2215 Nlm_RestorePort (tempPort);
2216 }
2217 #endif
2218
Nlm_DisablePulldown(Nlm_GraphiC m,Nlm_Boolean setFlag,Nlm_Boolean savePort)2219 static void Nlm_DisablePulldown (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
2220
2221 {
2222 #ifdef WIN_MAC
2223 Nlm_MenuTool h;
2224 Nlm_PrompT p;
2225 Nlm_WindoW tempPort;
2226
2227 if (setFlag) {
2228 Nlm_SetEnabled (m, FALSE);
2229 }
2230 if (Nlm_GetVisible (m) && Nlm_GetAllParentsVisible (m)) {
2231 tempPort = Nlm_SavePortIfNeeded (m, savePort);
2232 h = Nlm_GetMenuHandle ((Nlm_MenU) m);
2233 DisableMenuItem (h, 0);
2234 Nlm_DoDraw (m);
2235 p = Nlm_GetMenuPrompt ((Nlm_MenU) m);
2236 Nlm_DoDisable ((Nlm_GraphiC) p, TRUE, FALSE);
2237 Nlm_RestorePort (tempPort);
2238 }
2239
2240 #else
2241
2242 if ( setFlag )
2243 Nlm_SetEnabled(m, FALSE);
2244
2245 if (Nlm_GetVisible (m) && Nlm_GetAllParentsVisible (m))
2246 {
2247 Nlm_WindoW tempPort = Nlm_SavePortIfNeeded (m, savePort);
2248 #ifdef WIN_MSWIN
2249 Nlm_GraphiC g = Nlm_GetChild (m);
2250 while (g != NULL) {
2251 Nlm_DoDisable (g, FALSE, FALSE);
2252 g = Nlm_GetNext (g);
2253 }
2254 DrawMenuBar( Nlm_ParentWindowPtr(m) );
2255 #endif
2256 #ifdef WIN_MOTIF
2257 Nlm_PopupTool u = Nlm_GetMenuPopup ((Nlm_MenU) m);
2258 if (u != NULL)
2259 XtVaSetValues (u, XmNsensitive, FALSE, NULL);
2260 #endif
2261 Nlm_RestorePort (tempPort);
2262 }
2263 #endif
2264 }
2265
Nlm_DisablePopup(Nlm_GraphiC m,Nlm_Boolean setFlag,Nlm_Boolean savePort)2266 static void Nlm_DisablePopup (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
2267
2268 {
2269 #ifdef WIN_MAC
2270 Nlm_MenuTool h;
2271 Nlm_WindoW tempPort;
2272
2273 if (setFlag) {
2274 Nlm_SetEnabled (m, FALSE);
2275 }
2276 if (Nlm_GetVisible (m) && Nlm_GetAllParentsVisible (m)) {
2277 tempPort = Nlm_SavePortIfNeeded (m, savePort);
2278 h = Nlm_GetMenuHandle ((Nlm_MenU) m);
2279 DisableMenuItem (h, 0);
2280 Nlm_DoDraw (m);
2281 Nlm_RestorePort (tempPort);
2282 }
2283 #endif
2284 }
2285
Nlm_DisablePopList(Nlm_GraphiC m,Nlm_Boolean setFlag,Nlm_Boolean savePort)2286 static void Nlm_DisablePopList (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
2287
2288 {
2289 Nlm_WindoW tempPort;
2290 #ifdef WIN_MAC
2291 Nlm_MenuTool h;
2292 #endif
2293 #ifdef WIN_MSWIN
2294 Nlm_PopupTool u;
2295 #endif
2296 #ifdef WIN_MOTIF
2297 Nlm_PopupTool c;
2298 #endif
2299
2300 if (setFlag) {
2301 Nlm_SetEnabled (m, FALSE);
2302 }
2303 tempPort = Nlm_SavePortIfNeeded (m, savePort);
2304 #ifdef WIN_MAC
2305 if (Nlm_GetVisible (m) && Nlm_GetAllParentsVisible (m)) {
2306 h = Nlm_GetMenuHandle ((Nlm_MenU) m);
2307 DisableMenuItem (h, 0);
2308 Nlm_DoDraw (m);
2309 }
2310 #endif
2311 #ifdef WIN_MSWIN
2312 u = Nlm_GetMenuPopup ((Nlm_MenU) m);
2313 if (u != NULL) {
2314 EnableWindow (u, FALSE);
2315 }
2316 #endif
2317 #ifdef WIN_MOTIF
2318 c = Nlm_GetMenuPopup ((Nlm_MenU) m);
2319 XtSetSensitive(XmOptionButtonGadget(c), FALSE);
2320 XtVaSetValues(c, XmNpopupEnabled, FALSE, NULL);
2321 #endif
2322 Nlm_RestorePort (tempPort);
2323 }
2324
Nlm_DisableMenuItem(Nlm_GraphiC i,Nlm_Boolean setFlag,Nlm_Boolean savePort)2325 static void Nlm_DisableMenuItem (Nlm_GraphiC i, Nlm_Boolean setFlag, Nlm_Boolean savePort)
2326
2327 {
2328 Nlm_MenuTool h;
2329 Nlm_Int2 itm;
2330 Nlm_MenU m;
2331 Nlm_WindoW tempPort;
2332 #ifdef WIN_MSWIN
2333 Nlm_Int2 id;
2334 #endif
2335 #ifdef WIN_MOTIF
2336 Nlm_ItemTool itool;
2337 #endif
2338
2339 tempPort = Nlm_SavePortIfNeeded (i, savePort);
2340 Nlm_SetEnabled (i, FALSE);
2341 m = (Nlm_MenU) Nlm_GetParent (i);
2342 h = Nlm_GetMenuHandle (m);
2343 itm = Nlm_GetFirstItem ((Nlm_IteM) i);
2344 #ifdef WIN_MAC
2345 DisableMenuItem (h, itm);
2346 #endif
2347 #ifdef WIN_MSWIN
2348 id = Nlm_ItemToID (m, itm);
2349 EnableMenuItem (h, id, MF_GRAYED);
2350 #endif
2351 #ifdef WIN_MOTIF
2352 itool = Nlm_GetItemHandle ((Nlm_IteM) i);
2353 XtVaSetValues (itool, XmNsensitive, FALSE, NULL);
2354 #endif
2355 Nlm_RestorePort (tempPort);
2356 }
2357
2358
Nlm_DisableSubMenu(Nlm_GraphiC m,Nlm_Boolean setFlag,Nlm_Boolean savePort)2359 static void Nlm_DisableSubMenu (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
2360 {
2361 Nlm_WindoW tempPort = Nlm_SavePortIfNeeded(m, savePort);
2362 Nlm_IteM i = (Nlm_IteM)Nlm_GetParent( m );
2363
2364 Nlm_SetEnabled(m, FALSE);
2365
2366 if (i != NULL)
2367 {
2368 #ifdef WIN_MAC
2369 Nlm_Int2 tag;
2370 Nlm_DisableMenuItem ((Nlm_GraphiC) i, FALSE, FALSE);
2371 tag = Nlm_GetMenuTag ((Nlm_MenU) m);
2372 DeleteMenu (tag);
2373 #endif
2374 #ifdef WIN_MSWIN
2375 Nlm_MenU prnt = (Nlm_MenU)Nlm_GetParent( (Nlm_GraphiC)i);
2376 Nlm_MenuTool prnt_h = Nlm_GetMenuHandle( prnt );
2377 Nlm_Int2 pos = Nlm_GetChildPosition( (Nlm_GraphiC)i );
2378 EnableMenuItem(prnt_h, pos-1, MF_BYPOSITION|MF_GRAYED);
2379 #endif
2380 #ifdef WIN_MOTIF
2381 Nlm_PopupTool pop;
2382 Nlm_DisableMenuItem ((Nlm_GraphiC) i, FALSE, FALSE);
2383 pop = Nlm_GetMenuPopup ((Nlm_MenU) m);
2384 XtVaSetValues (pop, XmNsensitive, FALSE, NULL);
2385 #endif
2386 Nlm_DeactivateInnerMenus ((Nlm_MenU) m);
2387 }
2388 Nlm_RestorePort( tempPort );
2389 }
2390
2391
Nlm_DisableChoice(Nlm_GraphiC c,Nlm_Boolean setFlag,Nlm_Boolean savePort)2392 static void Nlm_DisableChoice (Nlm_GraphiC c, Nlm_Boolean setFlag, Nlm_Boolean savePort)
2393
2394 {
2395 Nlm_MenuTool h;
2396 Nlm_Int2 itm;
2397 Nlm_MenU m;
2398 Nlm_Int2 num;
2399 Nlm_WindoW tempPort;
2400 #ifdef WIN_MSWIN
2401 Nlm_Int2 id;
2402 #endif
2403 #ifdef WIN_MOTIF
2404 Nlm_ItemTool PNTR hdls;
2405 #endif
2406
2407 tempPort = Nlm_SavePortIfNeeded (c, savePort);
2408 Nlm_SetEnabled (c, FALSE);
2409 m = (Nlm_MenU) Nlm_GetParent (c);
2410 itm = Nlm_GetFirstItem ((Nlm_IteM) c);
2411 num = Nlm_GetNumItems ((Nlm_ChoicE) c);
2412 h = Nlm_GetMenuHandle (m);
2413 while (num > 0) {
2414 #ifdef WIN_MAC
2415 DisableMenuItem (h, itm);
2416 #endif
2417 #ifdef WIN_MSWIN
2418 if (! Nlm_IsItAPopupList ((Nlm_ChoicE) c)) {
2419 id = Nlm_ItemToID (m, itm);
2420 EnableMenuItem (h, id, MF_GRAYED);
2421 }
2422 #endif
2423 #ifdef WIN_MOTIF
2424 hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
2425 XtVaSetValues (hdls [num - 1], XmNsensitive, FALSE, NULL);
2426 #endif
2427 itm++;
2428 num--;
2429 }
2430 Nlm_RestorePort (tempPort);
2431 }
2432
2433
Nlm_DisablePopListChoice(Nlm_GraphiC c,Nlm_Boolean setFlag,Nlm_Boolean savePort)2434 static void Nlm_DisablePopListChoice(Nlm_GraphiC c, Nlm_Boolean setFlag,
2435 Nlm_Boolean savePort)
2436 {
2437 Nlm_DisableChoice(c, setFlag, savePort);
2438 Nlm_DoDisable(Nlm_GetParent(c), setFlag, savePort);
2439 }
2440
2441 #ifdef NOT_USED_XXXXX
Nlm_DisableChoiceGroup(Nlm_GraphiC c,Nlm_Boolean setFlag,Nlm_Boolean savePort)2442 static void Nlm_DisableChoiceGroup (Nlm_GraphiC c, Nlm_Boolean setFlag, Nlm_Boolean savePort)
2443 {
2444 Nlm_MenuTool h;
2445 Nlm_Int2 itm;
2446 Nlm_MenU m;
2447 Nlm_Int2 num;
2448 Nlm_WindoW tempPort;
2449 #ifdef WIN_MSWIN
2450 Nlm_Int2 id;
2451 #endif
2452 #ifdef WIN_MOTIF
2453 Nlm_ItemTool PNTR hdls;
2454 #endif
2455
2456 tempPort = Nlm_SavePortIfNeeded (c, savePort);
2457 Nlm_SetEnabled (c, FALSE);
2458 m = (Nlm_MenU) Nlm_GetParent (c);
2459 itm = Nlm_GetFirstItem ((Nlm_IteM) c);
2460 num = Nlm_GetNumItems ((Nlm_ChoicE) c);
2461 h = Nlm_GetMenuHandle (m);
2462 while (num > 0) {
2463 #ifdef WIN_MAC
2464 DisableMenuItem (h, itm);
2465 #endif
2466 #ifdef WIN_MSWIN
2467 if (! Nlm_IsItAPopupList ((Nlm_ChoicE) c)) {
2468 id = Nlm_ItemToID (m, itm);
2469 EnableMenuItem (h, id, MF_GRAYED);
2470 }
2471 #endif
2472 #ifdef WIN_MOTIF
2473 hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
2474 XtVaSetValues (hdls [num - 1], XmNsensitive, FALSE, NULL);
2475 #endif
2476 itm++;
2477 num--;
2478 }
2479 Nlm_RestorePort (tempPort);
2480 }
2481 #endif /* NOT_USED_XXXXX */
2482
Nlm_DisableChoiceItem(Nlm_GraphiC i,Nlm_Boolean setFlag,Nlm_Boolean savePort)2483 static void Nlm_DisableChoiceItem (Nlm_GraphiC i, Nlm_Boolean setFlag, Nlm_Boolean savePort)
2484
2485 {
2486 Nlm_ChoicE c;
2487 Nlm_MenuTool h;
2488 Nlm_Int2 index;
2489 Nlm_Int2 itm;
2490 Nlm_MenU m;
2491 Nlm_WindoW tempPort;
2492 #ifdef WIN_MSWIN
2493 Nlm_Int2 id;
2494 #endif
2495 #ifdef WIN_MOTIF
2496 Nlm_ItemTool PNTR hdls;
2497 #endif
2498
2499 tempPort = Nlm_SavePortIfNeeded (i, savePort);
2500 Nlm_SetEnabled (i, FALSE);
2501 c = (Nlm_ChoicE) Nlm_GetParent (i);
2502 index = Nlm_GetFirstItem ((Nlm_IteM) i);
2503 if (index > 0 && index <= Nlm_GetNumItems ((Nlm_ChoicE) c)) {
2504 m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) c);
2505 h = Nlm_GetMenuHandle (m);
2506 itm = (Nlm_Int2)(Nlm_GetFirstItem( (Nlm_IteM)c ) + index - 1);
2507 #ifdef WIN_MAC
2508 DisableMenuItem (h, itm);
2509 #endif
2510 #ifdef WIN_MSWIN
2511 if (! Nlm_IsItAPopupList ((Nlm_ChoicE) c)) {
2512 id = Nlm_ItemToID (m, itm);
2513 EnableMenuItem (h, id, MF_GRAYED);
2514 }
2515 #endif
2516 #ifdef WIN_MOTIF
2517 hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
2518 XtVaSetValues (hdls [index - 1], XmNsensitive, FALSE, NULL);
2519 #endif
2520 }
2521 Nlm_RestorePort (tempPort);
2522 }
2523
2524 #ifdef WIN_MAC
Nlm_RemoveDesktopMenuBar(Nlm_GraphiC mb,Nlm_Boolean savePort)2525 static void Nlm_RemoveDesktopMenuBar (Nlm_GraphiC mb, Nlm_Boolean savePort)
2526
2527 /*
2528 * A submenu is linked into the desktop menu bar immediately after the menu
2529 * that contains it is created. Thus, removal of desktop menus cannot safely
2530 * get the next child in the list of menus right before removing a link, since
2531 * that next child, if a submenu, will immediately become a dangling pointer.
2532 * Removal of desktop menus must instead repeatedly remove the first child of
2533 * the desktop menu bar.
2534 */
2535
2536 {
2537 Nlm_MenU m;
2538 Nlm_WindoW tempPort;
2539
2540 tempPort = Nlm_SavePortIfNeeded (mb, savePort);
2541 m = (Nlm_MenU) Nlm_GetChild (mb);
2542 while (m != NULL) {
2543 Nlm_DeactivateInnerMenus (m);
2544 Nlm_DoRemove ((Nlm_GraphiC) m, FALSE);
2545 m = (Nlm_MenU) Nlm_GetChild (mb);
2546 }
2547 Nlm_HandFree (mb);
2548 recentMenuBar = NULL;
2549 Nlm_RestorePort (tempPort);
2550 }
2551 #endif
2552
Nlm_RemoveWindowMenuBar(Nlm_GraphiC mb,Nlm_Boolean savePort)2553 static void Nlm_RemoveWindowMenuBar (Nlm_GraphiC mb, Nlm_Boolean savePort)
2554
2555 {
2556 Nlm_MenU m;
2557 Nlm_MenU n;
2558 Nlm_WindoW tempPort;
2559 Nlm_WindoW w;
2560 #ifdef WIN_MSWIN
2561 Nlm_MenuTool h;
2562 #endif
2563 #ifdef WIN_MOTIF
2564 Nlm_MenuTool h;
2565 #endif
2566
2567 tempPort = Nlm_SavePortIfNeeded (mb, savePort);
2568 m = (Nlm_MenU) Nlm_GetChild (mb);
2569 while (m != NULL) {
2570 n = (Nlm_MenU) Nlm_GetNext ((Nlm_GraphiC) m);
2571 Nlm_DeactivateInnerMenus (m);
2572 m = n;
2573 }
2574 m = (Nlm_MenU) Nlm_GetChild (mb);
2575 while (m != NULL) {
2576 n = (Nlm_MenU) Nlm_GetNext ((Nlm_GraphiC) m);
2577 Nlm_DoRemove ((Nlm_GraphiC) m, FALSE);
2578 m = n;
2579 }
2580 w = Nlm_GetParentWindow ((Nlm_GraphiC) mb);
2581 Nlm_SetWindowMenuBar (w, NULL);
2582 #ifdef WIN_MSWIN
2583 h = Nlm_GetMenuBarHandle ((Nlm_MenuBaR) mb);
2584 DestroyMenu (h);
2585 #endif
2586 #ifdef WIN_MOTIF
2587 h = Nlm_GetMenuBarHandle ((Nlm_MenuBaR) mb);
2588 XtUnrealizeWidget(h);
2589 #ifndef NLM_MOTIF_CASCADEB_BUG
2590 XtDestroyWidget( h );
2591 #endif
2592 #endif
2593 Nlm_HandFree (mb);
2594 recentMenuBar = NULL;
2595 Nlm_RestorePort (tempPort);
2596 }
2597
2598 #ifdef WIN_MAC
Nlm_RemoveDesktopMenu(Nlm_GraphiC m,Nlm_Boolean savePort)2599 static void Nlm_RemoveDesktopMenu (Nlm_GraphiC m, Nlm_Boolean savePort)
2600
2601 {
2602 Nlm_IteM i;
2603 Nlm_MenuTool h;
2604 Nlm_IteM n;
2605 Nlm_WindoW tempPort;
2606
2607 tempPort = Nlm_SavePortIfNeeded (m, savePort);
2608 i = (Nlm_IteM) Nlm_GetChild (m);
2609 while (i != NULL) {
2610 n = (Nlm_IteM) Nlm_GetNext ((Nlm_GraphiC) i);
2611 Nlm_DoRemove ((Nlm_GraphiC) i, FALSE);
2612 i = n;
2613 }
2614 h = Nlm_GetMenuHandle ((Nlm_MenU) m);
2615 DisposeMenu (h);
2616 DrawMenuBar ();
2617 Nlm_RemoveLink (m);
2618 recentMenu = NULL;
2619 Nlm_RestorePort (tempPort);
2620 }
2621 #endif
2622
Nlm_RemoveSubMenu(Nlm_GraphiC m,Nlm_Boolean savePort)2623 static void Nlm_RemoveSubMenu (Nlm_GraphiC m, Nlm_Boolean savePort)
2624
2625 {
2626 Nlm_IteM i;
2627 Nlm_MenuTool h;
2628 Nlm_IteM n;
2629 Nlm_WindoW tempPort;
2630 #ifdef WIN_MAC
2631 Nlm_MenuBaR mb;
2632 #else
2633 Nlm_GraphicData gdata;
2634 #endif
2635
2636 tempPort = Nlm_SavePortIfNeeded (m, savePort);
2637 Nlm_DoDisable (m, TRUE, FALSE);
2638 i = (Nlm_IteM) Nlm_GetChild (m);
2639 while (i != NULL) {
2640 n = (Nlm_IteM) Nlm_GetNext ((Nlm_GraphiC) i);
2641 Nlm_DoRemove ((Nlm_GraphiC) i, FALSE);
2642 i = n;
2643 }
2644 h = Nlm_GetMenuHandle ((Nlm_MenU) m);
2645 #ifdef WIN_MAC
2646 DisposeMenu (h);
2647 #endif
2648 #ifdef WIN_MSWIN
2649 DestroyMenu (h);
2650 #endif
2651
2652 i = (Nlm_IteM) Nlm_GetParent (m);
2653 Nlm_SetSubMenu (i, NULL);
2654 #ifdef WIN_MAC
2655 mb = Nlm_GetWindowMenuBar (Nlm_desktopWindow);
2656 Nlm_SetParent (m, (Nlm_GraphiC) mb);
2657 Nlm_RemoveLink (m);
2658 #else
2659 Nlm_GetGraphicData (m, &gdata);
2660 if (gdata.data != NULL && gdata.cleanup != NULL) {
2661 gdata.cleanup (m, gdata.data);
2662 }
2663 Nlm_HandFree (m);
2664 #endif
2665 recentMenu = NULL;
2666 Nlm_RestorePort (tempPort);
2667 }
2668
Nlm_RemovePopupMenu(Nlm_GraphiC m,Nlm_Boolean savePort)2669 static void Nlm_RemovePopupMenu (Nlm_GraphiC m, Nlm_Boolean savePort)
2670
2671 {
2672 Nlm_IteM i;
2673 Nlm_IteM n;
2674 Nlm_PrompT p;
2675 Nlm_WindoW tempPort;
2676 #ifdef WIN_MAC
2677 Nlm_MenuTool h;
2678 #endif
2679 #ifdef WIN_MSWIN
2680 Nlm_PopupTool u;
2681 #endif
2682 #ifdef WIN_MOTIF
2683 Nlm_MenuTool h;
2684 Nlm_PopupTool pop;
2685 #endif
2686
2687 tempPort = Nlm_SavePortIfNeeded (m, savePort);
2688 i = (Nlm_IteM) Nlm_GetChild (m);
2689 while (i != NULL) {
2690 n = (Nlm_IteM) Nlm_GetNext ((Nlm_GraphiC) i);
2691 Nlm_DoRemove ((Nlm_GraphiC) i, FALSE);
2692 i = n;
2693 }
2694 #ifdef WIN_MAC
2695 h = Nlm_GetMenuHandle ((Nlm_MenU) m);
2696 DisposeMenu (h);
2697 #endif
2698 #ifdef WIN_MSWIN
2699 u = Nlm_GetMenuPopup ((Nlm_MenU) m);
2700 if (u != NULL) { /* Floating Popup [see NewFloatingPopup()] */
2701 ASSERT ( Nlm_GetMenuHandle( (Nlm_MenU)m ) == NULL );
2702 RemoveProp (u, (LPSTR) "Nlm_VibrantProp");
2703 DestroyWindow (u);
2704 }
2705 else { /* Pulldown [see NewPopup()] */
2706 Nlm_MenuBaR mb = (Nlm_MenuBaR)Nlm_GetParent( m );
2707 Nlm_MenuTool mbh = Nlm_GetMenuBarHandle( mb );
2708 Nlm_Int2 pos = Nlm_GetChildPosition( m );
2709 VERIFY ( DeleteMenu(mbh, pos-1, MF_BYPOSITION) );
2710 DrawMenuBar( Nlm_ParentWindowPtr((Nlm_GraphiC)mb) );
2711 }
2712 #endif
2713 #ifdef WIN_MOTIF
2714 h = Nlm_GetMenuHandle ((Nlm_MenU) m);
2715 if (h != NULL) {
2716 XtUnrealizeWidget(h);
2717 /*
2718 This code will, for some unknown reason, crash on the next
2719 update if you run a program from outside the window manager.
2720 */
2721 /*
2722 XtDestroyWidget (h);
2723 */
2724 }
2725 pop = Nlm_GetMenuPopup ((Nlm_MenU) m);
2726 if (pop != NULL) {
2727 #ifdef NLM_MOTIF_CASCADEB_BUG
2728 XtUnmanageChild( pop );
2729 #else
2730 XtDestroyWidget( pop );
2731 #endif
2732 }
2733 #endif
2734 p = Nlm_GetMenuPrompt ((Nlm_MenU) m);
2735 if (p != NULL) {
2736 Nlm_DoRemove ((Nlm_GraphiC) p, FALSE);
2737 }
2738 Nlm_RemoveLink (m);
2739 recentMenu = NULL;
2740 Nlm_RestorePort (tempPort);
2741 }
2742
Nlm_RemovePopListMenu(Nlm_GraphiC m,Nlm_Boolean savePort)2743 static void Nlm_RemovePopListMenu (Nlm_GraphiC m, Nlm_Boolean savePort)
2744
2745 {
2746 Nlm_IteM i;
2747 Nlm_IteM n;
2748 Nlm_PrompT p;
2749 Nlm_WindoW tempPort;
2750 #ifdef WIN_MAC
2751 Nlm_MenuTool h;
2752 #endif
2753 #ifdef WIN_MSWIN
2754 Nlm_PopupTool u;
2755 #endif
2756
2757 tempPort = Nlm_SavePortIfNeeded (m, savePort);
2758 i = (Nlm_IteM) Nlm_GetChild (m);
2759 while (i != NULL) {
2760 n = (Nlm_IteM) Nlm_GetNext ((Nlm_GraphiC) i);
2761 Nlm_DoRemove ((Nlm_GraphiC) i, FALSE);
2762 i = n;
2763 }
2764 #ifdef WIN_MAC
2765 h = Nlm_GetMenuHandle ((Nlm_MenU) m);
2766 DisposeMenu (h);
2767 #endif
2768 #ifdef WIN_MSWIN
2769 u = Nlm_GetMenuPopup ((Nlm_MenU) m);
2770 if (u != NULL) {
2771 RemoveProp (u, (LPSTR) "Nlm_VibrantProp");
2772 DestroyWindow (u);
2773 }
2774 #endif
2775 #ifdef WIN_MOTIF
2776 #endif
2777 p = Nlm_GetMenuPrompt ((Nlm_MenU) m);
2778 if (p != NULL) {
2779 Nlm_DoRemove ((Nlm_GraphiC) p, FALSE);
2780 }
2781 Nlm_RemoveLink (m);
2782 recentMenu = NULL;
2783 Nlm_RestorePort (tempPort);
2784 }
2785
2786
2787 #ifdef WIN_MOTIF
MenuShellColormapCB(Widget w,XtPointer client_data,XEvent * event,Boolean * cont)2788 static void MenuShellColormapCB(Widget w, XtPointer client_data,
2789 XEvent *event, Boolean *cont)
2790 {
2791 Colormap cMap;
2792 if ( !Nlm_GetFixedColormap((Nlm_GraphiC)(client_data), &cMap, NULL) )
2793 return;
2794
2795 if (event->type == ColormapNotify &&
2796 event->xcolormap.state == ColormapUninstalled &&
2797 event->xcolormap.colormap != None &&
2798 w != NULL && XtIsManaged(w) &&
2799 event->xcolormap.window == XtWindow(w))
2800 XInstallColormap(Nlm_currentXDisplay, cMap);
2801 }
2802 #endif
2803
2804
Nlm_RemovePopupList(Nlm_GraphiC c,Nlm_Boolean savePort)2805 static void Nlm_RemovePopupList (Nlm_GraphiC c, Nlm_Boolean savePort)
2806 /*
2807 * If the user calls Remove (c) to remove the popup list, then
2808 * savePort will be TRUE, and the implicitly created parent menu
2809 * is also removed. If the user calls Remove (w) to remove the
2810 * parent window, then RemovePopupList will be called by the
2811 * implicitly created parent menu just prior to its removal, and
2812 * an additional attempt to remove the menu is both unnecessary
2813 * and dangerous.
2814 */
2815 {
2816 Nlm_WindoW tempPort = Nlm_SavePortIfNeeded(c, savePort);
2817 Nlm_MenU m = (Nlm_MenU)Nlm_GetParent( c );
2818
2819 #ifdef WIN_MOTIF
2820 Nlm_ItemTool PNTR hdls;
2821 XtRemoveEventHandler(Nlm_GetMenuHandle( m ), ColormapChangeMask, FALSE,
2822 MenuShellColormapCB, (XtPointer)m);
2823 hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
2824 if (hdls != NULL) {
2825 Nlm_MemFree (hdls);
2826 }
2827 #endif
2828 Nlm_RemoveLink (c);
2829 recentItem = NULL;
2830 recentChoice = NULL;
2831 if (savePort) {
2832 Nlm_DoRemove ((Nlm_GraphiC) m, FALSE);
2833 }
2834 Nlm_RestorePort (tempPort);
2835 }
2836
Nlm_RemoveMenuItem(Nlm_GraphiC i,Nlm_Boolean savePort)2837 static void Nlm_RemoveMenuItem (Nlm_GraphiC i, Nlm_Boolean savePort)
2838
2839 {
2840 Nlm_MenU sub;
2841 Nlm_WindoW tempPort;
2842
2843 tempPort = Nlm_SavePortIfNeeded (i, savePort);
2844 sub = Nlm_GetSubMenu ((Nlm_IteM) i);
2845 if (sub != NULL) {
2846 Nlm_DoRemove ((Nlm_GraphiC) sub, FALSE);
2847 }
2848 Nlm_RemoveLink (i);
2849 recentItem = NULL;
2850 recentChoice = NULL;
2851 Nlm_RestorePort (tempPort);
2852 }
2853
2854 #ifdef WIN_MAC
Nlm_RemoveMenuItemButNotSub(Nlm_GraphiC i,Nlm_Boolean savePort)2855 static void Nlm_RemoveMenuItemButNotSub (Nlm_GraphiC i, Nlm_Boolean savePort)
2856
2857 {
2858 Nlm_MenU sub;
2859 Nlm_WindoW tempPort;
2860
2861 tempPort = Nlm_SavePortIfNeeded (i, savePort);
2862 sub = Nlm_GetSubMenu ((Nlm_IteM) i);
2863 if (sub != NULL) {
2864 Nlm_SetSubMenu ((Nlm_IteM) i, NULL);
2865 /*Nlm_SetParent ((Nlm_GraphiC) sub, NULL);*/
2866 Nlm_DoRemove ((Nlm_GraphiC) sub, FALSE);
2867 }
2868 Nlm_RemoveLink (i);
2869 recentItem = NULL;
2870 recentChoice = NULL;
2871 Nlm_RestorePort (tempPort);
2872 }
2873 #endif
2874
Nlm_RemoveChoiceGroup(Nlm_GraphiC c,Nlm_Boolean savePort)2875 static void Nlm_RemoveChoiceGroup (Nlm_GraphiC c, Nlm_Boolean savePort)
2876
2877 {
2878 Nlm_IteM i;
2879 Nlm_IteM n;
2880 Nlm_MenU sub;
2881 Nlm_WindoW tempPort;
2882 #ifdef WIN_MOTIF
2883 Nlm_ItemTool PNTR hdls;
2884 #endif
2885
2886 tempPort = Nlm_SavePortIfNeeded (c, savePort);
2887 sub = Nlm_GetSubMenu ((Nlm_IteM) c);
2888 if (sub != NULL) {
2889 Nlm_DoRemove ((Nlm_GraphiC) sub, FALSE);
2890 }
2891 #ifdef WIN_MOTIF
2892 hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
2893 if (hdls != NULL) {
2894 Nlm_Int2 item = Nlm_GetNumItems( (Nlm_ChoicE)c );
2895 ASSERT ( item >= 0 );
2896 while ( item-- ) {
2897 if ( hdls[item] ) {
2898 #ifdef NLM_MOTIF_CASCADEB_BUG
2899 if ( XmIsCascadeButton( hdls[item] ) )
2900 XtUnmanageChild( hdls[item] );
2901 else
2902 #endif
2903 XtDestroyWidget( hdls[item] );
2904 }
2905 }
2906 Nlm_MemFree( hdls );
2907 }
2908 #endif
2909 i = (Nlm_IteM) Nlm_GetChild (c);
2910 while (i != NULL) {
2911 n = (Nlm_IteM) Nlm_GetNext ((Nlm_GraphiC) i);
2912 Nlm_DoRemove ((Nlm_GraphiC) i, FALSE);
2913 i = n;
2914 }
2915 Nlm_RemoveLink (c);
2916 recentItem = NULL;
2917 recentChoice = NULL;
2918 Nlm_RestorePort (tempPort);
2919 }
2920
Nlm_RemoveChoiceItem(Nlm_GraphiC i,Nlm_Boolean savePort)2921 static void Nlm_RemoveChoiceItem (Nlm_GraphiC i, Nlm_Boolean savePort)
2922
2923 {
2924 Nlm_WindoW tempPort;
2925
2926 tempPort = Nlm_SavePortIfNeeded (i, savePort);
2927 Nlm_RemoveLink (i);
2928 recentItem = NULL;
2929 recentChoice = NULL;
2930 Nlm_RestorePort (tempPort);
2931 }
2932
2933
Nlm_ResetMenu(Nlm_GraphiC m,Nlm_Boolean savePort)2934 static void Nlm_ResetMenu (Nlm_GraphiC m, Nlm_Boolean savePort)
2935 {
2936 Nlm_MenuTool h = Nlm_GetMenuHandle( (Nlm_MenU)m );
2937 Nlm_WindoW tempPort = Nlm_SavePortIfNeeded(m, savePort);
2938
2939 {{ /* reset the Vibrant menu structure */
2940 Nlm_GraphiC item = Nlm_GetChild( m );
2941 while ( item ) {
2942 Nlm_GraphiC next_item = Nlm_GetNext( item );
2943 Nlm_DoRemove(item, FALSE);
2944 item = next_item;
2945 }
2946 }}
2947
2948 {{ /* reset platform-dependent menu structures */
2949 #if defined(WIN_MAC)
2950 Nlm_Int2 cnt = CountMenuItems( h );
2951 while (cnt-- > 0)
2952 DeleteMenuItem(h, cnt);
2953 #elif defined(WIN_MSWIN)
2954 Nlm_WindowTool wptr = Nlm_ParentWindowPtr( m );
2955 int cnt = GetMenuItemCount( h );
2956 while (cnt-- > 0)
2957 DeleteMenu(h, cnt, MF_BYPOSITION);
2958 DrawMenuBar( wptr );
2959 #elif defined(WIN_MOTIF)
2960 Cardinal cnt;
2961 WidgetList children;
2962 XtVaGetValues(h, XtNnumChildren, &cnt, XtNchildren, &children, NULL);
2963 if ( children ) {
2964 while (cnt-- > 0) {
2965 ASSERT ( children[cnt] );
2966 #ifdef NLM_MOTIF_CASCADEB_BUG
2967 if ( XmIsCascadeButton( children[cnt] ) )
2968 XtUnmanageChild( children[cnt] );
2969 else
2970 #endif
2971 XtDestroyWidget( children[cnt] );
2972 }
2973 }
2974 #endif
2975 }}
2976
2977 Nlm_RestorePort( tempPort );
2978 }
2979
2980
2981 #ifndef WIN_MOTIF
Nlm_ResetPopList(Nlm_GraphiC c,Nlm_Boolean savePort)2982 static void Nlm_ResetPopList (Nlm_GraphiC c, Nlm_Boolean savePort)
2983
2984 {
2985 Nlm_Int2 hbounds;
2986 Nlm_MenU m;
2987 Nlm_RecT r;
2988 Nlm_WindoW tempPort;
2989 #ifdef WIN_MAC
2990 Nlm_Int2 cnt;
2991 Nlm_MenuTool h;
2992 #endif
2993 #ifdef WIN_MSWIN
2994 Nlm_PopupTool u;
2995 #endif
2996
2997 tempPort = Nlm_SavePortIfNeeded (c, savePort);
2998 m = (Nlm_MenU) Nlm_GetParent (c);
2999 #ifdef WIN_MAC
3000 h = Nlm_GetMenuHandle (m);
3001 cnt = CountMenuItems (h);
3002 while (cnt > 0) {
3003 DeleteMenuItem (h, cnt);
3004 cnt--;
3005 }
3006 #endif
3007 #ifdef WIN_MSWIN
3008 u = Nlm_GetMenuPopup (m);
3009 if (u != NULL) {
3010 ComboBox_ResetContent (u);
3011 }
3012 #endif
3013 Nlm_LoadItemData ((Nlm_IteM) c, NULL, 1, NULL);
3014 Nlm_LoadChoiceData ((Nlm_ChoicE) c, 0, TRUE, 0, NULL);
3015 #ifdef WIN_MAC
3016 hbounds = 13;
3017 #endif
3018 #ifdef WIN_MSWIN
3019 hbounds = 13;
3020 #endif
3021 Nlm_GetRect ((Nlm_GraphiC) m, &r);
3022 r.right = (Nlm_Int2)(r.left + hbounds * 2);
3023 r.bottom = (Nlm_Int2)(r.top + Nlm_popupMenuHeight);
3024 Nlm_DoSetPosition ((Nlm_GraphiC) c, &r, FALSE, FALSE);
3025 Nlm_RestorePort (tempPort);
3026 }
3027 #endif
3028
3029
3030 #ifdef WIN_MOTIF
Nlm_ResetPopList(Nlm_GraphiC c,Nlm_Boolean savePort)3031 static void Nlm_ResetPopList (Nlm_GraphiC c, Nlm_Boolean savePort)
3032 {
3033 Nlm_ItemTool *hdls = Nlm_GetChoiceHandles( (Nlm_ChoicE)c );
3034 Nlm_MenU m = (Nlm_MenU)Nlm_GetParent( c );
3035 Nlm_PopupTool pop = Nlm_GetMenuPopup( m );
3036 Nlm_Int2 i;
3037
3038 Nlm_DoSetValue(c, 0, FALSE);
3039 for (i = 0; i < 63; i++)
3040 {
3041 if (hdls[i] != NULL)
3042 {
3043 XtDestroyWidget( hdls[i] );
3044 hdls[i] = NULL;
3045 }
3046 }
3047
3048 Nlm_LoadItemData((Nlm_IteM)c, m, 1, pop);
3049 Nlm_LoadChoiceData((Nlm_ChoicE)c, 0, TRUE, 0, hdls);
3050 }
3051 #endif
3052
Nlm_CountMenuItems(Nlm_GraphiC m)3053 static Nlm_Int2 Nlm_CountMenuItems (Nlm_GraphiC m)
3054
3055 {
3056 Nlm_MenuTool h;
3057 Nlm_Int2 rsult;
3058
3059 rsult = 0;
3060 h = Nlm_GetMenuHandle ((Nlm_MenU) m);
3061 #ifdef WIN_MAC
3062 rsult = CountMenuItems (h);
3063 #endif
3064 #ifdef WIN_MSWIN
3065 rsult = (Nlm_Int2)GetMenuItemCount( h );
3066 #endif
3067 #ifdef WIN_MOTIF
3068 #endif
3069 return rsult;
3070 }
3071
Nlm_CountChoiceItems(Nlm_GraphiC c)3072 static Nlm_Int2 Nlm_CountChoiceItems (Nlm_GraphiC c)
3073
3074 {
3075 return (Nlm_GetNumItems ((Nlm_ChoicE) c));
3076 }
3077
Nlm_SetMenuItem(Nlm_MenU m,Nlm_ItemTool itool,Nlm_Int2 item,Nlm_CharPtr itemName)3078 static void Nlm_SetMenuItem (Nlm_MenU m, Nlm_ItemTool itool,
3079 Nlm_Int2 item, Nlm_CharPtr itemName)
3080
3081 {
3082 #ifdef WIN_MAC
3083 Nlm_MenuTool h;
3084 Nlm_Char temp [256];
3085
3086 h = Nlm_GetMenuHandle ((Nlm_MenU) m);
3087 if (item > 0) {
3088 if (Nlm_StringLen (itemName) == 0) {
3089 temp [0] = '(';
3090 temp [1] = '\0';
3091 Nlm_CtoPstr (temp);
3092 SetMenuItemText (h, item, (StringPtr) temp);
3093 } else {
3094 Nlm_StringNCpy_0(temp, itemName, sizeof(temp));
3095 Nlm_CtoPstr (temp);
3096 SetMenuItemText (h, item, (StringPtr) temp);
3097 }
3098 }
3099 #endif
3100 #ifdef WIN_MSWIN
3101 Nlm_MenuTool h;
3102 Nlm_Int2 id;
3103 Nlm_Char temp [256];
3104 Nlm_WindowTool wptr;
3105
3106 h = Nlm_GetMenuHandle ((Nlm_MenU) m);
3107 id = Nlm_ItemToID ((Nlm_MenU) m, item);
3108 Nlm_StringNCpy_0(temp, itemName, sizeof(temp));
3109 ModifyMenu (h, id, /*MF_CHANGE |*/ MF_BYCOMMAND | MF_STRING, item, temp);
3110 wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) m);
3111 DrawMenuBar (wptr);
3112 #endif
3113 #ifdef WIN_MOTIF
3114 XmString label;
3115 Nlm_Char temp [256];
3116
3117 if (itool != NULL) {
3118 Nlm_StringNCpy_0(temp, itemName, sizeof(temp));
3119 label = XmStringCreateSimple (temp);
3120 XtVaSetValues (itool, XmNlabelString, label, NULL);
3121 XmStringFree (label);
3122 }
3123 #endif
3124 }
3125
Nlm_SetSingleTitle(Nlm_GraphiC i,Nlm_Int2 item,Nlm_CharPtr title,Nlm_Boolean savePort)3126 static void Nlm_SetSingleTitle (Nlm_GraphiC i, Nlm_Int2 item,
3127 Nlm_CharPtr title, Nlm_Boolean savePort)
3128
3129 {
3130 Nlm_Int2 itm;
3131 Nlm_ItemTool itool;
3132 Nlm_MenU m;
3133 Nlm_WindoW tempPort;
3134
3135 tempPort = Nlm_SavePortIfNeeded (i, savePort);
3136 m = (Nlm_MenU) Nlm_GetParent (i);
3137 itm = Nlm_GetFirstItem ((Nlm_IteM) i);
3138 itool = Nlm_GetItemHandle ((Nlm_IteM) i);
3139 Nlm_SetMenuItem (m, itool, itm, title);
3140 Nlm_RestorePort (tempPort);
3141 }
3142
Nlm_SetChoiceTitle(Nlm_GraphiC c,Nlm_Int2 item,Nlm_CharPtr title,Nlm_Boolean savePort)3143 static void Nlm_SetChoiceTitle (Nlm_GraphiC c, Nlm_Int2 item,
3144 Nlm_CharPtr title, Nlm_Boolean savePort)
3145
3146 {
3147 Nlm_Int2 first;
3148 Nlm_ItemTool itool;
3149 Nlm_MenU m;
3150 Nlm_Int2 num;
3151 Nlm_PrompT p;
3152 Nlm_WindoW tempPort;
3153
3154 tempPort = Nlm_SavePortIfNeeded (c, savePort);
3155 first = Nlm_GetFirstItem ((Nlm_IteM) c);
3156 num = Nlm_GetNumItems ((Nlm_ChoicE) c);
3157 m = (Nlm_MenU) Nlm_GetParent (c);
3158 itool = NULL;
3159 if (item > 0 && item <= num) {
3160 Nlm_SetMenuItem (m, itool, (Nlm_Int2)(first + item - 1), title);
3161 } else if (item == 0) {
3162 p = Nlm_GetMenuPrompt (m);
3163 if (p != NULL) {
3164 Nlm_DoSetTitle ((Nlm_GraphiC) p, 0, title, FALSE);
3165 }
3166 }
3167 Nlm_RestorePort (tempPort);
3168 }
3169
Nlm_SetChoiceGroupTitle(Nlm_GraphiC c,Nlm_Int2 item,Nlm_CharPtr title,Nlm_Boolean savePort)3170 static void Nlm_SetChoiceGroupTitle (Nlm_GraphiC c, Nlm_Int2 item,
3171 Nlm_CharPtr title, Nlm_Boolean savePort)
3172
3173 {
3174 Nlm_MenU m;
3175 Nlm_PrompT p;
3176 Nlm_WindoW tempPort;
3177
3178 tempPort = Nlm_SavePortIfNeeded (c, savePort);
3179 m = (Nlm_MenU) Nlm_GetParent (c);
3180 p = Nlm_GetMenuPrompt (m);
3181 if (p != NULL) {
3182 Nlm_DoSetTitle ((Nlm_GraphiC) p, 0, title, FALSE);
3183 }
3184 Nlm_RestorePort (tempPort);
3185 }
3186
Nlm_SetChoiceItemTitle(Nlm_GraphiC i,Nlm_Int2 item,Nlm_CharPtr title,Nlm_Boolean savePort)3187 static void Nlm_SetChoiceItemTitle (Nlm_GraphiC i, Nlm_Int2 item,
3188 Nlm_CharPtr title, Nlm_Boolean savePort)
3189
3190 {
3191 Nlm_ChoicE c;
3192 Nlm_Int2 first;
3193 Nlm_Int2 index;
3194 Nlm_ItemTool itool;
3195 Nlm_MenU m;
3196 Nlm_WindoW tempPort;
3197
3198 tempPort = Nlm_SavePortIfNeeded (i, savePort);
3199 c = (Nlm_ChoicE) Nlm_GetParent (i);
3200 index = Nlm_GetFirstItem ((Nlm_IteM) i);
3201 first = Nlm_GetFirstItem ((Nlm_IteM) c);
3202 m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) c);
3203 itool = NULL;
3204 Nlm_SetMenuItem (m, itool, (Nlm_Int2)(first + index - 1), title);
3205 Nlm_RestorePort (tempPort);
3206 }
3207
Nlm_SetPopListTitle(Nlm_GraphiC c,Nlm_Int2 item,Nlm_CharPtr title,Nlm_Boolean savePort)3208 static void Nlm_SetPopListTitle (Nlm_GraphiC c, Nlm_Int2 item,
3209 Nlm_CharPtr title, Nlm_Boolean savePort)
3210
3211 {
3212 #ifdef WIN_MAC
3213 Nlm_SetChoiceTitle (c, item, title, savePort);
3214 #endif
3215 }
3216
Nlm_SetSubmenuTitle(Nlm_GraphiC m,Nlm_Int2 item,Nlm_CharPtr title,Nlm_Boolean savePort)3217 static void Nlm_SetSubmenuTitle (Nlm_GraphiC m, Nlm_Int2 item,
3218 Nlm_CharPtr title, Nlm_Boolean savePort)
3219
3220 {
3221 #ifdef WIN_MAC
3222 Nlm_IteM i;
3223 Nlm_WindoW tempPort;
3224
3225 tempPort = Nlm_SavePortIfNeeded (m, savePort);
3226 i = (Nlm_IteM) Nlm_GetParent (m);
3227 if (i != NULL) {
3228 Nlm_SetSingleTitle ((Nlm_GraphiC) i, item, title, FALSE);
3229 }
3230 Nlm_RestorePort (tempPort);
3231 #endif
3232 }
3233
Nlm_GetMenuItem(Nlm_GraphiC m,Nlm_ItemTool itool,Nlm_Int2 item,Nlm_CharPtr itemName,size_t maxsize)3234 static void Nlm_GetMenuItem (Nlm_GraphiC m, Nlm_ItemTool itool,
3235 Nlm_Int2 item, Nlm_CharPtr itemName,
3236 size_t maxsize)
3237
3238 {
3239 Nlm_MenuTool h;
3240 Nlm_Char temp [256];
3241 #ifdef WIN_MSWIN
3242 Nlm_Int2 id;
3243 #endif
3244 #ifdef WIN_MOTIF
3245 XmString label;
3246 char *text;
3247 #endif
3248
3249 h = Nlm_GetMenuHandle ((Nlm_MenU) m);
3250 temp [0] = '\0';
3251 if (item > 0) {
3252 #ifdef WIN_MAC
3253 GetMenuItemText (h, item, (StringPtr) temp);
3254 Nlm_PtoCstr (temp);
3255 #endif
3256 #ifdef WIN_MSWIN
3257 id = Nlm_ItemToID ((Nlm_MenU) m, item);
3258 GetMenuString (h, id, temp, sizeof (temp), MF_BYCOMMAND);
3259 #endif
3260 #ifdef WIN_MOTIF
3261 if (itool != NULL) {
3262 XtVaGetValues (itool, XmNlabelString, &label, NULL);
3263 if (XmStringGetLtoR (label, XmSTRING_DEFAULT_CHARSET, &text)) {
3264 Nlm_StringNCpy_0(temp, text, sizeof(temp));
3265 XtFree (text);
3266 }
3267 }
3268 #endif
3269 }
3270 Nlm_StringNCpy_0(itemName, temp, maxsize);
3271 }
3272
Nlm_GetSingleTitle(Nlm_GraphiC i,Nlm_Int2 item,Nlm_CharPtr title,size_t maxsize)3273 static void Nlm_GetSingleTitle (Nlm_GraphiC i, Nlm_Int2 item,
3274 Nlm_CharPtr title, size_t maxsize)
3275
3276 {
3277 Nlm_Int2 itm;
3278 Nlm_ItemTool itool;
3279 Nlm_MenU m;
3280
3281 m = (Nlm_MenU) Nlm_GetParent (i);
3282 itm = Nlm_GetFirstItem ((Nlm_IteM) i);
3283 itool = Nlm_GetItemHandle ((Nlm_IteM) i);
3284 Nlm_GetMenuItem ((Nlm_GraphiC) m, itool, itm, title, maxsize);
3285 }
3286
Nlm_GetChoiceTitle(Nlm_GraphiC c,Nlm_Int2 item,Nlm_CharPtr title,size_t maxsize)3287 extern void Nlm_GetChoiceTitle (Nlm_GraphiC c, Nlm_Int2 item,
3288 Nlm_CharPtr title, size_t maxsize)
3289
3290 {
3291 Nlm_Int2 first;
3292 Nlm_ItemTool itool;
3293 Nlm_MenU m;
3294 Nlm_Int2 num;
3295 Nlm_PrompT p;
3296
3297 first = Nlm_GetFirstItem ((Nlm_IteM) c);
3298 num = Nlm_GetNumItems ((Nlm_ChoicE) c);
3299 m = (Nlm_MenU) Nlm_GetParent (c);
3300 itool = NULL;
3301 if (item > 0 && item <= num) {
3302 Nlm_GetMenuItem ((Nlm_GraphiC) m, itool, (Nlm_Int2)(first + item - 1),
3303 title, maxsize);
3304 } else if (item == 0) {
3305 p = Nlm_GetMenuPrompt (m);
3306 if (p != NULL) {
3307 Nlm_DoGetTitle ((Nlm_GraphiC) p, 0, title, maxsize);
3308 }
3309 }
3310 }
3311
Nlm_GetChoiceGroupTitle(Nlm_GraphiC c,Nlm_Int2 item,Nlm_CharPtr title,size_t maxsize)3312 static void Nlm_GetChoiceGroupTitle (Nlm_GraphiC c, Nlm_Int2 item,
3313 Nlm_CharPtr title, size_t maxsize)
3314
3315 {
3316 Nlm_MenU m;
3317 Nlm_PrompT p;
3318
3319 m = (Nlm_MenU) Nlm_GetParent (c);
3320 p = Nlm_GetMenuPrompt (m);
3321 if (p != NULL) {
3322 Nlm_DoGetTitle ((Nlm_GraphiC) p, 0, title, maxsize);
3323 }
3324 }
3325
Nlm_GetChoiceItemTitle(Nlm_GraphiC i,Nlm_Int2 item,Nlm_CharPtr title,size_t maxsize)3326 static void Nlm_GetChoiceItemTitle (Nlm_GraphiC i, Nlm_Int2 item,
3327 Nlm_CharPtr title, size_t maxsize)
3328
3329 {
3330 Nlm_ChoicE c;
3331 Nlm_Int2 first;
3332 Nlm_Int2 index;
3333 Nlm_ItemTool itool;
3334 Nlm_MenU m;
3335
3336 c = (Nlm_ChoicE) Nlm_GetParent (i);
3337 index = Nlm_GetFirstItem ((Nlm_IteM) i);
3338 first = Nlm_GetFirstItem ((Nlm_IteM) c);
3339 m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) c);
3340 itool = NULL;
3341 Nlm_GetMenuItem ((Nlm_GraphiC) m, itool, (Nlm_Int2)(first + index - 1),
3342 title, maxsize);
3343 }
3344
Nlm_GetPopListTitle(Nlm_GraphiC c,Nlm_Int2 item,Nlm_CharPtr title,size_t maxsize)3345 static void Nlm_GetPopListTitle (Nlm_GraphiC c, Nlm_Int2 item,
3346 Nlm_CharPtr title, size_t maxsize)
3347
3348 {
3349 Nlm_MenU m;
3350 #ifdef WIN_MSWIN
3351 Nlm_Char temp [256];
3352 Nlm_PopupTool u;
3353 #endif
3354
3355 m = (Nlm_MenU) Nlm_GetParent (c);
3356 #ifdef WIN_MAC
3357 Nlm_GetChoiceTitle (c, item, title, maxsize);
3358 #endif
3359 #ifdef WIN_MSWIN
3360 u = Nlm_GetMenuPopup (m);
3361 if (u != NULL) {
3362 if (ComboBox_GetLBTextLen (u, item - 1) < sizeof (temp)) {
3363 ComboBox_GetLBText (u, item - 1, temp);
3364 } else {
3365 temp [0] = '\0';
3366 }
3367 Nlm_StringNCpy_0(title, temp, maxsize);
3368 }
3369 #endif
3370 #ifdef WIN_MOTIF
3371 #endif
3372 }
3373
Nlm_GetSubmenuTitle(Nlm_GraphiC m,Nlm_Int2 item,Nlm_CharPtr title,size_t maxsize)3374 static void Nlm_GetSubmenuTitle (Nlm_GraphiC m, Nlm_Int2 item,
3375 Nlm_CharPtr title, size_t maxsize)
3376
3377 {
3378 #ifdef WIN_MAC
3379 Nlm_IteM i;
3380
3381 i = (Nlm_IteM) Nlm_GetParent (m);
3382 if (i != NULL) {
3383 Nlm_GetSingleTitle ((Nlm_GraphiC) i, item, title, maxsize);
3384 }
3385 #endif
3386 #ifdef WIN_MSWIN
3387 if (title != NULL && maxsize > 0) {
3388 title [0] = '\0';
3389 }
3390 #endif
3391 #ifdef WIN_MOTIF
3392 if (title != NULL && maxsize > 0) {
3393 title [0] = '\0';
3394 }
3395 #endif
3396 }
3397
Nlm_SetStatValue(Nlm_GraphiC i,Nlm_Int2 item,Nlm_Boolean value,Nlm_Boolean savePort)3398 static void Nlm_SetStatValue (Nlm_GraphiC i, Nlm_Int2 item,
3399 Nlm_Boolean value, Nlm_Boolean savePort)
3400
3401 {
3402 Nlm_Int2 itm;
3403 Nlm_ItemTool itool;
3404 Nlm_MenU m;
3405 Nlm_WindoW tempPort;
3406
3407 tempPort = Nlm_SavePortIfNeeded (i, savePort);
3408 m = (Nlm_MenU) Nlm_GetParent (i);
3409 itm = Nlm_GetFirstItem ((Nlm_IteM) i);
3410 itool = Nlm_GetItemHandle ((Nlm_IteM) i);
3411 Nlm_CheckMenuItem (m, itool, itm, value);
3412 Nlm_RestorePort (tempPort);
3413 }
3414
Nlm_SetChoiceValue(Nlm_GraphiC c,Nlm_Int2 value,Nlm_Boolean savePort)3415 static void Nlm_SetChoiceValue (Nlm_GraphiC c, Nlm_Int2 value, Nlm_Boolean savePort)
3416
3417 {
3418 Nlm_Int2 first;
3419 Nlm_ItemTool PNTR hdls;
3420 Nlm_Int2 index;
3421 Nlm_ItemTool itool;
3422 Nlm_MenU m;
3423 Nlm_Int2 num;
3424 Nlm_WindoW tempPort;
3425
3426 tempPort = Nlm_SavePortIfNeeded (c, savePort);
3427 first = Nlm_GetFirstItem ((Nlm_IteM) c);
3428 num = Nlm_GetNumItems ((Nlm_ChoicE) c);
3429 m = (Nlm_MenU) Nlm_GetParent (c);
3430 index = 1;
3431 hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
3432 while (index <= num) {
3433 if (hdls != NULL) {
3434 itool = hdls [index - 1];
3435 } else {
3436 itool = NULL;
3437 }
3438 Nlm_CheckMenuItem (m, itool, (Nlm_Int2)(first + index - 1), FALSE);
3439 index++;
3440 }
3441 if (value > 0 && value <= num) {
3442 if (hdls != NULL) {
3443 itool = hdls [value - 1];
3444 } else {
3445 itool = NULL;
3446 }
3447 Nlm_CheckMenuItem (m, itool, (Nlm_Int2)(first + value - 1), TRUE);
3448 }
3449 Nlm_RestorePort (tempPort);
3450 }
3451
Nlm_SetChoiceGroupValue(Nlm_GraphiC c,Nlm_Int2 value,Nlm_Boolean savePort)3452 static void Nlm_SetChoiceGroupValue (Nlm_GraphiC c, Nlm_Int2 value, Nlm_Boolean savePort)
3453
3454 {
3455 Nlm_Int2 first;
3456 Nlm_ItemTool PNTR hdls;
3457 Nlm_Int2 index;
3458 Nlm_ItemTool itool;
3459 Nlm_MenU m;
3460 Nlm_Int2 num;
3461 Nlm_WindoW tempPort;
3462
3463 tempPort = Nlm_SavePortIfNeeded (c, savePort);
3464 first = Nlm_GetFirstItem ((Nlm_IteM) c);
3465 num = Nlm_GetNumItems ((Nlm_ChoicE) c);
3466 m = (Nlm_MenU) Nlm_GetParent (c);
3467 index = 1;
3468 hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
3469 while (index <= num) {
3470 if (hdls != NULL) {
3471 itool = hdls [index - 1];
3472 } else {
3473 itool = NULL;
3474 }
3475 Nlm_CheckMenuItem (m, itool, (Nlm_Int2)(first + index - 1), FALSE);
3476 index++;
3477 }
3478 if (value > 0 && value <= num) {
3479 if (hdls != NULL) {
3480 itool = hdls [value - 1];
3481 } else {
3482 itool = NULL;
3483 }
3484 Nlm_CheckMenuItem (m, itool, (Nlm_Int2)(first + value - 1), TRUE);
3485 }
3486 Nlm_RestorePort (tempPort);
3487 }
3488
Nlm_SetPopListValue(Nlm_GraphiC c,Nlm_Int2 value,Nlm_Boolean savePort)3489 static void Nlm_SetPopListValue (Nlm_GraphiC c, Nlm_Int2 value, Nlm_Boolean savePort)
3490
3491 {
3492 Nlm_MenU m;
3493 Nlm_WindoW tempPort;
3494 #ifdef WIN_MAC
3495 Nlm_RecT r;
3496 #endif
3497 #ifdef WIN_MSWIN
3498 Nlm_PopupTool u;
3499 #endif
3500 #ifdef WIN_MOTIF
3501 Nlm_ItemTool PNTR hdls;
3502 Nlm_PopupTool u;
3503 #endif
3504
3505 tempPort = Nlm_SavePortIfNeeded (c, savePort);
3506 m = (Nlm_MenU) Nlm_GetParent (c);
3507 #ifdef WIN_MAC
3508 Nlm_SetChoiceValue (c, value, FALSE);
3509 if (Nlm_GetVisible (c) && Nlm_GetAllParentsVisible (c)) {
3510 Nlm_GetRect ((Nlm_GraphiC) m, &r);
3511 Nlm_UpsetRect (&r, 1, 1, 2, 2);
3512 Nlm_InvalRect (&r);
3513 }
3514 #endif
3515 #ifdef WIN_MSWIN
3516 u = Nlm_GetMenuPopup (m);
3517 if (u != NULL) {
3518 if (value > 0) {
3519 ComboBox_SetCurSel (u, value - 1);
3520 } else {
3521 ComboBox_SetCurSel (u, -1);
3522 }
3523 }
3524 #endif
3525 #ifdef WIN_MOTIF
3526 Nlm_SetPopupValue ((Nlm_ChoicE) c, value);
3527 u = Nlm_GetMenuPopup (m);
3528 if (u != NULL) {
3529 hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
3530 if (value > 0 && value < 64) {
3531 XtVaSetValues (u, XmNmenuHistory, hdls [value - 1], NULL);
3532 XtUnmanageChild (hdls [63]);
3533 } else {
3534 XtVaSetValues (u, XmNmenuHistory, hdls [63], NULL);
3535 XtManageChild (hdls [63]);
3536 }
3537 }
3538 #endif
3539 Nlm_RestorePort (tempPort);
3540 }
3541
Nlm_GetStatValue(Nlm_GraphiC i,Nlm_Int2 item)3542 static Nlm_Boolean Nlm_GetStatValue (Nlm_GraphiC i, Nlm_Int2 item)
3543
3544 {
3545 Nlm_Int2 itm;
3546 Nlm_ItemTool itool;
3547 Nlm_MenU m;
3548
3549 m = (Nlm_MenU) Nlm_GetParent (i);
3550 itm = Nlm_GetFirstItem ((Nlm_IteM) i);
3551 itool = Nlm_GetItemHandle ((Nlm_IteM) i);
3552 return (Nlm_IsMenuItemChecked (m, itool, itm));
3553 }
3554
Nlm_GetChoiceValue(Nlm_GraphiC c)3555 static Nlm_Int2 Nlm_GetChoiceValue (Nlm_GraphiC c)
3556
3557 {
3558 Nlm_Int2 first;
3559 Nlm_ItemTool PNTR hdls;
3560 Nlm_Int2 itm;
3561 Nlm_ItemTool itool;
3562 Nlm_MenU m;
3563 Nlm_Int2 num;
3564 Nlm_Int2 rsult;
3565
3566 rsult = 0;
3567 first = Nlm_GetFirstItem ((Nlm_IteM) c);
3568 num = Nlm_GetNumItems ((Nlm_ChoicE) c);
3569 m = (Nlm_MenU) Nlm_GetParent (c);
3570 itm = 1;
3571 hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
3572 while (itm <= num && rsult == 0) {
3573 if (hdls != NULL) {
3574 itool = hdls [itm - 1];
3575 } else {
3576 itool = NULL;
3577 }
3578 if (Nlm_IsMenuItemChecked (m, itool, (Nlm_Int2)(first + itm - 1))) {
3579 rsult = itm;
3580 }
3581 itm++;
3582 }
3583 return rsult;
3584 }
3585
Nlm_GetChoiceGroupValue(Nlm_GraphiC c)3586 static Nlm_Int2 Nlm_GetChoiceGroupValue (Nlm_GraphiC c)
3587
3588 {
3589 Nlm_Int2 first;
3590 Nlm_ItemTool PNTR hdls;
3591 Nlm_Int2 itm;
3592 Nlm_ItemTool itool;
3593 Nlm_MenU m;
3594 Nlm_Int2 num;
3595 Nlm_Int2 rsult;
3596
3597 rsult = 0;
3598 first = Nlm_GetFirstItem ((Nlm_IteM) c);
3599 num = Nlm_GetNumItems ((Nlm_ChoicE) c);
3600 m = (Nlm_MenU) Nlm_GetParent (c);
3601 itm = 1;
3602 hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
3603 while (itm <= num && rsult == 0) {
3604 if (hdls != NULL) {
3605 itool = hdls [itm - 1];
3606 } else {
3607 itool = NULL;
3608 }
3609 if (Nlm_IsMenuItemChecked (m, itool, (Nlm_Int2)(first + itm - 1))) {
3610 rsult = itm;
3611 }
3612 itm++;
3613 }
3614 return rsult;
3615 }
3616
Nlm_GetPopListValue(Nlm_GraphiC c)3617 static Nlm_Int2 Nlm_GetPopListValue (Nlm_GraphiC c)
3618
3619 {
3620 Nlm_Int2 rsult;
3621 #ifdef WIN_MSWIN
3622 Nlm_MenU m;
3623 Nlm_PopupTool u;
3624 #endif
3625
3626 rsult = 0;
3627 #ifdef WIN_MAC
3628 rsult = Nlm_GetChoiceValue (c);
3629 #endif
3630 #ifdef WIN_MSWIN
3631 m = (Nlm_MenU) Nlm_GetParent (c);
3632 u = Nlm_GetMenuPopup (m);
3633 if (u != NULL) {
3634 rsult = (Nlm_Int2)(ComboBox_GetCurSel( u ) + 1);
3635 }
3636 #endif
3637 #ifdef WIN_MOTIF
3638 rsult = Nlm_GetPopupValue ((Nlm_ChoicE) c);
3639 #endif
3640 return rsult;
3641 }
3642
3643 #ifdef WIN_MOTIF
Nlm_MenuCallback(Widget w,XtPointer client_data,XtPointer call_data)3644 static void Nlm_MenuCallback (Widget w, XtPointer client_data, XtPointer call_data)
3645
3646 {
3647 Nlm_GraphiC i;
3648
3649 choiceWidget = w;
3650 i = (Nlm_GraphiC) client_data;
3651 Nlm_DoCallback (i);
3652 }
3653 #endif
3654
3655 #ifdef WIN_MAC
Nlm_TitleGetAccel(Nlm_CharPtr title,Nlm_CharPtr accel)3656 static Nlm_Boolean Nlm_TitleGetAccel(Nlm_CharPtr title,
3657 Nlm_CharPtr accel)
3658 {
3659 Nlm_Uint4 slash_pos;
3660
3661 if ( !Nlm_StrngPos(title, "/", 0, FALSE, &slash_pos) ||
3662 ! IS_ALPHANUM(title[slash_pos+1]) )
3663 return FALSE;
3664
3665 if ( accel ) {
3666 if ( IS_ALPHANUM( title[slash_pos+1]) ) {
3667 *accel = title[slash_pos+1] ;
3668 } else {
3669 *accel = '\0';
3670 }
3671 }
3672
3673 return TRUE;
3674 }
3675
3676 #else
Nlm_TitleGetAccel(Nlm_CharPtr title,Nlm_CharPtr accel,Nlm_CharPtr mnemo,Nlm_Uint4Ptr mnemo_pos)3677 static Nlm_Boolean Nlm_TitleGetAccel(Nlm_CharPtr title,
3678 Nlm_CharPtr accel,
3679 Nlm_CharPtr mnemo,
3680 Nlm_Uint4Ptr mnemo_pos)
3681 {
3682 static Nlm_Char letter[2];
3683 Nlm_Uint4 slash_pos, x_pos;
3684
3685 if ( !Nlm_StrngPos(title, "/", 0, FALSE, &slash_pos) ||
3686 title[slash_pos+1] == '\0' || title[slash_pos+2] == '\0')
3687 return FALSE;
3688
3689
3690 if ( accel )
3691 *accel = IS_ALPHANUM( title[slash_pos+3] ) ? title[slash_pos+3] : '\0';
3692
3693 letter[0] = title[slash_pos + 2];
3694
3695 if (!mnemo && !mnemo_pos)
3696 return TRUE;
3697
3698 /* Look for the letter; try to match the case, if possible... */
3699 if (IS_ALPHANUM( letter[0] ) &&
3700 ((Nlm_StrngPos(title, letter, 0, TRUE, &x_pos) && x_pos < slash_pos) ||
3701 (Nlm_StrngPos(title, letter, 0, FALSE, &x_pos) && x_pos < slash_pos)))
3702 {
3703 if ( mnemo )
3704 *mnemo = title[x_pos];
3705 if ( mnemo_pos )
3706 *mnemo_pos = x_pos;
3707 }
3708 else
3709 {
3710 if ( mnemo )
3711 *mnemo = '\0';
3712 }
3713
3714 return TRUE;
3715 }
3716 #endif
3717
Nlm_StripTitleAccel(Nlm_CharPtr title)3718 static void Nlm_StripTitleAccel(Nlm_CharPtr title)
3719 {
3720 Nlm_Uint4 pos;
3721 if ( Nlm_StrngPos(title, "/", 0, FALSE, &pos) )
3722 title[pos] = '\0';
3723 }
3724
3725
3726 #ifdef WIN_MOTIF
3727 #define NO_MNEMO 0x1
3728 #define NO_ACCEL 0x2
3729 #define NO_ACCEL_DESCR 0x4
3730
Nlm_AddTitleAccel(Widget w,Nlm_CharPtr title,Nlm_Int4 flags)3731 static void Nlm_AddTitleAccel(Widget w, Nlm_CharPtr title, Nlm_Int4 flags)
3732 {
3733 Nlm_Char accel, mnemo;
3734
3735 if (((flags & 0x3) ^ 0x3) &&
3736 Nlm_TitleGetAccel(title, &accel, &mnemo, NULL) )
3737 {
3738 if (!(flags & NO_ACCEL) && accel)
3739 {
3740 static char accel_key[] = "Ctrl<Key> ";
3741 accel_key[sizeof(accel_key) - 2] = accel;
3742 XtVaSetValues(w, XmNaccelerator, accel_key, NULL);
3743
3744 if ( !(flags & NO_ACCEL_DESCR) )
3745 {
3746 XmString accel_text;
3747 static char accel_descr[] = "Ctrl- ";
3748 accel_descr[sizeof(accel_descr) - 2] = accel;
3749
3750 accel_text = XmStringCreateSimple( accel_descr );
3751 XtVaSetValues(w, XmNacceleratorText, accel_text, NULL);
3752 XmStringFree( accel_text );
3753 }
3754 }
3755
3756 if (!(flags & NO_MNEMO) && mnemo)
3757 XtVaSetValues(w, XmNmnemonic, mnemo, NULL);
3758 }
3759
3760 {{
3761 XmString label;
3762 Nlm_StripTitleAccel( title );
3763 label = XmStringCreateSimple( title );
3764 XtVaSetValues(w, XmNlabelString, label, NULL);
3765 XmStringFree( label );
3766 }}
3767 }
3768 #endif /* WIN_MOTIF */
3769
3770 #ifdef WIN_MSWIN
3771
3772 extern Nlm_Handle Nlm_GetWindowHAccel (Nlm_WindoW w);
3773 extern void Nlm_SetWindowHAccel (Nlm_WindoW w, Nlm_Handle h);
3774
Nlm_AddAccel(Nlm_MenU m,Nlm_Int2 id,Nlm_Char key)3775 static void Nlm_AddAccel(Nlm_MenU m, Nlm_Int2 id, Nlm_Char key)
3776 {
3777 HACCEL haccel = NULL; /* handle to accelerator table */
3778
3779 int i; /* loop counter */
3780 LPACCEL lpaccelNew; /* pointer to new accelerator table */
3781 HACCEL haccelOld; /* handle to old accelerator table */
3782 int nAccelerators; /* number of accelerators in table */
3783
3784 BYTE fAccelFlags; /* accelerator flags */
3785
3786 Nlm_WindoW w; /* top-level window that contains the menu */
3787
3788 if(key == 0)
3789 /* no accelerator key specified */
3790 return;
3791
3792 if(IS_ALPHA(key))
3793 {
3794 /* - old implementation
3795 fAccelFlags = FCONTROL;
3796 key = TO_UPPER(key) - 'A' + 1;
3797 */
3798
3799 /*
3800 use virtual keycodes to distinguish between Return and controlM
3801 and Backspace and controlH. (the old way of using character codes
3802 used ascii values which did not distinguish the two, i.e. both
3803 controlM and Return map to ascii 13)
3804 */
3805 fAccelFlags = FCONTROL | FVIRTKEY;
3806 }
3807 else
3808 if(IS_DIGIT(key))
3809 {
3810 fAccelFlags = FCONTROL | FVIRTKEY;
3811 }
3812 else
3813 /* key is not supported */
3814 return;
3815
3816 /* Get top-level window */
3817 w = Nlm_GetParentWindow((Nlm_GraphiC)m);
3818 if(w == NULL)
3819 /* failure */
3820 return;
3821
3822 haccel = Nlm_GetWindowHAccel(w);
3823
3824 /* Save the current accelerator table. */
3825
3826 haccelOld = haccel;
3827
3828 /* Count the number of entries in the current
3829 table, allocate a buffer for the table, and
3830 then copy the table into the buffer,
3831 reserving space for a new accelerator */
3832
3833 if(haccelOld)
3834 nAccelerators = CopyAcceleratorTable(haccelOld, NULL, 0);
3835 else
3836 nAccelerators = 0;
3837
3838 lpaccelNew = (LPACCEL) Nlm_MemNew((nAccelerators + 1) * sizeof(ACCEL));
3839 if(lpaccelNew == NULL)
3840 /* failure */
3841 return;
3842
3843 if(lpaccelNew != NULL && nAccelerators)
3844 CopyAcceleratorTable(haccel, lpaccelNew, nAccelerators);
3845
3846 /* Find the accelerator that the user modified
3847 and change its flags and virtual-key code
3848 as appropriate. */
3849
3850 for(i = 0; i < nAccelerators; ++i)
3851 {
3852 if(lpaccelNew[i].cmd == (WORD) id ||
3853 (lpaccelNew[i].fVirt == fAccelFlags &&
3854 lpaccelNew[i].key == key))
3855 break;
3856 }
3857
3858 lpaccelNew[i].cmd = id;
3859 lpaccelNew[i].fVirt = fAccelFlags;
3860 lpaccelNew[i].key = key;
3861
3862 if(i == nAccelerators)
3863 /* new accelerator added */
3864 ++nAccelerators;
3865
3866 /* Create the new accelerator table, and
3867 destroy the old one. */
3868
3869 if(haccelOld)
3870 DestroyAcceleratorTable(haccelOld);
3871 haccel = CreateAcceleratorTable(lpaccelNew, nAccelerators);
3872
3873 Nlm_SetWindowHAccel(w, haccel);
3874
3875 Nlm_MemFree(lpaccelNew);
3876 }
3877
3878
Nlm_PrepareTitleMsWin(Nlm_CharPtr temp,Nlm_CharPtr title,size_t siztemp,Nlm_CharPtr paccel,Nlm_Boolean isMenu)3879 static void Nlm_PrepareTitleMsWin(Nlm_CharPtr temp, Nlm_CharPtr title,
3880 size_t siztemp, Nlm_CharPtr paccel,
3881 Nlm_Boolean isMenu)
3882 {
3883 /* duplicate existing '&',
3884 mark mnemo char with single '&',
3885 add accelerator description */
3886
3887 Nlm_Char accel = '\0';
3888 Nlm_Char mnemo = '\0';
3889 Nlm_Uint4 mnemo_pos = 0;
3890 Nlm_Uint4 src_pos = 0;
3891 Nlm_Uint4 dest_pos = 0;
3892
3893 Nlm_TitleGetAccel(temp, &accel, &mnemo, &mnemo_pos);
3894
3895 if(isMenu)
3896 accel = '\0';
3897
3898 if(paccel != NULL)
3899 *paccel = accel;
3900
3901 for(src_pos = 0, dest_pos = 0;
3902 title[src_pos] != '\0' && dest_pos+1 < siztemp;
3903 ++src_pos)
3904 {
3905 if(mnemo && src_pos == mnemo_pos)
3906 {
3907 if(dest_pos + 2 < siztemp)
3908 {
3909 temp[dest_pos++] = '&';
3910 temp[dest_pos++] = title[src_pos];
3911 }
3912 else
3913 break;
3914 }
3915 else
3916 if(title[src_pos] == '&')
3917 {
3918 if(dest_pos + 2 < siztemp)
3919 {
3920 temp[dest_pos++] = '&';
3921 temp[dest_pos++] = title[src_pos];
3922 }
3923 else
3924 break;
3925 }
3926 else
3927 if(title[src_pos] == '/')
3928 break;
3929 else
3930 temp[dest_pos++] = title[src_pos];
3931 }
3932
3933 temp[dest_pos] = '\0';
3934
3935 if(accel != '\0' && dest_pos + 7 < siztemp)
3936 {
3937 Nlm_StrCpy(temp+dest_pos, "\tCtrl- ");
3938 if(IS_ALPHA(accel))
3939 temp[dest_pos+6] = TO_UPPER(accel);
3940 else
3941 temp[dest_pos+6] = accel;
3942 }
3943 }
3944 #endif /* WIN_MSWIN */
3945
3946
Nlm_PrepareTitle(Nlm_CharPtr temp,Nlm_CharPtr title,size_t siztemp,Nlm_Boolean isMenu)3947 static void Nlm_PrepareTitle(Nlm_CharPtr temp, Nlm_CharPtr title,
3948 size_t siztemp, Nlm_Boolean isMenu)
3949 {
3950 Nlm_StringNCpy_0(temp, title, siztemp);
3951
3952 #ifdef WIN_MAC
3953 if ( isMenu ) {
3954 Nlm_StripTitleAccel( temp );
3955 } else {
3956 Nlm_Uint4 pos;
3957 if ( Nlm_StrngPos(temp, "/ ", 0, FALSE, &pos) )
3958 temp[pos] = '\0';
3959 }
3960 #endif
3961 }
3962
3963
3964 #define COMMAND_ITEM 1
3965 #define STATUS_ITEM 2
3966 #define CHOICE_ITEM 3
3967 #define POPUP_ITEM 4
3968 #define CASCADE_ITEM 5
3969
Nlm_AppendItems(Nlm_MenU m,Nlm_IteM i,Nlm_CharPtr itemNames,Nlm_Int2 type,Nlm_Boolean savePort)3970 static Nlm_ItemTool Nlm_AppendItems(Nlm_MenU m, Nlm_IteM i,
3971 Nlm_CharPtr itemNames,
3972 Nlm_Int2 type, Nlm_Boolean savePort)
3973 {
3974 Nlm_MenuTool h;
3975 Nlm_ItemTool item = NULL;
3976 Nlm_Char temp[256];
3977 Nlm_WindoW tempPort;
3978 Nlm_Char accel;
3979 #ifdef WIN_MOTIF
3980 Cardinal n;
3981 Arg wargs[10];
3982 #endif
3983 #ifdef WIN_MAC
3984 CFStringRef cfTitle;
3985 #endif
3986
3987 Nlm_PrepareTitle(temp, itemNames, sizeof(temp), TRUE);
3988 if (temp[0] == '\0')
3989 return NULL;
3990
3991 tempPort = Nlm_SavePortIfNeeded((Nlm_GraphiC)m, savePort);
3992 h = Nlm_GetMenuHandle( (Nlm_MenU)m );
3993
3994 #ifdef WIN_MAC
3995 cfTitle = CFStringCreateWithBytes(kCFAllocatorDefault, (unsigned char *)temp,
3996 strlen(temp), kCFStringEncodingASCII, false);
3997
3998 AppendMenuItemTextWithCFString(h, cfTitle, 0, 0, NULL);
3999 CFRelease(cfTitle);
4000
4001 if (Nlm_TitleGetAccel(itemNames, &accel) && accel) {
4002 SetMenuItemCommandKey(h, CountMenuItems(h), FALSE, accel);
4003 }
4004 #endif
4005
4006 #ifdef WIN_MSWIN
4007 {{
4008 Nlm_PrepareTitleMsWin(temp, itemNames, sizeof(temp), &accel, FALSE);
4009 AppendMenu(h, MF_ENABLED, nextMenuNum, temp);
4010 Nlm_AddAccel(m, nextMenuNum, accel);
4011 if (nextMenuNum < 32767)
4012 nextMenuNum++;
4013 }}
4014 #endif
4015
4016 #ifdef WIN_MOTIF
4017 n = 0;
4018 XtSetArg (wargs [n], XmNfontList, Nlm_XfontList); n++;
4019 if (type != POPUP_ITEM) {
4020 XtSetArg (wargs [n], XmNmarginHeight, (Dimension)5); n++;
4021 XtSetArg (wargs [n], XmNmarginWidth, (Dimension)5); n++;
4022 }
4023 XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
4024 XtSetArg (wargs [n], XmNheight, (Dimension)(Nlm_stdLineHeight+10)); n++;
4025 switch ( type )
4026 {
4027 case COMMAND_ITEM:
4028 item = XmCreatePushButton(h, (String)"", wargs, n);
4029 XtAddCallback(item, XmNactivateCallback,
4030 Nlm_MenuCallback, (XtPointer)i);
4031 break;
4032 case STATUS_ITEM:
4033 XtSetArg(wargs[n], XmNindicatorType, XmN_OF_MANY); n++;
4034 item = XmCreateToggleButton(h, (String)"", wargs, n);
4035 XtAddCallback(item, XmNvalueChangedCallback,
4036 Nlm_MenuCallback, (XtPointer)i);
4037 break;
4038 case CHOICE_ITEM:
4039 XtSetArg(wargs[n], XmNindicatorType, XmONE_OF_MANY); n++;
4040 item = XmCreateToggleButton(h, (String)"", wargs, n);
4041 XtAddCallback(item, XmNvalueChangedCallback,
4042 Nlm_MenuCallback, (XtPointer)i);
4043 break;
4044 case POPUP_ITEM:
4045 XtSetArg(wargs[n], XmNrecomputeSize, (Boolean)FALSE); n++;
4046 item = XmCreatePushButton(h, (String)temp, wargs, n);
4047 XtAddCallback(item, XmNactivateCallback,
4048 Nlm_MenuCallback, (XtPointer)i);
4049 break;
4050 default:
4051 break;
4052 }
4053
4054 if ( item )
4055 Nlm_AddTitleAccel(item, temp, (type == POPUP_ITEM ? NO_ACCEL_DESCR : 0));
4056 #endif
4057
4058 Nlm_RestorePort( tempPort );
4059 return item;
4060 }
4061
4062
4063 #ifdef WIN_MAC
Nlm_AppendResources(Nlm_MenU m,ResType res,Nlm_Boolean savePort)4064 static void Nlm_AppendResources (Nlm_MenU m, ResType res, Nlm_Boolean savePort)
4065
4066 {
4067 Nlm_MenuTool h;
4068 Nlm_WindoW tempPort;
4069
4070 tempPort = Nlm_SavePortIfNeeded ((Nlm_GraphiC) m, savePort);
4071 h = Nlm_GetMenuHandle (m);
4072 AppendResMenu (h, res);
4073 Nlm_RestorePort (tempPort);
4074 }
4075 #endif
4076
Nlm_StripParens(Nlm_CharPtr to,Nlm_CharPtr from,size_t max)4077 static void Nlm_StripParens (Nlm_CharPtr to, Nlm_CharPtr from, size_t max)
4078
4079 {
4080 Nlm_Char ch;
4081 Nlm_Int2 i;
4082 Nlm_Int2 j;
4083
4084 if (to != NULL && max > 0) {
4085 *to = '\0';
4086 if (from != NULL) {
4087 i = 0;
4088 j = 0;
4089 ch = from [i];
4090 while (ch != '\0' && j < (Nlm_Int2) (max - 1)) {
4091 if (ch == '(') {
4092 to [j] = '[';
4093 i++;
4094 j++;
4095 } else if (ch == ')') {
4096 to [j] = ']';
4097 i++;
4098 j++;
4099 } else {
4100 to [j] = ch;
4101 i++;
4102 j++;
4103 }
4104 ch = from [i];
4105 }
4106 to [j] = '\0';
4107 }
4108 }
4109 }
4110
Nlm_AppendChoice(Nlm_ChoicE c,Nlm_CharPtr title,Nlm_Boolean poplist,Nlm_Boolean savePort)4111 static Nlm_IteM Nlm_AppendChoice (Nlm_ChoicE c, Nlm_CharPtr title,
4112 Nlm_Boolean poplist, Nlm_Boolean savePort)
4113
4114 {
4115 Nlm_IteM i;
4116 Nlm_ItemTool itool;
4117 Nlm_MenU m;
4118 Nlm_Int2 num = Nlm_GetNumItems(c);
4119 Nlm_RecT r;
4120 Nlm_Char temp [256];
4121 Nlm_WindoW tempPort;
4122 #ifdef WIN_MOTIF
4123 Nlm_ItemTool *hdls;
4124 if (num < 0 || 63 <= num)
4125 return 0;
4126 #endif
4127
4128 i = NULL;
4129 tempPort = Nlm_SavePortIfNeeded ((Nlm_GraphiC) c, savePort);
4130 Nlm_StripParens (temp, title, sizeof (temp));
4131 m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) c);
4132 if (poplist) {
4133 itool = Nlm_AppendItems (m, (Nlm_IteM) c, temp, POPUP_ITEM, FALSE);
4134 } else {
4135 itool = Nlm_AppendItems (m, (Nlm_IteM) c, temp, CHOICE_ITEM, FALSE);
4136 Nlm_LoadRect (&r, 0, 0, 0, 0);
4137 i = (Nlm_IteM) Nlm_CreateLink ((Nlm_GraphiC) c, &r, sizeof (Nlm_ItemRec), choiceItemProcs);
4138 if (i != NULL) {
4139 Nlm_SetVisible ((Nlm_GraphiC) i, TRUE);
4140 }
4141 }
4142
4143 num++;
4144 Nlm_LoadItemData (i, NULL, num, NULL);
4145 #ifdef WIN_MOTIF
4146 hdls = Nlm_GetChoiceHandles (c);
4147 if (hdls == NULL) {
4148 hdls = (Nlm_ItemTool *) Nlm_MemNew(64 * sizeof (Nlm_ItemTool));
4149 Nlm_SetChoiceHandles (c, hdls);
4150 }
4151 if ( hdls ) {
4152 Nlm_SetNumItems(c, num);
4153 hdls[num - 1] = itool;
4154 XtManageChild(itool);
4155 }
4156 #else
4157 Nlm_SetNumItems (c, num);
4158 #endif
4159
4160 Nlm_RestorePort (tempPort);
4161 return i;
4162 }
4163
4164
Nlm_AppendPopList(Nlm_ChoicE c,Nlm_CharPtr title,Nlm_Boolean savePort)4165 static void Nlm_AppendPopList (Nlm_ChoicE c, Nlm_CharPtr title, Nlm_Boolean savePort)
4166 {
4167 Nlm_MenU m;
4168 Nlm_RecT r;
4169 Nlm_Int2 swid;
4170 Nlm_Char temp[256];
4171 Nlm_WindoW tempPort;
4172 Nlm_Int4 wid;
4173 #ifdef WIN_MSWIN
4174 Nlm_Int2 num;
4175 Nlm_PopupTool u;
4176 #endif
4177 #ifdef WIN_MOTIF
4178 Nlm_Boolean done;
4179 Nlm_ItemTool *hdls;
4180 Nlm_ItemTool itool;
4181 XmString label;
4182 Nlm_Int2 num;
4183 Nlm_PopupTool u;
4184 #endif
4185
4186 tempPort = Nlm_SavePortIfNeeded ((Nlm_GraphiC) c, savePort);
4187 Nlm_StripParens(temp, title, sizeof(temp));
4188 m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) c);
4189 #ifdef WIN_MAC
4190 Nlm_StripTitleAccel( temp );
4191 Nlm_AppendChoice (c, temp, TRUE, FALSE);
4192 #endif
4193 #ifdef WIN_MSWIN
4194 Nlm_StripTitleAccel( temp );
4195 u = Nlm_GetMenuPopup (m);
4196 if (u != NULL) {
4197 ComboBox_AddString (u, temp);
4198 num = Nlm_GetNumItems ((Nlm_ChoicE) c);
4199 num++;
4200 Nlm_SetNumItems (c, num);
4201 }
4202 #endif
4203 #ifdef WIN_MOTIF
4204 done = FALSE;
4205 hdls = Nlm_GetChoiceHandles (c);
4206 if (hdls != NULL) {
4207 num = Nlm_GetNumItems ((Nlm_ChoicE) c);
4208 num++;
4209 if (num > 0 && num < 64) {
4210 itool = hdls [num - 1];
4211 if (itool != NULL) {
4212 label = XmStringCreateSimple (temp);
4213 XtVaSetValues (itool, XmNlabelString, label, NULL);
4214 XmStringFree (label);
4215 XtManageChild (itool);
4216 Nlm_SetNumItems ((Nlm_ChoicE) c, num);
4217 done = TRUE;
4218 }
4219 }
4220 }
4221 if (! done) {
4222 Nlm_AppendChoice (c, temp, TRUE, FALSE);
4223 }
4224 #endif
4225 Nlm_SelectFont (Nlm_systemFont);
4226 swid = Nlm_StringWidth (temp);
4227 Nlm_GetRect ((Nlm_GraphiC) m, &r);
4228 #ifdef WIN_MAC
4229 wid = r.right - r.left - 26;
4230 if (swid > wid) {
4231 r.right = r.left + swid + 26;
4232 Nlm_SetRect ((Nlm_GraphiC) m, &r);
4233 Nlm_SetRect ((Nlm_GraphiC) c, &r);
4234 }
4235 if (swid > wid) {
4236 if (Nlm_GetVisible ((Nlm_GraphiC) c) && Nlm_GetAllParentsVisible ((Nlm_GraphiC) c)) {
4237 Nlm_InsetRect (&r, -2, -2);
4238 Nlm_OffsetRect (&r, 1, 1);
4239 Nlm_InvalRect (&r);
4240 }
4241 }
4242 #endif
4243 #ifdef WIN_MSWIN
4244 wid = r.right - r.left - 26;
4245 if (swid > wid) {
4246 r.right = (Nlm_Int2)(r.left + swid + 26);
4247 Nlm_SetRect ((Nlm_GraphiC) m, &r);
4248 Nlm_SetRect ((Nlm_GraphiC) c, &r);
4249 }
4250 u = Nlm_GetMenuPopup (m);
4251 if (u != NULL) {
4252 if (num > 10) {
4253 num = 10;
4254 }
4255 MoveWindow (u, r.left, r.top, r.right - r.left,
4256 r.bottom - r.top + (num + 1) * Nlm_stdLineHeight, TRUE);
4257 UpdateWindow (u);
4258 }
4259 #endif
4260 #ifdef WIN_MOTIF
4261 wid = r.right - r.left - 52;
4262 if (swid > wid) {
4263 r.right = r.left + swid + 52;
4264 Nlm_SetRect ((Nlm_GraphiC) m, &r);
4265 Nlm_SetRect ((Nlm_GraphiC) c, &r);
4266 }
4267 u = Nlm_GetMenuPopup (m);
4268 if (u != NULL) {
4269 XtVaSetValues (u,
4270 XmNx, (Position) r.left,
4271 XmNy, (Position) r.top,
4272 XmNwidth, (Dimension) (r.right - r.left),
4273 XmNheight, (Dimension) (r.bottom - r.top),
4274 NULL);
4275 }
4276 #endif
4277 Nlm_GetRect ((Nlm_GraphiC) m, &r);
4278 Nlm_DoAdjustPrnt ((Nlm_GraphiC) m, &r, TRUE, FALSE);
4279 Nlm_RestorePort (tempPort);
4280 }
4281
4282
4283 #ifndef WIN_MSWIN
Nlm_AppendOnePopListItem(Nlm_MenU m,Nlm_IteM i,Nlm_CharPtr itemNames)4284 static Nlm_ItemTool Nlm_AppendOnePopListItem (Nlm_MenU m, Nlm_IteM i,
4285 Nlm_CharPtr itemNames)
4286
4287 {
4288 Nlm_MenuTool h;
4289 Nlm_ItemTool rsult;
4290 Nlm_Char temp [256];
4291 #ifdef WIN_MOTIF
4292 XmString label;
4293 Cardinal n;
4294 Arg wargs [10];
4295 #endif
4296
4297 rsult = NULL;
4298 h = Nlm_GetMenuHandle ((Nlm_MenU) m);
4299 Nlm_StringNCpy_0(temp, itemNames, sizeof(temp));
4300 if (temp [0] != '\0') {
4301 #ifdef WIN_MAC
4302 {{
4303 CFStringRef cfTitle;
4304 cfTitle = CFStringCreateWithBytes(kCFAllocatorDefault, (unsigned char *) temp,
4305 strlen(temp), kCFStringEncodingASCII, false);
4306
4307 AppendMenuItemTextWithCFString(h, cfTitle, 0, 0, NULL);
4308 CFRelease(cfTitle);
4309 }}
4310 #endif
4311 /*
4312 #ifdef WIN_MSWIN
4313 AppendMenu (h, MF_ENABLED, nextMenuNum, itemNames);
4314 if (nextMenuNum < 32767) {
4315 nextMenuNum++;
4316 }
4317 #endif
4318 */
4319 #ifdef WIN_MOTIF
4320 label = XmStringCreateSimple (temp);
4321 n = 0;
4322 XtSetArg (wargs [n], XmNlabelString, label); n++;
4323 XtSetArg (wargs [n], XmNfontList, Nlm_XfontList); n++;
4324 XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
4325 XtSetArg (wargs [n], XmNheight, (Dimension)(Nlm_stdLineHeight+10)); n++;
4326 XtSetArg (wargs [n], XmNrecomputeSize, (Boolean)FALSE); n++;
4327 rsult = XmCreatePushButton (h, (String) "", wargs, n);
4328 XtAddCallback (rsult, XmNactivateCallback, Nlm_MenuCallback, (XtPointer) i);
4329 XmStringFree (label);
4330 #endif
4331 }
4332 return rsult;
4333 }
4334 #endif
4335
4336
4337 #ifndef WIN_MSWIN
Nlm_AppendOnePopListChoice(Nlm_ChoicE c,Nlm_CharPtr title)4338 static Nlm_IteM Nlm_AppendOnePopListChoice (Nlm_ChoicE c, Nlm_CharPtr title)
4339
4340 {
4341 Nlm_IteM i;
4342 Nlm_ItemTool itool;
4343 Nlm_MenU m;
4344 Nlm_Int2 num;
4345 Nlm_Char temp [256];
4346 #ifdef WIN_MOTIF
4347 Nlm_ItemTool *hdls;
4348 #endif
4349
4350 i = NULL;
4351 Nlm_StripParens (temp, title, sizeof (temp));
4352 m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) c);
4353 itool = Nlm_AppendOnePopListItem (m, (Nlm_IteM) c, temp);
4354 num = Nlm_GetNumItems (c);
4355 num++;
4356 Nlm_LoadItemData (i, NULL, num, NULL);
4357 #ifdef WIN_MOTIF
4358 hdls = Nlm_GetChoiceHandles (c);
4359 if (hdls == NULL) {
4360 hdls = (Nlm_ItemTool *) Nlm_MemNew (64 * sizeof (Nlm_ItemTool));
4361 Nlm_SetChoiceHandles (c, hdls);
4362 }
4363 if (hdls != NULL && num > 0 && num < 64) {
4364 hdls [num - 1] = itool;
4365 Nlm_SetNumItems (c, num);
4366 XtManageChild (itool);
4367 }
4368 #else
4369 Nlm_SetNumItems (c, num);
4370 #endif
4371
4372 return i;
4373 }
4374 #endif
4375
4376
Nlm_MultiAppendPopList(Nlm_ChoicE c,Nlm_CharPtr PNTR titles,Nlm_Boolean savePort)4377 static void Nlm_MultiAppendPopList (Nlm_ChoicE c, Nlm_CharPtr PNTR titles, Nlm_Boolean savePort)
4378
4379 {
4380 Nlm_Int2 i;
4381 Nlm_MenU m;
4382 Nlm_RecT r;
4383 Nlm_Int4 swid;
4384 Nlm_Char temp [256];
4385 Nlm_WindoW tempPort;
4386 Nlm_Int4 wid;
4387 #ifdef WIN_MSWIN
4388 Nlm_Int2 num = 0;
4389 Nlm_PopupTool u;
4390 #endif
4391 #ifdef WIN_MOTIF
4392 Nlm_Boolean done;
4393 Nlm_ItemTool *hdls;
4394 Nlm_ItemTool itool;
4395 XmString label;
4396 Nlm_Int2 num = 0;
4397 Nlm_PopupTool u;
4398 #endif
4399
4400 if (titles == NULL) return;
4401 tempPort = Nlm_SavePortIfNeeded ((Nlm_GraphiC) c, savePort);
4402 m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) c);
4403 swid = 0;
4404 i = 0;
4405 while (titles [i] != NULL) {
4406 Nlm_StripParens (temp, titles [i], sizeof (temp));
4407 #ifdef WIN_MAC
4408 Nlm_AppendOnePopListChoice (c, temp);
4409 #endif
4410 #ifdef WIN_MSWIN
4411 u = Nlm_GetMenuPopup (m);
4412 if (u != NULL) {
4413 ComboBox_AddString (u, temp);
4414 num = Nlm_GetNumItems ((Nlm_ChoicE) c);
4415 num++;
4416 Nlm_SetNumItems (c, num);
4417 }
4418 #endif
4419 #ifdef WIN_MOTIF
4420 done = FALSE;
4421 hdls = Nlm_GetChoiceHandles (c);
4422 if (hdls != NULL) {
4423 num = Nlm_GetNumItems ((Nlm_ChoicE) c);
4424 num++;
4425 if (num > 0 && num < 64) {
4426 itool = hdls [num - 1];
4427 if (itool != NULL) {
4428 label = XmStringCreateSimple (temp);
4429 XtVaSetValues (itool, XmNlabelString, label, NULL);
4430 XmStringFree (label);
4431 XtManageChild (itool);
4432 Nlm_SetNumItems ((Nlm_ChoicE) c, num);
4433 done = TRUE;
4434 }
4435 }
4436 }
4437 if (! done) {
4438 Nlm_AppendOnePopListChoice (c, temp);
4439 }
4440 #endif
4441 Nlm_SelectFont (Nlm_systemFont);
4442 wid = Nlm_StringWidth (temp);
4443 if (wid > swid) {
4444 swid = wid;
4445 }
4446 i++;
4447 }
4448 Nlm_GetRect ((Nlm_GraphiC) m, &r);
4449 #ifdef WIN_MAC
4450 wid = r.right - r.left - 26;
4451 if (swid > wid) {
4452 r.right = r.left + swid + 26;
4453 Nlm_SetRect ((Nlm_GraphiC) m, &r);
4454 Nlm_SetRect ((Nlm_GraphiC) c, &r);
4455 }
4456 if (swid > wid) {
4457 if (Nlm_GetVisible ((Nlm_GraphiC) c) && Nlm_GetAllParentsVisible ((Nlm_GraphiC) c)) {
4458 Nlm_InsetRect (&r, -2, -2);
4459 Nlm_OffsetRect (&r, 1, 1);
4460 Nlm_InvalRect (&r);
4461 }
4462 }
4463 #endif
4464 #ifdef WIN_MSWIN
4465 wid = r.right - r.left - 26;
4466 if (swid > wid) {
4467 r.right = (Nlm_Int2)(r.left + swid + 26);
4468 Nlm_SetRect ((Nlm_GraphiC) m, &r);
4469 Nlm_SetRect ((Nlm_GraphiC) c, &r);
4470 }
4471 u = Nlm_GetMenuPopup (m);
4472 if (u != NULL) {
4473 if (num > 10) {
4474 num = 10;
4475 }
4476 MoveWindow (u, r.left, r.top, r.right - r.left,
4477 r.bottom - r.top + (num + 1) * Nlm_stdLineHeight, TRUE);
4478 UpdateWindow (u);
4479 }
4480 #endif
4481 #ifdef WIN_MOTIF
4482 wid = r.right - r.left - 52;
4483 if (swid > wid) {
4484 r.right = r.left + swid + 52;
4485 Nlm_SetRect ((Nlm_GraphiC) m, &r);
4486 Nlm_SetRect ((Nlm_GraphiC) c, &r);
4487 }
4488 u = Nlm_GetMenuPopup (m);
4489 if (u != NULL) {
4490 XtVaSetValues (u,
4491 XmNx, (Position) r.left,
4492 XmNy, (Position) r.top,
4493 XmNwidth, (Dimension) (r.right - r.left),
4494 XmNheight, (Dimension) (r.bottom - r.top),
4495 NULL);
4496 }
4497 #endif
4498 Nlm_GetRect ((Nlm_GraphiC) m, &r);
4499 Nlm_DoAdjustPrnt ((Nlm_GraphiC) m, &r, TRUE, FALSE);
4500 Nlm_RestorePort (tempPort);
4501 }
4502
Nlm_PopupItems(Nlm_PopuP p,Nlm_CharPtr PNTR titles)4503 extern void Nlm_PopupItems (Nlm_PopuP p, Nlm_CharPtr PNTR titles)
4504
4505 {
4506 Nlm_ChoicE c;
4507
4508 c = (Nlm_ChoicE) p;
4509 if (c != NULL && titles != NULL) {
4510 if (Nlm_IsItAPopupList (c)) {
4511 Nlm_MultiAppendPopList (c, titles, TRUE);
4512 }
4513 }
4514 }
4515
4516
4517
4518 #ifdef WIN_MAC
Nlm_InvalPopup(Nlm_GraphiC m)4519 static void Nlm_InvalPopup (Nlm_GraphiC m)
4520
4521 {
4522 Nlm_RecT r;
4523
4524 if (Nlm_GetVisible (m) && Nlm_GetAllParentsVisible (m)) {
4525 Nlm_GetRect (m, &r);
4526 Nlm_InsetRect (&r, -1, -1);
4527 Nlm_InvalRect (&r);
4528 }
4529 }
4530 #endif
4531
4532
Nlm_SetPopupPosition(Nlm_GraphiC m,Nlm_RectPtr r,Nlm_Boolean savePort,Nlm_Boolean force)4533 static void Nlm_SetPopupPosition (Nlm_GraphiC m, Nlm_RectPtr r,
4534 Nlm_Boolean savePort, Nlm_Boolean force)
4535 {
4536 #ifdef WIN_MAC
4537 Nlm_RecT oldRect;
4538 Nlm_WindoW tempPort;
4539
4540 if (r == NULL) return;
4541
4542 if ( !Nlm_GetRealized( m ) )
4543 {
4544 Nlm_SetRect(m, r);
4545 return;
4546 }
4547
4548 Nlm_DoGetPosition (m, &oldRect);
4549 if (!force && Nlm_EqualRect(r, &oldRect)) return;
4550
4551 tempPort = Nlm_SavePortIfNeeded (m, savePort);
4552 Nlm_InvalPopup (m);
4553 Nlm_SetRect (m, r);
4554 Nlm_InvalPopup (m);
4555 Nlm_RestorePort (tempPort);
4556 #endif
4557 }
4558
4559
Nlm_GetPopupPosition(Nlm_GraphiC m,Nlm_RectPtr r)4560 static void Nlm_GetPopupPosition (Nlm_GraphiC m, Nlm_RectPtr r)
4561
4562 {
4563 #ifdef WIN_MAC
4564 if (r != NULL) {
4565 Nlm_GetRect (m, r);
4566 }
4567 #endif
4568 }
4569
4570
Nlm_SetPopListPosition(Nlm_GraphiC m,Nlm_RectPtr r,Nlm_Boolean savePort,Nlm_Boolean force)4571 static void Nlm_SetPopListPosition (Nlm_GraphiC m, Nlm_RectPtr r,
4572 Nlm_Boolean savePort, Nlm_Boolean force)
4573 {
4574 Nlm_ChoicE c;
4575 Nlm_RecT oldRect;
4576 Nlm_WindoW tempPort = NULL;
4577 #ifdef WIN_MSWIN
4578 Nlm_Int2 num;
4579 Nlm_PopupTool u;
4580 #endif
4581 #ifdef WIN_MOTIF
4582 Nlm_PopupTool u;
4583 #endif
4584
4585 if (r == NULL) return;
4586
4587 Nlm_DoGetPosition (m, &oldRect);
4588 if (!force && Nlm_EqualRect(r, &oldRect)) return;
4589
4590 if ( Nlm_GetRealized( m ) )
4591 {
4592 tempPort = Nlm_SavePortIfNeeded (m, savePort);
4593 #ifdef WIN_MAC
4594 Nlm_InvalPopup (m);
4595 #endif
4596 }
4597
4598 Nlm_SetRect (m, r);
4599 c = (Nlm_ChoicE) Nlm_GetChild (m);
4600 Nlm_SetRect ((Nlm_GraphiC) c, r);
4601
4602 if ( !Nlm_GetRealized( m ) ) return;
4603
4604 #ifdef WIN_MAC
4605 Nlm_InvalPopup (m);
4606 #endif
4607 #ifdef WIN_MSWIN
4608 u = Nlm_GetMenuPopup ((Nlm_MenU) m);
4609 if (u != NULL) {
4610 c = (Nlm_ChoicE) Nlm_GetChild (m);
4611 num = Nlm_GetNumItems (c);
4612 if (num > 10) {
4613 num = 10;
4614 }
4615 MoveWindow (u, r->left, r->top, r->right - r->left,
4616 r->bottom - r->top + (num + 1) * Nlm_stdLineHeight, TRUE);
4617 UpdateWindow (u);
4618 }
4619 #endif
4620 #ifdef WIN_MOTIF
4621
4622 /* Adjust the popup slightly to the left in */
4623 /* order to adjust for the space that it */
4624 /* leaves for the empty label. */
4625
4626 r->left += POPUP_LOCATION_ADJUSTMENT;
4627
4628 /* Set the Popup's size and position */
4629
4630 u = Nlm_GetMenuPopup ((Nlm_MenU) m);
4631 XtVaSetValues (u,
4632 XmNx, (Position) r->left,
4633 XmNy, (Position) r->top,
4634 XmNwidth, (Dimension) (r->right - r->left),
4635 XmNheight, (Dimension) (r->bottom - r->top),
4636 NULL);
4637 #endif
4638
4639 Nlm_RestorePort (tempPort);
4640 }
4641
4642
Nlm_GetPopListPosition(Nlm_GraphiC m,Nlm_RectPtr r)4643 static void Nlm_GetPopListPosition (Nlm_GraphiC m, Nlm_RectPtr r)
4644
4645 {
4646 if (r != NULL) {
4647 Nlm_GetRect (m, r);
4648 }
4649 }
4650
4651
Nlm_SetPopupChoicePosition(Nlm_GraphiC p,Nlm_RectPtr r,Nlm_Boolean savePort,Nlm_Boolean force)4652 static void Nlm_SetPopupChoicePosition(Nlm_GraphiC p, Nlm_RectPtr r,
4653 Nlm_Boolean savePort, Nlm_Boolean force)
4654 {
4655 Nlm_GraphiC m;
4656
4657 if (r != NULL) {
4658 m = Nlm_GetParent (p);
4659 Nlm_DoSetPosition (m, r, savePort, force);
4660 }
4661 }
4662
4663
Nlm_GetPopupChoicePosition(Nlm_GraphiC p,Nlm_RectPtr r)4664 static void Nlm_GetPopupChoicePosition (Nlm_GraphiC p, Nlm_RectPtr r)
4665
4666 {
4667 Nlm_GraphiC m;
4668
4669 if (r != NULL) {
4670 m = Nlm_GetParent (p);
4671 Nlm_GetRect (m, r);
4672 }
4673 }
4674
4675 #ifdef WIN_MSWIN
4676 /* Message cracker functions */
4677
MyCls_OnChar(HWND hwnd,UINT ch,int cRepeat)4678 static void MyCls_OnChar (HWND hwnd, UINT ch, int cRepeat)
4679
4680 {
4681 Nlm_PopuP p;
4682
4683 p = (Nlm_PopuP) GetProp (hwnd, (LPSTR) "Nlm_VibrantProp");
4684 handlechar = FALSE;
4685 if (ch == '\t') {
4686 Nlm_DoSendFocus ((Nlm_GraphiC) p, (Nlm_Char) ch);
4687 } else if (ch == '\n' || ch == '\r') {
4688 Nlm_DoSendFocus ((Nlm_GraphiC) p, (Nlm_Char) ch);
4689 } else {
4690 handlechar = TRUE;
4691 }
4692 }
4693
PopupProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)4694 static LRESULT CALLBACK EXPORT PopupProc (HWND hwnd, UINT message,
4695 WPARAM wParam, LPARAM lParam)
4696 {
4697 Nlm_PopuP p;
4698 BOOL call_win_proc = TRUE;
4699 LRESULT rsult = 0;
4700 HDC tempHDC;
4701 HWND tempHWnd;
4702
4703 if (Nlm_VibrantDisabled ()) {
4704 return CallWindowProc (lpfnOldPopupProc, hwnd, message, wParam, lParam);
4705 }
4706
4707 tempHWnd = Nlm_currentHWnd;
4708 tempHDC = Nlm_currentHDC;
4709 p = (Nlm_PopuP) GetProp (hwnd, (LPSTR) "Nlm_VibrantProp");
4710 Nlm_theWindow = Nlm_GetParentWindow ((Nlm_GraphiC) p);
4711 Nlm_currentHWnd = GetParent (hwnd);
4712 Nlm_currentHDC = Nlm_ParentWindowPort ((Nlm_GraphiC) p);
4713 Nlm_currentWindowTool = hwnd;
4714 Nlm_currentKey = '\0';
4715 Nlm_currentWParam = wParam;
4716 Nlm_currentLParam = lParam;
4717 Nlm_cmmdKey = FALSE;
4718 Nlm_ctrlKey = FALSE;
4719 Nlm_optKey = FALSE;
4720 Nlm_shftKey = FALSE;
4721 Nlm_dblClick = FALSE;
4722
4723 switch (message) {
4724 case WM_KEYDOWN:
4725 call_win_proc = !Nlm_ProcessKeydown((Nlm_GraphiC)p, wParam,
4726 VERT_PAGE|VERT_ARROW);
4727 break;
4728 case WM_CHAR:
4729 HANDLE_WM_CHAR (hwnd, wParam, lParam, MyCls_OnChar);
4730 call_win_proc = handlechar;
4731 break;
4732 }
4733
4734 if ( call_win_proc )
4735 rsult = CallWindowProc(lpfnOldPopupProc, hwnd, message, wParam, lParam);
4736
4737 Nlm_currentHWnd = tempHWnd;
4738 Nlm_currentHDC = tempHDC;
4739 Nlm_currentWindowTool = tempHWnd;
4740 return rsult;
4741 }
4742 #endif
4743
4744 extern Nlm_Int2 Nlm_internalMenuBarHeight;
4745 Nlm_Int2 Nlm_internalMenuBarHeight = 0;
4746
Nlm_NewMenuBar(Nlm_MenuBaR mb)4747 static void Nlm_NewMenuBar (Nlm_MenuBaR mb)
4748
4749 {
4750 Nlm_PoinT npt;
4751 Nlm_RecT r;
4752 #ifdef WIN_MSWIN
4753 Nlm_MenuTool h;
4754 Nlm_WindowTool wptr;
4755 #endif
4756 #ifdef WIN_MOTIF
4757 Nlm_MenuTool h;
4758 Cardinal n;
4759 Nlm_MainTool man;
4760 Arg wargs [10];
4761 #endif
4762
4763 Nlm_GetRect ((Nlm_GraphiC) mb, &r);
4764 Nlm_LoadPt (&npt, (Nlm_Int2)(r.left + 15), r.top);
4765 Nlm_LoadBoxData ((Nlm_BoX) mb, npt, npt, npt, npt.y, npt.x, 7, 7, 7, 7, 0, 0);
4766 #ifdef WIN_MSWIN
4767 h = CreateMenu ();
4768 wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) mb);
4769 SetMenu (wptr, h);
4770 Nlm_LoadMenuBarData (mb, h);
4771 #endif
4772 #ifdef WIN_MOTIF
4773 man = Nlm_ParentWindowMain ((Nlm_GraphiC) mb);
4774 n = 0;
4775 XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
4776 h = XmCreateMenuBar (man, (String) "", wargs, n);
4777
4778 Nlm_LoadMenuBarData (mb, h);
4779 #endif
4780 }
4781
4782
4783 #ifdef WIN_MAC
Nlm_NewDesktopMenu(Nlm_MenU m,Nlm_CharPtr title)4784 static void Nlm_NewDesktopMenu (Nlm_MenU m, Nlm_CharPtr title)
4785
4786 {
4787 OSErr err;
4788 Nlm_MenuTool h;
4789 Nlm_Char temp [256];
4790 CFStringRef cfTitle;
4791
4792 err = CreateNewMenu(nextMenuNum, 0, &h);
4793 if (err != noErr)
4794 return;
4795 /* M.I */
4796 Nlm_PrepareTitle (temp, title, sizeof (temp), TRUE);
4797 /* M.I */
4798 cfTitle = CFStringCreateWithBytes(kCFAllocatorDefault, (unsigned char *) temp,
4799 strlen(temp), kCFStringEncodingASCII, false);
4800 if (cfTitle) {
4801 SetMenuTitleWithCFString(h, cfTitle);
4802 CFRelease(cfTitle);
4803 }
4804
4805 Nlm_LoadMenuData (m, h, NULL, nextMenuNum, NULL);
4806 if (nextMenuNum < 32767) {
4807 nextMenuNum++;
4808 }
4809 }
4810 #endif
4811
4812
4813 #ifdef WIN_MOTIF
Nlm_SetupCmapVis(Nlm_GraphiC g,Arg * wargs,Cardinal * n)4814 static void Nlm_SetupCmapVis(Nlm_GraphiC g, Arg *wargs, Cardinal *n)
4815 {
4816 Colormap cMap;
4817 Visual *visual;
4818 if ( !Nlm_GetFixedColormap(g, &cMap, &visual) )
4819 {
4820 cMap = Nlm_VibrantDefaultColormap();
4821 visual = Nlm_VibrantDefaultVisual();
4822 }
4823
4824 XtSetArg(wargs[*n], XmNcolormap, cMap); (*n)++;
4825 XtSetArg(wargs[*n], XmNvisual, visual); (*n)++;
4826 }
4827 #endif
4828
4829
Nlm_NewPopup(Nlm_MenU m,Nlm_CharPtr title,Nlm_RectPtr r)4830 static void Nlm_NewPopup (Nlm_MenU m, Nlm_CharPtr title, Nlm_RectPtr r)
4831 {
4832 Nlm_MenuTool h;
4833 Nlm_PrompT p;
4834 Nlm_PopupTool pop;
4835 Nlm_Char temp [256];
4836 #ifdef WIN_MSWIN
4837 Nlm_MenuBaR mb;
4838 Nlm_MenuTool mbh;
4839 #endif
4840 #ifdef WIN_MOTIF
4841 Dimension height;
4842 Nlm_MenuBaR mb;
4843 Nlm_MenuTool mbh;
4844 Cardinal n;
4845 Arg wargs[16];
4846 #endif
4847
4848 h = NULL;
4849 p = NULL;
4850 pop = NULL;
4851 /* M.I */
4852 Nlm_PrepareTitle (temp, title, sizeof (temp), TRUE);
4853 /* M.I */
4854
4855 #ifdef WIN_MAC
4856 CreateNewMenu(nextMenuNum, 0, &h);
4857 p = Nlm_DependentPrompt ((Nlm_GraphiC) m, r, temp, Nlm_systemFont, 'c');
4858 #endif
4859
4860 #ifdef WIN_MSWIN
4861 p = NULL;
4862 mb = (Nlm_MenuBaR) Nlm_GetParent ((Nlm_GraphiC) m);
4863 mbh = Nlm_GetMenuBarHandle( mb );
4864 h = CreateMenu();
4865 Nlm_PrepareTitleMsWin(temp, title, sizeof (temp), NULL, TRUE);
4866 AppendMenu(mbh, MF_POPUP | MF_ENABLED, (UINT)h, temp);
4867 #endif
4868
4869 #ifdef WIN_MOTIF
4870 p = NULL;
4871 mb = (Nlm_MenuBaR) Nlm_GetParent ((Nlm_GraphiC) m);
4872 mbh = Nlm_GetMenuBarHandle (mb);
4873
4874 n = 0;
4875 XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
4876 Nlm_SetupCmapVis((Nlm_GraphiC)m, wargs, &n);
4877 h = XmCreatePulldownMenu (mbh, (String) "", wargs, n);
4878 XtRealizeWidget( h );
4879
4880 n = 0;
4881 XtSetArg (wargs [n], XmNsubMenuId, h); n++;
4882 XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
4883 Nlm_SetupCmapVis((Nlm_GraphiC)m, wargs, &n);
4884 pop = XmCreateCascadeButton (mbh, (String) "", wargs, n);
4885 Nlm_AddTitleAccel(pop, temp, 0);
4886 XtManageChild (pop);
4887
4888 if (Nlm_internalMenuBarHeight == 0) {
4889 XtVaGetValues (mbh, XmNborderWidth, &height, NULL);
4890 Nlm_internalMenuBarHeight += (Nlm_Int2) height;
4891 XtVaGetValues (mbh, XmNmarginHeight, &height, NULL);
4892 Nlm_internalMenuBarHeight += (Nlm_Int2) height;
4893 XtVaGetValues (mbh, XmNhighlightThickness, &height, NULL);
4894 Nlm_internalMenuBarHeight += (Nlm_Int2) height;
4895 XtVaGetValues (pop, XmNheight, &height, NULL);
4896 Nlm_internalMenuBarHeight += (Nlm_Int2) height;
4897 }
4898 #endif
4899
4900 Nlm_LoadMenuData (m, h, p, nextMenuNum, pop);
4901 if (nextMenuNum < 32767) {
4902 nextMenuNum++;
4903 }
4904 }
4905
4906
Nlm_NewFloatingPopup(Nlm_MenU m,Nlm_CharPtr title,Nlm_RectPtr mr)4907 static void Nlm_NewFloatingPopup (Nlm_MenU m, Nlm_CharPtr title, Nlm_RectPtr mr)
4908
4909 {
4910 #ifdef WIN_MAC
4911 Nlm_MenuTool h;
4912 Nlm_PrompT p;
4913 Nlm_Char temp [256];
4914 #endif
4915 #ifdef WIN_MSWIN
4916 Nlm_PopupTool c;
4917 Nlm_RecT r;
4918 Nlm_WindowTool wptr;
4919 Nlm_FntPtr fntptr;
4920 #endif
4921
4922 #ifdef WIN_MAC
4923 /* M.I */
4924 Nlm_PrepareTitle (temp, title, sizeof (temp), TRUE);
4925 /* M.I */
4926 CreateNewMenu(nextMenuNum, 0, &h);
4927 p = Nlm_DependentPrompt ((Nlm_GraphiC) m, mr, temp, Nlm_systemFont, 'c');
4928 Nlm_LoadMenuData (m, h, p, nextMenuNum, NULL);
4929 if (nextMenuNum < 32767) {
4930 nextMenuNum++;
4931 }
4932 #endif
4933 #ifdef WIN_MSWIN
4934 r = *mr;
4935 wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) m);
4936 c = CreateWindow ("Combobox", title,
4937 WS_CHILD | CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED,
4938 r.left, r.top, r.right - r.left,
4939 r.bottom - r.top, wptr, 0,
4940 Nlm_currentHInst, NULL);
4941 if (c != NULL) {
4942 SetProp (c, (LPSTR) "Nlm_VibrantProp", (Nlm_HandleTool) m);
4943 }
4944 Nlm_LoadMenuData (m, NULL, NULL, nextMenuNum, c);
4945 if (nextMenuNum < 32767) {
4946 nextMenuNum++;
4947 }
4948 fntptr = (Nlm_FntPtr) Nlm_HandLock (Nlm_systemFont);
4949 SetWindowFont(c, fntptr->handle, FALSE);
4950 Nlm_HandUnlock(Nlm_systemFont);
4951
4952 #endif
4953 #ifdef WIN_MOTIF
4954 #endif
4955 }
4956
4957 #ifdef WIN_MOTIF
Nlm_NewPopupList(Nlm_MenU m,Nlm_ChoicE c,Nlm_PupActnProc actn)4958 static void Nlm_NewPopupList (Nlm_MenU m, Nlm_ChoicE c, Nlm_PupActnProc actn)
4959
4960 {
4961 Nlm_MenuTool h;
4962 Nlm_ItemTool PNTR hdls;
4963 Nlm_ItemTool itool;
4964 Nlm_PopupTool pop;
4965 Nlm_RecT r;
4966 Nlm_WindowTool wptr;
4967 Pixel color;
4968 XmString label;
4969 Widget lbl;
4970 Cardinal n;
4971 Arg wargs [15];
4972
4973 Nlm_GetRect ((Nlm_GraphiC) m, &r);
4974 wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) m);
4975
4976 n = 0;
4977 Nlm_SetupCmapVis((Nlm_GraphiC)m, wargs, &n);
4978 h = XmCreatePulldownMenu (wptr, (String) "", wargs, n);
4979 XtRealizeWidget( h );
4980 XtAddEventHandler(h, ColormapChangeMask, FALSE,
4981 MenuShellColormapCB, (XtPointer) m);
4982
4983 n = 0;
4984 XtSetArg (wargs [n], XmNx, (Position) r.left); n++;
4985 XtSetArg (wargs [n], XmNy, (Position) r.top ); n++;
4986 XtSetArg (wargs [n], XmNwidth, (Dimension) (r.right - r.left)); n++;
4987 XtSetArg (wargs [n], XmNheight, (Dimension) (r.bottom - r.top )); n++;
4988 XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
4989 XtSetArg (wargs [n], XmNhighlightThickness, 0); n++;
4990 XtSetArg (wargs [n], XmNsubMenuId, h); n++;
4991 /*
4992 XtSetArg (wargs [n], XmNorientation, XmVERTICAL); n++;
4993 */
4994
4995 pop = XmCreateOptionMenu (wptr, (String) "", wargs, n);
4996 Nlm_OverrideStdTranslations((Nlm_GraphiC)m, pop,
4997 VERT_PAGE|VERT_ARROW|HORIZ_PAGE|HORIZ_ARROW);
4998
4999 /*
5000 lbl = XmOptionLabelGadget (pop);
5001 XtVaGetValues (lbl, XmNforeground, &color, 0);
5002
5003 n = 0;
5004 label = XmStringCreateSimple ("");
5005 XtSetArg (wargs [n], XmNlabelString, label); n++;
5006 XtSetArg (wargs [n], XmNwidth, (Dimension) 0); n++;
5007 XtSetArg (wargs [n], XmNheight, (Dimension) 0); n++;
5008 XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
5009 XtSetArg (wargs [n], XmNhighlightThickness, (Dimension) 0); n++;
5010 XtSetArg (wargs [n], XmNbackground, (Pixel) color); n++;
5011 XtSetValues (lbl, wargs, n);
5012 XmStringFree (label);
5013 */
5014
5015 XtManageChild (pop);
5016
5017 Nlm_LoadMenuData (m, h, NULL, nextMenuNum, pop);
5018 if (nextMenuNum < 32767) {
5019 nextMenuNum++;
5020 }
5021
5022 n = 0;
5023 label = XmStringCreateSimple (" ");
5024 XtSetArg (wargs [n], XmNlabelString, label); n++;
5025 XtSetArg (wargs [n], XmNfontList, Nlm_XfontList); n++;
5026 XtSetArg (wargs [n], XmNmarginHeight, 5); n++;
5027 XtSetArg (wargs [n], XmNmarginWidth, 5); n++;
5028 XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
5029 XtSetArg (wargs [n], XmNheight, Nlm_stdLineHeight+10); n++;
5030 XtSetArg (wargs [n], XmNrecomputeSize, FALSE); n++;
5031 itool = XmCreatePushButton (h, (String) "", wargs, n);
5032 XtAddCallback (itool, XmNactivateCallback, Nlm_MenuCallback, (XtPointer) c);
5033 XmStringFree (label);
5034 XtManageChild (itool);
5035 hdls = (Nlm_ItemTool *) Nlm_MemNew (64 * sizeof (Nlm_ItemTool));
5036 hdls [63] = itool;
5037 XtVaSetValues (pop, XmNmenuHistory, hdls [63], NULL);
5038 Nlm_LoadItemData ((Nlm_IteM) c, m, 1, pop);
5039 Nlm_LoadChoiceData (c, 0, TRUE, 0, hdls);
5040 Nlm_LoadAction ((Nlm_GraphiC) c, (Nlm_ActnProc) actn);
5041 }
5042 #endif /* WIN_MOTIF */
5043
5044
5045 #if defined(WIN_MSWIN) || defined(WIN_MAC)
Nlm_NewPopListMenu(Nlm_MenU m)5046 static void Nlm_NewPopListMenu (Nlm_MenU m)
5047 {
5048 Nlm_PopupTool c;
5049 Nlm_MenuTool h;
5050 #ifdef WIN_MSWIN
5051 Nlm_RecT r;
5052 Nlm_WindowTool wptr;
5053 Nlm_FntPtr fntptr;
5054 #endif
5055
5056 #ifdef WIN_MAC
5057 CreateNewMenu(nextMenuNum, 0, &h);
5058 c = NULL;
5059 Nlm_LoadMenuData (m, h, NULL, nextMenuNum, c);
5060 #endif
5061 #ifdef WIN_MSWIN
5062 Nlm_GetRect ((Nlm_GraphiC) m, &r);
5063 h = NULL;
5064 wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) m);
5065 c = CreateWindow ("Combobox", "", WS_CHILD | CBS_DROPDOWNLIST | WS_VSCROLL,
5066 r.left, r.top, r.right - r.left,
5067 r.bottom - r.top, wptr, 0,
5068 Nlm_currentHInst, NULL);
5069 if (c != NULL) {
5070 SetProp (c, (LPSTR) "Nlm_VibrantProp", (Nlm_HandleTool) m);
5071 }
5072 Nlm_LoadMenuData (m, h, NULL, nextMenuNum, c);
5073 if (lpfnNewPopupProc == NULL) {
5074 lpfnNewPopupProc = (WNDPROC) MakeProcInstance ((FARPROC) PopupProc, Nlm_currentHInst);
5075 }
5076 if (lpfnOldPopupProc == NULL) {
5077 lpfnOldPopupProc = (WNDPROC) GetWindowLongPtr (c, GWLP_WNDPROC);
5078 } else if (lpfnOldPopupProc != (WNDPROC) GetWindowLongPtr (c, GWLP_WNDPROC)) {
5079 Nlm_Message (MSG_ERROR, "PopupProc subclass error");
5080 }
5081 SetWindowLongPtr (c, GWLP_WNDPROC, (LONG_PTR) lpfnNewPopupProc);
5082 fntptr = (Nlm_FntPtr) Nlm_HandLock (Nlm_systemFont);
5083 SetWindowFont(c, fntptr->handle, FALSE);
5084 Nlm_HandUnlock(Nlm_systemFont);
5085
5086 #endif
5087
5088 if (nextMenuNum < 32767)
5089 nextMenuNum++;
5090 }
5091 #endif /* WIN_MSWIN | WIN_MAC */
5092
5093
5094 #ifdef WIN_MAC
Nlm_NewSubMenu(Nlm_MenU m)5095 static void Nlm_NewSubMenu (Nlm_MenU m)
5096
5097 {
5098 OSErr err;
5099 Nlm_MenuTool h;
5100
5101 err = CreateNewMenu(nextMenuNum, 0, &h);
5102 Nlm_LoadMenuData (m, h, NULL, nextMenuNum, NULL);
5103 if (nextMenuNum < 32767) {
5104 nextMenuNum++;
5105 }
5106 }
5107
Nlm_NewSubmenuItem(Nlm_IteM i,Nlm_MenU sub,Nlm_CharPtr title)5108 static void Nlm_NewSubmenuItem (Nlm_IteM i, Nlm_MenU sub, Nlm_CharPtr title)
5109
5110 {
5111 Nlm_MenuTool h;
5112 Nlm_MenuTool mt;
5113 Nlm_Int2 index;
5114 Nlm_MenU m;
5115
5116 m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) i);
5117 Nlm_AppendItems (m, i, title, CASCADE_ITEM, FALSE);
5118 index = Nlm_CountMenuItems ((Nlm_GraphiC) m);
5119 Nlm_LoadItemData (i, sub, index, NULL);
5120 h = Nlm_GetMenuHandle (sub);
5121 InsertMenu (h, -1);
5122 mt = Nlm_GetMenuHandle(m);
5123 SetMenuItemHierarchicalMenu(mt, index, h);
5124 }
5125 #endif
5126
5127 #ifdef WIN_MSWIN
Nlm_NewSubMenuAndItem(Nlm_IteM i,Nlm_MenU sub,Nlm_CharPtr title)5128 static void Nlm_NewSubMenuAndItem (Nlm_IteM i, Nlm_MenU sub, Nlm_CharPtr title)
5129 {
5130 Nlm_MenuTool h;
5131 Nlm_Int2 index;
5132 Nlm_MenU m;
5133 Nlm_MenuTool mh;
5134
5135 m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) i);
5136 mh = Nlm_GetMenuHandle (m);
5137 h = CreateMenu ();
5138 AppendMenu (mh, MF_POPUP | MF_ENABLED, (UINT) h, title);
5139 Nlm_LoadMenuData (sub, h, NULL, nextMenuNum, NULL);
5140 if (nextMenuNum < 32767) {
5141 nextMenuNum++;
5142 }
5143 index = Nlm_CountMenuItems ((Nlm_GraphiC) m);
5144 Nlm_LoadItemData (i, sub, index, NULL);
5145 }
5146 #endif
5147
5148
5149 #ifdef WIN_MOTIF
Nlm_NewCascadingMenu(Nlm_MenU m,Nlm_IteM i,Nlm_MenU sub,Nlm_CharPtr title)5150 static void Nlm_NewCascadingMenu (Nlm_MenU m, Nlm_IteM i,
5151 Nlm_MenU sub, Nlm_CharPtr title)
5152
5153 {
5154 Nlm_MenuTool h;
5155 Nlm_MenuTool mh;
5156 Nlm_PopupTool pop;
5157 Cardinal n;
5158 Arg wargs [10];
5159
5160 mh = Nlm_GetMenuHandle (m);
5161
5162 n = 0;
5163 Nlm_SetupCmapVis((Nlm_GraphiC)m, wargs, &n);
5164 h = XmCreatePulldownMenu (mh, (String) "", wargs, n);
5165 XtRealizeWidget( h );
5166
5167 n = 0;
5168 XtSetArg (wargs [n], XmNfontList, Nlm_XfontList); n++;
5169 XtSetArg (wargs [n], XmNmarginHeight, 5); n++;
5170 XtSetArg (wargs [n], XmNmarginWidth, 5); n++;
5171 XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
5172 XtSetArg (wargs [n], XmNsubMenuId, h); n++;
5173 /* XtSetArg (wargs [n], XmNrecomputeSize, FALSE); n++;*/
5174 pop = XmCreateCascadeButton (mh, (String) "", wargs, n);
5175 Nlm_AddTitleAccel(pop, title, 0);
5176 XtManageChild (pop);
5177
5178 Nlm_LoadMenuData (sub, h, NULL, nextMenuNum, pop);
5179 Nlm_LoadItemData (i, sub, 0, pop);
5180 }
5181 #endif
5182
5183
5184
Nlm_NewComm(Nlm_IteM i,Nlm_CharPtr title,Nlm_ItmActnProc actn)5185 static void Nlm_NewComm (Nlm_IteM i, Nlm_CharPtr title, Nlm_ItmActnProc actn)
5186
5187 {
5188 Nlm_Int2 index;
5189 Nlm_ItemTool itool;
5190 Nlm_MenU m;
5191 Nlm_Char temp [256];
5192
5193 m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) i);
5194 /* M.I */
5195 Nlm_PrepareTitle (temp, title, sizeof (temp), FALSE);
5196 /* M.I */
5197 itool = Nlm_AppendItems (m, i, temp, COMMAND_ITEM, FALSE);
5198 index = Nlm_CountMenuItems ((Nlm_GraphiC) m);
5199 Nlm_LoadItemData (i, NULL, index, itool);
5200 Nlm_LoadAction ((Nlm_GraphiC) i, (Nlm_ActnProc) actn);
5201 #ifdef WIN_MOTIF
5202 XtManageChild (itool);
5203 #endif
5204 }
5205
5206
Nlm_NewStat(Nlm_IteM i,Nlm_CharPtr title,Nlm_ItmActnProc actn)5207 static void Nlm_NewStat (Nlm_IteM i, Nlm_CharPtr title, Nlm_ItmActnProc actn)
5208
5209 {
5210 Nlm_Int2 index;
5211 Nlm_ItemTool itool;
5212 Nlm_MenU m;
5213 Nlm_Char temp [256];
5214
5215 m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) i);
5216 /* M.I */
5217 Nlm_PrepareTitle (temp, title, sizeof (temp), FALSE);
5218 /* M.I */
5219 itool = Nlm_AppendItems (m, i, temp, STATUS_ITEM, FALSE);
5220 index = Nlm_CountMenuItems ((Nlm_GraphiC) m);
5221 Nlm_LoadItemData (i, NULL, index, itool);
5222 Nlm_LoadAction ((Nlm_GraphiC) i, (Nlm_ActnProc) actn);
5223 #ifdef WIN_MOTIF
5224 XtManageChild (itool);
5225 #endif
5226 }
5227
5228
Nlm_NewChoice(Nlm_ChoicE c,Nlm_ChsActnProc actn)5229 static void Nlm_NewChoice (Nlm_ChoicE c, Nlm_ChsActnProc actn)
5230
5231 {
5232 Nlm_Int2 index;
5233 Nlm_MenU m;
5234
5235 m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) c);
5236 index = Nlm_CountMenuItems ((Nlm_GraphiC) m);
5237 Nlm_LoadItemData ((Nlm_IteM) c, NULL, (Nlm_Int2)(index + 1), NULL);
5238 Nlm_LoadChoiceData (c, 0, FALSE, 0, NULL);
5239 Nlm_LoadAction ((Nlm_GraphiC) c, (Nlm_ActnProc) actn);
5240 }
5241
5242
5243 #if defined(WIN_MAC) || defined(WIN_MSWIN)
Nlm_NewPopListChoice(Nlm_ChoicE c,Nlm_PupActnProc actn)5244 static void Nlm_NewPopListChoice (Nlm_ChoicE c, Nlm_PupActnProc actn)
5245 {
5246 Nlm_Int2 index;
5247 Nlm_MenU sub;
5248 #ifdef WIN_MAC
5249 Nlm_MenU m;
5250 #endif
5251
5252 sub = NULL;
5253 index = 0;
5254 #ifdef WIN_MAC
5255 m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) c);
5256 index = Nlm_CountMenuItems ((Nlm_GraphiC) m);
5257 #endif
5258 #ifdef WIN_MSWIN
5259 index = 0;
5260 #endif
5261 Nlm_LoadItemData ((Nlm_IteM) c, sub, (Nlm_Int2)(index + 1), NULL);
5262 Nlm_LoadChoiceData (c, 0, TRUE, 0, NULL);
5263 Nlm_LoadAction ((Nlm_GraphiC) c, (Nlm_ActnProc) actn);
5264 }
5265 #endif /* WIN_MAC | WIN_MSWIN */
5266
5267
5268 #ifdef WIN_MAC
Nlm_NewDeskAcc(Nlm_ChoicE c)5269 static void Nlm_NewDeskAcc (Nlm_ChoicE c)
5270 {
5271 Nlm_Int2 frst;
5272 Nlm_Int2 index;
5273 Nlm_MenU m;
5274
5275 m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) c);
5276 index = Nlm_CountMenuItems ((Nlm_GraphiC) m);
5277 frst = index + 1;
5278 Nlm_AppendResources (m, 'DRVR', FALSE);
5279 index = Nlm_CountMenuItems ((Nlm_GraphiC) m);
5280 Nlm_LoadItemData ((Nlm_IteM) c, NULL, frst, NULL);
5281 Nlm_LoadChoiceData (c, index + 1 - frst, FALSE, 0, NULL);
5282 }
5283 #endif /* WIN_MAC */
5284
5285
Nlm_NewFontGroup(Nlm_ChoicE c)5286 static void Nlm_NewFontGroup (Nlm_ChoicE c)
5287
5288 {
5289 #ifdef WIN_MAC
5290 Nlm_MenU m;
5291 Nlm_Int2 newval;
5292 Nlm_Int2 oldval;
5293
5294 m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) c);
5295 oldval = Nlm_CountMenuItems ((Nlm_GraphiC) m);
5296 Nlm_AppendResources (m, 'FOND', FALSE);
5297 newval = Nlm_CountMenuItems ((Nlm_GraphiC) m);
5298 Nlm_LoadItemData ((Nlm_IteM) c, NULL, oldval + 1, NULL);
5299 Nlm_LoadChoiceData (c, newval - oldval, FALSE, 0, NULL);
5300 #endif
5301 #ifdef WIN_MSWIN
5302 /*
5303 WNDPROC inst;
5304 */
5305 Nlm_MenU m;
5306 Nlm_Int2 newval;
5307 Nlm_Int2 oldval;
5308
5309 m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) c);
5310 oldval = Nlm_CountMenuItems ((Nlm_GraphiC) m);
5311 /*
5312 inst = (WNDPROC) MakeProcInstance (EnumAllFaces, Nlm_currentHInst);
5313 FreeProcInstance (inst);
5314 */
5315 newval = Nlm_CountMenuItems ((Nlm_GraphiC) m);
5316 Nlm_LoadItemData ((Nlm_IteM) c, NULL, (Nlm_Int2)(oldval + 1), NULL);
5317 Nlm_LoadChoiceData (c, (Nlm_Int2)(newval - oldval), FALSE, 0, NULL);
5318 #endif
5319 #ifdef WIN_MOTIF
5320 #endif
5321 }
5322
5323 #ifdef WIN_MAC
Nlm_CreateDesktopMenuBar(Nlm_WindoW w)5324 static Nlm_MenuBaR Nlm_CreateDesktopMenuBar (Nlm_WindoW w)
5325
5326 {
5327 Nlm_MenuBaR mb;
5328 Nlm_MenuBarData mbdata;
5329 Nlm_RecT r;
5330
5331 Nlm_LoadRect (&r, 0, 0, 0, 0);
5332 mb = (Nlm_MenuBaR) Nlm_HandNew (sizeof (Nlm_MenuBarRec));
5333 if (mb != NULL) {
5334 Nlm_LoadGraphicData ((Nlm_GraphiC) mb, NULL, (Nlm_GraphiC) w, NULL, NULL,
5335 desktopMenuBarProcs, NULL, &r, TRUE, FALSE, NULL, NULL);
5336 if (Nlm_nextIdNumber < 32767) {
5337 Nlm_nextIdNumber++;
5338 }
5339 Nlm_SetWindowMenuBar (w, mb);
5340 Nlm_SetVisible ((Nlm_GraphiC) mb, TRUE);
5341 Nlm_GetMenuBarData (mb, &mbdata);
5342 mbdata.notJustSubMenu = FALSE;
5343 Nlm_SetMenuBarData (mb, &mbdata);
5344 }
5345 return mb;
5346 }
5347 #endif
5348
Nlm_CreateWindowMenuBar(Nlm_WindoW w)5349 static Nlm_MenuBaR Nlm_CreateWindowMenuBar (Nlm_WindoW w)
5350
5351 {
5352 Nlm_MenuBaR mb;
5353 Nlm_RecT r;
5354 #ifdef WIN_MAC
5355 Nlm_BoxData bdata;
5356 #endif
5357
5358 Nlm_LoadRect (&r, 0, 0, 0, 20);
5359 mb = (Nlm_MenuBaR) Nlm_HandNew (sizeof (Nlm_MenuBarRec));
5360 if (mb != NULL) {
5361 Nlm_LoadGraphicData ((Nlm_GraphiC) mb, NULL, (Nlm_GraphiC) w, NULL, NULL,
5362 windowMenuBarProcs, NULL, &r, TRUE, FALSE, NULL, NULL);
5363 if (Nlm_nextIdNumber < 32767) {
5364 Nlm_nextIdNumber++;
5365 }
5366 }
5367 if (mb != NULL) {
5368 #ifdef WIN_MAC
5369 Nlm_DoAdjustPrnt ((Nlm_GraphiC) mb, &r, TRUE, FALSE);
5370 Nlm_GetBoxData ((Nlm_BoX) w, &bdata);
5371 bdata.topRow = bdata.limitPoint.y + bdata.yMargin;
5372 bdata.nextCol = bdata.resetPoint.x;
5373 bdata.nextPoint.y = bdata.topRow;
5374 bdata.nextPoint.x = bdata.nextCol;
5375 Nlm_SetBoxData ((Nlm_BoX) w, &bdata);
5376 #endif
5377 Nlm_SetWindowMenuBar (w, mb);
5378 Nlm_NewMenuBar (mb);
5379 Nlm_DoShow ((Nlm_GraphiC) mb, TRUE, FALSE);
5380 }
5381 return mb;
5382 }
5383
Nlm_PulldownMenu(Nlm_WindoW w,Nlm_CharPtr title)5384 extern Nlm_MenU Nlm_PulldownMenu (Nlm_WindoW w, Nlm_CharPtr title)
5385
5386 {
5387 Nlm_MenU m;
5388 Nlm_MenuBaR mb;
5389 Nlm_RecT r;
5390 Nlm_WindoW tempPort;
5391 #ifdef WIN_MAC
5392 Nlm_MenuBarData mbdata;
5393 Nlm_PoinT npt;
5394 #endif
5395 #ifdef WIN_MSWIN
5396 Nlm_PoinT npt;
5397 #endif
5398
5399 m = NULL;
5400 if (w != NULL && title != NULL && w == Nlm_GetParentWindow ((Nlm_GraphiC) w)) {
5401 tempPort = Nlm_SavePort ((Nlm_GraphiC) w);
5402 Nlm_SelectFont (Nlm_systemFont);
5403 mb = Nlm_GetWindowMenuBar (w);
5404 if (mb == NULL) {
5405 mb = Nlm_CreateWindowMenuBar (w);
5406 }
5407 #ifdef WIN_MAC
5408 Nlm_GetNextPosition ((Nlm_GraphiC) mb, &npt);
5409 r.top = npt.y;
5410 r.left = npt.x;
5411 r.bottom = r.top + 20;
5412 r.right = r.left + Nlm_StringWidth (title) + 5;
5413 Nlm_RecordRect ((Nlm_GraphiC) mb, &r);
5414 Nlm_Advance ((Nlm_GraphiC) mb);
5415 #endif
5416 #ifdef WIN_MSWIN
5417 Nlm_GetNextPosition ((Nlm_GraphiC) mb, &npt);
5418 r.top = npt.y;
5419 r.left = npt.x;
5420 r.bottom = r.top;
5421 r.right = (Nlm_Int2)(r.left + Nlm_StringWidth(title) + 50);
5422 Nlm_DoAdjustPrnt ((Nlm_GraphiC) mb, &r, TRUE, FALSE);
5423 Nlm_Advance ((Nlm_GraphiC) mb);
5424 #endif
5425 #ifdef WIN_MOTIF
5426 Nlm_LoadRect (&r, 0, 0, 0, 0);
5427 #endif
5428 m = (Nlm_MenU) Nlm_CreateLink ((Nlm_GraphiC) mb, &r, sizeof (Nlm_MenuRec),
5429 windowPulldownProcs);
5430 if (m != NULL) {
5431 r.top += 3;
5432 Nlm_NewPopup (m, title, &r);
5433 Nlm_DoShow ((Nlm_GraphiC) m, TRUE, FALSE);
5434 }
5435 Nlm_RestorePort (tempPort);
5436 } else if (title != NULL) {
5437 #ifdef WIN_MAC
5438 w = Nlm_desktopWindow;
5439 mb = Nlm_GetWindowMenuBar (w);
5440 if (mb == NULL) {
5441 mb = Nlm_CreateDesktopMenuBar (w);
5442 }
5443 if (mb != NULL) {
5444 Nlm_GetMenuBarData (mb, &mbdata);
5445 mbdata.notJustSubMenu = TRUE;
5446 Nlm_SetMenuBarData (mb, &mbdata);
5447 }
5448 Nlm_LoadRect (&r, 0, 0, 0, 0);
5449 m = (Nlm_MenU) Nlm_CreateLink ((Nlm_GraphiC) mb, &r, sizeof (Nlm_MenuRec),
5450 desktopPulldownProcs);
5451 if (m != NULL) {
5452 Nlm_NewDesktopMenu (m, title);
5453 Nlm_DoShow ((Nlm_GraphiC) m, TRUE, TRUE);
5454 }
5455 #endif
5456 }
5457 return m;
5458 }
5459
Nlm_AppleMenu(Nlm_WindoW w)5460 extern Nlm_MenU Nlm_AppleMenu (Nlm_WindoW w)
5461
5462 {
5463 Nlm_MenU m;
5464 #ifdef WIN_MAC
5465 Nlm_Char appleStr [2] = {'\24', '\0'};
5466 #endif
5467
5468 m = NULL;
5469 #ifdef WIN_MAC
5470 m = Nlm_PulldownMenu (w, appleStr);
5471 #endif
5472 return m;
5473 }
5474
Nlm_PopupMenu(Nlm_GrouP prnt,Nlm_CharPtr title)5475 extern Nlm_MenU Nlm_PopupMenu (Nlm_GrouP prnt, Nlm_CharPtr title)
5476
5477 {
5478 Nlm_MenU m;
5479 Nlm_PoinT npt;
5480 Nlm_RecT p;
5481 Nlm_RecT r;
5482 Nlm_WindoW tempPort;
5483 Nlm_Int2 wid;
5484
5485 m = NULL;
5486 if (prnt != NULL && title != NULL) {
5487 tempPort = Nlm_SavePort ((Nlm_GraphiC) prnt);
5488 Nlm_GetNextPosition ((Nlm_GraphiC) prnt, &npt);
5489 Nlm_SelectFont (Nlm_systemFont);
5490 wid = Nlm_StringWidth (title);
5491 r.left = npt.x;
5492 r.top = npt.y;
5493 r.right = (Nlm_Int2)(r.left + wid + 10);
5494 r.bottom = (Nlm_Int2)(r.top + Nlm_stdLineHeight + 8);
5495 m = (Nlm_MenU) Nlm_CreateLink ((Nlm_GraphiC) prnt, &r, sizeof (Nlm_MenuRec), popupProcs);
5496 if (m != NULL) {
5497 p = r;
5498 Nlm_UpsetRect (&p, 1, 1, 2, 2);
5499 Nlm_NewFloatingPopup (m, title, &p);
5500 Nlm_DoAdjustPrnt ((Nlm_GraphiC) m, &r, TRUE, FALSE);
5501 Nlm_DoShow ((Nlm_GraphiC) m, TRUE, FALSE);
5502 }
5503 Nlm_RestorePort (tempPort);
5504 }
5505 return m;
5506 }
5507
Nlm_SubMenu(Nlm_MenU m,Nlm_CharPtr title)5508 extern Nlm_MenU Nlm_SubMenu (Nlm_MenU m, Nlm_CharPtr title)
5509 /*
5510 * WARNING -- Sub menus on the Macintosh link into the desktop window menu
5511 * bar in addition to their own parent items, so removing windows with
5512 * sub menus in them is dangerous.
5513 */
5514 {
5515 Nlm_IteM i;
5516 Nlm_RecT r;
5517 Nlm_MenU sub = NULL;
5518 Nlm_Char temp [256];
5519 #ifdef WIN_MAC
5520 Nlm_MenuBaR mb;
5521 Nlm_WindoW w;
5522 #endif
5523
5524 if (!m || !title)
5525 return NULL;
5526
5527 #ifdef WIN_MAC
5528 w = Nlm_desktopWindow;
5529 mb = Nlm_GetWindowMenuBar (w);
5530 if (mb == NULL) {
5531 mb = Nlm_CreateDesktopMenuBar (w);
5532 }
5533 Nlm_LoadRect (&r, 0, 0, 0, 0);
5534 sub = (Nlm_MenU) Nlm_CreateLink ((Nlm_GraphiC) mb, &r, sizeof (Nlm_MenuRec), subMenuProcs);
5535 if ( !sub )
5536 return NULL;
5537
5538 Nlm_NewSubMenu (sub);
5539 Nlm_SetVisible ((Nlm_GraphiC) sub, TRUE);
5540 Nlm_PrepareTitle (temp, title, sizeof (temp), TRUE);
5541 /*
5542 len = (Nlm_Int2) Nlm_StringLen (temp);
5543 tag = Nlm_GetMenuTag (sub);
5544 if (len < 250) {
5545 temp [len] = '/';
5546 temp [len + 1] = '\33';
5547 temp [len + 2] = '!';
5548 temp [len + 3] = (Nlm_Char) tag;
5549 temp [len + 4] = '\0';
5550 }
5551 */
5552 i = (Nlm_IteM) Nlm_CreateLink ((Nlm_GraphiC) m, &r, sizeof (Nlm_ItemRec), subItemProcs);
5553 if (i != NULL) {
5554 Nlm_NewSubmenuItem (i, sub, temp);
5555 Nlm_SetParent ((Nlm_GraphiC) sub, (Nlm_GraphiC) i);
5556 Nlm_SetVisible ((Nlm_GraphiC) i, TRUE);
5557 }
5558 #endif
5559
5560 #if defined(WIN_MSWIN) || defined(WIN_MOTIF)
5561 sub = (Nlm_MenU) Nlm_HandNew( sizeof(Nlm_MenuRec) );
5562 if ( !sub )
5563 return NULL;
5564
5565 Nlm_LoadRect(&r, 0, 0, 0, 0);
5566 Nlm_LoadGraphicData((Nlm_GraphiC)sub, NULL, (Nlm_GraphiC)m, NULL, NULL,
5567 subMenuProcs, NULL, &r, TRUE, FALSE, NULL, NULL);
5568 if (Nlm_nextIdNumber < 32767)
5569 Nlm_nextIdNumber++;
5570 Nlm_PrepareTitle(temp, title, sizeof(temp), TRUE);
5571 i = (Nlm_IteM)Nlm_CreateLink((Nlm_GraphiC)m,
5572 &r, sizeof(Nlm_ItemRec), subItemProcs);
5573 if (i != NULL) {
5574 #ifdef WIN_MSWIN
5575 Nlm_PrepareTitleMsWin(temp, title, sizeof(temp), NULL, TRUE);
5576 Nlm_NewSubMenuAndItem(i, sub, temp);
5577 #else /* WIN_MOTIF */
5578 Nlm_NewCascadingMenu(m, i, sub, temp);
5579 #endif
5580 Nlm_SetParent ((Nlm_GraphiC) sub, (Nlm_GraphiC)i);
5581 Nlm_SetVisible((Nlm_GraphiC) sub, TRUE);
5582 Nlm_SetVisible((Nlm_GraphiC) i, TRUE);
5583 }
5584 #endif
5585
5586 return sub;
5587 }
5588
Nlm_CommandItem(Nlm_MenU m,Nlm_CharPtr title,Nlm_ItmActnProc actn)5589 extern Nlm_IteM Nlm_CommandItem (Nlm_MenU m, Nlm_CharPtr title, Nlm_ItmActnProc actn)
5590
5591 {
5592 Nlm_IteM i;
5593 Nlm_RecT r;
5594
5595 i = NULL;
5596 if (m != NULL && title != NULL) {
5597 Nlm_LoadRect (&r, 0, 0, 0, 0);
5598 i = (Nlm_IteM) Nlm_CreateLink ((Nlm_GraphiC) m, &r, sizeof (Nlm_ItemRec), commandItemProcs);
5599 if (i != NULL) {
5600 Nlm_NewComm (i, title, actn);
5601 Nlm_SetVisible ((Nlm_GraphiC) i, TRUE);
5602 }
5603 }
5604 return i;
5605 }
5606
Nlm_StatusItem(Nlm_MenU m,Nlm_CharPtr title,Nlm_ItmActnProc actn)5607 extern Nlm_IteM Nlm_StatusItem (Nlm_MenU m, Nlm_CharPtr title, Nlm_ItmActnProc actn)
5608
5609 {
5610 Nlm_IteM i;
5611 Nlm_RecT r;
5612
5613 i = NULL;
5614 if (m != NULL && title != NULL) {
5615 Nlm_LoadRect (&r, 0, 0, 0, 0);
5616 i = (Nlm_IteM) Nlm_CreateLink ((Nlm_GraphiC) m, &r, sizeof (Nlm_ItemRec), statusItemProcs);
5617 if (i != NULL) {
5618 Nlm_NewStat (i, title, actn);
5619 Nlm_SetVisible ((Nlm_GraphiC) i, TRUE);
5620 }
5621 }
5622 return i;
5623 }
5624
5625
Nlm_SeparatorItem(Nlm_MenU m)5626 extern void Nlm_SeparatorItem (Nlm_MenU m)
5627
5628 {
5629 Nlm_MenuTool h;
5630 #ifdef WIN_MSWIN
5631 Nlm_IteM i;
5632 Nlm_RecT r;
5633 #endif
5634 #ifdef WIN_MOTIF
5635 Nlm_ItemTool itool;
5636 Cardinal n;
5637 Arg wargs [10];
5638 #endif
5639
5640 if (m != NULL) {
5641 h = Nlm_GetMenuHandle (m);
5642 #ifdef WIN_MAC
5643 AppendMenuItemTextWithCFString(h, CFSTR("-"), kMenuItemAttrSeparator, 0, NULL);
5644 #endif
5645 #ifdef WIN_MSWIN
5646 Nlm_LoadRect (&r, 0, 0, 0, 0);
5647 i = (Nlm_IteM) Nlm_CreateLink ((Nlm_GraphiC) m, &r, sizeof (Nlm_ItemRec), statusItemProcs);
5648 if (i != NULL) {
5649 Nlm_NewStat (i, NULL, NULL);
5650 Nlm_SetVisible ((Nlm_GraphiC) i, TRUE);
5651 }
5652 AppendMenu (h, MF_SEPARATOR, 0, NULL);
5653 #endif
5654 #ifdef WIN_MOTIF
5655 n = 0;
5656 XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
5657 itool = XmCreateSeparator (h, (String) "", wargs, n);
5658 XtManageChild (itool);
5659 #endif
5660 }
5661 }
5662
5663
Nlm_ChoiceGroup(Nlm_MenU m,Nlm_ChsActnProc actn)5664 extern Nlm_ChoicE Nlm_ChoiceGroup (Nlm_MenU m, Nlm_ChsActnProc actn)
5665
5666 {
5667 Nlm_ChoicE c;
5668 Nlm_RecT r;
5669
5670 c = NULL;
5671 if (m != NULL) {
5672 Nlm_LoadRect (&r, 0, 0, 0, 0);
5673 c = (Nlm_ChoicE) Nlm_CreateLink ((Nlm_GraphiC) m, &r, sizeof (Nlm_ChoiceRec),
5674 choiceGroupProcs);
5675 if (c != NULL) {
5676 Nlm_NewChoice (c, actn);
5677 Nlm_SetVisible ((Nlm_GraphiC) c, TRUE);
5678 }
5679 }
5680 return c;
5681 }
5682
Nlm_PopupList(Nlm_GrouP prnt,Nlm_Boolean macLike,Nlm_PupActnProc actn)5683 extern Nlm_PopuP Nlm_PopupList (Nlm_GrouP prnt, Nlm_Boolean macLike,
5684 Nlm_PupActnProc actn)
5685
5686 {
5687 Nlm_ChoicE c;
5688 Nlm_GphPrcs PNTR classPtr;
5689 Nlm_Int2 hbounds;
5690 Nlm_MenU m;
5691 Nlm_PoinT npt;
5692 Nlm_RecT r;
5693 Nlm_WindoW tempPort;
5694
5695 c = NULL;
5696 if (prnt != NULL) {
5697 tempPort = Nlm_SavePort ((Nlm_GraphiC) prnt);
5698 Nlm_GetNextPosition ((Nlm_GraphiC) prnt, &npt);
5699 Nlm_SelectFont (Nlm_systemFont);
5700 if (macLike) {
5701 classPtr = macPopListProcs;
5702 } else {
5703 classPtr = msPopListProcs;
5704 }
5705 #ifdef WIN_MAC
5706 hbounds = 13;
5707 #endif
5708 #ifdef WIN_MSWIN
5709 hbounds = 13;
5710 #endif
5711 #ifdef WIN_MOTIF
5712 hbounds = 26;
5713 #endif
5714 r.left = npt.x;
5715 r.top = npt.y;
5716 r.right = (Nlm_Int2)(r.left + hbounds * 2);
5717 r.bottom = (Nlm_Int2)(r.top + Nlm_popupMenuHeight);
5718 #ifdef WIN_MAC
5719 m = (Nlm_MenU) Nlm_CreateLink ((Nlm_GraphiC) prnt, &r, sizeof (Nlm_MenuRec), classPtr);
5720 if (m != NULL) {
5721 Nlm_NewPopListMenu (m);
5722 Nlm_DoAdjustPrnt ((Nlm_GraphiC) m, &r, TRUE, FALSE);
5723 Nlm_DoShow ((Nlm_GraphiC) m, TRUE, FALSE);
5724 c = (Nlm_ChoicE) Nlm_CreateLink ((Nlm_GraphiC) m, &r, sizeof (Nlm_ChoiceRec),
5725 popUpChoiceProcs);
5726 if (c != NULL) {
5727 Nlm_NewPopListChoice (c, actn);
5728 Nlm_SetVisible ((Nlm_GraphiC) c, TRUE);
5729 }
5730 }
5731 #endif
5732 #ifdef WIN_MSWIN
5733 m = (Nlm_MenU) Nlm_CreateLink ((Nlm_GraphiC) prnt, &r, sizeof (Nlm_MenuRec), classPtr);
5734 if (m != NULL) {
5735 Nlm_NewPopListMenu (m);
5736 Nlm_DoAdjustPrnt ((Nlm_GraphiC) m, &r, TRUE, FALSE);
5737 Nlm_DoShow ((Nlm_GraphiC) m, TRUE, FALSE);
5738 c = (Nlm_ChoicE) Nlm_CreateLink ((Nlm_GraphiC) m, &r, sizeof (Nlm_ChoiceRec),
5739 popUpChoiceProcs);
5740 if (c != NULL) {
5741 Nlm_NewPopListChoice (c, actn);
5742 Nlm_SetVisible ((Nlm_GraphiC) c, TRUE);
5743 }
5744 }
5745 #endif
5746 #ifdef WIN_MOTIF
5747 m = (Nlm_MenU) Nlm_CreateLink ((Nlm_GraphiC) prnt, &r, sizeof (Nlm_MenuRec), classPtr);
5748 if (m != NULL) {
5749 c = (Nlm_ChoicE) Nlm_CreateLink ((Nlm_GraphiC) m, &r, sizeof (Nlm_ChoiceRec),
5750 popUpChoiceProcs);
5751 if (c != NULL) {
5752 Nlm_NewPopupList (m, c, actn);
5753 Nlm_DoAdjustPrnt ((Nlm_GraphiC) m, &r, TRUE, FALSE);
5754 Nlm_SetVisible ((Nlm_GraphiC) c, TRUE);
5755 Nlm_DoShow ((Nlm_GraphiC) m, TRUE, FALSE);
5756 }
5757 }
5758 #endif
5759 Nlm_RestorePort (tempPort);
5760 }
5761 return (Nlm_PopuP) c;
5762 }
5763
Nlm_ChoiceItem(Nlm_ChoicE c,Nlm_CharPtr title)5764 extern Nlm_IteM Nlm_ChoiceItem (Nlm_ChoicE c, Nlm_CharPtr title)
5765
5766 {
5767 Nlm_IteM i;
5768
5769 i = NULL;
5770 if (c != NULL && title != NULL) {
5771 if (! Nlm_IsItAPopupList (c)) {
5772 i = Nlm_AppendChoice (c, title, FALSE, FALSE);
5773 }
5774 }
5775 return i;
5776 }
5777
Nlm_PopupItem(Nlm_PopuP p,Nlm_CharPtr title)5778 extern void Nlm_PopupItem (Nlm_PopuP p, Nlm_CharPtr title)
5779
5780 {
5781 Nlm_ChoicE c;
5782
5783 c = (Nlm_ChoicE) p;
5784 if (c != NULL && title != NULL) {
5785 if (Nlm_IsItAPopupList (c)) {
5786 Nlm_AppendPopList (c, title, TRUE);
5787 }
5788 }
5789 }
5790
Nlm_DeskAccGroup(Nlm_MenU m)5791 extern void Nlm_DeskAccGroup (Nlm_MenU m)
5792
5793 {
5794 #ifdef WIN_MAC
5795 Nlm_ChoicE c;
5796 Nlm_RecT r;
5797
5798 c = NULL;
5799 if (m != NULL) {
5800 Nlm_LoadRect (&r, 0, 0, 0, 0);
5801 c = (Nlm_ChoicE) Nlm_CreateLink ((Nlm_GraphiC) m, &r, sizeof (Nlm_ChoiceRec), daProcs);
5802 if (c != NULL) {
5803 Nlm_NewDeskAcc (c);
5804 Nlm_SetVisible ((Nlm_GraphiC) c, TRUE);
5805 }
5806 }
5807 #endif
5808 }
5809
Nlm_FontGroup(Nlm_MenU m)5810 extern Nlm_ChoicE Nlm_FontGroup (Nlm_MenU m)
5811
5812 {
5813 Nlm_ChoicE c;
5814 Nlm_RecT r;
5815
5816 c = NULL;
5817 if (m != NULL) {
5818 Nlm_LoadRect (&r, 0, 0, 0, 0);
5819 c = (Nlm_ChoicE) Nlm_CreateLink ((Nlm_GraphiC) m, &r, sizeof (Nlm_ChoiceRec),
5820 choiceGroupProcs);
5821 if (c != NULL) {
5822 Nlm_NewFontGroup (c);
5823 Nlm_SetVisible ((Nlm_GraphiC) c, TRUE);
5824 }
5825 }
5826 return c;
5827 }
5828
Nlm_FreeMenus(void)5829 extern void Nlm_FreeMenus (void)
5830
5831 {
5832 gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemFree (gphprcsptr);
5833 }
5834
Nlm_InitMenus(void)5835 extern void Nlm_InitMenus (void)
5836
5837 {
5838 gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemNew (sizeof (Nlm_GphPrcs) * 15);
5839
5840 #ifdef WIN_MAC
5841 desktopMenuBarProcs = &(gphprcsptr [0]);
5842 desktopMenuBarProcs->click = Nlm_DesktopMenuBarClick;
5843 desktopMenuBarProcs->key = Nlm_DesktopMenuBarKey;
5844 desktopMenuBarProcs->remove = Nlm_RemoveDesktopMenuBar;
5845 desktopMenuBarProcs->linkIn = Nlm_LinkIn;
5846
5847 desktopPulldownProcs = &(gphprcsptr [1]);
5848 desktopPulldownProcs->click = Nlm_DesktopMenuClick;
5849 desktopPulldownProcs->key = Nlm_DesktopMenuKey;
5850 desktopPulldownProcs->draw = Nlm_DrawDesktopMenu;
5851 desktopPulldownProcs->show = Nlm_ShowDesktopMenu;
5852 desktopPulldownProcs->hide = Nlm_HideDesktopMenu;
5853 desktopPulldownProcs->enable = Nlm_EnableDesktopMenu;
5854 desktopPulldownProcs->disable = Nlm_DisableDesktopMenu;
5855 desktopPulldownProcs->remove = Nlm_RemoveDesktopMenu;
5856 desktopPulldownProcs->reset = Nlm_ResetMenu;
5857 desktopPulldownProcs->countItems = Nlm_CountMenuItems;
5858 desktopPulldownProcs->linkIn = Nlm_LinkIn;
5859 #endif
5860
5861 windowMenuBarProcs = &(gphprcsptr [2]);
5862 #ifdef WIN_MAC
5863 windowMenuBarProcs->click = Nlm_WindowMenuBarClick;
5864 windowMenuBarProcs->key = NULL;
5865 windowMenuBarProcs->draw = Nlm_DrawWindowMenuBar;
5866 #endif
5867 #ifdef WIN_MSWIN
5868 windowMenuBarProcs->command = Nlm_WindowMenuBarCommand;
5869 #endif
5870 windowMenuBarProcs->show = Nlm_ShowWindowMenuBar;
5871 windowMenuBarProcs->remove = Nlm_RemoveWindowMenuBar;
5872 windowMenuBarProcs->linkIn = Nlm_LinkIn;
5873
5874 windowPulldownProcs = &(gphprcsptr [3]);
5875 #ifdef WIN_MAC
5876 windowPulldownProcs->click = Nlm_PulldownClick;
5877 windowPulldownProcs->key = Nlm_PopupKey;
5878 windowPulldownProcs->draw = Nlm_DrawWindowMenu;
5879 #endif
5880 #ifdef WIN_MSWIN
5881 windowPulldownProcs->command = Nlm_PulldownCommand;
5882 #endif
5883 windowPulldownProcs->show = Nlm_ShowPopup;
5884 windowPulldownProcs->hide = Nlm_HidePulldown;
5885 windowPulldownProcs->enable = Nlm_EnablePulldown;
5886 windowPulldownProcs->disable = Nlm_DisablePulldown;
5887 windowPulldownProcs->remove = Nlm_RemovePopupMenu;
5888 windowPulldownProcs->reset = Nlm_ResetMenu;
5889 windowPulldownProcs->countItems = Nlm_CountMenuItems;
5890 windowPulldownProcs->linkIn = Nlm_LinkIn;
5891
5892 popupProcs = &(gphprcsptr [4]);
5893 #ifdef WIN_MAC
5894 popupProcs->click = Nlm_PopupClick;
5895 popupProcs->key = Nlm_PopupKey;
5896 popupProcs->draw = Nlm_DrawPopup;
5897 #endif
5898 popupProcs->show = Nlm_ShowPopup;
5899 popupProcs->hide = Nlm_HidePopup;
5900 popupProcs->enable = Nlm_EnablePopup;
5901 popupProcs->disable = Nlm_DisablePopup;
5902 popupProcs->remove = Nlm_RemovePopupMenu;
5903 popupProcs->reset = Nlm_ResetMenu;
5904 popupProcs->countItems = Nlm_CountMenuItems;
5905 popupProcs->linkIn = Nlm_LinkIn;
5906 popupProcs->setPosition = Nlm_SetPopupPosition;
5907 popupProcs->getPosition = Nlm_GetPopupPosition;
5908
5909 subMenuProcs = &(gphprcsptr [5]);
5910 #ifdef WIN_MAC
5911 subMenuProcs->click = Nlm_DesktopMenuClick;
5912 subMenuProcs->key = Nlm_SubMenuKey;
5913 #endif
5914 subMenuProcs->enable = Nlm_EnableSubMenu;
5915 subMenuProcs->disable = Nlm_DisableSubMenu;
5916 subMenuProcs->remove = Nlm_RemoveSubMenu;
5917 subMenuProcs->reset = Nlm_ResetMenu;
5918 subMenuProcs->countItems = Nlm_CountMenuItems;
5919 subMenuProcs->linkIn = Nlm_LinkIn;
5920 subMenuProcs->setTitle = Nlm_SetSubmenuTitle;
5921 subMenuProcs->getTitle = Nlm_GetSubmenuTitle;
5922
5923 subItemProcs = &(gphprcsptr [6]);
5924 #ifdef WIN_MAC
5925 subItemProcs->click = Nlm_SubItemClick;
5926 #endif
5927 #ifdef WIN_MSWIN
5928 subItemProcs->command = Nlm_SubItemCommand;
5929 #endif
5930 subItemProcs->enable = Nlm_EnableMenuItem;
5931 subItemProcs->disable = Nlm_DisableMenuItem;
5932 #ifdef WIN_MAC
5933 subItemProcs->remove = Nlm_RemoveMenuItemButNotSub;
5934 #else
5935 subItemProcs->remove = Nlm_RemoveMenuItem;
5936 #endif
5937 subItemProcs->linkIn = Nlm_LinkIn;
5938 subItemProcs->setTitle = Nlm_SetSingleTitle;
5939 subItemProcs->getTitle = Nlm_GetSingleTitle;
5940
5941 commandItemProcs = &(gphprcsptr [7]);
5942 #ifdef WIN_MAC
5943 commandItemProcs->click = Nlm_CommItemClick;
5944 commandItemProcs->key = Nlm_CommItemKey;
5945 #endif
5946 #ifdef WIN_MSWIN
5947 commandItemProcs->command = Nlm_CommItemCommand;
5948 #endif
5949 #ifdef WIN_MOTIF
5950 commandItemProcs->callback = Nlm_CommItemCallback;
5951 #endif
5952 commandItemProcs->enable = Nlm_EnableMenuItem;
5953 commandItemProcs->disable = Nlm_DisableMenuItem;
5954 commandItemProcs->remove = Nlm_RemoveMenuItem;
5955 commandItemProcs->setTitle = Nlm_SetSingleTitle;
5956 commandItemProcs->getTitle = Nlm_GetSingleTitle;
5957
5958 statusItemProcs = &(gphprcsptr [8]);
5959 #ifdef WIN_MAC
5960 statusItemProcs->click = Nlm_StatItemClick;
5961 statusItemProcs->key = Nlm_StatItemKey;
5962 #endif
5963 #ifdef WIN_MSWIN
5964 statusItemProcs->command = Nlm_StatItemCommand;
5965 #endif
5966 #ifdef WIN_MOTIF
5967 statusItemProcs->callback = Nlm_StatItemCallback;
5968 #endif
5969 statusItemProcs->enable = Nlm_EnableMenuItem;
5970 statusItemProcs->disable = Nlm_DisableMenuItem;
5971 statusItemProcs->remove = Nlm_RemoveMenuItem;
5972 statusItemProcs->setTitle = Nlm_SetSingleTitle;
5973 statusItemProcs->getTitle = Nlm_GetSingleTitle;
5974 statusItemProcs->setStatus = Nlm_SetStatValue;
5975 statusItemProcs->getStatus = Nlm_GetStatValue;
5976
5977 choiceGroupProcs = &(gphprcsptr [9]);
5978 #ifdef WIN_MAC
5979 choiceGroupProcs->click = Nlm_ChoiceGroupClick;
5980 choiceGroupProcs->key = Nlm_ChoiceGroupKey;
5981 #endif
5982 #ifdef WIN_MSWIN
5983 choiceGroupProcs->command = Nlm_ChoiceGroupCommand;
5984 #endif
5985 #ifdef WIN_MOTIF
5986 choiceGroupProcs->callback = Nlm_ChoiceGroupCallback;
5987 #endif
5988 choiceGroupProcs->enable = Nlm_EnableChoiceGroup;
5989 choiceGroupProcs->disable = Nlm_DisableChoice;
5990 choiceGroupProcs->remove = Nlm_RemoveChoiceGroup;
5991 choiceGroupProcs->linkIn = Nlm_LinkIn;
5992 choiceGroupProcs->countItems = Nlm_CountChoiceItems;
5993 choiceGroupProcs->setTitle = Nlm_SetChoiceGroupTitle;
5994 choiceGroupProcs->getTitle = Nlm_GetChoiceGroupTitle;
5995 choiceGroupProcs->setValue = Nlm_SetChoiceGroupValue;
5996 choiceGroupProcs->getValue = Nlm_GetChoiceGroupValue;
5997
5998 choiceItemProcs = &(gphprcsptr [10]);
5999 choiceItemProcs->enable = Nlm_EnableChoiceItem;
6000 choiceItemProcs->disable = Nlm_DisableChoiceItem;
6001 choiceItemProcs->remove = Nlm_RemoveChoiceItem;
6002 choiceItemProcs->setTitle = Nlm_SetChoiceItemTitle;
6003 choiceItemProcs->getTitle = Nlm_GetChoiceItemTitle;
6004 choiceItemProcs->setStatus = NULL;
6005 choiceItemProcs->getStatus = NULL;
6006
6007 macPopListProcs = &(gphprcsptr [11]);
6008 #ifdef WIN_MAC
6009 macPopListProcs->click = Nlm_MacPopListClick;
6010 macPopListProcs->key = NULL;
6011 macPopListProcs->draw = Nlm_DrawPopList;
6012 #endif
6013 #ifdef WIN_MSWIN
6014 macPopListProcs->command = Nlm_MacPopListCommand;
6015 #endif
6016 macPopListProcs->show = Nlm_ShowPopListMenu;
6017 macPopListProcs->hide = Nlm_HidePopListMenu;
6018 macPopListProcs->enable = Nlm_EnablePopList;
6019 macPopListProcs->disable = Nlm_DisablePopList;
6020 macPopListProcs->remove = Nlm_RemovePopListMenu;
6021 macPopListProcs->reset = Nlm_ResetMenu;
6022 macPopListProcs->countItems = Nlm_CountMenuItems;
6023 macPopListProcs->linkIn = Nlm_LinkIn;
6024 macPopListProcs->setPosition = Nlm_SetPopListPosition;
6025 macPopListProcs->getPosition = Nlm_GetPopListPosition;
6026
6027 msPopListProcs = &(gphprcsptr [12]);
6028 #ifdef WIN_MAC
6029 msPopListProcs->click = Nlm_MSPopListClick;
6030 msPopListProcs->key = NULL;
6031 msPopListProcs->draw = Nlm_DrawPopList;
6032 #endif
6033 #ifdef WIN_MSWIN
6034 msPopListProcs->command = Nlm_MSPopListCommand;
6035 #endif
6036 msPopListProcs->show = Nlm_ShowPopListMenu;
6037 msPopListProcs->hide = Nlm_HidePopListMenu;
6038 msPopListProcs->enable = Nlm_EnablePopList;
6039 msPopListProcs->disable = Nlm_DisablePopList;
6040 msPopListProcs->remove = Nlm_RemovePopListMenu;
6041 msPopListProcs->reset = Nlm_ResetMenu;
6042 msPopListProcs->countItems = Nlm_CountMenuItems;
6043 msPopListProcs->linkIn = Nlm_LinkIn;
6044 msPopListProcs->setPosition = Nlm_SetPopListPosition;
6045 msPopListProcs->getPosition = Nlm_GetPopListPosition;
6046
6047 popUpChoiceProcs = &(gphprcsptr [13]);
6048 #ifdef WIN_MAC
6049 popUpChoiceProcs->click = Nlm_PopupChoiceGroupClick;
6050 popUpChoiceProcs->key = Nlm_ChoiceGroupKey;
6051 #endif
6052 #ifdef WIN_MOTIF
6053 popUpChoiceProcs->callback = Nlm_PopupChoiceCallback;
6054 #endif
6055 popUpChoiceProcs->show = Nlm_ShowPopListChoice;
6056 popUpChoiceProcs->hide = Nlm_HidePopListChoice;
6057 popUpChoiceProcs->enable = Nlm_EnablePopListChoice;
6058 popUpChoiceProcs->disable = Nlm_DisablePopListChoice;
6059 popUpChoiceProcs->remove = Nlm_RemovePopupList;
6060 popUpChoiceProcs->reset = Nlm_ResetPopList;
6061 popUpChoiceProcs->countItems = Nlm_CountChoiceItems;
6062 popUpChoiceProcs->setTitle = Nlm_SetPopListTitle;
6063 popUpChoiceProcs->getTitle = Nlm_GetPopListTitle;
6064 popUpChoiceProcs->setValue = Nlm_SetPopListValue;
6065 popUpChoiceProcs->getValue = Nlm_GetPopListValue;
6066 popUpChoiceProcs->setPosition = Nlm_SetPopupChoicePosition;
6067 popUpChoiceProcs->getPosition = Nlm_GetPopupChoicePosition;
6068
6069 daProcs = &(gphprcsptr [14]);
6070 #ifdef WIN_MAC
6071 daProcs->click = Nlm_DAClick;
6072 daProcs->key = Nlm_DAKey;
6073 #endif
6074 daProcs->enable = Nlm_EnableChoice;
6075 daProcs->disable = Nlm_DisableChoice;
6076 daProcs->remove = Nlm_RemoveMenuItem;
6077 daProcs->countItems = Nlm_CountChoiceItems;
6078 daProcs->setTitle = Nlm_SetChoiceTitle;
6079 daProcs->getTitle = Nlm_GetChoiceTitle;
6080 daProcs->setValue = Nlm_SetChoiceValue;
6081 daProcs->getValue = Nlm_GetChoiceValue;
6082 }
6083
6084