comparison lwlib/xlwscrollbar.c @ 183:e121b013d1f0 r20-3b18

Import from CVS: tag r20-3b18
author cvs
date Mon, 13 Aug 2007 09:54:23 +0200
parents 6075d714658b
children 262b8bb4a523
comparison
equal deleted inserted replaced
182:f07455f06202 183:e121b013d1f0
1 /* Implements a lightweight scrollbar widget. 1 /* Implements a lightweight scrollbar widget.
2 Copyright (C) 1992, 1993, 1994 Lucid, Inc. 2 Copyright (C) 1992, 1993, 1994 Lucid, Inc.
3 Copyright (C) 1997 Sun Microsystems, Inc. 3 Copyright (C) 1997 Sun Microsystems, Inc.
4 4
5 This file is part of the Lucid Widget Library. 5 This file is part of the Lucid Widget Library.
6 6
29 * To use them, put this resource in your .Xdefaults 29 * To use them, put this resource in your .Xdefaults
30 * 30 *
31 * Emacs*XlwScrollBar.translations: #override \n\ 31 * Emacs*XlwScrollBar.translations: #override \n\
32 * <Btn1Down>: PageDownOrRight() \n\ 32 * <Btn1Down>: PageDownOrRight() \n\
33 * <Btn3Down>: PageUpOrLeft() 33 * <Btn3Down>: PageUpOrLeft()
34 * 34 *
35 */ 35 */
36 36
37 /* 37 /*
38 * Resources Supported: 38 * Resources Supported:
39 * XmNforeground 39 * XmNforeground
190 190
191 /* "knob" is obsolete; use "slider" instead. */ 191 /* "knob" is obsolete; use "slider" instead. */
192 { XmNsliderStyle, XmCSliderStyle, XtRString, sizeof(char *), 192 { XmNsliderStyle, XmCSliderStyle, XtRString, sizeof(char *),
193 offset(sb.sliderStyle), XtRImmediate, NULL}, 193 offset(sb.sliderStyle), XtRImmediate, NULL},
194 { XmNknobStyle, XmCKnobStyle, XtRString, sizeof(char *), 194 { XmNknobStyle, XmCKnobStyle, XtRString, sizeof(char *),
195 offset(sb.sliderStyle), XtRImmediate, NULL}, 195 offset(sb.knobStyle), XtRImmediate, NULL},
196 196
197 { XmNarrowPosition, XmCArrowPosition, XtRString, 197 { XmNarrowPosition, XmCArrowPosition, XtRString, sizeof(char *),
198 sizeof(char *), offset(sb.arrowPosition), XtRImmediate, NULL}, 198 offset(sb.arrowPosition), XtRImmediate, NULL},
199 }; 199 };
200 200
201 /*-------------------------- Prototypes ---------------------------------*/ 201 /*-------------------------- Prototypes ---------------------------------*/
202 202
203 /* Actions */ 203 /* Actions */
306 306
307 if ((w->sb.above + w->sb.ss + w->sb.below > height) || 307 if ((w->sb.above + w->sb.ss + w->sb.below > height) ||
308 (w->sb.value < w->sb.minimum) || 308 (w->sb.value < w->sb.minimum) ||
309 (w->sb.value > w->sb.maximum - w->sb.sliderSize)) 309 (w->sb.value > w->sb.maximum - w->sb.sliderSize))
310 { 310 {
311 printf("above=%d ss=%d below=%d height=%d\n", 311 printf("above=%d ss=%d below=%d height=%d\n",
312 w->sb.above, w->sb.ss, w->sb.below, height); 312 w->sb.above, w->sb.ss, w->sb.below, height);
313 printf("value=%d min=%d max=%d ss=%d max-ss=%d\n", 313 printf("value=%d min=%d max=%d ss=%d max-ss=%d\n",
314 w->sb.value, w->sb.minimum, w->sb.maximum, 314 w->sb.value, w->sb.minimum, w->sb.maximum,
315 w->sb.sliderSize, w->sb.maximum - w->sb.sliderSize); 315 w->sb.sliderSize, w->sb.maximum - w->sb.sliderSize);
316 abort(); 316 abort();
471 } 471 }
472 472
473 static SliderStyle 473 static SliderStyle
474 slider_style (XlwScrollBarWidget w) 474 slider_style (XlwScrollBarWidget w)
475 { 475 {
476 return w->sb.sliderStyle && w->sb.sliderStyle[0] == 'd' ? 476 return (w->sb.sliderStyle ? w->sb.sliderStyle[0] == 'd' :
477 w->sb.knobStyle ? w->sb.knobStyle[0] == 'd' :
478 0) ?
477 SLIDER_DIMPLE : 479 SLIDER_DIMPLE :
478 SLIDER_PLAIN; 480 SLIDER_PLAIN;
479 } 481 }
480 482
481 static Boolean 483 static Boolean
499 */ 501 */
500 502
501 fg = WhitePixelOfScreen (DefaultScreenOfDisplay (XtDisplay (w))); 503 fg = WhitePixelOfScreen (DefaultScreenOfDisplay (XtDisplay (w)));
502 bg = BlackPixelOfScreen (DefaultScreenOfDisplay (XtDisplay (w))); 504 bg = BlackPixelOfScreen (DefaultScreenOfDisplay (XtDisplay (w)));
503 } 505 }
504 506
505 values.foreground = fg; 507 values.foreground = fg;
506 values.background = bg; 508 values.background = bg;
507 values.fill_style = FillOpaqueStippled; 509 values.fill_style = FillOpaqueStippled;
508 values.stipple = pm; 510 values.stipple = pm;
509 mask = GCForeground | GCBackground | 511 mask = GCForeground | GCBackground |
654 else 656 else
655 w->sb.bottomShadowColor = fg; 657 w->sb.bottomShadowColor = fg;
656 } 658 }
657 } 659 }
658 660
659 if (w->sb.topShadowColor == w->core.background_pixel || 661 if (w->sb.topShadowColor == w->core.background_pixel ||
660 w->sb.bottomShadowColor == w->core.background_pixel) 662 w->sb.bottomShadowColor == w->core.background_pixel)
661 { 663 {
662 /* Assume we're in mono. This code should be okay even if we're 664 /* Assume we're in mono. This code should be okay even if we're
663 * really in color but just short on color cells -- We want the 665 * really in color but just short on color cells -- We want the
664 * following behavior, which has been empirically determined to 666 * following behavior, which has been empirically determined to
665 * work well for all fg/bg combinations in mono: If the trough 667 * work well for all fg/bg combinations in mono: If the trough
666 * and slider are BOTH black, then use a white top shadow and a 668 * and slider are BOTH black, then use a white top shadow and a
667 * grey bottom shadow, otherwise use a grey top shadow and a 669 * grey bottom shadow, otherwise use a grey top shadow and a
668 * black bottom shadow. 670 * black bottom shadow.
862 mid = width / 2; 864 mid = width / 2;
863 865
864 if (shadowT > (width / 2)) shadowT = (width / 2); 866 if (shadowT > (width / 2)) shadowT = (width / 2);
865 if (shadowT > (height / 2)) shadowT = (height / 2); 867 if (shadowT > (height / 2)) shadowT = (height / 2);
866 if (shadowT < 0) shadowT = 0; 868 if (shadowT < 0) shadowT = 0;
867 869
868 /* \- */ 870 /* \- */
869 make_vert_seg (shine, 871 make_vert_seg (shine,
870 x, y, 872 x, y,
871 x + mid, y + height - shadowT - 1, shadowT); 873 x + mid, y + height - shadowT - 1, shadowT);
872 make_vert_seg (shine + shadowT, 874 make_vert_seg (shine + shadowT,
901 mid = width / 2; 903 mid = width / 2;
902 904
903 if (shadowT > (width / 2)) shadowT = (width / 2); 905 if (shadowT > (width / 2)) shadowT = (width / 2);
904 if (shadowT > (height / 2)) shadowT = (height / 2); 906 if (shadowT > (height / 2)) shadowT = (height / 2);
905 if (shadowT < 0) shadowT = 0; 907 if (shadowT < 0) shadowT = 0;
906 908
907 /* |\ */ 909 /* |\ */
908 make_hor_seg (shine, 910 make_hor_seg (shine,
909 x, y, 911 x, y,
910 x + width - shadowT - 1, y + mid, shadowT); 912 x + width - shadowT - 1, y + mid, shadowT);
911 make_hor_seg (shine + shadowT, 913 make_hor_seg (shine + shadowT,
1499 w->sb.sliderSize != sliderSize || 1501 w->sb.sliderSize != sliderSize ||
1500 w->sb.increment != increment || 1502 w->sb.increment != increment ||
1501 w->sb.pageIncrement != pageIncrement)) 1503 w->sb.pageIncrement != pageIncrement))
1502 { 1504 {
1503 int last_value = w->sb.value; 1505 int last_value = w->sb.value;
1504 1506
1505 w->sb.value = value; 1507 w->sb.value = value;
1506 w->sb.sliderSize = sliderSize; 1508 w->sb.sliderSize = sliderSize;
1507 w->sb.increment = increment; 1509 w->sb.increment = increment;
1508 w->sb.pageIncrement = pageIncrement; 1510 w->sb.pageIncrement = pageIncrement;
1509 1511
1589 1591
1590 if (w->sb.showArrows) 1592 if (w->sb.showArrows)
1591 { 1593 {
1592 if (mouse_y >= (height -= arrow_height)) 1594 if (mouse_y >= (height -= arrow_height))
1593 return BUTTON_DOWN_ARROW; 1595 return BUTTON_DOWN_ARROW;
1594 1596
1595 if (arrow_same_end (w)) 1597 if (arrow_same_end (w))
1596 { 1598 {
1597 if (mouse_y >= (height -= arrow_height)) 1599 if (mouse_y >= (height -= arrow_height))
1598 return BUTTON_UP_ARROW; 1600 return BUTTON_UP_ARROW;
1599 } 1601 }
1600 else 1602 else
1601 if ( (mouse_y -= arrow_height) < 0) 1603 if ( (mouse_y -= arrow_height) < 0)
1602 return BUTTON_UP_ARROW; 1604 return BUTTON_UP_ARROW;
1603 } 1605 }
1604 1606
1605 if ( (mouse_y -= w->sb.above) < 0) 1607 if ( (mouse_y -= w->sb.above) < 0)
1606 return BUTTON_TROUGH_ABOVE; 1608 return BUTTON_TROUGH_ABOVE;
1607 1609
1608 if ( (mouse_y -= w->sb.ss) < 0) 1610 if ( (mouse_y -= w->sb.ss) < 0)
1609 return BUTTON_SLIDER; 1611 return BUTTON_SLIDER;
1709 1711
1710 if (last_value != w->sb.value) 1712 if (last_value != w->sb.value)
1711 { 1713 {
1712 seg_pixel_sizes (w, &w->sb.above, &w->sb.ss, &w->sb.below); 1714 seg_pixel_sizes (w, &w->sb.above, &w->sb.ss, &w->sb.below);
1713 draw_slider (w, w->sb.above, w->sb.ss, w->sb.below); 1715 draw_slider (w, w->sb.above, w->sb.ss, w->sb.below);
1714 1716
1715 call_callbacks (w, reason, w->sb.value, mouse_y, event); 1717 call_callbacks (w, reason, w->sb.value, mouse_y, event);
1716 1718
1717 if (w->sb.timerActive) 1719 if (w->sb.timerActive)
1718 XtRemoveTimeOut (w->sb.timerId); 1720 XtRemoveTimeOut (w->sb.timerId);
1719 1721
1821 int mouse_x = event_x (w, event); 1823 int mouse_x = event_x (w, event);
1822 int mouse_y = event_y (w, event); 1824 int mouse_y = event_y (w, event);
1823 1825
1824 int scroll_region_y = widget_y (w); 1826 int scroll_region_y = widget_y (w);
1825 int scroll_region_h = widget_h (w); 1827 int scroll_region_h = widget_h (w);
1826 1828
1827 if (w->sb.showArrows) 1829 if (w->sb.showArrows)
1828 { 1830 {
1829 int arrow_height = arrow_h (w); 1831 int arrow_height = arrow_h (w);
1830 scroll_region_h -= 2 * arrow_height; 1832 scroll_region_h -= 2 * arrow_height;
1831 if (!arrow_same_end (w)) 1833 if (!arrow_same_end (w))
1845 last_value = w->sb.value; 1847 last_value = w->sb.value;
1846 1848
1847 w->sb.above = mouse_y - (w->sb.ss / 2) - scroll_region_y; 1849 w->sb.above = mouse_y - (w->sb.ss / 2) - scroll_region_y;
1848 if (w->sb.above < 0) 1850 if (w->sb.above < 0)
1849 w->sb.above = 0; 1851 w->sb.above = 0;
1850 else if (w->sb.above + w->sb.ss > scroll_region_h) 1852 else if (w->sb.above + w->sb.ss > scroll_region_h)
1851 w->sb.above = scroll_region_h - w->sb.ss; 1853 w->sb.above = scroll_region_h - w->sb.ss;
1852 1854
1853 w->sb.below = scroll_region_h - w->sb.ss - w->sb.above; 1855 w->sb.below = scroll_region_h - w->sb.ss - w->sb.above;
1854 1856
1855 w->sb.armed = ARM_SLIDER; 1857 w->sb.armed = ARM_SLIDER;
1861 1863
1862 w->sb.lastY = mouse_y; 1864 w->sb.lastY = mouse_y;
1863 1865
1864 if (w->sb.value != last_value) 1866 if (w->sb.value != last_value)
1865 call_callbacks (w, XmCR_DRAG, w->sb.value, mouse_y, event); 1867 call_callbacks (w, XmCR_DRAG, w->sb.value, mouse_y, event);
1866 1868
1867 break; 1869 break;
1868 default: 1870 default:
1869 ; /* Do nothing */ 1871 ; /* Do nothing */
1870 } 1872 }
1871 CHECK (w); 1873 CHECK (w);