update.
[chise/xemacs-chise.git.1] / src / toolbar-msw.c
index b9fa959..774e34f 100644 (file)
@@ -22,7 +22,7 @@ along with XEmacs; see the file COPYING.  If not, write to
 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
-/* This implementation by Andy Piper <andyp@parallax.co.uk>, with bits
+/* This implementation by Andy Piper <andy@xemacs.org>, with bits
    borrowed from toolbar-x.c */
 
 /* Synched up with: Not in FSF. */
@@ -46,19 +46,14 @@ Boston, MA 02111-1307, USA.  */
 #define TOOLBAR_ID_BIAS 16
 #define TOOLBAR_HANDLE(f,p) \
 GetDlgItem(FRAME_MSWINDOWS_HANDLE(f), TOOLBAR_ID_BIAS + p)
-#ifndef TB_SETIMAGELIST
-#define TB_SETIMAGELIST (WM_USER + 48)
-#define TB_GETIMAGELIST (WM_USER + 49)
-#define TB_SETDISABLEDIMAGELIST (WM_USER + 54)
-#define TB_GETDISABLEDIMAGELIST (WM_USER + 55)
-#endif
-#ifndef TB_SETPADDING
-#define TB_SETPADDING   (WM_USER + 87)
-#endif
+
 #define MSWINDOWS_BUTTON_SHADOW_THICKNESS 2
 #define MSWINDOWS_BLANK_SIZE 5
 #define MSWINDOWS_MINIMUM_TOOLBAR_SIZE 8
 
+static void
+mswindows_move_toolbar (struct frame *f, enum toolbar_pos pos);
+
 #define SET_TOOLBAR_WAS_VISIBLE_FLAG(frame, pos, flag)                 \
   do {                                                                 \
     switch (pos)                                                       \
@@ -76,7 +71,7 @@ GetDlgItem(FRAME_MSWINDOWS_HANDLE(f), TOOLBAR_ID_BIAS + p)
        (frame)->right_toolbar_was_visible = flag;                      \
        break;                                                          \
       default:                                                         \
-       abort ();                                                       \
+       ABORT ();                                                       \
       }                                                                        \
   } while (0)
 
@@ -87,7 +82,7 @@ allocate_toolbar_item_id (struct frame* f, struct toolbar_button* button,
   /* hmm what do we generate an id based on */
   int id = TOOLBAR_ITEM_ID_BITS (internal_hash (button->callback, 0));
   while (!NILP (Fgethash (make_int (id),
-                         FRAME_MSWINDOWS_TOOLBAR_HASHTABLE (f), Qnil)))
+                         FRAME_MSWINDOWS_TOOLBAR_HASH_TABLE (f), Qnil)))
     {
       id = TOOLBAR_ITEM_ID_BITS (id + 1);
     }
@@ -105,14 +100,14 @@ mswindows_clear_toolbar (struct frame *f, enum toolbar_pos pos,
     {
       TBBUTTON info;
       
-      /* delete the buttons and remove the command from the hashtable*/
+      /* Delete the buttons and remove the command from the hash table*/
       i = SendMessage (toolbarwnd, TB_BUTTONCOUNT, 0, 0);
       for (i--; i >= 0; i--)
        {
          SendMessage (toolbarwnd, TB_GETBUTTON, (WPARAM)i, 
                       (LPARAM)&info);
          Fremhash(make_int(info.idCommand), 
-                  FRAME_MSWINDOWS_TOOLBAR_HASHTABLE(f));
+                  FRAME_MSWINDOWS_TOOLBAR_HASH_TABLE(f));
          SendMessage (toolbarwnd, TB_DELETEBUTTON, (WPARAM)i, 0);
        }
          
@@ -128,7 +123,7 @@ mswindows_clear_toolbar (struct frame *f, enum toolbar_pos pos,
       ShowWindow(toolbarwnd, SW_HIDE);
     }
 
-  FRAME_MSWINDOWS_TOOLBAR_CHECKSUM(f,pos)=0;
+  FRAME_MSWINDOWS_TOOLBAR_CHECKSUM (f, pos) = 0;
   SET_TOOLBAR_WAS_VISIBLE_FLAG (f, pos, 0);
 }
 
@@ -205,10 +200,11 @@ mswindows_output_toolbar (struct frame *f, enum toolbar_pos pos)
     {
 
       struct toolbar_button *tb = XTOOLBAR_BUTTON (button);
-      checksum = HASH4 (checksum, 
+      checksum = HASH5 (checksum, 
                        internal_hash (get_toolbar_button_glyph(w, tb), 0),
                        internal_hash (tb->callback, 0),
-                       width);
+                       width,
+                       LISP_HASH (w->toolbar_buttons_captioned_p));
       button = tb->next;
       nbuttons++;
     }
