Mercurial > hg > xemacs-beta
comparison lwlib/lwlib-Xlw.c @ 70:131b0175ea99 r20-0b30
Import from CVS: tag r20-0b30
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:02:59 +0200 |
parents | 9ee227acff29 |
children | c7528f8e288d |
comparison
equal
deleted
inserted
replaced
69:804d1389bcd6 | 70:131b0175ea99 |
---|---|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 GNU General Public License for more details. | 14 GNU General Public License for more details. |
15 | 15 |
16 You should have received a copy of the GNU General Public License | 16 You should have received a copy of the GNU General Public License |
17 along with XEmacs; see the file COPYING. If not, write to | 17 along with GNU Emacs; see the file COPYING. If not, write to |
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ |
19 Boston, MA 02111-1307, USA. */ | |
20 | 19 |
21 #include <stdlib.h> /* for abort () */ | 20 #include <stdlib.h> /* for abort () */ |
22 #include <limits.h> | 21 #include <limits.h> |
23 | 22 |
24 #include "lwlib-Xlw.h" | 23 #include "lwlib-Xlw.h" |
52 val = lw_get_widget_value_for_widget (instance, w); | 51 val = lw_get_widget_value_for_widget (instance, w); |
53 #if 0 | 52 #if 0 |
54 /* #### - this code used to (for some random back_asswards reason) pass | 53 /* #### - this code used to (for some random back_asswards reason) pass |
55 the expression below in the call_data slot. For incremental menu | 54 the expression below in the call_data slot. For incremental menu |
56 construction, this needs to go. I can't even figure out why it was done | 55 construction, this needs to go. I can't even figure out why it was done |
57 this way in the first place...it's just a historical weirdism. --Stig */ | 56 this way in the first place...it's just a historical wierdism. --Stig */ |
58 call_data = (val ? val->call_data : NULL); | 57 call_data = (val ? val->call_data : NULL); |
59 #endif | 58 #endif |
60 if (val && val->call_data) | 59 if (val && val->call_data) |
61 abort(); /* #### - the call_data for the top_level | 60 abort(); /* #### - the call_data for the top_level |
62 "menubar" widget_value used to be passed | 61 "menubar" widget_value used to be passed |
106 Widget widget = | 105 Widget widget = |
107 XtVaCreateWidget (instance->info->name, xlwMenuWidgetClass, | 106 XtVaCreateWidget (instance->info->name, xlwMenuWidgetClass, |
108 instance->parent, | 107 instance->parent, |
109 XtNmenu, instance->info->val, | 108 XtNmenu, instance->info->val, |
110 0); | 109 0); |
111 XtAddCallback (widget, XtNopen, pre_hook, (XtPointer)instance); | 110 XtAddCallback (widget, XtNopen, pre_hook, (XtPointer)instance); |
112 XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance); | 111 XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance); |
113 return widget; | 112 return widget; |
114 } | 113 } |
115 | 114 |
116 static Widget | 115 static Widget |
153 | 152 |
154 percent = (double) (data->value - 1) / (double) (INT_MAX - 1); | 153 percent = (double) (data->value - 1) / (double) (INT_MAX - 1); |
155 event_data.slider_value = | 154 event_data.slider_value = |
156 (int) (percent * (double) (val->maximum - val->minimum)) + val->minimum; | 155 (int) (percent * (double) (val->maximum - val->minimum)) + val->minimum; |
157 | 156 |
158 if (event_data.slider_value > val->maximum - val->slider_size) | 157 if (event_data.slider_value > (val->maximum - val->slider_size)) |
159 event_data.slider_value = val->maximum - val->slider_size; | 158 event_data.slider_value = val->maximum - val->slider_size; |
160 else if (event_data.slider_value < val->minimum) | 159 else if (event_data.slider_value < val->minimum) |
161 event_data.slider_value = val->minimum; | 160 event_data.slider_value = val->minimum; |
162 | 161 |
163 if (data->event) | 162 if (data->event) |
164 { | 163 { |
165 switch (data->event->type) | 164 switch (data->event->xany.type) |
166 { | 165 { |
167 case KeyPress: | 166 case KeyPress: |
168 case KeyRelease: | 167 case KeyRelease: |
169 event_data.time = data->event->xkey.time; | 168 event_data.time = data->event->xkey.time; |
170 break; | 169 break; |
187 else | 186 else |
188 event_data.time = 0; | 187 event_data.time = 0; |
189 | 188 |
190 switch (data->reason) | 189 switch (data->reason) |
191 { | 190 { |
192 case XmCR_DECREMENT: event_data.action = SCROLLBAR_LINE_UP; break; | 191 case XmCR_DECREMENT: |
193 case XmCR_INCREMENT: event_data.action = SCROLLBAR_LINE_DOWN; break; | 192 event_data.action = SCROLLBAR_LINE_UP; |
194 case XmCR_PAGE_DECREMENT: event_data.action = SCROLLBAR_PAGE_UP; break; | 193 break; |
195 case XmCR_PAGE_INCREMENT: event_data.action = SCROLLBAR_PAGE_DOWN; break; | 194 case XmCR_INCREMENT: |
196 case XmCR_TO_TOP: event_data.action = SCROLLBAR_TOP; break; | 195 event_data.action = SCROLLBAR_LINE_DOWN; |
197 case XmCR_TO_BOTTOM: event_data.action = SCROLLBAR_BOTTOM; break; | 196 break; |
198 case XmCR_DRAG: event_data.action = SCROLLBAR_DRAG; break; | 197 case XmCR_PAGE_DECREMENT: |
199 case XmCR_VALUE_CHANGED: event_data.action = SCROLLBAR_CHANGE; break; | 198 event_data.action = SCROLLBAR_PAGE_UP; |
200 default: event_data.action = SCROLLBAR_CHANGE; break; | 199 break; |
200 case XmCR_PAGE_INCREMENT: | |
201 event_data.action = SCROLLBAR_PAGE_DOWN; | |
202 break; | |
203 case XmCR_TO_TOP: | |
204 event_data.action = SCROLLBAR_TOP; | |
205 break; | |
206 case XmCR_TO_BOTTOM: | |
207 event_data.action = SCROLLBAR_BOTTOM; | |
208 break; | |
209 case XmCR_DRAG: | |
210 event_data.action = SCROLLBAR_DRAG; | |
211 break; | |
212 case XmCR_VALUE_CHANGED: | |
213 event_data.action = SCROLLBAR_CHANGE; | |
214 break; | |
215 default: | |
216 event_data.action = SCROLLBAR_CHANGE; | |
217 break; | |
201 } | 218 } |
202 | 219 |
203 if (instance->info->pre_activate_cb) | 220 if (instance->info->pre_activate_cb) |
204 instance->info->pre_activate_cb (widget, id, (XtPointer) &event_data); | 221 instance->info->pre_activate_cb (widget, id, (XtPointer) &event_data); |
205 } | 222 } |
206 | |
207 #define add_scrollbar_callback(resource) \ | |
208 XtAddCallback (scrollbar, resource, xlw_scrollbar_callback, (XtPointer) instance) | |
209 | 223 |
210 /* #### Does not yet support horizontal scrollbars. */ | 224 /* #### Does not yet support horizontal scrollbars. */ |
211 static Widget | 225 static Widget |
212 xlw_create_scrollbar (widget_instance *instance, int vertical) | 226 xlw_create_scrollbar (widget_instance *instance, int vertical) |
213 { | 227 { |
214 Arg al[20]; | 228 Arg al[20]; |
215 int ac = 0; | 229 int ac = 0; |
216 static XtCallbackRec callbacks[2] = | 230 Widget scrollbar; |
217 { {xlw_scrollbar_callback, NULL}, {NULL, NULL} }; | 231 |
218 | 232 XtSetArg (al[ac], (String) XmNminimum, 1); ac++; |
219 callbacks[0].closure = (XtPointer) instance; | 233 XtSetArg (al[ac], (String) XmNmaximum, INT_MAX); ac++; |
220 | 234 XtSetArg (al[ac], (String) XmNincrement, 1); ac++; |
221 XtSetArg (al[ac], XmNminimum, 1); ac++; | 235 XtSetArg (al[ac], (String) XmNpageIncrement, 1); ac++; |
222 XtSetArg (al[ac], XmNmaximum, INT_MAX); ac++; | 236 if (vertical) |
223 XtSetArg (al[ac], XmNincrement, 1); ac++; | 237 { |
224 XtSetArg (al[ac], XmNpageIncrement, 1); ac++; | 238 XtSetArg (al[ac], (String) XmNorientation, XmVERTICAL); ac++; |
225 XtSetArg (al[ac], XmNorientation, (vertical ? XmVERTICAL : XmHORIZONTAL)); | 239 } |
226 ac++; | 240 else |
227 | 241 { |
228 XtSetArg (al[ac], XmNdecrementCallback, callbacks); ac++; | 242 XtSetArg (al[ac], (String) XmNorientation, XmHORIZONTAL); ac++; |
229 XtSetArg (al[ac], XmNdragCallback, callbacks); ac++; | 243 } |
230 XtSetArg (al[ac], XmNincrementCallback, callbacks); ac++; | 244 |
231 XtSetArg (al[ac], XmNpageDecrementCallback, callbacks); ac++; | 245 scrollbar = |
232 XtSetArg (al[ac], XmNpageIncrementCallback, callbacks); ac++; | 246 XtCreateWidget (instance->info->name, xlwScrollBarWidgetClass, instance->parent, al, ac); |
233 XtSetArg (al[ac], XmNtoBottomCallback, callbacks); ac++; | 247 |
234 XtSetArg (al[ac], XmNtoTopCallback, callbacks); ac++; | 248 XtAddCallback(scrollbar, XmNdecrementCallback, xlw_scrollbar_callback, |
235 XtSetArg (al[ac], XmNvalueChangedCallback, callbacks); ac++; | 249 (XtPointer) instance); |
236 | 250 XtAddCallback(scrollbar, XmNdragCallback, xlw_scrollbar_callback, |
237 return XtCreateWidget (instance->info->name, xlwScrollBarWidgetClass, | 251 (XtPointer) instance); |
238 instance->parent, al, ac); | 252 XtAddCallback(scrollbar, XmNincrementCallback, xlw_scrollbar_callback, |
253 (XtPointer) instance); | |
254 XtAddCallback(scrollbar, XmNpageDecrementCallback, xlw_scrollbar_callback, | |
255 (XtPointer) instance); | |
256 XtAddCallback(scrollbar, XmNpageIncrementCallback, xlw_scrollbar_callback, | |
257 (XtPointer) instance); | |
258 XtAddCallback(scrollbar, XmNtoBottomCallback, xlw_scrollbar_callback, | |
259 (XtPointer) instance); | |
260 XtAddCallback(scrollbar, XmNtoTopCallback, xlw_scrollbar_callback, | |
261 (XtPointer) instance); | |
262 XtAddCallback(scrollbar, XmNvalueChangedCallback, xlw_scrollbar_callback, | |
263 (XtPointer) instance); | |
264 | |
265 return scrollbar; | |
239 } | 266 } |
240 | 267 |
241 static Widget | 268 static Widget |
242 xlw_create_vertical_scrollbar (widget_instance *instance) | 269 xlw_create_vertical_scrollbar (widget_instance *instance) |
243 { | 270 { |
259 scrollbar_values *data = val->scrollbar_data; | 286 scrollbar_values *data = val->scrollbar_data; |
260 int widget_sliderSize, widget_val; | 287 int widget_sliderSize, widget_val; |
261 int new_sliderSize, new_value; | 288 int new_sliderSize, new_value; |
262 double percent; | 289 double percent; |
263 | 290 |
264 /* First size and position the scrollbar widget. */ | 291 /* |
292 * First size and position the scrollbar widget. | |
293 */ | |
265 XtVaSetValues (widget, | 294 XtVaSetValues (widget, |
266 XtNx, data->scrollbar_x, | 295 XtNx, data->scrollbar_x, |
267 XtNy, data->scrollbar_y, | 296 XtNy, data->scrollbar_y, |
268 XtNwidth, data->scrollbar_width, | 297 XtNwidth, data->scrollbar_width, |
269 XtNheight, data->scrollbar_height, | 298 XtNheight, data->scrollbar_height, |
270 0); | 299 0); |
271 | 300 |
272 /* Now size the scrollbar's slider. */ | 301 /* |
302 * Now the size the scrollbar's slider. | |
303 */ | |
304 | |
273 XtVaGetValues (widget, | 305 XtVaGetValues (widget, |
274 XmNsliderSize, &widget_sliderSize, | 306 XmNsliderSize, &widget_sliderSize, |
275 XmNvalue, &widget_val, | 307 XmNvalue, &widget_val, |
276 0); | 308 0); |
277 | 309 |
278 percent = (double) data->slider_size / | 310 percent = (double) data->slider_size / |
279 (double) (data->maximum - data->minimum); | 311 (double) (data->maximum - data->minimum); |
280 percent = (percent > 1.0 ? 1.0 : percent); | 312 percent = (percent > 1.0 ? 1.0 : percent); |
283 percent = (double) (data->slider_position - data->minimum) / | 315 percent = (double) (data->slider_position - data->minimum) / |
284 (double) (data->maximum - data->minimum); | 316 (double) (data->maximum - data->minimum); |
285 percent = (percent > 1.0 ? 1.0 : percent); | 317 percent = (percent > 1.0 ? 1.0 : percent); |
286 new_value = (int) ((double) (INT_MAX - 1) * percent); | 318 new_value = (int) ((double) (INT_MAX - 1) * percent); |
287 | 319 |
288 if (new_sliderSize > INT_MAX - 1) | 320 if (new_sliderSize > (INT_MAX - 1)) |
289 new_sliderSize = INT_MAX - 1; | 321 new_sliderSize = INT_MAX - 1; |
290 if (new_sliderSize < 1) | 322 if (new_sliderSize < 1) |
291 new_sliderSize = 1; | 323 new_sliderSize = 1; |
292 | 324 |
293 if (new_value > (INT_MAX - new_sliderSize)) | 325 if (new_value > (INT_MAX - new_sliderSize)) |
294 new_value = INT_MAX - new_sliderSize; | 326 new_value = INT_MAX - new_sliderSize; |
295 else if (new_value < 1) | 327 else if (new_value < 1) |
296 new_value = 1; | 328 new_value = 1; |
297 | 329 |
298 if (new_sliderSize != widget_sliderSize || new_value != widget_val) | 330 if (new_sliderSize != widget_sliderSize || new_value != widget_val) |
299 XlwScrollBarSetValues (widget, new_value, new_sliderSize, 1, 1, False); | 331 XlwScrollBarSetValues (widget, new_value, new_sliderSize, 1, 1, False); |
300 } | 332 } |
301 } | 333 } |
402 xlw_destroy_instance (widget_instance* instance) | 434 xlw_destroy_instance (widget_instance* instance) |
403 { | 435 { |
404 if (instance->widget) | 436 if (instance->widget) |
405 XtDestroyWidget (instance->widget); | 437 XtDestroyWidget (instance->widget); |
406 } | 438 } |
439 |