428
|
1 /* scrollbar implementation -- mswindows 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>.
|
|
6
|
|
7 This file is part of XEmacs.
|
|
8
|
|
9 XEmacs is free software; you can redistribute it and/or modify it
|
|
10 under the terms of the GNU General Public License as published by the
|
|
11 Free Software Foundation; either version 2, or (at your option) any
|
|
12 later version.
|
|
13
|
|
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
17 for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with XEmacs; see the file COPYING. If not, write to
|
|
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 Boston, MA 02111-1307, USA. */
|
|
23
|
|
24 /* Synched up with: Not in FSF. */
|
|
25
|
|
26 #include <config.h>
|
|
27 #include "lisp.h"
|
|
28
|
|
29 #include "console-msw.h"
|
|
30 #include "events.h"
|
|
31 #include "frame.h"
|
|
32 #include "scrollbar-msw.h"
|
|
33 #include "scrollbar.h"
|
|
34 #include "specifier.h"
|
|
35 #include "window.h"
|
|
36
|
|
37 /* We use a similar sort of vertical scrollbar drag hack for mswindows
|
|
38 * scrollbars as is used for Motif or Lucid scrollbars under X.
|
|
39 * We do character-based instead of line-based scrolling, which can mean that
|
|
40 * without the hack it is impossible to drag to the end of a buffer. */
|
|
41 #define VERTICAL_SCROLLBAR_DRAG_HACK
|
|
42
|
|
43 static int vertical_drag_in_progress = 0;
|
|
44
|
|
45 static void
|
|
46 mswindows_create_scrollbar_instance (struct frame *f, int vertical,
|
|
47 struct scrollbar_instance *sb)
|
|
48 {
|
|
49 int orientation;
|
442
|
50
|
428
|
51 sb->scrollbar_data = xnew_and_zero (struct mswindows_scrollbar_data);
|
442
|
52
|
428
|
53 if (vertical)
|
|
54 orientation = SBS_VERT;
|
|
55 else
|
|
56 orientation = SBS_HORZ;
|
442
|
57
|
428
|
58 SCROLLBAR_MSW_HANDLE (sb) =
|
546
|
59 CreateWindowEx (0, "SCROLLBAR", 0, orientation|WS_CHILD,
|
|
60 CW_USEDEFAULT, CW_USEDEFAULT,
|
|
61 CW_USEDEFAULT, CW_USEDEFAULT,
|
|
62 FRAME_MSWINDOWS_HANDLE (f),
|
|
63 NULL, NULL, NULL);
|
|
64 SCROLLBAR_MSW_INFO (sb).cbSize = sizeof (SCROLLINFO);
|
428
|
65 SCROLLBAR_MSW_INFO (sb).fMask = SIF_ALL;
|
|
66 GetScrollInfo(SCROLLBAR_MSW_HANDLE (sb), SB_CTL,
|
|
67 &SCROLLBAR_MSW_INFO (sb));
|
546
|
68 SetWindowLong (SCROLLBAR_MSW_HANDLE (sb), GWL_USERDATA, (LONG) sb);
|
428
|
69
|
|
70 #if 0
|
|
71 {
|
546
|
72 HWND h = SCROLLBAR_MSW_HANDLE (sb);
|
|
73 int x = SetWindowLong (SCROLLBAR_MSW_HANDLE(sb), GWL_USERDATA, (LONG)sb);
|
|
74 int y = GetLastError();
|
|
75 struct scrollbar_instance *z =
|
|
76 (struct scrollbar_instance *)GetWindowLong (SCROLLBAR_MSW_HANDLE(sb),
|
|
77 GWL_USERDATA);
|
|
78 *z = *z;
|
428
|
79 }
|
|
80 #endif
|
|
81 }
|
|
82
|
|
83 static void
|
|
84 mswindows_free_scrollbar_instance (struct scrollbar_instance *sb)
|
|
85 {
|
|
86 DestroyWindow (SCROLLBAR_MSW_HANDLE (sb));
|
442
|
87 if (sb->scrollbar_data)
|
428
|
88 xfree (sb->scrollbar_data);
|
|
89 }
|
|
90
|
|
91 static void
|
611
|
92 unshow_that_mofo (void *handle)
|
|
93 {
|
|
94 ShowScrollBar ((HWND) handle, SB_CTL, 0);
|
|
95 }
|
|
96
|
|
97 static void
|
428
|
98 mswindows_release_scrollbar_instance (struct scrollbar_instance *sb)
|
|
99 {
|
611
|
100 if (gc_in_progress)
|
|
101 /* #### way bogus! need to remove the offending call.
|
|
102 see mark_redisplay(). */
|
|
103 register_post_gc_action (unshow_that_mofo,
|
|
104 (void *) SCROLLBAR_MSW_HANDLE (sb));
|
|
105 else
|
|
106 ShowScrollBar (SCROLLBAR_MSW_HANDLE (sb), SB_CTL, 0);
|
428
|
107 SCROLLBAR_MSW_SIZE (sb) = 0;
|
|
108 }
|
|
109
|
|
110 #define UPDATE_POS_FIELD(field) \
|
|
111 if (new_##field >= 0 && SCROLLBAR_MSW_DATA (sb)->field != new_##field) { \
|
|
112 SCROLLBAR_MSW_DATA (sb)->field = new_##field; \
|
|
113 pos_changed = 1; \
|
|
114 }
|
|
115
|
|
116 static void
|
|
117 mswindows_update_scrollbar_instance_values (struct window *w,
|
|
118 struct scrollbar_instance *sb,
|
|
119 int new_line_increment,
|
|
120 int new_page_increment,
|
|
121 int new_minimum, int new_maximum,
|
|
122 int new_slider_size,
|
|
123 int new_slider_position,
|
|
124 int new_scrollbar_width,
|
|
125 int new_scrollbar_height,
|
|
126 int new_scrollbar_x,
|
|
127 int new_scrollbar_y)
|
|
128 {
|
|
129 int pos_changed = 0;
|
|
130 int vert = GetWindowLong (SCROLLBAR_MSW_HANDLE (sb), GWL_STYLE) & SBS_VERT;
|
|
131
|
|
132 #if 0
|
|
133 stderr_out ("[%d, %d], page = %d, pos = %d, inhibit = %d\n", new_minimum, new_maximum,
|
|
134 new_slider_size, new_slider_position,inhibit_slider_size_change);
|
|
135 #endif
|
|
136
|
|
137 /* These might be optimized, but since at least one will change at each
|
|
138 call, it's probably not worth it. */
|
|
139 SCROLLBAR_MSW_INFO (sb).nMin = new_minimum;
|
|
140 SCROLLBAR_MSW_INFO (sb).nMax = new_maximum;
|
|
141 SCROLLBAR_MSW_INFO (sb).nPage = new_slider_size + 1; /* +1 for DISABLENOSCROLL */
|
|
142 SCROLLBAR_MSW_INFO (sb).nPos = new_slider_position;
|
|
143 #ifndef VERTICAL_SCROLLBAR_DRAG_HACK
|
|
144 SCROLLBAR_MSW_INFO (sb).fMask = ((vert && vertical_drag_in_progress)
|
|
145 ? SIF_RANGE | SIF_POS
|
|
146 : SIF_ALL | SIF_DISABLENOSCROLL);
|
|
147 #else
|
|
148 SCROLLBAR_MSW_INFO (sb).fMask = SIF_ALL | SIF_DISABLENOSCROLL;
|
|
149
|
|
150 /* Ignore XEmacs' requests to update the thumb position and size; they don't
|
|
151 * bear any relation to reality because we're reporting made-up positions */
|
|
152 if (!(vert && vertical_drag_in_progress))
|
|
153 #endif
|
|
154 SetScrollInfo (SCROLLBAR_MSW_HANDLE (sb), SB_CTL, &SCROLLBAR_MSW_INFO (sb),
|
|
155 TRUE);
|
|
156
|
|
157 UPDATE_POS_FIELD (scrollbar_x);
|
|
158 UPDATE_POS_FIELD (scrollbar_y);
|
|
159 UPDATE_POS_FIELD (scrollbar_width);
|
|
160 UPDATE_POS_FIELD (scrollbar_height);
|
|
161
|
442
|
162 if (pos_changed)
|
428
|
163 {
|
|
164 MoveWindow(SCROLLBAR_MSW_HANDLE (sb),
|
|
165 new_scrollbar_x, new_scrollbar_y,
|
|
166 new_scrollbar_width, new_scrollbar_height,
|
|
167 TRUE);
|
|
168 }
|
|
169 }
|
|
170
|
|
171 static void
|
|
172 mswindows_update_scrollbar_instance_status (struct window *w,
|
|
173 int active, int size,
|
|
174 struct scrollbar_instance *sb)
|
|
175 {
|
|
176 if (SCROLLBAR_MSW_SIZE (sb) != size)
|
|
177 {
|
|
178 SCROLLBAR_MSW_SIZE (sb) = size;
|
|
179 ShowScrollBar (SCROLLBAR_MSW_HANDLE (sb), SB_CTL,
|
|
180 SCROLLBAR_MSW_SIZE (sb));
|
|
181 SCROLLBAR_MSW_INFO(sb).fMask |= SIF_DISABLENOSCROLL;
|
|
182 SetScrollInfo(SCROLLBAR_MSW_HANDLE (sb), SB_CTL, &SCROLLBAR_MSW_INFO (sb), TRUE);
|
|
183 }
|
|
184 }
|
|
185
|
|
186 void
|
|
187 mswindows_handle_scrollbar_event (HWND hwnd, int code, int pos)
|
|
188 {
|
|
189 struct frame *f;
|
|
190 Lisp_Object win, frame;
|
|
191 struct scrollbar_instance *sb;
|
|
192 SCROLLINFO scrollinfo;
|
|
193 int vert = GetWindowLong (hwnd, GWL_STYLE) & SBS_VERT;
|
|
194 int value;
|
|
195
|
546
|
196 sb = (struct scrollbar_instance *) GetWindowLong (hwnd, GWL_USERDATA);
|
|
197 if (!sb)
|
|
198 {
|
|
199 frame = mswindows_find_frame (hwnd);
|
|
200 f = XFRAME (frame);
|
|
201 win = FRAME_SELECTED_WINDOW (f);
|
|
202 }
|
|
203 else
|
|
204 {
|
|
205 win = real_window (sb->mirror, 0);
|
|
206 frame = XWINDOW (win)->frame;
|
|
207 f = XFRAME (frame);
|
|
208 }
|
428
|
209
|
|
210 /* SB_LINEDOWN == SB_CHARLEFT etc. This is the way they will
|
442
|
211 always be - any Windows is binary compatible backward with
|
428
|
212 old programs */
|
|
213
|
|
214 switch (code)
|
|
215 {
|
|
216 case SB_LINEDOWN:
|
|
217 mswindows_enqueue_misc_user_event
|
|
218 (frame, vert ? Qscrollbar_line_down : Qscrollbar_char_right, win);
|
|
219 break;
|
442
|
220
|
428
|
221 case SB_LINEUP:
|
|
222 mswindows_enqueue_misc_user_event
|
|
223 (frame, vert ? Qscrollbar_line_up : Qscrollbar_char_left, win);
|
|
224 break;
|
442
|
225
|
428
|
226 case SB_PAGEDOWN:
|
|
227 mswindows_enqueue_misc_user_event
|
|
228 (win, vert ? Qscrollbar_page_down : Qscrollbar_page_right,
|
|
229 vert ? Fcons (win, Qnil) : win);
|
|
230 break;
|
|
231
|
|
232 case SB_PAGEUP:
|
|
233 mswindows_enqueue_misc_user_event
|
|
234 (frame,
|
|
235 vert ? Qscrollbar_page_up : Qscrollbar_page_left,
|
|
236 vert ? Fcons (win, Qnil) : win);
|
|
237 break;
|
442
|
238
|
428
|
239 case SB_BOTTOM:
|
|
240 mswindows_enqueue_misc_user_event
|
|
241 (frame, vert ? Qscrollbar_to_bottom : Qscrollbar_to_right, win);
|
|
242 break;
|
|
243
|
|
244 case SB_TOP:
|
|
245 mswindows_enqueue_misc_user_event
|
|
246 (frame, vert ? Qscrollbar_to_top : Qscrollbar_to_left, win);
|
|
247 break;
|
|
248
|
|
249 case SB_THUMBTRACK:
|
|
250 case SB_THUMBPOSITION:
|
|
251 scrollinfo.cbSize = sizeof(SCROLLINFO);
|
|
252 scrollinfo.fMask = SIF_ALL;
|
|
253 GetScrollInfo (hwnd, SB_CTL, &scrollinfo);
|
|
254 vertical_drag_in_progress = vert;
|
|
255 #ifdef VERTICAL_SCROLLBAR_DRAG_HACK
|
|
256 if (vert && (scrollinfo.nTrackPos > scrollinfo.nPos))
|
|
257 /* new buffer position =
|
|
258 * buffer position at start of drag +
|
|
259 * ((text remaining in buffer at start of drag) *
|
|
260 * (amount that the thumb has been moved) /
|
|
261 * (space that remained past end of the thumb at start of drag)) */
|
|
262 value = (int)
|
|
263 (scrollinfo.nPos
|
|
264 + (((double)
|
|
265 (scrollinfo.nMax - scrollinfo.nPos)
|
|
266 * (scrollinfo.nTrackPos - scrollinfo.nPos))
|
|
267 / (scrollinfo.nMax - scrollinfo.nPage - scrollinfo.nPos)))
|
|
268 - 2; /* ensure that the last line doesn't disappear off screen */
|
|
269 else
|
|
270 #endif
|
|
271 value = scrollinfo.nTrackPos;
|
|
272 mswindows_enqueue_misc_user_event
|
|
273 (frame,
|
|
274 vert ? Qscrollbar_vertical_drag : Qscrollbar_horizontal_drag,
|
|
275 Fcons (win, make_int (value)));
|
|
276 break;
|
|
277
|
|
278 case SB_ENDSCROLL:
|
|
279 #ifdef VERTICAL_SCROLLBAR_DRAG_HACK
|
546
|
280 if (vertical_drag_in_progress && sb)
|
428
|
281 /* User has just dropped the thumb - finally update it */
|
|
282 SetScrollInfo (SCROLLBAR_MSW_HANDLE (sb), SB_CTL,
|
|
283 &SCROLLBAR_MSW_INFO (sb), TRUE);
|
|
284 #endif
|
|
285 vertical_drag_in_progress = 0;
|
|
286 break;
|
|
287 }
|
|
288 }
|
|
289
|
|
290 static int
|
464
|
291 can_scroll (struct scrollbar_instance* scrollbar)
|
428
|
292 {
|
|
293 return scrollbar != NULL
|
|
294 && IsWindowVisible (SCROLLBAR_MSW_HANDLE (scrollbar))
|
|
295 && IsWindowEnabled (SCROLLBAR_MSW_HANDLE (scrollbar));
|
|
296 }
|
|
297
|
|
298 int
|
464
|
299 mswindows_handle_mousewheel_event (Lisp_Object frame, int keys, int delta,
|
|
300 POINTS where)
|
428
|
301 {
|
442
|
302 int hasVertBar, hasHorzBar; /* Indicates presence of scroll bars */
|
428
|
303 unsigned wheelScrollLines = 0; /* Number of lines per wheel notch */
|
464
|
304 Lisp_Object win;
|
|
305 struct window_mirror *mirror;
|
|
306 POINT donde_esta;
|
428
|
307
|
464
|
308 donde_esta.x = where.x;
|
|
309 donde_esta.y = where.y;
|
|
310
|
|
311 ScreenToClient (FRAME_MSWINDOWS_HANDLE (XFRAME (frame)), &donde_esta);
|
|
312
|
|
313 /* Find the window to scroll */
|
|
314 {
|
|
315 int mene, _mene, tekel, upharsin;
|
|
316 Bufpos mens, sana;
|
|
317 Charcount in;
|
|
318 Lisp_Object corpore, sano;
|
|
319 struct window *needle_in_haystack;
|
|
320
|
|
321 pixel_to_glyph_translation (XFRAME (frame), donde_esta.x, donde_esta.y,
|
|
322 &mene, &_mene, &tekel, &upharsin,
|
|
323 &needle_in_haystack,
|
|
324 &mens, &sana, &in, &corpore, &sano);
|
|
325
|
|
326 if (needle_in_haystack)
|
|
327 {
|
|
328 XSETWINDOW (win, needle_in_haystack);
|
|
329 }
|
|
330 else
|
|
331 {
|
|
332 win = FRAME_SELECTED_WINDOW (XFRAME (frame));
|
|
333 needle_in_haystack = XWINDOW (win);
|
|
334 }
|
|
335
|
|
336 mirror = find_window_mirror (needle_in_haystack);
|
|
337 }
|
428
|
338
|
|
339 /* Check that there is something to scroll */
|
|
340 hasVertBar = can_scroll (mirror->scrollbar_vertical_instance);
|
|
341 hasHorzBar = can_scroll (mirror->scrollbar_horizontal_instance);
|
|
342 if (!hasVertBar && !hasHorzBar)
|
|
343 return FALSE;
|
|
344
|
|
345 /* No support for panning and zooming, so ignore */
|
|
346 if (keys & (MK_SHIFT | MK_CONTROL))
|
|
347 return FALSE;
|
|
348
|
|
349 /* Get the number of lines per wheel delta */
|
|
350 SystemParametersInfo (SPI_GETWHEELSCROLLLINES, 0, &wheelScrollLines, 0);
|
|
351
|
|
352 /* Calculate the amount to scroll */
|
|
353 if (wheelScrollLines == WHEEL_PAGESCROLL)
|
|
354 {
|
|
355 /* Scroll by a page */
|
|
356 Lisp_Object function;
|
|
357 if (hasVertBar)
|
|
358 function = delta > 0 ? Qscrollbar_page_up : Qscrollbar_page_down;
|
|
359 else
|
|
360 function = delta > 0 ? Qscrollbar_page_left : Qscrollbar_page_right;
|
|
361 mswindows_enqueue_misc_user_event (frame, function, Fcons (win, Qnil));
|
|
362 }
|
|
363 else /* Scroll by a number of lines */
|
|
364 {
|
|
365 /* Calc the number of lines to scroll */
|
|
366 int toScroll = MulDiv (delta, wheelScrollLines, WHEEL_DELTA);
|
|
367
|
|
368 /* Do the scroll */
|
|
369 Lisp_Object function;
|
|
370 if (hasVertBar)
|
|
371 function = delta > 0 ? Qscrollbar_line_up : Qscrollbar_line_down;
|
|
372 else
|
|
373 function = delta > 0 ? Qscrollbar_char_left : Qscrollbar_char_right;
|
|
374 if (toScroll < 0)
|
|
375 toScroll = -toScroll;
|
|
376 while (toScroll--)
|
|
377 mswindows_enqueue_misc_user_event (frame, function, win);
|
|
378 }
|
|
379
|
|
380 return TRUE;
|
|
381 }
|
|
382
|
|
383 #ifdef MEMORY_USAGE_STATS
|
|
384
|
|
385 static int
|
|
386 mswindows_compute_scrollbar_instance_usage (struct device *d,
|
|
387 struct scrollbar_instance *inst,
|
|
388 struct overhead_stats *ovstats)
|
|
389 {
|
|
390 int total = 0;
|
|
391
|
|
392 while (inst)
|
|
393 {
|
|
394 struct mswindows_scrollbar_data *data =
|
|
395 (struct mswindows_scrollbar_data *) inst->scrollbar_data;
|
|
396
|
|
397 total += malloced_storage_size (data, sizeof (*data), ovstats);
|
|
398 inst = inst->next;
|
|
399 }
|
|
400
|
|
401 return total;
|
|
402 }
|
|
403
|
|
404 #endif /* MEMORY_USAGE_STATS */
|
|
405
|
|
406 /************************************************************************/
|
|
407 /* Device-specific ghost specifiers initialization */
|
|
408 /************************************************************************/
|
|
409
|
|
410 DEFUN ("mswindows-init-scrollbar-metrics", Fmswindows_init_scrollbar_metrics, 1, 1, 0, /*
|
|
411 */
|
|
412 (locale))
|
|
413 {
|
|
414 if (DEVICEP (locale))
|
|
415 {
|
|
416 add_spec_to_ghost_specifier (Vscrollbar_width,
|
|
417 make_int (GetSystemMetrics (SM_CXVSCROLL)),
|
|
418 locale, Qmswindows, Qnil);
|
|
419 add_spec_to_ghost_specifier (Vscrollbar_height,
|
|
420 make_int (GetSystemMetrics (SM_CYHSCROLL)),
|
|
421 locale, Qmswindows, Qnil);
|
|
422 }
|
|
423 return Qnil;
|
|
424 }
|
|
425
|
|
426
|
|
427 /************************************************************************/
|
|
428 /* initialization */
|
|
429 /************************************************************************/
|
|
430
|
|
431 void
|
|
432 console_type_create_scrollbar_mswindows (void)
|
|
433 {
|
|
434 CONSOLE_HAS_METHOD (mswindows, create_scrollbar_instance);
|
|
435 CONSOLE_HAS_METHOD (mswindows, free_scrollbar_instance);
|
|
436 CONSOLE_HAS_METHOD (mswindows, release_scrollbar_instance);
|
|
437 CONSOLE_HAS_METHOD (mswindows, update_scrollbar_instance_values);
|
|
438 CONSOLE_HAS_METHOD (mswindows, update_scrollbar_instance_status);
|
|
439 /* CONSOLE_HAS_METHOD (mswindows, scrollbar_width_changed_in_frame); */
|
|
440 #ifdef MEMORY_USAGE_STATS
|
|
441 CONSOLE_HAS_METHOD (mswindows, compute_scrollbar_instance_usage);
|
|
442 #endif
|
|
443 }
|
|
444
|
|
445 void
|
|
446 syms_of_scrollbar_mswindows(void)
|
|
447 {
|
|
448 DEFSUBR (Fmswindows_init_scrollbar_metrics);
|
|
449 }
|
|
450
|
|
451 void
|
|
452 vars_of_scrollbar_mswindows(void)
|
|
453 {
|
|
454 Fprovide (intern ("mswindows-scrollbars"));
|
|
455 }
|
|
456
|