1 /* vibsbars.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: vibsbars.c
27 *
28 * Author: Jonathan Kans
29 *
30 * Version Creation Date: 7/1/91
31 *
32 * $Revision: 6.8 $
33 *
34 * File Description:
35 * Vibrant scroll bar functions
36 *
37 * Modifications:
38 * --------------------------------------------------------------------------
39 * Date Name Description of modification
40 * ------- ---------- -----------------------------------------------------
41 *
42 *
43 * $Log: vibsbars.c,v $
44 * Revision 6.8 2016/07/19 16:58:07 choi
45 * JIRA SM-1185
46 * Fixed Windows implementation of invalRange().
47 *
48 * Revision 6.7 2016/04/01 16:15:08 bazhin
49 * Fixed to satisfy 64-bit Windows.
50 *
51 * Revision 6.6 2006/09/14 19:18:29 ivanov
52 * Rollback last changes. All missed defines added to corelib/ncbiwin.h.
53 *
54 * Revision 6.5 2006/09/14 18:05:45 ivanov
55 * Fixed compilation errors on MS Windows
56 *
57 * Revision 6.4 2006/09/14 14:45:38 kans
58 * changes for 64-bit Windows (GC) plus a few CodeWarrior complaints (JK)
59 *
60 * Revision 6.3 2001/04/05 03:23:07 juran
61 * Carbon UPP fix and removed pre-UPP support.
62 *
63 * Revision 6.2 1997/12/12 21:08:43 kans
64 * a number of symbols changed in the latest CodeWarrior release, now using headers from Apple
65 *
66 * Revision 6.1 1997/11/26 21:30:36 vakatov
67 * Fixed errors and warnings issued by C and C++ (GNU and Sun) compilers
68 *
69 * Revision 6.0 1997/08/25 18:57:35 madden
70 * Revision changed to 6.0
71 *
72 * Revision 5.10 1997/04/25 16:12:46 vakatov
73 * Process all line/page scrolling actions uniformly -- with the
74 * (new) Nlm_Scroll() function
75 *
76 * Revision 5.9 1996/09/25 23:43:17 kans
77 * setPos calls invalPos BEFORE user's callback, otherwise the scroll bar
78 * thumb can have a noticable delay, e.g., a doc object pulling items from
79 * the net to calculate the new bar maximum
80 *
81 * Revision 5.8 1996/09/24 14:21:57 kans
82 * restored call to invalPos after call to user's callback, which was used
83 * only to synchronize appearance of scroll bar with its internal state, not
84 * to affect the position returned by GetValue
85 *
86 * Revision 5.7 1996/09/24 12:31:10 kans
87 * ResetBar calls setMax with doCallback FALSE, to avoid an unwanted redraw,
88 * and setPos calls invalPos before calling the user's callback, to ensure
89 * that GetValue will be correct inside the callback.
90 *
91 * Revision 5.6 1996/09/19 18:51:39 vakatov
92 * [WIN_MOTIF] Set the scrollbar location and dimensions when creating
93 * the new scrollbar
94 *
95 * Revision 5.5 1996/09/10 15:31:03 vakatov
96 * [WIN_MOTIF] Syncronized the scrollbar slider size with the page
97 * size and maximum scrollbar value
98 *
99 * Revision 5.4 1996/09/06 17:26:16 kans
100 * when wrapping with saveportifneeded, pass FALSE instead of savePort inside
101 *
102 * Revision 5.3 1996/09/06 15:07:54 vakatov
103 * setPos(): Saved port before executing the scrollbar callback routine
104 *
105 * Revision 5.2 1996/08/27 20:48:10 vakatov
106 * Rearranged and partially rewritten in order to expand maximum scrollbar
107 * range from [0, INT2_MAX] to [0, INT4_MAX]
108 *
109 * Revision 5.1 1996/07/25 18:48:05 vakatov
110 * Made Nlm_GetBarMax() external (it was static)
111 *
112 * Revision 5.0 1996/05/28 13:45:08 ostell
113 * Set to revision 5.0
114 *
115 * Revision 4.3 1996/03/02 22:36:38 kans
116 * reduction of X traffic (DV)
117 *
118 * Revision 4.2 1996/02/13 19:49:04 kans
119 * scroll bar "realized" if force is TRUE, to handle cases where bar is
120 * owned by a panel or text, not in the normal vibrant child list
121 *
122 * Revision 4.1 1996/02/13 17:24:07 kans
123 * accelerated set position prior to realization (Denis Vakatov)
124 *
125 * Revision 4.0 1995/07/26 13:51:04 ostell
126 * force revision to 4.0
127 *
128 * Revision 2.18 1995/05/17 15:15:14 kans
129 * added Log line
130 *
131 *
132 * ==========================================================================
133 */
134
135 #include <vibtypes.h>
136 #include <vibprocs.h>
137 #include <vibincld.h>
138
139
140 /*********************************************************************
141 * PRIVATE
142 *********************************************************************/
143
144 /* Note that the scroll bar tool type is also duplicated in vibwndws.c */
145
146 #ifdef WIN_MAC
147 #define Nlm_BarTool ControlHandle
148 #endif
149
150 #ifdef WIN_MSWIN
151 # define Nlm_BarTool HWND
152 #endif
153
154 #ifdef WIN_MOTIF
155 #define Nlm_BarTool Widget
156 #endif
157
158 typedef struct Nlm_bardata
159 {
160 Nlm_BarTool handle;
161 Nlm_Int4 pageUp;
162 Nlm_Int4 pageDn;
163 Nlm_Int4 delta;
164 Nlm_Int4 delta_max;
165 Nlm_Boolean anomaly;
166 Nlm_GraphiC slave;
167
168 Nlm_BarScrlProc4 action4;
169 Nlm_BarScrlProc action;
170
171 Nlm_Int2 value;
172 Nlm_Int2 maximum;
173
174 Nlm_Int4 factor;
175 Nlm_Int4 rem;
176 Nlm_Int4 max;
177 Nlm_Int4 pos;
178 } Nlm_BarData;
179
180
181 typedef struct Nlm_barrec
182 {
183 Nlm_GraphicRec graphicR;
184 Nlm_BarData bar;
185 } Nlm_BarRec, PNTR Nlm_BarPtr;
186
187 static Nlm_BaR recentBar = NULL;
188 static Nlm_BarData recentBarData;
189
190
Nlm_SetBarData(Nlm_BaR b,Nlm_BarData * bdata)191 static void Nlm_SetBarData (Nlm_BaR b, Nlm_BarData *bdata)
192 {
193 Nlm_BarPtr bp = (Nlm_BarPtr)Nlm_HandLock( b );
194 if (bp == NULL)
195 return;
196
197 bp->bar = *bdata;
198 Nlm_HandUnlock( b );
199
200 recentBar = b;
201 recentBarData = *bdata;
202 }
203
Nlm_GetBarData(Nlm_BaR b,Nlm_BarData * bdata)204 static void Nlm_GetBarData (Nlm_BaR b, Nlm_BarData *bdata)
205 {
206 if (b == NULL)
207 return;
208
209 if (b == recentBar)
210 *bdata = recentBarData;
211 else
212 {
213 Nlm_BarPtr bp = (Nlm_BarPtr)Nlm_HandLock( b );
214 *bdata = bp->bar;
215 Nlm_HandUnlock( b );
216 recentBar = b;
217 recentBarData = *bdata;
218 }
219 }
220
221
invalPos(Nlm_BaR b,Nlm_Boolean savePort)222 static void invalPos(Nlm_BaR b, Nlm_Boolean savePort)
223 {
224 Nlm_BarData bdata;
225 Nlm_WindoW tempPort;
226
227 if (b == NULL)
228 return;
229
230 Nlm_GetBarData((Nlm_BaR)b, &bdata);
231 if (bdata.delta == 0 /* || !Nlm_GetEnabled( (Nlm_GraphiC)b ) */ )
232 return;
233
234 tempPort = Nlm_SavePortIfNeeded((Nlm_GraphiC)b, savePort);
235
236 #ifdef WIN_MAC
237 SetControlValue(bdata.handle, bdata.value);
238 #endif
239 #ifdef WIN_MSWIN
240 SetScrollPos(bdata.handle, SB_CTL, bdata.value, TRUE);
241 #endif
242 #ifdef WIN_MOTIF
243 XtVaSetValues(bdata.handle, XmNvalue, (int)bdata.value, NULL);
244 #endif
245
246 bdata.delta = 0;
247 Nlm_SetBarData(b, &bdata);
248 Nlm_RestorePort( tempPort );
249 }
250
251
setPos(Nlm_BaR b,Nlm_Int4 pos,Nlm_Boolean savePort,Nlm_Boolean doCallback)252 static void setPos(Nlm_BaR b, Nlm_Int4 pos,
253 Nlm_Boolean savePort, Nlm_Boolean doCallback)
254 {
255 Nlm_BarData bdata;
256 Nlm_Int4 prev_pos;
257 Nlm_WindoW tempPort;
258
259 if (b == NULL)
260 return;
261
262 Nlm_GetBarData(b, &bdata);
263
264 if (pos < 0)
265 pos = 0;
266 else if (pos > bdata.max)
267 pos = bdata.max;
268
269 if (pos == bdata.pos)
270 return;
271
272 prev_pos = bdata.pos;
273 bdata.delta += pos - bdata.pos;
274 bdata.pos = pos;
275 bdata.rem = pos % bdata.factor;
276 bdata.value = (Nlm_Int2)(pos / bdata.factor);
277 ASSERT ( bdata.value <= bdata.maximum );
278 #if defined(TEST_MODULE_VIBSBARS) && defined(OS_UNIX)
279 fprintf(stderr, "dpos=%ld, newpos=%ld, newval=%ld\n",
280 (long)bdata.delta, (long)bdata.pos, (long)bdata.value);
281 #endif
282 Nlm_SetBarData(b, &bdata);
283
284 tempPort = Nlm_SavePortIfNeeded((Nlm_GraphiC)b, savePort);
285 invalPos(b, FALSE);
286
287 if ( doCallback )
288 {
289
290 if (bdata.action4 != NULL)
291 (*bdata.action4)(b, bdata.slave, bdata.pos, prev_pos);
292
293 if (bdata.action != NULL)
294 {
295 Nlm_Int2 curr_pos_2 = (Nlm_Int2)
296 ((bdata.pos < INT2_MAX) ? bdata.pos : INT2_MAX);
297 Nlm_Int2 prev_pos_2 = (Nlm_Int2)
298 ((prev_pos < INT2_MAX) ? prev_pos : INT2_MAX);
299
300 (*bdata.action)(b, bdata.slave, curr_pos_2, prev_pos_2);
301 }
302
303 }
304
305 Nlm_RestorePort( tempPort );
306 }
307
308
getPos(Nlm_BaR b)309 static Nlm_Int4 getPos(Nlm_BaR b)
310 {
311 Nlm_BarData bdata;
312 if (b == NULL)
313 return 0;
314
315 Nlm_GetBarData(b, &bdata);
316
317 return bdata.pos;
318 }
319
320
setValue(Nlm_BaR b,Nlm_Int2 value,Nlm_Boolean savePort)321 static void setValue(Nlm_BaR b, Nlm_Int2 value, Nlm_Boolean savePort)
322 {
323 Nlm_BarData bdata;
324 Nlm_GetBarData(b, &bdata);
325
326 setPos(b, value * bdata.factor, savePort, TRUE);
327 }
328
329
invalRange(Nlm_BaR b,Nlm_Boolean savePort)330 static void invalRange(Nlm_BaR b, Nlm_Boolean savePort)
331 {
332 Nlm_BarData bdata;
333 Nlm_WindoW tempPort;
334
335 if (b == NULL /* || !Nlm_GetEnabled( (Nlm_GraphiC)b ) */ )
336 return;
337
338 Nlm_GetBarData(b, &bdata);
339 if (bdata.delta_max == 0 && bdata.max != 0)
340 return;
341
342 bdata.delta_max = 0;
343 Nlm_SetBarData(b, &bdata);
344
345 if (bdata.maximum < 0)
346 return;
347
348 tempPort = Nlm_SavePortIfNeeded((Nlm_GraphiC)b, savePort);
349
350 #ifdef WIN_MAC
351 SetControlMaximum(bdata.handle, bdata.maximum);
352 #endif
353 #ifdef WIN_MSWIN
354 /* SetScrollRange(bdata.handle, SB_CTL, 0, bdata.maximum, TRUE); */
355 /* SendMessage(bdata.handle, SBM_SETRANGEREDRAW, 0, bdata.maximum); */
356 {{
357 SCROLLINFO si;
358 int page = ((bdata.pageUp + bdata.pageDn) / 2) / bdata.factor;
359 page = MAX(1, page);
360 page = MIN(page, (INT2_MAX - bdata.maximum - 1));
361 memset(&si, 0, sizeof(si));
362 si.cbSize = sizeof(si);
363 si.fMask = SIF_PAGE | SIF_RANGE;
364 si.nMin = 0;
365 /*
366 Win32 docs say : MaxScrollPos = MaxRangeValue - (PageSize - 1)
367 since we want MaxScrollPos == bdata.maximum, then we have via substitution
368 MaxScrollPos = (bdata.maximum + PageSize - 1) - (PageSize - 1)
369 MaxScrollPos = bdata.maximum
370 */
371 si.nMax = bdata.maximum + page - 1;
372 si.nPage = page;
373 SetScrollInfo(bdata.handle, SB_CTL, &si, TRUE);
374 }}
375 #endif
376 #ifdef WIN_MOTIF
377 {{
378 int page = ((bdata.pageUp + bdata.pageDn) / 2) / bdata.factor;
379 page = MAX(1, page);
380 page = MIN(page, (INT2_MAX - bdata.maximum - 1));
381 XtVaSetValues(bdata.handle,
382 XmNmaximum, (int)(bdata.maximum + page),
383 XmNpageIncrement, page,
384 XmNsliderSize, page,
385 NULL);
386 }}
387 #endif
388
389 Nlm_RestorePort( tempPort );
390 }
391
392
setMax(Nlm_BaR b,Nlm_Int4 max,Nlm_Boolean savePort,Nlm_Boolean doCallback)393 static void setMax(Nlm_BaR b, Nlm_Int4 max,
394 Nlm_Boolean savePort, Nlm_Boolean doCallback)
395 {
396 Nlm_BarData bdata;
397 Nlm_WindoW tempPort;
398
399 Nlm_GetBarData(b, &bdata);
400
401 if (b == NULL)
402 return;
403
404 if (max < 0)
405 max = 0;
406 bdata.delta_max = max - bdata.max;
407 bdata.max = max;
408 bdata.factor = max / INT2_MAX + 1;
409 bdata.maximum = (Nlm_Int2)((max + bdata.factor - 1) / bdata.factor);
410 Nlm_SetBarData(b, &bdata);
411 #if defined(TEST_MODULE_VIBSBARS) && defined(OS_UNIX)
412 fprintf(stderr, "dmax=%ld, newmax=%ld, newmaxval=%ld\n",
413 (long)bdata.delta_max, (long)bdata.max, (long)bdata.maximum);
414 #endif
415 tempPort = Nlm_SavePortIfNeeded((Nlm_GraphiC)b, savePort);
416 if (bdata.delta_max < 0)
417 setPos(b, bdata.pos, FALSE, doCallback);
418 invalRange(b, FALSE);
419 Nlm_RestorePort( tempPort );
420 }
421
422
423
424 static Nlm_GphPrcsPtr gphprcsptr = NULL;
425
426 static Nlm_GphPrcsPtr barProcs;
427 static Nlm_GphPrcsPtr linkedBarProcs;
428
429 #ifdef WIN_MSWIN
430 static WNDPROC lpfnNewBarProc = NULL;
431 static WNDPROC lpfnOldBarProc = NULL;
432 static Nlm_Boolean handlechar;
433 #endif
434
435
Nlm_LoadBarData(Nlm_BaR b,Nlm_BarTool hdl,Nlm_Int4 pgUp,Nlm_Int4 pgDn,Nlm_Int4 dlta,Nlm_Int4 val,Nlm_Int4 max,Nlm_Boolean anomaly,Nlm_GraphiC slv,Nlm_BarScrlProc4 actn4,Nlm_BarScrlProc actn)436 static void Nlm_LoadBarData (Nlm_BaR b, Nlm_BarTool hdl,
437 Nlm_Int4 pgUp, Nlm_Int4 pgDn,
438 Nlm_Int4 dlta, Nlm_Int4 val,
439 Nlm_Int4 max, Nlm_Boolean anomaly,
440 Nlm_GraphiC slv,
441 Nlm_BarScrlProc4 actn4, Nlm_BarScrlProc actn)
442 {
443 Nlm_BarPtr bp = (Nlm_BarPtr)Nlm_HandLock( b );
444 Nlm_BarData PNTR bdptr = &bp->bar;
445 bdptr->handle = hdl;
446 bdptr->pageUp = pgUp;
447 bdptr->pageDn = pgDn;
448 bdptr->delta = dlta;
449 bdptr->delta_max = 0;
450 bdptr->anomaly = anomaly;
451 bdptr->slave = slv;
452 bdptr->action4 = actn4;
453 bdptr->action = actn;
454 setMax(b, max, FALSE, FALSE);
455 setPos(b, val, FALSE, FALSE);
456 Nlm_HandUnlock( b );
457 recentBar = NULL;
458 }
459
460
Nlm_GetBarHandle(Nlm_BaR b)461 static Nlm_BarTool Nlm_GetBarHandle (Nlm_BaR b)
462 {
463 Nlm_BarData bdata;
464
465 Nlm_GetBarData(b, &bdata);
466 return bdata.handle;
467 }
468
469
Nlm_GetBarPageUp(Nlm_BaR b)470 static Nlm_Int4 Nlm_GetBarPageUp (Nlm_BaR b)
471 {
472 Nlm_BarData bdata;
473
474 Nlm_GetBarData (b, &bdata);
475 return bdata.pageUp;
476 }
477
478
Nlm_GetBarPageDown(Nlm_BaR b)479 static Nlm_Int4 Nlm_GetBarPageDown (Nlm_BaR b)
480 {
481 Nlm_BarData bdata;
482
483 Nlm_GetBarData (b, &bdata);
484 return bdata.pageDn;
485 }
486
487
488 #ifdef WIN_MAC
489 pascal void ScrollAction PROTO((Nlm_BarTool c, Nlm_Int2 part));
ScrollAction(Nlm_BarTool c,Nlm_Int2 part)490 pascal void ScrollAction(Nlm_BarTool c, Nlm_Int2 part)
491 {
492 Nlm_enumScrollEvent event;
493
494 switch ( part )
495 {
496 case kControlUpButtonPart:
497 event = SCROLL_LINEUP; break;
498 case kControlDownButtonPart:
499 event = SCROLL_LINEDN; break;
500 case kControlPageUpPart:
501 event = SCROLL_PAGEUP; break;
502 case kControlPageDownPart:
503 event = SCROLL_PAGEDN; break;
504 default:
505 return;
506 }
507
508 Nlm_Scroll((Nlm_BaR)GetControlReference( c ), event);
509 }
510
511
Nlm_ScrollClick(Nlm_GraphiC b,Nlm_PoinT pt)512 static Nlm_Boolean Nlm_ScrollClick (Nlm_GraphiC b, Nlm_PoinT pt)
513 {
514 Nlm_BarTool c;
515 Nlm_Int2 part;
516 Nlm_PointTool ptool;
517 Nlm_RecT r;
518
519 Nlm_GetRect (b, &r);
520 if ( !Nlm_PtInRect(pt, &r) )
521 return FALSE;
522
523 c = Nlm_GetBarHandle ( (Nlm_BaR)b );
524 Nlm_PoinTToPointTool (pt, &ptool);
525
526 part = TestControl(c, ptool);
527 if (part == kControlIndicatorPart)
528 {
529 TrackControl(c, ptool, NULL);
530 setValue((Nlm_BaR)b, GetControlValue(c), TRUE);
531 }
532 else
533 {
534 ControlActionUPP proc = NewControlActionUPP(ScrollAction);
535 TrackControl(c, ptool, proc);
536 DisposeControlActionUPP( proc );
537 }
538
539 return TRUE;
540 }
541 #endif
542
543
544 #ifdef WIN_MSWIN
Nlm_ScrollCommand(Nlm_GraphiC g)545 static Nlm_Boolean Nlm_ScrollCommand(Nlm_GraphiC g)
546 {
547 Nlm_enumScrollEvent event;
548
549 switch ( Nlm_currentCode )
550 {
551 case SB_LINEUP:
552 event = SCROLL_LINEUP; break;
553 case SB_LINEDOWN:
554 event = SCROLL_LINEDN; break;
555 case SB_PAGEUP:
556 event = SCROLL_PAGEUP; break;
557 case SB_PAGEDOWN:
558 event = SCROLL_PAGEDN; break;
559 case SB_THUMBPOSITION:
560 setValue((Nlm_BaR)g, (Nlm_Int2)Nlm_currentPos, TRUE);
561 return TRUE;
562 case SB_THUMBTRACK:
563 setValue((Nlm_BaR)g, (Nlm_Int2)Nlm_currentPos, TRUE);
564 return TRUE;
565 default:
566 return FALSE;
567 }
568
569 Nlm_Scroll((Nlm_BaR)g, event);
570 return TRUE;
571 }
572 #endif
573
574
575 #ifdef WIN_MAC
Nlm_DrawBar(Nlm_GraphiC b)576 static void Nlm_DrawBar (Nlm_GraphiC b)
577 {
578 Nlm_BarData bdata;
579 Nlm_BarTool c;
580 Nlm_RecT r;
581
582 if (!Nlm_GetVisible( b ) || !Nlm_GetAllParentsVisible( b ))
583 return;
584
585 Nlm_GetBarData ((Nlm_BaR) b, &bdata);
586 Nlm_GetRect (b, &r);
587 if ( !Nlm_RectInRgn(&r, Nlm_updateRgn) )
588 return;
589
590 c = bdata.handle;
591
592 if (bdata.maximum != GetControlMaximum( c ))
593 SetControlMaximum(c, bdata.maximum);
594 if (bdata.value != GetControlValue( c ))
595 SetControlValue(c, bdata.value);
596
597 Draw1Control( c );
598 }
599 #endif
600
601
Nlm_ShowBar(Nlm_GraphiC b,Nlm_Boolean setFlag,Nlm_Boolean savePort)602 static void Nlm_ShowBar (Nlm_GraphiC b, Nlm_Boolean setFlag, Nlm_Boolean savePort)
603 {
604 Nlm_BarTool c;
605 Nlm_WindoW tempPort;
606
607 if ( setFlag )
608 Nlm_SetVisible(b, TRUE);
609
610 if (!Nlm_GetVisible( b ) || !Nlm_AllParentsButWindowVisible( b ))
611 return;
612
613 tempPort = Nlm_SavePortIfNeeded(b, savePort);
614 c = Nlm_GetBarHandle( (Nlm_BaR)b );
615
616 #ifdef WIN_MAC
617 ShowControl( c );
618 Nlm_DoDraw( b );
619 #endif
620 #ifdef WIN_MSWIN
621 ShowWindow(c, SW_SHOW);
622 UpdateWindow( c );
623 #endif
624 #ifdef WIN_MOTIF
625 XtManageChild( c );
626 #endif
627
628 Nlm_RestorePort( tempPort );
629 }
630
631
Nlm_HideBar(Nlm_GraphiC b,Nlm_Boolean setFlag,Nlm_Boolean savePort)632 static void Nlm_HideBar (Nlm_GraphiC b, Nlm_Boolean setFlag, Nlm_Boolean savePort)
633 {
634 Nlm_BarTool c = Nlm_GetBarHandle( (Nlm_BaR)b );
635 Nlm_WindoW tempPort = Nlm_SavePortIfNeeded(b, savePort);
636 #ifdef WIN_MAC
637 Nlm_RecT r;
638 #endif
639
640 if ( setFlag )
641 Nlm_SetVisible(b, FALSE);
642
643 #ifdef WIN_MAC
644 HideControl( c );
645 if ( Nlm_GetAllParentsVisible(b) )
646 {
647 Nlm_GetRect (b, &r);
648 Nlm_InsetRect (&r, -1, -1);
649 Nlm_EraseRect (&r);
650 Nlm_ValidRect (&r);
651 }
652 #endif
653 #ifdef WIN_MSWIN
654 ShowWindow(c, SW_HIDE);
655 UpdateWindow( c );
656 #endif
657 #ifdef WIN_MOTIF
658 XtUnmanageChild( c );
659 #endif
660
661 Nlm_RestorePort( tempPort );
662 }
663
664
Nlm_EnableBar(Nlm_GraphiC b,Nlm_Boolean setFlag,Nlm_Boolean savePort)665 static void Nlm_EnableBar (Nlm_GraphiC b, Nlm_Boolean setFlag, Nlm_Boolean savePort)
666 {
667 Nlm_BarData bdata;
668 Nlm_WindoW tempPort;
669
670 if ( setFlag )
671 Nlm_SetEnabled(b, TRUE);
672
673 if (!Nlm_GetEnabled( b ) || !Nlm_GetAllParentsEnabled( b ))
674 return;
675
676 Nlm_GetBarData ((Nlm_BaR) b, &bdata);
677 tempPort = Nlm_SavePortIfNeeded(b, savePort);
678
679 #ifdef WIN_MSWIN
680 EnableWindow(bdata.handle, TRUE);
681 #endif
682
683 invalPos ((Nlm_BaR)b, savePort);
684 invalRange((Nlm_BaR)b, savePort);
685
686 #ifdef WIN_MAC
687 HiliteControl(bdata.handle, 0);
688 #endif
689 #ifdef WIN_MOTIF
690 XtVaSetValues(bdata.handle, XmNsensitive, TRUE, NULL);
691 #endif
692
693 Nlm_RestorePort (tempPort);
694 }
695
696
Nlm_DisableBar(Nlm_GraphiC b,Nlm_Boolean setFlag,Nlm_Boolean savePort)697 static void Nlm_DisableBar (Nlm_GraphiC b, Nlm_Boolean setFlag, Nlm_Boolean savePort)
698 {
699 Nlm_BarTool c = Nlm_GetBarHandle( (Nlm_BaR)b );
700 Nlm_WindoW tempPort = Nlm_SavePortIfNeeded(b, savePort);
701
702 if ( setFlag )
703 Nlm_SetEnabled(b, FALSE);
704
705 #ifdef WIN_MAC
706 HiliteControl(c, 255);
707 #endif
708 #ifdef WIN_MSWIN
709 EnableWindow(c, FALSE);
710 #endif
711 #ifdef WIN_MOTIF
712 XtVaSetValues(c, XmNsensitive, FALSE, NULL);
713 #endif
714
715 Nlm_RestorePort( tempPort );
716 }
717
718
Nlm_ResetBar(Nlm_GraphiC b,Nlm_Boolean savePort)719 static void Nlm_ResetBar (Nlm_GraphiC b, Nlm_Boolean savePort)
720 {
721 setMax((Nlm_BaR)b, 0, savePort, FALSE);
722 }
723
724
Nlm_RemoveBar(Nlm_GraphiC b,Nlm_Boolean savePort)725 static void Nlm_RemoveBar (Nlm_GraphiC b, Nlm_Boolean savePort)
726 {
727 Nlm_BarTool c = Nlm_GetBarHandle( (Nlm_BaR)b );
728 Nlm_WindoW tempPort = Nlm_SavePortIfNeeded(b, savePort);
729 Nlm_GraphicData gdata;
730
731 #ifdef WIN_MAC
732 DisposeControl( c );
733 #endif
734 #ifdef WIN_MSWIN
735 RemoveProp(c, (LPSTR)"Nlm_VibrantProp");
736 DestroyWindow( c );
737 #endif
738 #ifdef WIN_MOTIF
739 XtDestroyWidget( c );
740 #endif
741
742 Nlm_GetGraphicData(b, &gdata);
743 if (gdata.data != NULL && gdata.cleanup != NULL)
744 gdata.cleanup(b, gdata.data);
745
746 Nlm_HandFree( b );
747 recentBar = NULL;
748 Nlm_RestorePort( tempPort );
749 }
750
751
Nlm_RemoveLinkedInBar(Nlm_GraphiC b,Nlm_Boolean savePort)752 static void Nlm_RemoveLinkedInBar (Nlm_GraphiC b, Nlm_Boolean savePort)
753 {
754 Nlm_BarTool c = Nlm_GetBarHandle( (Nlm_BaR)b );
755 Nlm_WindoW tempPort = Nlm_SavePortIfNeeded(b, savePort);
756
757 #ifdef WIN_MAC
758 DisposeControl( c );
759 #endif
760 #ifdef WIN_MSWIN
761 RemoveProp(c, (LPSTR)"Nlm_VibrantProp");
762 DestroyWindow( c );
763 #endif
764 #ifdef WIN_MOTIF
765 XtDestroyWidget( c );
766 #endif
767
768 Nlm_RemoveLink( b );
769 recentBar = NULL;
770 Nlm_RestorePort( tempPort );
771 }
772
773
Nlm_SetBarValue2(Nlm_GraphiC b,Nlm_Int2 val,Nlm_Boolean savePort)774 static void Nlm_SetBarValue2(Nlm_GraphiC b, Nlm_Int2 val, Nlm_Boolean savePort)
775 {
776 setPos((Nlm_BaR)b, (Nlm_Int4)val, savePort, TRUE);
777 }
778
779
Nlm_GetBarValue2(Nlm_GraphiC b)780 static Nlm_Int2 Nlm_GetBarValue2 (Nlm_GraphiC b)
781 {
782 Nlm_Int4 pos = getPos( (Nlm_BaR)b );
783 if (pos > INT2_MAX)
784 pos = INT2_MAX;
785
786 return (Nlm_Int2)pos;
787 }
788
789
790 #ifdef WIN_MAC
Nlm_InvalBar(Nlm_GraphiC b)791 static void Nlm_InvalBar (Nlm_GraphiC b)
792 {
793 Nlm_RecT r;
794 if (!Nlm_GetVisible( b ) || !Nlm_GetAllParentsVisible( b ))
795 return;
796
797 Nlm_GetRect(b, &r);
798 Nlm_InsetRect(&r, -1, -1);
799 Nlm_InvalRect( &r );
800 }
801 #endif
802
803
Nlm_SetBarPosition(Nlm_GraphiC b,Nlm_RectPtr r,Nlm_Boolean savePort,Nlm_Boolean force)804 static void Nlm_SetBarPosition (Nlm_GraphiC b, Nlm_RectPtr r,
805 Nlm_Boolean savePort, Nlm_Boolean force)
806 {
807 Nlm_BarTool c;
808 Nlm_GraphicData gdata;
809 Nlm_WindoW tempPort;
810
811 if (r == NULL)
812 return;
813
814 tempPort = Nlm_SavePortIfNeeded(b, savePort);
815 if (force)
816 {
817 Nlm_GetGraphicData(b, &gdata);
818 if ( !gdata.realized )
819 {
820 gdata.realized = TRUE;
821 Nlm_SetGraphicData(b, &gdata);
822 }
823 invalRange((Nlm_BaR)b, FALSE);
824 invalPos ((Nlm_BaR)b, FALSE);
825 }
826
827 if ( !Nlm_GetRealized( b ) )
828 {
829 Nlm_SetRect (b, r);
830 Nlm_RestorePort( tempPort );
831 return;
832 }
833
834 c = Nlm_GetBarHandle( (Nlm_BaR)b );
835
836 #ifdef WIN_MAC
837 Nlm_InvalBar( b );
838 MoveControl(c, r->left, r->top);
839 SizeControl(c, r->right - r->left, r->bottom - r->top);
840 Nlm_SetRect(b, r);
841 Nlm_InvalBar( b );
842 #endif
843 #ifdef WIN_MSWIN
844 Nlm_SetRect(b, r);
845 MoveWindow(c, r->left, r->top, r->right - r->left, r->bottom - r->top, TRUE);
846 UpdateWindow( c );
847 #endif
848 #ifdef WIN_MOTIF
849 XtVaSetValues (c,
850 XmNx, (Position) r->left,
851 XmNy, (Position) r->top,
852 XmNwidth, (Dimension) (r->right - r->left),
853 XmNheight, (Dimension) (r->bottom - r->top),
854 NULL);
855 Nlm_SetRect(b, r);
856 #endif
857
858 Nlm_RestorePort( tempPort );
859 }
860
861
Nlm_GetBarPosition(Nlm_GraphiC b,Nlm_RectPtr r)862 static void Nlm_GetBarPosition (Nlm_GraphiC b, Nlm_RectPtr r)
863 {
864 if (r != NULL)
865 Nlm_GetRect(b, r);
866 }
867
868
869
Nlm_SetBarRange2(Nlm_GraphiC b,Nlm_Int2 pgUp,Nlm_Int2 pgDn,Nlm_Int2 max,Nlm_Boolean savePort)870 static void Nlm_SetBarRange2(Nlm_GraphiC b, Nlm_Int2 pgUp,
871 Nlm_Int2 pgDn, Nlm_Int2 max,
872 Nlm_Boolean savePort)
873 {
874 Nlm_CorrectBarPage((Nlm_BaR)b, (Nlm_Int4)pgUp, (Nlm_Int4)pgDn);
875 if (max > 0) {
876 setMax((Nlm_BaR)b, max, savePort, FALSE);
877 }
878 }
879
880
881 #ifdef WIN_MSWIN
882 /* Message cracker functions */
MyCls_OnChar(HWND hwnd,UINT ch,int cRepeat)883 static void MyCls_OnChar (HWND hwnd, UINT ch, int cRepeat)
884
885 {
886 Nlm_BaR b = (Nlm_BaR)GetProp(hwnd, (LPSTR)"Nlm_VibrantProp");
887
888 if (ch == '\t' || ch == '\n' || ch == '\r')
889 {
890 handlechar = FALSE;
891 Nlm_DoSendFocus ((Nlm_GraphiC) b, (Nlm_Char) ch);
892 }
893 else
894 handlechar = TRUE;
895 }
896
897
BarProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)898 static LRESULT CALLBACK EXPORT BarProc (HWND hwnd, UINT message,
899 WPARAM wParam, LPARAM lParam)
900 {
901 Nlm_BaR b;
902 LRESULT rsult = 0;
903 BOOL call_win_proc = TRUE;
904 HDC tempHDC;
905 HWND tempHWnd;
906
907 if ( Nlm_VibrantDisabled() )
908 return CallWindowProc(lpfnOldBarProc, hwnd, message, wParam, lParam);
909
910 tempHWnd = Nlm_currentHWnd;
911 tempHDC = Nlm_currentHDC;
912
913 b = (Nlm_BaR)GetProp(hwnd, (LPSTR)"Nlm_VibrantProp");
914
915 Nlm_theWindow = Nlm_GetParentWindow( (Nlm_GraphiC)b );
916 Nlm_currentHWnd = GetParent( hwnd );
917 Nlm_currentHDC = Nlm_ParentWindowPort( (Nlm_GraphiC)b );
918 Nlm_currentWindowTool = hwnd;
919
920 Nlm_currentWParam = wParam;
921 Nlm_currentLParam = lParam;
922
923 Nlm_currentKey = '\0';
924 Nlm_cmmdKey = FALSE;
925 Nlm_ctrlKey = FALSE;
926 Nlm_optKey = FALSE;
927 Nlm_shftKey = FALSE;
928 Nlm_dblClick = FALSE;
929
930 switch ( message )
931 {
932 case WM_KEYDOWN:
933 call_win_proc = !Nlm_ProcessKeydown((Nlm_GraphiC)b, wParam,
934 VERT_PAGE|VERT_ARROW|HORIZ_PAGE|HORIZ_ARROW);
935 break;
936 case WM_CHAR:
937 HANDLE_WM_CHAR(hwnd, wParam, lParam, MyCls_OnChar);
938 call_win_proc = handlechar;
939 break;
940 }
941
942 if ( call_win_proc )
943 rsult = CallWindowProc(lpfnOldBarProc, hwnd, message, wParam, lParam);
944
945 Nlm_currentHWnd = tempHWnd;
946 Nlm_currentHDC = tempHDC;
947 Nlm_currentWindowTool = tempHWnd;
948 return rsult;
949 }
950 #endif
951
952
953 #ifdef WIN_MOTIF
Nlm_LineUpCallback(Widget w,XtPointer client_data,XtPointer call_data)954 static void Nlm_LineUpCallback (Widget w,
955 XtPointer client_data, XtPointer call_data)
956 {
957 Nlm_Scroll((Nlm_BaR)client_data, SCROLL_LINEUP);
958 }
959
Nlm_LineDnCallback(Widget w,XtPointer client_data,XtPointer call_data)960 static void Nlm_LineDnCallback (Widget w,
961 XtPointer client_data, XtPointer call_data)
962 {
963 Nlm_Scroll((Nlm_BaR)client_data, SCROLL_LINEDN);
964 }
965
Nlm_PageUpCallback(Widget w,XtPointer client_data,XtPointer call_data)966 static void Nlm_PageUpCallback (Widget w,
967 XtPointer client_data, XtPointer call_data)
968 {
969 Nlm_Scroll((Nlm_BaR)client_data, SCROLL_PAGEUP);
970 }
971
Nlm_PageDnCallback(Widget w,XtPointer client_data,XtPointer call_data)972 static void Nlm_PageDnCallback (Widget w,
973 XtPointer client_data, XtPointer call_data)
974 {
975 Nlm_Scroll((Nlm_BaR)client_data, SCROLL_PAGEDN);
976 }
977
Nlm_ThumbCallback(Widget w,XtPointer client_data,XtPointer call_data)978 static void Nlm_ThumbCallback (Widget w,
979 XtPointer client_data, XtPointer call_data)
980 {
981 XmScrollBarCallbackStruct *cbs = (XmScrollBarCallbackStruct *)call_data;
982 setValue((Nlm_BaR)client_data, (Nlm_Int2)cbs->value, TRUE);
983 }
984
Nlm_TopCallback(Widget w,XtPointer client_data,XtPointer call_data)985 static void Nlm_TopCallback (Widget w,
986 XtPointer client_data, XtPointer call_data)
987 {
988 setValue((Nlm_BaR)client_data, 0, TRUE);
989 }
990
Nlm_BottomCallback(Widget w,XtPointer client_data,XtPointer call_data)991 static void Nlm_BottomCallback (Widget w,
992 XtPointer client_data, XtPointer call_data)
993 {
994 setValue((Nlm_BaR)client_data, (Nlm_Int2)INT2_MAX, TRUE);
995 }
996
Nlm_DragCallback(Widget w,XtPointer client_data,XtPointer call_data)997 static void Nlm_DragCallback (Widget w,
998 XtPointer client_data, XtPointer call_data)
999 {
1000 XmScrollBarCallbackStruct *cbs = (XmScrollBarCallbackStruct *)call_data;
1001 setValue((Nlm_BaR)client_data, (Nlm_Int2)cbs->value, TRUE);
1002 }
1003 #endif
1004
1005
Nlm_NewBarX(Nlm_BaR b,Nlm_GraphiC slv,Nlm_Boolean vert,Nlm_BarScrlProc4 actn4,Nlm_BarScrlProc actn)1006 static void Nlm_NewBarX (Nlm_BaR b, Nlm_GraphiC slv,
1007 Nlm_Boolean vert,
1008 Nlm_BarScrlProc4 actn4, Nlm_BarScrlProc actn)
1009 {
1010 Nlm_BarTool c;
1011 Nlm_RecT r;
1012 Nlm_WindowTool wptr = Nlm_ParentWindowPtr( (Nlm_GraphiC)b );
1013 #ifdef WIN_MAC
1014 Nlm_Int4 ref;
1015 Nlm_RectTool rtool;
1016 #endif
1017 #ifdef WIN_MSWIN
1018 Nlm_Int4 style = vert ? SBS_VERT : SBS_HORZ;
1019 #endif
1020 #ifdef WIN_MOTIF
1021 Cardinal n;
1022 Arg wargs [20];
1023 #endif
1024
1025 Nlm_GetRect((Nlm_GraphiC)b, &r);
1026
1027 #ifdef WIN_MAC
1028 Nlm_RecTToRectTool(&r, &rtool);
1029 ref = (Nlm_Int4)b;
1030 c = NewControl (wptr, &rtool, (StringPtr) "", FALSE, 0, 0, 0, 16, ref);
1031 Nlm_LoadBarData(b, c, 10, 10, 0, 0, 0, FALSE, slv, actn4, actn);
1032 #endif
1033
1034 #ifdef WIN_MSWIN
1035 c = CreateWindow("Scrollbar", "", WS_CHILD | style,
1036 r.left, r.top, r.right - r.left, r.bottom - r.top,
1037 wptr, 0, Nlm_currentHInst, NULL);
1038 if (c != NULL)
1039 SetProp(c, (LPSTR)"Nlm_VibrantProp", (Nlm_HandleTool)b);
1040
1041 Nlm_LoadBarData(b, c, 10, 10, 0, 0, 0, FALSE, slv, actn4, actn);
1042 if (lpfnNewBarProc == NULL)
1043 lpfnNewBarProc = (WNDPROC)MakeProcInstance((FARPROC) BarProc,
1044 Nlm_currentHInst);
1045
1046 if (lpfnOldBarProc == NULL)
1047 lpfnOldBarProc = (WNDPROC)GetWindowLongPtr(c, GWLP_WNDPROC);
1048 else if (lpfnOldBarProc != (WNDPROC)GetWindowLongPtr(c, GWLP_WNDPROC))
1049 Nlm_Message(MSG_ERROR, "BarProc subclass error");
1050
1051 SetWindowLongPtr(c, GWLP_WNDPROC, (LONG_PTR)lpfnNewBarProc);
1052 #endif
1053
1054 #ifdef WIN_MOTIF
1055 n = 0;
1056 XtSetArg(wargs [n], XmNx, (Position) r.left); n++;
1057 XtSetArg(wargs [n], XmNy, (Position) r.top ); n++;
1058 XtSetArg(wargs [n], XmNwidth, (Dimension) (r.right - r.left)); n++;
1059 XtSetArg(wargs [n], XmNheight, (Dimension) (r.bottom - r.top)); n++;
1060 XtSetArg(wargs [n], XmNborderWidth, (Dimension)0); n++;
1061 XtSetArg(wargs [n], XmNmarginHeight, 0); n++;
1062 XtSetArg(wargs [n], XmNmarginWidth, 0); n++;
1063 XtSetArg(wargs [n], XmNsliderSize, 1); n++;
1064
1065 if (vert) {
1066 XtSetArg(wargs [n], XmNorientation, XmVERTICAL ); n++;
1067 XtSetArg(wargs [n], XmNprocessingDirection, XmMAX_ON_BOTTOM); n++;
1068 } else {
1069 XtSetArg(wargs [n], XmNorientation, XmHORIZONTAL ); n++;
1070 XtSetArg(wargs [n], XmNprocessingDirection, XmMAX_ON_RIGHT ); n++;
1071 }
1072
1073 c = XmCreateScrollBar(wptr, (String) "", wargs, n);
1074
1075 {{
1076 XtPointer b_ptr = (XtPointer)b;
1077 XtAddCallback(c, XmNincrementCallback, Nlm_LineDnCallback, b_ptr);
1078 XtAddCallback(c, XmNdecrementCallback, Nlm_LineUpCallback, b_ptr);
1079 XtAddCallback(c, XmNpageIncrementCallback, Nlm_PageDnCallback, b_ptr);
1080 XtAddCallback(c, XmNpageDecrementCallback, Nlm_PageUpCallback, b_ptr);
1081 XtAddCallback(c, XmNvalueChangedCallback, Nlm_ThumbCallback, b_ptr);
1082 XtAddCallback(c, XmNtoTopCallback, Nlm_BottomCallback, b_ptr);
1083 XtAddCallback(c, XmNtoBottomCallback, Nlm_TopCallback, b_ptr);
1084 XtAddCallback(c, XmNdragCallback, Nlm_DragCallback, b_ptr);
1085 }}
1086
1087 XtManageChild( c );
1088
1089 Nlm_LoadBarData(b, c, 10, 10, 0, 0, 0, FALSE, slv, actn4, actn);
1090 #endif
1091 }
1092
1093
Nlm_CommonScrollBarX(Nlm_GraphiC slave,Nlm_RectPtr r,Nlm_BarScrlProc4 actn4,Nlm_BarScrlProc actn,Nlm_Boolean vert)1094 static Nlm_BaR Nlm_CommonScrollBarX (Nlm_GraphiC slave, Nlm_RectPtr r,
1095 Nlm_BarScrlProc4 actn4,
1096 Nlm_BarScrlProc actn,
1097 Nlm_Boolean vert)
1098 {
1099 Nlm_BaR b;
1100 Nlm_WindoW tempPort;
1101
1102 if (slave == NULL || r == NULL)
1103 return NULL;
1104
1105 b = (Nlm_BaR)Nlm_HandNew( sizeof(Nlm_BarRec) );
1106 if (b == NULL)
1107 return NULL;
1108
1109 tempPort = Nlm_SavePort( slave );
1110 Nlm_LoadGraphicData((Nlm_GraphiC)b, NULL, (Nlm_GraphiC)slave,
1111 NULL, NULL, barProcs, NULL, r, TRUE, FALSE, NULL, NULL);
1112 if (Nlm_nextIdNumber < 32767)
1113 Nlm_nextIdNumber++;
1114 Nlm_NewBarX(b, slave, vert, actn4, actn);
1115
1116 Nlm_RestorePort( tempPort );
1117 return b;
1118 }
1119
1120
Nlm_ScrollBarX(Nlm_GrouP prnt,Nlm_Int2 width,Nlm_Int2 height,Nlm_BarScrlProc4 actn4,Nlm_BarScrlProc actn)1121 static Nlm_BaR Nlm_ScrollBarX (Nlm_GrouP prnt,
1122 Nlm_Int2 width, Nlm_Int2 height,
1123 Nlm_BarScrlProc4 actn4, Nlm_BarScrlProc actn)
1124 {
1125 Nlm_BaR b;
1126 Nlm_PoinT npt;
1127 Nlm_RecT r;
1128 Nlm_WindoW tempPort;
1129 Nlm_Boolean vert;
1130
1131 if (prnt == NULL)
1132 return NULL;
1133
1134 tempPort = Nlm_SavePort( (Nlm_GraphiC)prnt );
1135 Nlm_GetNextPosition((Nlm_GraphiC)prnt, &npt);
1136 if (width > 0)
1137 {
1138 vert = FALSE;
1139 width *= Nlm_stdCharWidth;
1140 Nlm_LoadRect(&r, npt.x, npt.y,
1141 (Nlm_Int2)(npt.x + width),
1142 (Nlm_Int2)(npt.y + Nlm_hScrollBarHeight));
1143 }
1144 else
1145 {
1146 vert = TRUE;
1147 height *= Nlm_stdLineHeight;
1148 Nlm_LoadRect(&r, npt.x, npt.y,
1149 (Nlm_Int2)(npt.x + Nlm_vScrollBarWidth),
1150 (Nlm_Int2)(npt.y + height));
1151 }
1152 b = (Nlm_BaR)Nlm_CreateLink((Nlm_GraphiC)prnt,
1153 &r, sizeof(Nlm_BarRec), linkedBarProcs);
1154 if (b == NULL)
1155 return NULL;
1156
1157 Nlm_NewBarX(b, (Nlm_GraphiC)prnt, vert, actn4, actn);
1158 Nlm_DoAdjustPrnt((Nlm_GraphiC)b, &r, TRUE, FALSE);
1159 Nlm_DoShow((Nlm_GraphiC)b, TRUE, FALSE);
1160 Nlm_RestorePort( tempPort );
1161
1162 return b;
1163 }
1164
1165
1166
1167 /*********************************************************************
1168 * PUBLIC
1169 *********************************************************************/
1170
1171 /*
1172 * Creation
1173 */
1174
Nlm_HorizScrollBar4(Nlm_GraphiC slave,Nlm_RectPtr r,Nlm_BarScrlProc4 actn)1175 extern Nlm_BaR Nlm_HorizScrollBar4 (Nlm_GraphiC slave,
1176 Nlm_RectPtr r, Nlm_BarScrlProc4 actn)
1177 {
1178 return Nlm_CommonScrollBarX(slave, r, actn, NULL, FALSE);
1179 }
1180
Nlm_HorizScrollBar(Nlm_GraphiC slave,Nlm_RectPtr r,Nlm_BarScrlProc actn)1181 extern Nlm_BaR Nlm_HorizScrollBar (Nlm_GraphiC slave,
1182 Nlm_RectPtr r, Nlm_BarScrlProc actn)
1183 {
1184 return Nlm_CommonScrollBarX(slave, r, NULL, actn, FALSE);
1185 }
1186
1187
Nlm_VertScrollBar4(Nlm_GraphiC slave,Nlm_RectPtr r,Nlm_BarScrlProc4 actn)1188 extern Nlm_BaR Nlm_VertScrollBar4 (Nlm_GraphiC slave,
1189 Nlm_RectPtr r, Nlm_BarScrlProc4 actn)
1190 {
1191 return Nlm_CommonScrollBarX(slave, r, actn, NULL, TRUE);
1192 }
1193
Nlm_VertScrollBar(Nlm_GraphiC slave,Nlm_RectPtr r,Nlm_BarScrlProc actn)1194 extern Nlm_BaR Nlm_VertScrollBar (Nlm_GraphiC slave,
1195 Nlm_RectPtr r, Nlm_BarScrlProc actn)
1196 {
1197 return Nlm_CommonScrollBarX(slave, r, NULL, actn, TRUE);
1198 }
1199
1200
Nlm_ScrollBar4(Nlm_GrouP prnt,Nlm_Int2 width,Nlm_Int2 height,Nlm_BarScrlProc4 actn)1201 extern Nlm_BaR Nlm_ScrollBar4 (Nlm_GrouP prnt, Nlm_Int2 width,
1202 Nlm_Int2 height, Nlm_BarScrlProc4 actn)
1203 {
1204 return Nlm_ScrollBarX(prnt, width, height, actn, NULL);
1205 }
1206
Nlm_ScrollBar(Nlm_GrouP prnt,Nlm_Int2 width,Nlm_Int2 height,Nlm_BarScrlProc actn)1207 extern Nlm_BaR Nlm_ScrollBar (Nlm_GrouP prnt, Nlm_Int2 width,
1208 Nlm_Int2 height, Nlm_BarScrlProc actn)
1209 {
1210 return Nlm_ScrollBarX(prnt, width, height, NULL, actn);
1211 }
1212
1213
1214 /*
1215 * Methods
1216 */
1217
Nlm_SetBarValue(Nlm_BaR b,Nlm_Int4 val)1218 extern void Nlm_SetBarValue(Nlm_BaR b, Nlm_Int4 val)
1219 {
1220 setPos(b, val, TRUE, TRUE);
1221 }
1222
Nlm_CorrectBarValue(Nlm_BaR b,Nlm_Int4 val)1223 extern void Nlm_CorrectBarValue (Nlm_BaR b, Nlm_Int4 val)
1224 {
1225 setPos(b, val, TRUE, FALSE);
1226 }
1227
Nlm_GetBarValue(Nlm_BaR b)1228 extern Nlm_Int4 Nlm_GetBarValue (Nlm_BaR b)
1229 {
1230 return getPos( b );
1231 }
1232
1233
Nlm_SetBarMax(Nlm_BaR b,Nlm_Int4 max)1234 extern void Nlm_SetBarMax (Nlm_BaR b, Nlm_Int4 max)
1235 {
1236 setMax(b, max, TRUE, TRUE);
1237 }
1238
Nlm_CorrectBarMax(Nlm_BaR b,Nlm_Int4 max)1239 extern void Nlm_CorrectBarMax (Nlm_BaR b, Nlm_Int4 max)
1240 {
1241 setMax(b, max, TRUE, FALSE);
1242 }
1243
Nlm_GetBarMax(Nlm_BaR b)1244 extern Nlm_Int4 Nlm_GetBarMax (Nlm_BaR b)
1245 {
1246 Nlm_BarData bdata;
1247
1248 Nlm_GetBarData (b, &bdata);
1249 return bdata.max;
1250 }
1251
1252
Nlm_CorrectBarPage(Nlm_BaR b,Nlm_Int4 pgUp,Nlm_Int4 pgDn)1253 extern void Nlm_CorrectBarPage(Nlm_BaR b, Nlm_Int4 pgUp, Nlm_Int4 pgDn)
1254 {
1255 Nlm_BarData bdata;
1256
1257 if (b == NULL)
1258 return;
1259
1260 Nlm_GetBarData(b, &bdata);
1261 if ((bdata.pageUp == pgUp && bdata.pageDn == pgDn) ||
1262 (pgUp <= 0 && pgDn <= 0))
1263 return;
1264
1265 if (pgUp > 0)
1266 bdata.pageUp = pgUp;
1267 if (pgDn > 0)
1268 bdata.pageDn = pgDn;
1269 #ifdef WIN_MOTIF
1270 bdata.delta_max = INT4_MAX;
1271 #endif
1272 Nlm_SetBarData(b, &bdata);
1273 #ifdef WIN_MOTIF
1274 invalRange(b, TRUE);
1275 #endif
1276 }
1277
1278
Nlm_Scroll(Nlm_BaR b,Nlm_enumScrollEvent event)1279 extern void Nlm_Scroll(Nlm_BaR b, Nlm_enumScrollEvent event)
1280 {
1281 switch ( event )
1282 {
1283 case SCROLL_LINEUP:
1284 setPos(b, getPos(b) - 1, TRUE, TRUE);
1285 break;
1286 case SCROLL_LINEDN:
1287 setPos(b, getPos(b) + 1, TRUE, TRUE);
1288 break;
1289 case SCROLL_PAGEUP:
1290 setPos(b, getPos(b) - Nlm_GetBarPageUp(b), TRUE, TRUE);
1291 break;
1292 case SCROLL_PAGEDN:
1293 setPos(b, getPos(b) + Nlm_GetBarPageDown(b), TRUE, TRUE);
1294 break;
1295 default:
1296 AbnormalExit( 1 );
1297 }
1298 }
1299
1300
1301
1302 /*********************************************************************
1303 * PROTECTED
1304 *********************************************************************/
1305
Nlm_SetBarAnomaly(Nlm_BaR b,Nlm_Boolean anomaly)1306 extern void Nlm_SetBarAnomaly (Nlm_BaR b, Nlm_Boolean anomaly)
1307
1308 {
1309 Nlm_BarData bdata;
1310
1311 if (b == NULL)
1312 return;
1313
1314 Nlm_GetBarData(b, &bdata);
1315 bdata.anomaly = anomaly;
1316 Nlm_SetBarData(b, &bdata);
1317 }
1318
1319
Nlm_FreeBars(void)1320 extern void Nlm_FreeBars (void)
1321 {
1322 gphprcsptr = (Nlm_GphPrcsPtr)Nlm_MemFree( gphprcsptr );
1323 }
1324
1325
Nlm_InitBars(void)1326 extern void Nlm_InitBars (void)
1327 {
1328 barProcs = gphprcsptr = (Nlm_GphPrcsPtr)Nlm_MemNew(2 * sizeof(Nlm_GphPrcs));
1329 if (barProcs == NULL)
1330 return;
1331
1332 #ifdef WIN_MAC
1333 barProcs->click = Nlm_ScrollClick;
1334 barProcs->draw = Nlm_DrawBar;
1335 #endif
1336 #ifdef WIN_MSWIN
1337 barProcs->command = Nlm_ScrollCommand;
1338 #endif
1339 barProcs->show = Nlm_ShowBar;
1340 barProcs->hide = Nlm_HideBar;
1341 barProcs->enable = Nlm_EnableBar;
1342 barProcs->disable = Nlm_DisableBar;
1343 barProcs->remove = Nlm_RemoveBar;
1344 barProcs->reset = Nlm_ResetBar;
1345 barProcs->setValue = Nlm_SetBarValue2;
1346 barProcs->getValue = Nlm_GetBarValue2;
1347 barProcs->setPosition = Nlm_SetBarPosition;
1348 barProcs->getPosition = Nlm_GetBarPosition;
1349 barProcs->setRange = Nlm_SetBarRange2;
1350
1351 linkedBarProcs = gphprcsptr + 1;
1352 #ifdef WIN_MAC
1353 linkedBarProcs->click = Nlm_ScrollClick;
1354 linkedBarProcs->draw = Nlm_DrawBar;
1355 #endif
1356 #ifdef WIN_MSWIN
1357 linkedBarProcs->command = Nlm_ScrollCommand;
1358 #endif
1359 #ifdef WIN_MOTIF
1360 #endif
1361 linkedBarProcs->show = Nlm_ShowBar;
1362 linkedBarProcs->hide = Nlm_HideBar;
1363 linkedBarProcs->enable = Nlm_EnableBar;
1364 linkedBarProcs->disable = Nlm_DisableBar;
1365 linkedBarProcs->remove = Nlm_RemoveLinkedInBar;
1366 linkedBarProcs->reset = Nlm_ResetBar;
1367 linkedBarProcs->setValue = Nlm_SetBarValue2;
1368 linkedBarProcs->getValue = Nlm_GetBarValue2;
1369 linkedBarProcs->setPosition = Nlm_SetBarPosition;
1370 linkedBarProcs->getPosition = Nlm_GetBarPosition;
1371 linkedBarProcs->setRange = Nlm_SetBarRange2;
1372 }
1373
1374
1375 /*********************************************************************
1376 * TEST-ONLY
1377 *********************************************************************/
1378
1379 #ifdef TEST_MODULE_VIBSBARS
1380 #ifdef OS_UNIX
1381 #include <stdio.h>
1382 #endif
1383
1384 static void scroll4CB(Nlm_BaR b, Nlm_GraphiC slave,
1385 Nlm_Int4 prev_pos, Nlm_Int4 curr_pos);
1386 static void scroll2CB(Nlm_BaR b, Nlm_GraphiC slave,
1387 Nlm_Int2 prev_pos, Nlm_Int2 curr_pos);
1388 static void QuitCB(Nlm_WindoW w);
1389
1390
Nlm_Main(void)1391 extern Nlm_Int2 Nlm_Main( void )
1392 {
1393 Nlm_WindoW www =
1394 Nlm_FixedWindow(-30, -50, -10, -10, "TEST_MODULE_VIBSBARS", QuitCB);
1395
1396 {{
1397 Nlm_BaR bar4 = Nlm_ScrollBar4(www, 0, 20, scroll4CB);
1398 Nlm_CorrectBarMax(bar4, 100000);
1399 }}
1400
1401 {{
1402 Nlm_BaR bar2 = Nlm_ScrollBar (www, 0, 20, scroll2CB);
1403 Nlm_CorrectBarMax(bar2, 1000);
1404 }}
1405
1406 Nlm_Show( www );
1407 Nlm_ProcessEvents();
1408 return 0;
1409 }
1410
1411
scroll4CB(Nlm_BaR b,Nlm_GraphiC slave,Nlm_Int4 curr_pos,Nlm_Int4 prev_pos)1412 static void scroll4CB(Nlm_BaR b, Nlm_GraphiC slave,
1413 Nlm_Int4 curr_pos, Nlm_Int4 prev_pos)
1414 {
1415 Nlm_Int4 pos = Nlm_GetBarValue( b );
1416 Nlm_Int4 max = Nlm_GetBarMax ( b );
1417
1418 #ifdef OS_UNIX
1419 fprintf(stderr, "Scroll4CB(): prev=%ld curr=%ld val=%ld max=%ld\n",
1420 (long)prev_pos, (long)curr_pos,
1421 (long)pos, (long)max);
1422 #endif
1423 return;
1424
1425 if (prev_pos + 5 < curr_pos)
1426 Nlm_CorrectBarMax(b, max - 1000);
1427 else
1428 Nlm_CorrectBarMax(b, max + 1000);
1429 }
1430
1431
scroll2CB(Nlm_BaR b,Nlm_GraphiC slave,Nlm_Int2 curr_pos,Nlm_Int2 prev_pos)1432 static void scroll2CB(Nlm_BaR b, Nlm_GraphiC slave,
1433 Nlm_Int2 curr_pos, Nlm_Int2 prev_pos)
1434 {
1435 Nlm_Int4 pos = Nlm_GetBarValue( b );
1436 Nlm_Int4 max = Nlm_GetBarMax ( b );
1437
1438 static Nlm_Int4 div = 1;
1439 Nlm_Int4 page;
1440
1441 if (curr_pos > prev_pos)
1442 {
1443 page = max / div;
1444 if (div < max)
1445 div *= 2;
1446 }
1447 else
1448 {
1449 if (div > 1)
1450 div /= 2;
1451 page = max / div;
1452 }
1453 #ifdef OS_UNIX
1454 fprintf(stderr,
1455 "Scroll2CB(): prev=%ld curr=%ld val=%ld max=%ld page=%ld\n",
1456 (long)prev_pos, (long)curr_pos,
1457 (long)pos, (long)max, (long)page);
1458 #endif
1459 Nlm_CorrectBarPage(b, page, page);
1460 }
1461
1462
QuitCB(Nlm_WindoW w)1463 static void QuitCB(Nlm_WindoW w)
1464 {
1465 Nlm_QuitProgram();
1466 }
1467
1468 #endif /* TEST_MODULE_VIBSBARS */
1469