comparison src/toolbar-msw.c @ 5178:97eb4942aec8

merge
author Ben Wing <ben@xemacs.org>
date Mon, 29 Mar 2010 21:28:13 -0500
parents 8b2f75cecb89 d372b17f63ce
children 635f4b506855
comparison
equal deleted inserted replaced
5177:b785049378e3 5178:97eb4942aec8
1 /* toolbar implementation -- mswindows interface. 1 /* toolbar implementation -- mswindows interface.
2 Copyright (C) 1995 Board of Trustees, University of Illinois. 2 Copyright (C) 1995 Board of Trustees, University of Illinois.
3 Copyright (C) 1995 Sun Microsystems, Inc. 3 Copyright (C) 1995 Sun Microsystems, Inc.
4 Copyright (C) 1995, 1996, 2002 Ben Wing. 4 Copyright (C) 1995, 1996, 2002, 2010 Ben Wing.
5 Copyright (C) 1996 Chuck Thompson. 5 Copyright (C) 1996 Chuck Thompson.
6 Copyright (C) 1998 Andy Piper. 6 Copyright (C) 1998 Andy Piper.
7 7
8 This file is part of XEmacs. 8 This file is part of XEmacs.
9 9
50 #define TOOLBAR_ITEM_ID_MIN 0x4000 50 #define TOOLBAR_ITEM_ID_MIN 0x4000
51 #define TOOLBAR_ITEM_ID_MAX 0x7FFF 51 #define TOOLBAR_ITEM_ID_MAX 0x7FFF
52 #define TOOLBAR_ITEM_ID_BITS(x) (((x) & 0x3FFF) | 0x4000) 52 #define TOOLBAR_ITEM_ID_BITS(x) (((x) & 0x3FFF) | 0x4000)
53 #define TOOLBAR_ID_BIAS 16 53 #define TOOLBAR_ID_BIAS 16
54 #define TOOLBAR_HANDLE(f,p) \ 54 #define TOOLBAR_HANDLE(f,p) \
55 GetDlgItem(FRAME_MSWINDOWS_HANDLE(f), TOOLBAR_ID_BIAS + p) 55 GetDlgItem (FRAME_MSWINDOWS_HANDLE (f), TOOLBAR_ID_BIAS + p)
56 56
57 #define MSWINDOWS_BUTTON_SHADOW_THICKNESS 2 57 #define MSWINDOWS_BUTTON_SHADOW_THICKNESS 2
58 #define MSWINDOWS_BLANK_SIZE 5 58 #define MSWINDOWS_BLANK_SIZE 5
59 #define MSWINDOWS_MINIMUM_TOOLBAR_SIZE 8 59 #define MSWINDOWS_MINIMUM_TOOLBAR_SIZE 8
60 60
61 static void 61 static void
62 mswindows_move_toolbar (struct frame *f, enum toolbar_pos pos); 62 mswindows_move_toolbar (struct frame *f, enum edge_pos pos);
63
64 #define SET_TOOLBAR_WAS_VISIBLE_FLAG(frame, pos, flag) \
65 do { \
66 switch (pos) \
67 { \
68 case TOP_TOOLBAR: \
69 (frame)->top_toolbar_was_visible = flag; \
70 break; \
71 case BOTTOM_TOOLBAR: \
72 (frame)->bottom_toolbar_was_visible = flag; \
73 break; \
74 case LEFT_TOOLBAR: \
75 (frame)->left_toolbar_was_visible = flag; \
76 break; \
77 case RIGHT_TOOLBAR: \
78 (frame)->right_toolbar_was_visible = flag; \
79 break; \
80 default: \
81 ABORT (); \
82 } \
83 } while (0)
84 63
85 static int 64 static int
86 allocate_toolbar_item_id (struct frame *f, struct toolbar_button *button, 65 allocate_toolbar_item_id (struct frame *f, struct toolbar_button *button,
87 enum toolbar_pos UNUSED (pos)) 66 enum edge_pos UNUSED (pos))
88 { 67 {
89 /* hmm what do we generate an id based on */ 68 /* hmm what do we generate an id based on */
90 int id = TOOLBAR_ITEM_ID_BITS (internal_hash (button->callback, 0)); 69 int id = TOOLBAR_ITEM_ID_BITS (internal_hash (button->callback, 0));
91 while (!NILP (Fgethash (make_int (id), 70 while (!NILP (Fgethash (make_int (id),
92 FRAME_MSWINDOWS_TOOLBAR_HASH_TABLE (f), Qnil))) 71 FRAME_MSWINDOWS_TOOLBAR_HASH_TABLE (f), Qnil)))
95 } 74 }
96 return id; 75 return id;
97 } 76 }
98 77
99 static void 78 static void
100 mswindows_clear_toolbar (struct frame *f, enum toolbar_pos pos, 79 mswindows_clear_toolbar (struct frame *f, enum edge_pos pos,
101 int UNUSED (thickness_change)) 80 int UNUSED (thickness_change))
102 { 81 {
103 HIMAGELIST ilist = NULL; 82 HIMAGELIST ilist = NULL;
104 int i; 83 int i;
105 HWND toolbarwnd = TOOLBAR_HANDLE (f, pos); 84 HWND toolbarwnd = TOOLBAR_HANDLE (f, pos);
121 /* finally get rid of the image list assuming it clears up its 100 /* finally get rid of the image list assuming it clears up its
122 bitmaps */ 101 bitmaps */
123 qxeSendMessage (toolbarwnd, TB_GETIMAGELIST, 0, (LONG) &ilist); 102 qxeSendMessage (toolbarwnd, TB_GETIMAGELIST, 0, (LONG) &ilist);
124 if (ilist) 103 if (ilist)
125 { 104 {
126 ImageList_Destroy(ilist); 105 ImageList_Destroy (ilist);
127 } 106 }
128 qxeSendMessage (toolbarwnd, TB_SETIMAGELIST, 0, (LPARAM)NULL); 107 qxeSendMessage (toolbarwnd, TB_SETIMAGELIST, 0, (LPARAM)NULL);
129 108
130 ShowWindow(toolbarwnd, SW_HIDE); 109 ShowWindow (toolbarwnd, SW_HIDE);
131 } 110 }
132 111
133 FRAME_MSWINDOWS_TOOLBAR_CHECKSUM (f, pos) = 0; 112 FRAME_MSWINDOWS_TOOLBAR_CHECKSUM (f, pos) = 0;
134 SET_TOOLBAR_WAS_VISIBLE_FLAG (f, pos, 0); 113 SET_TOOLBAR_WAS_VISIBLE_FLAG (f, pos, 0);
135 } 114 }
136 115
137 static void 116 static void
138 mswindows_output_toolbar (struct frame *f, enum toolbar_pos pos) 117 mswindows_output_toolbar (struct frame *f, enum edge_pos pos)
139 { 118 {
140 int x, y, bar_width, bar_height, vert; 119 int x, y, bar_width, bar_height, vert;
141 int width=-1, height=-1, bmwidth=0, bmheight=0, maxbmwidth, maxbmheight; 120 int width=-1, height=-1, bmwidth=0, bmheight=0, maxbmwidth, maxbmheight;
142 int style_3d=0; 121 int style_3d=0;
143 int border_width = FRAME_REAL_TOOLBAR_BORDER_WIDTH (f, pos); 122 int border_width = FRAME_REAL_TOOLBAR_BORDER_WIDTH (f, pos);
206 while (!NILP (button)) 185 while (!NILP (button))
207 { 186 {
208 187
209 struct toolbar_button *tb = XTOOLBAR_BUTTON (button); 188 struct toolbar_button *tb = XTOOLBAR_BUTTON (button);
210 checksum = HASH5 (checksum, 189 checksum = HASH5 (checksum,
211 internal_hash (get_toolbar_button_glyph(w, tb), 0), 190 internal_hash (get_toolbar_button_glyph (w, tb), 0),
212 internal_hash (tb->callback, 0), 191 internal_hash (tb->callback, 0),
213 width, 192 width,
214 LISP_HASH (w->toolbar_buttons_captioned_p)); 193 LISP_HASH (w->toolbar_buttons_captioned_p));
215 button = tb->next; 194 button = tb->next;
216 nbuttons++; 195 nbuttons++;
217 } 196 }
218 197
219 /* only rebuild if something has changed */ 198 /* only rebuild if something has changed */
220 if (!toolbarwnd || FRAME_MSWINDOWS_TOOLBAR_CHECKSUM(f,pos)!=checksum) 199 if (!toolbarwnd || FRAME_MSWINDOWS_TOOLBAR_CHECKSUM (f,pos)!=checksum)
221 { 200 {
222 /* remove the old one */ 201 /* remove the old one */
223 mswindows_clear_toolbar (f, pos, 0); 202 mswindows_clear_toolbar (f, pos, 0);
224 203
225 FRAME_MSWINDOWS_TOOLBAR_CHECKSUM (f, pos)=checksum; 204 FRAME_MSWINDOWS_TOOLBAR_CHECKSUM (f, pos)=checksum;
399 gui_error ("couldn't create toolbar", Qunbound); 378 gui_error ("couldn't create toolbar", Qunbound);
400 } 379 }
401 380
402 /* finally populate with images */ 381 /* finally populate with images */
403 if (qxeSendMessage (toolbarwnd, TB_BUTTONSTRUCTSIZE, 382 if (qxeSendMessage (toolbarwnd, TB_BUTTONSTRUCTSIZE,
404 (WPARAM)sizeof(TBBUTTON), (LPARAM)0) == -1) 383 (WPARAM)sizeof (TBBUTTON), (LPARAM)0) == -1)
405 { 384 {
406 mswindows_clear_toolbar (f, pos, 0); 385 mswindows_clear_toolbar (f, pos, 0);
407 gui_error ("couldn't set button structure size", Qunbound); 386 gui_error ("couldn't set button structure size", Qunbound);
408 } 387 }
409 388
444 } 423 }
445 424
446 else 425 else
447 { 426 {
448 RECT tmp; 427 RECT tmp;
449 qxeSendMessage (toolbarwnd, TB_SETROWS, MAKEWPARAM(1, FALSE), 428 qxeSendMessage (toolbarwnd, TB_SETROWS, MAKEWPARAM (1, FALSE),
450 (LPARAM)&tmp); 429 (LPARAM)&tmp);
451 } 430 }
452 431
453 /* finally populate with images */ 432 /* finally populate with images */
454 if (qxeSendMessage (toolbarwnd, TB_SETIMAGELIST, 0, 433 if (qxeSendMessage (toolbarwnd, TB_SETIMAGELIST, 0,
473 SET_TOOLBAR_WAS_VISIBLE_FLAG (f, pos, 1); 452 SET_TOOLBAR_WAS_VISIBLE_FLAG (f, pos, 1);
474 } 453 }
475 } 454 }
476 455
477 static void 456 static void
478 mswindows_move_toolbar (struct frame *f, enum toolbar_pos pos) 457 mswindows_move_toolbar (struct frame *f, enum edge_pos pos)
479 { 458 {
480 int bar_x, bar_y, bar_width, bar_height, vert; 459 int bar_x, bar_y, bar_width, bar_height, vert;
481 HWND toolbarwnd = TOOLBAR_HANDLE(f,pos); 460 HWND toolbarwnd = TOOLBAR_HANDLE (f,pos);
482 461
483 if (toolbarwnd) 462 if (toolbarwnd)
484 { 463 {
485 get_toolbar_coords (f, pos, &bar_x, &bar_y, &bar_width, &bar_height, 464 get_toolbar_coords (f, pos, &bar_x, &bar_y, &bar_width, &bar_height,
486 &vert, 1); 465 &vert, 1);
488 /* #### This terrible mangling with coordinates perhaps 467 /* #### This terrible mangling with coordinates perhaps
489 arises from different treatment of toolbar positions 468 arises from different treatment of toolbar positions
490 by Windows and by XEmacs. */ 469 by Windows and by XEmacs. */
491 switch (pos) 470 switch (pos)
492 { 471 {
493 case TOP_TOOLBAR: 472 case TOP_EDGE:
494 bar_x--; bar_y-=2; 473 bar_x--; bar_y-=2;
495 bar_width+=3; bar_height+=3; 474 bar_width+=3; bar_height+=3;
496 break; 475 break;
497 case LEFT_TOOLBAR: 476 case LEFT_EDGE:
498 bar_x--; bar_y-=2; 477 bar_x--; bar_y-=2;
499 bar_height++; bar_width++; 478 bar_height++; bar_width++;
500 break; 479 break;
501 case BOTTOM_TOOLBAR: 480 case BOTTOM_EDGE:
502 bar_y-=2; 481 bar_y-=2;
503 bar_width+=4; bar_height+=4; 482 bar_width+=4; bar_height+=4;
504 break; 483 break;
505 case RIGHT_TOOLBAR: 484 case RIGHT_EDGE:
506 bar_y-=2; bar_x++; 485 bar_y-=2; bar_x++;
507 bar_width++; bar_height++; 486 bar_width++; bar_height++;
508 break; 487 break;
509 } 488 }
510 SetWindowPos (toolbarwnd, NULL, bar_x, bar_y, 489 SetWindowPos (toolbarwnd, NULL, bar_x, bar_y,
515 static void 494 static void
516 mswindows_redraw_exposed_toolbars (struct frame *f, 495 mswindows_redraw_exposed_toolbars (struct frame *f,
517 int UNUSED (x), int UNUSED (y), 496 int UNUSED (x), int UNUSED (y),
518 int UNUSED (width), int UNUSED (height)) 497 int UNUSED (width), int UNUSED (height))
519 { 498 {
499 enum edge_pos pos;
520 assert (FRAME_MSWINDOWS_P (f)); 500 assert (FRAME_MSWINDOWS_P (f));
521 501
522 if (FRAME_REAL_TOP_TOOLBAR_VISIBLE (f)) 502 EDGE_POS_LOOP (pos)
523 mswindows_move_toolbar (f, TOP_TOOLBAR); 503 {
524 504 if (FRAME_REAL_TOOLBAR_VISIBLE (f, pos))
525 if (FRAME_REAL_BOTTOM_TOOLBAR_VISIBLE (f)) 505 mswindows_move_toolbar (f, pos);
526 mswindows_move_toolbar (f, BOTTOM_TOOLBAR); 506 }
527
528 if (FRAME_REAL_LEFT_TOOLBAR_VISIBLE (f))
529 mswindows_move_toolbar (f, LEFT_TOOLBAR);
530
531 if (FRAME_REAL_RIGHT_TOOLBAR_VISIBLE (f))
532 mswindows_move_toolbar (f, RIGHT_TOOLBAR);
533 } 507 }
534 508
535 static void 509 static void
536 mswindows_redraw_frame_toolbars (struct frame *f) 510 mswindows_redraw_frame_toolbars (struct frame *f)
537 { 511 {
540 } 514 }
541 515
542 static void 516 static void
543 mswindows_initialize_frame_toolbars (struct frame *UNUSED (f)) 517 mswindows_initialize_frame_toolbars (struct frame *UNUSED (f))
544 { 518 {
545
546 } 519 }
547 520
548 static void 521 static void
549 mswindows_output_frame_toolbars (struct frame *f) 522 mswindows_output_frame_toolbars (struct frame *f)
550 { 523 {
524 enum edge_pos pos;
551 assert (FRAME_MSWINDOWS_P (f)); 525 assert (FRAME_MSWINDOWS_P (f));
552 526
553 if (FRAME_REAL_TOP_TOOLBAR_VISIBLE (f)) 527 EDGE_POS_LOOP (pos)
554 mswindows_output_toolbar (f, TOP_TOOLBAR); 528 {
555 if (FRAME_REAL_BOTTOM_TOOLBAR_VISIBLE (f)) 529 if (FRAME_REAL_TOOLBAR_VISIBLE (f, pos))
556 mswindows_output_toolbar (f, BOTTOM_TOOLBAR); 530 mswindows_output_toolbar (f, pos);
557 if (FRAME_REAL_LEFT_TOOLBAR_VISIBLE (f)) 531 }
558 mswindows_output_toolbar (f, LEFT_TOOLBAR);
559 if (FRAME_REAL_RIGHT_TOOLBAR_VISIBLE (f))
560 mswindows_output_toolbar (f, RIGHT_TOOLBAR);
561 } 532 }
562 533
563 static void 534 static void
564 mswindows_clear_frame_toolbars (struct frame *f) 535 mswindows_clear_frame_toolbars (struct frame *f)
565 { 536 {
537 enum edge_pos pos;
566 assert (FRAME_MSWINDOWS_P (f)); 538 assert (FRAME_MSWINDOWS_P (f));
567 539
568 if (f->top_toolbar_was_visible 540 EDGE_POS_LOOP (pos)
569 && !FRAME_REAL_TOP_TOOLBAR_VISIBLE (f)) 541 {
570 mswindows_clear_toolbar (f, TOP_TOOLBAR, 0); 542 if (f->toolbar_was_visible[pos]
571 if (f->bottom_toolbar_was_visible 543 && !FRAME_REAL_TOOLBAR_VISIBLE (f, pos))
572 && !FRAME_REAL_BOTTOM_TOOLBAR_VISIBLE (f)) 544 mswindows_clear_toolbar (f, pos, 0);
573 mswindows_clear_toolbar (f, BOTTOM_TOOLBAR, 0); 545 }
574 if (f->left_toolbar_was_visible
575 && !FRAME_REAL_LEFT_TOOLBAR_VISIBLE (f))
576 mswindows_clear_toolbar (f, LEFT_TOOLBAR, 0);
577 if (f->right_toolbar_was_visible
578 && !FRAME_REAL_RIGHT_TOOLBAR_VISIBLE (f))
579 mswindows_clear_toolbar (f, RIGHT_TOOLBAR, 0);
580 } 546 }
581 547
582 static void 548 static void
583 mswindows_free_frame_toolbars (struct frame *f) 549 mswindows_free_frame_toolbars (struct frame *f)
584 { 550 {
585 HWND twnd=NULL; 551 HWND twnd=NULL;
586 #define DELETE_TOOLBAR(pos) \ 552 #define DELETE_TOOLBAR(pos) \
587 mswindows_clear_toolbar(f, pos, 0); \ 553 mswindows_clear_toolbar (f, pos, 0); \
588 if ((twnd=GetDlgItem(FRAME_MSWINDOWS_HANDLE(f), \ 554 if ((twnd=GetDlgItem (FRAME_MSWINDOWS_HANDLE (f), \
589 TOOLBAR_ID_BIAS + pos))) \ 555 TOOLBAR_ID_BIAS + pos))) \
590 DestroyWindow(twnd) 556 DestroyWindow (twnd)
591 557
592 DELETE_TOOLBAR(TOP_TOOLBAR); 558 DELETE_TOOLBAR (TOP_EDGE);
593 DELETE_TOOLBAR(BOTTOM_TOOLBAR); 559 DELETE_TOOLBAR (BOTTOM_EDGE);
594 DELETE_TOOLBAR(LEFT_TOOLBAR); 560 DELETE_TOOLBAR (LEFT_EDGE);
595 DELETE_TOOLBAR(RIGHT_TOOLBAR); 561 DELETE_TOOLBAR (RIGHT_EDGE);
596 #undef DELETE_TOOLBAR 562 #undef DELETE_TOOLBAR
597 } 563 }
598 564
599 Lisp_Object 565 Lisp_Object
600 mswindows_get_toolbar_button_text (struct frame *f, int command_id) 566 mswindows_get_toolbar_button_text (struct frame *f, int command_id)