Mercurial > hg > xemacs-beta
comparison lwlib/xlwscrollbar.c @ 14:9ee227acff29 r19-15b90
Import from CVS: tag r19-15b90
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:48:42 +0200 |
parents | 49a24b4fd526 |
children | 441bb1e64a06 |
comparison
equal
deleted
inserted
replaced
13:13c6d0aaafe5 | 14:9ee227acff29 |
---|---|
114 ** | 114 ** |
115 */ | 115 */ |
116 #define offset(field) XtOffset(XlwScrollBarWidget, field) | 116 #define offset(field) XtOffset(XlwScrollBarWidget, field) |
117 | 117 |
118 static XtResource resources[] = { | 118 static XtResource resources[] = { |
119 { (String) XmNforeground, (String) XmCForeground, XtRPixel, sizeof(Pixel), | 119 { XmNforeground, XmCForeground, XtRPixel, sizeof(Pixel), |
120 offset(sb.foreground), XtRImmediate, (XtPointer) XtDefaultForeground }, | 120 offset(sb.foreground), XtRImmediate, (XtPointer) XtDefaultForeground }, |
121 | 121 |
122 { (String) XmNtopShadowColor, (String) XmCTopShadowColor, XtRPixel, | 122 { XmNtopShadowColor, XmCTopShadowColor, XtRPixel, |
123 sizeof(Pixel), offset(sb.topShadowColor), XtRImmediate, (XtPointer) ~0 }, | 123 sizeof(Pixel), offset(sb.topShadowColor), XtRImmediate, (XtPointer) ~0 }, |
124 { (String) XmNbottomShadowColor, (String) XmCBottomShadowColor, XtRPixel, | 124 { XmNbottomShadowColor, XmCBottomShadowColor, XtRPixel, |
125 sizeof(Pixel), offset(sb.bottomShadowColor), XtRImmediate, | 125 sizeof(Pixel), offset(sb.bottomShadowColor), XtRImmediate, |
126 (XtPointer)~0 }, | 126 (XtPointer)~0 }, |
127 | 127 |
128 { (String) XmNtopShadowPixmap, (String) XmCTopShadowPixmap, XtRPixmap, | 128 { XmNtopShadowPixmap, XmCTopShadowPixmap, XtRPixmap, |
129 sizeof (Pixmap), offset(sb.topShadowPixmap), XtRImmediate, | 129 sizeof (Pixmap), offset(sb.topShadowPixmap), XtRImmediate, |
130 (XtPointer)None}, | 130 (XtPointer)None}, |
131 { (String) XmNbottomShadowPixmap, (String) XmCBottomShadowPixmap, | 131 { XmNbottomShadowPixmap, XmCBottomShadowPixmap, |
132 XtRPixmap, sizeof (Pixmap), offset(sb.bottomShadowPixmap), | 132 XtRPixmap, sizeof (Pixmap), offset(sb.bottomShadowPixmap), |
133 XtRImmediate, (XtPointer)None}, | 133 XtRImmediate, (XtPointer)None}, |
134 | 134 |
135 { (String)XmNtroughColor, (String)XmCTroughColor, XtRPixel, sizeof(Pixel), | 135 { XmNtroughColor, XmCTroughColor, XtRPixel, sizeof(Pixel), |
136 offset(sb.troughColor), XtRImmediate, (XtPointer)~0 }, | 136 offset(sb.troughColor), XtRImmediate, (XtPointer)~0 }, |
137 | 137 |
138 { (String)XmNshadowThickness, (String)XmCShadowThickness, XtRInt, | 138 { XmNshadowThickness, XmCShadowThickness, XtRInt, |
139 sizeof(int), offset(sb.shadowThickness), XtRImmediate, (XtPointer)2 }, | 139 sizeof(int), offset(sb.shadowThickness), XtRImmediate, (XtPointer)2 }, |
140 | 140 |
141 { (String) XmNborderWidth, (String) XmCBorderWidth, XtRDimension, | 141 { XmNborderWidth, XmCBorderWidth, XtRDimension, |
142 sizeof(Dimension), offset(core.border_width), XtRImmediate, | 142 sizeof(Dimension), offset(core.border_width), XtRImmediate, |
143 (XtPointer)0 }, | 143 (XtPointer)0 }, |
144 | 144 |
145 { (String) XmNshowArrows, (String) XmCShowArrows, XtRBoolean, | 145 { XmNshowArrows, XmCShowArrows, XtRBoolean, |
146 sizeof(Boolean), offset(sb.showArrows), XtRImmediate, (XtPointer)True }, | 146 sizeof(Boolean), offset(sb.showArrows), XtRImmediate, (XtPointer)True }, |
147 | 147 |
148 { (String) XmNinitialDelay, (String) XmCInitialDelay, XtRInt, sizeof(int), | 148 { XmNinitialDelay, XmCInitialDelay, XtRInt, sizeof(int), |
149 offset(sb.initialDelay), XtRImmediate, (XtPointer) 250 }, | 149 offset(sb.initialDelay), XtRImmediate, (XtPointer) 250 }, |
150 { (String) XmNrepeatDelay, (String) XmCRepeatDelay, XtRInt, sizeof(int), | 150 { XmNrepeatDelay, XmCRepeatDelay, XtRInt, sizeof(int), |
151 offset(sb.repeatDelay), XtRImmediate, (XtPointer) 50 }, | 151 offset(sb.repeatDelay), XtRImmediate, (XtPointer) 50 }, |
152 | 152 |
153 { (String) XmNorientation, (String) XmCOrientation, XtROrientation, | 153 { XmNorientation, XmCOrientation, XtROrientation, |
154 sizeof(unsigned char), offset(sb.orientation), XtRImmediate, | 154 sizeof(unsigned char), offset(sb.orientation), XtRImmediate, |
155 (XtPointer) XmVERTICAL }, | 155 (XtPointer) XmVERTICAL }, |
156 | 156 |
157 { (String) XmNminimum, (String) XmCMinimum, XtRInt, sizeof(int), | 157 { XmNminimum, XmCMinimum, XtRInt, sizeof(int), |
158 offset(sb.minimum), XtRImmediate, (XtPointer) 0}, | 158 offset(sb.minimum), XtRImmediate, (XtPointer) 0}, |
159 { (String) XmNmaximum, (String) XmCMaximum, XtRInt, sizeof(int), | 159 { XmNmaximum, XmCMaximum, XtRInt, sizeof(int), |
160 offset(sb.maximum), XtRImmediate, (XtPointer) 100}, | 160 offset(sb.maximum), XtRImmediate, (XtPointer) 100}, |
161 { (String) XmNvalue, (String) XmCValue, XtRInt, sizeof(int), | 161 { XmNvalue, XmCValue, XtRInt, sizeof(int), |
162 offset(sb.value), XtRImmediate, (XtPointer) 0}, | 162 offset(sb.value), XtRImmediate, (XtPointer) 0}, |
163 { (String) XmNsliderSize, (String) XmCSliderSize, XtRInt, sizeof(int), | 163 { XmNsliderSize, XmCSliderSize, XtRInt, sizeof(int), |
164 offset(sb.sliderSize), XtRImmediate, (XtPointer) 10}, | 164 offset(sb.sliderSize), XtRImmediate, (XtPointer) 10}, |
165 { (String) XmNincrement, (String) XmCIncrement, XtRInt, sizeof(int), | 165 { XmNincrement, XmCIncrement, XtRInt, sizeof(int), |
166 offset(sb.increment), XtRImmediate, (XtPointer) 1}, | 166 offset(sb.increment), XtRImmediate, (XtPointer) 1}, |
167 { (String)XmNpageIncrement, (String)XmCPageIncrement, XtRInt, sizeof(int), | 167 { XmNpageIncrement, XmCPageIncrement, XtRInt, sizeof(int), |
168 offset(sb.pageIncrement), XtRImmediate, (XtPointer) 10}, | 168 offset(sb.pageIncrement), XtRImmediate, (XtPointer) 10}, |
169 | 169 |
170 { (String) XmNvalueChangedCallback, (String) XmCValueChangedCallback, | 170 { XmNvalueChangedCallback, XmCValueChangedCallback, |
171 XtRCallback, sizeof(XtPointer), offset(sb.valueChangedCBL), | 171 XtRCallback, sizeof(XtPointer), offset(sb.valueChangedCBL), |
172 XtRCallback, NULL}, | 172 XtRCallback, NULL}, |
173 { (String) XmNincrementCallback, (String) XmCIncrementCallback, | 173 { XmNincrementCallback, XmCIncrementCallback, |
174 XtRCallback, sizeof(XtPointer), offset(sb.incrementCBL), | 174 XtRCallback, sizeof(XtPointer), offset(sb.incrementCBL), |
175 XtRCallback, NULL}, | 175 XtRCallback, NULL}, |
176 { (String) XmNdecrementCallback, (String) XmCDecrementCallback, | 176 { XmNdecrementCallback, XmCDecrementCallback, |
177 XtRCallback, sizeof(XtPointer), offset(sb.decrementCBL), | 177 XtRCallback, sizeof(XtPointer), offset(sb.decrementCBL), |
178 XtRCallback, NULL}, | 178 XtRCallback, NULL}, |
179 { (String) XmNpageIncrementCallback, (String) XmCPageIncrementCallback, | 179 { XmNpageIncrementCallback, XmCPageIncrementCallback, |
180 XtRCallback, sizeof(XtPointer), offset(sb.pageIncrementCBL), | 180 XtRCallback, sizeof(XtPointer), offset(sb.pageIncrementCBL), |
181 XtRCallback, NULL}, | 181 XtRCallback, NULL}, |
182 { (String) XmNpageDecrementCallback, (String) XmCPageDecrementCallback, | 182 { XmNpageDecrementCallback, XmCPageDecrementCallback, |
183 XtRCallback, sizeof(XtPointer), offset(sb.pageDecrementCBL), | 183 XtRCallback, sizeof(XtPointer), offset(sb.pageDecrementCBL), |
184 XtRCallback, NULL}, | 184 XtRCallback, NULL}, |
185 { (String) XmNtoTopCallback, (String) XmCToTopCallback, XtRCallback, | 185 { XmNtoTopCallback, XmCToTopCallback, XtRCallback, |
186 sizeof(XtPointer), offset(sb.toTopCBL), XtRCallback, NULL}, | 186 sizeof(XtPointer), offset(sb.toTopCBL), XtRCallback, NULL}, |
187 { (String) XmNtoBottomCallback, (String) XmCToBottomCallback, XtRCallback, | 187 { XmNtoBottomCallback, XmCToBottomCallback, XtRCallback, |
188 sizeof(XtPointer), offset(sb.toBottomCBL), XtRCallback, NULL}, | 188 sizeof(XtPointer), offset(sb.toBottomCBL), XtRCallback, NULL}, |
189 { (String) XmNdragCallback, (String) XmCDragCallback, XtRCallback, | 189 { XmNdragCallback, XmCDragCallback, XtRCallback, |
190 sizeof(XtPointer), offset(sb.dragCBL), XtRCallback, NULL}, | 190 sizeof(XtPointer), offset(sb.dragCBL), XtRCallback, NULL}, |
191 | 191 |
192 { (String) XmNknobStyle, (String) XmCKnobStyle, XtRString, sizeof(char *), | 192 { XmNknobStyle, XmCKnobStyle, XtRString, sizeof(char *), |
193 offset(sb.knobStyle), XtRImmediate, NULL}, | 193 offset(sb.knobStyle), XtRImmediate, NULL}, |
194 | 194 |
195 { (String) XmNarrowPosition, (String) XmCArrowPosition, XtRString, | 195 { XmNarrowPosition, XmCArrowPosition, XtRString, |
196 sizeof(char *), offset(sb.arrowPosition), XtRImmediate, NULL}, | 196 sizeof(char *), offset(sb.arrowPosition), XtRImmediate, NULL}, |
197 }; | 197 }; |
198 | 198 |
199 /************************************************************************ | 199 /************************************************************************ |
200 ** | 200 ** |
232 ** | 232 ** |
233 ** Actions Table | 233 ** Actions Table |
234 ** | 234 ** |
235 */ | 235 */ |
236 static XtActionsRec actions[] = { | 236 static XtActionsRec actions[] = { |
237 {(String) "Select", Select}, | 237 {"Select", Select}, |
238 {(String) "PageDownOrRight",PageDownOrRight}, | 238 {"PageDownOrRight", PageDownOrRight}, |
239 {(String) "PageUpOrLeft", PageUpOrLeft}, | 239 {"PageUpOrLeft", PageUpOrLeft}, |
240 {(String) "Drag", Drag}, | 240 {"Drag", Drag}, |
241 {(String) "Release", Release}, | 241 {"Release", Release}, |
242 {(String) "Jump", Jump}, | 242 {"Jump", Jump}, |
243 {(String) "Abort", Abort}, | 243 {"Abort", Abort}, |
244 }; | 244 }; |
245 | 245 |
246 /************************************************************************ | 246 /************************************************************************ |
247 ** | 247 ** |
248 ** Default Translation Table | 248 ** Default Translation Table |
265 */ | 265 */ |
266 XlwScrollBarClassRec xlwScrollBarClassRec = { | 266 XlwScrollBarClassRec xlwScrollBarClassRec = { |
267 /* core_class fields */ | 267 /* core_class fields */ |
268 { | 268 { |
269 /* superclass */ (WidgetClass) &coreClassRec, | 269 /* superclass */ (WidgetClass) &coreClassRec, |
270 /* class_name */ (String) "XlwScrollBar", | 270 /* class_name */ "XlwScrollBar", |
271 /* widget_size */ sizeof(XlwScrollBarRec), | 271 /* widget_size */ sizeof(XlwScrollBarRec), |
272 /* class_initialize */ NULL, | 272 /* class_initialize */ NULL, |
273 /* class_part_init */ NULL, | 273 /* class_part_init */ NULL, |
274 /* class_inited */ False, | 274 /* class_inited */ False, |
275 /* initialize */ Initialize, | 275 /* initialize */ Initialize, |
580 going to try to get the next closest color. | 580 going to try to get the next closest color. |
581 The algorithm used is a least-squares matching, which is | 581 The algorithm used is a least-squares matching, which is |
582 what X uses for closest color matching with StaticColor visuals. */ | 582 what X uses for closest color matching with StaticColor visuals. */ |
583 | 583 |
584 int nearest, x; | 584 int nearest, x; |
585 unsigned long nearest_delta, trial_delta; | 585 unsigned long nearest_delta = ULONG_MAX; |
586 | 586 |
587 int no_cells = XDisplayCells (display, XDefaultScreen (display)); | 587 int no_cells = XDisplayCells (display, XDefaultScreen (display)); |
588 /* Don't use alloca here because lwlib doesn't have the | 588 /* Don't use alloca here because lwlib doesn't have the |
589 necessary configuration information that src does. */ | 589 necessary configuration information that src does. */ |
590 XColor *cells = (XColor *) malloc (sizeof (XColor) * no_cells); | 590 XColor *cells = (XColor *) malloc (sizeof (XColor) * no_cells); |
592 for (x = 0; x < no_cells; x++) | 592 for (x = 0; x < no_cells; x++) |
593 cells[x].pixel = x; | 593 cells[x].pixel = x; |
594 | 594 |
595 XQueryColors (display, screen_colormap, cells, no_cells); | 595 XQueryColors (display, screen_colormap, cells, no_cells); |
596 | 596 |
597 for (x = 0; x < no_cells; x++) | 597 for (nearest = 0, x = 0; x < no_cells; x++) |
598 { | 598 { |
599 long dred = (color_def->red >> 8) - (cells[x].red >> 8); | 599 long dred = (color_def->red >> 8) - (cells[x].red >> 8); |
600 long dgreen = (color_def->green >> 8) - (cells[x].green >> 8); | 600 long dgreen = (color_def->green >> 8) - (cells[x].green >> 8); |
601 long dblue = (color_def->blue >> 8) - (cells[x].blue >> 8); | 601 long dblue = (color_def->blue >> 8) - (cells[x].blue >> 8); |
602 trial_delta = dred * dred + dgreen * dgreen + dblue * dblue; | 602 unsigned long delta = dred * dred + dgreen * dgreen + dblue * dblue; |
603 | 603 |
604 if (x == 0 || trial_delta < nearest_delta) | 604 if (delta < nearest_delta) |
605 { | 605 { |
606 nearest = x; | 606 nearest = x; |
607 nearest_delta = trial_delta; | 607 nearest_delta = delta; |
608 } | 608 } |
609 } | 609 } |
610 color_def->red = cells[nearest].red; | 610 color_def->red = cells[nearest].red; |
611 color_def->green = cells[nearest].green; | 611 color_def->green = cells[nearest].green; |
612 color_def->blue = cells[nearest].blue; | 612 color_def->blue = cells[nearest].blue; |
1071 if (w->sb.value < w->sb.minimum) | 1071 if (w->sb.value < w->sb.minimum) |
1072 w->sb.value = w->sb.minimum; | 1072 w->sb.value = w->sb.minimum; |
1073 | 1073 |
1074 if (w->sb.value > w->sb.maximum - w->sb.sliderSize) | 1074 if (w->sb.value > w->sb.maximum - w->sb.sliderSize) |
1075 w->sb.value = w->sb.maximum - w->sb.sliderSize; | 1075 w->sb.value = w->sb.maximum - w->sb.sliderSize; |
1076 | |
1077 } | 1076 } |
1078 | 1077 |
1079 static int | 1078 static int |
1080 value_from_pixel (XlwScrollBarWidget w, int above) | 1079 value_from_pixel (XlwScrollBarWidget w, int above) |
1081 { | 1080 { |