]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/tbargtk.cpp
removed stray return from SetFont()
[wxWidgets.git] / src / gtk / tbargtk.cpp
index cd573461e5e620b10fe57027042c5089d678e8c9..f1e0bcc9ad4467c6ebfd72b4e2c35049c2603579 100644 (file)
@@ -52,8 +52,7 @@ extern wxCursor   g_globalCursor;
 static void GetGtkStyle(long style,
                         GtkOrientation *orient, GtkToolbarStyle *gtkStyle)
 {
-    *orient = style & wxTB_VERTICAL ? GTK_ORIENTATION_VERTICAL
-                                    : GTK_ORIENTATION_HORIZONTAL;
+    *orient = ( style & wxTB_LEFT || style & wxTB_RIGHT ) ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL;
 
 
     if ( style & wxTB_TEXT )
@@ -124,21 +123,17 @@ public:
         }
     }
 
-    void SetPixmap(const wxBitmap& bitmap)
+    void SetImage(const wxBitmap& bitmap)
     {
         if (bitmap.Ok())
         {
-            GdkBitmap *mask = bitmap.GetMask() ? bitmap.GetMask()->GetBitmap()
-                                               : (GdkBitmap *)NULL;
-            if (bitmap.HasPixbuf())
-                gtk_image_set_from_pixbuf( GTK_IMAGE(m_pixmap), bitmap.GetPixbuf() );
-            else
-                gtk_pixmap_set( GTK_PIXMAP(m_pixmap), bitmap.GetPixmap(), mask );
+            // setting from pixmap doesn't seem to work right, but pixbuf works well
+            gtk_image_set_from_pixbuf((GtkImage*)m_image, bitmap.GetPixbuf());
         }
     }
 
     GtkWidget            *m_item;
-    GtkWidget            *m_pixmap;
+    GtkWidget            *m_image;
 
 protected:
     void Init();
@@ -176,7 +171,7 @@ static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget),
     {
         tool->Toggle();
 
-        tool->SetPixmap(tool->GetBitmap());
+        tool->SetImage(tool->GetBitmap());
 
         if ( tool->IsRadio() && !tool->IsToggled() )
         {
@@ -190,7 +185,7 @@ static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget),
         // revert back
         tool->Toggle();
 
-        tool->SetPixmap(tool->GetBitmap());
+        tool->SetImage(tool->GetBitmap());
     }
 }
 }
@@ -220,6 +215,27 @@ static gint gtk_toolbar_tool_callback( GtkWidget *WXUNUSED(widget),
 }
 }
 
+extern "C" {
+static
+void gtktoolwidget_size_callback( GtkWidget *widget,
+                                  GtkAllocation *alloc,
+                                  wxWindow *win )
+{
+    // this shouldn't happen...
+    if (win->GetParent()->m_wxwindow) return;
+    
+    wxSize size = win->GetEffectiveMinSize();
+    if (size.y != alloc->height)
+    {
+        GtkAllocation alloc2;
+        alloc2.x = alloc->x;
+        alloc2.y = (alloc->height - size.y + 3) / 2;
+        alloc2.width = alloc->width;
+        alloc2.height = size.y;
+        gtk_widget_size_allocate( widget, &alloc2 );
+    }
+}
+}
 //-----------------------------------------------------------------------------
 // InsertChild callback for wxToolBar
 //-----------------------------------------------------------------------------
@@ -237,7 +253,7 @@ static void wxInsertChildInToolBar( wxToolBar* WXUNUSED(parent),
 void wxToolBarTool::Init()
 {
     m_item =
-    m_pixmap = (GtkWidget *)NULL;
+    m_image = NULL;
 }
 
 wxToolBarToolBase *wxToolBar::CreateTool(int id,
@@ -292,6 +308,8 @@ bool wxToolBar::Create( wxWindow *parent,
         return false;
     }
 
+    FixupStyle();
+
     m_toolbar = GTK_TOOLBAR( gtk_toolbar_new() );
     GtkSetStyle();
 
@@ -331,6 +349,11 @@ bool wxToolBar::Create( wxWindow *parent,
     return true;
 }
 
+GdkWindow *wxToolBar::GTKGetWindow(wxArrayGdkWindows& windows) const
+{
+    return GTK_WIDGET(m_toolbar)->window;
+}
+
 void wxToolBar::GtkSetStyle()
 {
     GtkOrientation orient;
@@ -339,7 +362,7 @@ void wxToolBar::GtkSetStyle()
 
     gtk_toolbar_set_orientation(m_toolbar, orient);
     gtk_toolbar_set_style(m_toolbar, style);
-    gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), !(style & wxTB_NO_TOOLTIPS) );
+    gtk_toolbar_set_tooltips(m_toolbar, !(style & wxTB_NO_TOOLTIPS));
 }
 
 void wxToolBar::SetWindowStyleFlag( long style )
