]> git.saurik.com Git - wxWidgets.git/commitdiff
Better disabling of toolbars and menubars
authorRobert Roebling <robert@roebling.de>
Wed, 13 Jan 1999 18:19:09 +0000 (18:19 +0000)
committerRobert Roebling <robert@roebling.de>
Wed, 13 Jan 1999 18:19:09 +0000 (18:19 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1397 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/gtk/menu.h
include/wx/gtk1/menu.h
samples/minifram/test.cpp
src/common/image.cpp
src/gtk/menu.cpp
src/gtk/tbargtk.cpp
src/gtk1/menu.cpp
src/gtk1/tbargtk.cpp

index 78445e7432759a3703896aed44d37bc604db73aa..860e0b8d14dcc711e1a927bb60b3585099290b7b 100644 (file)
@@ -56,8 +56,8 @@ public:
   bool Checked( int id ) const;
   void Enable( int id, bool enable );
   bool Enabled( int id ) const;
-  inline bool IsEnabled(int Id) const { return Enabled(Id); };
-  inline bool IsChecked(int Id) const { return Checked(Id); };
+  inline bool IsEnabled(int Id) const { return Enabled(Id); }
+  inline bool IsChecked(int Id) const { return Checked(Id); }
   
   wxString GetLabel( int id ) const;
   void SetLabel( int id, const wxString &label );
@@ -140,6 +140,7 @@ public:
   void          *m_clientData;
 
   GtkWidget     *m_menu;  // GtkMenu
+  GtkWidget     *m_owner;
 };
 
 #endif // __GTKMENUH__
index 78445e7432759a3703896aed44d37bc604db73aa..860e0b8d14dcc711e1a927bb60b3585099290b7b 100644 (file)
@@ -56,8 +56,8 @@ public:
   bool Checked( int id ) const;
   void Enable( int id, bool enable );
   bool Enabled( int id ) const;
-  inline bool IsEnabled(int Id) const { return Enabled(Id); };
-  inline bool IsChecked(int Id) const { return Checked(Id); };
+  inline bool IsEnabled(int Id) const { return Enabled(Id); }
+  inline bool IsChecked(int Id) const { return Checked(Id); }
   
   wxString GetLabel( int id ) const;
   void SetLabel( int id, const wxString &label );
@@ -140,6 +140,7 @@ public:
   void          *m_clientData;
 
   GtkWidget     *m_menu;  // GtkMenu
+  GtkWidget     *m_owner;
 };
 
 #endif // __GTKMENUH__
