comparison src/scrollbar-x.c @ 185:3d6bfa290dbd r20-3b19

Import from CVS: tag r20-3b19
author cvs
date Mon, 13 Aug 2007 09:55:28 +0200
parents 5a88923fcbfe
children eb5470882647
comparison
equal deleted inserted replaced
184:bcd2674570bf 185:3d6bfa290dbd
99 struct scrollbar_instance *instance) 99 struct scrollbar_instance *instance)
100 { 100 {
101 char buffer[32]; 101 char buffer[32];
102 102
103 /* initialize the X specific data section. */ 103 /* initialize the X specific data section. */
104 instance->scrollbar_data = malloc_type_and_zero (struct x_scrollbar_data); 104 instance->scrollbar_data = xnew_and_zero (struct x_scrollbar_data);
105 105
106 SCROLLBAR_X_ID (instance) = new_lwlib_id (); 106 SCROLLBAR_X_ID (instance) = new_lwlib_id ();
107 sprintf (buffer, "scrollbar_%d", SCROLLBAR_X_ID (instance)); 107 sprintf (buffer, "scrollbar_%d", SCROLLBAR_X_ID (instance));
108 SCROLLBAR_X_NAME (instance) = xstrdup (buffer); 108 SCROLLBAR_X_NAME (instance) = xstrdup (buffer);
109 #if defined (LWLIB_SCROLLBARS_MOTIF) || defined (LWLIB_SCROLLBARS_LUCID) || \ 109 #if defined (LWLIB_SCROLLBARS_MOTIF) || defined (LWLIB_SCROLLBARS_LUCID) || \
194 194
195 if (use_backing_store && sb_widget) 195 if (use_backing_store && sb_widget)
196 { 196 {
197 unsigned long mask = CWBackingStore; 197 unsigned long mask = CWBackingStore;
198 XSetWindowAttributes attrs; 198 XSetWindowAttributes attrs;
199 199
200 attrs.backing_store = Always; 200 attrs.backing_store = Always;
201 XChangeWindowAttributes (XtDisplay (sb_widget), 201 XChangeWindowAttributes (XtDisplay (sb_widget),
202 XtWindow (sb_widget), 202 XtWindow (sb_widget),
203 mask, 203 mask,
204 &attrs); 204 &attrs);
213 { 213 {
214 widget_value *wv; 214 widget_value *wv;
215 215
216 wv = xmalloc_widget_value (); 216 wv = xmalloc_widget_value ();
217 /* #### maybe should add malloc_scrollbar_values to resource these? */ 217 /* #### maybe should add malloc_scrollbar_values to resource these? */
218 wv->scrollbar_data = (scrollbar_values *) 218 wv->scrollbar_data = xnew (scrollbar_values);
219 xmalloc (sizeof (scrollbar_values));
220 219
221 wv->name = SCROLLBAR_X_NAME (instance); 220 wv->name = SCROLLBAR_X_NAME (instance);
222 wv->value = 0; 221 wv->value = 0;
223 wv->key = 0; 222 wv->key = 0;
224 wv->enabled = instance->scrollbar_is_active; 223 wv->enabled = instance->scrollbar_is_active;
236 static void 235 static void
237 update_one_widget_scrollbar_pointer (struct window *w, Widget wid) 236 update_one_widget_scrollbar_pointer (struct window *w, Widget wid)
238 { 237 {
239 if (POINTER_IMAGE_INSTANCEP (w->scrollbar_pointer)) 238 if (POINTER_IMAGE_INSTANCEP (w->scrollbar_pointer))
240 { 239 {
241 XDefineCursor (XtDisplay (wid), XtWindow (wid), 240 XDefineCursor (XtDisplay (wid), XtWindow (wid),
242 XIMAGE_INSTANCE_X_CURSOR (w->scrollbar_pointer)); 241 XIMAGE_INSTANCE_X_CURSOR (w->scrollbar_pointer));
243 XSync (XtDisplay (wid), False); 242 XSync (XtDisplay (wid), False);
244 } 243 }
245 } 244 }
246 245
323 f->scrollbar_width, so temporarily set it back to the old 322 f->scrollbar_width, so temporarily set it back to the old
324 one. */ 323 one. */
325 f->scrollbar_width = oldval; 324 f->scrollbar_width = oldval;
326 XtQueryGeometry (FRAME_X_CONTAINER_WIDGET (f), &req, &repl); 325 XtQueryGeometry (FRAME_X_CONTAINER_WIDGET (f), &req, &repl);
327 f->scrollbar_width = newval; 326 f->scrollbar_width = newval;
328 327
329 repl.width += XINT (newval) - XINT (oldval); 328 repl.width += XINT (newval) - XINT (oldval);
330 EmacsManagerChangeSize (FRAME_X_CONTAINER_WIDGET (f), repl.width, 329 EmacsManagerChangeSize (FRAME_X_CONTAINER_WIDGET (f), repl.width,
331 repl.height); 330 repl.height);
332 } 331 }
333 332
368 f->scrollbar_height, so temporarily set it back to the old 367 f->scrollbar_height, so temporarily set it back to the old
369 one. */ 368 one. */
370 f->scrollbar_height = oldval; 369 f->scrollbar_height = oldval;
371 XtQueryGeometry (FRAME_X_CONTAINER_WIDGET (f), &req, &repl); 370 XtQueryGeometry (FRAME_X_CONTAINER_WIDGET (f), &req, &repl);
372 f->scrollbar_height = newval; 371 f->scrollbar_height = newval;
373 372
374 repl.height += XINT (newval) - XINT (oldval); 373 repl.height += XINT (newval) - XINT (oldval);
375 EmacsManagerChangeSize (FRAME_X_CONTAINER_WIDGET (f), repl.width, 374 EmacsManagerChangeSize (FRAME_X_CONTAINER_WIDGET (f), repl.width,
376 repl.height); 375 repl.height);
377 } 376 }
378 377
549 { 548 {
550 double tmp = ((double) data->slider_value / 549 double tmp = ((double) data->slider_value /
551 (double) SCROLLBAR_X_POS_DATA(instance).scrollbar_height); 550 (double) SCROLLBAR_X_POS_DATA(instance).scrollbar_height);
552 double line = tmp * 551 double line = tmp *
553 (double) window_displayed_height (XWINDOW (win)); 552 (double) window_displayed_height (XWINDOW (win));
554 553
555 if (line > -1.0) 554 if (line > -1.0)
556 line = -1.0; 555 line = -1.0;
557 signal_special_Xt_user_event (win, Qscrollbar_page_up, 556 signal_special_Xt_user_event (win, Qscrollbar_page_up,
558 Fcons (win, make_int ((int) line))); 557 Fcons (win, make_int ((int) line)));
559 } 558 }
622 you can scroll all the way to the top or bottom of the 621 you can scroll all the way to the top or bottom of the
623 buffer. This can all be replaced with something sane when 622 buffer. This can all be replaced with something sane when
624 we get line-based scrolling. */ 623 we get line-based scrolling. */
625 624
626 vertical_drag_in_progress = 1; 625 vertical_drag_in_progress = 1;
627 626
628 if (SCROLLBAR_X_VDRAG_ORIG_VALUE (instance) < 0) 627 if (SCROLLBAR_X_VDRAG_ORIG_VALUE (instance) < 0)
629 { 628 {
630 SCROLLBAR_X_VDRAG_ORIG_VALUE (instance) = data->slider_value; 629 SCROLLBAR_X_VDRAG_ORIG_VALUE (instance) = data->slider_value;
631 SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (instance) = 630 SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (instance) =
632 XINT (Fwindow_start (win)); 631 XINT (Fwindow_start (win));
633 } 632 }
634 633
635 /* Could replace this piecewise linear scrolling with a 634 /* Could replace this piecewise linear scrolling with a
636 quadratic through the three points, but I'm not sure that 635 quadratic through the three points, but I'm not sure that
637 would feel any nicer in practice. */ 636 would feel any nicer in practice. */
638 if (data->slider_value < SCROLLBAR_X_VDRAG_ORIG_VALUE (instance)) 637 if (data->slider_value < SCROLLBAR_X_VDRAG_ORIG_VALUE (instance))
639 { 638 {
640 /* We've dragged up; slide linearly from original position to 639 /* We've dragged up; slide linearly from original position to
641 window-start=data.minimum, slider-value=data.minimum. */ 640 window-start=data.minimum, slider-value=data.minimum. */
642 641
643 if (SCROLLBAR_X_VDRAG_ORIG_VALUE (instance) 642 if (SCROLLBAR_X_VDRAG_ORIG_VALUE (instance)
644 <= SCROLLBAR_X_POS_DATA (instance).minimum) 643 <= SCROLLBAR_X_POS_DATA (instance).minimum)
645 { 644 {
646 /* shouldn't get here, but just in case */ 645 /* shouldn't get here, but just in case */
647 value = SCROLLBAR_X_POS_DATA (instance).minimum; 646 value = SCROLLBAR_X_POS_DATA (instance).minimum;
648 } 647 }
649 else 648 else
650 { 649 {
651 value = (SCROLLBAR_X_POS_DATA (instance).minimum 650 value = (SCROLLBAR_X_POS_DATA (instance).minimum
652 + (((double) 651 + (((double)
653 (SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (instance) 652 (SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (instance)
654 - SCROLLBAR_X_POS_DATA (instance).minimum) 653 - SCROLLBAR_X_POS_DATA (instance).minimum)
655 * (data->slider_value - 654 * (data->slider_value -
656 SCROLLBAR_X_POS_DATA (instance).minimum)) 655 SCROLLBAR_X_POS_DATA (instance).minimum))
657 / (SCROLLBAR_X_VDRAG_ORIG_VALUE (instance) 656 / (SCROLLBAR_X_VDRAG_ORIG_VALUE (instance)
658 - SCROLLBAR_X_POS_DATA (instance).minimum))); 657 - SCROLLBAR_X_POS_DATA (instance).minimum)));
659 } 658 }
660 } 659 }
661 else 660 else
662 { 661 {
663 /* We've dragged down; slide linearly from original position to 662 /* We've dragged down; slide linearly from original position to
664 window-start=data.maximum, slider-value=data.maximum. */ 663 window-start=data.maximum, slider-value=data.maximum. */
665 664
666 if (SCROLLBAR_X_VDRAG_ORIG_VALUE (instance) 665 if (SCROLLBAR_X_VDRAG_ORIG_VALUE (instance)
667 >= (SCROLLBAR_X_POS_DATA (instance).maximum - 666 >= (SCROLLBAR_X_POS_DATA (instance).maximum -
668 SCROLLBAR_X_POS_DATA (instance).slider_size)) 667 SCROLLBAR_X_POS_DATA (instance).slider_size))
669 { 668 {
670 /* avoid divide by zero */ 669 /* avoid divide by zero */
671 value = SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (instance); 670 value = SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (instance);
672 } 671 }
673 else 672 else
674 { 673 {
675 value = (SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (instance) 674 value = (SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (instance)
676 + (((double) (SCROLLBAR_X_POS_DATA (instance).maximum 675 + (((double) (SCROLLBAR_X_POS_DATA (instance).maximum
677 - SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (instance)) 676 - SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (instance))
678 * (data->slider_value 677 * (data->slider_value
679 - SCROLLBAR_X_VDRAG_ORIG_VALUE (instance))) 678 - SCROLLBAR_X_VDRAG_ORIG_VALUE (instance)))
680 / (SCROLLBAR_X_POS_DATA (instance).maximum 679 / (SCROLLBAR_X_POS_DATA (instance).maximum
681 - SCROLLBAR_X_POS_DATA (instance).slider_size 680 - SCROLLBAR_X_POS_DATA (instance).slider_size
682 - SCROLLBAR_X_VDRAG_ORIG_VALUE (instance)))); 681 - SCROLLBAR_X_VDRAG_ORIG_VALUE (instance))));
683 } 682 }
684 } 683 }