225
|
1 /* scrollbar implementation -- mswindows interface.
|
|
2 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois.
|
|
3 Copyright (C) 1994 Amdhal 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"
|
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
|
227
|
37 /* This has really different semantics in Windows than in Motif.
|
|
38 There's no corresponding method; we just do not change slider
|
|
39 size while dragging. It makes the scrollbar look smother and
|
|
40 prevents some weird behavior when scrolled near the bottom */
|
|
41 static int inhibit_slider_size_change = 0;
|
|
42
|
225
|
43 static void
|
|
44 mswindows_create_scrollbar_instance (struct frame *f, int vertical,
|
|
45 struct scrollbar_instance *sb)
|
|
46 {
|
|
47 int orientation;
|
|
48
|
|
49 sb->scrollbar_data = xnew_and_zero (struct mswindows_scrollbar_data);
|
|
50
|
|
51 if (vertical)
|
|
52 orientation = SBS_VERT;
|
|
53 else
|
|
54 orientation = SBS_HORZ;
|
|
55
|
|
56 SCROLLBAR_MSW_HANDLE (sb) =
|
|
57 CreateWindowEx(0, "SCROLLBAR", 0, orientation|WS_CHILD,
|
|
58 CW_USEDEFAULT, CW_USEDEFAULT,
|
|
59 CW_USEDEFAULT, CW_USEDEFAULT,
|
|
60 FRAME_MSWINDOWS_HANDLE (f),
|
|
61 NULL, NULL, NULL);
|
|
62 SCROLLBAR_MSW_INFO (sb).fMask = SIF_ALL;
|
|
63 GetScrollInfo(SCROLLBAR_MSW_HANDLE (sb), SB_CTL,
|
|
64 &SCROLLBAR_MSW_INFO (sb));
|
|
65 SetWindowLong (SCROLLBAR_MSW_HANDLE(sb), GWL_USERDATA, (LONG)sb);
|
|
66
|
|
67 #if 0
|
|
68 {
|
|
69 HWND h = SCROLLBAR_MSW_HANDLE (sb);
|
|
70 int x = SetWindowLong (SCROLLBAR_MSW_HANDLE(sb), GWL_USERDATA, (LONG)sb);
|
|
71 int y = GetLastError();
|
|
72 struct scrollbar_instance *z = (struct scrollbar_instance *)GetWindowLong (SCROLLBAR_MSW_HANDLE(sb),
|
|
73 GWL_USERDATA);
|
|
74 *z = *z;
|
|
75 }
|
|
76 #endif
|
|
77 }
|
|
78
|
|
79 static void
|
|
80 mswindows_free_scrollbar_instance (struct scrollbar_instance *sb)
|
|
81 {
|
|
82 DestroyWindow (SCROLLBAR_MSW_HANDLE (sb));
|
|
83 if (sb->scrollbar_data)
|
|
84 xfree (sb->scrollbar_data);
|
|
85 }
|
|
86
|
|
87 static void
|
|
88 mswindows_release_scrollbar_instance (struct scrollbar_instance *sb)
|
|
89 {
|
|
90 ShowScrollBar (SCROLLBAR_MSW_HANDLE (sb), SB_CTL, 0);
|
|
91 SCROLLBAR_MSW_SIZE (sb) = 0;
|
|
92 }
|
|
93
|
|
94 #define UPDATE_POS_FIELD(field) \
|
|
95 if (new_##field >= 0 && SCROLLBAR_MSW_DATA (sb)->field != new_##field) { \
|
|
96 SCROLLBAR_MSW_DATA (sb)->field = new_##field; \
|
|
97 pos_changed = 1; \
|
|
98 }
|
|
99
|
|
100 static void
|
|
101 mswindows_update_scrollbar_instance_values (struct window *w,
|
|
102 struct scrollbar_instance *sb,
|
|
103 int new_line_increment,
|
|
104 int new_page_increment,
|
|
105 int new_minimum, int new_maximum,
|
|
106 int new_slider_size,
|
|
107 int new_slider_position,
|
|
108 int new_scrollbar_width,
|
|
109 int new_scrollbar_height,
|
|
110 int new_scrollbar_x,
|
|
111 int new_scrollbar_y)
|
|
112 {
|
|
113 struct frame *f;
|
|
114 int pos_changed = 0;
|
|
115
|
|
116 f = XFRAME (w->frame);
|
|
117
|
227
|
118 #if 0
|
|
119 stderr_out ("[%d, %d], page = %d, pos = %d, inhibit = %d\n", new_minimum, new_maximum,
|
|
120 new_slider_size, new_slider_position,inhibit_slider_size_change);
|
|
121 #endif
|
|
122
|
225
|
123 /* These might be optimized, but since at least one will change at each
|
|
124 call, it's probably not worth it. */
|
227
|
125 SCROLLBAR_MSW_INFO (sb).nMin = new_minimum;
|
|
126 SCROLLBAR_MSW_INFO (sb).nMax = new_maximum;
|
|
127 SCROLLBAR_MSW_INFO (sb).nPage = new_slider_size + 1; /* for DISABLENOSCROLL */
|
225
|
128 SCROLLBAR_MSW_INFO (sb).nPos = new_slider_position;
|
227
|
129 SCROLLBAR_MSW_INFO (sb).fMask = (inhibit_slider_size_change
|
|
130 ? SIF_RANGE | SIF_POS
|
|
131 : SIF_ALL | SIF_DISABLENOSCROLL);
|
225
|
132
|
|
133 SetScrollInfo(SCROLLBAR_MSW_HANDLE (sb), SB_CTL, &SCROLLBAR_MSW_INFO (sb),
|
227
|
134 !pos_changed);
|
225
|
135
|
|
136 UPDATE_POS_FIELD (scrollbar_x);
|
|
137 UPDATE_POS_FIELD (scrollbar_y);
|
|
138 UPDATE_POS_FIELD (scrollbar_width);
|
|
139 UPDATE_POS_FIELD (scrollbar_height);
|
|
140
|
|
141 if (pos_changed)
|
|
142 {
|
|
143 MoveWindow(SCROLLBAR_MSW_HANDLE (sb),
|
|
144 new_scrollbar_x, new_scrollbar_y,
|
|
145 new_scrollbar_width, new_scrollbar_height,
|
|
146 TRUE);
|
|
147 }
|
|
148 }
|
|
149
|
|
150 static void
|
|
151 mswindows_update_scrollbar_instance_status (struct window *w,
|
|
152 int active, int size,
|
|
153 struct scrollbar_instance *sb)
|
|
154 {
|
|
155 struct frame *f = XFRAME (w->frame);
|
|
156
|
269
|
157 if (SCROLLBAR_MSW_SIZE (sb) != size)
|
|
158 {
|
|
159 SCROLLBAR_MSW_SIZE (sb) = size;
|
|
160 ShowScrollBar (SCROLLBAR_MSW_HANDLE (sb), SB_CTL,
|
|
161 SCROLLBAR_MSW_SIZE (sb));
|
|
162 SCROLLBAR_MSW_INFO(sb).fMask |= SIF_DISABLENOSCROLL;
|
|
163 SetScrollInfo(SCROLLBAR_MSW_HANDLE (sb), SB_CTL, &SCROLLBAR_MSW_INFO (sb), TRUE);
|
|
164 }
|
225
|
165 }
|
|
166
|
|
167 void
|
|
168 mswindows_handle_scrollbar_event (HWND hwnd, int code, int pos)
|
|
169 {
|
|
170 struct frame *f;
|
|
171 Lisp_Object win;
|
|
172 struct scrollbar_instance *sb;
|
|
173 SCROLLINFO scrollinfo;
|
227
|
174 int vert = GetWindowLong (hwnd, GWL_STYLE) & SBS_VERT;
|
225
|
175
|
|
176 sb = (struct scrollbar_instance *)GetWindowLong (hwnd, GWL_USERDATA);
|
|
177 win = real_window (sb->mirror, 1);
|
|
178 f = XFRAME (XWINDOW (win)->frame);
|
|
179
|
227
|
180 inhibit_slider_size_change = code == SB_THUMBTRACK;
|
|
181
|
|
182 /* SB_LINEDOWN == SB_CHARLEFT etc. This is the way they will
|
|
183 always be - any Windows is binary compatible backward with
|
|
184 old programs */
|
|
185
|
225
|
186 switch (code)
|
|
187 {
|
|
188 case SB_LINEDOWN:
|
227
|
189 enqueue_misc_user_event(win,
|
|
190 vert ? Qscrollbar_line_down : Qscrollbar_char_right,
|
|
191 win);
|
225
|
192 break;
|
|
193
|
|
194 case SB_LINEUP:
|
227
|
195 enqueue_misc_user_event(win,
|
|
196 vert ? Qscrollbar_line_up : Qscrollbar_char_left,
|
|
197 win);
|
225
|
198 break;
|
|
199
|
|
200 case SB_PAGEDOWN:
|
227
|
201 enqueue_misc_user_event(win,
|
|
202 vert ? Qscrollbar_page_down : Qscrollbar_page_right,
|
|
203 vert ? Fcons (win, Qnil) : win);
|
225
|
204 break;
|
|
205
|
|
206 case SB_PAGEUP:
|
227
|
207 enqueue_misc_user_event(win,
|
|
208 vert ? Qscrollbar_page_up : Qscrollbar_page_left,
|
|
209 vert ? Fcons (win, Qnil) : win);
|
225
|
210 break;
|
|
211
|
|
212 case SB_BOTTOM:
|
227
|
213 enqueue_misc_user_event(win,
|
|
214 vert ? Qscrollbar_to_bottom : Qscrollbar_to_right,
|
|
215 win);
|
225
|
216 break;
|
|
217
|
|
218 case SB_TOP:
|
227
|
219 enqueue_misc_user_event(win,
|
|
220 vert ? Qscrollbar_to_top : Qscrollbar_to_left,
|
|
221 win);
|
225
|
222 break;
|
|
223
|
|
224 case SB_THUMBTRACK:
|
|
225 case SB_THUMBPOSITION:
|
227
|
226 scrollinfo.cbSize = sizeof(SCROLLINFO);
|
|
227 scrollinfo.fMask = SIF_TRACKPOS;
|
|
228 GetScrollInfo (hwnd, SB_CTL, &scrollinfo);
|
|
229 enqueue_misc_user_event (win,
|
|
230 (vert ? Qscrollbar_vertical_drag
|
|
231 : Qscrollbar_horizontal_drag),
|
|
232 Fcons (win, make_int (scrollinfo.nTrackPos)));
|
225
|
233 break;
|
|
234 }
|
|
235 }
|
|
236
|
|
237 #ifdef MEMORY_USAGE_STATS
|
|
238
|
|
239 static int
|
|
240 mswindows_compute_scrollbar_instance_usage (struct device *d,
|
|
241 struct scrollbar_instance *inst,
|
|
242 struct overhead_stats *ovstats)
|
|
243 {
|
|
244 int total = 0;
|
|
245
|
|
246 while (inst)
|
|
247 {
|
|
248 struct mswindows_scrollbar_data *data =
|
|
249 (struct mswindows_scrollbar_data *) inst->scrollbar_data;
|
|
250
|
|
251 total += malloced_storage_size (data, sizeof (*data), ovstats);
|
|
252 inst = inst->next;
|
|
253 }
|
|
254
|
|
255 return total;
|
|
256 }
|
|
257
|
|
258 #endif /* MEMORY_USAGE_STATS */
|
276
|
259
|
|
260 /************************************************************************/
|
|
261 /* Device-specific ghost specifiers initialization */
|
|
262 /************************************************************************/
|
225
|
263
|
276
|
264 DEFUN ("mswindows-init-scrollbar-metrics", Fmswindows_init_scrollbar_metrics, 1, 1, 0, /*
|
|
265 */
|
|
266 (locale))
|
|
267 {
|
|
268 if (DEVICEP (locale))
|
|
269 {
|
|
270 add_spec_to_ghost_specifier (Vscrollbar_width,
|
|
271 make_int (GetSystemMetrics (SM_CXVSCROLL)),
|
|
272 locale, Qmswindows, Qnil);
|
|
273 add_spec_to_ghost_specifier (Vscrollbar_height,
|
|
274 make_int (GetSystemMetrics (SM_CYHSCROLL)),
|
|
275 locale, Qmswindows, Qnil);
|
|
276 }
|
|
277 return Qnil;
|
|
278 }
|
|
279
|
|
280
|
225
|
281 /************************************************************************/
|
|
282 /* initialization */
|
|
283 /************************************************************************/
|
|
284
|
|
285 void
|
|
286 console_type_create_scrollbar_mswindows (void)
|
|
287 {
|
|
288 CONSOLE_HAS_METHOD (mswindows, create_scrollbar_instance);
|
|
289 CONSOLE_HAS_METHOD (mswindows, free_scrollbar_instance);
|
|
290 CONSOLE_HAS_METHOD (mswindows, release_scrollbar_instance);
|
|
291 CONSOLE_HAS_METHOD (mswindows, update_scrollbar_instance_values);
|
|
292 CONSOLE_HAS_METHOD (mswindows, update_scrollbar_instance_status);
|
|
293 /* CONSOLE_HAS_METHOD (mswindows, scrollbar_width_changed_in_frame); */
|
|
294 #ifdef MEMORY_USAGE_STATS
|
|
295 CONSOLE_HAS_METHOD (mswindows, compute_scrollbar_instance_usage);
|
|
296 #endif
|
|
297 }
|
|
298
|
|
299 void
|
276
|
300 syms_of_scrollbar_mswindows(void)
|
|
301 {
|
|
302 DEFSUBR (Fmswindows_init_scrollbar_metrics);
|
|
303 }
|
|
304
|
|
305 void
|
225
|
306 vars_of_scrollbar_mswindows(void)
|
|
307 {
|
|
308 Fprovide (intern ("mswindows-scrollbars"));
|
|
309 }
|
|
310
|