225
|
1 /* scrollbar implementation -- mswindows interface.
|
|
2 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois.
|
380
|
3 Copyright (C) 1994 Amdahl Corporation.
|
225
|
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"
|
276
|
30 #include "events.h"
|
225
|
31 #include "frame.h"
|
276
|
32 #include "scrollbar-msw.h"
|
|
33 #include "scrollbar.h"
|
|
34 #include "specifier.h"
|
225
|
35 #include "window.h"
|
|
36
|
375
|
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;
|
227
|
44
|
225
|
45 static void
|
|
46 mswindows_create_scrollbar_instance (struct frame *f, int vertical,
|
|
47 struct scrollbar_instance *sb)
|
|
48 {
|
|
49 int orientation;
|
|
50
|
|
51 sb->scrollbar_data = xnew_and_zero (struct mswindows_scrollbar_data);
|
|
52
|
|
53 if (vertical)
|
|
54 orientation = SBS_VERT;
|
|
55 else
|
|
56 orientation = SBS_HORZ;
|
|
57
|
|
58 SCROLLBAR_MSW_HANDLE (sb) =
|
|
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);
|
375
|
64 SCROLLBAR_MSW_INFO (sb).cbSize = sizeof(SCROLLINFO);
|
225
|
65 SCROLLBAR_MSW_INFO (sb).fMask = SIF_ALL;
|
|
66 GetScrollInfo(SCROLLBAR_MSW_HANDLE (sb), SB_CTL,
|
|
67 &SCROLLBAR_MSW_INFO (sb));
|
|
68 SetWindowLong (SCROLLBAR_MSW_HANDLE(sb), GWL_USERDATA, (LONG)sb);
|
|
69
|
|
70 #if 0
|
|
71 {
|
|
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 = (struct scrollbar_instance *)GetWindowLong (SCROLLBAR_MSW_HANDLE(sb),
|
|
76 GWL_USERDATA);
|
|
77 *z = *z;
|
|
78 }
|
|
79 #endif
|
|
80 }
|
|
81
|
|
82 static void
|
|
83 mswindows_free_scrollbar_instance (struct scrollbar_instance *sb)
|
|
84 {
|
|
85 DestroyWindow (SCROLLBAR_MSW_HANDLE (sb));
|
|
86 if (sb->scrollbar_data)
|
|
87 xfree (sb->scrollbar_data);
|
|
88 }
|
|
89
|
|
90 static void
|
|
91 mswindows_release_scrollbar_instance (struct scrollbar_instance *sb)
|
|
92 {
|
|
93 ShowScrollBar (SCROLLBAR_MSW_HANDLE (sb), SB_CTL, 0);
|
|
94 SCROLLBAR_MSW_SIZE (sb) = 0;
|
|
95 }
|
|
96
|
|
97 #define UPDATE_POS_FIELD(field) \
|
|
98 if (new_##field >= 0 && SCROLLBAR_MSW_DATA (sb)->field != new_##field) { \
|
|
99 SCROLLBAR_MSW_DATA (sb)->field = new_##field; \
|
|
100 pos_changed = 1; \
|
|
101 }
|
|
102
|
|
103 static void
|
|
104 mswindows_update_scrollbar_instance_values (struct window *w,
|
|
105 struct scrollbar_instance *sb,
|
|
106 int new_line_increment,
|
|
107 int new_page_increment,
|
|
108 int new_minimum, int new_maximum,
|
|
109 int new_slider_size,
|
|
110 int new_slider_position,
|
|
111 int new_scrollbar_width,
|
|
112 int new_scrollbar_height,
|
|
113 int new_scrollbar_x,
|
|
114 int new_scrollbar_y)
|
|
115 {
|
|
116 int pos_changed = 0;
|
375
|
117 int vert = GetWindowLong (SCROLLBAR_MSW_HANDLE (sb), GWL_STYLE) & SBS_VERT;
|
225
|
118
|
227
|
119 #if 0
|
|
120 stderr_out ("[%d, %d], page = %d, pos = %d, inhibit = %d\n", new_minimum, new_maximum,
|
|
121 new_slider_size, new_slider_position,inhibit_slider_size_change);
|
|
122 #endif
|
|
123
|
225
|
124 /* These might be optimized, but since at least one will change at each
|
|
125 call, it's probably not worth it. */
|
227
|
126 SCROLLBAR_MSW_INFO (sb).nMin = new_minimum;
|
|
127 SCROLLBAR_MSW_INFO (sb).nMax = new_maximum;
|
375
|
128 SCROLLBAR_MSW_INFO (sb).nPage = new_slider_size + 1; /* +1 for DISABLENOSCROLL */
|
225
|
129 SCROLLBAR_MSW_INFO (sb).nPos = new_slider_position;
|
375
|
130 #ifndef VERTICAL_SCROLLBAR_DRAG_HACK
|
|
131 SCROLLBAR_MSW_INFO (sb).fMask = ((vert && vertical_drag_in_progress)
|
227
|
132 ? SIF_RANGE | SIF_POS
|
|
133 : SIF_ALL | SIF_DISABLENOSCROLL);
|
375
|
134 #else
|
|
135 SCROLLBAR_MSW_INFO (sb).fMask = SIF_ALL | SIF_DISABLENOSCROLL;
|
|
136
|
|
137 /* Ignore XEmacs' requests to update the thumb position and size; they don't
|
|
138 * bear any relation to reality because we're reporting made-up positions */
|
|
139 if (!(vert && vertical_drag_in_progress))
|
|
140 #endif
|
|
141 SetScrollInfo (SCROLLBAR_MSW_HANDLE (sb), SB_CTL, &SCROLLBAR_MSW_INFO (sb),
|
|
142 TRUE);
|
225
|
143
|
|
144 UPDATE_POS_FIELD (scrollbar_x);
|
|
145 UPDATE_POS_FIELD (scrollbar_y);
|
|
146 UPDATE_POS_FIELD (scrollbar_width);
|
|
147 UPDATE_POS_FIELD (scrollbar_height);
|
|
148
|
|
149 if (pos_changed)
|
|
150 {
|
|
151 MoveWindow(SCROLLBAR_MSW_HANDLE (sb),
|
|
152 new_scrollbar_x, new_scrollbar_y,
|
|
153 new_scrollbar_width, new_scrollbar_height,
|
|
154 TRUE);
|
|
155 }
|
|
156 }
|
|
157
|
|
158 static void
|
|
159 mswindows_update_scrollbar_instance_status (struct window *w,
|
|
160 int active, int size,
|
|
161 struct scrollbar_instance *sb)
|
|
162 {
|
269
|
163 if (SCROLLBAR_MSW_SIZE (sb) != size)
|
|
164 {
|
|
165 SCROLLBAR_MSW_SIZE (sb) = size;
|
|
166 ShowScrollBar (SCROLLBAR_MSW_HANDLE (sb), SB_CTL,
|
|
167 SCROLLBAR_MSW_SIZE (sb));
|
|
168 SCROLLBAR_MSW_INFO(sb).fMask |= SIF_DISABLENOSCROLL;
|
|
169 SetScrollInfo(SCROLLBAR_MSW_HANDLE (sb), SB_CTL, &SCROLLBAR_MSW_INFO (sb), TRUE);
|
|
170 }
|
225
|
171 }
|
|
172
|
|
173 void
|
|
174 mswindows_handle_scrollbar_event (HWND hwnd, int code, int pos)
|
|
175 {
|
|
176 struct frame *f;
|
288
|
177 Lisp_Object win, frame;
|
225
|
178 struct scrollbar_instance *sb;
|
|
179 SCROLLINFO scrollinfo;
|
227
|
180 int vert = GetWindowLong (hwnd, GWL_STYLE) & SBS_VERT;
|
375
|
181 int value;
|
225
|
182
|
|
183 sb = (struct scrollbar_instance *)GetWindowLong (hwnd, GWL_USERDATA);
|
|
184 win = real_window (sb->mirror, 1);
|
288
|
185 frame = XWINDOW (win)->frame;
|
|
186 f = XFRAME (frame);
|
225
|
187
|
227
|
188 /* SB_LINEDOWN == SB_CHARLEFT etc. This is the way they will
|
|
189 always be - any Windows is binary compatible backward with
|
|
190 old programs */
|
|
191
|
225
|
192 switch (code)
|
|
193 {
|
|
194 case SB_LINEDOWN:
|
288
|
195 mswindows_enqueue_misc_user_event
|
|
196 (frame, vert ? Qscrollbar_line_down : Qscrollbar_char_right, win);
|
225
|
197 break;
|
|
198
|
|
199 case SB_LINEUP:
|
288
|
200 mswindows_enqueue_misc_user_event
|
|
201 (frame, vert ? Qscrollbar_line_up : Qscrollbar_char_left, win);
|
225
|
202 break;
|
|
203
|
|
204 case SB_PAGEDOWN:
|
288
|
205 mswindows_enqueue_misc_user_event
|
|
206 (win, vert ? Qscrollbar_page_down : Qscrollbar_page_right,
|
|
207 vert ? Fcons (win, Qnil) : win);
|
225
|
208 break;
|
|
209
|
|
210 case SB_PAGEUP:
|
288
|
211 mswindows_enqueue_misc_user_event
|
|
212 (frame,
|
|
213 vert ? Qscrollbar_page_up : Qscrollbar_page_left,
|
|
214 vert ? Fcons (win, Qnil) : win);
|
225
|
215 break;
|
|
216
|
|
217 case SB_BOTTOM:
|
288
|
218 mswindows_enqueue_misc_user_event
|
|
219 (frame, vert ? Qscrollbar_to_bottom : Qscrollbar_to_right, win);
|
225
|
220 break;
|
|
221
|
|
222 case SB_TOP:
|
288
|
223 mswindows_enqueue_misc_user_event
|
|
224 (frame, vert ? Qscrollbar_to_top : Qscrollbar_to_left, win);
|
225
|
225 break;
|
|
226
|
|
227 case SB_THUMBTRACK:
|
|
228 case SB_THUMBPOSITION:
|
227
|
229 scrollinfo.cbSize = sizeof(SCROLLINFO);
|
375
|
230 scrollinfo.fMask = SIF_ALL;
|
227
|
231 GetScrollInfo (hwnd, SB_CTL, &scrollinfo);
|
375
|
232 vertical_drag_in_progress = vert;
|
|
233 #ifdef VERTICAL_SCROLLBAR_DRAG_HACK
|
|
234 if (vert && (scrollinfo.nTrackPos > scrollinfo.nPos))
|
|
235 /* new buffer position =
|
|
236 * buffer position at start of drag +
|
|
237 * ((text remaining in buffer at start of drag) *
|
|
238 * (amount that the thumb has been moved) /
|
|
239 * (space that remained past end of the thumb at start of drag)) */
|
|
240 value = (int)
|
|
241 (scrollinfo.nPos
|
|
242 + (((double)
|
|
243 (scrollinfo.nMax - scrollinfo.nPos)
|
|
244 * (scrollinfo.nTrackPos - scrollinfo.nPos))
|
|
245 / (scrollinfo.nMax - scrollinfo.nPage - scrollinfo.nPos)))
|
|
246 - 2; /* ensure that the last line doesn't disappear off screen */
|
|
247 else
|
|
248 #endif
|
|
249 value = scrollinfo.nTrackPos;
|
288
|
250 mswindows_enqueue_misc_user_event
|
|
251 (frame,
|
|
252 vert ? Qscrollbar_vertical_drag : Qscrollbar_horizontal_drag,
|
375
|
253 Fcons (win, make_int (value)));
|
|
254 break;
|
|
255
|
|
256 case SB_ENDSCROLL:
|
|
257 #ifdef VERTICAL_SCROLLBAR_DRAG_HACK
|
|
258 if (vertical_drag_in_progress)
|
|
259 /* User has just dropped the thumb - finally update it */
|
|
260 SetScrollInfo (SCROLLBAR_MSW_HANDLE (sb), SB_CTL,
|
|
261 &SCROLLBAR_MSW_INFO (sb), TRUE);
|
|
262 #endif
|
|
263 vertical_drag_in_progress = 0;
|
225
|
264 break;
|
|
265 }
|
|
266 }
|
|
267
|
|
268 #ifdef MEMORY_USAGE_STATS
|
|
269
|
|
270 static int
|
|
271 mswindows_compute_scrollbar_instance_usage (struct device *d,
|
|
272 struct scrollbar_instance *inst,
|
|
273 struct overhead_stats *ovstats)
|
|
274 {
|
|
275 int total = 0;
|
|
276
|
|
277 while (inst)
|
|
278 {
|
|
279 struct mswindows_scrollbar_data *data =
|
|
280 (struct mswindows_scrollbar_data *) inst->scrollbar_data;
|
|
281
|
|
282 total += malloced_storage_size (data, sizeof (*data), ovstats);
|
|
283 inst = inst->next;
|
|
284 }
|
|
285
|
|
286 return total;
|
|
287 }
|
|
288
|
|
289 #endif /* MEMORY_USAGE_STATS */
|
276
|
290
|
|
291 /************************************************************************/
|
|
292 /* Device-specific ghost specifiers initialization */
|
|
293 /************************************************************************/
|
225
|
294
|
276
|
295 DEFUN ("mswindows-init-scrollbar-metrics", Fmswindows_init_scrollbar_metrics, 1, 1, 0, /*
|
|
296 */
|
|
297 (locale))
|
|
298 {
|
|
299 if (DEVICEP (locale))
|
|
300 {
|
|
301 add_spec_to_ghost_specifier (Vscrollbar_width,
|
|
302 make_int (GetSystemMetrics (SM_CXVSCROLL)),
|
|
303 locale, Qmswindows, Qnil);
|
|
304 add_spec_to_ghost_specifier (Vscrollbar_height,
|
|
305 make_int (GetSystemMetrics (SM_CYHSCROLL)),
|
|
306 locale, Qmswindows, Qnil);
|
|
307 }
|
|
308 return Qnil;
|
|
309 }
|
|
310
|
|
311
|
225
|
312 /************************************************************************/
|
|
313 /* initialization */
|
|
314 /************************************************************************/
|
|
315
|
|
316 void
|
|
317 console_type_create_scrollbar_mswindows (void)
|
|
318 {
|
|
319 CONSOLE_HAS_METHOD (mswindows, create_scrollbar_instance);
|
|
320 CONSOLE_HAS_METHOD (mswindows, free_scrollbar_instance);
|
|
321 CONSOLE_HAS_METHOD (mswindows, release_scrollbar_instance);
|
|
322 CONSOLE_HAS_METHOD (mswindows, update_scrollbar_instance_values);
|
|
323 CONSOLE_HAS_METHOD (mswindows, update_scrollbar_instance_status);
|
|
324 /* CONSOLE_HAS_METHOD (mswindows, scrollbar_width_changed_in_frame); */
|
|
325 #ifdef MEMORY_USAGE_STATS
|
|
326 CONSOLE_HAS_METHOD (mswindows, compute_scrollbar_instance_usage);
|
|
327 #endif
|
|
328 }
|
|
329
|
|
330 void
|
276
|
331 syms_of_scrollbar_mswindows(void)
|
|
332 {
|
|
333 DEFSUBR (Fmswindows_init_scrollbar_metrics);
|
|
334 }
|
|
335
|
|
336 void
|
225
|
337 vars_of_scrollbar_mswindows(void)
|
|
338 {
|
|
339 Fprovide (intern ("mswindows-scrollbars"));
|
|
340 }
|
|
341
|