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 {
|
269
|
155 if (SCROLLBAR_MSW_SIZE (sb) != size)
|
|
156 {
|
|
157 SCROLLBAR_MSW_SIZE (sb) = size;
|
|
158 ShowScrollBar (SCROLLBAR_MSW_HANDLE (sb), SB_CTL,
|
|
159 SCROLLBAR_MSW_SIZE (sb));
|
|
160 SCROLLBAR_MSW_INFO(sb).fMask |= SIF_DISABLENOSCROLL;
|
|
161 SetScrollInfo(SCROLLBAR_MSW_HANDLE (sb), SB_CTL, &SCROLLBAR_MSW_INFO (sb), TRUE);
|
|
162 }
|
225
|
163 }
|
|
164
|
|
165 void
|
|
166 mswindows_handle_scrollbar_event (HWND hwnd, int code, int pos)
|
|
167 {
|
|
168 struct frame *f;
|
|
169 Lisp_Object win;
|
|
170 struct scrollbar_instance *sb;
|
|
171 SCROLLINFO scrollinfo;
|
227
|
172 int vert = GetWindowLong (hwnd, GWL_STYLE) & SBS_VERT;
|
225
|
173
|
|
174 sb = (struct scrollbar_instance *)GetWindowLong (hwnd, GWL_USERDATA);
|
|
175 win = real_window (sb->mirror, 1);
|
|
176 f = XFRAME (XWINDOW (win)->frame);
|
|
177
|
227
|
178 inhibit_slider_size_change = code == SB_THUMBTRACK;
|
|
179
|
|
180 /* SB_LINEDOWN == SB_CHARLEFT etc. This is the way they will
|
|
181 always be - any Windows is binary compatible backward with
|
|
182 old programs */
|
|
183
|
225
|
184 switch (code)
|
|
185 {
|
|
186 case SB_LINEDOWN:
|
227
|
187 enqueue_misc_user_event(win,
|
|
188 vert ? Qscrollbar_line_down : Qscrollbar_char_right,
|
|
189 win);
|
225
|
190 break;
|
|
191
|
|
192 case SB_LINEUP:
|
227
|
193 enqueue_misc_user_event(win,
|
|
194 vert ? Qscrollbar_line_up : Qscrollbar_char_left,
|
|
195 win);
|
225
|
196 break;
|
|
197
|
|
198 case SB_PAGEDOWN:
|
227
|
199 enqueue_misc_user_event(win,
|
|
200 vert ? Qscrollbar_page_down : Qscrollbar_page_right,
|
|
201 vert ? Fcons (win, Qnil) : win);
|
225
|
202 break;
|
|
203
|
|
204 case SB_PAGEUP:
|
227
|
205 enqueue_misc_user_event(win,
|
|
206 vert ? Qscrollbar_page_up : Qscrollbar_page_left,
|
|
207 vert ? Fcons (win, Qnil) : win);
|
225
|
208 break;
|
|
209
|
|
210 case SB_BOTTOM:
|
227
|
211 enqueue_misc_user_event(win,
|
|
212 vert ? Qscrollbar_to_bottom : Qscrollbar_to_right,
|
|
213 win);
|
225
|
214 break;
|
|
215
|
|
216 case SB_TOP:
|
227
|
217 enqueue_misc_user_event(win,
|
|
218 vert ? Qscrollbar_to_top : Qscrollbar_to_left,
|
|
219 win);
|
225
|
220 break;
|
|
221
|
|
222 case SB_THUMBTRACK:
|
|
223 case SB_THUMBPOSITION:
|
227
|
224 scrollinfo.cbSize = sizeof(SCROLLINFO);
|
|
225 scrollinfo.fMask = SIF_TRACKPOS;
|
|
226 GetScrollInfo (hwnd, SB_CTL, &scrollinfo);
|
|
227 enqueue_misc_user_event (win,
|
|
228 (vert ? Qscrollbar_vertical_drag
|
|
229 : Qscrollbar_horizontal_drag),
|
|
230 Fcons (win, make_int (scrollinfo.nTrackPos)));
|
225
|
231 break;
|
|
232 }
|
|
233 }
|
|
234
|
|
235 #ifdef MEMORY_USAGE_STATS
|
|
236
|
|
237 static int
|
|
238 mswindows_compute_scrollbar_instance_usage (struct device *d,
|
|
239 struct scrollbar_instance *inst,
|
|
240 struct overhead_stats *ovstats)
|
|
241 {
|
|
242 int total = 0;
|
|
243
|
|
244 while (inst)
|
|
245 {
|
|
246 struct mswindows_scrollbar_data *data =
|
|
247 (struct mswindows_scrollbar_data *) inst->scrollbar_data;
|
|
248
|
|
249 total += malloced_storage_size (data, sizeof (*data), ovstats);
|
|
250 inst = inst->next;
|
|
251 }
|
|
252
|
|
253 return total;
|
|
254 }
|
|
255
|
|
256 #endif /* MEMORY_USAGE_STATS */
|
276
|
257
|
|
258 /************************************************************************/
|
|
259 /* Device-specific ghost specifiers initialization */
|
|
260 /************************************************************************/
|
225
|
261
|
276
|
262 DEFUN ("mswindows-init-scrollbar-metrics", Fmswindows_init_scrollbar_metrics, 1, 1, 0, /*
|
|
263 */
|
|
264 (locale))
|
|
265 {
|
|
266 if (DEVICEP (locale))
|
|
267 {
|
|
268 add_spec_to_ghost_specifier (Vscrollbar_width,
|
|
269 make_int (GetSystemMetrics (SM_CXVSCROLL)),
|
|
270 locale, Qmswindows, Qnil);
|
|
271 add_spec_to_ghost_specifier (Vscrollbar_height,
|
|
272 make_int (GetSystemMetrics (SM_CYHSCROLL)),
|
|
273 locale, Qmswindows, Qnil);
|
|
274 }
|
|
275 return Qnil;
|
|
276 }
|
|
277
|
|
278
|
225
|
279 /************************************************************************/
|
|
280 /* initialization */
|
|
281 /************************************************************************/
|
|
282
|
|
283 void
|
|
284 console_type_create_scrollbar_mswindows (void)
|
|
285 {
|
|
286 CONSOLE_HAS_METHOD (mswindows, create_scrollbar_instance);
|
|
287 CONSOLE_HAS_METHOD (mswindows, free_scrollbar_instance);
|
|
288 CONSOLE_HAS_METHOD (mswindows, release_scrollbar_instance);
|
|
289 CONSOLE_HAS_METHOD (mswindows, update_scrollbar_instance_values);
|
|
290 CONSOLE_HAS_METHOD (mswindows, update_scrollbar_instance_status);
|
|
291 /* CONSOLE_HAS_METHOD (mswindows, scrollbar_width_changed_in_frame); */
|
|
292 #ifdef MEMORY_USAGE_STATS
|
|
293 CONSOLE_HAS_METHOD (mswindows, compute_scrollbar_instance_usage);
|
|
294 #endif
|
|
295 }
|
|
296
|
|
297 void
|
276
|
298 syms_of_scrollbar_mswindows(void)
|
|
299 {
|
|
300 DEFSUBR (Fmswindows_init_scrollbar_metrics);
|
|
301 }
|
|
302
|
|
303 void
|
225
|
304 vars_of_scrollbar_mswindows(void)
|
|
305 {
|
|
306 Fprovide (intern ("mswindows-scrollbars"));
|
|
307 }
|
|
308
|