]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/tbargtk.cpp
removed stray return from SetFont()
[wxWidgets.git] / src / gtk / tbargtk.cpp
index e56eba64a14790c3d4995e60d8dc48ad3075e37d..f1e0bcc9ad4467c6ebfd72b4e2c35049c2603579 100644 (file)
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
-#include "wx/toolbar.h"
-
 #if wxUSE_TOOLBAR_NATIVE
 
+#include "wx/toolbar.h"
+
 #ifndef WX_PRECOMP
     #include "wx/frame.h"
 #endif
@@ -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());
     }
 }
 }
@@ -204,7 +199,7 @@ static gint gtk_toolbar_tool_callback( GtkWidget *WXUNUSED(widget),
                                        GdkEventCrossing *gdk_event,
                                        wxToolBarTool *tool )
 {
-    if (g_isIdle) wxapp_install_idle_handler();
+    // don't need to install idle handler, its done from "event" signal
 
     if (g_blockEventsOnDrag) return TRUE;
 
@@ -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();
 
@@ -317,7 +335,6 @@ bool wxToolBar::Create( wxWindow *parent,
         ConnectWidget( m_widget );
         gtk_widget_show(GTK_WIDGET(m_toolbar));
     }
-    gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), !(style & wxTB_NO_TOOLTIPS) );
 
     // FIXME: there is no such function for toolbars in 2.0
 #if 0
@@ -332,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;
@@ -340,30 +362,20 @@ void wxToolBar::GtkSetStyle()
 
     gtk_toolbar_set_orientation(m_toolbar, orient);
     gtk_toolbar_set_style(m_toolbar, style);
+    gtk_toolbar_set_tooltips(m_toolbar, !(style & wxTB_NO_TOOLTIPS));
 }
 
 void wxToolBar::SetWindowStyleFlag( long style )
 {
     wxToolBarBase::SetWindowStyleFlag(style);
-    if( style & wxTB_TOOLTIPS )
-    {
-        if( m_toolbar )
-             gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), TRUE );
-    }
-    else
-    {
-        if( m_toolbar )
-             gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), FALSE );
-    }
+
     if ( m_toolbar )
         GtkSetStyle();
 }
 
 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() )
     {
@@ -374,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.GetBitmap() == NULL, false,
-                         wxT("wxToolBar doesn't support GdkBitmap") );
-
-            wxCHECK_MSG( bitmap.GetPixmap() != NULL, false,
-                         wxT("wxToolBar::Add needs a wxBitmap") );
-
-            GtkWidget *tool_pixmap = (GtkWidget *)NULL;
-
+            tool->m_image = gtk_image_new();
+            tool->SetImage(bitmap);
 
-            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_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:
@@ -455,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),
@@ -491,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;
     }
 
@@ -506,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() )
     {
@@ -533,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)
     {
@@ -543,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;
 
@@ -599,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 )
     {
@@ -609,12 +597,39 @@ 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
 // ----------------------------------------------------------------------------
 
 void wxToolBar::OnInternalIdle()
 {
+    // Check if we have to show window now
+    if (GtkShowFromOnIdle()) return;
+    
     wxCursor cursor = m_cursor;
     if (g_globalCursor.Ok()) cursor = g_globalCursor;