Mercurial > hg > xemacs-beta
annotate src/scrollbar-x.c @ 5172:be6e5ea38dda
merge
| author | Ben Wing <ben@xemacs.org> |
|---|---|
| date | Mon, 29 Mar 2010 00:11:03 -0500 |
| parents | 5ddbab03b0e6 |
| children | 308d34e9f07d |
| rev | line source |
|---|---|
| 428 | 1 /* scrollbar implementation -- X interface. |
| 2 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois. | |
| 3 Copyright (C) 1994 Amdahl Corporation. | |
| 4 Copyright (C) 1995 Sun Microsystems, Inc. | |
| 5 Copyright (C) 1995 Darrell Kindred <dkindred+@cmu.edu>. | |
|
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
6 Copyright (C) 2010 Ben Wing. |
| 428 | 7 |
| 8 This file is part of XEmacs. | |
| 9 | |
| 10 XEmacs is free software; you can redistribute it and/or modify it | |
| 11 under the terms of the GNU General Public License as published by the | |
| 12 Free Software Foundation; either version 2, or (at your option) any | |
| 13 later version. | |
| 14 | |
| 15 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
| 16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 18 for more details. | |
| 19 | |
| 20 You should have received a copy of the GNU General Public License | |
| 21 along with XEmacs; see the file COPYING. If not, write to | |
| 22 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
| 23 Boston, MA 02111-1307, USA. */ | |
| 24 | |
| 25 /* Synched up with: Not in FSF. */ | |
| 26 | |
| 442 | 27 /* This file Mule-ized (more like Mule-verified) by Ben Wing, 7-8-00. */ |
| 28 | |
| 428 | 29 #include <config.h> |
| 30 #include "lisp.h" | |
| 31 | |
| 872 | 32 #include "device-impl.h" |
| 33 #include "frame-impl.h" | |
| 800 | 34 #include "window.h" |
| 35 | |
| 872 | 36 #include "console-x-impl.h" |
| 428 | 37 #include "glyphs-x.h" |
| 38 #include "scrollbar-x.h" | |
| 39 | |
| 800 | 40 #include "EmacsFrame.h" |
| 428 | 41 |
| 42 static void x_update_vertical_scrollbar_callback (Widget widget, LWLIB_ID id, | |
| 43 XtPointer client_data); | |
| 44 static void x_update_horizontal_scrollbar_callback (Widget widget, LWLIB_ID id, | |
| 45 XtPointer client_data); | |
| 46 | |
| 47 /* Used to prevent changing the size of the slider while drag | |
| 48 scrolling, under Motif. This is necessary because the Motif | |
| 49 scrollbar is incredibly stupid about updating the slider and causes | |
| 50 lots of flicker if it is done too often. */ | |
| 51 static int inhibit_slider_size_change; | |
| 52 int stupid_vertical_scrollbar_drag_hack; | |
| 53 | |
| 54 /* Doesn't work with athena */ | |
| 55 #if defined (LWLIB_SCROLLBARS_MOTIF) || defined (LWLIB_SCROLLBARS_LUCID) | |
| 56 static int vertical_drag_in_progress; | |
| 57 #endif | |
| 58 | |
| 59 | |
| 60 /* A device method. */ | |
| 61 static int | |
| 62 x_inhibit_scrollbar_slider_size_change (void) | |
| 63 { | |
| 64 /* Doesn't work with Athena */ | |
| 65 #if defined (LWLIB_SCROLLBARS_MOTIF) || defined (LWLIB_SCROLLBARS_LUCID) | |
| 66 return inhibit_slider_size_change; | |
| 67 #else | |
| 68 return 0; | |
| 69 #endif | |
| 70 } | |
| 71 | |
| 72 /* A device method. */ | |
| 73 static void | |
| 74 x_free_scrollbar_instance (struct scrollbar_instance *instance) | |
| 75 { | |
| 3462 | 76 if (instance->scrollbar_data) |
| 428 | 77 { |
| 3462 | 78 if (SCROLLBAR_X_NAME (instance)) |
|
5169
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
79 { |
|
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
80 xfree (SCROLLBAR_X_NAME (instance)); |
|
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
81 SCROLLBAR_X_NAME (instance) = 0; |
|
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
82 } |
| 428 | 83 |
| 3462 | 84 if (SCROLLBAR_X_WIDGET (instance)) |
| 85 { | |
| 86 if (XtIsManaged (SCROLLBAR_X_WIDGET (instance))) | |
| 87 XtUnmanageChild (SCROLLBAR_X_WIDGET (instance)); | |
| 428 | 88 |
| 3462 | 89 lw_destroy_all_widgets (SCROLLBAR_X_ID (instance)); |
| 90 } | |
| 91 | |
|
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
3462
diff
changeset
|
92 xfree (instance->scrollbar_data); |
|
5169
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
93 instance->scrollbar_data = 0; |
| 3462 | 94 } |
| 428 | 95 } |
| 96 | |
| 97 /* A device method. */ | |
| 98 static void | |
| 99 x_release_scrollbar_instance (struct scrollbar_instance *instance) | |
| 100 { | |
| 101 if (XtIsManaged (SCROLLBAR_X_WIDGET (instance))) | |
| 102 XtUnmanageChild (SCROLLBAR_X_WIDGET (instance)); | |
| 103 } | |
| 104 | |
| 105 /* A device method. */ | |
| 106 static void | |
| 107 x_create_scrollbar_instance (struct frame *f, int vertical, | |
| 108 struct scrollbar_instance *instance) | |
| 109 { | |
| 110 char buffer[32]; | |
| 111 | |
| 112 /* initialize the X specific data section. */ | |
| 113 instance->scrollbar_data = xnew_and_zero (struct x_scrollbar_data); | |
| 114 | |
| 115 SCROLLBAR_X_ID (instance) = new_lwlib_id (); | |
| 116 sprintf (buffer, "scrollbar_%d", SCROLLBAR_X_ID (instance)); | |
| 117 SCROLLBAR_X_NAME (instance) = xstrdup (buffer); | |
| 118 #if defined (LWLIB_SCROLLBARS_MOTIF) || defined (LWLIB_SCROLLBARS_LUCID) || \ | |
| 119 defined (LWLIB_SCROLLBARS_ATHENA3D) | |
| 120 SCROLLBAR_X_VDRAG_ORIG_VALUE (instance) = -1; | |
| 121 #endif | |
| 122 | |
| 123 if (vertical) | |
| 124 { | |
| 125 SCROLLBAR_X_WIDGET (instance) = | |
| 126 lw_create_widget ("vertical-scrollbar", SCROLLBAR_X_NAME (instance), | |
| 127 SCROLLBAR_X_ID (instance), | |
| 128 NULL, FRAME_X_CONTAINER_WIDGET (f), 0, | |
| 129 x_update_vertical_scrollbar_callback, NULL, NULL); | |
| 130 } | |
| 131 else | |
| 132 { | |
| 133 SCROLLBAR_X_WIDGET (instance) = | |
| 134 lw_create_widget ("horizontal-scrollbar", SCROLLBAR_X_NAME (instance), | |
| 135 SCROLLBAR_X_ID (instance), | |
| 136 NULL, FRAME_X_CONTAINER_WIDGET (f), 0, | |
| 137 x_update_horizontal_scrollbar_callback, NULL, NULL); | |
| 138 } | |
| 139 } | |
| 140 | |
| 141 #define UPDATE_DATA_FIELD(field) \ | |
| 142 if (new_##field >= 0 && \ | |
| 143 SCROLLBAR_X_POS_DATA (inst).field != new_##field) { \ | |
| 144 SCROLLBAR_X_POS_DATA (inst).field = new_##field; \ | |
| 145 inst->scrollbar_instance_changed = 1; \ | |
| 146 } | |
| 147 | |
| 148 /* A device method. */ | |
| 149 /* #### The -1 check is such a hack. */ | |
| 150 static void | |
| 151 x_update_scrollbar_instance_values (struct window *w, | |
| 152 struct scrollbar_instance *inst, | |
| 153 int new_line_increment, | |
| 154 int new_page_increment, | |
| 155 int new_minimum, int new_maximum, | |
| 156 int new_slider_size, | |
| 157 int new_slider_position, | |
| 158 int new_scrollbar_width, | |
| 159 int new_scrollbar_height, | |
| 160 int new_scrollbar_x, int new_scrollbar_y) | |
| 161 { | |
| 162 UPDATE_DATA_FIELD (line_increment); | |
| 163 UPDATE_DATA_FIELD (page_increment); | |
| 164 UPDATE_DATA_FIELD (minimum); | |
| 165 UPDATE_DATA_FIELD (maximum); | |
| 166 UPDATE_DATA_FIELD (slider_size); | |
| 167 UPDATE_DATA_FIELD (slider_position); | |
| 168 UPDATE_DATA_FIELD (scrollbar_width); | |
| 169 UPDATE_DATA_FIELD (scrollbar_height); | |
| 170 UPDATE_DATA_FIELD (scrollbar_x); | |
| 171 UPDATE_DATA_FIELD (scrollbar_y); | |
| 172 | |
| 173 /* This doesn't work with Athena, why? */ | |
| 174 #if defined (LWLIB_SCROLLBARS_MOTIF) || defined (LWLIB_SCROLLBARS_LUCID) | |
| 175 if (w && !vertical_drag_in_progress) | |
| 176 { | |
| 177 int new_vov = SCROLLBAR_X_POS_DATA (inst).slider_position; | |
| 178 int new_vows = marker_position (w->start[CURRENT_DISP]); | |
| 179 | |
| 180 if (SCROLLBAR_X_VDRAG_ORIG_VALUE (inst) != new_vov) | |
| 181 { | |
| 182 SCROLLBAR_X_VDRAG_ORIG_VALUE (inst) = new_vov; | |
| 183 inst->scrollbar_instance_changed = 1; | |
| 184 } | |
| 185 if (SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (inst) != new_vows) | |
| 186 { | |
| 187 SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (inst) = new_vows; | |
| 188 inst->scrollbar_instance_changed = 1; | |
| 189 } | |
| 190 } | |
| 191 #endif | |
| 192 } | |
| 193 | |
| 194 /* Used by x_update_scrollbar_instance_status. */ | |
| 195 static void | |
| 196 update_one_scrollbar_bs (struct frame *f, Widget sb_widget) | |
| 197 { | |
| 198 Boolean use_backing_store; | |
| 199 | |
| 200 Xt_GET_VALUE (FRAME_X_TEXT_WIDGET (f), XtNuseBackingStore, &use_backing_store); | |
| 201 | |
| 202 if (use_backing_store && sb_widget) | |
| 203 { | |
| 204 unsigned long mask = CWBackingStore; | |
| 205 XSetWindowAttributes attrs; | |
| 206 | |
| 207 attrs.backing_store = Always; | |
| 208 XChangeWindowAttributes (XtDisplay (sb_widget), | |
| 209 XtWindow (sb_widget), | |
| 210 mask, | |
| 211 &attrs); | |
| 212 } | |
| 213 } | |
| 214 | |
| 215 /* Create a widget value structure for passing down to lwlib so that | |
| 216 it can update the scrollbar widgets. Used by | |
| 217 x_update_scrollbar_instance_status. */ | |
| 218 static widget_value * | |
| 219 scrollbar_instance_to_widget_value (struct scrollbar_instance *instance) | |
| 220 { | |
| 221 widget_value *wv; | |
| 222 | |
| 223 wv = xmalloc_widget_value (); | |
| 224 /* #### maybe should add malloc_scrollbar_values to resource these? */ | |
| 225 wv->scrollbar_data = xnew (scrollbar_values); | |
| 226 | |
| 227 wv->name = SCROLLBAR_X_NAME (instance); | |
| 436 | 228 wv->name = xstrdup (wv->name); |
| 428 | 229 wv->value = 0; |
| 230 wv->key = 0; | |
| 231 wv->enabled = instance->scrollbar_is_active; | |
| 232 wv->selected = 0; | |
| 233 wv->call_data = NULL; | |
| 234 | |
| 235 *wv->scrollbar_data = SCROLLBAR_X_POS_DATA (instance); | |
| 236 | |
| 237 wv->next = NULL; | |
| 238 | |
| 239 return wv; | |
| 240 } | |
| 241 | |
| 242 /* Used by x_update_scrollbar_instance_status. */ | |
| 243 static void | |
| 244 update_one_widget_scrollbar_pointer (struct window *w, Widget wid) | |
| 245 { | |
| 246 if (POINTER_IMAGE_INSTANCEP (w->scrollbar_pointer)) | |
| 247 { | |
| 248 XDefineCursor (XtDisplay (wid), XtWindow (wid), | |
| 249 XIMAGE_INSTANCE_X_CURSOR (w->scrollbar_pointer)); | |
| 250 XSync (XtDisplay (wid), False); | |
| 251 } | |
| 252 } | |
| 253 | |
| 254 /* A device method. */ | |
| 255 static void | |
| 256 x_update_scrollbar_instance_status (struct window *w, int active, int size, | |
| 257 struct scrollbar_instance *instance) | |
| 258 { | |
| 259 struct frame *f = XFRAME (w->frame); | |
| 260 Boolean managed = XtIsManaged (SCROLLBAR_X_WIDGET (instance)); | |
| 261 | |
| 262 if (active && size) | |
| 263 { | |
| 264 widget_value *wv = scrollbar_instance_to_widget_value (instance); | |
| 265 | |
| 266 if (instance->scrollbar_instance_changed) | |
| 267 { | |
| 268 lw_modify_all_widgets (SCROLLBAR_X_ID (instance), wv, 0); | |
| 269 instance->scrollbar_instance_changed = 0; | |
| 270 } | |
| 271 | |
| 272 if (!managed) | |
| 273 { | |
| 274 XtManageChild (SCROLLBAR_X_WIDGET (instance)); | |
| 275 if (XtWindow (SCROLLBAR_X_WIDGET (instance))) | |
| 276 { | |
| 277 /* Raise this window so that it's visible on top of the | |
| 278 text window below it. */ | |
| 279 XRaiseWindow (XtDisplay (SCROLLBAR_X_WIDGET (instance)), | |
| 280 XtWindow (SCROLLBAR_X_WIDGET (instance))); | |
| 281 update_one_widget_scrollbar_pointer | |
| 282 (w, SCROLLBAR_X_WIDGET (instance)); | |
| 283 if (!SCROLLBAR_X_BACKING_STORE_INITIALIZED (instance)) | |
| 284 { | |
| 285 update_one_scrollbar_bs (f, SCROLLBAR_X_WIDGET (instance)); | |
| 286 SCROLLBAR_X_BACKING_STORE_INITIALIZED (instance) = 1; | |
| 287 } | |
| 288 } | |
| 289 } | |
| 290 | |
|
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
291 assert (wv->scrollbar_data); |
| 436 | 292 free_widget_value_tree (wv); |
| 428 | 293 } |
| 294 else if (managed) | |
| 295 { | |
| 296 #if defined (LWLIB_SCROLLBARS_MOTIF) || defined (LWLIB_SCROLLBARS_LUCID) | |
| 297 /* This isn't needed with Athena Scrollbars. It might not be needed */ | |
| 298 /* with Motif scrollbars (it is apparently needed with Lesstif). */ | |
| 299 XtUngrabKeyboard (SCROLLBAR_X_WIDGET (instance), CurrentTime); | |
| 300 #endif | |
| 301 XtUnmanageChild (SCROLLBAR_X_WIDGET (instance)); | |
| 302 } | |
| 303 } | |
| 304 | |
| 305 enum x_scrollbar_loop | |
| 306 { | |
| 307 X_FIND_SCROLLBAR_WINDOW_MIRROR, | |
| 308 X_SET_SCROLLBAR_POINTER, | |
| 309 X_WINDOW_IS_SCROLLBAR, | |
| 310 X_UPDATE_FRAME_SCROLLBARS | |
| 311 }; | |
| 312 | |
| 313 static struct window_mirror * | |
| 314 x_scrollbar_loop (enum x_scrollbar_loop type, Lisp_Object window, | |
| 315 struct window_mirror *mir, | |
| 316 LWLIB_ID id, Window x_win) | |
| 317 { | |
| 318 struct window_mirror *retval = NULL; | |
| 319 | |
| 320 while (mir) | |
| 321 { | |
| 322 struct scrollbar_instance *vinstance = mir->scrollbar_vertical_instance; | |
| 323 struct scrollbar_instance *hinstance = mir->scrollbar_horizontal_instance; | |
| 324 struct window *w = XWINDOW (window); | |
| 325 | |
| 326 if (mir->vchild) | |
| 327 retval = x_scrollbar_loop (type, w->vchild, mir->vchild, id, x_win); | |
| 328 else if (mir->hchild) | |
| 329 retval = x_scrollbar_loop (type, w->hchild, mir->hchild, id, x_win); | |
| 330 if (retval) | |
| 331 return retval; | |
| 332 | |
| 333 if (hinstance || vinstance) | |
| 334 { | |
| 335 switch (type) | |
| 336 { | |
| 337 case X_FIND_SCROLLBAR_WINDOW_MIRROR: | |
| 338 if ((vinstance && SCROLLBAR_X_ID (vinstance) == id) || | |
| 339 (hinstance && SCROLLBAR_X_ID (hinstance) == id)) | |
| 340 return mir; | |
| 341 break; | |
| 342 case X_UPDATE_FRAME_SCROLLBARS: | |
| 343 if (!mir->vchild && !mir->hchild) | |
| 344 update_window_scrollbars (w, mir, 1, 0); | |
| 345 break; | |
| 346 case X_SET_SCROLLBAR_POINTER: | |
| 347 if (!mir->vchild && !mir->hchild) | |
| 348 { | |
| 349 Widget widget; | |
| 350 | |
| 351 widget = SCROLLBAR_X_WIDGET (hinstance); | |
| 352 if (widget && XtIsManaged (widget)) | |
| 353 update_one_widget_scrollbar_pointer (w, widget); | |
| 354 | |
| 355 widget = SCROLLBAR_X_WIDGET (vinstance); | |
| 356 if (widget && XtIsManaged (widget)) | |
| 357 update_one_widget_scrollbar_pointer (w, widget); | |
| 358 } | |
| 359 break; | |
| 360 case X_WINDOW_IS_SCROLLBAR: | |
| 361 if (!mir->vchild && !mir->hchild) | |
| 362 { | |
| 363 Widget widget; | |
| 364 | |
| 365 widget = SCROLLBAR_X_WIDGET (hinstance); | |
| 366 if (widget && XtIsManaged (widget) && | |
| 367 XtWindow (widget) == x_win) | |
| 368 return (struct window_mirror *) 1; | |
| 369 | |
| 370 widget = SCROLLBAR_X_WIDGET (vinstance); | |
| 371 if (widget && XtIsManaged (widget) && | |
| 372 XtWindow (widget) == x_win) | |
| 373 return (struct window_mirror *) 1; | |
| 374 } | |
| 375 break; | |
| 376 default: | |
| 2500 | 377 ABORT (); |
| 428 | 378 } |
| 379 } | |
| 380 | |
| 381 mir = mir->next; | |
| 382 window = w->next; | |
| 383 } | |
| 384 | |
| 385 return NULL; | |
| 386 } | |
| 387 | |
| 388 /* Used by callbacks. */ | |
| 389 static struct window_mirror * | |
| 390 find_scrollbar_window_mirror (struct frame *f, LWLIB_ID id) | |
| 391 { | |
| 392 if (f->mirror_dirty) | |
| 393 update_frame_window_mirror (f); | |
| 394 return x_scrollbar_loop (X_FIND_SCROLLBAR_WINDOW_MIRROR, f->root_window, | |
| 617 | 395 XWINDOW_MIRROR (f->root_mirror), id, (Window) NULL); |
| 428 | 396 } |
| 397 | |
| 398 /* | |
| 399 * This is the only callback provided for vertical scrollbars. It | |
| 400 * should be able to handle all of the scrollbar events in | |
| 401 * scroll_action (see lwlib.h). The client data will be of type | |
| 402 * scroll_event (see lwlib.h). */ | |
| 403 static void | |
| 404 x_update_vertical_scrollbar_callback (Widget widget, LWLIB_ID id, | |
| 405 XtPointer client_data) | |
| 406 { | |
| 407 /* This function can GC */ | |
| 408 scroll_event *data = (scroll_event *) client_data; | |
| 409 struct device *d = get_device_from_display (XtDisplay (widget)); | |
| 410 struct frame *f = x_any_window_to_frame (d, XtWindow (widget)); | |
| 411 Lisp_Object win, frame; | |
| 412 struct scrollbar_instance *instance; | |
| 413 struct window_mirror *mirror; | |
| 414 | |
| 415 if (!f) | |
| 416 return; | |
| 417 | |
| 418 mirror = find_scrollbar_window_mirror (f, id); | |
| 442 | 419 if (!mirror) |
| 420 return; | |
| 421 | |
| 428 | 422 win = real_window (mirror, 1); |
| 423 | |
| 424 if (NILP (win)) | |
| 425 return; | |
| 426 instance = mirror->scrollbar_vertical_instance; | |
| 427 frame = WINDOW_FRAME (XWINDOW (win)); | |
| 428 | |
| 429 /* It seems that this is necessary whenever signal_special_Xt_user_event() | |
| 430 is called. #### Why??? */ | |
| 431 DEVICE_X_MOUSE_TIMESTAMP (d) = DEVICE_X_GLOBAL_MOUSE_TIMESTAMP (d); | |
| 432 | |
| 433 switch (data->action) | |
| 434 { | |
| 435 case SCROLLBAR_LINE_UP: | |
| 436 signal_special_Xt_user_event (frame, Qscrollbar_line_up, win); | |
| 437 break; | |
| 438 | |
| 439 case SCROLLBAR_LINE_DOWN: | |
| 440 signal_special_Xt_user_event (frame, Qscrollbar_line_down, win); | |
| 441 break; | |
| 442 | |
| 443 /* The Athena scrollbar paging behavior is that of xterms. | |
| 444 Depending on where you click the size of the page varies. | |
| 445 Motif always does a standard Emacs page. */ | |
| 446 case SCROLLBAR_PAGE_UP: | |
| 447 #if !defined (LWLIB_SCROLLBARS_MOTIF) && !defined (LWLIB_SCROLLBARS_LUCID) && \ | |
| 448 !defined (LWLIB_SCROLLBARS_ATHENA3D) | |
| 449 { | |
| 450 double tmp = ((double) data->slider_value / | |
| 451 (double) SCROLLBAR_X_POS_DATA(instance).scrollbar_height); | |
| 452 double line = tmp * | |
| 453 (double) window_displayed_height (XWINDOW (win)); | |
| 454 | |
| 455 if (line > -1.0) | |
| 456 line = -1.0; | |
| 457 signal_special_Xt_user_event (frame, Qscrollbar_page_up, | |
| 458 Fcons (win, make_int ((int) line))); | |
| 459 } | |
| 460 #else | |
| 461 signal_special_Xt_user_event (frame, Qscrollbar_page_up, | |
| 462 Fcons (win, Qnil)); | |
| 463 #endif | |
| 464 break; | |
| 465 | |
| 466 case SCROLLBAR_PAGE_DOWN: | |
| 467 #if !defined (LWLIB_SCROLLBARS_MOTIF) && !defined (LWLIB_SCROLLBARS_LUCID) && \ | |
| 468 !defined (LWLIB_SCROLLBARS_ATHENA3D) | |
| 469 { | |
| 470 double tmp = ((double) data->slider_value / | |
| 471 (double) SCROLLBAR_X_POS_DATA(instance).scrollbar_height); | |
| 472 double line = tmp * | |
| 473 (double) window_displayed_height (XWINDOW (win)); | |
| 474 | |
| 475 if (SCROLLBAR_X_POS_DATA(instance).maximum > | |
| 476 (SCROLLBAR_X_POS_DATA(instance).slider_size + SCROLLBAR_X_POS_DATA(instance).slider_position)) | |
| 477 { | |
| 478 if (line < 1.0) | |
| 479 line = 1.0; | |
| 480 signal_special_Xt_user_event (frame, Qscrollbar_page_down, | |
| 481 Fcons (win, | |
| 482 make_int ((int) line))); | |
| 483 } | |
| 484 } | |
| 485 #else | |
| 486 signal_special_Xt_user_event (frame, Qscrollbar_page_down, | |
| 487 Fcons (win, Qnil)); | |
| 488 #endif | |
| 489 break; | |
| 490 | |
| 491 case SCROLLBAR_TOP: | |
| 492 signal_special_Xt_user_event (frame, Qscrollbar_to_top, win); | |
| 493 break; | |
| 494 | |
| 495 case SCROLLBAR_BOTTOM: | |
| 496 signal_special_Xt_user_event (frame, Qscrollbar_to_bottom, win); | |
| 497 break; | |
| 498 | |
| 499 | |
| 500 case SCROLLBAR_CHANGE: | |
| 501 inhibit_slider_size_change = 0; | |
| 502 #if defined (LWLIB_SCROLLBARS_MOTIF) || defined (LWLIB_SCROLLBARS_LUCID) | |
| 503 vertical_drag_in_progress = 0; | |
| 504 SCROLLBAR_X_VDRAG_ORIG_VALUE (instance) = data->slider_value; | |
| 505 SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (instance) = | |
| 506 XINT (Fwindow_start (win)); | |
| 507 #else | |
| 508 stupid_vertical_scrollbar_drag_hack = 0; | |
| 509 #endif | |
| 510 break; | |
| 511 | |
| 512 case SCROLLBAR_DRAG: | |
| 513 { | |
| 514 int value; | |
| 515 | |
| 516 inhibit_slider_size_change = 1; | |
| 517 | |
| 518 #if defined (LWLIB_SCROLLBARS_MOTIF) || defined (LWLIB_SCROLLBARS_LUCID) | |
| 519 /* Doing drags with Motif-like scrollbars is a mess, since we | |
| 520 want to avoid having the window position jump when you | |
| 521 first grab the scrollbar, but we also want to ensure that | |
| 522 you can scroll all the way to the top or bottom of the | |
| 523 buffer. This can all be replaced with something sane when | |
| 524 we get line-based scrolling. */ | |
| 525 | |
| 526 vertical_drag_in_progress = 1; | |
| 527 | |
| 528 if (SCROLLBAR_X_VDRAG_ORIG_VALUE (instance) < 0) | |
| 529 { | |
| 530 SCROLLBAR_X_VDRAG_ORIG_VALUE (instance) = data->slider_value; | |
| 531 SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (instance) = | |
| 532 XINT (Fwindow_start (win)); | |
| 533 } | |
| 534 | |
| 535 /* Could replace this piecewise linear scrolling with a | |
| 536 quadratic through the three points, but I'm not sure that | |
| 537 would feel any nicer in practice. */ | |
| 538 if (data->slider_value < SCROLLBAR_X_VDRAG_ORIG_VALUE (instance)) | |
| 539 { | |
| 540 /* We've dragged up; slide linearly from original position to | |
| 541 window-start=data.minimum, slider-value=data.minimum. */ | |
| 542 | |
| 543 if (SCROLLBAR_X_VDRAG_ORIG_VALUE (instance) | |
| 544 <= SCROLLBAR_X_POS_DATA (instance).minimum) | |
| 545 { | |
| 546 /* shouldn't get here, but just in case */ | |
| 547 value = SCROLLBAR_X_POS_DATA (instance).minimum; | |
| 548 } | |
| 549 else | |
| 550 { | |
| 551 value = (int) | |
| 552 (SCROLLBAR_X_POS_DATA (instance).minimum | |
| 553 + (((double) | |
| 554 (SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (instance) | |
| 555 - SCROLLBAR_X_POS_DATA (instance).minimum) | |
| 556 * (data->slider_value - | |
| 557 SCROLLBAR_X_POS_DATA (instance).minimum)) | |
| 558 / (SCROLLBAR_X_VDRAG_ORIG_VALUE (instance) | |
| 559 - SCROLLBAR_X_POS_DATA (instance).minimum))); | |
| 560 } | |
| 561 } | |
| 562 else | |
| 563 { | |
| 564 /* We've dragged down; slide linearly from original position to | |
| 565 window-start=data.maximum, slider-value=data.maximum. */ | |
| 566 | |
| 567 if (SCROLLBAR_X_VDRAG_ORIG_VALUE (instance) | |
| 568 >= (SCROLLBAR_X_POS_DATA (instance).maximum - | |
| 569 SCROLLBAR_X_POS_DATA (instance).slider_size)) | |
| 570 { | |
| 571 /* avoid divide by zero */ | |
| 572 value = SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (instance); | |
| 573 } | |
| 574 else | |
| 575 { | |
| 576 value = (int) | |
| 577 (SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (instance) | |
| 578 + (((double) | |
| 579 (SCROLLBAR_X_POS_DATA (instance).maximum | |
| 580 - SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (instance)) | |
| 581 * (data->slider_value | |
| 582 - SCROLLBAR_X_VDRAG_ORIG_VALUE (instance))) | |
| 583 / (SCROLLBAR_X_POS_DATA (instance).maximum | |
| 584 - SCROLLBAR_X_POS_DATA (instance).slider_size | |
| 585 - SCROLLBAR_X_VDRAG_ORIG_VALUE (instance)))); | |
| 586 } | |
| 587 } | |
| 588 #else | |
| 589 stupid_vertical_scrollbar_drag_hack = 0; | |
| 590 value = data->slider_value; | |
| 591 #endif | |
| 592 | |
| 593 if (value >= SCROLLBAR_X_POS_DATA (instance).maximum) | |
| 594 value = SCROLLBAR_X_POS_DATA (instance).maximum - 1; | |
| 595 if (value < SCROLLBAR_X_POS_DATA (instance).minimum) | |
| 596 value = SCROLLBAR_X_POS_DATA (instance).minimum; | |
| 597 | |
| 598 signal_special_Xt_user_event (frame, Qscrollbar_vertical_drag, | |
| 599 Fcons (win, make_int (value))); | |
| 600 } | |
| 601 break; | |
| 602 | |
| 603 } | |
| 604 } | |
| 605 | |
| 606 /* | |
| 607 * This is the only callback provided for horizontal scrollbars. It | |
| 608 * should be able to handle all of the scrollbar events in | |
| 609 * scroll_action (see lwlib.h). The client data will be of type | |
| 610 * scroll_event (see lwlib.h). */ | |
| 611 static void | |
| 612 x_update_horizontal_scrollbar_callback (Widget widget, LWLIB_ID id, | |
| 613 XtPointer client_data) | |
| 614 { | |
| 615 scroll_event *data = (scroll_event *) client_data; | |
| 616 struct device *d = get_device_from_display (XtDisplay (widget)); | |
| 617 struct frame *f = x_any_window_to_frame (d, XtWindow (widget)); | |
| 618 Lisp_Object win, frame; | |
| 619 struct window_mirror *mirror; | |
| 620 | |
| 621 if (!f) | |
| 622 return; | |
| 623 | |
| 624 mirror = find_scrollbar_window_mirror (f, id); | |
| 442 | 625 if (!mirror) |
| 626 return; | |
| 627 | |
| 428 | 628 win = real_window (mirror, 1); |
| 629 | |
| 630 if (NILP (win)) | |
| 631 return; | |
| 632 frame = WINDOW_FRAME (XWINDOW (win)); | |
| 633 | |
| 634 /* It seems that this is necessary whenever signal_special_Xt_user_event() | |
| 635 is called. #### Why??? */ | |
| 636 DEVICE_X_MOUSE_TIMESTAMP (d) = DEVICE_X_GLOBAL_MOUSE_TIMESTAMP (d); | |
| 637 | |
| 638 switch (data->action) | |
| 639 { | |
| 640 case SCROLLBAR_LINE_UP: | |
| 641 signal_special_Xt_user_event (frame, Qscrollbar_char_left, win); | |
| 642 break; | |
| 643 case SCROLLBAR_LINE_DOWN: | |
| 644 signal_special_Xt_user_event (frame, Qscrollbar_char_right, win); | |
| 645 break; | |
| 646 case SCROLLBAR_PAGE_UP: | |
| 647 signal_special_Xt_user_event (frame, Qscrollbar_page_left, win); | |
| 648 break; | |
| 649 case SCROLLBAR_PAGE_DOWN: | |
| 650 signal_special_Xt_user_event (frame, Qscrollbar_page_right, win); | |
| 651 break; | |
| 652 case SCROLLBAR_TOP: | |
| 653 signal_special_Xt_user_event (frame, Qscrollbar_to_left, win); | |
| 654 break; | |
| 655 case SCROLLBAR_BOTTOM: | |
| 656 signal_special_Xt_user_event (frame, Qscrollbar_to_right, win); | |
| 657 break; | |
| 658 case SCROLLBAR_CHANGE: | |
| 659 inhibit_slider_size_change = 0; | |
| 660 break; | |
| 661 case SCROLLBAR_DRAG: | |
| 662 inhibit_slider_size_change = 1; | |
| 663 /* #### Fix the damn toolkit code so they all work the same way. | |
| 664 Lucid is the one mostly wrong.*/ | |
| 665 #if defined (LWLIB_SCROLLBARS_LUCID) || defined (LWLIB_SCROLLBARS_ATHENA3D) | |
| 666 signal_special_Xt_user_event (frame, Qscrollbar_horizontal_drag, | |
| 667 (Fcons | |
| 668 (win, make_int (data->slider_value)))); | |
| 669 #else | |
| 670 signal_special_Xt_user_event (frame, Qscrollbar_horizontal_drag, | |
| 671 (Fcons | |
| 672 (win, | |
| 673 make_int (data->slider_value - 1)))); | |
| 674 #endif | |
| 675 break; | |
| 676 default: | |
| 677 break; | |
| 678 } | |
| 679 } | |
| 680 | |
| 681 static void | |
| 682 x_scrollbar_pointer_changed_in_window (struct window *w) | |
| 683 { | |
| 793 | 684 Lisp_Object window = wrap_window (w); |
| 428 | 685 |
| 686 x_scrollbar_loop (X_SET_SCROLLBAR_POINTER, window, find_window_mirror (w), | |
| 687 0, (Window) NULL); | |
| 688 } | |
| 689 | |
| 690 /* Make sure that all scrollbars on frame are up-to-date. Called | |
| 691 directly from x_set_frame_properties in frame-x.c*/ | |
| 692 void | |
| 693 x_update_frame_scrollbars (struct frame *f) | |
| 694 { | |
| 617 | 695 x_scrollbar_loop (X_UPDATE_FRAME_SCROLLBARS, f->root_window, |
| 696 XWINDOW_MIRROR (f->root_mirror), 0, (Window) NULL); | |
| 428 | 697 } |
| 698 | |
| 699 #ifdef MEMORY_USAGE_STATS | |
| 700 | |
|
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5169
diff
changeset
|
701 static Bytecount |
| 2286 | 702 x_compute_scrollbar_instance_usage (struct device *UNUSED (d), |
| 428 | 703 struct scrollbar_instance *inst, |
|
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5050
diff
changeset
|
704 struct usage_stats *ustats) |
| 428 | 705 { |
|
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5169
diff
changeset
|
706 Bytecount total = 0; |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5169
diff
changeset
|
707 struct x_scrollbar_data *data = |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5169
diff
changeset
|
708 (struct x_scrollbar_data *) inst->scrollbar_data; |
| 428 | 709 |
|
5170
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5169
diff
changeset
|
710 total += malloced_storage_size (data, sizeof (*data), ustats); |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5169
diff
changeset
|
711 total += malloced_storage_size (data->name, 1 + strlen (data->name), |
|
5ddbab03b0e6
various fixes to memory-usage stats
Ben Wing <ben@xemacs.org>
parents:
5169
diff
changeset
|
712 ustats); |
| 428 | 713 |
| 714 return total; | |
| 715 } | |
| 716 | |
| 717 #endif /* MEMORY_USAGE_STATS */ | |
| 718 | |
| 719 | |
| 720 /************************************************************************/ | |
| 721 /* initialization */ | |
| 722 /************************************************************************/ | |
| 723 | |
| 724 void | |
| 725 console_type_create_scrollbar_x (void) | |
| 726 { | |
| 727 CONSOLE_HAS_METHOD (x, inhibit_scrollbar_slider_size_change); | |
| 728 CONSOLE_HAS_METHOD (x, free_scrollbar_instance); | |
| 729 CONSOLE_HAS_METHOD (x, release_scrollbar_instance); | |
| 730 CONSOLE_HAS_METHOD (x, create_scrollbar_instance); | |
| 731 CONSOLE_HAS_METHOD (x, update_scrollbar_instance_values); | |
| 732 CONSOLE_HAS_METHOD (x, update_scrollbar_instance_status); | |
| 733 CONSOLE_HAS_METHOD (x, scrollbar_pointer_changed_in_window); | |
| 734 #ifdef MEMORY_USAGE_STATS | |
| 735 CONSOLE_HAS_METHOD (x, compute_scrollbar_instance_usage); | |
| 736 #endif /* MEMORY_USAGE_STATS */ | |
| 737 } | |
| 738 | |
| 739 void | |
| 740 reinit_vars_of_scrollbar_x (void) | |
| 741 { | |
| 742 stupid_vertical_scrollbar_drag_hack = 1; | |
| 743 } | |
| 744 | |
| 745 void | |
| 746 vars_of_scrollbar_x (void) | |
| 747 { | |
| 748 #if defined (LWLIB_SCROLLBARS_LUCID) | |
| 749 Fprovide (intern ("lucid-scrollbars")); | |
| 750 #elif defined (LWLIB_SCROLLBARS_MOTIF) | |
| 751 Fprovide (intern ("motif-scrollbars")); | |
| 752 #elif defined (LWLIB_SCROLLBARS_ATHENA) | |
| 753 Fprovide (intern ("athena-scrollbars")); | |
| 754 #endif | |
| 755 } |
