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