Mercurial > hg > xemacs-beta
comparison src/scrollbar-msw.c @ 375:a300bb07d72d r21-2b3
Import from CVS: tag r21-2b3
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:04:51 +0200 |
parents | cc15677e0335 |
children | 8626e4521993 |
comparison
equal
deleted
inserted
replaced
374:4ebeb1a5388b | 375:a300bb07d72d |
---|---|
32 #include "scrollbar-msw.h" | 32 #include "scrollbar-msw.h" |
33 #include "scrollbar.h" | 33 #include "scrollbar.h" |
34 #include "specifier.h" | 34 #include "specifier.h" |
35 #include "window.h" | 35 #include "window.h" |
36 | 36 |
37 /* This has really different semantics in Windows than in Motif. | 37 /* We use a similar sort of vertical scrollbar drag hack for mswindows |
38 There's no corresponding method; we just do not change slider | 38 * scrollbars as is used for Motif or Lucid scrollbars under X. |
39 size while dragging. It makes the scrollbar look smother and | 39 * We do character-based instead of line-based scrolling, which can mean that |
40 prevents some weird behavior when scrolled near the bottom */ | 40 * without the hack it is impossible to drag to the end of a buffer. */ |
41 static int inhibit_slider_size_change = 0; | 41 #define VERTICAL_SCROLLBAR_DRAG_HACK |
42 | |
43 static int vertical_drag_in_progress = 0; | |
42 | 44 |
43 static void | 45 static void |
44 mswindows_create_scrollbar_instance (struct frame *f, int vertical, | 46 mswindows_create_scrollbar_instance (struct frame *f, int vertical, |
45 struct scrollbar_instance *sb) | 47 struct scrollbar_instance *sb) |
46 { | 48 { |
57 CreateWindowEx(0, "SCROLLBAR", 0, orientation|WS_CHILD, | 59 CreateWindowEx(0, "SCROLLBAR", 0, orientation|WS_CHILD, |
58 CW_USEDEFAULT, CW_USEDEFAULT, | 60 CW_USEDEFAULT, CW_USEDEFAULT, |
59 CW_USEDEFAULT, CW_USEDEFAULT, | 61 CW_USEDEFAULT, CW_USEDEFAULT, |
60 FRAME_MSWINDOWS_HANDLE (f), | 62 FRAME_MSWINDOWS_HANDLE (f), |
61 NULL, NULL, NULL); | 63 NULL, NULL, NULL); |
64 SCROLLBAR_MSW_INFO (sb).cbSize = sizeof(SCROLLINFO); | |
62 SCROLLBAR_MSW_INFO (sb).fMask = SIF_ALL; | 65 SCROLLBAR_MSW_INFO (sb).fMask = SIF_ALL; |
63 GetScrollInfo(SCROLLBAR_MSW_HANDLE (sb), SB_CTL, | 66 GetScrollInfo(SCROLLBAR_MSW_HANDLE (sb), SB_CTL, |
64 &SCROLLBAR_MSW_INFO (sb)); | 67 &SCROLLBAR_MSW_INFO (sb)); |
65 SetWindowLong (SCROLLBAR_MSW_HANDLE(sb), GWL_USERDATA, (LONG)sb); | 68 SetWindowLong (SCROLLBAR_MSW_HANDLE(sb), GWL_USERDATA, (LONG)sb); |
66 | 69 |
108 int new_scrollbar_width, | 111 int new_scrollbar_width, |
109 int new_scrollbar_height, | 112 int new_scrollbar_height, |
110 int new_scrollbar_x, | 113 int new_scrollbar_x, |
111 int new_scrollbar_y) | 114 int new_scrollbar_y) |
112 { | 115 { |
113 struct frame *f; | |
114 int pos_changed = 0; | 116 int pos_changed = 0; |
115 | 117 int vert = GetWindowLong (SCROLLBAR_MSW_HANDLE (sb), GWL_STYLE) & SBS_VERT; |
116 f = XFRAME (w->frame); | |
117 | 118 |
118 #if 0 | 119 #if 0 |
119 stderr_out ("[%d, %d], page = %d, pos = %d, inhibit = %d\n", new_minimum, new_maximum, | 120 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 new_slider_size, new_slider_position,inhibit_slider_size_change); |
121 #endif | 122 #endif |
122 | 123 |
123 /* These might be optimized, but since at least one will change at each | 124 /* These might be optimized, but since at least one will change at each |
124 call, it's probably not worth it. */ | 125 call, it's probably not worth it. */ |
125 SCROLLBAR_MSW_INFO (sb).cbSize = sizeof(SCROLLINFO); | |
126 SCROLLBAR_MSW_INFO (sb).nMin = new_minimum; | 126 SCROLLBAR_MSW_INFO (sb).nMin = new_minimum; |
127 SCROLLBAR_MSW_INFO (sb).nMax = new_maximum; | 127 SCROLLBAR_MSW_INFO (sb).nMax = new_maximum; |
128 SCROLLBAR_MSW_INFO (sb).nPage = new_slider_size + 1; /* for DISABLENOSCROLL */ | 128 SCROLLBAR_MSW_INFO (sb).nPage = new_slider_size + 1; /* +1 for DISABLENOSCROLL */ |
129 SCROLLBAR_MSW_INFO (sb).nPos = new_slider_position; | 129 SCROLLBAR_MSW_INFO (sb).nPos = new_slider_position; |
130 SCROLLBAR_MSW_INFO (sb).fMask = (inhibit_slider_size_change | 130 #ifndef VERTICAL_SCROLLBAR_DRAG_HACK |
131 SCROLLBAR_MSW_INFO (sb).fMask = ((vert && vertical_drag_in_progress) | |
131 ? SIF_RANGE | SIF_POS | 132 ? SIF_RANGE | SIF_POS |
132 : SIF_ALL | SIF_DISABLENOSCROLL); | 133 : SIF_ALL | SIF_DISABLENOSCROLL); |
133 | 134 #else |
134 SetScrollInfo(SCROLLBAR_MSW_HANDLE (sb), SB_CTL, &SCROLLBAR_MSW_INFO (sb), | 135 SCROLLBAR_MSW_INFO (sb).fMask = SIF_ALL | SIF_DISABLENOSCROLL; |
135 !pos_changed); | 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); | |
136 | 143 |
137 UPDATE_POS_FIELD (scrollbar_x); | 144 UPDATE_POS_FIELD (scrollbar_x); |
138 UPDATE_POS_FIELD (scrollbar_y); | 145 UPDATE_POS_FIELD (scrollbar_y); |
139 UPDATE_POS_FIELD (scrollbar_width); | 146 UPDATE_POS_FIELD (scrollbar_width); |
140 UPDATE_POS_FIELD (scrollbar_height); | 147 UPDATE_POS_FIELD (scrollbar_height); |
169 struct frame *f; | 176 struct frame *f; |
170 Lisp_Object win, frame; | 177 Lisp_Object win, frame; |
171 struct scrollbar_instance *sb; | 178 struct scrollbar_instance *sb; |
172 SCROLLINFO scrollinfo; | 179 SCROLLINFO scrollinfo; |
173 int vert = GetWindowLong (hwnd, GWL_STYLE) & SBS_VERT; | 180 int vert = GetWindowLong (hwnd, GWL_STYLE) & SBS_VERT; |
181 int value; | |
174 | 182 |
175 sb = (struct scrollbar_instance *)GetWindowLong (hwnd, GWL_USERDATA); | 183 sb = (struct scrollbar_instance *)GetWindowLong (hwnd, GWL_USERDATA); |
176 win = real_window (sb->mirror, 1); | 184 win = real_window (sb->mirror, 1); |
177 frame = XWINDOW (win)->frame; | 185 frame = XWINDOW (win)->frame; |
178 f = XFRAME (frame); | 186 f = XFRAME (frame); |
179 | 187 |
180 inhibit_slider_size_change = code == SB_THUMBTRACK; | |
181 | |
182 /* SB_LINEDOWN == SB_CHARLEFT etc. This is the way they will | 188 /* SB_LINEDOWN == SB_CHARLEFT etc. This is the way they will |
183 always be - any Windows is binary compatible backward with | 189 always be - any Windows is binary compatible backward with |
184 old programs */ | 190 old programs */ |
185 | 191 |
186 switch (code) | 192 switch (code) |
219 break; | 225 break; |
220 | 226 |
221 case SB_THUMBTRACK: | 227 case SB_THUMBTRACK: |
222 case SB_THUMBPOSITION: | 228 case SB_THUMBPOSITION: |
223 scrollinfo.cbSize = sizeof(SCROLLINFO); | 229 scrollinfo.cbSize = sizeof(SCROLLINFO); |
224 scrollinfo.fMask = SIF_TRACKPOS; | 230 scrollinfo.fMask = SIF_ALL; |
225 GetScrollInfo (hwnd, SB_CTL, &scrollinfo); | 231 GetScrollInfo (hwnd, SB_CTL, &scrollinfo); |
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; | |
226 mswindows_enqueue_misc_user_event | 250 mswindows_enqueue_misc_user_event |
227 (frame, | 251 (frame, |
228 vert ? Qscrollbar_vertical_drag : Qscrollbar_horizontal_drag, | 252 vert ? Qscrollbar_vertical_drag : Qscrollbar_horizontal_drag, |
229 Fcons (win, make_int (scrollinfo.nTrackPos))); | 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; | |
230 break; | 264 break; |
231 } | 265 } |
232 } | 266 } |
233 | 267 |
234 #ifdef MEMORY_USAGE_STATS | 268 #ifdef MEMORY_USAGE_STATS |