Mercurial > hg > xemacs-beta
comparison src/toolbar-msw.c @ 288:e11d67e05968 r21-0b42
Import from CVS: tag r21-0b42
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:35:54 +0200 |
parents | 57709be46d1b |
children | 4b85ae5eabfb |
comparison
equal
deleted
inserted
replaced
287:13a0bd77a29d | 288:e11d67e05968 |
---|---|
47 #define TOOLBAR_HANDLE(f,p) \ | 47 #define TOOLBAR_HANDLE(f,p) \ |
48 GetDlgItem(FRAME_MSWINDOWS_HANDLE(f), TOOLBAR_ID_BIAS + p) | 48 GetDlgItem(FRAME_MSWINDOWS_HANDLE(f), TOOLBAR_ID_BIAS + p) |
49 #ifndef TB_SETIMAGELIST | 49 #ifndef TB_SETIMAGELIST |
50 #define TB_SETIMAGELIST (WM_USER + 48) | 50 #define TB_SETIMAGELIST (WM_USER + 48) |
51 #define TB_GETIMAGELIST (WM_USER + 49) | 51 #define TB_GETIMAGELIST (WM_USER + 49) |
52 #define TB_SETDISABLEDIMAGELIST (WM_USER + 54) | |
53 #define TB_GETDISABLEDIMAGELIST (WM_USER + 55) | |
54 #endif | |
55 #ifndef TB_SETPADDING | |
52 #define TB_SETPADDING (WM_USER + 87) | 56 #define TB_SETPADDING (WM_USER + 87) |
53 #endif | 57 #endif |
58 #define MSWINDOWS_BUTTON_SHADOW_THICKNESS 2 | |
59 #define MSWINDOWS_BLANK_SIZE 5 | |
54 | 60 |
55 #define SET_TOOLBAR_WAS_VISIBLE_FLAG(frame, pos, flag) \ | 61 #define SET_TOOLBAR_WAS_VISIBLE_FLAG(frame, pos, flag) \ |
56 do { \ | 62 do { \ |
57 switch (pos) \ | 63 switch (pos) \ |
58 { \ | 64 { \ |
127 | 133 |
128 static void | 134 static void |
129 mswindows_output_toolbar (struct frame *f, enum toolbar_pos pos) | 135 mswindows_output_toolbar (struct frame *f, enum toolbar_pos pos) |
130 { | 136 { |
131 int x, y, bar_width, bar_height, vert; | 137 int x, y, bar_width, bar_height, vert; |
132 int width=-1, height=-1, bmwidth=-1, bmheight=-1; | 138 int width=-1, height=-1, bmwidth=0, bmheight=0, maxbmwidth, maxbmheight; |
139 int style_3d=0; | |
133 int border_width = FRAME_REAL_TOOLBAR_BORDER_WIDTH (f, pos); | 140 int border_width = FRAME_REAL_TOOLBAR_BORDER_WIDTH (f, pos); |
134 Lisp_Object button, window, glyph, instance; | 141 Lisp_Object button, glyph, instance; |
142 Lisp_Object window = FRAME_LAST_NONMINIBUF_WINDOW (f); | |
143 | |
135 int nbuttons=0; | 144 int nbuttons=0; |
136 int shadow_thickness = 2; /* get this from somewhere else? */ | 145 int shadow_thickness = 2; /* get this from somewhere else? */ |
137 int window_frame_width = 3; | 146 int window_frame_width = 3; |
147 int padding = (border_width + shadow_thickness) * 2; | |
138 unsigned int checksum=0; | 148 unsigned int checksum=0; |
139 struct window *w; | 149 struct window *w = XWINDOW (window); |
140 TBBUTTON* button_tbl, *tbbutton; | 150 TBBUTTON* button_tbl, *tbbutton; |
141 HIMAGELIST ilist=NULL; | 151 HIMAGELIST ilist=NULL; |
142 HWND toolbarwnd=NULL; | 152 HWND toolbarwnd=NULL; |
143 | 153 |
144 get_toolbar_coords (f, pos, &x, &y, &bar_width, &bar_height, &vert, 0); | 154 get_toolbar_coords (f, pos, &x, &y, &bar_width, &bar_height, &vert, 0); |
145 | 155 |
146 if (x==1) | 156 if (x==1) |
147 x=0; | 157 x=0; |
148 | |
149 window = FRAME_LAST_NONMINIBUF_WINDOW (f); | |
150 w = XWINDOW (window); | |
151 | 158 |
152 toolbarwnd = TOOLBAR_HANDLE (f,pos); | 159 toolbarwnd = TOOLBAR_HANDLE (f,pos); |
153 | 160 |
154 /* set button sizes based on bar size */ | 161 /* set button sizes based on bar size */ |
155 if (vert) | 162 if (vert) |
156 { | 163 { |
157 width = height = bar_width | 164 if (style_3d) |
158 - (window_frame_width + shadow_thickness) * 2; | 165 { |
159 bmwidth = bmheight = width - (border_width + shadow_thickness) * 2; | 166 width = height = bar_width |
167 - (window_frame_width + shadow_thickness) * 2; | |
168 } | |
169 else | |
170 width = height = bar_width; | |
171 | |
172 maxbmwidth = maxbmheight = width - padding; | |
160 } | 173 } |
161 else | 174 else |
162 { | 175 { |
163 height = width = bar_height | 176 if (style_3d) |
164 - (window_frame_width + shadow_thickness) * 2; | 177 { |
165 bmwidth = bmheight = width - (border_width + shadow_thickness) * 2; | 178 height = width = bar_height |
179 - (window_frame_width + shadow_thickness) * 2; | |
180 } | |
181 else | |
182 width = height = bar_height; | |
183 | |
184 maxbmwidth = maxbmheight = width - padding; | |
166 } | 185 } |
167 | 186 |
168 button = FRAME_TOOLBAR_BUTTONS (f, pos); | 187 button = FRAME_TOOLBAR_BUTTONS (f, pos); |
169 | 188 |
170 /* First loop over all of the buttons to determine how many there | 189 /* First loop over all of the buttons to determine how many there |
198 | 217 |
199 while (!NILP (button)) | 218 while (!NILP (button)) |
200 { | 219 { |
201 struct toolbar_button *tb = XTOOLBAR_BUTTON (button); | 220 struct toolbar_button *tb = XTOOLBAR_BUTTON (button); |
202 HBITMAP bitmap=NULL, mask=NULL; | 221 HBITMAP bitmap=NULL, mask=NULL; |
203 | 222 bitmap=mask=NULL; |
204 tbbutton->idCommand = allocate_toolbar_item_id (f, tb, pos); | 223 |
205 tbbutton->fsState=tb->enabled ? TBSTATE_ENABLED | 224 if (tb->blank) |
206 : TBSTATE_INDETERMINATE; | 225 tbbutton->fsStyle = TBSTYLE_SEP; |
207 tbbutton->fsStyle=tb->blank ? TBSTYLE_SEP : TBSTYLE_BUTTON; | 226 else |
208 tbbutton->dwData=0; | |
209 tbbutton->iString=0; | |
210 | |
211 /* note that I am not doing the button size here. This is | |
212 because it is slightly out of my control and the main | |
213 place they are used is in redisplay for getting events | |
214 over toolbar buttons. Since the right way to do help echo | |
215 is with tooltips I'm not going to bother with the extra | |
216 work involved. */ | |
217 | |
218 /* mess with the button image */ | |
219 glyph = get_toolbar_button_glyph (w, tb); | |
220 | |
221 if (GLYPHP (glyph)) | |
222 instance = glyph_image_instance (glyph, window, ERROR_ME_NOT, 1); | |
223 else | |
224 instance = Qnil; | |
225 | |
226 if (IMAGE_INSTANCEP (instance)) | |
227 { | 227 { |
228 struct Lisp_Image_Instance* p = XIMAGE_INSTANCE (instance); | 228 tbbutton->idCommand = allocate_toolbar_item_id (f, tb, pos); |
229 /* currently we output the toolbar again with disabled | |
230 buttons it might be good to use the ms disabled code | |
231 instead but that means another image list, so we'll stick | |
232 with the emacs model. */ | |
233 tbbutton->fsState = tb->enabled ? TBSTATE_ENABLED : | |
234 TBSTATE_INDETERMINATE; | |
235 tbbutton->fsStyle = TBSTYLE_BUTTON; | |
236 tbbutton->dwData=0; | |
237 tbbutton->iString=0; | |
229 | 238 |
230 if (IMAGE_INSTANCE_PIXMAP_TYPE_P (p)) | 239 /* mess with the button image */ |
240 glyph = get_toolbar_button_glyph (w, tb); | |
241 | |
242 if (GLYPHP (glyph)) | |
243 instance = glyph_image_instance (glyph, window, | |
244 ERROR_ME_NOT, 1); | |
245 else | |
246 instance = Qnil; | |
247 | |
248 if (IMAGE_INSTANCEP (instance)) | |
231 { | 249 { |
232 /* we are going to honour the toolbar settings and | 250 struct Lisp_Image_Instance* p = XIMAGE_INSTANCE (instance); |
233 resize the bitmaps accordingly */ | |
234 | 251 |
235 if (IMAGE_INSTANCE_PIXMAP_WIDTH (p) != bmwidth | 252 if (IMAGE_INSTANCE_PIXMAP_TYPE_P (p)) |
236 || | |
237 IMAGE_INSTANCE_PIXMAP_HEIGHT (p) != bmheight) | |
238 { | 253 { |
239 if (! (bitmap = mswindows_create_resized_bitmap | 254 /* we are going to honour the toolbar settings |
240 (p, f, bmwidth, bmheight))) | 255 and resize the bitmaps accordingly if they are |
256 too big. If they are too small we leave them | |
257 and pad the difference - unless a different size | |
258 crops up in the middle, at which point we *have* | |
259 to resize since the ImageList won't cope.*/ | |
260 | |
261 if ((bmwidth | |
262 && | |
263 IMAGE_INSTANCE_PIXMAP_WIDTH (p) != bmwidth) | |
264 || | |
265 (bmheight | |
266 && | |
267 IMAGE_INSTANCE_PIXMAP_HEIGHT (p) != bmheight) | |
268 || | |
269 IMAGE_INSTANCE_PIXMAP_WIDTH (p) > maxbmwidth | |
270 || | |
271 IMAGE_INSTANCE_PIXMAP_HEIGHT (p) > maxbmheight) | |
272 { | |
273 if (!bmheight) | |
274 bmheight = min (maxbmheight, | |
275 IMAGE_INSTANCE_PIXMAP_HEIGHT (p)); | |
276 if (!bmwidth) | |
277 bmwidth = min (maxbmwidth, | |
278 IMAGE_INSTANCE_PIXMAP_WIDTH (p)); | |
279 | |
280 if (! (bitmap = mswindows_create_resized_bitmap | |
281 (p, f, bmwidth, bmheight))) | |
282 { | |
283 xfree (button_tbl); | |
284 if (ilist) ImageList_Destroy (ilist); | |
285 signal_simple_error ("couldn't resize pixmap", | |
286 instance); | |
287 } | |
288 /* we don't care if the mask fails */ | |
289 mask = mswindows_create_resized_mask | |
290 (p, f, bmwidth, bmheight); | |
291 } | |
292 else | |
293 { | |
294 if (!bmwidth) | |
295 bmwidth = IMAGE_INSTANCE_PIXMAP_WIDTH (p); | |
296 if (!bmheight) | |
297 bmheight = IMAGE_INSTANCE_PIXMAP_HEIGHT (p); | |
298 } | |
299 | |
300 /* need to build an image list for the bitmaps */ | |
301 if (!ilist && !(ilist = ImageList_Create | |
302 ( bmwidth, bmheight, | |
303 ILC_COLOR24, nbuttons, nbuttons * 2 ))) | |
304 { | |
305 xfree (button_tbl); | |
306 signal_simple_error ("couldn't create image list", | |
307 instance); | |
308 } | |
309 | |
310 /* add a bitmap to the list */ | |
311 if ((tbbutton->iBitmap = | |
312 ImageList_Add | |
313 (ilist, | |
314 bitmap ? bitmap | |
315 : IMAGE_INSTANCE_MSWINDOWS_BITMAP (p), | |
316 mask ? mask | |
317 : IMAGE_INSTANCE_MSWINDOWS_MASK (p))) < 0) | |
241 { | 318 { |
242 xfree (button_tbl); | 319 xfree (button_tbl); |
243 if (ilist) ImageList_Destroy (ilist); | 320 if (ilist) ImageList_Destroy (ilist); |
244 signal_simple_error ("couldn't resize pixmap", | 321 signal_simple_error |
245 instance); | 322 ("couldn't add image to image list", instance); |
246 } | 323 } |
247 /* we don't care if the mask fails */ | 324 /* we're done with these now */ |
248 mask = mswindows_create_resized_mask | 325 DeleteObject (bitmap); |
249 (p, f, bmwidth, bmheight); | 326 DeleteObject (mask); |
250 } | 327 } |
251 else | |
252 { | |
253 bmwidth = IMAGE_INSTANCE_PIXMAP_WIDTH (p); | |
254 bmheight = IMAGE_INSTANCE_PIXMAP_HEIGHT (p); | |
255 } | |
256 | |
257 /* need to build an image list for the bitmaps */ | |
258 if (!ilist && !(ilist = ImageList_Create | |
259 ( bmwidth, bmheight, | |
260 ILC_COLOR24, nbuttons, nbuttons * 2 ))) | |
261 { | |
262 xfree (button_tbl); | |
263 signal_simple_error ("couldn't create image list", | |
264 instance); | |
265 } | |
266 | |
267 /* add a bitmap to the list */ | |
268 if ((tbbutton->iBitmap = | |
269 ImageList_Add (ilist, bitmap, mask)) < 0) | |
270 { | |
271 xfree (button_tbl); | |
272 if (ilist) ImageList_Destroy (ilist); | |
273 signal_simple_error ("image list creation failed", | |
274 instance); | |
275 } | |
276 /* we're done with these now */ | |
277 DeleteObject (bitmap); | |
278 DeleteObject (mask); | |
279 } | 328 } |
329 | |
330 Fputhash (make_int (tbbutton->idCommand), | |
331 button, FRAME_MSWINDOWS_TOOLBAR_HASHTABLE (f)); | |
280 } | 332 } |
281 | 333 |
282 Fputhash (make_int (tbbutton->idCommand), | 334 /* now fix up the button size */ |
283 button, FRAME_MSWINDOWS_TOOLBAR_HASHTABLE (f)); | 335 tb->x = x; |
284 | 336 tb->y = y; |
337 tb->vertical = vert; | |
338 tb->border_width = border_width; | |
339 tb->width = width + MSWINDOWS_BUTTON_SHADOW_THICKNESS * 2; | |
340 tb->height = height + MSWINDOWS_BUTTON_SHADOW_THICKNESS * 2; | |
341 | |
342 if (tb->blank) | |
343 { | |
344 if (vert) | |
345 tb->height = MSWINDOWS_BLANK_SIZE; | |
346 else | |
347 tb->width = MSWINDOWS_BLANK_SIZE; | |
348 } | |
349 | |
350 if (vert) | |
351 y += tb->height; | |
352 else | |
353 x += tb->width; | |
354 /* move on to the next button */ | |
285 tbbutton++; | 355 tbbutton++; |
286 button = tb->next; | 356 button = tb->next; |
287 } | 357 } |
288 | 358 |
289 button = FRAME_TOOLBAR_BUTTONS (f, pos); | 359 button = FRAME_TOOLBAR_BUTTONS (f, pos); |
293 && | 363 && |
294 (toolbarwnd = | 364 (toolbarwnd = |
295 CreateWindowEx ( WS_EX_WINDOWEDGE, | 365 CreateWindowEx ( WS_EX_WINDOWEDGE, |
296 TOOLBARCLASSNAME, | 366 TOOLBARCLASSNAME, |
297 NULL, | 367 NULL, |
298 WS_CHILD | WS_VISIBLE | WS_DLGFRAME | 368 WS_CHILD | WS_VISIBLE |
299 | TBSTYLE_TOOLTIPS | CCS_NORESIZE | 369 | (style_3d ? WS_DLGFRAME : 0) |
370 | TBSTYLE_TOOLTIPS | CCS_NORESIZE | |
300 | CCS_NOPARENTALIGN | CCS_NODIVIDER, | 371 | CCS_NOPARENTALIGN | CCS_NODIVIDER, |
301 x, y, bar_width, bar_height, | 372 x, y, bar_width, bar_height, |
302 FRAME_MSWINDOWS_HANDLE (f), | 373 FRAME_MSWINDOWS_HANDLE (f), |
303 (HMENU)(TOOLBAR_ID_BIAS + pos), | 374 (HMENU)(TOOLBAR_ID_BIAS + pos), |
304 NULL, | 375 NULL, |
307 xfree (button_tbl); | 378 xfree (button_tbl); |
308 ImageList_Destroy (ilist); | 379 ImageList_Destroy (ilist); |
309 error ("couldn't create toolbar"); | 380 error ("couldn't create toolbar"); |
310 } | 381 } |
311 | 382 |
312 #if 0 | |
313 SendMessage (toolbarwnd, TB_SETPADDING, | |
314 0, MAKELPARAM(border_width, border_width)); | |
315 #endif | |
316 /* finally populate with images */ | 383 /* finally populate with images */ |
317 if (SendMessage (toolbarwnd, TB_BUTTONSTRUCTSIZE, | 384 if (SendMessage (toolbarwnd, TB_BUTTONSTRUCTSIZE, |
318 (WPARAM)sizeof(TBBUTTON), (LPARAM)0) == -1) | 385 (WPARAM)sizeof(TBBUTTON), (LPARAM)0) == -1) |
319 { | 386 { |
320 mswindows_clear_toolbar (f, pos, 0); | 387 mswindows_clear_toolbar (f, pos, 0); |
321 error ("couldn't set button structure size"); | 388 error ("couldn't set button structure size"); |
322 } | 389 } |
390 | |
391 if (vert) | |
392 height = min (bmheight + padding, height); | |
393 else | |
394 width = min (bmwidth + padding, width); | |
395 | |
396 /* pad the buttons */ | |
397 SendMessage (toolbarwnd, TB_SETPADDING, | |
398 0, MAKELPARAM(width - bmwidth, height - bmheight)); | |
323 | 399 |
324 /* set the size of buttons */ | 400 /* set the size of buttons */ |
325 SendMessage (toolbarwnd, TB_SETBUTTONSIZE, 0, | 401 SendMessage (toolbarwnd, TB_SETBUTTONSIZE, 0, |
326 (LPARAM)MAKELONG (width, height)); | 402 (LPARAM)MAKELONG (width, height)); |
327 | 403 |
355 (LPARAM)&tmp); | 431 (LPARAM)&tmp); |
356 } | 432 } |
357 | 433 |
358 /* finally populate with images */ | 434 /* finally populate with images */ |
359 if (SendMessage (toolbarwnd, TB_SETIMAGELIST, 0, | 435 if (SendMessage (toolbarwnd, TB_SETIMAGELIST, 0, |
360 (LPARAM)ilist) == -1) | 436 (LPARAM)ilist) < 0 |
437 || | |
438 SendMessage (toolbarwnd, TB_SETDISABLEDIMAGELIST, 0, | |
439 (LPARAM)ilist) < 0) | |
361 { | 440 { |
362 mswindows_clear_toolbar (f, pos, 0); | 441 mswindows_clear_toolbar (f, pos, 0); |
363 error ("couldn't add image list to toolbar"); | 442 error ("couldn't add image list to toolbar"); |
364 } | 443 } |
365 | 444 |
375 static void | 454 static void |
376 mswindows_move_toolbar (struct frame *f, enum toolbar_pos pos) | 455 mswindows_move_toolbar (struct frame *f, enum toolbar_pos pos) |
377 { | 456 { |
378 int bar_x, bar_y, bar_width, bar_height, vert; | 457 int bar_x, bar_y, bar_width, bar_height, vert; |
379 HWND toolbarwnd = TOOLBAR_HANDLE(f,pos); | 458 HWND toolbarwnd = TOOLBAR_HANDLE(f,pos); |
380 | 459 |
381 if (toolbarwnd) | 460 if (toolbarwnd) |
382 { | 461 { |
383 get_toolbar_coords (f, pos, &bar_x, &bar_y, &bar_width, &bar_height, | 462 get_toolbar_coords (f, pos, &bar_x, &bar_y, &bar_width, &bar_height, |
384 &vert, 1); | 463 &vert, 1); |
385 | 464 |
387 arises from different treatment of toolbar positions | 466 arises from different treatment of toolbar positions |
388 by Windows and by XEmacs. */ | 467 by Windows and by XEmacs. */ |
389 switch (pos) | 468 switch (pos) |
390 { | 469 { |
391 case TOP_TOOLBAR: | 470 case TOP_TOOLBAR: |
392 bar_x -= 2; bar_y--; | 471 bar_x--; bar_y-=2; |
472 bar_width+=3; bar_height+=3; | |
473 break; | |
474 case LEFT_TOOLBAR: | |
475 bar_x--; bar_y-=2; | |
476 bar_height++; bar_width++; | |
477 break; | |
478 case BOTTOM_TOOLBAR: | |
479 bar_y-=2; | |
480 bar_width+=4; bar_height+=4; | |
481 break; | |
482 case RIGHT_TOOLBAR: | |
483 bar_y-=2; bar_x++; | |
393 bar_width++; bar_height++; | 484 bar_width++; bar_height++; |
394 break; | 485 break; |
395 case LEFT_TOOLBAR: | |
396 bar_x -= 2; bar_y--; | |
397 bar_width++; bar_height++; | |
398 break; | |
399 case BOTTOM_TOOLBAR: | |
400 bar_x--; | |
401 bar_width++; | |
402 break; | |
403 case RIGHT_TOOLBAR: | |
404 bar_y--; | |
405 break; | |
406 } | 486 } |
407 SetWindowPos (toolbarwnd, NULL, bar_x, bar_y, | 487 SetWindowPos (toolbarwnd, NULL, bar_x, bar_y, |
408 bar_width + 1, bar_height + 1, SWP_NOZORDER); | 488 bar_width, bar_height, SWP_NOZORDER); |
409 } | 489 } |
410 } | 490 } |
411 | 491 |
412 static void | 492 static void |
413 mswindows_redraw_exposed_toolbars (struct frame *f, int x, int y, int width, | 493 mswindows_redraw_exposed_toolbars (struct frame *f, int x, int y, int width, |
520 /* #### ? */ | 600 /* #### ? */ |
521 if (UNBOUNDP (data)) | 601 if (UNBOUNDP (data)) |
522 return Qnil; | 602 return Qnil; |
523 | 603 |
524 /* Ok, this is our one. Enqueue it. */ | 604 /* Ok, this is our one. Enqueue it. */ |
525 get_callback (data, &fn, &arg); | 605 get_gui_callback (data, &fn, &arg); |
526 | |
527 XSETFRAME (frame, f); | 606 XSETFRAME (frame, f); |
528 enqueue_misc_user_event (frame, fn, arg); | 607 mswindows_enqueue_misc_user_event (frame, fn, arg); |
529 | 608 |
530 /* Needs good bump also, for WM_COMMAND may have been dispatched from | |
531 mswindows_need_event, which will block again despite new command | |
532 event has arrived */ | |
533 mswindows_bump_queue (); | |
534 return Qt; | 609 return Qt; |
535 } | 610 } |
536 | |
537 | 611 |
538 /************************************************************************/ | 612 /************************************************************************/ |
539 /* initialization */ | 613 /* initialization */ |
540 /************************************************************************/ | 614 /************************************************************************/ |
541 | 615 |