]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/menu.cpp
Fixed compilo
[wxWidgets.git] / src / gtk / menu.cpp
index 08dae1a86782a600199aa573f4e3103c040f040c..ff08f83f5aa22fdfed3c33f237e70682448c5908 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        menu.cpp
+// Name:        src/gtk/menu.cpp
 // Purpose:
 // Author:      Robert Roebling
 // Id:          $Id$
 #include "wx/wxprec.h"
 
 #include "wx/menu.h"
-#include "wx/log.h"
-#include "wx/intl.h"
-#include "wx/app.h"
-#include "wx/bitmap.h"
 
-#if wxUSE_ACCEL
-    #include "wx/accel.h"
-#endif // wxUSE_ACCEL
+#ifndef WX_PRECOMP
+    #include "wx/intl.h"
+    #include "wx/log.h"
+    #include "wx/frame.h"
+    #include "wx/bitmap.h"
+#endif
 
+#include "wx/accel.h"
+#include "wx/stockitem.h"
 #include "wx/gtk/private.h"
 
-#include <gdk/gdkkeysyms.h>
-
 // FIXME: is this right? somehow I don't think so (VZ)
-#ifdef __WXGTK20__
-    #include <glib-object.h>
-
-    #define gtk_accel_group_attach(g, o) gtk_window_add_accel_group((o), (g))
-    #define gtk_accel_group_detach(g, o) gtk_window_remove_accel_group((o), (g))
-    #define gtk_menu_ensure_uline_accel_group(m) gtk_menu_get_accel_group(m)
-
-    #define ACCEL_OBJECT        GtkWindow
-    #define ACCEL_OBJECTS(a)    (a)->acceleratables
-    #define ACCEL_OBJ_CAST(obj) ((GtkWindow*) obj)
-#else // GTK+ 1.x
-    #define ACCEL_OBJECT        GtkObject
-    #define ACCEL_OBJECTS(a)    (a)->attach_objects
-    #define ACCEL_OBJ_CAST(obj) GTK_OBJECT(obj)
-#endif
+
+#define gtk_accel_group_attach(g, o) gtk_window_add_accel_group((o), (g))
+//#define gtk_accel_group_detach(g, o) gtk_window_remove_accel_group((o), (g))
+//#define gtk_menu_ensure_uline_accel_group(m) gtk_menu_get_accel_group(m)
+
+#define ACCEL_OBJECT        GtkWindow
+#define ACCEL_OBJECTS(a)    (a)->acceleratables
+#define ACCEL_OBJ_CAST(obj) ((GtkWindow*) obj)
 
 // we use normal item but with a special id for the menu title
 static const int wxGTK_TITLE_ID = -3;
@@ -147,7 +139,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxMenuBar,wxWindow)
 void wxMenuBar::Init(size_t n, wxMenu *menus[], const wxString titles[], long style)
 {
     // the parent window is known after wxFrame::SetMenu()
-    m_needParent = FALSE;
+    m_needParent = false;
     m_style = style;
     m_invokingWindow = (wxWindow*) NULL;
 
@@ -282,7 +274,7 @@ void wxMenuBar::UnsetInvokingWindow( wxWindow *win )
 bool wxMenuBar::Append( wxMenu *menu, const wxString &title )
 {
     if ( !wxMenuBarBase::Append( menu, title ) )
-        return FALSE;
+        return false;
 
     return GtkAppend(menu, title);
 }
@@ -328,20 +320,20 @@ bool wxMenuBar::GtkAppend(wxMenu *menu, const wxString& title, int pos)
             frame->UpdateMenuBarSize();
     }
 
-    return TRUE;
+    return true;
 }
 
 bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
 {
     if ( !wxMenuBarBase::Insert(pos, menu, title) )
-        return FALSE;
+        return false;
 
     // TODO
 
     if ( !GtkAppend(menu, title, (int)pos) )
-        return FALSE;
+        return false;
 
-    return TRUE;
+    return true;
 }
 
 wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