index 0343dea714e433d92e45e91e29e28da6a5b174ac..5fe386612ac17d735fb989d9747c2dc656d8b37e 100644 (file)
@@ -119,6 +119,8 @@ bool MyApp::InitToolbar(wxToolBar* toolBar)
   toolBar->AddTool(wxID_HELP, *(toolBarBitmaps[7]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Help");
 
   toolBar->Realize();
+  
+  toolBar->EnableTool( wxID_HELP, FALSE );
 
   // Can delete the bitmaps since they're reference counted
   int i;
index 7b0dc57f73ca29d568ac1430cf94e06d7ee49355..cfceb4dc1c2e2b31dfde914ae32c95b01d2b36fe 100644 (file)
@@ -491,12 +491,12 @@ bool wxPNGHandler::LoadFile( wxImage *image, wxInputStream& stream )
 {
     // VZ: as this function uses setjmp() the only fool proof error handling
     //     method is to use goto (setjmp is not really C++ dtors friendly...)
+    
+    unsigned char **lines = (unsigned char **) NULL;
+    png_infop info_ptr = (png_infop) NULL;
+    
     image->Destroy();
 
-    unsigned int i;
-    unsigned char **lines = NULL;
-    png_infop info_ptr = NULL;
-
     png_structp png_ptr = png_create_read_struct( PNG_LIBPNG_VER_STRING,
                                                   (voidp) NULL,
                                                   (png_error_ptr) NULL,
@@ -540,7 +540,7 @@ bool wxPNGHandler::LoadFile( wxImage *image, wxInputStream& stream )
     if (lines == NULL)
         goto error;
 
-    for (i = 0; i < height; i++)
+    for (unsigned int i = 0; i < height; i++)
     {
         if ((lines[i] = (unsigned char *)malloc(width * (sizeof(unsigned char) * 4))) == NULL)
         {
index 4696faeb11a73dd4df88c5214ecb175de663c88f..424da9aa7e341bc3bb5f894606c43dfc865fafbc 100644 (file)
@@ -55,12 +55,11 @@ void wxMenuBar::Append( wxMenu *menu, const wxString &title )
         if (pos != -1) menu->m_title.Remove( pos, 1 );
     } while (pos != -1);
 
-    GtkWidget *root_menu;
-    root_menu = gtk_menu_item_new_with_label( WXSTRINGCAST(menu->m_title) );
-    gtk_widget_show( root_menu );
-    gtk_menu_item_set_submenu( GTK_MENU_ITEM(root_menu), menu->m_menu );
+    menu->m_owner = gtk_menu_item_new_with_label( WXSTRINGCAST(menu->m_title) );
+    gtk_widget_show( menu->m_owner );
+    gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu );
 
-    gtk_menu_bar_append( GTK_MENU_BAR(m_menubar), root_menu );
+    gtk_menu_bar_append( GTK_MENU_BAR(m_menubar), menu->m_owner );
 }
 
 static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString, const wxString &itemString )
@@ -77,6 +76,7 @@ static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString
         wxMenuItem *item = (wxMenuItem*)node->Data();
         if (item->IsSubMenu())
             return FindMenuItemRecursive(item->GetSubMenu(), menuString, itemString);
+
         node = node->Next();
     }
 
@@ -158,27 +158,50 @@ bool wxMenuBar::Enabled( int id ) const
 wxString wxMenuBar::GetLabel( int id ) const
 {
     wxMenuItem* item = FindMenuItemById( id );
+    
     if (item) return item->GetText();
+    
     return "";
 }
 
 void wxMenuBar::SetLabel( int id, const wxString &label )
 {
     wxMenuItem* item = FindMenuItemById( id );
+    
     if (item) return item->SetText( label );
 }
 
-void wxMenuBar::EnableTop( int WXUNUSED(pos), bool WXUNUSED(flag) )
+void wxMenuBar::EnableTop( int pos, bool flag )
 {
+    wxNode *node = m_menus.Nth( pos );
+  
+    wxCHECK_RET( node, "menu not found" );
+  
+    wxMenu* menu = (wxMenu*)node->Data();
+  
+    if (menu->m_owner) gtk_widget_set_sensitive( menu->m_owner, flag );
 }
 
-wxString wxMenuBar::GetLabelTop( int WXUNUSED(pos) ) const
+wxString wxMenuBar::GetLabelTop( int pos ) const
 {
-  return "menu";
+    wxNode *node = m_menus.Nth( pos );
+  
+    wxCHECK_MSG( node, "invalid", "menu not found" );
+  
+    wxMenu* menu = (wxMenu*)node->Data();
+  
+    return menu->GetTitle();
 }
 
-void wxMenuBar::SetLabelTop( int WXUNUSED(pos), const wxString& WXUNUSED(label) )
+void wxMenuBar::SetLabelTop( int pos, const wxString& label )
 {
+    wxNode *node = m_menus.Nth( pos );
+  
+    wxCHECK_RET( node, "menu not found" );
+  
+    wxMenu* menu = (wxMenu*)node->Data();
+  
+    menu->SetTitle( label );
 }
 
 //-----------------------------------------------------------------------------
@@ -345,6 +368,8 @@ wxMenu::wxMenu( const wxString& title, const wxFunction func )
         Append(-2, m_title);
         AppendSeparator();
     }
+    
+    m_owner = (GtkWidget*) NULL;
 }
 
 void wxMenu::SetTitle( const wxString& title )
index 0c7e7f13208846982f4c56f906520c43890f8cad..df1b967d1d1ee2f90401fd67cf8339abf80a77a4 100644 (file)
@@ -196,10 +196,6 @@ wxToolBarTool *wxToolBar::AddTool( int toolIndex, const wxBitmap& bitmap,
     wxCHECK_MSG( bitmap.Ok(), (wxToolBarTool *)NULL,
                  "invalid bitmap for wxToolBar icon" );
 
-    wxToolBarTool *tool = new wxToolBarTool( this, toolIndex, bitmap, pushedBitmap,
-                                             toggle, clientData,
-                                             helpString1, helpString2 );
-
     wxCHECK_MSG( bitmap.GetBitmap() == NULL, (wxToolBarTool *)NULL,
                  "wxToolBar doesn't support GdkBitmap" );
 
@@ -218,6 +214,11 @@ wxToolBarTool *wxToolBar::AddTool( int toolIndex, const wxBitmap& bitmap,
   
     gtk_misc_set_alignment( GTK_MISC(tool_pixmap), 0.5, 0.5 );
 
+    wxToolBarTool *tool = new wxToolBarTool( this, toolIndex, bitmap, pushedBitmap,
+                                             toggle, clientData,
+                                             helpString1, helpString2,
+                                            tool_pixmap );
+
     GtkToolbarChildType ctype = toggle ? GTK_TOOLBAR_CHILD_TOGGLEBUTTON
                                        : GTK_TOOLBAR_CHILD_BUTTON;
 
@@ -288,8 +289,12 @@ void wxToolBar::EnableTool(int toolIndex, bool enable)
     {
         wxToolBarTool *tool = (wxToolBarTool*)node->Data();
         if (tool->m_index == toolIndex)
-        { 
+        {
             tool->m_enabled = enable;
+           
+           if (tool->m_item)
+               gtk_widget_set_sensitive( tool->m_item, enable );
+               
             return;
         }
         node = node->Next();
index 4696faeb11a73dd4df88c5214ecb175de663c88f..424da9aa7e341bc3bb5f894606c43dfc865fafbc 100644 (file)
@@ -55,12 +55,11 @@ void wxMenuBar::Append( wxMenu *menu, const wxString &title )
         if (pos != -1) menu->m_title.Remove( pos, 1 );
     } while (pos != -1);
 
-    GtkWidget *root_menu;
-    root_menu = gtk_menu_item_new_with_label( WXSTRINGCAST(menu->m_title) );
-    gtk_widget_show( root_menu );
-    gtk_menu_item_set_submenu( GTK_MENU_ITEM(root_menu), menu->m_menu );
+    menu->m_owner = gtk_menu_item_new_with_label( WXSTRINGCAST(menu->m_title) );
+    gtk_widget_show( menu->m_owner );
+    gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu );
 
-    gtk_menu_bar_append( GTK_MENU_BAR(m_menubar), root_menu );
+    gtk_menu_bar_append( GTK_MENU_BAR(m_menubar), menu->m_owner );
 }
 
 static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString, const wxString &itemString )
