Mercurial > hg > xemacs-beta
comparison lwlib/xlwscrollbar.c @ 5118:e0db3c197671 ben-lisp-object
merge up to latest default branch, doesn't compile yet
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Sat, 26 Dec 2009 21:18:49 -0600 |
parents | 726060ee587c |
children | ade4c7e2c6cb |
comparison
equal
deleted
inserted
replaced
5117:3742ea8250b5 | 5118:e0db3c197671 |
---|---|
76 | 76 |
77 #include <X11/IntrinsicP.h> | 77 #include <X11/IntrinsicP.h> |
78 #include <X11/StringDefs.h> | 78 #include <X11/StringDefs.h> |
79 #include <X11/bitmaps/gray> | 79 #include <X11/bitmaps/gray> |
80 | 80 |
81 #include "lwlib-colors.h" | |
82 #include "xt-wrappers.h" | |
83 | |
81 #include "xlwscrollbarP.h" | 84 #include "xlwscrollbarP.h" |
82 #include "xlwscrollbar.h" | 85 #include "xlwscrollbar.h" |
83 | 86 |
84 #ifdef USE_DEBUG_MALLOC | 87 #ifdef USE_DEBUG_MALLOC |
85 #include <dmalloc.h> | 88 #include <dmalloc.h> |
109 SLIDER_PLAIN, | 112 SLIDER_PLAIN, |
110 SLIDER_DIMPLE | 113 SLIDER_DIMPLE |
111 } SliderStyle; | 114 } SliderStyle; |
112 | 115 |
113 /*-------------------------- Resources ----------------------------------*/ | 116 /*-------------------------- Resources ----------------------------------*/ |
117 | |
118 static XtResource resources[] = { | |
114 #define offset(field) XtOffset(XlwScrollBarWidget, field) | 119 #define offset(field) XtOffset(XlwScrollBarWidget, field) |
115 | 120 #define res(name,_class,intrepr,type,member,extrepr,value) \ |
116 static XtResource resources[] = { | 121 Xt_RESOURCE (name, _class, intrepr, type, offset(sb.member), extrepr, value) |
117 { XmNforeground, XmCForeground, XtRPixel, sizeof(Pixel), | 122 |
118 offset(sb.foreground), XtRImmediate, (XtPointer) XtDefaultForeground }, | 123 res (XmNforeground, XmCForeground, XtRPixel, Pixel, |
119 | 124 foreground, XtRImmediate, XtDefaultForeground), |
120 { XmNtopShadowColor, XmCTopShadowColor, XtRPixel, | 125 res (XmNtopShadowColor, XmCTopShadowColor, XtRPixel, |
121 sizeof(Pixel), offset(sb.topShadowColor), XtRImmediate, (XtPointer) ~0 }, | 126 Pixel, topShadowColor, XtRImmediate, ~0), |
122 { XmNbottomShadowColor, XmCBottomShadowColor, XtRPixel, | 127 res (XmNbottomShadowColor, XmCBottomShadowColor, XtRPixel, |
123 sizeof(Pixel), offset(sb.bottomShadowColor), XtRImmediate, | 128 Pixel, bottomShadowColor, XtRImmediate, ~0), |
124 (XtPointer)~0 }, | 129 |
125 | 130 res (XmNtopShadowPixmap, XmCTopShadowPixmap, XtRPixmap, |
126 { XmNtopShadowPixmap, XmCTopShadowPixmap, XtRPixmap, | 131 Pixmap, topShadowPixmap, XtRImmediate, None), |
127 sizeof (Pixmap), offset(sb.topShadowPixmap), XtRImmediate, | 132 res (XmNbottomShadowPixmap, XmCBottomShadowPixmap, |
128 (XtPointer)None}, | 133 XtRPixmap, Pixmap, bottomShadowPixmap, XtRImmediate, None), |
129 { XmNbottomShadowPixmap, XmCBottomShadowPixmap, | 134 |
130 XtRPixmap, sizeof (Pixmap), offset(sb.bottomShadowPixmap), | 135 res (XmNtroughColor, XmCTroughColor, XtRPixel, Pixel, troughColor, |
131 XtRImmediate, (XtPointer)None}, | 136 XtRImmediate, ~0), |
132 | 137 |
133 { XmNtroughColor, XmCTroughColor, XtRPixel, sizeof(Pixel), | 138 res (XmNshadowThickness, XmCShadowThickness, XtRInt, int, |
134 offset(sb.troughColor), XtRImmediate, (XtPointer)~0 }, | 139 shadowThickness, XtRImmediate, 2), |
135 | 140 |
136 { XmNshadowThickness, XmCShadowThickness, XtRInt, | 141 Xt_RESOURCE (XmNborderWidth, XmCBorderWidth, XtRDimension, Dimension, |
137 sizeof(int), offset(sb.shadowThickness), XtRImmediate, (XtPointer)2 }, | 142 offset(core.border_width), XtRImmediate, 0), |
138 | 143 |
139 { XmNborderWidth, XmCBorderWidth, XtRDimension, | 144 res (XmNshowArrows, XmCShowArrows, XtRBoolean, Boolean, showArrows, |
140 sizeof(Dimension), offset(core.border_width), XtRImmediate, | 145 XtRImmediate, True), |
141 (XtPointer)0 }, | 146 |
142 | 147 res (XmNinitialDelay, XmCInitialDelay, XtRInt, int, initialDelay, |
143 { XmNshowArrows, XmCShowArrows, XtRBoolean, | 148 XtRImmediate, 250), |
144 sizeof(Boolean), offset(sb.showArrows), XtRImmediate, (XtPointer)True }, | 149 res (XmNrepeatDelay, XmCRepeatDelay, XtRInt, int, repeatDelay, |
145 | 150 XtRImmediate, 50), |
146 { XmNinitialDelay, XmCInitialDelay, XtRInt, sizeof(int), | 151 |
147 offset(sb.initialDelay), XtRImmediate, (XtPointer) 250 }, | 152 res (XmNorientation, XmCOrientation, XtROrientation, |
148 { XmNrepeatDelay, XmCRepeatDelay, XtRInt, sizeof(int), | 153 unsigned char, orientation, XtRImmediate, XmVERTICAL), |
149 offset(sb.repeatDelay), XtRImmediate, (XtPointer) 50 }, | 154 |
150 | 155 res (XmNminimum, XmCMinimum, XtRInt, int, minimum, XtRImmediate, 0), |
151 { XmNorientation, XmCOrientation, XtROrientation, | 156 res (XmNmaximum, XmCMaximum, XtRInt, int, maximum, XtRImmediate, 100), |
152 sizeof(unsigned char), offset(sb.orientation), XtRImmediate, | 157 res (XmNvalue, XmCValue, XtRInt, int, value, XtRImmediate, 0), |
153 (XtPointer) XmVERTICAL }, | 158 res (XmNsliderSize, XmCSliderSize, XtRInt, int, sliderSize, XtRImmediate, 10), |
154 | 159 res (XmNincrement, XmCIncrement, XtRInt, int, increment, XtRImmediate, 1), |
155 { XmNminimum, XmCMinimum, XtRInt, sizeof(int), | 160 res (XmNpageIncrement, XmCPageIncrement, XtRInt, int, |
156 offset(sb.minimum), XtRImmediate, (XtPointer) 0}, | 161 pageIncrement, XtRImmediate, 10), |
157 { XmNmaximum, XmCMaximum, XtRInt, sizeof(int), | 162 |
158 offset(sb.maximum), XtRImmediate, (XtPointer) 100}, | 163 res (XmNvalueChangedCallback, XmCValueChangedCallback, |
159 { XmNvalue, XmCValue, XtRInt, sizeof(int), | 164 XtRCallback, XtPointer, valueChangedCBL, XtRCallback, NULL), |
160 offset(sb.value), XtRImmediate, (XtPointer) 0}, | 165 res (XmNincrementCallback, XmCIncrementCallback, |
161 { XmNsliderSize, XmCSliderSize, XtRInt, sizeof(int), | 166 XtRCallback, XtPointer, incrementCBL, XtRCallback, NULL), |
162 offset(sb.sliderSize), XtRImmediate, (XtPointer) 10}, | 167 res (XmNdecrementCallback, XmCDecrementCallback, |
163 { XmNincrement, XmCIncrement, XtRInt, sizeof(int), | 168 XtRCallback, XtPointer, decrementCBL, XtRCallback, NULL), |
164 offset(sb.increment), XtRImmediate, (XtPointer) 1}, | 169 res (XmNpageIncrementCallback, XmCPageIncrementCallback, |
165 { XmNpageIncrement, XmCPageIncrement, XtRInt, sizeof(int), | 170 XtRCallback, XtPointer, pageIncrementCBL, XtRCallback, NULL), |
166 offset(sb.pageIncrement), XtRImmediate, (XtPointer) 10}, | 171 res (XmNpageDecrementCallback, XmCPageDecrementCallback, |
167 | 172 XtRCallback, XtPointer, pageDecrementCBL, XtRCallback, NULL), |
168 { XmNvalueChangedCallback, XmCValueChangedCallback, | 173 res (XmNtoTopCallback, XmCToTopCallback, XtRCallback, |
169 XtRCallback, sizeof(XtPointer), offset(sb.valueChangedCBL), | 174 XtPointer, toTopCBL, XtRCallback, NULL), |
170 XtRCallback, NULL}, | 175 res (XmNtoBottomCallback, XmCToBottomCallback, XtRCallback, |
171 { XmNincrementCallback, XmCIncrementCallback, | 176 XtPointer, toBottomCBL, XtRCallback, NULL), |
172 XtRCallback, sizeof(XtPointer), offset(sb.incrementCBL), | 177 res (XmNdragCallback, XmCDragCallback, XtRCallback, |
173 XtRCallback, NULL}, | 178 XtPointer, dragCBL, XtRCallback, NULL), |
174 { XmNdecrementCallback, XmCDecrementCallback, | |
175 XtRCallback, sizeof(XtPointer), offset(sb.decrementCBL), | |
176 XtRCallback, NULL}, | |
177 { XmNpageIncrementCallback, XmCPageIncrementCallback, | |
178 XtRCallback, sizeof(XtPointer), offset(sb.pageIncrementCBL), | |
179 XtRCallback, NULL}, | |
180 { XmNpageDecrementCallback, XmCPageDecrementCallback, | |
181 XtRCallback, sizeof(XtPointer), offset(sb.pageDecrementCBL), | |
182 XtRCallback, NULL}, | |
183 { XmNtoTopCallback, XmCToTopCallback, XtRCallback, | |
184 sizeof(XtPointer), offset(sb.toTopCBL), XtRCallback, NULL}, | |
185 { XmNtoBottomCallback, XmCToBottomCallback, XtRCallback, | |
186 sizeof(XtPointer), offset(sb.toBottomCBL), XtRCallback, NULL}, | |
187 { XmNdragCallback, XmCDragCallback, XtRCallback, | |
188 sizeof(XtPointer), offset(sb.dragCBL), XtRCallback, NULL}, | |
189 | 179 |
190 /* "knob" is obsolete; use "slider" instead. */ | 180 /* "knob" is obsolete; use "slider" instead. */ |
191 { XmNsliderStyle, XmCSliderStyle, XtRString, sizeof(char *), | 181 res (XmNsliderStyle, XmCSliderStyle, XtRString, char *, |
192 offset(sb.sliderStyle), XtRImmediate, NULL}, | 182 sliderStyle, XtRImmediate, NULL), |
193 { XmNknobStyle, XmCKnobStyle, XtRString, sizeof(char *), | 183 res (XmNknobStyle, XmCKnobStyle, XtRString, char *, |
194 offset(sb.knobStyle), XtRImmediate, NULL}, | 184 knobStyle, XtRImmediate, NULL), |
195 | 185 |
196 { XmNarrowPosition, XmCArrowPosition, XtRString, sizeof(char *), | 186 res (XmNarrowPosition, XmCArrowPosition, XtRString, char *, |
197 offset(sb.arrowPosition), XtRImmediate, NULL}, | 187 arrowPosition, XtRImmediate, NULL), |
188 #undef offset | |
189 #undef res | |
198 }; | 190 }; |
199 | 191 |
200 /*-------------------------- Prototypes ---------------------------------*/ | 192 /*-------------------------- Prototypes ---------------------------------*/ |
201 | 193 |
202 /* Actions */ | 194 /* Actions */ |
214 /* Private */ | 206 /* Private */ |
215 | 207 |
216 /*-------------------------- Actions Table ------------------------------*/ | 208 /*-------------------------- Actions Table ------------------------------*/ |
217 static XtActionsRec actions[] = | 209 static XtActionsRec actions[] = |
218 { | 210 { |
219 {"Select", Select}, | 211 { (String) "Select", Select}, |
220 {"PageDownOrRight", PageDownOrRight}, | 212 { (String) "PageDownOrRight", PageDownOrRight}, |
221 {"PageUpOrLeft", PageUpOrLeft}, | 213 { (String) "PageUpOrLeft", PageUpOrLeft}, |
222 {"Drag", Drag}, | 214 { (String) "Drag", Drag}, |
223 {"Release", Release}, | 215 { (String) "Release", Release}, |
224 {"Jump", Jump}, | 216 { (String) "Jump", Jump}, |
225 {"Abort", Abort}, | 217 { (String) "Abort", Abort}, |
226 }; | 218 }; |
227 | 219 |
228 /*--------------------- Default Translation Table -----------------------*/ | 220 /*--------------------- Default Translation Table -----------------------*/ |
229 static char default_translations[] = | 221 static char default_translations[] = |
230 "<Btn1Down>: Select()\n" | 222 "<Btn1Down>: Select()\n" |
239 /*------------------- Class record initialization -----------------------*/ | 231 /*------------------- Class record initialization -----------------------*/ |
240 XlwScrollBarClassRec xlwScrollBarClassRec = { | 232 XlwScrollBarClassRec xlwScrollBarClassRec = { |
241 /* core_class fields */ | 233 /* core_class fields */ |
242 { | 234 { |
243 /* superclass */ (WidgetClass) &coreClassRec, | 235 /* superclass */ (WidgetClass) &coreClassRec, |
244 /* class_name */ "XlwScrollBar", | 236 /* class_name */ (String) "XlwScrollBar", |
245 /* widget_size */ sizeof(XlwScrollBarRec), | 237 /* widget_size */ sizeof(XlwScrollBarRec), |
246 /* class_initialize */ NULL, | 238 /* class_initialize */ NULL, |
247 /* class_part_init */ NULL, | 239 /* class_part_init */ NULL, |
248 /* class_inited */ False, | 240 /* class_inited */ False, |
249 /* initialize */ Initialize, | 241 /* initialize */ Initialize, |
521 (values.stipple == None ? 0 : GCStipple | GCFillStyle); | 513 (values.stipple == None ? 0 : GCStipple | GCFillStyle); |
522 | 514 |
523 return XtGetGC((Widget) w, mask, &values); | 515 return XtGetGC((Widget) w, mask, &values); |
524 } | 516 } |
525 | 517 |
526 /* Replacement for XAllocColor() that tries to return the nearest | |
527 available color if the colormap is full. From FSF Emacs. */ | |
528 | |
529 static int | |
530 allocate_nearest_color (Display *display, Colormap screen_colormap, | |
531 XColor *color_def) | |
532 { | |
533 int status = XAllocColor (display, screen_colormap, color_def); | |
534 if (status) | |
535 return status; | |
536 | |
537 { | |
538 /* If we got to this point, the colormap is full, so we're | |
539 going to try to get the next closest color. | |
540 The algorithm used is a least-squares matching, which is | |
541 what X uses for closest color matching with StaticColor visuals. */ | |
542 | |
543 int nearest, x; | |
544 unsigned long nearest_delta = ULONG_MAX; | |
545 | |
546 int no_cells = XDisplayCells (display, XDefaultScreen (display)); | |
547 /* Don't use alloca here because lwlib doesn't have the | |
548 necessary configuration information that src does. */ | |
549 XColor *cells = (XColor *) malloc (sizeof (XColor) * no_cells); | |
550 | |
551 for (x = 0; x < no_cells; x++) | |
552 cells[x].pixel = x; | |
553 | |
554 XQueryColors (display, screen_colormap, cells, no_cells); | |
555 | |
556 for (nearest = 0, x = 0; x < no_cells; x++) | |
557 { | |
558 long dred = (color_def->red >> 8) - (cells[x].red >> 8); | |
559 long dgreen = (color_def->green >> 8) - (cells[x].green >> 8); | |
560 long dblue = (color_def->blue >> 8) - (cells[x].blue >> 8); | |
561 unsigned long delta = dred * dred + dgreen * dgreen + dblue * dblue; | |
562 | |
563 if (delta < nearest_delta) | |
564 { | |
565 nearest = x; | |
566 nearest_delta = delta; | |
567 } | |
568 } | |
569 color_def->red = cells[nearest].red; | |
570 color_def->green = cells[nearest].green; | |
571 color_def->blue = cells[nearest].blue; | |
572 free (cells); | |
573 return XAllocColor (display, screen_colormap, color_def); | |
574 } | |
575 } | |
576 | |
577 static void | 518 static void |
578 make_shadow_pixels (XlwScrollBarWidget w) | 519 make_shadow_pixels (XlwScrollBarWidget w) |
579 { | 520 { |
580 Display *dpy = XtDisplay((Widget) w); | 521 Display *dpy = XtDisplay ((Widget) w); |
581 Colormap cmap = w->core.colormap; | 522 Colormap cmap = w->core.colormap; |
582 XColor topc, botc; | 523 XColor topc, botc; |
583 int top_frobbed, bottom_frobbed; | 524 int top_frobbed, bottom_frobbed; |
584 Pixel bg, fg; | 525 Pixel bg, fg; |
526 Visual *visual; | |
527 int ignored; | |
528 | |
529 visual_info_from_widget ((Widget) w, &visual, &ignored); | |
530 /* #### Apparently this is called before any shell has a visual? | |
531 or maybe the widget doesn't have a parent yet? */ | |
532 if (visual == CopyFromParent) | |
533 { | |
534 Screen *screen = DefaultScreenOfDisplay (dpy); | |
535 visual = DefaultVisualOfScreen (screen); | |
536 } | |
585 | 537 |
586 top_frobbed = bottom_frobbed = 0; | 538 top_frobbed = bottom_frobbed = 0; |
587 | 539 |
588 bg = w->core.background_pixel; | 540 bg = w->core.background_pixel; |
589 fg = w->sb.foreground; | 541 fg = w->sb.foreground; |
593 | 545 |
594 if (w->sb.topShadowColor == bg || w->sb.topShadowColor == fg) | 546 if (w->sb.topShadowColor == bg || w->sb.topShadowColor == fg) |
595 { | 547 { |
596 topc.pixel = bg; | 548 topc.pixel = bg; |
597 XQueryColor (dpy, cmap, &topc); | 549 XQueryColor (dpy, cmap, &topc); |
550 /* #### can we use a (generalized) xft_convert_color here? */ | |
598 /* don't overflow/wrap! */ | 551 /* don't overflow/wrap! */ |
599 topc.red = MINL(65535, topc.red * 1.2); | 552 topc.red = MINL(65535, topc.red * 1.2); |
600 topc.green = MINL(65535, topc.green * 1.2); | 553 topc.green = MINL(65535, topc.green * 1.2); |
601 topc.blue = MINL(65535, topc.blue * 1.2); | 554 topc.blue = MINL(65535, topc.blue * 1.2); |
602 if (allocate_nearest_color (dpy, cmap, &topc)) | 555 if (x_allocate_nearest_color (dpy, cmap, visual, &topc)) |
603 { | 556 { |
604 if (topc.pixel == bg) | 557 if (topc.pixel == bg) |
605 { | 558 { |
606 XFreeColors (dpy, cmap, &topc.pixel, 1, 0); | 559 XFreeColors (dpy, cmap, &topc.pixel, 1, 0); |
607 topc.red = MINL(65535, topc.red + 0x8000); | 560 topc.red = MINL(65535, topc.red + 0x8000); |
608 topc.green = MINL(65535, topc.green + 0x8000); | 561 topc.green = MINL(65535, topc.green + 0x8000); |
609 topc.blue = MINL(65535, topc.blue + 0x8000); | 562 topc.blue = MINL(65535, topc.blue + 0x8000); |
610 if (allocate_nearest_color (dpy, cmap, &topc)) | 563 if (x_allocate_nearest_color (dpy, cmap, visual, &topc)) |
611 { | 564 { |
612 w->sb.topShadowColor = topc.pixel; | 565 w->sb.topShadowColor = topc.pixel; |
613 } | 566 } |
614 } | 567 } |
615 else | 568 else |
626 botc.pixel = bg; | 579 botc.pixel = bg; |
627 XQueryColor (dpy, cmap, &botc); | 580 XQueryColor (dpy, cmap, &botc); |
628 botc.red = (botc.red * 3) / 5; | 581 botc.red = (botc.red * 3) / 5; |
629 botc.green = (botc.green * 3) / 5; | 582 botc.green = (botc.green * 3) / 5; |
630 botc.blue = (botc.blue * 3) / 5; | 583 botc.blue = (botc.blue * 3) / 5; |
631 if (allocate_nearest_color (dpy, cmap, &botc)) | 584 if (x_allocate_nearest_color (dpy, cmap, visual, &botc)) |
632 { | 585 { |
633 if (botc.pixel == bg) | 586 if (botc.pixel == bg) |
634 { | 587 { |
635 XFreeColors (dpy, cmap, &botc.pixel, 1, 0); | 588 XFreeColors (dpy, cmap, &botc.pixel, 1, 0); |
636 botc.red = MINL(65535, botc.red + 0x4000); | 589 botc.red = MINL(65535, botc.red + 0x4000); |
637 botc.green = MINL(65535, botc.green + 0x4000); | 590 botc.green = MINL(65535, botc.green + 0x4000); |
638 botc.blue = MINL(65535, botc.blue + 0x4000); | 591 botc.blue = MINL(65535, botc.blue + 0x4000); |
639 if (allocate_nearest_color (dpy, cmap, &botc)) | 592 if (x_allocate_nearest_color (dpy, cmap, visual, &botc)) |
640 { | 593 { |
641 w->sb.bottomShadowColor = botc.pixel; | 594 w->sb.bottomShadowColor = botc.pixel; |
642 } | 595 } |
643 } | 596 } |
644 else | 597 else |
701 make_trough_pixel (XlwScrollBarWidget w) | 654 make_trough_pixel (XlwScrollBarWidget w) |
702 { | 655 { |
703 Display *dpy = XtDisplay((Widget) w); | 656 Display *dpy = XtDisplay((Widget) w); |
704 Colormap cmap = w->core.colormap; | 657 Colormap cmap = w->core.colormap; |
705 XColor troughC; | 658 XColor troughC; |
659 Visual *visual; | |
660 int ignored; | |
661 | |
662 visual_info_from_widget ((Widget) w, &visual, &ignored); | |
663 /* #### Apparently this is called before any shell has a visual? | |
664 or maybe the widget doesn't have a parent yet? */ | |
665 if (visual == CopyFromParent) | |
666 { | |
667 Screen *screen = DefaultScreenOfDisplay (dpy); | |
668 visual = DefaultVisualOfScreen (screen); | |
669 } | |
706 | 670 |
707 if (w->sb.troughColor == (Pixel)~0) w->sb.troughColor = w->core.background_pixel; | 671 if (w->sb.troughColor == (Pixel)~0) w->sb.troughColor = w->core.background_pixel; |
708 | 672 |
709 if (w->sb.troughColor == w->core.background_pixel) | 673 if (w->sb.troughColor == w->core.background_pixel) |
710 { | 674 { |
711 troughC.pixel = w->core.background_pixel; | 675 troughC.pixel = w->core.background_pixel; |
712 XQueryColor (dpy, cmap, &troughC); | 676 XQueryColor (dpy, cmap, &troughC); |
713 troughC.red = (troughC.red * 4) / 5; | 677 troughC.red = (troughC.red * 4) / 5; |
714 troughC.green = (troughC.green * 4) / 5; | 678 troughC.green = (troughC.green * 4) / 5; |
715 troughC.blue = (troughC.blue * 4) / 5; | 679 troughC.blue = (troughC.blue * 4) / 5; |
716 if (allocate_nearest_color (dpy, cmap, &troughC)) | 680 if (x_allocate_nearest_color (dpy, cmap, visual, &troughC)) |
717 w->sb.troughColor = troughC.pixel; | 681 w->sb.troughColor = troughC.pixel; |
718 } | 682 } |
719 } | 683 } |
720 | 684 |
721 /*-------------------------- Draw 3D Border -----------------------------*/ | 685 /*-------------------------- Draw 3D Border -----------------------------*/ |