@@ -747,7 +739,7 @@ void wxMenuItem::SetText( const wxString& str )
     oldLabel.Replace(wxT("_"), wxT(""));
     wxString label1 = wxStripMenuCodes(str);
     wxString oldhotkey = GetHotKey();    // Store the old hotkey in Ctrl-foo format
-    wxCharBuffer oldbuf = wxGTK_CONV( GetGtkHotKey(*this) );  // and as <control>foo
+    wxCharBuffer oldbuf = wxGTK_CONV_SYS( GetGtkHotKey(*this) );  // and as <control>foo
 
     DoSetText(str);
 
@@ -763,7 +755,7 @@ void wxMenuItem::SetText( const wxString& str )
         else
             label = GTK_LABEL( GTK_BIN(m_menuItem)->child );
 
-        gtk_label_set_text_with_mnemonic( GTK_LABEL(label), wxGTK_CONV(m_text) );
+        gtk_label_set_text_with_mnemonic( GTK_LABEL(label), wxGTK_CONV_SYS(m_text) );
     }
 
     guint accel_key;
@@ -777,7 +769,7 @@ void wxMenuItem::SetText( const wxString& str )
                                        accel_mods );
     }
 
-    wxCharBuffer buf = wxGTK_CONV( GetGtkHotKey(*this) );
+    wxCharBuffer buf = wxGTK_CONV_SYS( GetGtkHotKey(*this) );
     gtk_accelerator_parse( (const char*) buf, &accel_key, &accel_mods);
     if (accel_key != 0)
     {
@@ -880,9 +872,9 @@ void wxMenuItem::Enable( bool enable )
 
 bool wxMenuItem::IsChecked() const
 {
-    wxCHECK_MSG( m_menuItem, FALSE, wxT("invalid menu item") );
+    wxCHECK_MSG( m_menuItem, false, wxT("invalid menu item") );
 
-    wxCHECK_MSG( IsCheckable(), FALSE,
+    wxCHECK_MSG( IsCheckable(), false,
                  wxT("can't get state of uncheckable item!") );
 
     return ((GtkCheckMenuItem*)m_menuItem)->active != 0;
@@ -949,43 +941,62 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
     {
         menuItem = gtk_separator_menu_item_new();
     }
-    else if (mitem->GetBitmap().Ok())
+    else if ( mitem->GetBitmap().Ok() ||
+                (mitem->GetKind() == wxITEM_NORMAL &&
+                    wxIsStockID(mitem->GetId())) )
     {
         text = mitem->GetText();
-        const wxBitmap *bitmap = &mitem->GetBitmap();
+        wxBitmap bitmap(mitem->GetBitmap());
 
-        menuItem = gtk_image_menu_item_new_with_mnemonic( wxGTK_CONV( text ) );
+        menuItem = gtk_image_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text ) );
 
         GtkWidget *image;
-        if (bitmap->HasPixbuf())
+        if ( !bitmap.Ok() )
         {
-            image = gtk_image_new_from_pixbuf(bitmap->GetPixbuf());
+            // use stock bitmap for this item if available on the assumption
+            // that it never hurts to follow GTK+ conventions more closely
+            const char *stock = wxGetStockGtkID(mitem->GetId());
+            image = stock ? gtk_image_new_from_stock(stock, GTK_ICON_SIZE_MENU)
+                          : NULL;
         }
-        else
+        else // we have a custom bitmap
         {
-            GdkPixmap *gdk_pixmap = bitmap->GetPixmap();
-            GdkBitmap *gdk_bitmap = bitmap->GetMask() ?
-                                        bitmap->GetMask()->GetBitmap() :
-                                        (GdkBitmap*) NULL;
-            image = gtk_image_new_from_pixmap( gdk_pixmap, gdk_bitmap );
+            wxASSERT_MSG( mitem->GetKind() == wxITEM_NORMAL,
+                            _T("only normal menu items can have bitmaps") );
+
+            if ( bitmap.HasPixbuf() )
+            {
+                image = gtk_image_new_from_pixbuf(bitmap.GetPixbuf());
+            }
+            else
+            {
+                GdkPixmap *gdk_pixmap = bitmap.GetPixmap();
+                GdkBitmap *gdk_bitmap = bitmap.GetMask() ?
+                                            bitmap.GetMask()->GetBitmap() :
+                                            (GdkBitmap*) NULL;
+                image = gtk_image_new_from_pixmap( gdk_pixmap, gdk_bitmap );
+            }
         }
 
-        gtk_widget_show(image);
+        if ( image )
+        {
+            gtk_widget_show(image);
 
-        gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(menuItem), image );
+            gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(menuItem), image );
+        }
 
         m_prevRadio = NULL;
     }
     else // a normal item
     {
         // text has "_" instead of "&" after mitem->SetText() so don't use it
-        text =  mitem->GetText() ;
+        text = mitem->GetText() ;
 
         switch ( mitem->GetKind() )
         {
             case wxITEM_CHECK:
             {
-                menuItem = gtk_check_menu_item_new_with_mnemonic( wxGTK_CONV( text ) );
+                menuItem = gtk_check_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text ) );
                 m_prevRadio = NULL;
                 break;
             }