@@ -77,6 +76,7 @@ static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString
         wxMenuItem *item = (wxMenuItem*)node->Data();
         if (item->IsSubMenu())
             return FindMenuItemRecursive(item->GetSubMenu(), menuString, itemString);
+
         node = node->Next();
     }
 
@@ -158,27 +158,50 @@ bool wxMenuBar::Enabled( int id ) const
 wxString wxMenuBar::GetLabel( int id ) const
 {
     wxMenuItem* item = FindMenuItemById( id );
+    
     if (item) return item->GetText();
+    
     return "";
 }
 
 void wxMenuBar::SetLabel( int id, const wxString &label )
 {
     wxMenuItem* item = FindMenuItemById( id );
+    
     if (item) return item->SetText( label );
 }
 
-void wxMenuBar::EnableTop( int WXUNUSED(pos), bool WXUNUSED(flag) )
+void wxMenuBar::EnableTop( int pos, bool flag )
 {
+    wxNode *node = m_menus.Nth( pos );
+  
+    wxCHECK_RET( node, "menu not found" );
+  
+    wxMenu* menu = (wxMenu*)node->Data();
+  
+    if (menu->m_owner) gtk_widget_set_sensitive( menu->m_owner, flag );
 }
 
-wxString wxMenuBar::GetLabelTop( int WXUNUSED(pos) ) const
+wxString wxMenuBar::GetLabelTop( int pos ) const
 {
-  return "menu";
+    wxNode *node = m_menus.Nth( pos );
+  
+    wxCHECK_MSG( node, "invalid", "menu not found" );
+  
+    wxMenu* menu = (wxMenu*)node->Data();
+  
+    return menu->GetTitle();
 }
 
-void wxMenuBar::SetLabelTop( int WXUNUSED(pos), const wxString& WXUNUSED(label) )
+void wxMenuBar::SetLabelTop( int pos, const wxString& label )
 {
+    wxNode *node = m_menus.Nth( pos );
+  
+    wxCHECK_RET( node, "menu not found" );
+  
+    wxMenu* menu = (wxMenu*)node->Data();
+  
+    menu->SetTitle( label );
 }
 
 //-----------------------------------------------------------------------------
@@ -345,6 +368,8 @@ wxMenu::wxMenu( const wxString& title, const wxFunction func )
         Append(-2, m_title);
         AppendSeparator();
     }
+    
+    m_owner = (GtkWidget*) NULL;
 }
 
 void wxMenu::SetTitle( const wxString& title )
index 0c7e7f13208846982f4c56f906520c43890f8cad..df1b967d1d1ee2f90401fd67cf8339abf80a77a4 100644 (file)
@@ -196,10 +196,6 @@ wxToolBarTool *wxToolBar::AddTool( int toolIndex, const wxBitmap& bitmap,
     wxCHECK_MSG( bitmap.Ok(), (wxToolBarTool *)NULL,
                  "invalid bitmap for wxToolBar icon" );
 
-    wxToolBarTool *tool = new wxToolBarTool( this, toolIndex, bitmap, pushedBitmap,
-                                             toggle, clientData,
-                                             helpString1, helpString2 );
-
     wxCHECK_MSG( bitmap.GetBitmap() == NULL, (wxToolBarTool *)NULL,
                  "wxToolBar doesn't support GdkBitmap" );
 
@@ -218,6 +214,11 @@ wxToolBarTool *wxToolBar::AddTool( int toolIndex, const wxBitmap& bitmap,
   
     gtk_misc_set_alignment( GTK_MISC(tool_pixmap), 0.5, 0.5 );
 
+    wxToolBarTool *tool = new wxToolBarTool( this, toolIndex, bitmap, pushedBitmap,
+                                             toggle, clientData,
+                                             helpString1, helpString2,
+                                            tool_pixmap );
+
     GtkToolbarChildType ctype = toggle ? GTK_TOOLBAR_CHILD_TOGGLEBUTTON
                                        : GTK_TOOLBAR_CHILD_BUTTON;
 
@@ -288,8 +289,12 @@ void wxToolBar::EnableTool(int toolIndex, bool enable)
     {
         wxToolBarTool *tool = (wxToolBarTool*)node->Data();
         if (tool->m_index == toolIndex)
-        { 
+        {
             tool->m_enabled = enable;
+           
+           if (tool->m_item)
+               gtk_widget_set_sensitive( tool->m_item, enable );
+               
             return;
         }
         node = node->Next();