comparison src/toolbar-msw.c @ 771:943eaba38521

[xemacs-hg @ 2002-03-13 08:51:24 by ben] The big ben-mule-21-5 check-in! Various files were added and deleted. See CHANGES-ben-mule. There are still some test suite failures. No crashes, though. Many of the failures have to do with problems in the test suite itself rather than in the actual code. I'll be addressing these in the next day or so -- none of the test suite failures are at all critical. Meanwhile I'll be trying to address the biggest issues -- i.e. build or run failures, which will almost certainly happen on various platforms. All comments should be sent to ben@xemacs.org -- use a Cc: if necessary when sending to mailing lists. There will be pre- and post- tags, something like pre-ben-mule-21-5-merge-in, and post-ben-mule-21-5-merge-in.
author ben
date Wed, 13 Mar 2002 08:54:06 +0000
parents 183866b06e0b
children e38acbeb1cae
comparison
equal deleted inserted replaced
770:336a418893b5 771:943eaba38521
24 24
25 /* This implementation by Andy Piper <andyp@parallax.co.uk>, with bits 25 /* This implementation by Andy Piper <andyp@parallax.co.uk>, with bits
26 borrowed from toolbar-x.c */ 26 borrowed from toolbar-x.c */
27 27
28 /* Synched up with: Not in FSF. */ 28 /* Synched up with: Not in FSF. */
29
30 /* This file essentially Mule-ized (except perhaps some Unicode splitting).
31 5-2000. (??? Needs a once-over.) */
32
33 #define NEED_MSWINDOWS_COMMCTRL
29 34
30 #include <config.h> 35 #include <config.h>
31 #include "lisp.h" 36 #include "lisp.h"
32 37
33 #include "faces.h" 38 #include "faces.h"
74 abort (); \ 79 abort (); \
75 } \ 80 } \
76 } while (0) 81 } while (0)
77 82
78 static int 83 static int
79 allocate_toolbar_item_id (struct frame* f, struct toolbar_button* button, 84 allocate_toolbar_item_id (struct frame *f, struct toolbar_button *button,
80 enum toolbar_pos pos) 85 enum toolbar_pos pos)
81 { 86 {
82 /* hmm what do we generate an id based on */ 87 /* hmm what do we generate an id based on */
83 int id = TOOLBAR_ITEM_ID_BITS (internal_hash (button->callback, 0)); 88 int id = TOOLBAR_ITEM_ID_BITS (internal_hash (button->callback, 0));
84 while (!NILP (Fgethash (make_int (id), 89 while (!NILP (Fgethash (make_int (id),
98 HWND toolbarwnd = TOOLBAR_HANDLE(f, pos); 103 HWND toolbarwnd = TOOLBAR_HANDLE(f, pos);
99 if (toolbarwnd) 104 if (toolbarwnd)
100 { 105 {
101 TBBUTTON info; 106 TBBUTTON info;
102 107
103 /* Delete the buttons and remove the command from the hash table*/ 108 /* Delete the buttons and remove the command from the hash table */
104 i = SendMessage (toolbarwnd, TB_BUTTONCOUNT, 0, 0); 109 i = qxeSendMessage (toolbarwnd, TB_BUTTONCOUNT, 0, 0);
105 for (i--; i >= 0; i--) 110 for (i--; i >= 0; i--)
106 { 111 {
107 SendMessage (toolbarwnd, TB_GETBUTTON, (WPARAM)i, 112 qxeSendMessage (toolbarwnd, TB_GETBUTTON, (WPARAM)i,
108 (LPARAM)&info); 113 (LPARAM)&info);
109 Fremhash(make_int(info.idCommand), 114 Fremhash(make_int(info.idCommand),
110 FRAME_MSWINDOWS_TOOLBAR_HASH_TABLE(f)); 115 FRAME_MSWINDOWS_TOOLBAR_HASH_TABLE(f));
111 SendMessage (toolbarwnd, TB_DELETEBUTTON, (WPARAM)i, 0); 116 qxeSendMessage (toolbarwnd, TB_DELETEBUTTON, (WPARAM)i, 0);
112 } 117 }
113 118
114 /* finally get rid of the image list assuming it clears up its 119 /* finally get rid of the image list assuming it clears up its
115 bitmaps */ 120 bitmaps */
116 SendMessage (toolbarwnd, TB_GETIMAGELIST, 0, (LONG) &ilist); 121 qxeSendMessage (toolbarwnd, TB_GETIMAGELIST, 0, (LONG) &ilist);
117 if (ilist) 122 if (ilist)
118 { 123 {
119 ImageList_Destroy(ilist); 124 ImageList_Destroy(ilist);
120 } 125 }
121 SendMessage (toolbarwnd, TB_SETIMAGELIST, 0, (LPARAM)NULL); 126 qxeSendMessage (toolbarwnd, TB_SETIMAGELIST, 0, (LPARAM)NULL);
122 127
123 ShowWindow(toolbarwnd, SW_HIDE); 128 ShowWindow(toolbarwnd, SW_HIDE);
124 } 129 }
125 130
126 FRAME_MSWINDOWS_TOOLBAR_CHECKSUM (f, pos) = 0; 131 FRAME_MSWINDOWS_TOOLBAR_CHECKSUM (f, pos) = 0;
141 int shadow_thickness = 2; /* get this from somewhere else? */ 146 int shadow_thickness = 2; /* get this from somewhere else? */
142 int window_frame_width = 3; 147 int window_frame_width = 3;
143 int padding = (border_width + shadow_thickness) * 2; 148 int padding = (border_width + shadow_thickness) * 2;
144 unsigned int checksum=0; 149 unsigned int checksum=0;
145 struct window *w = XWINDOW (window); 150 struct window *w = XWINDOW (window);
146 TBBUTTON* button_tbl, *tbbutton; 151 TBBUTTON *button_tbl, *tbbutton;
147 HIMAGELIST ilist=NULL; 152 HIMAGELIST ilist=NULL;
148 HWND toolbarwnd=NULL; 153 HWND toolbarwnd=NULL;
149 154
150 get_toolbar_coords (f, pos, &x, &y, &bar_width, &bar_height, &vert, 0); 155 get_toolbar_coords (f, pos, &x, &y, &bar_width, &bar_height, &vert, 0);
151 156
252 else 257 else
253 instance = Qnil; 258 instance = Qnil;
254 259
255 if (IMAGE_INSTANCEP (instance)) 260 if (IMAGE_INSTANCEP (instance))
256 { 261 {
257 Lisp_Image_Instance* p = XIMAGE_INSTANCE (instance); 262 Lisp_Image_Instance *p = XIMAGE_INSTANCE (instance);
258 263
259 if (IMAGE_INSTANCE_PIXMAP_TYPE_P (p)) 264 if (IMAGE_INSTANCE_PIXMAP_TYPE_P (p))
260 { 265 {
261 /* we are going to honor the toolbar settings 266 /* we are going to honor the toolbar settings
262 and resize the bitmaps accordingly if they are 267 and resize the bitmaps accordingly if they are
263 too big. If they are too small we leave them 268 too big. If they are too small we leave them
264 and pad the difference - unless a different size 269 and pad the difference - unless a different size
265 crops up in the middle, at which point we *have* 270 crops up in the middle, at which point we *have*
266 to resize since the ImageList won't cope.*/ 271 to resize since the ImageList won't cope. */
267 272
268 if ((bmwidth 273 if ((bmwidth
269 && 274 &&
270 IMAGE_INSTANCE_PIXMAP_WIDTH (p) != bmwidth) 275 IMAGE_INSTANCE_PIXMAP_WIDTH (p) != bmwidth)
271 || 276 ||
324 : IMAGE_INSTANCE_MSWINDOWS_BITMAP (p), 329 : IMAGE_INSTANCE_MSWINDOWS_BITMAP (p),
325 mask ? mask 330 mask ? mask
326 : IMAGE_INSTANCE_MSWINDOWS_MASK (p))) < 0) 331 : IMAGE_INSTANCE_MSWINDOWS_MASK (p))) < 0)
327 { 332 {
328 xfree (button_tbl); 333 xfree (button_tbl);
329 if (ilist) ImageList_Destroy (ilist); 334 if (ilist)
335 ImageList_Destroy (ilist);
330 gui_error 336 gui_error
331 ("couldn't add image to image list", instance); 337 ("couldn't add image to image list", instance);
332 } 338 }
333 /* we're done with these now */ 339 /* we're done with these now */
334 DeleteObject (bitmap); 340 DeleteObject (bitmap);
369 375
370 /* create the toolbar window? */ 376 /* create the toolbar window? */
371 if (!toolbarwnd 377 if (!toolbarwnd
372 && 378 &&
373 (toolbarwnd = 379 (toolbarwnd =
374 CreateWindowEx ( WS_EX_WINDOWEDGE, 380 qxeCreateWindowEx (WS_EX_WINDOWEDGE,
375 TOOLBARCLASSNAME, 381 XETEXT (TOOLBARCLASSNAME),
376 NULL, 382 NULL,
377 WS_CHILD 383 WS_CHILD
378 | (style_3d ? WS_DLGFRAME : 0) 384 | (style_3d ? WS_DLGFRAME : 0)
379 | TBSTYLE_TOOLTIPS 385 | TBSTYLE_TOOLTIPS
380 | CCS_NORESIZE 386 | CCS_NORESIZE
381 | CCS_NOPARENTALIGN | CCS_NODIVIDER 387 | CCS_NOPARENTALIGN | CCS_NODIVIDER
382 | CCS_ADJUSTABLE, 388 | CCS_ADJUSTABLE,
383 x, y, bar_width, bar_height, 389 x, y, bar_width, bar_height,
384 FRAME_MSWINDOWS_HANDLE (f), 390 FRAME_MSWINDOWS_HANDLE (f),
385 (HMENU)(TOOLBAR_ID_BIAS + pos), 391 (HMENU)(TOOLBAR_ID_BIAS + pos),
386 NULL, 392 NULL,
387 NULL))==NULL) 393 NULL))==NULL)
388 { 394 {
389 xfree (button_tbl); 395 xfree (button_tbl);
390 ImageList_Destroy (ilist); 396 ImageList_Destroy (ilist);
391 gui_error ("couldn't create toolbar", Qunbound); 397 gui_error ("couldn't create toolbar", Qunbound);
392 } 398 }
393 399
394 /* finally populate with images */ 400 /* finally populate with images */
395 if (SendMessage (toolbarwnd, TB_BUTTONSTRUCTSIZE, 401 if (qxeSendMessage (toolbarwnd, TB_BUTTONSTRUCTSIZE,
396 (WPARAM)sizeof(TBBUTTON), (LPARAM)0) == -1) 402 (WPARAM)sizeof(TBBUTTON), (LPARAM)0) == -1)
397 { 403 {
398 mswindows_clear_toolbar (f, pos, 0); 404 mswindows_clear_toolbar (f, pos, 0);
399 gui_error ("couldn't set button structure size", Qunbound); 405 gui_error ("couldn't set button structure size", Qunbound);
400 } 406 }
401 407
403 height = min (bmheight + padding, height); 409 height = min (bmheight + padding, height);
404 else 410 else
405 width = min (bmwidth + padding, width); 411 width = min (bmwidth + padding, width);
406 412
407 /* pad the buttons */ 413 /* pad the buttons */
408 SendMessage (toolbarwnd, TB_SETPADDING, 414 qxeSendMessage (toolbarwnd, TB_SETPADDING,
409 0, MAKELPARAM(width - bmwidth, height - bmheight)); 415 0, MAKELPARAM (width - bmwidth, height - bmheight));
410 416
411 /* set the size of buttons */ 417 /* set the size of buttons */
412 SendMessage (toolbarwnd, TB_SETBUTTONSIZE, 0, 418 qxeSendMessage (toolbarwnd, TB_SETBUTTONSIZE, 0,
413 (LPARAM)MAKELONG (width, height)); 419 (LPARAM) MAKELONG (width, height));
414 420
415 /* set the size of bitmaps */ 421 /* set the size of bitmaps */
416 SendMessage (toolbarwnd, TB_SETBITMAPSIZE, 0, 422 qxeSendMessage (toolbarwnd, TB_SETBITMAPSIZE, 0,
417 (LPARAM)MAKELONG (bmwidth, bmheight)); 423 (LPARAM) MAKELONG (bmwidth, bmheight));
418 424
419 /* tell it we've done it */ 425 /* tell it we've done it */
420 SendMessage (toolbarwnd, TB_AUTOSIZE, 0, 0); 426 qxeSendMessage (toolbarwnd, TB_AUTOSIZE, 0, 0);
421 427
422 /* finally populate with images */ 428 /* finally populate with images */
423 if (!SendMessage (toolbarwnd, TB_ADDBUTTONS, 429 if (!qxeSendMessage (toolbarwnd, TB_ADDBUTTONS,
424 (WPARAM)nbuttons, (LPARAM)button_tbl)) 430 (WPARAM) nbuttons, (LPARAM) button_tbl))
425 { 431 {
426 mswindows_clear_toolbar (f, pos, 0); 432 mswindows_clear_toolbar (f, pos, 0);
427 gui_error ("couldn't add button list to toolbar", Qunbound); 433 gui_error ("couldn't add button list to toolbar", Qunbound);
428 } 434 }
429 435
430 /* vertical toolbars need more rows */ 436 /* vertical toolbars need more rows */
431 if (vert) 437 if (vert)
432 { 438 {
433 RECT tmp; 439 RECT tmp;
434 SendMessage (toolbarwnd, TB_SETROWS, 440 qxeSendMessage (toolbarwnd, TB_SETROWS,
435 MAKEWPARAM(nbuttons, FALSE), (LPARAM)&tmp); 441 MAKEWPARAM (nbuttons, FALSE), (LPARAM) &tmp);
436 } 442 }
437 443
438 else 444 else
439 { 445 {
440 RECT tmp; 446 RECT tmp;
441 SendMessage (toolbarwnd, TB_SETROWS, MAKEWPARAM(1, FALSE), 447 qxeSendMessage (toolbarwnd, TB_SETROWS, MAKEWPARAM(1, FALSE),
442 (LPARAM)&tmp); 448 (LPARAM)&tmp);
443 } 449 }
444 450
445 /* finally populate with images */ 451 /* finally populate with images */
446 if (SendMessage (toolbarwnd, TB_SETIMAGELIST, 0, 452 if (qxeSendMessage (toolbarwnd, TB_SETIMAGELIST, 0,
447 (LPARAM)ilist) < 0 453 (LPARAM)ilist) < 0
448 || 454 ||
449 SendMessage (toolbarwnd, TB_SETDISABLEDIMAGELIST, 0, 455 qxeSendMessage (toolbarwnd, TB_SETDISABLEDIMAGELIST, 0,
450 (LPARAM)ilist) < 0) 456 (LPARAM)ilist) < 0)
451 { 457 {
452 mswindows_clear_toolbar (f, pos, 0); 458 mswindows_clear_toolbar (f, pos, 0);
453 gui_error ("couldn't add image list to toolbar", Qunbound); 459 gui_error ("couldn't add image list to toolbar", Qunbound);
454 } 460 }
455 461
576 DELETE_TOOLBAR(LEFT_TOOLBAR); 582 DELETE_TOOLBAR(LEFT_TOOLBAR);
577 DELETE_TOOLBAR(RIGHT_TOOLBAR); 583 DELETE_TOOLBAR(RIGHT_TOOLBAR);
578 #undef DELETE_TOOLBAR 584 #undef DELETE_TOOLBAR
579 } 585 }
580 586
581 /* map toolbar hwnd to pos*/ 587 /* map toolbar hwnd to pos */
582 static int mswindows_find_toolbar_pos(struct frame* f, HWND ctrl) 588 static int
583 { 589 mswindows_find_toolbar_pos (struct frame *f, HWND ctrl)
584 int id = GetDlgCtrlID(ctrl); 590 {
591 int id = GetDlgCtrlID (ctrl);
585 return id ? id - TOOLBAR_ID_BIAS : -1; 592 return id ? id - TOOLBAR_ID_BIAS : -1;
586 } 593 }
587 594
588 Lisp_Object 595 Lisp_Object
589 mswindows_get_toolbar_button_text ( struct frame* f, int command_id ) 596 mswindows_get_toolbar_button_text (struct frame *f, int command_id)
590 { 597 {
591 Lisp_Object button = Fgethash (make_int (command_id), 598 Lisp_Object button = Fgethash (make_int (command_id),
592 FRAME_MSWINDOWS_TOOLBAR_HASH_TABLE (f), Qnil); 599 FRAME_MSWINDOWS_TOOLBAR_HASH_TABLE (f), Qnil);
593 600
594 if (!NILP (button)) 601 if (!NILP (button))
604 * or Qnil if id has not been mapped to a callback. 611 * or Qnil if id has not been mapped to a callback.
605 * Window procedure may try other targets to route the 612 * Window procedure may try other targets to route the
606 * command if we return nil 613 * command if we return nil
607 */ 614 */
608 Lisp_Object 615 Lisp_Object
609 mswindows_handle_toolbar_wm_command (struct frame* f, HWND ctrl, WORD id) 616 mswindows_handle_toolbar_wm_command (struct frame *f, HWND ctrl, WORD id)
610 { 617 {
611 /* Try to map the command id through the proper hash table */ 618 /* Try to map the command id through the proper hash table */
612 Lisp_Object button, data, fn, arg, frame; 619 Lisp_Object button, data, fn, arg, frame;
613 620
614 button = Fgethash (make_int (id), 621 button = Fgethash (make_int (id),