@@ -219,7 +215,7 @@ mswindows_output_toolbar (struct frame *f, enum toolbar_pos pos)
       /* remove the old one */
       mswindows_clear_toolbar (f, pos, 0);
 
-      FRAME_MSWINDOWS_TOOLBAR_CHECKSUM(f,pos)=checksum;
+      FRAME_MSWINDOWS_TOOLBAR_CHECKSUM (f, pos)=checksum;
 
       /* build up the data required by win32 fns. */
       button_tbl = xnew_array_and_zero (TBBUTTON, nbuttons);
@@ -258,11 +254,11 @@ mswindows_output_toolbar (struct frame *f, enum toolbar_pos pos)
              
              if (IMAGE_INSTANCEP (instance))
                {
-                 struct Lisp_Image_Instance* p = XIMAGE_INSTANCE (instance);
+                 Lisp_Image_Instance* p = XIMAGE_INSTANCE (instance);
                  
                  if (IMAGE_INSTANCE_PIXMAP_TYPE_P (p))
                    {
-                     /* we are going to honour the toolbar settings
+                     /* we are going to honor the toolbar settings
                         and resize the bitmaps accordingly if they are
                         too big.  If they are too small we leave them
                         and pad the difference - unless a different size
@@ -293,7 +289,7 @@ mswindows_output_toolbar (struct frame *f, enum toolbar_pos pos)
                            {
                              xfree (button_tbl);
                              if (ilist) ImageList_Destroy (ilist);
-                             signal_simple_error ("couldn't resize pixmap", 
+                             signal_simple_error ("Couldn't resize pixmap", 
                                                   instance);
                            }
                          /* we don't care if the mask fails */
@@ -316,7 +312,7 @@ mswindows_output_toolbar (struct frame *f, enum toolbar_pos pos)
                                        nbuttons, nbuttons * 2 )))
                        {
                          xfree (button_tbl);
-                         signal_simple_error ("couldn't create image list",
+                         signal_simple_error ("Couldn't create image list",
                                               instance);
                        }
 
@@ -343,7 +339,7 @@ mswindows_output_toolbar (struct frame *f, enum toolbar_pos pos)
                }
 
              Fputhash (make_int (tbbutton->idCommand), 
-                       button, FRAME_MSWINDOWS_TOOLBAR_HASHTABLE (f));
+                       button, FRAME_MSWINDOWS_TOOLBAR_HASH_TABLE (f));
            }
 
          /* now fix up the button size */
