1 /* vibbutns.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: vibbutns.c
27 *
28 * Author: Jonathan Kans
29 *
30 * Version Creation Date: 7/1/91
31 *
32 * $Revision: 6.19 $
33 *
34 * File Description:
35 * Vibrant button functions
36 *
37 * Modifications:
38 * --------------------------------------------------------------------------
39 * Date Name Description of modification
40 * ------- ---------- -----------------------------------------------------
41 *
42 * ==========================================================================
43 */
44
45 #include <vibtypes.h>
46 #include <vibprocs.h>
47 #include <vibincld.h>
48
49 #ifdef WIN_MAC
50 # define Nlm_ControlTool ControlHandle
51 #endif
52
53 #ifdef WIN_MSWIN
54 # define Nlm_ControlTool HWND
55 #endif
56
57 #ifdef WIN_MOTIF
58 # define Nlm_ControlTool Widget
59 #endif
60
61 typedef struct Nlm_buttondata {
62 Nlm_ControlTool handle;
63 Nlm_Int2 border;
64 Nlm_Int2 offset;
65 Nlm_Int2 shrinkX;
66 Nlm_Int2 shrinkY;
67 Nlm_Boolean defaultBtn;
68 } Nlm_ButtonData;
69
70 typedef struct Nlm_buttonrec {
71 Nlm_GraphicRec graphicR;
72 Nlm_ButtonData button;
73 } Nlm_ButtonRec, PNTR Nlm_BtnPtr;
74
75 static Nlm_GphPrcsPtr gphprcsptr = NULL;
76
77 static Nlm_GphPrcsPtr pushProcs;
78 static Nlm_GphPrcsPtr defaultProcs;
79 static Nlm_GphPrcsPtr checkProcs;
80 static Nlm_GphPrcsPtr radioProcs;
81
82 static Nlm_ButtoN recentButton = NULL;
83 static Nlm_ButtonData recentButtonData;
84
85 #ifdef WIN_MSWIN
86 static WNDPROC lpfnNewButtonProc = NULL;
87 static WNDPROC lpfnOldButtonProc = NULL;
88 static Nlm_Boolean handlechar;
89 #endif
90
91 #ifdef WIN_MOTIF
92 static void NlmHint_ResetDefButtonE(Widget w, XtPointer client_data,
93 XEvent *event,
94 Boolean *continue_to_dispatch);
95 static void NlmHint_ResetDefButtonA(Widget w, XtPointer client_data,
96 XtPointer call_data);
97 #endif
98
Nlm_LoadButtonData(Nlm_ButtoN b,Nlm_ControlTool hdl,Nlm_Int2 bdr,Nlm_Int2 ofs,Nlm_Int2 shkX,Nlm_Int2 shkY,Nlm_Boolean dflt)99 static void Nlm_LoadButtonData (Nlm_ButtoN b, Nlm_ControlTool hdl,
100 Nlm_Int2 bdr, Nlm_Int2 ofs,
101 Nlm_Int2 shkX, Nlm_Int2 shkY,
102 Nlm_Boolean dflt)
103
104 {
105 Nlm_BtnPtr bp;
106 Nlm_ButtonData PNTR ptr;
107
108 if (b != NULL) {
109 bp = (Nlm_BtnPtr) Nlm_HandLock (b);
110 ptr = &(bp->button);
111 ptr->handle = hdl;
112 ptr->border = bdr;
113 ptr->offset = ofs;
114 ptr->shrinkX = shkX;
115 ptr->shrinkY = shkY;
116 ptr->defaultBtn = dflt;
117 Nlm_HandUnlock (b);
118 recentButton = NULL;
119 }
120 }
121
122
Nlm_GetButtonData(Nlm_ButtoN b,Nlm_ButtonData * bdata)123 static void Nlm_GetButtonData (Nlm_ButtoN b, Nlm_ButtonData * bdata)
124 {
125 Nlm_BtnPtr bp;
126
127 if (b != NULL && bdata != NULL) {
128 if (b == recentButton && NLM_RISKY) {
129 *bdata = recentButtonData;
130 } else {
131 bp = (Nlm_BtnPtr) Nlm_HandLock (b);
132 *bdata = bp->button;
133 Nlm_HandUnlock (b);
134 recentButton = b;
135 recentButtonData = *bdata;
136 }
137 }
138 }
139
Nlm_GetButtonHandle(Nlm_ButtoN b)140 static Nlm_ControlTool Nlm_GetButtonHandle (Nlm_ButtoN b)
141
142 {
143 Nlm_ButtonData bdata;
144
145 Nlm_GetButtonData (b, &bdata);
146 return bdata.handle;
147 }
148
149
150 static Nlm_BtnActnProc buttonAction = NULL;
151
Nlm_SetButtonAction(Nlm_BtnActnProc actn)152 extern void Nlm_SetButtonAction (Nlm_BtnActnProc actn)
153
154 {
155 buttonAction = actn;
156 }
157
158 #ifdef WIN_MAC
Nlm_GetButtonBorder(Nlm_ButtoN b)159 static Nlm_Int2 Nlm_GetButtonBorder (Nlm_ButtoN b)
160 {
161 Nlm_ButtonData bdata;
162
163 Nlm_GetButtonData (b, &bdata);
164 return bdata.border;
165 }
166
167
Nlm_CommonPtInRect(Nlm_GraphiC b,Nlm_PoinT pt)168 static Nlm_Boolean Nlm_CommonPtInRect (Nlm_GraphiC b, Nlm_PoinT pt)
169
170 {
171 Nlm_RecT r;
172
173 Nlm_GetRect (b, &r);
174 return (Nlm_PtInRect (pt, &r));
175 }
176
Nlm_CommonButtonClick(Nlm_GraphiC b,Nlm_PoinT pt,Nlm_Int2 part)177 static Nlm_Boolean Nlm_CommonButtonClick (Nlm_GraphiC b, Nlm_PoinT pt, Nlm_Int2 part)
178
179 {
180 Nlm_ControlTool c;
181 Nlm_PointTool ptool;
182
183 c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
184 Nlm_PoinTToPointTool (pt, &ptool);
185 return (part == TrackControl (c, ptool, NULL));
186 }
187
Nlm_PushClick(Nlm_GraphiC b,Nlm_PoinT pt)188 static Nlm_Boolean Nlm_PushClick (Nlm_GraphiC b, Nlm_PoinT pt)
189
190 {
191 Nlm_Boolean rsult;
192
193 rsult = FALSE;
194 if (Nlm_CommonPtInRect (b, pt)) {
195 if (Nlm_CommonButtonClick (b, pt, kControlButtonPart)) {
196 Nlm_DoAction (b);
197 if (buttonAction != NULL) {
198 buttonAction ((Nlm_ButtoN) b);
199 }
200 }
201 rsult = TRUE;
202 }
203 return rsult;
204 }
205
Nlm_DefaultClick(Nlm_GraphiC b,Nlm_PoinT pt)206 static Nlm_Boolean Nlm_DefaultClick (Nlm_GraphiC b, Nlm_PoinT pt)
207
208 {
209 Nlm_Boolean rsult;
210
211 rsult = FALSE;
212 if (Nlm_CommonPtInRect (b, pt)) {
213 if (Nlm_CommonButtonClick (b, pt, kControlButtonPart)) {
214 Nlm_DoAction (b);
215 if (buttonAction != NULL) {
216 buttonAction ((Nlm_ButtoN) b);
217 }
218 }
219 rsult = TRUE;
220 }
221 return rsult;
222 }
223
Nlm_CheckClick(Nlm_GraphiC b,Nlm_PoinT pt)224 static Nlm_Boolean Nlm_CheckClick (Nlm_GraphiC b, Nlm_PoinT pt)
225
226 {
227 Nlm_Boolean _bool_;
228 Nlm_GraphiC g;
229 Nlm_Boolean rsult;
230
231 rsult = FALSE;
232 if (Nlm_CommonPtInRect (b, pt)) {
233 if (Nlm_CommonButtonClick (b, pt, kControlCheckBoxPart)) {
234 _bool_ = Nlm_DoGetStatus (b, 0);
235 if (_bool_) {
236 Nlm_DoSetStatus (b, 0, FALSE, FALSE);
237 } else {
238 Nlm_DoSetStatus (b, 0, TRUE, FALSE);
239 }
240 Nlm_DoAction (b);
241 g = Nlm_GetParent (b);
242 Nlm_DoAction (g);
243 }
244 rsult = TRUE;
245 }
246 return rsult;
247 }
248
Nlm_RadioClick(Nlm_GraphiC b,Nlm_PoinT pt)249 static Nlm_Boolean Nlm_RadioClick (Nlm_GraphiC b, Nlm_PoinT pt)
250
251 {
252 Nlm_Boolean _bool_;
253 Nlm_GraphiC g;
254 Nlm_Boolean rsult;
255
256 rsult = FALSE;
257 if (Nlm_CommonPtInRect (b, pt)) {
258 if (Nlm_CommonButtonClick (b, pt, kControlCheckBoxPart)) {
259 _bool_ = Nlm_DoGetStatus (b, 0);
260 if (! _bool_) {
261 g = Nlm_GetParent (b);
262 Nlm_ClearItemsInGroup (g, b, FALSE);
263 Nlm_DoSetStatus (b, 0, TRUE, FALSE);
264 Nlm_DoAction (b);
265 Nlm_DoAction (g);
266 }
267 }
268 rsult = TRUE;
269 }
270 return rsult;
271 }
272 #endif
273
274 #ifdef WIN_MSWIN
Nlm_PushCommand(Nlm_GraphiC b)275 static Nlm_Boolean Nlm_PushCommand (Nlm_GraphiC b)
276
277 {
278 Nlm_DoAction (b);
279 if (buttonAction != NULL) {
280 buttonAction ((Nlm_ButtoN) b);
281 }
282 return TRUE;
283 }
284
Nlm_DefaultCommand(Nlm_GraphiC b)285 static Nlm_Boolean Nlm_DefaultCommand (Nlm_GraphiC b)
286
287 {
288 Nlm_DoAction (b);
289 if (buttonAction != NULL) {
290 buttonAction ((Nlm_ButtoN) b);
291 }
292 return TRUE;
293 }
294
Nlm_CheckCommand(Nlm_GraphiC b)295 static Nlm_Boolean Nlm_CheckCommand (Nlm_GraphiC b)
296
297 {
298 Nlm_Boolean _bool_;
299 Nlm_GraphiC g;
300
301 _bool_ = Nlm_DoGetStatus (b, 0);
302 if (_bool_) {
303 Nlm_DoSetStatus (b, 0, FALSE, FALSE);
304 } else {
305 Nlm_DoSetStatus (b, 0, TRUE, FALSE);
306 }
307 Nlm_DoAction (b);
308 g = Nlm_GetParent (b);
309 Nlm_DoAction (g);
310 return TRUE;
311 }
312
Nlm_RadioCommand(Nlm_GraphiC b)313 static Nlm_Boolean Nlm_RadioCommand (Nlm_GraphiC b)
314
315 {
316 Nlm_Boolean _bool_;
317 Nlm_GraphiC g;
318
319 _bool_ = Nlm_DoGetStatus (b, 0);
320 if (! _bool_) {
321 g = Nlm_GetParent (b);
322 Nlm_ClearItemsInGroup (g, b, FALSE);
323 Nlm_DoSetStatus (b, 0, TRUE, FALSE);
324 Nlm_DoAction (b);
325 Nlm_DoAction (g);
326 }
327 return TRUE;
328 }
329 #endif
330
331 #ifdef WIN_MOTIF
Nlm_PushCallback(Nlm_GraphiC b)332 static void Nlm_PushCallback (Nlm_GraphiC b)
333
334 {
335 Nlm_DoAction (b);
336 if (buttonAction != NULL) {
337 buttonAction ((Nlm_ButtoN) b);
338 }
339 }
340
Nlm_DefaultCallback(Nlm_GraphiC b)341 static void Nlm_DefaultCallback (Nlm_GraphiC b)
342
343 {
344 Nlm_DoAction (b);
345 if (buttonAction != NULL) {
346 buttonAction ((Nlm_ButtoN) b);
347 }
348 }
349
Nlm_CheckCallback(Nlm_GraphiC b)350 static void Nlm_CheckCallback (Nlm_GraphiC b)
351
352 {
353 Nlm_Boolean _bool_;
354 Nlm_ControlTool c;
355 Nlm_GraphiC g;
356
357 c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
358 _bool_ = Nlm_DoGetStatus (b, 0);
359 if (! _bool_) {
360 Nlm_DoSetStatus (b, 0, FALSE, FALSE);
361 } else {
362 Nlm_DoSetStatus (b, 0, TRUE, FALSE);
363 }
364 Nlm_DoAction (b);
365 g = Nlm_GetParent (b);
366 Nlm_DoAction (g);
367 }
368
Nlm_RadioCallback(Nlm_GraphiC b)369 static void Nlm_RadioCallback (Nlm_GraphiC b)
370
371 {
372 Nlm_Boolean _bool_;
373 Nlm_ControlTool c;
374 Nlm_GraphiC g;
375
376 c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
377 _bool_ = Nlm_DoGetStatus (b, 0);
378 if (_bool_) {
379 g = Nlm_GetParent (b);
380 Nlm_ClearItemsInGroup (g, b, FALSE);
381 Nlm_DoSetStatus (b, 0, TRUE, FALSE);
382 Nlm_DoAction (b);
383 Nlm_DoAction (g);
384 } else {
385 Nlm_DoSetStatus (b, 0, TRUE, FALSE);
386 }
387 }
388 #endif
389
390 #ifdef WIN_MAC
Nlm_DefaultKey(Nlm_GraphiC b,Nlm_Char ch)391 static Nlm_Boolean Nlm_DefaultKey (Nlm_GraphiC b, Nlm_Char ch)
392
393 {
394 Nlm_ControlTool c;
395 unsigned long res;
396 Nlm_Boolean rsult;
397
398 rsult = FALSE;
399 if (ch == '\15' || ch == '\3') {
400 c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
401 HiliteControl (c, 1);
402 Delay (8, &res);
403 HiliteControl (c, 0);
404 Nlm_DoSetStatus (b, 0, TRUE, FALSE);
405 Nlm_DoAction (b);
406 rsult = TRUE;
407 }
408 return rsult;
409 }
410
Nlm_DrawButton(Nlm_GraphiC b)411 static void Nlm_DrawButton (Nlm_GraphiC b)
412
413 {
414 Nlm_ControlTool c;
415 Nlm_RecT r;
416
417 if (Nlm_GetVisible (b) && Nlm_GetAllParentsVisible (b)) {
418 Nlm_GetRect (b, &r);
419 if (Nlm_RectInRgn (&r, Nlm_updateRgn)) {
420 c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
421 Draw1Control (c);
422 }
423 }
424 }
425
Nlm_DrawDefault(Nlm_GraphiC b)426 static void Nlm_DrawDefault (Nlm_GraphiC b)
427
428 {
429 Nlm_ControlTool c;
430 Nlm_RecT r;
431
432 if (Nlm_HasAquaMenuLayout ()) {
433 Nlm_DrawButton (b);
434 return;
435 }
436 if (Nlm_GetVisible (b) && Nlm_GetAllParentsVisible (b)) {
437 Nlm_GetRect (b, &r);
438 Nlm_InsetRect (&r, -4, -4);
439 if (Nlm_RectInRgn (&r, Nlm_updateRgn)) {
440 Nlm_SetPenWidth (3);
441 Nlm_FrameRoundRect (&r, 16, 16);
442 Nlm_SetPenWidth (1);
443 c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
444 Draw1Control (c);
445 }
446 }
447 }
448 #endif
449
Nlm_ShowButton(Nlm_GraphiC b,Nlm_Boolean setFlag,Nlm_Boolean savePort)450 static void Nlm_ShowButton (Nlm_GraphiC b, Nlm_Boolean setFlag, Nlm_Boolean savePort)
451
452 {
453 Nlm_ControlTool c;
454 Nlm_WindoW tempPort;
455
456 if (setFlag) {
457 Nlm_SetVisible (b, TRUE);
458 }
459 if (Nlm_GetVisible (b) && Nlm_AllParentsButWindowVisible (b)) {
460 tempPort = Nlm_SavePortIfNeeded (b, savePort);
461 c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
462 #ifdef WIN_MAC
463 ShowControl (c);
464 Nlm_DoDraw (b);
465 #endif
466 #ifdef WIN_MSWIN
467 ShowWindow (c, SW_SHOW);
468 UpdateWindow (c);
469 #endif
470 #ifdef WIN_MOTIF
471 XtManageChild (c);
472 #endif
473 Nlm_RestorePort (tempPort);
474 }
475 }
476
Nlm_HideButton(Nlm_GraphiC b,Nlm_Boolean setFlag,Nlm_Boolean savePort)477 static void Nlm_HideButton (Nlm_GraphiC b, Nlm_Boolean setFlag, Nlm_Boolean savePort)
478
479 {
480 Nlm_ControlTool c;
481 Nlm_WindoW tempPort;
482 #ifdef WIN_MAC
483 Nlm_Int2 border;
484 Nlm_RecT r;
485 #endif
486
487 if (setFlag) {
488 Nlm_SetVisible (b, FALSE);
489 }
490 tempPort = Nlm_SavePortIfNeeded (b, savePort);
491 c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
492 #ifdef WIN_MAC
493 border = Nlm_GetButtonBorder ((Nlm_ButtoN) b);
494 HideControl (c);
495 if (Nlm_GetAllParentsVisible (b)) {
496 Nlm_GetRect (b, &r);
497 Nlm_InsetRect (&r, -1 - border, -1 - border);
498 Nlm_EraseRect (&r);
499 Nlm_ValidRect (&r);
500 }
501 #endif
502 #ifdef WIN_MSWIN
503 ShowWindow (c, SW_HIDE);
504 UpdateWindow (c);
505 #endif
506 #ifdef WIN_MOTIF
507 XtUnmanageChild (c);
508 #endif
509 Nlm_RestorePort (tempPort);
510 }
511
Nlm_EnableButton(Nlm_GraphiC b,Nlm_Boolean setFlag,Nlm_Boolean savePort)512 static void Nlm_EnableButton (Nlm_GraphiC b, Nlm_Boolean setFlag, Nlm_Boolean savePort)
513
514 {
515 Nlm_ControlTool c;
516 Nlm_WindoW tempPort;
517
518 if (setFlag) {
519 Nlm_SetEnabled (b, TRUE);
520 }
521 if (Nlm_GetEnabled (b) && Nlm_GetAllParentsEnabled (b)) {
522 tempPort = Nlm_SavePortIfNeeded (b, savePort);
523 c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
524 #ifdef WIN_MAC
525 ActivateControl (c);
526 #endif
527 #ifdef WIN_MSWIN
528 EnableWindow (c, TRUE);
529 #endif
530 #ifdef WIN_MOTIF
531 XtVaSetValues (c, XmNsensitive, TRUE, NULL);
532 #endif
533 Nlm_RestorePort (tempPort);
534 }
535 }
536
Nlm_DisableButton(Nlm_GraphiC b,Nlm_Boolean setFlag,Nlm_Boolean savePort)537 static void Nlm_DisableButton (Nlm_GraphiC b, Nlm_Boolean setFlag, Nlm_Boolean savePort)
538
539 {
540 Nlm_ControlTool c;
541 Nlm_WindoW tempPort;
542
543 if (setFlag) {
544 Nlm_SetEnabled (b, FALSE);
545 }
546 tempPort = Nlm_SavePortIfNeeded (b, savePort);
547 c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
548 #ifdef WIN_MAC
549 DeactivateControl (c);
550 #endif
551 #ifdef WIN_MSWIN
552 EnableWindow (c, FALSE);
553 #endif
554 #ifdef WIN_MOTIF
555 XtVaSetValues (c, XmNsensitive, FALSE, NULL);
556 #endif
557 Nlm_RestorePort (tempPort);
558 }
559
Nlm_RemoveButton(Nlm_GraphiC b,Nlm_Boolean savePort)560 static void Nlm_RemoveButton (Nlm_GraphiC b, Nlm_Boolean savePort)
561
562 {
563 Nlm_ControlTool c;
564 Nlm_WindoW tempPort;
565
566 tempPort = Nlm_SavePortIfNeeded (b, savePort);
567 c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
568 #ifdef WIN_MAC
569 DisposeControl (c);
570 #endif
571 #ifdef WIN_MSWIN
572 RemoveProp (c, (LPSTR) "Nlm_VibrantProp");
573 DestroyWindow (c);
574 #endif
575 #ifdef WIN_MOTIF
576 XtDestroyWidget (c);
577 #endif
578 Nlm_RemoveLink (b);
579 recentButton = NULL;
580 Nlm_RestorePort (tempPort);
581 }
582
Nlm_RemoveDefaultButton(Nlm_GraphiC b,Nlm_Boolean savePort)583 static void Nlm_RemoveDefaultButton (Nlm_GraphiC b, Nlm_Boolean savePort)
584
585 {
586 Nlm_ControlTool c;
587 Nlm_WindoW tempPort;
588 #ifdef WIN_MOTIF
589 Nlm_WindoW w;
590 Nlm_WindowTool wptr;
591 #endif
592
593 tempPort = Nlm_SavePortIfNeeded (b, savePort);
594 c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
595 #ifdef WIN_MAC
596 DisposeControl (c);
597 #endif
598 #ifdef WIN_MSWIN
599 RemoveProp (c, (LPSTR) "Nlm_VibrantProp");
600 DestroyWindow (c);
601 #endif
602 #ifdef WIN_MOTIF
603 w = Nlm_ParentWindow (b);
604 wptr = Nlm_ParentWindowPtr (b);
605 if (Nlm_GetWindowDefaultButton (w) == (Nlm_ButtoN) b) {
606 Nlm_SetWindowDefaultButton (w, NULL);
607 #ifndef LESSTIF_VERSION
608 /* causes segfault using LessTif (0.89) under RH Linux 6 */
609 XtVaSetValues (wptr, XmNdefaultButton, NULL, NULL);
610 #endif
611 {{
612 Widget shell = Nlm_ParentWindowShell((Nlm_GraphiC) b);
613 Atom atom =XmInternAtom(Nlm_currentXDisplay, "WM_TAKE_FOCUS", TRUE);
614 if ( atom )
615 XmRemoveWMProtocolCallback(shell, atom,
616 NlmHint_ResetDefButtonA,
617 (XtPointer) b);
618 XtRemoveEventHandler(shell, FocusChangeMask, FALSE,
619 NlmHint_ResetDefButtonE, (XtPointer)b);
620 }}
621 }
622 XtDestroyWidget (c);
623 #endif
624 Nlm_RemoveLink (b);
625 recentButton = NULL;
626 Nlm_RestorePort (tempPort);
627 }
628
Nlm_SetButtonTitle(Nlm_GraphiC b,Nlm_Int2 item,Nlm_CharPtr title,Nlm_Boolean savePort)629 static void Nlm_SetButtonTitle (Nlm_GraphiC b, Nlm_Int2 item,
630 Nlm_CharPtr title, Nlm_Boolean savePort)
631
632 {
633 Nlm_ControlTool c;
634 Nlm_Char temp [256];
635 Nlm_WindoW tempPort;
636 #ifdef WIN_MOTIF
637 XmString label;
638 #endif
639
640 tempPort = Nlm_SavePortIfNeeded (b, savePort);
641 c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
642 Nlm_StringNCpy_0 (temp, title, sizeof (temp));
643 #ifdef WIN_MAC
644 Nlm_CtoPstr (temp);
645 SetControlTitle (c, (StringPtr) temp);
646 #endif
647 #ifdef WIN_MSWIN
648 SetWindowText (c, temp);
649 #endif
650 #ifdef WIN_MOTIF
651 label = XmStringCreateSimple (temp);
652 XtVaSetValues (c, XmNlabelString, label, NULL);
653 XmStringFree (label);
654 #endif
655 Nlm_RestorePort (tempPort);
656 }
657
Nlm_GetButtonTitle(Nlm_GraphiC b,Nlm_Int2 item,Nlm_CharPtr title,size_t maxsize)658 static void Nlm_GetButtonTitle (Nlm_GraphiC b, Nlm_Int2 item,
659 Nlm_CharPtr title, size_t maxsize)
660
661 {
662 Nlm_ControlTool c;
663 Nlm_Char temp [256];
664 #ifdef WIN_MOTIF
665 XmString label;
666 char *text;
667 #endif
668
669 c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
670 #ifdef WIN_MAC
671 GetControlTitle (c, (StringPtr) temp);
672 Nlm_PtoCstr (temp);
673 #endif
674 #ifdef WIN_MSWIN
675 GetWindowText (c, temp, sizeof (temp));
676 #endif
677 #ifdef WIN_MOTIF
678 XtVaGetValues (c, XmNlabelString, &label, NULL);
679 temp [0] = '\0';
680 if (XmStringGetLtoR (label, XmSTRING_DEFAULT_CHARSET, &text)) {
681 Nlm_StringNCpy_0 (temp, text, sizeof (temp));
682 XtFree (text);
683 }
684 #endif
685 Nlm_StringNCpy_0 (title, temp, maxsize);
686 }
687
Nlm_SetButtonStatus(Nlm_GraphiC b,Nlm_Int2 item,Nlm_Boolean set,Nlm_Boolean savePort)688 static void Nlm_SetButtonStatus (Nlm_GraphiC b, Nlm_Int2 item,
689 Nlm_Boolean set, Nlm_Boolean savePort)
690
691 {
692 Nlm_ControlTool c;
693 Nlm_WindoW tempPort;
694 Nlm_Int2 val;
695
696 tempPort = Nlm_SavePortIfNeeded (b, savePort);
697 c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
698 if (set) {
699 val = 1;
700 } else {
701 val = 0;
702 }
703 #ifdef WIN_MAC
704 SetControl32BitValue (c, val);
705 #endif
706 #ifdef WIN_MSWIN
707 Button_SetCheck (c, val);
708 #endif
709 #ifdef WIN_MOTIF
710 XmToggleButtonSetState (c, (Boolean) set, FALSE);
711 #endif
712 Nlm_RestorePort (tempPort);
713 }
714
Nlm_GetButtonStatus(Nlm_GraphiC b,Nlm_Int2 item)715 static Nlm_Boolean Nlm_GetButtonStatus (Nlm_GraphiC b, Nlm_Int2 item)
716
717 {
718 Nlm_ControlTool c;
719
720 c = Nlm_GetButtonHandle ((Nlm_ButtoN) b);
721 #ifdef WIN_MAC
722 return (GetControl32BitValue (c) != 0);
723 #endif
724 #ifdef WIN_MSWIN
725 return (Nlm_Boolean) (Button_GetCheck (c) != 0);
726 #endif
727 #ifdef WIN_MOTIF
728 return (Nlm_Boolean) (XmToggleButtonGetState (c) != FALSE);
729 #endif
730 }
731
732 #ifdef WIN_MAC
Nlm_InvalButton(Nlm_GraphiC b,Nlm_Int2 border)733 static void Nlm_InvalButton (Nlm_GraphiC b, Nlm_Int2 border)
734
735 {
736 Nlm_RecT r;
737
738 if (Nlm_GetVisible (b) && Nlm_GetAllParentsVisible (b)) {
739 Nlm_GetRect (b, &r);
740 Nlm_InsetRect (&r, -1 - border, -1 - border);
741 Nlm_InvalRect (&r);
742 }
743 }
744 #endif
745
Nlm_SetButtonPosition(Nlm_GraphiC b,Nlm_RectPtr r,Nlm_Boolean savePort,Nlm_Boolean force)746 static void Nlm_SetButtonPosition (Nlm_GraphiC b, Nlm_RectPtr r, Nlm_Boolean savePort, Nlm_Boolean force)
747
748 {
749 Nlm_ButtonData bdata;
750 Nlm_ControlTool c;
751 Nlm_RecT oldRect;
752 Nlm_WindoW tempPort;
753 #ifdef WIN_MAC
754 Nlm_Int2 border;
755 #endif
756
757 if (r == NULL) return;
758
759 if ( !Nlm_GetRealized( b ) )
760 {
761 Nlm_SetRect(b, r);
762 return;
763 }
764
765 Nlm_DoGetPosition (b, &oldRect);
766 if (!force && Nlm_EqualRect(r, &oldRect)) return;
767
768 tempPort = Nlm_SavePortIfNeeded (b, savePort);
769 Nlm_GetButtonData ((Nlm_ButtoN) b, &bdata);
770 c = bdata.handle;
771 #ifdef WIN_MAC
772 border = bdata.border;
773 Nlm_InvalButton (b, border);
774 MoveControl (c, r->left, r->top);
775 SizeControl (c, r->right - r->left - bdata.shrinkX, r->bottom - r->top - bdata.shrinkY);
776 Nlm_SetRect (b, r);
777 Nlm_InvalButton (b, border);
778 #endif
779 #ifdef WIN_MSWIN
780 MoveWindow(c, r->left, r->top, r->right - r->left, r->bottom - r->top, TRUE);
781 Nlm_SetRect (b, r);
782 UpdateWindow (c);
783 #endif
784 #ifdef WIN_MOTIF
785 {{
786 Nlm_Int2 offset = bdata.offset;
787 XtVaSetValues (c,
788 XmNx, (Position) (r->left - offset),
789 XmNy, (Position) (r->top - offset),
790 XmNwidth, (Dimension) (r->right - r->left),
791 XmNheight, (Dimension) (r->bottom - r->top),
792 NULL);
793 }}
794 Nlm_SetRect (b, r);
795 #endif
796
797 Nlm_RestorePort (tempPort);
798 }
799
Nlm_GetButtonPosition(Nlm_GraphiC b,Nlm_RectPtr r)800 static void Nlm_GetButtonPosition (Nlm_GraphiC b, Nlm_RectPtr r)
801
802 {
803 if (r != NULL) {
804 Nlm_GetRect (b, r);
805 }
806 }
807
Nlm_DefaultGainFocus(Nlm_GraphiC b,Nlm_Char ch,Nlm_Boolean savePort)808 static Nlm_GraphiC Nlm_DefaultGainFocus (Nlm_GraphiC b, Nlm_Char ch, Nlm_Boolean savePort)
809
810 {
811 #ifdef WIN_MAC
812 return NULL;
813 #endif
814 #ifdef WIN_MSWIN
815 Nlm_GraphiC rsult;
816
817 rsult = NULL;
818 if (ch == '\n' || ch == '\r') {
819 if (Nlm_GetVisible (b) && Nlm_GetAllParentsVisible (b) &&
820 Nlm_GetEnabled (b) && Nlm_GetAllParentsEnabled (b)) {
821 Nlm_DoAction (b);
822 rsult = b;
823 }
824 }
825 return rsult;
826 #endif
827 #ifdef WIN_MOTIF
828 return NULL;
829 #endif
830 }
831
832
833 #ifdef WIN_MSWIN
Nlm_IsDefaultButton(Nlm_ButtoN b)834 static Nlm_Boolean Nlm_IsDefaultButton (Nlm_ButtoN b)
835 {
836 Nlm_ButtonData bdata;
837 Nlm_GetButtonData (b, &bdata);
838 return bdata.defaultBtn;
839 }
840
841 /* Message cracker functions */
842
MyCls_OnChar(HWND hwnd,UINT ch,int cRepeat)843 static void MyCls_OnChar (HWND hwnd, UINT ch, int cRepeat)
844
845 {
846 Nlm_ButtoN b;
847
848 b = (Nlm_ButtoN) GetProp (hwnd, (LPSTR) "Nlm_VibrantProp");
849 handlechar = FALSE;
850 if (ch == '\t') {
851 Nlm_DoSendFocus ((Nlm_GraphiC) b, (Nlm_Char) ch);
852 } else if (ch == '\n' || ch == '\r') {
853 if (Nlm_IsDefaultButton (b)) {
854 Nlm_DoGainFocus ((Nlm_GraphiC) b, (Nlm_Char) ch, FALSE);
855 } else {
856 Nlm_DoSendFocus ((Nlm_GraphiC) b, (Nlm_Char) ch);
857 }
858 } else {
859 handlechar = TRUE;
860 }
861 }
862
ButtonProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)863 static LRESULT CALLBACK EXPORT ButtonProc (HWND hwnd, UINT message,
864 WPARAM wParam, LPARAM lParam)
865
866 {
867 Nlm_ButtoN b;
868 BOOL call_win_proc = TRUE;
869 LRESULT rsult = 0;
870 HDC tempHDC;
871 HWND tempHWnd;
872
873 if (Nlm_VibrantDisabled ()) {
874 return CallWindowProc (lpfnOldButtonProc, hwnd, message, wParam, lParam);
875 }
876
877 tempHWnd = Nlm_currentHWnd;
878 tempHDC = Nlm_currentHDC;
879 b = (Nlm_ButtoN) GetProp (hwnd, (LPSTR) "Nlm_VibrantProp");
880 Nlm_theWindow = Nlm_GetParentWindow ((Nlm_GraphiC) b);
881 Nlm_currentHWnd = GetParent (hwnd);
882 Nlm_currentHDC = Nlm_ParentWindowPort ((Nlm_GraphiC) b);
883 Nlm_currentWindowTool = hwnd;
884 Nlm_currentKey = '\0';
885 Nlm_currentWParam = wParam;
886 Nlm_currentLParam = lParam;
887 Nlm_cmmdKey = FALSE;
888 Nlm_ctrlKey = FALSE;
889 Nlm_optKey = FALSE;
890 Nlm_shftKey = FALSE;
891 Nlm_dblClick = FALSE;
892
893 switch (message) {
894 case WM_KEYDOWN:
895 call_win_proc = !Nlm_ProcessKeydown((Nlm_GraphiC)b, wParam,
896 VERT_PAGE|VERT_ARROW|HORIZ_PAGE|HORIZ_ARROW);
897 break;
898 case WM_CHAR:
899 HANDLE_WM_CHAR (hwnd, wParam, lParam, MyCls_OnChar);
900 call_win_proc = handlechar;
901 break;
902 }
903
904 if ( call_win_proc )
905 rsult = CallWindowProc(lpfnOldButtonProc, hwnd, message, wParam, lParam);
906
907 Nlm_currentHWnd = tempHWnd;
908 Nlm_currentHDC = tempHDC;
909 Nlm_currentWindowTool = tempHWnd;
910 return rsult;
911 }
912
913
Nlm_PrepareTitleMsWin(Nlm_CharPtr temp,Nlm_CharPtr title,size_t siztemp)914 static void Nlm_PrepareTitleMsWin(Nlm_CharPtr temp, Nlm_CharPtr title,
915 size_t siztemp)
916 {
917 /* duplicate existing '&' */
918 Nlm_Uint4 src_pos = 0;
919 Nlm_Uint4 dest_pos = 0;
920
921 for(src_pos = 0, dest_pos = 0;
922 title[src_pos] != '\0' && dest_pos+1 < siztemp;
923 ++src_pos)
924 {
925 if(title[src_pos] == '&')
926 {
927 if(dest_pos + 2 < siztemp)
928 {
929 temp[dest_pos++] = '&';
930 temp[dest_pos++] = title[src_pos];
931 }
932 else
933 break;
934 }
935 else
936 temp[dest_pos++] = title[src_pos];
937 }
938
939 temp[dest_pos] = '\0';
940 }
941 #endif
942
943 #ifdef WIN_MOTIF
Nlm_ButtonCallback(Widget w,XtPointer client_data,XtPointer call_data)944 static void Nlm_ButtonCallback (Widget w, XtPointer client_data, XtPointer call_data)
945
946 {
947 Nlm_GraphiC b;
948
949 b = (Nlm_GraphiC) client_data;
950 Nlm_DoCallback (b);
951 }
952
Nlm_MapDefaultButton(Nlm_WindoW w,Nlm_ButtoN b)953 extern void Nlm_MapDefaultButton (Nlm_WindoW w, Nlm_ButtoN b)
954
955 {
956 Nlm_ControlTool c;
957 Nlm_WindowTool wptr;
958
959 if (w != NULL && b != NULL) {
960 wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) b);
961 c = Nlm_GetButtonHandle (b);
962 Nlm_SetWindowDefaultButton (w, b);
963 XtVaSetValues (wptr, XmNdefaultButton, c, NULL);
964 }
965 }
966 #endif
967
968
969 #define PUSH_STYLE 1
970 #define DEFAULT_STYLE 2
971 #define CHECK_STYLE 3
972 #define RADIO_STYLE 4
973
974 #ifdef WIN_MOTIF
NlmHint_ResetDefButton(Nlm_ButtoN b)975 static void NlmHint_ResetDefButton(Nlm_ButtoN b)
976 {
977 Nlm_WindowTool wptr = Nlm_ParentWindowPtr((Nlm_GraphiC) b);
978 Nlm_ControlTool bptr = Nlm_GetButtonHandle( b );
979
980 XtVaSetValues(wptr, XmNdefaultButton, NULL, NULL);
981 XtVaSetValues(wptr, XmNdefaultButton, bptr, NULL);
982 }
983
NlmHint_ResetDefButtonE(Widget w,XtPointer client_data,XEvent * event,Boolean * continue_to_dispatch)984 static void NlmHint_ResetDefButtonE(Widget w, XtPointer client_data,
985 XEvent *event,
986 Boolean *continue_to_dispatch )
987 {
988 if (event->type == FocusIn)
989 NlmHint_ResetDefButton( (Nlm_ButtoN)client_data );
990 }
991
NlmHint_ResetDefButtonA(Widget w,XtPointer client_data,XtPointer call_data)992 static void NlmHint_ResetDefButtonA(Widget w, XtPointer client_data,
993 XtPointer call_data)
994 {
995 NlmHint_ResetDefButton( (Nlm_ButtoN)client_data );
996 }
997 #endif
998
999
Nlm_NewButton(Nlm_ButtoN b,Nlm_CharPtr title,Nlm_Int2 type,Nlm_Int2 shrinkX,Nlm_Int2 shrinkY,Nlm_BtnActnProc actn)1000 static void Nlm_NewButton (Nlm_ButtoN b, Nlm_CharPtr title,
1001 Nlm_Int2 type, Nlm_Int2 shrinkX,
1002 Nlm_Int2 shrinkY, Nlm_BtnActnProc actn)
1003 {
1004 Nlm_Int2 border;
1005 Nlm_ControlTool c;
1006 Nlm_Boolean dflt;
1007 Nlm_Int2 offset;
1008 Nlm_RecT r;
1009 Nlm_Char temp [256];
1010 Nlm_WindowTool wptr;
1011 #ifdef WIN_MAC
1012 Nlm_Int2 procID;
1013 Nlm_RectTool rtool;
1014 CFStringRef cfTitle;
1015 #endif
1016 #ifdef WIN_MSWIN
1017 Nlm_Uint4 style;
1018 Nlm_FntPtr fntptr;
1019 #endif
1020 #ifdef WIN_MOTIF
1021 String call;
1022 XmString label;
1023 Cardinal n;
1024 Arg wargs [15];
1025 #endif
1026
1027 Nlm_GetRect ((Nlm_GraphiC) b, &r);
1028 wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) b);
1029 #ifdef WIN_MSWIN
1030 Nlm_PrepareTitleMsWin (temp, title, sizeof (temp));
1031 #else
1032 Nlm_StringNCpy_0 (temp, title, sizeof (temp));
1033 #endif
1034 c = (Nlm_ControlTool) 0;
1035 border = 0;
1036 offset = 0;
1037 dflt = (Nlm_Boolean) (type == DEFAULT_STYLE);
1038
1039 #ifdef WIN_MAC
1040 cfTitle = CFStringCreateWithCString(NULL, temp, kCFStringEncodingMacRoman);
1041 switch (type) {
1042 case DEFAULT_STYLE:
1043 if (! Nlm_HasAquaMenuLayout ()) {
1044 border = 5;
1045 }
1046 /* fall through */
1047 case PUSH_STYLE:
1048 r.right -= shrinkX;
1049 r.bottom -= shrinkY;
1050 Nlm_RecTToRectTool (&r, &rtool);
1051 CreatePushButtonControl(wptr, &rtool, cfTitle, &c);
1052 break;
1053 case CHECK_STYLE:
1054 Nlm_RecTToRectTool (&r, &rtool);
1055 CreateCheckBoxControl(wptr, &rtool, cfTitle, 0, FALSE, &c);
1056 break;
1057 case RADIO_STYLE:
1058 Nlm_RecTToRectTool (&r, &rtool);
1059 CreateRadioButtonControl(wptr, &rtool, cfTitle, 0, FALSE, &c);
1060 break;
1061 default:
1062 procID = 0;
1063 break;
1064 }
1065 Nlm_LoadButtonData (b, c, border, offset, shrinkX, shrinkY, dflt);
1066 #endif
1067
1068 #ifdef WIN_MSWIN
1069 switch (type) {
1070 case PUSH_STYLE:
1071 style = BS_PUSHBUTTON;
1072 break;
1073 case DEFAULT_STYLE:
1074 style = BS_DEFPUSHBUTTON;
1075 break;
1076 case CHECK_STYLE:
1077 style = BS_CHECKBOX;
1078 break;
1079 case RADIO_STYLE:
1080 style = BS_RADIOBUTTON;
1081 break;
1082 default:
1083 style = BS_PUSHBUTTON;
1084 break;
1085 }
1086 c = CreateWindow ("Button", temp, WS_CHILD | style,
1087 r.left, r.top, r.right - r.left,
1088 r.bottom - r.top, wptr, 0,
1089 Nlm_currentHInst, NULL);
1090 if ( c ) {
1091 SetProp (c, (LPSTR) "Nlm_VibrantProp", (Nlm_HandleTool) b);
1092 }
1093 Nlm_LoadButtonData (b, c, border, offset, 0, 0, dflt);
1094 if (lpfnNewButtonProc == NULL) {
1095 lpfnNewButtonProc = (WNDPROC) MakeProcInstance ((FARPROC) ButtonProc, Nlm_currentHInst);
1096 }
1097 if (lpfnOldButtonProc == NULL) {
1098 lpfnOldButtonProc = (WNDPROC) GetWindowLongPtr (c, GWLP_WNDPROC);
1099 } else if (lpfnOldButtonProc != (WNDPROC) GetWindowLongPtr (c, GWLP_WNDPROC)) {
1100 Nlm_Message (MSG_ERROR, "ButtonProc subclass error");
1101 }
1102 SetWindowLongPtr (c, GWLP_WNDPROC, (LONG_PTR) lpfnNewButtonProc);
1103 fntptr = (Nlm_FntPtr) Nlm_HandLock (Nlm_systemFont);
1104 SetWindowFont(c, fntptr->handle, FALSE);
1105 Nlm_HandUnlock(Nlm_systemFont);
1106 #endif
1107
1108 #ifdef WIN_MOTIF
1109 n = 0;
1110 label = XmStringCreateSimple (temp);
1111 XtSetArg (wargs [n], XmNlabelString, label); n++;
1112
1113 if (r.right > r.left)
1114 {
1115 XtSetArg (wargs [n], XmNwidth, (Dimension) (r.right - r.left));
1116 n++;
1117 }
1118
1119 if (r.bottom > r.top)
1120 {
1121 XtSetArg (wargs [n], XmNheight, (Dimension) (r.bottom - r.top));
1122 n++;
1123 }
1124
1125 if (type == DEFAULT_STYLE || type == PUSH_STYLE)
1126 {
1127 r.left -= 2;
1128 r.top -= 4;
1129 }
1130 XtSetArg (wargs [n], XmNx, (Position) r.left - offset); n++;
1131 XtSetArg (wargs [n], XmNy, (Position) r.top - offset); n++;
1132 XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
1133 XtSetArg (wargs [n], XmNhighlightThickness, (Dimension) 0); n++;
1134 switch (type) {
1135 case DEFAULT_STYLE:
1136 Nlm_SetWindowDefaultButton(Nlm_ParentWindow((Nlm_GraphiC) b), b);
1137 case PUSH_STYLE:
1138 XtSetArg (wargs [n], XmNrecomputeSize, FALSE); n++;
1139 c = XmCreatePushButton (wptr, (String) "", wargs, n);
1140 XtVaSetValues (wptr, XmNdefaultButton, c, NULL);
1141 call = XmNactivateCallback;
1142 break;
1143 case CHECK_STYLE:
1144 XtSetArg (wargs [n], XmNindicatorType, XmN_OF_MANY); n++;
1145 XtSetArg (wargs [n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
1146 c = XmCreateToggleButton (wptr, (String) "", wargs, n);
1147 call = XmNvalueChangedCallback;
1148 break;
1149 case RADIO_STYLE:
1150 XtSetArg (wargs [n], XmNindicatorType, XmONE_OF_MANY); n++;
1151 XtSetArg (wargs [n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
1152 c = XmCreateToggleButton (wptr, (String) "", wargs, n);
1153 call = XmNvalueChangedCallback;
1154 break;
1155 default:
1156 break;
1157 }
1158 XmStringFree (label);
1159 XtAddCallback (c, call, Nlm_ButtonCallback, (XtPointer) b);
1160 Nlm_LoadButtonData (b, c, border, offset, 0, 0, dflt);
1161 Nlm_OverrideStdTranslations((Nlm_GraphiC)b, c,
1162 VERT_PAGE|VERT_ARROW|HORIZ_PAGE|HORIZ_ARROW);
1163 XtManageChild( c );
1164 XtVaGetValues(c, XmNwidth, &r.right, XmNheight, &r.bottom, NULL);
1165 r.right += r.left;
1166 r.bottom += r.top;
1167 Nlm_SetRect((Nlm_GraphiC)b, &r);
1168 switch ( type )
1169 {
1170 case DEFAULT_STYLE:
1171 {
1172 Atom atom = XmInternAtom(Nlm_currentXDisplay, "WM_TAKE_FOCUS",
1173 TRUE);
1174 Widget shell = Nlm_ParentWindowShell((Nlm_GraphiC) b);
1175 if ( atom )
1176 XmAddWMProtocolCallback(shell, atom,
1177 NlmHint_ResetDefButtonA, (XtPointer) b);
1178 XtAddEventHandler(shell,
1179 FocusChangeMask, FALSE,
1180 NlmHint_ResetDefButtonE, (XtPointer) b);
1181 }
1182 case PUSH_STYLE:
1183 XtVaSetValues(wptr, XmNdefaultButton, NULL, NULL);
1184 break;
1185 }
1186 #endif
1187
1188 Nlm_LoadAction ((Nlm_GraphiC) b, (Nlm_ActnProc) actn);
1189 }
1190
1191
Nlm_CommonButton(Nlm_GrouP prnt,Nlm_CharPtr title,Nlm_Int2 type,Nlm_BtnActnProc actn,Nlm_GphPrcsPtr classPtr)1192 static Nlm_ButtoN Nlm_CommonButton (Nlm_GrouP prnt, Nlm_CharPtr title,
1193 Nlm_Int2 type, Nlm_BtnActnProc actn,
1194 Nlm_GphPrcsPtr classPtr)
1195
1196 {
1197 Nlm_ButtoN b = NULL;
1198 Nlm_Int2 hgt;
1199 Nlm_PoinT npt;
1200 Nlm_RecT r;
1201 Nlm_Int2 shrinkX = 0;
1202 Nlm_Int2 shrinkY = 0;
1203 Nlm_WindoW tempPort;
1204 Nlm_Int2 wid;
1205
1206 if (prnt == NULL) return NULL;
1207
1208 tempPort = Nlm_SavePort ((Nlm_GraphiC) prnt);
1209 Nlm_GetNextPosition ((Nlm_GraphiC) prnt, &npt);
1210 Nlm_SelectFont (Nlm_systemFont);
1211 wid = Nlm_StringWidth (title);
1212
1213 #ifdef WIN_MAC
1214 hgt = Nlm_stdLineHeight;
1215 wid += 20;
1216 switch (type) {
1217 case PUSH_STYLE:
1218 case DEFAULT_STYLE:
1219 hgt += 3;
1220 break;
1221 }
1222 if (Nlm_HasAquaMenuLayout ()) {
1223 switch (type) {
1224 case PUSH_STYLE:
1225 wid += 10;
1226 hgt = 26;
1227 shrinkX = 6;
1228 shrinkY = 6;
1229 break;
1230 case DEFAULT_STYLE:
1231 wid += 10;
1232 hgt = 26;
1233 shrinkX = 6;
1234 shrinkY = 6;
1235 break;
1236 case CHECK_STYLE:
1237 wid += 8;
1238 break;
1239 case RADIO_STYLE:
1240 wid += 8;
1241 break;
1242 default:
1243 wid += 0;
1244 break;
1245 }
1246 }
1247 #endif
1248
1249 #ifdef WIN_MSWIN
1250 switch (type) {
1251 case PUSH_STYLE:
1252 hgt = Nlm_stdLineHeight+8;
1253 wid += 20;
1254 break;
1255 case DEFAULT_STYLE:
1256 hgt = Nlm_stdLineHeight+8;
1257 wid += 20;
1258 break;
1259 case CHECK_STYLE:
1260 hgt = Nlm_stdLineHeight+3;
1261 wid += 20;
1262 break;
1263 case RADIO_STYLE:
1264 hgt = Nlm_stdLineHeight+3;
1265 wid += 20;
1266 break;
1267 default:
1268 hgt = Nlm_stdLineHeight;
1269 wid += 20;
1270 break;
1271 }
1272 #endif
1273
1274 #ifdef WIN_MOTIF
1275 hgt = 0;
1276 wid = 0;
1277 #endif
1278
1279 Nlm_LoadRect(&r, npt.x, npt.y, (Nlm_Int2)(npt.x+wid), (Nlm_Int2)(npt.y+hgt));
1280 b = (Nlm_ButtoN) Nlm_CreateLink ((Nlm_GraphiC) prnt, &r, sizeof (Nlm_ButtonRec), classPtr);
1281 if (b != NULL) {
1282 Nlm_NewButton (b, title, type, shrinkX, shrinkY, actn);
1283 Nlm_GetRect ((Nlm_GraphiC) b, &r);
1284 Nlm_DoAdjustPrnt ((Nlm_GraphiC) b, &r, TRUE, FALSE);
1285 Nlm_DoShow ((Nlm_GraphiC) b, TRUE, FALSE);
1286 }
1287 Nlm_RestorePort (tempPort);
1288
1289 return b;
1290 }
1291
1292
Nlm_PushButton(Nlm_GrouP prnt,Nlm_CharPtr title,Nlm_BtnActnProc actn)1293 extern Nlm_ButtoN Nlm_PushButton (Nlm_GrouP prnt, Nlm_CharPtr title,
1294 Nlm_BtnActnProc actn)
1295
1296 {
1297 Nlm_ButtoN b;
1298
1299 b = Nlm_CommonButton (prnt, title, PUSH_STYLE, actn, pushProcs);
1300 return b;
1301 }
1302
Nlm_DefaultButton(Nlm_GrouP prnt,Nlm_CharPtr title,Nlm_BtnActnProc actn)1303 extern Nlm_ButtoN Nlm_DefaultButton (Nlm_GrouP prnt, Nlm_CharPtr title,
1304 Nlm_BtnActnProc actn)
1305
1306 {
1307 Nlm_ButtoN b;
1308
1309 b = Nlm_CommonButton (prnt, title, DEFAULT_STYLE, actn, defaultProcs);
1310 return b;
1311 }
1312
Nlm_CheckBox(Nlm_GrouP prnt,Nlm_CharPtr title,Nlm_BtnActnProc actn)1313 extern Nlm_ButtoN Nlm_CheckBox (Nlm_GrouP prnt, Nlm_CharPtr title,
1314 Nlm_BtnActnProc actn)
1315
1316 {
1317 Nlm_ButtoN b;
1318
1319 b = Nlm_CommonButton (prnt, title, CHECK_STYLE, actn, checkProcs);
1320 return b;
1321 }
1322
Nlm_RadioButton(Nlm_GrouP prnt,Nlm_CharPtr title)1323 extern Nlm_ButtoN Nlm_RadioButton (Nlm_GrouP prnt, Nlm_CharPtr title)
1324
1325 {
1326 Nlm_ButtoN b;
1327
1328 b = Nlm_CommonButton (prnt, title, RADIO_STYLE, NULL, radioProcs);
1329 return b;
1330 }
1331
Nlm_FreeButtons(void)1332 extern void Nlm_FreeButtons (void)
1333
1334 {
1335 gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemFree (gphprcsptr);
1336 }
1337
Nlm_InitButtons(void)1338 extern void Nlm_InitButtons (void)
1339
1340 {
1341 gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemNew (sizeof (Nlm_GphPrcs) * 4);
1342
1343 pushProcs = &(gphprcsptr [0]);
1344 #ifdef WIN_MAC
1345 pushProcs->click = Nlm_PushClick;
1346 pushProcs->draw = Nlm_DrawButton;
1347 #endif
1348 #ifdef WIN_MSWIN
1349 pushProcs->command = Nlm_PushCommand;
1350 #endif
1351 #ifdef WIN_MOTIF
1352 pushProcs->callback = Nlm_PushCallback;
1353 #endif
1354 pushProcs->show = Nlm_ShowButton;
1355 pushProcs->hide = Nlm_HideButton;
1356 pushProcs->enable = Nlm_EnableButton;
1357 pushProcs->disable = Nlm_DisableButton;
1358 pushProcs->remove = Nlm_RemoveButton;
1359 pushProcs->setTitle = Nlm_SetButtonTitle;
1360 pushProcs->getTitle = Nlm_GetButtonTitle;
1361 pushProcs->setPosition = Nlm_SetButtonPosition;
1362 pushProcs->getPosition = Nlm_GetButtonPosition;
1363
1364 defaultProcs = &(gphprcsptr [1]);
1365 #ifdef WIN_MAC
1366 defaultProcs->click = Nlm_DefaultClick;
1367 defaultProcs->key = Nlm_DefaultKey;
1368 defaultProcs->draw = Nlm_DrawDefault;
1369 #endif
1370 #ifdef WIN_MSWIN
1371 defaultProcs->command = Nlm_DefaultCommand;
1372 #endif
1373 #ifdef WIN_MOTIF
1374 defaultProcs->callback = Nlm_DefaultCallback;
1375 #endif
1376 defaultProcs->show = Nlm_ShowButton;
1377 defaultProcs->hide = Nlm_HideButton;
1378 defaultProcs->enable = Nlm_EnableButton;
1379 defaultProcs->disable = Nlm_DisableButton;
1380 defaultProcs->remove = Nlm_RemoveDefaultButton;
1381 defaultProcs->setTitle = Nlm_SetButtonTitle;
1382 defaultProcs->getTitle = Nlm_GetButtonTitle;
1383 defaultProcs->setPosition = Nlm_SetButtonPosition;
1384 defaultProcs->getPosition = Nlm_GetButtonPosition;
1385 defaultProcs->gainFocus = Nlm_DefaultGainFocus;
1386
1387 checkProcs = &(gphprcsptr [2]);
1388 #ifdef WIN_MAC
1389 checkProcs->click = Nlm_CheckClick;
1390 checkProcs->draw = Nlm_DrawButton;
1391 #endif
1392 #ifdef WIN_MSWIN
1393 checkProcs->command = Nlm_CheckCommand;
1394 #endif
1395 #ifdef WIN_MOTIF
1396 checkProcs->callback = Nlm_CheckCallback;
1397 #endif
1398 checkProcs->show = Nlm_ShowButton;
1399 checkProcs->hide = Nlm_HideButton;
1400 checkProcs->enable = Nlm_EnableButton;
1401 checkProcs->disable = Nlm_DisableButton;
1402 checkProcs->remove = Nlm_RemoveButton;
1403 checkProcs->setTitle = Nlm_SetButtonTitle;
1404 checkProcs->getTitle = Nlm_GetButtonTitle;
1405 checkProcs->setStatus = Nlm_SetButtonStatus;
1406 checkProcs->getStatus = Nlm_GetButtonStatus;
1407 checkProcs->setPosition = Nlm_SetButtonPosition;
1408 checkProcs->getPosition = Nlm_GetButtonPosition;
1409
1410 radioProcs = &(gphprcsptr [3]);
1411 #ifdef WIN_MAC
1412 radioProcs->click = Nlm_RadioClick;
1413 radioProcs->draw = Nlm_DrawButton;
1414 #endif
1415 #ifdef WIN_MSWIN
1416 radioProcs->command = Nlm_RadioCommand;
1417 #endif
1418 #ifdef WIN_MOTIF
1419 radioProcs->callback = Nlm_RadioCallback;
1420 #endif
1421 radioProcs->show = Nlm_ShowButton;
1422 radioProcs->hide = Nlm_HideButton;
1423 radioProcs->enable = Nlm_EnableButton;
1424 radioProcs->disable = Nlm_DisableButton;
1425 radioProcs->remove = Nlm_RemoveButton;
1426 radioProcs->setTitle = Nlm_SetButtonTitle;
1427 radioProcs->getTitle = Nlm_GetButtonTitle;
1428 radioProcs->setStatus = Nlm_SetButtonStatus;
1429 radioProcs->getStatus = Nlm_GetButtonStatus;
1430 radioProcs->setPosition = Nlm_SetButtonPosition;
1431 radioProcs->getPosition = Nlm_GetButtonPosition;
1432 }
1433
1434
1435 extern void Nlm_SetButtonDefault (Nlm_ButtoN b, Nlm_Boolean dflt);
Nlm_SetButtonDefault(Nlm_ButtoN b,Nlm_Boolean dflt)1436 extern void Nlm_SetButtonDefault (Nlm_ButtoN b, Nlm_Boolean dflt)
1437 {
1438 if (b != NULL)
1439 {
1440 Nlm_BtnPtr bp = (Nlm_BtnPtr) Nlm_HandLock (b);
1441 bp->button.defaultBtn = dflt;
1442 Nlm_HandUnlock (b);
1443 }
1444 }
1445
1446
Nlm_NewButtonEx(Nlm_ButtoN b,Nlm_CharPtr title,Nlm_Int2 type,Nlm_Int2 shrinkX,Nlm_Int2 shrinkY,Nlm_BtnActnProc actn,Nlm_FonT font)1447 static void Nlm_NewButtonEx(Nlm_ButtoN b, Nlm_CharPtr title,
1448 Nlm_Int2 type, Nlm_Int2 shrinkX,
1449 Nlm_Int2 shrinkY, Nlm_BtnActnProc actn, Nlm_FonT font)
1450 {
1451 Nlm_FonT saveFont = Nlm_systemFont;
1452 Nlm_systemFont = font;
1453
1454 Nlm_NewButton(b, title, type, shrinkX, shrinkY, actn);
1455
1456 Nlm_systemFont = saveFont;
1457 }
1458
Nlm_CommonButtonEx(Nlm_GrouP prnt,Nlm_CharPtr title,Nlm_Int2 type,Nlm_BtnActnProc actn,Nlm_GphPrcsPtr classPtr,Nlm_FonT font)1459 static Nlm_ButtoN Nlm_CommonButtonEx(Nlm_GrouP prnt, Nlm_CharPtr title,
1460 Nlm_Int2 type, Nlm_BtnActnProc actn,
1461 Nlm_GphPrcsPtr classPtr, Nlm_FonT font)
1462
1463 {
1464 Nlm_ButtoN b = NULL;
1465 Nlm_Int2 hgt;
1466 Nlm_PoinT npt;
1467 Nlm_RecT r;
1468 Nlm_Int2 shrinkX = 0;
1469 Nlm_Int2 shrinkY = 0;
1470 Nlm_WindoW tempPort;
1471 Nlm_Int2 wid;
1472
1473 if (prnt == NULL) return NULL;
1474
1475 tempPort = Nlm_SavePort((Nlm_GraphiC)prnt);
1476 Nlm_GetNextPosition((Nlm_GraphiC)prnt, &npt);
1477 #if 1
1478 Nlm_SelectFont(font);
1479 #else
1480 Nlm_SelectFont(Nlm_systemFont);
1481 #endif
1482 wid = Nlm_StringWidth(title);
1483
1484 #ifdef WIN_MAC
1485 hgt = Nlm_stdLineHeight;
1486 wid += 20;
1487 switch (type) {
1488 case PUSH_STYLE:
1489 case DEFAULT_STYLE:
1490 hgt += 3;
1491 break;
1492 }
1493 if (Nlm_HasAquaMenuLayout()) {
1494 switch (type) {
1495 case PUSH_STYLE:
1496 wid += 10;
1497 hgt = 26;
1498 shrinkX = 6;
1499 shrinkY = 6;
1500 break;
1501 case DEFAULT_STYLE:
1502 wid += 10;
1503 hgt = 26;
1504 shrinkX = 6;
1505 shrinkY = 6;
1506 break;
1507 case CHECK_STYLE:
1508 wid += 4;
1509 break;
1510 case RADIO_STYLE:
1511 wid += 4;
1512 break;
1513 default:
1514 wid += 0;
1515 break;
1516 }
1517 }
1518 #endif
1519
1520 #ifdef WIN_MSWIN
1521 switch (type) {
1522 case PUSH_STYLE:
1523 hgt = Nlm_stdLineHeight + 8;
1524 wid += 20;
1525 break;
1526 case DEFAULT_STYLE:
1527 hgt = Nlm_stdLineHeight + 8;
1528 wid += 20;
1529 break;
1530 case CHECK_STYLE:
1531 hgt = Nlm_stdLineHeight + 3;
1532 wid += 20;
1533 break;
1534 case RADIO_STYLE:
1535 hgt = Nlm_stdLineHeight + 3;
1536 wid += 20;
1537 break;
1538 default:
1539 hgt = Nlm_stdLineHeight;
1540 wid += 20;
1541 break;
1542 }
1543 #endif
1544
1545 #ifdef WIN_MOTIF
1546 hgt = 0;
1547 wid = 0;
1548 #endif
1549
1550 Nlm_LoadRect(&r, npt.x, npt.y, (Nlm_Int2)(npt.x + wid), (Nlm_Int2)(npt.y + hgt));
1551 b = (Nlm_ButtoN)Nlm_CreateLink((Nlm_GraphiC)prnt, &r, sizeof(Nlm_ButtonRec), classPtr);
1552 if (b != NULL) {
1553 Nlm_NewButtonEx(b, title, type, shrinkX, shrinkY, actn, font);
1554 Nlm_GetRect((Nlm_GraphiC)b, &r);
1555 Nlm_DoAdjustPrnt((Nlm_GraphiC)b, &r, TRUE, FALSE);
1556 Nlm_DoShow((Nlm_GraphiC)b, TRUE, FALSE);
1557 }
1558 Nlm_RestorePort(tempPort);
1559
1560 return b;
1561 }
1562
Nlm_PushButtonEx(Nlm_GrouP prnt,Nlm_CharPtr title,Nlm_BtnActnProc actn,Nlm_FonT font)1563 extern Nlm_ButtoN Nlm_PushButtonEx(Nlm_GrouP prnt, Nlm_CharPtr title,
1564 Nlm_BtnActnProc actn, Nlm_FonT font)
1565
1566 {
1567 Nlm_ButtoN b;
1568
1569 b = Nlm_CommonButtonEx(prnt, title, PUSH_STYLE, actn, pushProcs, font);
1570 return b;
1571 }
1572
Nlm_DefaultButtonEx(Nlm_GrouP prnt,Nlm_CharPtr title,Nlm_BtnActnProc actn,Nlm_FonT font)1573 extern Nlm_ButtoN Nlm_DefaultButtonEx(Nlm_GrouP prnt, Nlm_CharPtr title,
1574 Nlm_BtnActnProc actn, Nlm_FonT font)
1575
1576 {
1577 Nlm_ButtoN b;
1578
1579 b = Nlm_CommonButtonEx(prnt, title, DEFAULT_STYLE, actn, defaultProcs, font);
1580 return b;
1581 }
1582
Nlm_CheckBoxEx(Nlm_GrouP prnt,Nlm_CharPtr title,Nlm_BtnActnProc actn,Nlm_FonT font)1583 extern Nlm_ButtoN Nlm_CheckBoxEx(Nlm_GrouP prnt, Nlm_CharPtr title,
1584 Nlm_BtnActnProc actn, Nlm_FonT font)
1585
1586 {
1587 Nlm_ButtoN b;
1588
1589 b = Nlm_CommonButtonEx(prnt, title, CHECK_STYLE, actn, checkProcs, font);
1590 return b;
1591 }
1592
Nlm_RadioButtonEx(Nlm_GrouP prnt,Nlm_CharPtr title,Nlm_FonT font)1593 extern Nlm_ButtoN Nlm_RadioButtonEx(Nlm_GrouP prnt, Nlm_CharPtr title, Nlm_FonT font)
1594
1595 {
1596 Nlm_ButtoN b;
1597
1598 b = Nlm_CommonButtonEx(prnt, title, RADIO_STYLE, NULL, radioProcs, font);
1599 return b;
1600 }
1601
Nlm_PopupListEx(Nlm_GrouP prnt,Nlm_Boolean macLike,Nlm_PupActnProc actn,Nlm_FonT font)1602 extern Nlm_PopuP Nlm_PopupListEx(Nlm_GrouP prnt, Nlm_Boolean macLike,
1603 Nlm_PupActnProc actn, Nlm_FonT font)
1604
1605 {
1606 Nlm_FonT saveFont = Nlm_systemFont;
1607 Nlm_systemFont = font;
1608
1609 Nlm_PopuP result = Nlm_PopupList(prnt, macLike, actn);
1610
1611 Nlm_systemFont = saveFont;
1612
1613 return result;
1614 }
1615
1616