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"
|
|
30 #include "frame.h"
|
|
31 #include "window.h"
|
|
32 #include "scrollbar-msw.h"
|
|
33 #include "events.h"
|
|
34 #include "event-msw.h"
|
|
35
|
|
36 static void
|
|
37 mswindows_create_scrollbar_instance (struct frame *f, int vertical,
|
|
38 struct scrollbar_instance *sb)
|
|
39 {
|
|
40 int orientation;
|
|
41
|
|
42 sb->scrollbar_data = xnew_and_zero (struct mswindows_scrollbar_data);
|
|
43
|
|
44 if (vertical)
|
|
45 orientation = SBS_VERT;
|
|
46 else
|
|
47 orientation = SBS_HORZ;
|
|
48
|
|
49 SCROLLBAR_MSW_HANDLE (sb) =
|
|
50 CreateWindowEx(0, "SCROLLBAR", 0, orientation|WS_CHILD,
|
|
51 CW_USEDEFAULT, CW_USEDEFAULT,
|
|
52 CW_USEDEFAULT, CW_USEDEFAULT,
|
|
53 FRAME_MSWINDOWS_HANDLE (f),
|
|
54 NULL, NULL, NULL);
|
|
55 SCROLLBAR_MSW_INFO (sb).fMask = SIF_ALL;
|
|
56 GetScrollInfo(SCROLLBAR_MSW_HANDLE (sb), SB_CTL,
|
|
57 &SCROLLBAR_MSW_INFO (sb));
|
|
58 SetWindowLong (SCROLLBAR_MSW_HANDLE(sb), GWL_USERDATA, (LONG)sb);
|
|
59
|
|
60 #if 0
|
|
61 {
|
|
62 HWND h = SCROLLBAR_MSW_HANDLE (sb);
|
|
63 int x = SetWindowLong (SCROLLBAR_MSW_HANDLE(sb), GWL_USERDATA, (LONG)sb);
|
|
64 int y = GetLastError();
|
|
65 struct scrollbar_instance *z = (struct scrollbar_instance *)GetWindowLong (SCROLLBAR_MSW_HANDLE(sb),
|
|
66 GWL_USERDATA);
|
|
67 *z = *z;
|
|
68 }
|
|
69 #endif
|
|
70 }
|
|
71
|
|
72 static void
|
|
73 mswindows_free_scrollbar_instance (struct scrollbar_instance *sb)
|
|
74 {
|
|
75 DestroyWindow (SCROLLBAR_MSW_HANDLE (sb));
|
|
76 if (sb->scrollbar_data)
|
|
77 xfree (sb->scrollbar_data);
|
|
78 }
|
|
79
|
|
80 static void
|
|
81 mswindows_release_scrollbar_instance (struct scrollbar_instance *sb)
|
|
82 {
|
|
83 ShowScrollBar (SCROLLBAR_MSW_HANDLE (sb), SB_CTL, 0);
|
|
84 SCROLLBAR_MSW_SIZE (sb) = 0;
|
|
85 }
|
|
86
|
|
87 #define UPDATE_POS_FIELD(field) \
|
|
88 if (new_##field >= 0 && SCROLLBAR_MSW_DATA (sb)->field != new_##field) { \
|
|
89 SCROLLBAR_MSW_DATA (sb)->field = new_##field; \
|
|
90 pos_changed = 1; \
|
|
91 }
|
|
92
|
|
93 static void
|
|
94 mswindows_update_scrollbar_instance_values (struct window *w,
|
|
95 struct scrollbar_instance *sb,
|
|
96 int new_line_increment,
|
|
97 int new_page_increment,
|
|
98 int new_minimum, int new_maximum,
|
|
99 int new_slider_size,
|
|
100 int new_slider_position,
|
|
101 int new_scrollbar_width,
|
|
102 int new_scrollbar_height,
|
|
103 int new_scrollbar_x,
|
|
104 int new_scrollbar_y)
|
|
105 {
|
|
106 struct frame *f;
|
|
107 int pos_changed = 0;
|
|
108
|
|
109 f = XFRAME (w->frame);
|
|
110
|
|
111 /* These might be optimized, but since at least one will change at each
|
|
112 call, it's probably not worth it. */
|
|
113 SCROLLBAR_MSW_INFO (sb).nMin = new_minimum - 1;
|
|
114 SCROLLBAR_MSW_INFO (sb).nMax = new_maximum - 1;
|
|
115 SCROLLBAR_MSW_INFO (sb).nPage = new_slider_size;
|
|
116 SCROLLBAR_MSW_INFO (sb).nPos = new_slider_position;
|
|
117 SCROLLBAR_MSW_INFO (sb).fMask = SIF_ALL;
|
|
118
|
|
119 SetScrollInfo(SCROLLBAR_MSW_HANDLE (sb), SB_CTL, &SCROLLBAR_MSW_INFO (sb),
|
|
120 TRUE);
|
|
121
|
|
122 UPDATE_POS_FIELD (scrollbar_x);
|
|
123 UPDATE_POS_FIELD (scrollbar_y);
|
|
124 UPDATE_POS_FIELD (scrollbar_width);
|
|
125 UPDATE_POS_FIELD (scrollbar_height);
|
|
126
|
|
127 if (pos_changed)
|
|
128 {
|
|
129 MoveWindow(SCROLLBAR_MSW_HANDLE (sb),
|
|
130 new_scrollbar_x, new_scrollbar_y,
|
|
131 new_scrollbar_width, new_scrollbar_height,
|
|
132 TRUE);
|
|
133 }
|
|
134 }
|
|
135
|
|
136 static void
|
|
137 mswindows_update_scrollbar_instance_status (struct window *w,
|
|
138 int active, int size,
|
|
139 struct scrollbar_instance *sb)
|
|
140 {
|
|
141 struct frame *f = XFRAME (w->frame);
|
|
142
|
|
143 if (SCROLLBAR_MSW_SIZE (sb) != size) {
|
|
144 SCROLLBAR_MSW_SIZE (sb) = size;
|
|
145 ShowScrollBar (SCROLLBAR_MSW_HANDLE (sb), SB_CTL,
|
|
146 SCROLLBAR_MSW_SIZE (sb));
|
|
147 FRAMEMETH (f, set_frame_size, (f, FRAME_WIDTH (f), FRAME_HEIGHT (f)));
|
|
148 }
|
|
149 }
|
|
150
|
|
151 void
|
|
152 mswindows_handle_scrollbar_event (HWND hwnd, int code, int pos)
|
|
153 {
|
|
154 struct frame *f;
|
|
155 Lisp_Object win;
|
|
156 struct scrollbar_instance *sb;
|
|
157 SCROLLINFO scrollinfo;
|
|
158
|
|
159 sb = (struct scrollbar_instance *)GetWindowLong (hwnd, GWL_USERDATA);
|
|
160 win = real_window (sb->mirror, 1);
|
|
161 f = XFRAME (XWINDOW (win)->frame);
|
|
162
|
|
163 switch (code)
|
|
164 {
|
|
165 case SB_LINEDOWN:
|
|
166 enqueue_misc_user_event(win, Qscrollbar_line_down, win);
|
|
167 break;
|
|
168
|
|
169 case SB_LINEUP:
|
|
170 enqueue_misc_user_event(win, Qscrollbar_line_up, win);
|
|
171 break;
|
|
172
|
|
173 case SB_PAGEDOWN:
|
|
174 enqueue_misc_user_event(win, Qscrollbar_page_down, Fcons (win, Qnil));
|
|
175 break;
|
|
176
|
|
177 case SB_PAGEUP:
|
|
178 enqueue_misc_user_event(win, Qscrollbar_page_up, Fcons (win, Qnil));
|
|
179 break;
|
|
180
|
|
181 case SB_BOTTOM:
|
|
182 enqueue_misc_user_event(win, Qscrollbar_to_bottom, win);
|
|
183 break;
|
|
184
|
|
185 case SB_TOP:
|
|
186 enqueue_misc_user_event(win, Qscrollbar_to_top, win);
|
|
187 break;
|
|
188
|
|
189 case SB_THUMBTRACK:
|
|
190 case SB_THUMBPOSITION:
|
|
191 enqueue_misc_user_event (win, Qscrollbar_vertical_drag,
|
|
192 Fcons (win, make_int (pos)));
|
|
193 break;
|
|
194 }
|
|
195 }
|
|
196
|
|
197 #ifdef MEMORY_USAGE_STATS
|
|
198
|
|
199 static int
|
|
200 mswindows_compute_scrollbar_instance_usage (struct device *d,
|
|
201 struct scrollbar_instance *inst,
|
|
202 struct overhead_stats *ovstats)
|
|
203 {
|
|
204 int total = 0;
|
|
205
|
|
206 while (inst)
|
|
207 {
|
|
208 struct mswindows_scrollbar_data *data =
|
|
209 (struct mswindows_scrollbar_data *) inst->scrollbar_data;
|
|
210
|
|
211 total += malloced_storage_size (data, sizeof (*data), ovstats);
|
|
212 inst = inst->next;
|
|
213 }
|
|
214
|
|
215 return total;
|
|
216 }
|
|
217
|
|
218 #endif /* MEMORY_USAGE_STATS */
|
|
219
|
|
220 /************************************************************************/
|
|
221 /* initialization */
|
|
222 /************************************************************************/
|
|
223
|
|
224 void
|
|
225 console_type_create_scrollbar_mswindows (void)
|
|
226 {
|
|
227 CONSOLE_HAS_METHOD (mswindows, create_scrollbar_instance);
|
|
228 CONSOLE_HAS_METHOD (mswindows, free_scrollbar_instance);
|
|
229 CONSOLE_HAS_METHOD (mswindows, release_scrollbar_instance);
|
|
230 CONSOLE_HAS_METHOD (mswindows, update_scrollbar_instance_values);
|
|
231 CONSOLE_HAS_METHOD (mswindows, update_scrollbar_instance_status);
|
|
232 /* CONSOLE_HAS_METHOD (mswindows, scrollbar_width_changed_in_frame); */
|
|
233 #ifdef MEMORY_USAGE_STATS
|
|
234 CONSOLE_HAS_METHOD (mswindows, compute_scrollbar_instance_usage);
|
|
235 #endif
|
|
236 }
|
|
237
|
|
238 void
|
|
239 vars_of_scrollbar_mswindows(void)
|
|
240 {
|
|
241 Fprovide (intern ("mswindows-scrollbars"));
|
|
242 }
|
|
243
|