@@ -996,12 +1007,14 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
                 if ( m_prevRadio == NULL )
                 {
                     // start of a new radio group
-                    m_prevRadio = menuItem = gtk_radio_menu_item_new_with_mnemonic( group, wxGTK_CONV( text ) );
+                    m_prevRadio = menuItem =
+                        gtk_radio_menu_item_new_with_mnemonic( group, wxGTK_CONV_SYS( text ) );
                 }
                 else // continue the radio group
                 {
                     group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (m_prevRadio));
-                    m_prevRadio = menuItem = gtk_radio_menu_item_new_with_mnemonic( group, wxGTK_CONV( text ) );
+                    m_prevRadio = menuItem =
+                        gtk_radio_menu_item_new_with_mnemonic( group, wxGTK_CONV_SYS( text ) );
                 }
                 break;
             }
@@ -1012,7 +1025,7 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
 
             case wxITEM_NORMAL:
             {
-                menuItem = gtk_menu_item_new_with_mnemonic( wxGTK_CONV( text ) );
+                menuItem = gtk_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text ) );
                 m_prevRadio = NULL;
                 break;
             }
@@ -1022,7 +1035,7 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
 
     guint accel_key;
     GdkModifierType accel_mods;
-    wxCharBuffer buf = wxGTK_CONV( GetGtkHotKey(*mitem) );
+    wxCharBuffer buf = wxGTK_CONV_SYS( GetGtkHotKey(*mitem) );
 
     // wxPrintf( wxT("item: %s hotkey %s\n"), mitem->GetText().c_str(), GetGtkHotKey(*mitem).c_str() );
     gtk_accelerator_parse( (const char*) buf, &accel_key, &accel_mods);
@@ -1080,7 +1093,7 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
         // gtk_widget_lock_accelerators(mitem->GetMenuItem());
     }
 
-    return TRUE;
+    return true;
 }
 
 wxMenuItem* wxMenu::DoAppend(wxMenuItem *mitem)
@@ -1409,7 +1422,7 @@ static wxString GetGtkHotKey( const wxMenuItem& item )
 extern "C" WXDLLIMPEXP_CORE
 void gtk_pop_hide_callback( GtkWidget *WXUNUSED(widget), bool* is_waiting  )
 {
-    *is_waiting = FALSE;
+    *is_waiting = false;
 }
 
 WXDLLIMPEXP_CORE void SetInvokingWindow( wxMenu *menu, wxWindow* win )
@@ -1512,4 +1525,3 @@ bool wxWindowGTK::DoPopupMenu( wxMenu *menu, int x, int y )
 }
 
 #endif // wxUSE_MENUS_NATIVE
-