Mercurial > hg > xemacs-beta
comparison src/toolbar-msw.c @ 278:90d73dddcdc4 r21-0b37
Import from CVS: tag r21-0b37
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:31:29 +0200 |
parents | 6330739388db |
children | 7df0dd720c89 |
comparison
equal
deleted
inserted
replaced
277:cfdf3ff11843 | 278:90d73dddcdc4 |
---|---|
29 #include "faces.h" | 29 #include "faces.h" |
30 #include "frame.h" | 30 #include "frame.h" |
31 #include "toolbar.h" | 31 #include "toolbar.h" |
32 #include "window.h" | 32 #include "window.h" |
33 #include "gui.h" | 33 #include "gui.h" |
34 #include "elhash.h" | |
34 #include "console-msw.h" | 35 #include "console-msw.h" |
35 #include "glyphs-msw.h" | 36 #include "glyphs-msw.h" |
36 #include "objects-msw.h" | 37 #include "objects-msw.h" |
37 | 38 |
38 /* Why did Kirill choose this range ? */ | 39 /* Why did Kirill choose this range ? */ |
39 #define TOOLBAR_ITEM_ID_MIN 0x4000 | 40 #define TOOLBAR_ITEM_ID_MIN 0x4000 |
40 #define TOOLBAR_ITEM_ID_MAX 0x7FFF | 41 #define TOOLBAR_ITEM_ID_MAX 0x7FFF |
41 #define TOOLBAR_ITEM_ID_BITS(x) (((x) & 0x3FFF) | 0x4000) | 42 #define TOOLBAR_ITEM_ID_BITS(x) (((x) & 0x3FFF) | 0x4000) |
43 #define TOOLBAR_ID_BIAS 16 | |
44 #define TOOLBAR_HANDLE(f,p) \ | |
45 GetDlgItem(FRAME_MSWINDOWS_HANDLE(f), TOOLBAR_ID_BIAS + p) | |
42 #ifndef TB_SETIMAGELIST | 46 #ifndef TB_SETIMAGELIST |
43 #define TB_SETIMAGELIST (WM_USER + 48) | 47 #define TB_SETIMAGELIST (WM_USER + 48) |
44 #define TB_GETIMAGELIST (WM_USER + 49) | 48 #define TB_GETIMAGELIST (WM_USER + 49) |
49 #define TB_SETPADDING (WM_USER + 87) | |
45 #endif | 50 #endif |
46 | 51 |
47 #define SET_TOOLBAR_WAS_VISIBLE_FLAG(frame, pos, flag) \ | 52 #define SET_TOOLBAR_WAS_VISIBLE_FLAG(frame, pos, flag) \ |
48 do { \ | 53 do { \ |
49 switch (pos) \ | 54 switch (pos) \ |
64 abort (); \ | 69 abort (); \ |
65 } \ | 70 } \ |
66 } while (0) | 71 } while (0) |
67 | 72 |
68 static int | 73 static int |
69 allocate_toolbar_item_id (struct frame* f, struct toolbar_button* button) | 74 allocate_toolbar_item_id (struct frame* f, struct toolbar_button* button, |
75 enum toolbar_pos pos) | |
70 { | 76 { |
71 /* hmm what do we generate an id based on */ | 77 /* hmm what do we generate an id based on */ |
72 int id = TOOLBAR_ITEM_ID_BITS (internal_hash (button->callback, 0)); | 78 int id = TOOLBAR_ITEM_ID_BITS (internal_hash (button->callback, 0)); |
73 while (!NILP (Fgethash (make_int (id), | 79 while (!NILP (Fgethash (make_int (id), |
74 FRAME_MSWINDOWS_TOOLBAR_HASHTABLE (f), Qnil))) | 80 FRAME_MSWINDOWS_TOOLBAR_HASHTABLE (f), Qnil))) |
81 static void | 87 static void |
82 mswindows_clear_toolbar (struct frame *f, enum toolbar_pos pos, | 88 mswindows_clear_toolbar (struct frame *f, enum toolbar_pos pos, |
83 int thickness_change) | 89 int thickness_change) |
84 { | 90 { |
85 HIMAGELIST ilist=NULL; | 91 HIMAGELIST ilist=NULL; |
86 if (FRAME_MSWINDOWS_TOOLBAR (f)) | 92 int i; |
87 { | 93 HWND toolbarwnd = TOOLBAR_HANDLE(f, pos); |
88 /* get the image list and delete it */ | 94 if (toolbarwnd) |
89 SendMessage (FRAME_MSWINDOWS_TOOLBAR (f), | 95 { |
90 TB_GETIMAGELIST, 0, | 96 TBBUTTON info; |
91 (LONG) &ilist); | |
92 | 97 |
93 /* destroy the toolbar window */ | 98 /* delete the buttons and remove the command from the hashtable*/ |
94 DestroyWindow (FRAME_MSWINDOWS_TOOLBAR (f)); | 99 i = SendMessage (toolbarwnd, TB_BUTTONCOUNT, 0, 0); |
95 FRAME_MSWINDOWS_TOOLBAR (f) = 0; | 100 for (i--; i >= 0; i--) |
96 | 101 { |
102 SendMessage (toolbarwnd, TB_GETBUTTON, (WPARAM)i, | |
103 (LPARAM)&info); | |
104 Fremhash(make_int(info.idCommand), | |
105 FRAME_MSWINDOWS_TOOLBAR_HASHTABLE(f)); | |
106 SendMessage (toolbarwnd, TB_DELETEBUTTON, (WPARAM)i, 0); | |
107 } | |
108 | |
97 /* finally get rid of the image list assuming it clears up its | 109 /* finally get rid of the image list assuming it clears up its |
98 bitmaps */ | 110 bitmaps */ |
111 SendMessage (toolbarwnd, TB_GETIMAGELIST, 0, (LONG) &ilist); | |
99 if (ilist) | 112 if (ilist) |
100 { | 113 { |
101 ImageList_Destroy(ilist); | 114 ImageList_Destroy(ilist); |
102 } | 115 } |
103 } | 116 SendMessage (toolbarwnd, TB_SETIMAGELIST, 0, (LPARAM)NULL); |
117 | |
118 ShowWindow(toolbarwnd, SW_HIDE); | |
119 } | |
120 | |
121 FRAME_MSWINDOWS_TOOLBAR_CHECKSUM(f,pos)=0; | |
122 SET_TOOLBAR_WAS_VISIBLE_FLAG (f, pos, 0); | |
104 } | 123 } |
105 | 124 |
106 static void | 125 static void |
107 mswindows_output_toolbar (struct frame *f, enum toolbar_pos pos) | 126 mswindows_output_toolbar (struct frame *f, enum toolbar_pos pos) |
108 { | 127 { |
109 int x, y, bar_width, bar_height, vert; | 128 int x, y, bar_width, bar_height, vert; |
110 int width=-1, height=-1, bmwidth=-1, bmheight=-1; | 129 int width=-1, height=-1, bmwidth=-1, bmheight=-1; |
111 int border_width = FRAME_REAL_TOOLBAR_BORDER_WIDTH (f, pos); | 130 int border_width = FRAME_REAL_TOOLBAR_BORDER_WIDTH (f, pos); |
112 Lisp_Object button, window, glyph, instance; | 131 Lisp_Object button, window, glyph, instance; |
113 int nbuttons=0; | 132 int nbuttons=0; |
133 int shadow_thickness = 2; /* get this from somewhere else? */ | |
134 int window_frame_width = 3; | |
135 unsigned int checksum=0; | |
114 struct window *w; | 136 struct window *w; |
115 TBBUTTON* button_tbl, *tbbutton; | 137 TBBUTTON* button_tbl, *tbbutton; |
116 HIMAGELIST ilist=NULL; | 138 HIMAGELIST ilist=NULL; |
139 HWND toolbarwnd=NULL; | |
117 | 140 |
118 get_toolbar_coords (f, pos, &x, &y, &bar_width, &bar_height, &vert, 0); | 141 get_toolbar_coords (f, pos, &x, &y, &bar_width, &bar_height, &vert, 0); |
142 | |
143 if (x==1) | |
144 x=0; | |
145 | |
119 window = FRAME_LAST_NONMINIBUF_WINDOW (f); | 146 window = FRAME_LAST_NONMINIBUF_WINDOW (f); |
120 w = XWINDOW (window); | 147 w = XWINDOW (window); |
121 | 148 |
149 toolbarwnd = TOOLBAR_HANDLE(f,pos); | |
150 | |
122 /* set button sizes based on bar size */ | 151 /* set button sizes based on bar size */ |
123 if (vert) | 152 if (vert) |
124 { | 153 { |
125 width = height = bar_width - border_width * 2; | 154 width = height = bar_width; |
126 bmwidth = bmheight = width -2; | 155 bmwidth = bmheight = width - (border_width + shadow_thickness) * 2; |
127 } | 156 } |
128 else | 157 else |
129 { | 158 { |
130 height = width = bar_height - border_width * 2; | 159 height = width = bar_height - window_frame_width * 2; |
131 bmwidth = bmheight = width -2; | 160 bmwidth = bmheight = width - (border_width + shadow_thickness) * 2; |
132 } | 161 } |
133 | 162 |
134 button = FRAME_TOOLBAR_DATA (f, pos)->toolbar_buttons; | 163 button = FRAME_TOOLBAR_DATA (f, pos)->toolbar_buttons; |
135 | 164 |
136 /* First loop over all of the buttons to determine how many there | 165 /* First loop over all of the buttons to determine how many there |
138 instantiated so when we actually output them they will come up | 167 instantiated so when we actually output them they will come up |
139 immediately. */ | 168 immediately. */ |
140 while (!NILP (button)) | 169 while (!NILP (button)) |
141 { | 170 { |
142 struct toolbar_button *tb = XTOOLBAR_BUTTON (button); | 171 struct toolbar_button *tb = XTOOLBAR_BUTTON (button); |
172 checksum = HASH3 (checksum, | |
173 internal_hash (get_toolbar_button_glyph(w, tb), 0), | |
174 internal_hash (tb->callback, 0)); | |
143 button = tb->next; | 175 button = tb->next; |
144 nbuttons++; | 176 nbuttons++; |
145 } | 177 } |
146 | 178 |
147 /* build up the data required by win32 fns. */ | 179 /* only rebuild if something has changed */ |
148 button_tbl = xnew_array_and_zero (TBBUTTON, nbuttons); | 180 if (!toolbarwnd || FRAME_MSWINDOWS_TOOLBAR_CHECKSUM(f,pos)!=checksum) |
149 button = FRAME_TOOLBAR_DATA (f, pos)->toolbar_buttons; | 181 { |
150 tbbutton = button_tbl; | 182 /* remove the old one */ |
151 | 183 mswindows_clear_toolbar (f, pos, 0); |
152 while (!NILP (button)) | 184 |
153 { | 185 FRAME_MSWINDOWS_TOOLBAR_CHECKSUM(f,pos)=checksum; |
154 struct toolbar_button *tb = XTOOLBAR_BUTTON (button); | 186 |
155 | 187 /* build up the data required by win32 fns. */ |
156 tbbutton->idCommand = allocate_toolbar_item_id (f, tb); | 188 button_tbl = xnew_array_and_zero (TBBUTTON, nbuttons); |
157 tbbutton->fsState=tb->enabled ? TBSTATE_ENABLED : TBSTATE_INDETERMINATE; | 189 button = FRAME_TOOLBAR_DATA (f, pos)->toolbar_buttons; |
158 tbbutton->fsStyle=tb->blank ? TBSTYLE_SEP : TBSTYLE_BUTTON; | 190 tbbutton = button_tbl; |
159 tbbutton->dwData=0; | 191 |
160 tbbutton->iString=0; | 192 while (!NILP (button)) |
161 | 193 { |
162 /* mess with the button image */ | 194 struct toolbar_button *tb = XTOOLBAR_BUTTON (button); |
163 glyph = get_toolbar_button_glyph (w, tb); | 195 |
164 | 196 tbbutton->idCommand = allocate_toolbar_item_id (f, tb, pos); |
165 if (GLYPHP (glyph)) | 197 tbbutton->fsState=tb->enabled ? TBSTATE_ENABLED |
166 instance = glyph_image_instance (glyph, window, ERROR_ME_NOT, 1); | 198 : TBSTATE_INDETERMINATE; |
167 else | 199 tbbutton->fsStyle=tb->blank ? TBSTYLE_SEP : TBSTYLE_BUTTON; |
168 instance = Qnil; | 200 tbbutton->dwData=0; |
169 | 201 tbbutton->iString=0; |
170 if (IMAGE_INSTANCEP (instance)) | 202 |
171 { | 203 /* note that I am not doing the button size here. This is |
172 struct Lisp_Image_Instance* p = XIMAGE_INSTANCE (instance); | 204 because it is slightly out of my control and the main |
173 | 205 place they are used is in redisplay for getting events |
174 if (IMAGE_INSTANCE_PIXMAP_TYPE_P (p)) | 206 over toolbar buttons. Since the right way to do help echo |
207 is with tooltips I'm not going to bother with the extra | |
208 work involved. */ | |
209 | |
210 /* mess with the button image */ | |
211 glyph = get_toolbar_button_glyph (w, tb); | |
212 | |
213 if (GLYPHP (glyph)) | |
214 instance = glyph_image_instance (glyph, window, ERROR_ME_NOT, 1); | |
215 else | |
216 instance = Qnil; | |
217 | |
218 if (IMAGE_INSTANCEP (instance)) | |
175 { | 219 { |
176 /* we are going to honour the toolbar settings and | 220 struct Lisp_Image_Instance* p = XIMAGE_INSTANCE (instance); |
177 resize the bitmaps accordingly */ | |
178 | 221 |
179 if ((IMAGE_INSTANCE_PIXMAP_WIDTH (p) != bmwidth | 222 if (IMAGE_INSTANCE_PIXMAP_TYPE_P (p)) |
180 || | |
181 IMAGE_INSTANCE_PIXMAP_HEIGHT (p) != bmheight) | |
182 && | |
183 !mswindows_resize_dibitmap_instance (p, f, | |
184 bmwidth, bmheight)) | |
185 { | 223 { |
186 xfree (button_tbl); | 224 /* we are going to honour the toolbar settings and |
187 if (ilist) ImageList_Destroy (ilist); | 225 resize the bitmaps accordingly */ |
188 signal_simple_error ("couldn't resize pixmap", | 226 |
189 instance); | 227 if (IMAGE_INSTANCE_PIXMAP_WIDTH (p) > bmwidth |
190 } | 228 || |
229 IMAGE_INSTANCE_PIXMAP_HEIGHT (p) > bmheight) | |
230 { | |
231 if (!mswindows_resize_dibitmap_instance | |
232 (p, f, bmwidth, bmheight)) | |
233 { | |
234 xfree (button_tbl); | |
235 if (ilist) ImageList_Destroy (ilist); | |
236 signal_simple_error ("couldn't resize pixmap", | |
237 instance); | |
238 } | |
239 } | |
240 else | |
241 { | |
242 bmwidth = IMAGE_INSTANCE_PIXMAP_WIDTH (p); | |
243 bmheight = IMAGE_INSTANCE_PIXMAP_HEIGHT (p); | |
244 } | |
191 | 245 |
192 /* need to build an image list for the bitmaps */ | 246 /* need to build an image list for the bitmaps */ |
193 if (!ilist) | 247 if (!ilist) |
194 { | 248 { |
195 if (!(ilist = ImageList_Create | 249 if (!(ilist = ImageList_Create |
196 ( IMAGE_INSTANCE_PIXMAP_WIDTH (p), | 250 ( IMAGE_INSTANCE_PIXMAP_WIDTH (p), |
197 IMAGE_INSTANCE_PIXMAP_HEIGHT (p), | 251 IMAGE_INSTANCE_PIXMAP_HEIGHT (p), |
198 ILC_COLOR24, | 252 ILC_COLOR24, |
199 nbuttons, | 253 nbuttons, |
200 nbuttons * 2 ))) | 254 nbuttons * 2 ))) |
255 { | |
256 xfree (button_tbl); | |
257 signal_simple_error ("couldn't create image list", | |
258 instance); | |
259 } | |
260 } | |
261 | |
262 /* add a bitmap to the list */ | |
263 if ((tbbutton->iBitmap = | |
264 ImageList_Add (ilist, | |
265 IMAGE_INSTANCE_MSWINDOWS_BITMAP (p), | |
266 IMAGE_INSTANCE_MSWINDOWS_MASK (p))) < 0) | |
201 { | 267 { |
202 xfree (button_tbl); | 268 xfree (button_tbl); |
203 signal_simple_error ("couldn't create image list", | 269 if (ilist) ImageList_Destroy (ilist); |
270 signal_simple_error ("image list creation failed", | |
204 instance); | 271 instance); |
205 } | 272 } |
206 } | 273 } |
207 | |
208 /* add a bitmap to the list */ | |
209 if ((tbbutton->iBitmap = | |
210 ImageList_Add (ilist, | |
211 IMAGE_INSTANCE_MSWINDOWS_BITMAP (p), | |
212 IMAGE_INSTANCE_MSWINDOWS_MASK (p))) < 0) | |
213 { | |
214 xfree (button_tbl); | |
215 if (ilist) ImageList_Destroy (ilist); | |
216 signal_simple_error ("image list creation failed", | |
217 instance); | |
218 } | |
219 } | 274 } |
220 } | 275 |
221 | 276 Fputhash (make_int (tbbutton->idCommand), |
222 Fputhash (make_int (tbbutton->idCommand), | 277 button, FRAME_MSWINDOWS_TOOLBAR_HASHTABLE (f)); |
223 tb->callback, FRAME_MSWINDOWS_TOOLBAR_HASHTABLE (f)); | |
224 | 278 |
225 tbbutton++; | 279 tbbutton++; |
226 button = tb->next; | 280 button = tb->next; |
227 } | 281 } |
228 | 282 |
229 button = FRAME_TOOLBAR_DATA (f, pos)->toolbar_buttons; | 283 button = FRAME_TOOLBAR_DATA (f, pos)->toolbar_buttons; |
230 | 284 |
231 /* now create the toolbar ... */ | 285 /* create the toolbar window? */ |
232 if ((FRAME_MSWINDOWS_TOOLBAR (f) = | 286 if (!toolbarwnd |
233 CreateToolbarEx (FRAME_MSWINDOWS_HANDLE (f), | 287 && |
234 TBSTYLE_ALTDRAG | WS_CHILD, | 288 (toolbarwnd = |
235 NULL, | 289 CreateWindowEx ( WS_EX_WINDOWEDGE, |
236 nbuttons, | 290 TOOLBARCLASSNAME, |
237 0, | 291 NULL, |
238 0, | 292 WS_CHILD | WS_VISIBLE | WS_DLGFRAME | TBSTYLE_TOOLTIPS |
239 button_tbl, | 293 | CCS_NORESIZE | CCS_NOPARENTALIGN | CCS_NODIVIDER, |
240 nbuttons, | 294 x, y, bar_width, bar_height, |
241 width, height, | 295 FRAME_MSWINDOWS_HANDLE (f), |
242 bmwidth, bmheight, | 296 (HMENU)(TOOLBAR_ID_BIAS + pos), |
243 sizeof(TBBUTTON) )) == NULL) | 297 NULL, |
244 { | 298 NULL))==NULL) |
245 xfree (button_tbl); | 299 { |
246 ImageList_Destroy (ilist); | 300 xfree (button_tbl); |
247 error ("couldn't create toolbar"); | 301 ImageList_Destroy (ilist); |
248 } | 302 error ("couldn't create toolbar"); |
249 | 303 } |
250 /* finally populate with images */ | |
251 if (SendMessage (FRAME_MSWINDOWS_TOOLBAR (f), TB_SETIMAGELIST, NULL, | |
252 (LPARAM)ilist) == -1) | |
253 { | |
254 mswindows_clear_toolbar (f, pos, 0); | |
255 error ("couldn't add image list to toolbar"); | |
256 } | |
257 | |
258 /* now move the window */ | |
259 SetWindowPos (FRAME_MSWINDOWS_TOOLBAR (f), HWND_TOP, x, y, | |
260 bar_width, bar_height, | |
261 SWP_SHOWWINDOW); | |
262 #if 0 | 304 #if 0 |
263 ShowWindow (FRAME_MSWINDOWS_TOOLBAR (f), SW_SHOWNORMAL); | 305 SendMessage (toolbarwnd, TB_SETPADDING, |
306 0, MAKELPARAM(border_width, border_width)); | |
264 #endif | 307 #endif |
265 | 308 /* finally populate with images */ |
266 if (button_tbl) xfree (button_tbl); | 309 if (SendMessage (toolbarwnd, TB_BUTTONSTRUCTSIZE, |
267 | 310 (WPARAM)sizeof(TBBUTTON), (LPARAM)0) == -1) |
268 SET_TOOLBAR_WAS_VISIBLE_FLAG (f, pos, 1); | 311 { |
312 mswindows_clear_toolbar (f, pos, 0); | |
313 error ("couldn't set button structure size"); | |
314 } | |
315 | |
316 /* set the size of buttons */ | |
317 SendMessage (toolbarwnd, TB_SETBUTTONSIZE, 0, | |
318 (LPARAM)MAKELONG (width, height)); | |
319 | |
320 /* set the size of bitmaps */ | |
321 SendMessage (toolbarwnd, TB_SETBITMAPSIZE, 0, | |
322 (LPARAM)MAKELONG (bmwidth, bmheight)); | |
323 | |
324 /* finally populate with images */ | |
325 if (!SendMessage (toolbarwnd, TB_ADDBUTTONS, | |
326 (WPARAM)nbuttons, (LPARAM)button_tbl)) | |
327 { | |
328 mswindows_clear_toolbar (f, pos, 0); | |
329 error ("couldn't add button list to toolbar"); | |
330 } | |
331 | |
332 /* vertical toolbars need more rows */ | |
333 if (vert) | |
334 { | |
335 SendMessage (toolbarwnd, TB_SETROWS, | |
336 MAKEWPARAM(nbuttons, FALSE), 0); | |
337 } | |
338 | |
339 else | |
340 { | |
341 SendMessage (toolbarwnd, TB_SETROWS, MAKEWPARAM(1, FALSE), 0); | |
342 } | |
343 | |
344 /* finally populate with images */ | |
345 if (SendMessage (toolbarwnd, TB_SETIMAGELIST, 0, | |
346 (LPARAM)ilist) == -1) | |
347 { | |
348 mswindows_clear_toolbar (f, pos, 0); | |
349 error ("couldn't add image list to toolbar"); | |
350 } | |
351 | |
352 /* now display the window */ | |
353 ShowWindow (toolbarwnd, SW_SHOW); | |
354 | |
355 if (button_tbl) xfree (button_tbl); | |
356 | |
357 SET_TOOLBAR_WAS_VISIBLE_FLAG (f, pos, 1); | |
358 } | |
359 } | |
360 | |
361 static void | |
362 mswindows_move_toolbar (struct frame *f, enum toolbar_pos pos) | |
363 { | |
364 int bar_x, bar_y, bar_width, bar_height, vert; | |
365 HWND toolbarwnd = TOOLBAR_HANDLE(f,pos); | |
366 | |
367 if (toolbarwnd) | |
368 { | |
369 get_toolbar_coords (f, pos, &bar_x, &bar_y, &bar_width, &bar_height, | |
370 &vert, 1); | |
371 | |
372 /* #### This terrible mangling with coordinates perhaps | |
373 arises from different treatment of toolbar positions | |
374 by Windows and by XEmacs. */ | |
375 switch (pos) | |
376 { | |
377 case TOP_TOOLBAR: | |
378 bar_x -= 2; bar_y--; | |
379 bar_width += 2; bar_height++; | |
380 break; | |
381 case LEFT_TOOLBAR: | |
382 bar_x -= 2; bar_y--; | |
383 bar_width++; bar_height++; | |
384 break; | |
385 case BOTTOM_TOOLBAR: | |
386 bar_x--; | |
387 bar_width++; | |
388 break; | |
389 case RIGHT_TOOLBAR: | |
390 bar_y--; | |
391 break; | |
392 } | |
393 SetWindowPos (toolbarwnd, NULL, bar_x, bar_y, | |
394 bar_width + 1, bar_height + 1, SWP_NOZORDER); | |
395 } | |
396 } | |
397 | |
398 static void | |
399 mswindows_redraw_exposed_toolbars (struct frame *f, int x, int y, int width, | |
400 int height) | |
401 { | |
402 assert (FRAME_MSWINDOWS_P (f)); | |
403 | |
404 if (FRAME_REAL_TOP_TOOLBAR_VISIBLE (f)) | |
405 mswindows_move_toolbar (f, TOP_TOOLBAR); | |
406 | |
407 if (FRAME_REAL_BOTTOM_TOOLBAR_VISIBLE (f)) | |
408 mswindows_move_toolbar (f, BOTTOM_TOOLBAR); | |
409 | |
410 if (FRAME_REAL_LEFT_TOOLBAR_VISIBLE (f)) | |
411 mswindows_move_toolbar (f, LEFT_TOOLBAR); | |
412 | |
413 if (FRAME_REAL_RIGHT_TOOLBAR_VISIBLE (f)) | |
414 mswindows_move_toolbar (f, RIGHT_TOOLBAR); | |
269 } | 415 } |
270 | 416 |
271 static void | 417 static void |
272 mswindows_initialize_frame_toolbars (struct frame *f) | 418 mswindows_initialize_frame_toolbars (struct frame *f) |
273 { | 419 { |
301 } | 447 } |
302 | 448 |
303 static void | 449 static void |
304 mswindows_free_frame_toolbars (struct frame *f) | 450 mswindows_free_frame_toolbars (struct frame *f) |
305 { | 451 { |
306 mswindows_clear_toolbar(f, 0, 0); | 452 HWND twnd=NULL; |
453 #define DELETE_TOOLBAR(pos) \ | |
454 mswindows_clear_toolbar(f, 0, pos); \ | |
455 if ((twnd=GetDlgItem(FRAME_MSWINDOWS_HANDLE(f), TOOLBAR_ID_BIAS + pos))) \ | |
456 DestroyWindow(twnd) | |
457 | |
458 DELETE_TOOLBAR(TOP_TOOLBAR); | |
459 DELETE_TOOLBAR(BOTTOM_TOOLBAR); | |
460 DELETE_TOOLBAR(LEFT_TOOLBAR); | |
461 DELETE_TOOLBAR(RIGHT_TOOLBAR); | |
462 #undef DELETE_TOOLBAR | |
463 } | |
464 | |
465 /* map toolbar hwnd to pos*/ | |
466 int mswindows_find_toolbar_pos(struct frame* f, HWND ctrl) | |
467 { | |
468 #if 1 | |
469 int id = GetDlgCtrlID(ctrl); | |
470 return id ? id - TOOLBAR_ID_BIAS : -1; | |
471 #else | |
472 if (GetDlgItem(FRAME_MSWINDOWS_HANDLE(f), TOOLBAR_ID_BIAS) == ctrl) | |
473 return 0; | |
474 else if (GetDlgItem(FRAME_MSWINDOWS_HANDLE(f), TOOLBAR_ID_BIAS +1) == ctrl) | |
475 return 1; | |
476 else if (GetDlgItem(FRAME_MSWINDOWS_HANDLE(f), TOOLBAR_ID_BIAS +2) == ctrl) | |
477 return 2; | |
478 else if (GetDlgItem(FRAME_MSWINDOWS_HANDLE(f), TOOLBAR_ID_BIAS +3) == ctrl) | |
479 return 3; | |
480 else | |
481 assert(0); | |
482 #endif | |
483 } | |
484 | |
485 Lisp_Object | |
486 mswindows_get_toolbar_button_text ( struct frame* f, int command_id ) | |
487 { | |
488 Lisp_Object button = Fgethash (make_int (command_id), | |
489 FRAME_MSWINDOWS_TOOLBAR_HASHTABLE (f), Qnil); | |
490 | |
491 if (!NILP (button)) | |
492 { | |
493 struct toolbar_button *tb = XTOOLBAR_BUTTON (button); | |
494 return tb->help_string; | |
495 } | |
496 return Qnil; | |
307 } | 497 } |
308 | 498 |
309 /* | 499 /* |
310 * Return value is Qt if we have dispatched the command, | 500 * Return value is Qt if we have dispatched the command, |
311 * or Qnil if id has not been mapped to a callback. | 501 * or Qnil if id has not been mapped to a callback. |
312 * Window procedure may try other targets to route the | 502 * Window procedure may try other targets to route the |
313 * command if we return nil | 503 * command if we return nil |
314 */ | 504 */ |
315 Lisp_Object | 505 Lisp_Object |
316 mswindows_handle_toolbar_wm_command (struct frame* f, WORD id) | 506 mswindows_handle_toolbar_wm_command (struct frame* f, HWND ctrl, WORD id) |
317 { | 507 { |
318 /* Try to map the command id through the proper hash table */ | 508 /* Try to map the command id through the proper hash table */ |
319 Lisp_Object command, funcsym, frame; | 509 Lisp_Object button, command, funcsym, frame; |
320 struct gcpro gcpro1; | 510 struct gcpro gcpro1; |
321 | 511 |
322 command = Fgethash (make_int (id), | 512 button = Fgethash (make_int (id), |
323 FRAME_MSWINDOWS_TOOLBAR_HASHTABLE (f), Qunbound); | 513 FRAME_MSWINDOWS_TOOLBAR_HASHTABLE (f), Qnil); |
324 if (UNBOUNDP (command)) | 514 |
325 { | 515 if (NILP (button)) |
326 return Qnil; | 516 return Qnil; |
327 } | 517 |
328 | 518 command = XTOOLBAR_BUTTON(button)->callback; |
519 | |
520 if (UNBOUNDP(command)) | |
521 return Qnil; | |
522 | |
329 /* Need to gcpro because the hashtable may get destroyed | 523 /* Need to gcpro because the hashtable may get destroyed |
330 by menu_cleanup(), and will not gcpro the command | 524 by menu_cleanup(), and will not gcpro the command |
331 any more */ | 525 any more */ |
332 GCPRO1 (command); | 526 GCPRO1 (command); |
333 | 527 |
361 console_type_create_toolbar_mswindows (void) | 555 console_type_create_toolbar_mswindows (void) |
362 { | 556 { |
363 CONSOLE_HAS_METHOD (mswindows, output_frame_toolbars); | 557 CONSOLE_HAS_METHOD (mswindows, output_frame_toolbars); |
364 CONSOLE_HAS_METHOD (mswindows, initialize_frame_toolbars); | 558 CONSOLE_HAS_METHOD (mswindows, initialize_frame_toolbars); |
365 CONSOLE_HAS_METHOD (mswindows, free_frame_toolbars); | 559 CONSOLE_HAS_METHOD (mswindows, free_frame_toolbars); |
366 } | 560 CONSOLE_HAS_METHOD (mswindows, redraw_exposed_toolbars); |
367 | 561 } |
562 |