Mercurial > hg > xemacs-beta
annotate src/scrollbar-x.c @ 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
-------------------- ChangeLog entries follow: --------------------
src/ChangeLog addition:
2010-03-24 Ben Wing <ben@xemacs.org>
* array.h:
* array.h (XD_LISP_DYNARR_DESC):
* dumper.c (pdump_register_sub):
* dumper.c (pdump_store_new_pointer_offsets):
* dumper.c (pdump_reloc_one_mc):
* elhash.c:
* gc.c (lispdesc_one_description_line_size):
* gc.c (kkcc_marking):
* lrecord.h:
* lrecord.h (IF_NEW_GC):
* lrecord.h (enum memory_description_type):
* lrecord.h (enum data_description_entry_flags):
* lrecord.h (struct opaque_convert_functions):
Rename XD_LISP_OBJECT_BLOCK_PTR to XD_INLINE_LISP_OBJECT_BLOCK_PTR
and document it in lrecord.h.
* data.c:
* data.c (finish_marking_weak_lists):
* data.c (continue_marking_ephemerons):
* data.c (finish_marking_ephemerons):
* elhash.c (MARK_OBJ):
* gc.c:
* gc.c (lispdesc_indirect_count_1):
* gc.c (struct):
* gc.c (kkcc_bt_push):
* gc.c (kkcc_gc_stack_push):
* gc.c (kkcc_gc_stack_push_lisp_object):
* gc.c (kkcc_gc_stack_repush_dirty_object):
* gc.c (KKCC_DO_CHECK_FREE):
* gc.c (mark_object_maybe_checking_free):
* gc.c (mark_struct_contents):
* gc.c (mark_lisp_object_block_contents):
* gc.c (register_for_finalization):
* gc.c (mark_object):
* gc.h:
* lisp.h:
* profile.c:
* profile.c (mark_profiling_info_maphash):
Clean up KKCC code related to DEBUG_XEMACS. Rename
kkcc_backtrace() to kkcc_backtrace_1() and add two params: a
`size' arg to control how many stack elements to print and a
`detailed' arg to control whether Lisp objects are printed using
`debug_print()'. Create front-ends to kkcc_backtrace_1() --
kkcc_detailed_backtrace(), kkcc_short_backtrace(),
kkcc_detailed_backtrace_full(), kkcc_short_backtrace_full(), as
well as shortened versions kbt(), kbts(), kbtf(), kbtsf() -- to
call it with various parameter values. Add an `is_lisp' field to
the stack and backtrace structures and use it to keep track of
whether an object pushed onto the stack is a Lisp object or a
non-Lisp structure; in kkcc_backtrace_1(), don't try to print a
non-Lisp structure as a Lisp object.
* elhash.c:
* extents.c:
* file-coding.c:
* lrecord.h:
* lrecord.h (IF_NEW_GC):
* marker.c:
* marker.c (Fmarker_buffer):
* mule-coding.c:
* number.c:
* rangetab.c:
* specifier.c:
New macros IF_OLD_GC(), IF_NEW_GC() to simplify declaration of
Lisp objects when a finalizer may exist in one but not the other.
Use them appropriately.
* extents.c (finalize_extent_info):
Don't zero out data->soe and data->extents before trying to free,
else we get memory leaks.
* lrecord.h (enum lrecord_type):
Make the first lrecord type have value 1 not 0 so that 0 remains
without implementation and attempts to interpret zeroed memory
as a Lisp object will be more obvious.
* array.c (Dynarr_free):
* device-msw.c (msprinter_delete_device):
* device-tty.c (free_tty_device_struct):
* device-tty.c (tty_delete_device):
* dialog-msw.c (handle_directory_dialog_box):
* dialog-x.c:
* emacs.c (free_argc_argv):
* emodules.c (attempt_module_delete):
* file-coding.c (chain_finalize_coding_stream_1):
* file-coding.c (chain_finalize_coding_stream):
* glyphs-eimage.c:
* glyphs-eimage.c (jpeg_instantiate_unwind):
* glyphs-eimage.c (gif_instantiate_unwind):
* glyphs-eimage.c (png_instantiate_unwind):
* glyphs-eimage.c (tiff_instantiate_unwind):
* imgproc.c:
* imgproc.c (build_EImage_quantable):
* insdel.c (uninit_buffer_text):
* mule-coding.c (iso2022_finalize_detection_state):
* objects-tty.c (tty_finalize_color_instance):
* objects-tty.c (tty_finalize_font_instance):
* objects-tty.c (tty_font_list):
* process.c:
* process.c (finalize_process):
* redisplay.c (add_propagation_runes):
* scrollbar-gtk.c:
* scrollbar-gtk.c (gtk_free_scrollbar_instance):
* scrollbar-gtk.c (gtk_release_scrollbar_instance):
* scrollbar-msw.c:
* scrollbar-msw.c (mswindows_free_scrollbar_instance):
* scrollbar-msw.c (unshow_that_mofo):
* scrollbar-x.c (x_free_scrollbar_instance):
* scrollbar-x.c (x_release_scrollbar_instance):
* select-x.c:
* select-x.c (x_handle_selection_request):
* syntax.c:
* syntax.c (uninit_buffer_syntax_cache):
* text.h (eifree):
If possible, whenever we call xfree() on a field in a structure,
set the field to 0 afterwards. A lot of code is written so that
it checks the value being freed to see if it is non-zero before
freeing it -- doing this and setting the value to 0 afterwards
ensures (a) we won't try to free twice if the cleanup code is
called twice; (b) if the object itself stays around, KKCC won't
crash when attempting to mark the freed field.
* rangetab.c:
Add a finalization method when not NEW_GC to avoid memory leaks.
(#### We still get memory leaks when NEW_GC; need to convert gap
array to Lisp object).
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Wed, 24 Mar 2010 01:22:51 -0500 |
parents | 1fae11d56ad2 |
children | 5ddbab03b0e6 |
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 | |
701 static int | |
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 { |
706 int total = 0; | |
707 | |
708 while (inst) | |
709 { | |
710 struct x_scrollbar_data *data = | |
711 (struct x_scrollbar_data *) inst->scrollbar_data; | |
712 | |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5050
diff
changeset
|
713 total += malloced_storage_size (data, sizeof (*data), ustats); |
3024 | 714 total += malloced_storage_size (data->name, 1 + strlen (data->name), |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5050
diff
changeset
|
715 ustats); |
428 | 716 inst = inst->next; |
717 } | |
718 | |
719 return total; | |
720 } | |
721 | |
722 #endif /* MEMORY_USAGE_STATS */ | |
723 | |
724 | |
725 /************************************************************************/ | |
726 /* initialization */ | |
727 /************************************************************************/ | |
728 | |
729 void | |
730 console_type_create_scrollbar_x (void) | |
731 { | |
732 CONSOLE_HAS_METHOD (x, inhibit_scrollbar_slider_size_change); | |
733 CONSOLE_HAS_METHOD (x, free_scrollbar_instance); | |
734 CONSOLE_HAS_METHOD (x, release_scrollbar_instance); | |
735 CONSOLE_HAS_METHOD (x, create_scrollbar_instance); | |
736 CONSOLE_HAS_METHOD (x, update_scrollbar_instance_values); | |
737 CONSOLE_HAS_METHOD (x, update_scrollbar_instance_status); | |
738 CONSOLE_HAS_METHOD (x, scrollbar_pointer_changed_in_window); | |
739 #ifdef MEMORY_USAGE_STATS | |
740 CONSOLE_HAS_METHOD (x, compute_scrollbar_instance_usage); | |
741 #endif /* MEMORY_USAGE_STATS */ | |
742 } | |
743 | |
744 void | |
745 reinit_vars_of_scrollbar_x (void) | |
746 { | |
747 stupid_vertical_scrollbar_drag_hack = 1; | |
748 } | |
749 | |
750 void | |
751 vars_of_scrollbar_x (void) | |
752 { | |
753 #if defined (LWLIB_SCROLLBARS_LUCID) | |
754 Fprovide (intern ("lucid-scrollbars")); | |
755 #elif defined (LWLIB_SCROLLBARS_MOTIF) | |
756 Fprovide (intern ("motif-scrollbars")); | |
757 #elif defined (LWLIB_SCROLLBARS_ATHENA) | |
758 Fprovide (intern ("athena-scrollbars")); | |
759 #endif | |
760 } |