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
|
|
92 mswindows_release_scrollbar_instance (struct scrollbar_instance *sb)
|
|
93 {
|
|
94 ShowScrollBar (SCROLLBAR_MSW_HANDLE (sb), SB_CTL, 0);
|
|
95 SCROLLBAR_MSW_SIZE (sb) = 0;
|
|
96 }
|
|
97
|
|
98 #define UPDATE_POS_FIELD(field) \
|
|
99 if (new_##field >= 0 && SCROLLBAR_MSW_DATA (sb)->field != new_##field) { \
|
|
100 SCROLLBAR_MSW_DATA (sb)->field = new_##field; \
|
|
101 pos_changed = 1; \
|
|
102 }
|
|
103
|
|
104 static void
|
|
105 mswindows_update_scrollbar_instance_values (struct window *w,
|
|
106 struct scrollbar_instance *sb,
|
|
107 int new_line_increment,
|
|
108 int new_page_increment,
|
|
109 int new_minimum, int new_maximum,
|
|
110 int new_slider_size,
|
|
111 int new_slider_position,
|
|
112 int new_scrollbar_width,
|
|
113 int new_scrollbar_height,
|
|
114 int new_scrollbar_x,
|
|
115 int new_scrollbar_y)
|
|
116 {
|
|
117 int pos_changed = 0;
|
|
118 int vert = GetWindowLong (SCROLLBAR_MSW_HANDLE (sb), GWL_STYLE) & SBS_VERT;
|
|
119
|
|
120 #if 0
|
|
121 stderr_out ("[%d, %d], page = %d, pos = %d, inhibit = %d\n", new_minimum, new_maximum,
|
|
122 new_slider_size, new_slider_position,inhibit_slider_size_change);
|
|
123 #endif
|
|
124
|
|
125 /* These might be optimized, but since at least one will change at each
|
|
126 call, it's probably not worth it. */
|
|
127 SCROLLBAR_MSW_INFO (sb).nMin = new_minimum;
|
|
128 SCROLLBAR_MSW_INFO (sb).nMax = new_maximum;
|
|
129 SCROLLBAR_MSW_INFO (sb).nPage = new_slider_size + 1; /* +1 for DISABLENOSCROLL */
|
|
130 SCROLLBAR_MSW_INFO (sb).nPos = new_slider_position;
|
|
131 #ifndef VERTICAL_SCROLLBAR_DRAG_HACK
|
|
132 SCROLLBAR_MSW_INFO (sb).fMask = ((vert && vertical_drag_in_progress)
|
|
133 ? SIF_RANGE | SIF_POS
|
|
134 : SIF_ALL | SIF_DISABLENOSCROLL);
|
|
135 #else
|
|
136 SCROLLBAR_MSW_INFO (sb).fMask = SIF_ALL | SIF_DISABLENOSCROLL;
|
|
137
|
|
138 /* Ignore XEmacs' requests to update the thumb position and size; they don't
|
|
139 * bear any relation to reality because we're reporting made-up positions */
|
|
140 if (!(vert && vertical_drag_in_progress))
|
|
141 #endif
|
|
142 SetScrollInfo (SCROLLBAR_MSW_HANDLE (sb), SB_CTL, &SCROLLBAR_MSW_INFO (sb),
|
|
143 TRUE);
|
|
144
|
|
145 UPDATE_POS_FIELD (scrollbar_x);
|
|
146 UPDATE_POS_FIELD (scrollbar_y);
|
|
147 UPDATE_POS_FIELD (scrollbar_width);
|
|
148 UPDATE_POS_FIELD (scrollbar_height);
|
|
149
|
442
|
150 if (pos_changed)
|
428
|
151 {
|
|
152 MoveWindow(SCROLLBAR_MSW_HANDLE (sb),
|
|
153 new_scrollbar_x, new_scrollbar_y,
|
|
154 new_scrollbar_width, new_scrollbar_height,
|
|
155 TRUE);
|
|
156 }
|
|
157 }
|
|
158
|
|
159 static void
|
|
160 mswindows_update_scrollbar_instance_status (struct window *w,
|
|
161 int active, int size,
|
|
162 struct scrollbar_instance *sb)
|
|
163 {
|
|
164 if (SCROLLBAR_MSW_SIZE (sb) != size)
|
|
165 {
|
|
166 SCROLLBAR_MSW_SIZE (sb) = size;
|
|
167 ShowScrollBar (SCROLLBAR_MSW_HANDLE (sb), SB_CTL,
|
|
168 SCROLLBAR_MSW_SIZE (sb));
|
|
169 SCROLLBAR_MSW_INFO(sb).fMask |= SIF_DISABLENOSCROLL;
|
|
170 SetScrollInfo(SCROLLBAR_MSW_HANDLE (sb), SB_CTL, &SCROLLBAR_MSW_INFO (sb), TRUE);
|
|
171 }
|
|
172 }
|
|
173
|
|
174 void
|
|
175 mswindows_handle_scrollbar_event (HWND hwnd, int code, int pos)
|
|
176 {
|
|
177 struct frame *f;
|
|
178 Lisp_Object win, frame;
|
|
179 struct scrollbar_instance *sb;
|
|
180 SCROLLINFO scrollinfo;
|
|
181 int vert = GetWindowLong (hwnd, GWL_STYLE) & SBS_VERT;
|
|
182 int value;
|
|
183
|
546
|
184 sb = (struct scrollbar_instance *) GetWindowLong (hwnd, GWL_USERDATA);
|
|
185 if (!sb)
|
|
186 {
|
|
187 frame = mswindows_find_frame (hwnd);
|
|
188 f = XFRAME (frame);
|
|
189 win = FRAME_SELECTED_WINDOW (f);
|
|
190 }
|
|
191 else
|
|
192 {
|
|
193 win = real_window (sb->mirror, 0);
|
|
194 frame = XWINDOW (win)->frame;
|
|
195 f = XFRAME (frame);
|
|
196 }
|
428
|
197
|
|
198 /* SB_LINEDOWN == SB_CHARLEFT etc. This is the way they will
|
442
|
199 always be - any Windows is binary compatible backward with
|
428
|
200 old programs */
|
|
201
|
|
202 switch (code)
|
|
203 {
|
|
204 case SB_LINEDOWN:
|
|
205 mswindows_enqueue_misc_user_event
|
|
206 (frame, vert ? Qscrollbar_line_down : Qscrollbar_char_right, win);
|
|
207 break;
|
442
|
208
|
428
|
209 case SB_LINEUP:
|
|
210 mswindows_enqueue_misc_user_event
|
|
211 (frame, vert ? Qscrollbar_line_up : Qscrollbar_char_left, win);
|
|
212 break;
|
442
|
213
|
428
|
214 case SB_PAGEDOWN:
|
|
215 mswindows_enqueue_misc_user_event
|
|
216 (win, vert ? Qscrollbar_page_down : Qscrollbar_page_right,
|
|
217 vert ? Fcons (win, Qnil) : win);
|
|
218 break;
|
|
219
|
|
220 case SB_PAGEUP:
|
|
221 mswindows_enqueue_misc_user_event
|
|
222 (frame,
|
|
223 vert ? Qscrollbar_page_up : Qscrollbar_page_left,
|
|
224 vert ? Fcons (win, Qnil) : win);
|
|
225 break;
|
442
|
226
|
428
|
227 case SB_BOTTOM:
|
|
228 mswindows_enqueue_misc_user_event
|
|
229 (frame, vert ? Qscrollbar_to_bottom : Qscrollbar_to_right, win);
|
|
230 break;
|
|
231
|
|
232 case SB_TOP:
|
|
233 mswindows_enqueue_misc_user_event
|
|
234 (frame, vert ? Qscrollbar_to_top : Qscrollbar_to_left, win);
|
|
235 break;
|
|
236
|
|
237 case SB_THUMBTRACK:
|
|
238 case SB_THUMBPOSITION:
|
|
239 scrollinfo.cbSize = sizeof(SCROLLINFO);
|
|
240 scrollinfo.fMask = SIF_ALL;
|
|
241 GetScrollInfo (hwnd, SB_CTL, &scrollinfo);
|
|
242 vertical_drag_in_progress = vert;
|
|
243 #ifdef VERTICAL_SCROLLBAR_DRAG_HACK
|
|
244 if (vert && (scrollinfo.nTrackPos > scrollinfo.nPos))
|
|
245 /* new buffer position =
|
|
246 * buffer position at start of drag +
|
|
247 * ((text remaining in buffer at start of drag) *
|
|
248 * (amount that the thumb has been moved) /
|
|
249 * (space that remained past end of the thumb at start of drag)) */
|
|
250 value = (int)
|
|
251 (scrollinfo.nPos
|
|
252 + (((double)
|
|
253 (scrollinfo.nMax - scrollinfo.nPos)
|
|
254 * (scrollinfo.nTrackPos - scrollinfo.nPos))
|
|
255 / (scrollinfo.nMax - scrollinfo.nPage - scrollinfo.nPos)))
|
|
256 - 2; /* ensure that the last line doesn't disappear off screen */
|
|
257 else
|
|
258 #endif
|
|
259 value = scrollinfo.nTrackPos;
|
|
260 mswindows_enqueue_misc_user_event
|
|
261 (frame,
|
|
262 vert ? Qscrollbar_vertical_drag : Qscrollbar_horizontal_drag,
|
|
263 Fcons (win, make_int (value)));
|
|
264 break;
|
|
265
|
|
266 case SB_ENDSCROLL:
|
|
267 #ifdef VERTICAL_SCROLLBAR_DRAG_HACK
|
546
|
268 if (vertical_drag_in_progress && sb)
|
428
|
269 /* User has just dropped the thumb - finally update it */
|
|
270 SetScrollInfo (SCROLLBAR_MSW_HANDLE (sb), SB_CTL,
|
|
271 &SCROLLBAR_MSW_INFO (sb), TRUE);
|
|
272 #endif
|
|
273 vertical_drag_in_progress = 0;
|
|
274 break;
|
|
275 }
|
|
276 }
|
|
277
|
|
278 static int
|
464
|
279 can_scroll (struct scrollbar_instance* scrollbar)
|
428
|
280 {
|
|
281 return scrollbar != NULL
|
|
282 && IsWindowVisible (SCROLLBAR_MSW_HANDLE (scrollbar))
|
|
283 && IsWindowEnabled (SCROLLBAR_MSW_HANDLE (scrollbar));
|
|
284 }
|
|
285
|
|
286 int
|
464
|
287 mswindows_handle_mousewheel_event (Lisp_Object frame, int keys, int delta,
|
|
288 POINTS where)
|
428
|
289 {
|
442
|
290 int hasVertBar, hasHorzBar; /* Indicates presence of scroll bars */
|
428
|
291 unsigned wheelScrollLines = 0; /* Number of lines per wheel notch */
|
464
|
292 Lisp_Object win;
|
|
293 struct window_mirror *mirror;
|
|
294 POINT donde_esta;
|
428
|
295
|
464
|
296 donde_esta.x = where.x;
|
|
297 donde_esta.y = where.y;
|
|
298
|
|
299 ScreenToClient (FRAME_MSWINDOWS_HANDLE (XFRAME (frame)), &donde_esta);
|
|
300
|
|
301 /* Find the window to scroll */
|
|
302 {
|
|
303 int mene, _mene, tekel, upharsin;
|
|
304 Bufpos mens, sana;
|
|
305 Charcount in;
|
|
306 Lisp_Object corpore, sano;
|
|
307 struct window *needle_in_haystack;
|
|
308
|
|
309 pixel_to_glyph_translation (XFRAME (frame), donde_esta.x, donde_esta.y,
|
|
310 &mene, &_mene, &tekel, &upharsin,
|
|
311 &needle_in_haystack,
|
|
312 &mens, &sana, &in, &corpore, &sano);
|
|
313
|
|
314 if (needle_in_haystack)
|
|
315 {
|
|
316 XSETWINDOW (win, needle_in_haystack);
|
|
317 }
|
|
318 else
|
|
319 {
|
|
320 win = FRAME_SELECTED_WINDOW (XFRAME (frame));
|
|
321 needle_in_haystack = XWINDOW (win);
|
|
322 }
|
|
323
|
|
324 mirror = find_window_mirror (needle_in_haystack);
|
|
325 }
|
428
|
326
|
|
327 /* Check that there is something to scroll */
|
|
328 hasVertBar = can_scroll (mirror->scrollbar_vertical_instance);
|
|
329 hasHorzBar = can_scroll (mirror->scrollbar_horizontal_instance);
|
|
330 if (!hasVertBar && !hasHorzBar)
|
|
331 return FALSE;
|
|
332
|
|
333 /* No support for panning and zooming, so ignore */
|
|
334 if (keys & (MK_SHIFT | MK_CONTROL))
|
|
335 return FALSE;
|
|
336
|
|
337 /* Get the number of lines per wheel delta */
|
|
338 SystemParametersInfo (SPI_GETWHEELSCROLLLINES, 0, &wheelScrollLines, 0);
|
|
339
|
|
340 /* Calculate the amount to scroll */
|
|
341 if (wheelScrollLines == WHEEL_PAGESCROLL)
|
|
342 {
|
|
343 /* Scroll by a page */
|
|
344 Lisp_Object function;
|
|
345 if (hasVertBar)
|
|
346 function = delta > 0 ? Qscrollbar_page_up : Qscrollbar_page_down;
|
|
347 else
|
|
348 function = delta > 0 ? Qscrollbar_page_left : Qscrollbar_page_right;
|
|
349 mswindows_enqueue_misc_user_event (frame, function, Fcons (win, Qnil));
|
|
350 }
|
|
351 else /* Scroll by a number of lines */
|
|
352 {
|
|
353 /* Calc the number of lines to scroll */
|
|
354 int toScroll = MulDiv (delta, wheelScrollLines, WHEEL_DELTA);
|
|
355
|
|
356 /* Do the scroll */
|
|
357 Lisp_Object function;
|
|
358 if (hasVertBar)
|
|
359 function = delta > 0 ? Qscrollbar_line_up : Qscrollbar_line_down;
|
|
360 else
|
|
361 function = delta > 0 ? Qscrollbar_char_left : Qscrollbar_char_right;
|
|
362 if (toScroll < 0)
|
|
363 toScroll = -toScroll;
|
|
364 while (toScroll--)
|
|
365 mswindows_enqueue_misc_user_event (frame, function, win);
|
|
366 }
|
|
367
|
|
368 return TRUE;
|
|
369 }
|
|
370
|
|
371 #ifdef MEMORY_USAGE_STATS
|
|
372
|
|
373 static int
|
|
374 mswindows_compute_scrollbar_instance_usage (struct device *d,
|
|
375 struct scrollbar_instance *inst,
|
|
376 struct overhead_stats *ovstats)
|
|
377 {
|
|
378 int total = 0;
|
|
379
|
|
380 while (inst)
|
|
381 {
|
|
382 struct mswindows_scrollbar_data *data =
|
|
383 (struct mswindows_scrollbar_data *) inst->scrollbar_data;
|
|
384
|
|
385 total += malloced_storage_size (data, sizeof (*data), ovstats);
|
|
386 inst = inst->next;
|
|
387 }
|
|
388
|
|
389 return total;
|
|
390 }
|
|
391
|
|
392 #endif /* MEMORY_USAGE_STATS */
|
|
393
|
|
394 /************************************************************************/
|
|
395 /* Device-specific ghost specifiers initialization */
|
|
396 /************************************************************************/
|
|
397
|
|
398 DEFUN ("mswindows-init-scrollbar-metrics", Fmswindows_init_scrollbar_metrics, 1, 1, 0, /*
|
|
399 */
|
|
400 (locale))
|
|
401 {
|
|
402 if (DEVICEP (locale))
|
|
403 {
|
|
404 add_spec_to_ghost_specifier (Vscrollbar_width,
|
|
405 make_int (GetSystemMetrics (SM_CXVSCROLL)),
|
|
406 locale, Qmswindows, Qnil);
|
|
407 add_spec_to_ghost_specifier (Vscrollbar_height,
|
|
408 make_int (GetSystemMetrics (SM_CYHSCROLL)),
|
|
409 locale, Qmswindows, Qnil);
|
|
410 }
|
|
411 return Qnil;
|
|
412 }
|
|
413
|
|
414
|
|
415 /************************************************************************/
|
|
416 /* initialization */
|
|
417 /************************************************************************/
|
|
418
|
|
419 void
|
|
420 console_type_create_scrollbar_mswindows (void)
|
|
421 {
|
|
422 CONSOLE_HAS_METHOD (mswindows, create_scrollbar_instance);
|
|
423 CONSOLE_HAS_METHOD (mswindows, free_scrollbar_instance);
|
|
424 CONSOLE_HAS_METHOD (mswindows, release_scrollbar_instance);
|
|
425 CONSOLE_HAS_METHOD (mswindows, update_scrollbar_instance_values);
|
|
426 CONSOLE_HAS_METHOD (mswindows, update_scrollbar_instance_status);
|
|
427 /* CONSOLE_HAS_METHOD (mswindows, scrollbar_width_changed_in_frame); */
|
|
428 #ifdef MEMORY_USAGE_STATS
|
|
429 CONSOLE_HAS_METHOD (mswindows, compute_scrollbar_instance_usage);
|
|
430 #endif
|
|
431 }
|
|
432
|
|
433 void
|
|
434 syms_of_scrollbar_mswindows(void)
|
|
435 {
|
|
436 DEFSUBR (Fmswindows_init_scrollbar_metrics);
|
|
437 }
|
|
438
|
|
439 void
|
|
440 vars_of_scrollbar_mswindows(void)
|
|
441 {
|
|
442 Fprovide (intern ("mswindows-scrollbars"));
|
|
443 }
|
|
444
|