@@ -380,10 +376,12 @@ mswindows_output_toolbar (struct frame *f, enum toolbar_pos pos)
           CreateWindowEx ( WS_EX_WINDOWEDGE,
                            TOOLBARCLASSNAME,
                            NULL,
-                           WS_CHILD | WS_VISIBLE 
+                           WS_CHILD 
                            | (style_3d ? WS_DLGFRAME : 0)
-                           | TBSTYLE_TOOLTIPS | CCS_NORESIZE 
-                           | CCS_NOPARENTALIGN | CCS_NODIVIDER,
+                           | TBSTYLE_TOOLTIPS 
+                           | CCS_NORESIZE 
+                           | CCS_NOPARENTALIGN | CCS_NODIVIDER
+                           | CCS_ADJUSTABLE,
                            x, y, bar_width, bar_height,
                            FRAME_MSWINDOWS_HANDLE (f),
                            (HMENU)(TOOLBAR_ID_BIAS + pos),
@@ -459,6 +457,9 @@ mswindows_output_toolbar (struct frame *f, enum toolbar_pos pos)
 
       /* now display the window */
       ShowWindow (toolbarwnd, SW_SHOW);
+      /* no idea why this is necessary but initial display will not
+         happen otherwise. */
+      mswindows_move_toolbar (f, pos);
 
       if (button_tbl) xfree (button_tbl);
 
@@ -524,6 +525,13 @@ mswindows_redraw_exposed_toolbars (struct frame *f, int x, int y, int width,
 }
 
 static void
+mswindows_redraw_frame_toolbars (struct frame *f)
+{
+  mswindows_redraw_exposed_toolbars (f, 0, 0, FRAME_PIXWIDTH (f),
+                                    FRAME_PIXHEIGHT (f));
+}
+
+static void
 mswindows_initialize_frame_toolbars (struct frame *f)
 {
 
@@ -536,22 +544,30 @@ mswindows_output_frame_toolbars (struct frame *f)
 
   if (FRAME_REAL_TOP_TOOLBAR_VISIBLE (f))
     mswindows_output_toolbar (f, TOP_TOOLBAR);
-  else if (f->top_toolbar_was_visible)
-    mswindows_clear_toolbar (f, TOP_TOOLBAR, 0);
-
   if (FRAME_REAL_BOTTOM_TOOLBAR_VISIBLE (f))
     mswindows_output_toolbar (f, BOTTOM_TOOLBAR);
-  else if (f->bottom_toolbar_was_visible)
-    mswindows_clear_toolbar (f, BOTTOM_TOOLBAR, 0);
-
   if (FRAME_REAL_LEFT_TOOLBAR_VISIBLE (f))
     mswindows_output_toolbar (f, LEFT_TOOLBAR);
-  else if (f->left_toolbar_was_visible)
-    mswindows_clear_toolbar (f, LEFT_TOOLBAR, 0);
-
   if (FRAME_REAL_RIGHT_TOOLBAR_VISIBLE (f))
     mswindows_output_toolbar (f, RIGHT_TOOLBAR);
-  else if (f->right_toolbar_was_visible)
+}
+
+static void
+mswindows_clear_frame_toolbars (struct frame *f)
+{
+  assert (FRAME_MSWINDOWS_P (f));
+
+  if (f->top_toolbar_was_visible
+      && !FRAME_REAL_TOP_TOOLBAR_VISIBLE (f))
+    mswindows_clear_toolbar (f, TOP_TOOLBAR, 0);
+  if (f->bottom_toolbar_was_visible
+      && !FRAME_REAL_BOTTOM_TOOLBAR_VISIBLE (f))
+    mswindows_clear_toolbar (f, BOTTOM_TOOLBAR, 0);
+  if (f->left_toolbar_was_visible 
+      && !FRAME_REAL_LEFT_TOOLBAR_VISIBLE (f))
+    mswindows_clear_toolbar (f, LEFT_TOOLBAR, 0);
+  if (f->right_toolbar_was_visible 
+      && !FRAME_REAL_RIGHT_TOOLBAR_VISIBLE (f))
     mswindows_clear_toolbar (f, RIGHT_TOOLBAR, 0);
 }
 
@@ -559,9 +575,10 @@ static void
 mswindows_free_frame_toolbars (struct frame *f)
 {
   HWND twnd=NULL;
-#define DELETE_TOOLBAR(pos) \
-  mswindows_clear_toolbar(f, 0, pos); \
-  if ((twnd=GetDlgItem(FRAME_MSWINDOWS_HANDLE(f), TOOLBAR_ID_BIAS + pos))) \
+#define DELETE_TOOLBAR(pos)                            \
+  mswindows_clear_toolbar(f, pos, 0);                  \
+  if ((twnd=GetDlgItem(FRAME_MSWINDOWS_HANDLE(f),      \
+                      TOOLBAR_ID_BIAS + pos)))         \
       DestroyWindow(twnd)
 
   DELETE_TOOLBAR(TOP_TOOLBAR);
@@ -572,7 +589,7 @@ mswindows_free_frame_toolbars (struct frame *f)
 }
 
 /* map toolbar hwnd to pos*/
-int mswindows_find_toolbar_pos(struct frame* f, HWND ctrl)
+static int mswindows_find_toolbar_pos(struct frame* f, HWND ctrl)
 {
   int id = GetDlgCtrlID(ctrl);
   return id ? id - TOOLBAR_ID_BIAS : -1;
@@ -582,7 +599,7 @@ Lisp_Object
 mswindows_get_toolbar_button_text ( struct frame* f, int command_id )
 {
   Lisp_Object button = Fgethash (make_int (command_id),
-                                FRAME_MSWINDOWS_TOOLBAR_HASHTABLE (f), Qnil);
+                                FRAME_MSWINDOWS_TOOLBAR_HASH_TABLE (f), Qnil);
   
   if (!NILP (button))
     {
@@ -605,7 +622,7 @@ mswindows_handle_toolbar_wm_command (struct frame* f, HWND ctrl, WORD id)
   Lisp_Object button, data, fn, arg, frame;
 
   button = Fgethash (make_int (id), 
-                    FRAME_MSWINDOWS_TOOLBAR_HASHTABLE (f), Qnil);
+                    FRAME_MSWINDOWS_TOOLBAR_HASH_TABLE (f), Qnil);
 
   if (NILP (button))
     return Qnil;
@@ -632,8 +649,10 @@ void
 console_type_create_toolbar_mswindows (void)
 {
   CONSOLE_HAS_METHOD (mswindows, output_frame_toolbars);
+  CONSOLE_HAS_METHOD (mswindows, clear_frame_toolbars);
   CONSOLE_HAS_METHOD (mswindows, initialize_frame_toolbars);
   CONSOLE_HAS_METHOD (mswindows, free_frame_toolbars);
   CONSOLE_HAS_METHOD (mswindows, redraw_exposed_toolbars);
+  CONSOLE_HAS_METHOD (mswindows, redraw_frame_toolbars);
 }