@@ -352,9 +375,7 @@ void wxToolBar::SetWindowStyleFlag( long style )
 
 bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
 {
-    wxToolBarTool *tool = (wxToolBarTool *)toolBase;
-
-    size_t posGtk = pos;
+    wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
 
     if ( tool->IsButton() )
     {
@@ -365,39 +386,15 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
             wxCHECK_MSG( bitmap.Ok(), false,
                          wxT("invalid bitmap for wxToolBar icon") );
 
-            wxCHECK_MSG( bitmap.GetDepth() != 1, false,
-                         wxT("wxToolBar doesn't support GdkBitmap") );
-
-            wxCHECK_MSG( bitmap.GetPixmap() != NULL, false,
-                         wxT("wxToolBar::Add needs a wxBitmap") );
-
-            GtkWidget *tool_pixmap = (GtkWidget *)NULL;
-
-
-            if (bitmap.HasPixbuf())
-            {
-                tool_pixmap = gtk_image_new();
-                tool->m_pixmap = tool_pixmap;
-                tool->SetPixmap(bitmap);
-            }
-            else
-            {
-                GdkPixmap *pixmap = bitmap.GetPixmap();
-
-                GdkBitmap *mask = (GdkBitmap *)NULL;
-                if ( bitmap.GetMask() )
-                    mask = bitmap.GetMask()->GetBitmap();
+            tool->m_image = gtk_image_new();
+            tool->SetImage(bitmap);
 
-                tool_pixmap = gtk_pixmap_new( pixmap, mask );
-                gtk_pixmap_set_build_insensitive( GTK_PIXMAP(tool_pixmap), TRUE );
-            }
-
-            gtk_misc_set_alignment( GTK_MISC(tool_pixmap), 0.5, 0.5 );
-
-            tool->m_pixmap = tool_pixmap;
+            gtk_misc_set_alignment((GtkMisc*)tool->m_image, 0.5, 0.5);
         }
     }
 
+    const int posGtk = int(pos);
+
     switch ( tool->GetStyle() )
     {
         case wxTOOL_STYLE_BUTTON:
@@ -446,18 +443,13 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
                                     ? NULL
                                     : (const char*) wxGTK_CONV( tool->GetShortHelp() ),
                                   "", // tooltip_private_text (?)
-                                  tool->m_pixmap,
+                                  tool->m_image,
                                   (GtkSignalFunc)gtk_toolbar_callback,
                                   (gpointer)tool,
                                   posGtk
                                );
 
-                if ( !tool->m_item )
-                {
-                    wxFAIL_MSG( _T("gtk_toolbar_insert_element() failed") );
-
-                    return false;
-                }
+                wxCHECK_MSG(tool->m_item != NULL, false, _T("gtk_toolbar_insert_element() failed"));
 
                 g_signal_connect (tool->m_item, "enter_notify_event",
                                   G_CALLBACK (gtk_toolbar_tool_callback),
@@ -482,6 +474,11 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
                                        (const char *) NULL,
                                        posGtk
                                       );
+                                      
+            // connect after in order to correct size_allocate events
+            g_signal_connect_after (tool->GetControl()->m_widget, "size_allocate",
+                          G_CALLBACK (gtktoolwidget_size_callback), tool->GetControl());
+                                      
             break;
     }
 
@@ -497,7 +494,7 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
 
 bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *toolBase)
 {
-    wxToolBarTool *tool = (wxToolBarTool *)toolBase;
+    wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
 
     switch ( tool->GetStyle() )
     {
@@ -524,7 +521,7 @@ bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *toolBase)
 
 void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable)
 {
-    wxToolBarTool *tool = (wxToolBarTool *)toolBase;
+    wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
 
     if (tool->m_item)
     {
@@ -534,12 +531,12 @@ void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable)
 
 void wxToolBar::DoToggleTool( wxToolBarToolBase *toolBase, bool toggle )
 {
-    wxToolBarTool *tool = (wxToolBarTool *)toolBase;
+    wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, toolBase);
 
     GtkWidget *item = tool->m_item;
     if ( item && GTK_IS_TOGGLE_BUTTON(item) )
     {
-        tool->SetPixmap(tool->GetBitmap());
+        tool->SetImage(tool->GetBitmap());
 
         m_blockEvent = true;
 
@@ -590,7 +587,7 @@ void wxToolBar::SetToolSeparation( int separation )
 
 void wxToolBar::SetToolShortHelp( int id, const wxString& helpString )
 {
-    wxToolBarTool *tool = (wxToolBarTool *)FindById(id);
+    wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id));
 
     if ( tool )
     {
@@ -600,6 +597,30 @@ void wxToolBar::SetToolShortHelp( int id, const wxString& helpString )
     }
 }
 
+void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap )
+{
+    wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id));
+    if ( tool )
+    {
+        wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools."));
+
+        tool->SetNormalBitmap(bitmap);
+        tool->SetImage(tool->GetBitmap());
+    }    
+}
+
+void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap )
+{
+    wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id));
+    if ( tool )
+    {
+        wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools."));
+
+        tool->SetDisabledBitmap(bitmap);
+        tool->SetImage(tool->GetBitmap());
+    }    
+}
+
 // ----------------------------------------------------------------------------
 // wxToolBar idle handling
 // ----------------------------------------------------------------------------