wxMenu code clean up

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1967 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1999-03-24 19:05:19 +00:00
parent 1c22cf1cf1
commit c626a8b797
16 changed files with 1458 additions and 1356 deletions

View File

@@ -201,13 +201,14 @@ before matching.
\membersection{wxMenu::FindItemForId}\label{wxmenufinditemforid} \membersection{wxMenu::FindItemForId}\label{wxmenufinditemforid}
\constfunc{wxMenuItem*}{FindItemForId}{\param{int}{ id}} \constfunc{wxMenuItem*}{FindItemForId}{\param{int}{ id}, \param{wxMenu **}{ menuForItem = NULL}}
Finds the menu item object associated with the given menu item identifier. Finds the menu item object associated with the given menu item identifier.
\wxheading{Parameters} \wxheading{Parameters}
\docparam{id}{Menu item identifier.} \docparam{id}{Menu item identifier.}
\docparam{menuForItem}{will be filled with the menu for this item if not NULL.}
\wxheading{Return value} \wxheading{Return value}

View File

@@ -39,118 +39,148 @@ class wxMenu;
// wxMenuBar // wxMenuBar
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class wxMenuBar: public wxWindow class wxMenuBar : public wxWindow
{ {
DECLARE_DYNAMIC_CLASS(wxMenuBar) DECLARE_DYNAMIC_CLASS(wxMenuBar)
public: public:
wxMenuBar( long style ); // ctors
wxMenuBar(); wxMenuBar();
void Append( wxMenu *menu, const wxString &title ); wxMenuBar(long style);
wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
int FindMenuItem( const wxString &menuString, const wxString &itemString ) const; // menubar construction
wxMenuItem* FindMenuItemById( int id ) const; void Append( wxMenu *menu, const wxString &title );
inline wxMenuItem* FindItemForId( int id ) const { return FindMenuItemById( id ); }
void Check( int id, bool check );
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); }
wxString GetLabel( int id ) const;
void SetLabel( int id, const wxString &label );
void EnableTop( int pos, bool flag );
void SetLabelTop( int pos, const wxString& label );
wxString GetLabelTop( int pos ) const;
virtual void SetHelpString( int id, const wxString& helpString ); // item search
virtual wxString GetHelpString( int id ) const; // by menu and item names, returns wxNOT_FOUND if not found
virtual int FindMenuItem(const wxString& menuString,
inline int GetMenuCount() const { return m_menus.Number(); } const wxString& itemString) const;
inline wxMenu *GetMenu( int n ) const { return (wxMenu *)m_menus.Nth(n)->Data(); } // returns NULL if not found
wxMenuItem* FindItem( int id ) const;
// returns NULL if not found, fills menuForItem if !NULL
wxMenuItem *FindItemForId(int itemId, wxMenu **menuForItem = NULL) const;
wxList m_menus; // state control
GtkWidget *m_menubar; void Check( int id, bool check );
bool IsChecked( int id ) const;
void Enable( int id, bool enable );
bool IsEnabled( int id ) const;
wxString GetLabel( int id ) const;
void SetLabel( int id, const wxString &label );
void EnableTop( int pos, bool flag );
void SetLabelTop( int pos, const wxString& label );
wxString GetLabelTop( int pos ) const;
virtual void SetHelpString( int id, const wxString& helpString );
virtual wxString GetHelpString( int id ) const;
int GetMenuCount() const { return m_menus.Number(); }
wxMenu *GetMenu( int n ) const { return (wxMenu *)m_menus.Nth(n)->Data(); }
#ifdef WXWIN_COMPATIBILITY
// compatibility: these functions are deprecated
bool Enabled(int id) const { return IsEnabled(id); }
bool Checked(int id) const { return IsChecked(id); }
wxMenuItem* FindMenuItemById( int id ) const { return FindItem(id); }
#endif // WXWIN_COMPATIBILITY
// implementation
wxList& GetMenus() { return m_menus; }
protected:
wxList m_menus;
GtkWidget *m_menubar;
}; };
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxMenu // wxMenu
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class wxMenu: public wxEvtHandler class wxMenu : public wxEvtHandler
{ {
DECLARE_DYNAMIC_CLASS(wxMenu) DECLARE_DYNAMIC_CLASS(wxMenu)
public: public:
// construction // construction
wxMenu( const wxString& title = wxEmptyString, const wxFunction func = (wxFunction) NULL ); wxMenu( const wxString& title = wxEmptyString,
const wxFunction func = (wxFunction) NULL );
// operations // operations
// title // title
void SetTitle(const wxString& label); void SetTitle(const wxString& label);
const wxString GetTitle() const; const wxString GetTitle() const;
// menu creation // menu creation
void AppendSeparator(); void AppendSeparator();
void Append(int id, const wxString &item, void Append(int id, const wxString &item,
const wxString &helpStr = "", bool checkable = FALSE); const wxString &helpStr = "", bool checkable = FALSE);
void Append(int id, const wxString &item, void Append(int id, const wxString &item,
wxMenu *subMenu, const wxString &helpStr = "" ); wxMenu *subMenu, const wxString &helpStr = "" );
void Append(wxMenuItem *pItem); void Append(wxMenuItem *pItem);
void Break() {}; void Break() { }
// find item by name/id // find item by name/id
int FindItem( const wxString itemString ) const; int FindItem( const wxString itemString ) const;
wxMenuItem *FindItem( int id ) const; wxMenuItem *FindItem( int id ) const;
wxMenuItem *FindItemForId( int id ) const { return FindItem( id ); }
// get/set item's state // get/set item's state
void Enable( int id, bool enable ); void Enable( int id, bool enable );
bool IsEnabled( int id ) const; bool IsEnabled( int id ) const;
void Check( int id, bool check ); void Check( int id, bool check );
bool IsChecked( int id ) const; bool IsChecked( int id ) const;
void SetLabel( int id, const wxString &label ); void SetLabel( int id, const wxString &label );
wxString GetLabel( int id ) const; wxString GetLabel( int id ) const;
// helpstring // helpstring
virtual void SetHelpString(int id, const wxString& helpString); virtual void SetHelpString(int id, const wxString& helpString);
virtual wxString GetHelpString(int id) const ; virtual wxString GetHelpString(int id) const ;
// accessors
wxList& GetItems() { return m_items; }
inline void Callback(const wxFunction func) { m_callback = func; } // accessors
wxList& GetItems() { return m_items; }
inline void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
inline wxEvtHandler *GetEventHandler() { return m_eventHandler; }
inline void SetClientData( void* clientData ) { m_clientData = clientData; }
inline void* GetClientData() const { return m_clientData; }
// Updates the UI for a menu and all submenus recursively.
// source is the object that has the update event handlers
// defined for it. If NULL, the menu or associated window
// will be used.
void UpdateUI(wxEvtHandler* source = (wxEvtHandler*) NULL);
// implementation void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
wxEvtHandler *GetEventHandler() { return m_eventHandler; }
int FindMenuIdByMenuItem( GtkWidget *menuItem ) const;
void SetInvokingWindow( wxWindow *win );
wxWindow *GetInvokingWindow();
wxString m_title; void SetClientData( void* clientData ) { m_clientData = clientData; }
wxList m_items; void* GetClientData() const { return m_clientData; }
wxWindow *m_invokingWindow;
wxFunction m_callback;
wxEvtHandler *m_eventHandler;
void *m_clientData;
GtkWidget *m_menu; // GtkMenu // Updates the UI for a menu and all submenus recursively.
GtkWidget *m_owner; // source is the object that has the update event handlers
// defined for it. If NULL, the menu or associated window
// will be used.
void UpdateUI(wxEvtHandler* source = (wxEvtHandler*) NULL);
wxMenuItem *FindItemForId( int id ) const { return FindItem( id ); }
#ifdef WXWIN_COMPATIBILITY
wxFunction GetCallback() const { return m_callback; }
void Callback(const wxFunction func) { m_callback = func; }
// compatibility: these functions are deprecated
bool Enabled(int id) const { return IsEnabled(id); }
bool Checked(int id) const { return IsChecked(id); }
#endif // WXWIN_COMPATIBILITY
// implementation
int FindMenuIdByMenuItem( GtkWidget *menuItem ) const;
void SetInvokingWindow( wxWindow *win );
wxWindow *GetInvokingWindow();
// implementation only
GtkWidget *m_menu; // GtkMenu
GtkWidget *m_owner;
private:
wxString m_title;
wxList m_items;
wxWindow *m_invokingWindow;
wxFunction m_callback;
wxEvtHandler *m_eventHandler;
void *m_clientData;
}; };
#endif // __GTKMENUH__ #endif // __GTKMENUH__

View File

@@ -28,63 +28,65 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class wxMenuItem; class wxMenuItem;
class wxMenu; class wxMenu;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxMenuItem // wxMenuItem
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class wxMenuItem: public wxObject class wxMenuItem : public wxObject
{ {
DECLARE_DYNAMIC_CLASS(wxMenuItem) DECLARE_DYNAMIC_CLASS(wxMenuItem)
public: public:
wxMenuItem(); wxMenuItem();
// accessors // accessors
// id // id
void SetId(int id) { m_id = id; } void SetId(int id) { m_id = id; }
int GetId() const { return m_id; } int GetId() const { return m_id; }
bool IsSeparator() const { return m_id == ID_SEPARATOR; } bool IsSeparator() const { return m_id == ID_SEPARATOR; }
// the item's text = name // the item's text = name
void SetName(const wxString& str); void SetName(const wxString& str);
void SetText(const wxString& str) { SetName(str); } // compatibility void SetText(const wxString& str) { SetName(str); } // compatibility
const wxString& GetName() const { return m_text; } const wxString& GetName() const { return m_text; }
const wxString& GetText() const { return GetName(); } const wxString& GetText() const { return GetName(); }
// what kind of menu item we are // what kind of menu item we are
void SetCheckable(bool checkable) { m_isCheckMenu = checkable; } void SetCheckable(bool checkable) { m_isCheckMenu = checkable; }
bool IsCheckable() const { return m_isCheckMenu; } bool IsCheckable() const { return m_isCheckMenu; }
void SetSubMenu(wxMenu *menu) { m_subMenu = menu; } void SetSubMenu(wxMenu *menu) { m_subMenu = menu; }
wxMenu *GetSubMenu() const { return m_subMenu; } wxMenu *GetSubMenu() const { return m_subMenu; }
bool IsSubMenu() const { return m_subMenu != NULL; } bool IsSubMenu() const { return m_subMenu != NULL; }
// state // state
void Enable( bool enable = TRUE ); void Enable( bool enable = TRUE );
bool IsEnabled() const { return m_isEnabled; } bool IsEnabled() const { return m_isEnabled; }
void Check( bool check = TRUE ); void Check( bool check = TRUE );
bool IsChecked() const; bool IsChecked() const;
// help string (displayed in the status bar by default) // help string (displayed in the status bar by default)
void SetHelp(const wxString& str) { m_helpStr = str; } void SetHelp(const wxString& str) { m_helpStr = str; }
const wxString& GetHelp() const { return m_helpStr; } const wxString& GetHelp() const { return m_helpStr; }
// implementation // implementation
void SetMenuItem(GtkWidget *menuItem) { m_menuItem = menuItem; }
void SetMenuItem(GtkWidget *menuItem) { m_menuItem = menuItem; } GtkWidget *GetMenuItem() const { return m_menuItem; }
GtkWidget *GetMenuItem() const { return m_menuItem; }
int m_id; void SetCheckedFlag(bool checked) { m_isChecked = checked; }
wxString m_text; bool GetCheckedFlag() const { return m_isChecked; }
bool m_isCheckMenu;
bool m_isChecked;
bool m_isEnabled;
wxMenu *m_subMenu;
wxString m_helpStr;
GtkWidget *m_menuItem; // GtkMenuItem private:
int m_id;
wxString m_text;
bool m_isCheckMenu;
bool m_isChecked;
bool m_isEnabled;
wxMenu *m_subMenu;
wxString m_helpStr;
GtkWidget *m_menuItem; // GtkMenuItem
}; };

View File

@@ -39,118 +39,148 @@ class wxMenu;
// wxMenuBar // wxMenuBar
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class wxMenuBar: public wxWindow class wxMenuBar : public wxWindow
{ {
DECLARE_DYNAMIC_CLASS(wxMenuBar) DECLARE_DYNAMIC_CLASS(wxMenuBar)
public: public:
wxMenuBar( long style ); // ctors
wxMenuBar(); wxMenuBar();
void Append( wxMenu *menu, const wxString &title ); wxMenuBar(long style);
wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
int FindMenuItem( const wxString &menuString, const wxString &itemString ) const; // menubar construction
wxMenuItem* FindMenuItemById( int id ) const; void Append( wxMenu *menu, const wxString &title );
inline wxMenuItem* FindItemForId( int id ) const { return FindMenuItemById( id ); }
void Check( int id, bool check );
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); }
wxString GetLabel( int id ) const;
void SetLabel( int id, const wxString &label );
void EnableTop( int pos, bool flag );
void SetLabelTop( int pos, const wxString& label );
wxString GetLabelTop( int pos ) const;
virtual void SetHelpString( int id, const wxString& helpString ); // item search
virtual wxString GetHelpString( int id ) const; // by menu and item names, returns wxNOT_FOUND if not found
virtual int FindMenuItem(const wxString& menuString,
inline int GetMenuCount() const { return m_menus.Number(); } const wxString& itemString) const;
inline wxMenu *GetMenu( int n ) const { return (wxMenu *)m_menus.Nth(n)->Data(); } // returns NULL if not found
wxMenuItem* FindItem( int id ) const;
// returns NULL if not found, fills menuForItem if !NULL
wxMenuItem *FindItemForId(int itemId, wxMenu **menuForItem = NULL) const;
wxList m_menus; // state control
GtkWidget *m_menubar; void Check( int id, bool check );
bool IsChecked( int id ) const;
void Enable( int id, bool enable );
bool IsEnabled( int id ) const;
wxString GetLabel( int id ) const;
void SetLabel( int id, const wxString &label );
void EnableTop( int pos, bool flag );
void SetLabelTop( int pos, const wxString& label );
wxString GetLabelTop( int pos ) const;
virtual void SetHelpString( int id, const wxString& helpString );
virtual wxString GetHelpString( int id ) const;
int GetMenuCount() const { return m_menus.Number(); }
wxMenu *GetMenu( int n ) const { return (wxMenu *)m_menus.Nth(n)->Data(); }
#ifdef WXWIN_COMPATIBILITY
// compatibility: these functions are deprecated
bool Enabled(int id) const { return IsEnabled(id); }
bool Checked(int id) const { return IsChecked(id); }
wxMenuItem* FindMenuItemById( int id ) const { return FindItem(id); }
#endif // WXWIN_COMPATIBILITY
// implementation
wxList& GetMenus() { return m_menus; }
protected:
wxList m_menus;
GtkWidget *m_menubar;
}; };
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxMenu // wxMenu
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class wxMenu: public wxEvtHandler class wxMenu : public wxEvtHandler
{ {
DECLARE_DYNAMIC_CLASS(wxMenu) DECLARE_DYNAMIC_CLASS(wxMenu)
public: public:
// construction // construction
wxMenu( const wxString& title = wxEmptyString, const wxFunction func = (wxFunction) NULL ); wxMenu( const wxString& title = wxEmptyString,
const wxFunction func = (wxFunction) NULL );
// operations // operations
// title // title
void SetTitle(const wxString& label); void SetTitle(const wxString& label);
const wxString GetTitle() const; const wxString GetTitle() const;
// menu creation // menu creation
void AppendSeparator(); void AppendSeparator();
void Append(int id, const wxString &item, void Append(int id, const wxString &item,
const wxString &helpStr = "", bool checkable = FALSE); const wxString &helpStr = "", bool checkable = FALSE);
void Append(int id, const wxString &item, void Append(int id, const wxString &item,
wxMenu *subMenu, const wxString &helpStr = "" ); wxMenu *subMenu, const wxString &helpStr = "" );
void Append(wxMenuItem *pItem); void Append(wxMenuItem *pItem);
void Break() {}; void Break() { }
// find item by name/id // find item by name/id
int FindItem( const wxString itemString ) const; int FindItem( const wxString itemString ) const;
wxMenuItem *FindItem( int id ) const; wxMenuItem *FindItem( int id ) const;
wxMenuItem *FindItemForId( int id ) const { return FindItem( id ); }
// get/set item's state // get/set item's state
void Enable( int id, bool enable ); void Enable( int id, bool enable );
bool IsEnabled( int id ) const; bool IsEnabled( int id ) const;
void Check( int id, bool check ); void Check( int id, bool check );
bool IsChecked( int id ) const; bool IsChecked( int id ) const;
void SetLabel( int id, const wxString &label ); void SetLabel( int id, const wxString &label );
wxString GetLabel( int id ) const; wxString GetLabel( int id ) const;
// helpstring // helpstring
virtual void SetHelpString(int id, const wxString& helpString); virtual void SetHelpString(int id, const wxString& helpString);
virtual wxString GetHelpString(int id) const ; virtual wxString GetHelpString(int id) const ;
// accessors
wxList& GetItems() { return m_items; }
inline void Callback(const wxFunction func) { m_callback = func; } // accessors
wxList& GetItems() { return m_items; }
inline void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
inline wxEvtHandler *GetEventHandler() { return m_eventHandler; }
inline void SetClientData( void* clientData ) { m_clientData = clientData; }
inline void* GetClientData() const { return m_clientData; }
// Updates the UI for a menu and all submenus recursively.
// source is the object that has the update event handlers
// defined for it. If NULL, the menu or associated window
// will be used.
void UpdateUI(wxEvtHandler* source = (wxEvtHandler*) NULL);
// implementation void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
wxEvtHandler *GetEventHandler() { return m_eventHandler; }
int FindMenuIdByMenuItem( GtkWidget *menuItem ) const;
void SetInvokingWindow( wxWindow *win );
wxWindow *GetInvokingWindow();
wxString m_title; void SetClientData( void* clientData ) { m_clientData = clientData; }
wxList m_items; void* GetClientData() const { return m_clientData; }
wxWindow *m_invokingWindow;
wxFunction m_callback;
wxEvtHandler *m_eventHandler;
void *m_clientData;
GtkWidget *m_menu; // GtkMenu // Updates the UI for a menu and all submenus recursively.
GtkWidget *m_owner; // source is the object that has the update event handlers
// defined for it. If NULL, the menu or associated window
// will be used.
void UpdateUI(wxEvtHandler* source = (wxEvtHandler*) NULL);
wxMenuItem *FindItemForId( int id ) const { return FindItem( id ); }
#ifdef WXWIN_COMPATIBILITY
wxFunction GetCallback() const { return m_callback; }
void Callback(const wxFunction func) { m_callback = func; }
// compatibility: these functions are deprecated
bool Enabled(int id) const { return IsEnabled(id); }
bool Checked(int id) const { return IsChecked(id); }
#endif // WXWIN_COMPATIBILITY
// implementation
int FindMenuIdByMenuItem( GtkWidget *menuItem ) const;
void SetInvokingWindow( wxWindow *win );
wxWindow *GetInvokingWindow();
// implementation only
GtkWidget *m_menu; // GtkMenu
GtkWidget *m_owner;
private:
wxString m_title;
wxList m_items;
wxWindow *m_invokingWindow;
wxFunction m_callback;
wxEvtHandler *m_eventHandler;
void *m_clientData;
}; };
#endif // __GTKMENUH__ #endif // __GTKMENUH__

View File

@@ -28,63 +28,65 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class wxMenuItem; class wxMenuItem;
class wxMenu; class wxMenu;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxMenuItem // wxMenuItem
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class wxMenuItem: public wxObject class wxMenuItem : public wxObject
{ {
DECLARE_DYNAMIC_CLASS(wxMenuItem) DECLARE_DYNAMIC_CLASS(wxMenuItem)
public: public:
wxMenuItem(); wxMenuItem();
// accessors // accessors
// id // id
void SetId(int id) { m_id = id; } void SetId(int id) { m_id = id; }
int GetId() const { return m_id; } int GetId() const { return m_id; }
bool IsSeparator() const { return m_id == ID_SEPARATOR; } bool IsSeparator() const { return m_id == ID_SEPARATOR; }
// the item's text = name // the item's text = name
void SetName(const wxString& str); void SetName(const wxString& str);
void SetText(const wxString& str) { SetName(str); } // compatibility void SetText(const wxString& str) { SetName(str); } // compatibility
const wxString& GetName() const { return m_text; } const wxString& GetName() const { return m_text; }
const wxString& GetText() const { return GetName(); } const wxString& GetText() const { return GetName(); }
// what kind of menu item we are // what kind of menu item we are
void SetCheckable(bool checkable) { m_isCheckMenu = checkable; } void SetCheckable(bool checkable) { m_isCheckMenu = checkable; }
bool IsCheckable() const { return m_isCheckMenu; } bool IsCheckable() const { return m_isCheckMenu; }
void SetSubMenu(wxMenu *menu) { m_subMenu = menu; } void SetSubMenu(wxMenu *menu) { m_subMenu = menu; }
wxMenu *GetSubMenu() const { return m_subMenu; } wxMenu *GetSubMenu() const { return m_subMenu; }
bool IsSubMenu() const { return m_subMenu != NULL; } bool IsSubMenu() const { return m_subMenu != NULL; }
// state // state
void Enable( bool enable = TRUE ); void Enable( bool enable = TRUE );
bool IsEnabled() const { return m_isEnabled; } bool IsEnabled() const { return m_isEnabled; }
void Check( bool check = TRUE ); void Check( bool check = TRUE );
bool IsChecked() const; bool IsChecked() const;
// help string (displayed in the status bar by default) // help string (displayed in the status bar by default)
void SetHelp(const wxString& str) { m_helpStr = str; } void SetHelp(const wxString& str) { m_helpStr = str; }
const wxString& GetHelp() const { return m_helpStr; } const wxString& GetHelp() const { return m_helpStr; }
// implementation // implementation
void SetMenuItem(GtkWidget *menuItem) { m_menuItem = menuItem; }
void SetMenuItem(GtkWidget *menuItem) { m_menuItem = menuItem; } GtkWidget *GetMenuItem() const { return m_menuItem; }
GtkWidget *GetMenuItem() const { return m_menuItem; }
int m_id; void SetCheckedFlag(bool checked) { m_isChecked = checked; }
wxString m_text; bool GetCheckedFlag() const { return m_isChecked; }
bool m_isCheckMenu;
bool m_isChecked;
bool m_isEnabled;
wxMenu *m_subMenu;
wxString m_helpStr;
GtkWidget *m_menuItem; // GtkMenuItem private:
int m_id;
wxString m_text;
bool m_isCheckMenu;
bool m_isChecked;
bool m_isEnabled;
wxMenu *m_subMenu;
wxString m_helpStr;
GtkWidget *m_menuItem; // GtkMenuItem
}; };

View File

@@ -13,7 +13,7 @@
#define _WX_MENU_H_ #define _WX_MENU_H_
#ifdef __GNUG__ #ifdef __GNUG__
#pragma interface "menu.h" #pragma interface "menu.h"
#endif #endif
#include "wx/defs.h" #include "wx/defs.h"
@@ -22,171 +22,212 @@
class WXDLLEXPORT wxMenuItem; class WXDLLEXPORT wxMenuItem;
class WXDLLEXPORT wxMenuBar; class WXDLLEXPORT wxMenuBar;
class WXDLLEXPORT wxMenu; class WXDLLEXPORT wxMenu;
class WXDLLEXPORT wxFrame;
WXDLLEXPORT_DATA(extern const char*) wxEmptyString; WXDLLEXPORT_DATA(extern const char*) wxEmptyString;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Menu // Menu
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class WXDLLEXPORT wxMenu: public wxEvtHandler
class WXDLLEXPORT wxMenu : public wxEvtHandler
{ {
DECLARE_DYNAMIC_CLASS(wxMenu) DECLARE_DYNAMIC_CLASS(wxMenu)
public: public:
// ctor & dtor // ctor & dtor
wxMenu(const wxString& title = wxEmptyString, const wxFunction func = NULL); wxMenu(const wxString& title = wxEmptyString, const wxFunction func = NULL);
~wxMenu(); virtual ~wxMenu();
// construct menu // construct menu
// append items to the menu // append a separator to the menu
// separator line void AppendSeparator();
void AppendSeparator(); // append a normal item to the menu
// normal item void Append(int id, const wxString& label,
void Append(int id, const wxString& Label, const wxString& helpString = wxEmptyString, const wxString& helpString = wxEmptyString,
bool checkable = FALSE); bool checkable = FALSE);
// a submenu // append a submenu
void Append(int id, const wxString& Label, wxMenu *SubMenu, void Append(int id, const wxString& label,
const wxString& helpString = wxEmptyString); wxMenu *submenu,
// the most generic form (create wxMenuItem first and use it's functions) const wxString& helpString = wxEmptyString);
void Append(wxMenuItem *pItem); // append anything (create wxMenuItem first)
// insert a break in the menu void Append(wxMenuItem *pItem);
void Break();
// delete an item
void Delete(int id); /* If it's a submenu, menu is not destroyed. VZ: why? */
// Client data // insert a break in the menu
inline void SetClientData(void* clientData) { m_clientData = clientData; } void Break();
inline void* GetClientData() const { return m_clientData; }
// menu item control // delete an item
void Enable(int id, bool Flag); // If it's a submenu, menu is not destroyed.
bool Enabled(int id) const; // VZ: why? shouldn't it return "wxMenu *" then?
inline bool IsEnabled(int id) const { return Enabled(id); }; void Delete(int id);
void Check(int id, bool Flag);
bool Checked(int id) const;
inline bool IsChecked(int id) const { return Checked(id); };
// item properties // client data
// title void SetClientData(void* clientData) { m_clientData = clientData; }
void SetTitle(const wxString& label); void* GetClientData() const { return m_clientData; }
const wxString GetTitle() const;
// label
void SetLabel(int id, const wxString& label);
wxString GetLabel(int id) const;
// help string
virtual void SetHelpString(int id, const wxString& helpString);
virtual wxString GetHelpString(int id) const ;
// find item // menu item control
// Finds the item id matching the given string, wxNOT_FOUND if not found. // enable/disable item
virtual int FindItem(const wxString& itemString) const ; void Enable(int id, bool enable);
// Find wxMenuItem by ID, and item's menu too if itemMenu is !NULL. // TRUE if enabled
wxMenuItem *FindItemForId(int itemId, wxMenu **itemMenu = NULL) const; bool IsEnabled(int id) const;
// Updates the UI for a menu and all submenus recursively. // check/uncheck item - only for checkable items, of course
// source is the object that has the update event handlers void Check(int id, bool check);
// defined for it. If NULL, the menu or associated window // TRUE if checked
// will be used. bool IsChecked(int id) const;
void UpdateUI(wxEvtHandler* source = (wxEvtHandler*) NULL);
void ProcessCommand(wxCommandEvent& event); // other properties
inline void Callback(const wxFunction func) { m_callback = func; } // the menu title
void SetTitle(const wxString& label);
const wxString GetTitle() const;
// the item label
void SetLabel(int id, const wxString& label);
wxString GetLabel(int id) const;
// help string
virtual void SetHelpString(int id, const wxString& helpString);
virtual wxString GetHelpString(int id) const;
virtual void SetParent(wxEvtHandler *parent) { m_parent = parent; } // get the list of items
inline void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; } wxList& GetItems() const { return (wxList &)m_menuItems; }
inline wxEvtHandler *GetEventHandler() { return m_eventHandler; }
inline wxList& GetItems() const { return (wxList&) m_menuItems; } // find item
// returns id of the item matching the given string or wxNOT_FOUND
virtual int FindItem(const wxString& itemString) const;
// returns NULL if not found
wxMenuItem* FindItem(int id) const { return FindItemForId(id); }
// find wxMenuItem by ID, and item's menu too if itemMenu is !NULL
wxMenuItem *FindItemForId(int itemId, wxMenu **itemMenu = NULL) const;
// IMPLEMENTATION // Updates the UI for a menu and all submenus recursively. source is the
bool MSWCommand(WXUINT param, WXWORD id); // object that has the update event handlers defined for it. If NULL, the
// menu or associated window will be used.
void UpdateUI(wxEvtHandler* source = (wxEvtHandler*)NULL);
void SetInvokingWindow(wxWindow *pWin) { m_pInvokingWindow = pWin; } void ProcessCommand(wxCommandEvent& event);
wxWindow *GetInvokingWindow() const { return m_pInvokingWindow; }
// semi-private accessors virtual void SetParent(wxEvtHandler *parent) { m_parent = parent; }
// get the window which contains this menu void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
wxWindow *GetWindow() const; wxEvtHandler *GetEventHandler() const { return m_eventHandler; }
// get the menu handle
WXHMENU GetHMenu() const; #ifdef WXWIN_COMPATIBILITY
void Callback(const wxFunction func) { m_callback = func; }
// compatibility: these functions are deprecated
bool Enabled(int id) const { return IsEnabled(id); }
bool Checked(int id) const { return IsChecked(id); }
#endif // WXWIN_COMPATIBILITY
// IMPLEMENTATION
bool MSWCommand(WXUINT param, WXWORD id);
void SetInvokingWindow(wxWindow *pWin) { m_pInvokingWindow = pWin; }
wxWindow *GetInvokingWindow() const { return m_pInvokingWindow; }
// semi-private accessors
// get the window which contains this menu
wxWindow *GetWindow() const;
// get the menu handle
WXHMENU GetHMenu() const;
private: private:
bool m_doBreak ; bool m_doBreak ;
public: public:
// This is used when m_hMenu is NULL because we don't want to // This is used when m_hMenu is NULL because we don't want to
// delete it in ~wxMenu (it's been added to a parent menu). // delete it in ~wxMenu (it's been added to a parent menu).
// But we'll still need the handle for other purposes. // But we'll still need the handle for other purposes.
// Might be better to have a flag saying whether it's deleteable or not. // Might be better to have a flag saying whether it's deleteable or not.
WXHMENU m_savehMenu ; // Used for Enable() on popup WXHMENU m_savehMenu ; // Used for Enable() on popup
WXHMENU m_hMenu; WXHMENU m_hMenu;
wxFunction m_callback; wxFunction m_callback;
int m_noItems; int m_noItems;
wxString m_title; wxString m_title;
wxMenu * m_topLevelMenu; wxMenu * m_topLevelMenu;
wxMenuBar * m_menuBar; wxMenuBar * m_menuBar;
wxList m_menuItems; wxList m_menuItems;
wxEvtHandler * m_parent; wxEvtHandler * m_parent;
wxEvtHandler * m_eventHandler; wxEvtHandler * m_eventHandler;
wxWindow *m_pInvokingWindow; wxWindow *m_pInvokingWindow;
void* m_clientData; void* m_clientData;
}; };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Menu Bar (a la Windows) // Menu Bar (a la Windows)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class WXDLLEXPORT wxFrame;
class WXDLLEXPORT wxMenuBar: public wxEvtHandler class WXDLLEXPORT wxMenuBar : public wxEvtHandler
{ {
DECLARE_DYNAMIC_CLASS(wxMenuBar) DECLARE_DYNAMIC_CLASS(wxMenuBar)
public: public:
wxMenuBar(); // ctors & dtor
wxMenuBar( long style ); wxMenuBar();
wxMenuBar(int n, wxMenu *menus[], const wxString titles[]); wxMenuBar(long style);
~wxMenuBar(); wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
virtual ~wxMenuBar();
void Append(wxMenu *menu, const wxString& title); // menubar construction
// Must only be used AFTER menu has been attached to frame, void Append(wxMenu *menu, const wxString& title);
// otherwise use individual menus to enable/disable items virtual void Delete(wxMenu *menu, int index = 0); /* Menu not destroyed */
void Enable(int Id, bool Flag);
bool Enabled(int Id) const ;
inline bool IsEnabled(int Id) const { return Enabled(Id); };
void EnableTop(int pos, bool Flag);
void Check(int id, bool Flag);
bool Checked(int id) const ;
inline bool IsChecked(int Id) const { return Checked(Id); };
void SetLabel(int id, const wxString& label) ;
wxString GetLabel(int id) const ;
void SetLabelTop(int pos, const wxString& label) ;
wxString GetLabelTop(int pos) const ;
virtual void Delete(wxMenu *menu, int index = 0); /* Menu not destroyed */
virtual bool OnAppend(wxMenu *menu, const char *title);
virtual bool OnDelete(wxMenu *menu, int index);
virtual void SetHelpString(int Id, const wxString& helpString); // state control
virtual wxString GetHelpString(int Id) const ; // NB: must only be used AFTER menu has been attached to frame,
// otherwise use individual menus to enable/disable items
// enable the item
void Enable(int id, bool enable);
// TRUE if item enabled
bool IsEnabled(int id) const;
//
void EnableTop(int pos, bool enable);
virtual int FindMenuItem(const wxString& menuString, const wxString& itemString) const ; // works only with checkable items
void Check(int id, bool check);
// TRUE if checked
bool IsChecked(int id) const;
// Find wxMenuItem for item ID, and return item's void SetLabel(int id, const wxString& label) ;
// menu too if itemMenu is non-NULL. wxString GetLabel(int id) const ;
wxMenuItem *FindItemForId(int itemId, wxMenu **menuForItem = NULL) const ;
inline void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; } virtual void SetHelpString(int id, const wxString& helpString);
inline wxEvtHandler *GetEventHandler() { return m_eventHandler; } virtual wxString GetHelpString(int id) const ;
inline int GetMenuCount() const { return m_menuCount; } void SetLabelTop(int pos, const wxString& label) ;
inline wxMenu* GetMenu(int i) const { return m_menus[i]; } wxString GetLabelTop(int pos) const ;
public: // notifications
wxEvtHandler * m_eventHandler; virtual bool OnAppend(wxMenu *menu, const char *title);
int m_menuCount; virtual bool OnDelete(wxMenu *menu, int index);
wxMenu ** m_menus;
wxString * m_titles; // item search
wxFrame * m_menuBarFrame; // by menu and item names, returns wxNOT_FOUND if not found
WXHMENU m_hMenu; virtual int FindMenuItem(const wxString& menuString,
const wxString& itemString) const;
// returns NULL if not found
wxMenuItem* FindItem(int id) const { return FindItemForId(id); }
// returns NULL if not found, fills menuForItem if !NULL
wxMenuItem *FindItemForId(int itemId, wxMenu **menuForItem = NULL) const;
// submenus access
int GetMenuCount() const { return m_menuCount; }
wxMenu *GetMenu(int i) const { return m_menus[i]; }
void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
wxEvtHandler *GetEventHandler() { return m_eventHandler; }
#ifdef WXWIN_COMPATIBILITY
// compatibility: these functions are deprecated
bool Enabled(int id) const { return IsEnabled(id); }
bool Checked(int id) const { return IsChecked(id); }
#endif // WXWIN_COMPATIBILITY
public:
wxEvtHandler * m_eventHandler;
int m_menuCount;
wxMenu ** m_menus;
wxString * m_titles;
wxFrame * m_menuBarFrame;
WXHMENU m_hMenu;
}; };
#endif // _WX_MENU_H_ #endif // _WX_MENU_H_

View File

@@ -2,7 +2,7 @@
// Name: menuitem.h // Name: menuitem.h
// Purpose: wxMenuItem class // Purpose: wxMenuItem class
// Author: Vadim Zeitlin // Author: Vadim Zeitlin
// Modified by: // Modified by:
// Created: 11.11.97 // Created: 11.11.97
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
@@ -13,7 +13,7 @@
#define _MENUITEM_H #define _MENUITEM_H
#ifdef __GNUG__ #ifdef __GNUG__
#pragma interface "menuitem.h" #pragma interface "menuitem.h"
#endif #endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -26,7 +26,7 @@
// headers - only because ownerdrw.h is not always included and I don't want // headers - only because ownerdrw.h is not always included and I don't want
// to write #ifdef's everywhere... // to write #ifdef's everywhere...
#if wxUSE_OWNER_DRAWN #if wxUSE_OWNER_DRAWN
#include "wx/ownerdrw.h" #include "wx/ownerdrw.h"
#endif #endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -514,7 +514,7 @@ void wxFrame::OnSize( wxSizeEvent &WXUNUSED(event) )
static void SetInvokingWindow( wxMenu *menu, wxWindow *win ) static void SetInvokingWindow( wxMenu *menu, wxWindow *win )
{ {
menu->SetInvokingWindow( win ); menu->SetInvokingWindow( win );
wxNode *node = menu->m_items.First(); wxNode *node = menu->GetItems().First();
while (node) while (node)
{ {
wxMenuItem *menuitem = (wxMenuItem*)node->Data(); wxMenuItem *menuitem = (wxMenuItem*)node->Data();
@@ -533,7 +533,7 @@ void wxFrame::SetMenuBar( wxMenuBar *menuBar )
if (m_frameMenuBar) if (m_frameMenuBar)
{ {
wxNode *node = m_frameMenuBar->m_menus.First(); wxNode *node = m_frameMenuBar->GetMenus().First();
while (node) while (node)
{ {
wxMenu *menu = (wxMenu*)node->Data(); wxMenu *menu = (wxMenu*)node->Data();
@@ -548,7 +548,8 @@ void wxFrame::SetMenuBar( wxMenuBar *menuBar )
m_frameMenuBar->m_widget, m_frameMenuBar->m_x, m_frameMenuBar->m_y ); m_frameMenuBar->m_widget, m_frameMenuBar->m_x, m_frameMenuBar->m_y );
/* an mdi child menu bar might be underneath */ /* an mdi child menu bar might be underneath */
if (m_mdiMenuBar) m_frameMenuBar->Show( FALSE ); if (m_mdiMenuBar)
m_frameMenuBar->Show( FALSE );
} }
} }

View File

@@ -124,7 +124,7 @@ void wxMDIParentFrame::GtkOnSize( int x, int y, int width, int height )
if (m_mdiMenuBar) if (m_mdiMenuBar)
{ {
m_mdiMenuBar->m_x = 0; m_mdiMenuBar->m_x = 0;
m_mdiMenuBar->m_y = 0; m_mdiMenuBar->m_y = 0;
m_mdiMenuBar->m_width = m_width; m_mdiMenuBar->m_width = m_width;
m_mdiMenuBar->m_height = wxMENU_HEIGHT; m_mdiMenuBar->m_height = wxMENU_HEIGHT;
@@ -137,13 +137,13 @@ void wxMDIParentFrame::SetMDIMenuBar( wxMenuBar *menu_bar )
{ {
/* hide old child menu bar */ /* hide old child menu bar */
if (m_mdiMenuBar) m_mdiMenuBar->Show( FALSE ); if (m_mdiMenuBar) m_mdiMenuBar->Show( FALSE );
m_mdiMenuBar = menu_bar; m_mdiMenuBar = menu_bar;
/* show and resize new menu child menu bar */ /* show and resize new menu child menu bar */
if (m_mdiMenuBar) if (m_mdiMenuBar)
{ {
m_mdiMenuBar->m_x = 0; m_mdiMenuBar->m_x = 0;
m_mdiMenuBar->m_y = 0; m_mdiMenuBar->m_y = 0;
m_mdiMenuBar->m_width = m_width; m_mdiMenuBar->m_width = m_width;
m_mdiMenuBar->m_height = wxMENU_HEIGHT; m_mdiMenuBar->m_height = wxMENU_HEIGHT;
@@ -151,7 +151,7 @@ void wxMDIParentFrame::SetMDIMenuBar( wxMenuBar *menu_bar )
gtk_widget_set_usize( m_mdiMenuBar->m_widget, m_width, wxMENU_HEIGHT ); gtk_widget_set_usize( m_mdiMenuBar->m_widget, m_width, wxMENU_HEIGHT );
m_mdiMenuBar->Show( TRUE ); m_mdiMenuBar->Show( TRUE );
} }
/* show/hide parent menu bar as required */ /* show/hide parent menu bar as required */
if (m_frameMenuBar) m_frameMenuBar->Show( (m_mdiMenuBar == NULL) ); if (m_frameMenuBar) m_frameMenuBar->Show( (m_mdiMenuBar == NULL) );
} }
@@ -202,7 +202,7 @@ void wxMDIParentFrame::OnSysColourChanged( wxSysColourChangedEvent& WXUNUSED(eve
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame,wxFrame) IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame,wxFrame)
BEGIN_EVENT_TABLE(wxMDIChildFrame, wxFrame) BEGIN_EVENT_TABLE(wxMDIChildFrame, wxFrame)
EVT_ACTIVATE(wxMDIChildFrame::OnActivate) EVT_ACTIVATE(wxMDIChildFrame::OnActivate)
END_EVENT_TABLE() END_EVENT_TABLE()
@@ -243,7 +243,7 @@ bool wxMDIChildFrame::Create( wxMDIParentFrame *parent,
long style, const wxString& name ) long style, const wxString& name )
{ {
m_title = title; m_title = title;
return wxWindow::Create( parent->GetClientWindow(), id, wxDefaultPosition, size, style, name ); return wxWindow::Create( parent->GetClientWindow(), id, wxDefaultPosition, size, style, name );
} }
@@ -256,11 +256,11 @@ void wxMDIChildFrame::AddChild( wxWindow *child )
{ {
wxWindow::AddChild( child ); wxWindow::AddChild( child );
} }
static void SetInvokingWindow( wxMenu *menu, wxWindow *win ) static void SetInvokingWindow( wxMenu *menu, wxWindow *win )
{ {
menu->SetInvokingWindow( win ); menu->SetInvokingWindow( win );
wxNode *node = menu->m_items.First(); wxNode *node = menu->GetItems().First();
while (node) while (node)
{ {
wxMenuItem *menuitem = (wxMenuItem*)node->Data(); wxMenuItem *menuitem = (wxMenuItem*)node->Data();
@@ -280,7 +280,7 @@ void wxMDIChildFrame::SetMenuBar( wxMenuBar *menu_bar )
if (m_menuBar->m_parent != this) if (m_menuBar->m_parent != this)
{ {
wxNode *node = m_menuBar->m_menus.First(); wxNode *node = m_menuBar->GetMenus().First();
while (node) while (node)
{ {
wxMenu *menu = (wxMenu*)node->Data(); wxMenu *menu = (wxMenu*)node->Data();
@@ -290,10 +290,10 @@ void wxMDIChildFrame::SetMenuBar( wxMenuBar *menu_bar )
m_menuBar->m_parent = mdi_frame; m_menuBar->m_parent = mdi_frame;
} }
gtk_myfixed_put( GTK_MYFIXED(mdi_frame->m_wxwindow), gtk_myfixed_put( GTK_MYFIXED(mdi_frame->m_wxwindow),
m_menuBar->m_widget, m_menuBar->m_x, m_menuBar->m_y ); m_menuBar->m_widget, m_menuBar->m_x, m_menuBar->m_y );
mdi_frame->SetMDIMenuBar( m_menuBar ); mdi_frame->SetMDIMenuBar( m_menuBar );
} }
} }
@@ -325,15 +325,15 @@ static void wxInsertChildInMDI( wxMDIClientWindow* parent, wxMDIChildFrame* chil
gtk_signal_connect( GTK_OBJECT(child->m_widget), "size_allocate", gtk_signal_connect( GTK_OBJECT(child->m_widget), "size_allocate",
GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)child ); GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)child );
GtkNotebook *notebook = GTK_NOTEBOOK(parent->m_widget); GtkNotebook *notebook = GTK_NOTEBOOK(parent->m_widget);
gtk_notebook_append_page( notebook, child->m_widget, label_widget ); gtk_notebook_append_page( notebook, child->m_widget, label_widget );
child->m_page = (GtkNotebookPage*) (g_list_last(notebook->children)->data); child->m_page = (GtkNotebookPage*) (g_list_last(notebook->children)->data);
gtk_notebook_set_page( notebook, parent->m_children.Number()-1 ); gtk_notebook_set_page( notebook, parent->m_children.Number()-1 );
gtk_page_change_callback( (GtkNotebook *) NULL, child->m_page, 0, parent ); gtk_page_change_callback( (GtkNotebook *) NULL, child->m_page, 0, parent );
} }
@@ -359,7 +359,7 @@ wxMDIClientWindow::~wxMDIClientWindow(void)
bool wxMDIClientWindow::CreateClient( wxMDIParentFrame *parent, long style ) bool wxMDIClientWindow::CreateClient( wxMDIParentFrame *parent, long style )
{ {
m_needParent = TRUE; m_needParent = TRUE;
m_insertCallback = (wxInsertChildFunction)wxInsertChildInMDI; m_insertCallback = (wxInsertChildFunction)wxInsertChildInMDI;
PreCreation( parent, -1, wxPoint(10,10), wxSize(100,100), style, "wxMDIClientWindow" ); PreCreation( parent, -1, wxPoint(10,10), wxSize(100,100), style, "wxMDIClientWindow" );
@@ -374,7 +374,7 @@ bool wxMDIClientWindow::CreateClient( wxMDIParentFrame *parent, long style )
m_parent->AddChild( this ); m_parent->AddChild( this );
(m_parent->m_insertCallback)( m_parent, this ); (m_parent->m_insertCallback)( m_parent, this );
PostCreation(); PostCreation();
Show( TRUE ); Show( TRUE );

View File

@@ -39,8 +39,8 @@ wxMenuBar::wxMenuBar( long style )
if (style & wxMB_DOCKABLE) if (style & wxMB_DOCKABLE)
{ {
m_widget = gtk_handle_box_new(); m_widget = gtk_handle_box_new();
gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_menubar) ); gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_menubar) );
gtk_widget_show( GTK_WIDGET(m_menubar) ); gtk_widget_show( GTK_WIDGET(m_menubar) );
} }
else else
{ {
@@ -72,16 +72,19 @@ wxMenuBar::wxMenuBar()
void wxMenuBar::Append( wxMenu *menu, const wxString &title ) void wxMenuBar::Append( wxMenu *menu, const wxString &title )
{ {
m_menus.Append( menu ); m_menus.Append( menu );
menu->m_title = title; wxString title2 = title;
int pos; int pos;
do do
{ {
pos = menu->m_title.First( '&' ); pos = title2.First( '&' );
if (pos != -1) menu->m_title.Remove( pos, 1 ); if (pos != wxNOT_FOUND)
} while (pos != -1); title2.Remove( pos, 1 );
} while (pos != wxNOT_FOUND);
menu->m_owner = gtk_menu_item_new_with_label( WXSTRINGCAST(menu->m_title) ); menu->SetTitle(title2);
menu->m_owner = gtk_menu_item_new_with_label( WXSTRINGCAST(title2) );
gtk_widget_show( menu->m_owner ); gtk_widget_show( menu->m_owner );
gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu ); gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu );
@@ -90,13 +93,14 @@ void wxMenuBar::Append( wxMenu *menu, const wxString &title )
static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString, const wxString &itemString ) static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString, const wxString &itemString )
{ {
if (menu->m_title == menuString) if (menu->GetTitle() == menuString)
{ {
int res = menu->FindItem( itemString ); int res = menu->FindItem( itemString );
if (res != -1) return res; if (res != wxNOT_FOUND)
return res;
} }
wxNode *node = menu->m_items.First(); wxNode *node = ((wxMenu *)menu)->GetItems().First(); // const_cast
while (node) while (node)
{ {
wxMenuItem *item = (wxMenuItem*)node->Data(); wxMenuItem *item = (wxMenuItem*)node->Data();
@@ -106,7 +110,19 @@ static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString
node = node->Next(); node = node->Next();
} }
return -1; return wxNOT_FOUND;
}
wxMenuItem *wxMenuBar::FindItemForId(int itemId, wxMenu **menuForItem = NULL) const
{
if ( menuForItem )
{
// TODO return the pointer to the menu
*menuForItem = NULL;
}
return FindItem(itemId);
} }
int wxMenuBar::FindMenuItem( const wxString &menuString, const wxString &itemString ) const int wxMenuBar::FindMenuItem( const wxString &menuString, const wxString &itemString ) const
@@ -122,26 +138,26 @@ int wxMenuBar::FindMenuItem( const wxString &menuString, const wxString &itemStr
return -1; return -1;
} }
/* Find a wxMenuItem using its id. Recurses down into sub-menus */ // Find a wxMenuItem using its id. Recurses down into sub-menus
static wxMenuItem* FindMenuItemByIdRecursive(const wxMenu* menu, int id) static wxMenuItem* FindMenuItemByIdRecursive(const wxMenu* menu, int id)
{ {
wxMenuItem* result = menu->FindItem(id); wxMenuItem* result = menu->FindItem(id);
wxNode *node = menu->m_items.First(); wxNode *node = ((wxMenu *)menu)->GetItems().First(); // const_cast
while ( node && result == NULL ) while ( node && result == NULL )
{ {
wxMenuItem *item = (wxMenuItem*)node->Data(); wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->IsSubMenu()) if (item->IsSubMenu())
{ {
result = FindMenuItemByIdRecursive( item->GetSubMenu(), id ); result = FindMenuItemByIdRecursive( item->GetSubMenu(), id );
} }
node = node->Next(); node = node->Next();
} }
return result; return result;
} }
wxMenuItem* wxMenuBar::FindMenuItemById( int id ) const wxMenuItem* wxMenuBar::FindItem( int id ) const
{ {
wxMenuItem* result = 0; wxMenuItem* result = 0;
wxNode *node = m_menus.First(); wxNode *node = m_menus.First();
@@ -151,101 +167,114 @@ wxMenuItem* wxMenuBar::FindMenuItemById( int id ) const
result = FindMenuItemByIdRecursive( menu, id ); result = FindMenuItemByIdRecursive( menu, id );
node = node->Next(); node = node->Next();
} }
return result; return result;
} }
void wxMenuBar::Check( int id, bool check ) void wxMenuBar::Check( int id, bool check )
{ {
wxMenuItem* item = FindMenuItemById( id ); wxMenuItem* item = FindMenuItemById( id );
if (item) item->Check(check);
wxCHECK_RET( item, "wxMenuBar::Check: no such item" );
item->Check(check);
} }
bool wxMenuBar::Checked( int id ) const bool wxMenuBar::IsChecked( int id ) const
{ {
wxMenuItem* item = FindMenuItemById( id ); wxMenuItem* item = FindMenuItemById( id );
if (item) return item->IsChecked();
return FALSE; wxCHECK_MSG( item, FALSE, "wxMenuBar::IsChecked: no such item" );
return item->IsChecked();
} }
void wxMenuBar::Enable( int id, bool enable ) void wxMenuBar::Enable( int id, bool enable )
{ {
wxMenuItem* item = FindMenuItemById( id ); wxMenuItem* item = FindMenuItemById( id );
if (item) item->Enable(enable);
wxCHECK_RET( item, "wxMenuBar::Enable: no such item" );
item->Enable(enable);
} }
bool wxMenuBar::Enabled( int id ) const bool wxMenuBar::IsEnabled( int id ) const
{ {
wxMenuItem* item = FindMenuItemById( id ); wxMenuItem* item = FindMenuItemById( id );
if (item) return item->IsEnabled();
wxCHECK_MSG( item, FALSE, "wxMenuBar::IsEnabled: no such item" );
return FALSE;
return item->IsEnabled();
} }
wxString wxMenuBar::GetLabel( int id ) const wxString wxMenuBar::GetLabel( int id ) const
{ {
wxMenuItem* item = FindMenuItemById( id ); wxMenuItem* item = FindMenuItemById( id );
if (item) return item->GetText(); wxCHECK_MSG( item, "", "wxMenuBar::GetLabel: no such item" );
return wxString(""); return item->GetText();
} }
void wxMenuBar::SetLabel( int id, const wxString &label ) void wxMenuBar::SetLabel( int id, const wxString &label )
{ {
wxMenuItem* item = FindMenuItemById( id ); wxMenuItem* item = FindMenuItemById( id );
if (item) item->SetText( label ); wxCHECK_RET( item, "wxMenuBar::SetLabel: no such item" );
item->SetText( label );
} }
void wxMenuBar::EnableTop( int pos, bool flag ) void wxMenuBar::EnableTop( int pos, bool flag )
{ {
wxNode *node = m_menus.Nth( pos ); wxNode *node = m_menus.Nth( pos );
wxCHECK_RET( node, "menu not found" ); wxCHECK_RET( node, "menu not found" );
wxMenu* menu = (wxMenu*)node->Data(); wxMenu* menu = (wxMenu*)node->Data();
if (menu->m_owner) gtk_widget_set_sensitive( menu->m_owner, flag ); if (menu->m_owner)
gtk_widget_set_sensitive( menu->m_owner, flag );
} }
wxString wxMenuBar::GetLabelTop( int pos ) const wxString wxMenuBar::GetLabelTop( int pos ) const
{ {
wxNode *node = m_menus.Nth( pos ); wxNode *node = m_menus.Nth( pos );
wxCHECK_MSG( node, "invalid", "menu not found" ); wxCHECK_MSG( node, "invalid", "menu not found" );
wxMenu* menu = (wxMenu*)node->Data(); wxMenu* menu = (wxMenu*)node->Data();
return menu->GetTitle(); return menu->GetTitle();
} }
void wxMenuBar::SetLabelTop( int pos, const wxString& label ) void wxMenuBar::SetLabelTop( int pos, const wxString& label )
{ {
wxNode *node = m_menus.Nth( pos ); wxNode *node = m_menus.Nth( pos );
wxCHECK_RET( node, "menu not found" ); wxCHECK_RET( node, "menu not found" );
wxMenu* menu = (wxMenu*)node->Data(); wxMenu* menu = (wxMenu*)node->Data();
menu->SetTitle( label ); menu->SetTitle( label );
} }
void wxMenuBar::SetHelpString( int id, const wxString& helpString ) void wxMenuBar::SetHelpString( int id, const wxString& helpString )
{ {
wxMenuItem* item = FindMenuItemById( id ); wxMenuItem* item = FindMenuItemById( id );
if (item) item->SetHelp( helpString ); wxCHECK_RET( item, "wxMenuBar::SetHelpString: no such item" );
item->SetHelp( helpString );
} }
wxString wxMenuBar::GetHelpString( int id ) const wxString wxMenuBar::GetHelpString( int id ) const
{ {
wxMenuItem* item = FindMenuItemById( id ); wxMenuItem* item = FindMenuItemById( id );
if (item) wxCHECK_MSG( item, "", "wxMenuBar::GetHelpString: no such item" );
return item->GetHelp();
else return item->GetHelp();
return wxString("");
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -257,41 +286,44 @@ static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu )
int id = menu->FindMenuIdByMenuItem(widget); int id = menu->FindMenuIdByMenuItem(widget);
/* should find it for normal (not popup) menu */ /* should find it for normal (not popup) menu */
wxASSERT( (id != -1) || (menu->GetInvokingWindow() != NULL) ); wxASSERT( (id != -1) || (menu->GetInvokingWindow() != NULL) );
if (!menu->IsEnabled(id)) return; if (!menu->IsEnabled(id))
return;
wxMenuItem* item = menu->FindItem( id ); wxMenuItem* item = menu->FindItem( id );
wxCHECK_RET( item, "error in menu item callback" ); wxCHECK_RET( item, "error in menu item callback" );
if (item->m_isCheckMenu) if (item->IsCheckable())
{ {
if (item->m_isChecked == item->IsChecked()) if (item->GetCheckedFlag() == item->IsChecked())
{ {
/* the menu item has been checked by calling wxMenuItem->Check() */ /* the menu item has been checked by calling wxMenuItem->Check() */
return; return;
} }
else else
{ {
/* the user pressed on the menu item -> report */ /* the user pressed on the menu item -> report */
item->m_isChecked = item->IsChecked(); /* make consistent again */ item->SetCheckedFlag(item->IsChecked()); /* make consistent again */
} }
} }
wxCommandEvent event( wxEVT_COMMAND_MENU_SELECTED, id ); wxCommandEvent event( wxEVT_COMMAND_MENU_SELECTED, id );
event.SetEventObject( menu ); event.SetEventObject( menu );
event.SetInt(id ); event.SetInt(id );
if (menu->m_callback) if (menu->GetCallback())
{ {
(void) (*(menu->m_callback)) (*menu, event); (void) (*(menu->GetCallback())) (*menu, event);
return; return;
} }
if (menu->GetEventHandler()->ProcessEvent(event)) return; if (menu->GetEventHandler()->ProcessEvent(event))
return;
wxWindow *win = menu->GetInvokingWindow(); wxWindow *win = menu->GetInvokingWindow();
if (win) win->GetEventHandler()->ProcessEvent( event ); if (win)
win->GetEventHandler()->ProcessEvent( event );
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -304,7 +336,8 @@ static void gtk_menu_hilight_callback( GtkWidget *widget, wxMenu *menu )
wxASSERT( id != -1 ); // should find it! wxASSERT( id != -1 ); // should find it!
if (!menu->IsEnabled(id)) return; if (!menu->IsEnabled(id))
return;
wxMenuEvent event( wxEVT_MENU_HIGHLIGHT, id ); wxMenuEvent event( wxEVT_MENU_HIGHLIGHT, id );
event.SetEventObject( menu ); event.SetEventObject( menu );
@@ -318,7 +351,8 @@ static void gtk_menu_hilight_callback( GtkWidget *widget, wxMenu *menu )
} }
*/ */
if (menu->GetEventHandler()->ProcessEvent(event)) return; if (menu->GetEventHandler()->ProcessEvent(event))
return;
wxWindow *win = menu->GetInvokingWindow(); wxWindow *win = menu->GetInvokingWindow();
if (win) win->GetEventHandler()->ProcessEvent( event ); if (win) win->GetEventHandler()->ProcessEvent( event );
@@ -334,15 +368,18 @@ static void gtk_menu_nolight_callback( GtkWidget *widget, wxMenu *menu )
wxASSERT( id != -1 ); // should find it! wxASSERT( id != -1 ); // should find it!
if (!menu->IsEnabled(id)) return; if (!menu->IsEnabled(id))
return;
wxMenuEvent event( wxEVT_MENU_HIGHLIGHT, -1 ); wxMenuEvent event( wxEVT_MENU_HIGHLIGHT, -1 );
event.SetEventObject( menu ); event.SetEventObject( menu );
if (menu->GetEventHandler()->ProcessEvent(event)) return; if (menu->GetEventHandler()->ProcessEvent(event))
return;
wxWindow *win = menu->GetInvokingWindow(); wxWindow *win = menu->GetInvokingWindow();
if (win) win->GetEventHandler()->ProcessEvent( event ); if (win)
win->GetEventHandler()->ProcessEvent( event );
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -361,7 +398,7 @@ wxMenuItem::wxMenuItem()
m_menuItem = (GtkWidget *) NULL; m_menuItem = (GtkWidget *) NULL;
} }
/* it's valid for this function to be called even if m_menuItem == NULL */ // it's valid for this function to be called even if m_menuItem == NULL
void wxMenuItem::SetName( const wxString& str ) void wxMenuItem::SetName( const wxString& str )
{ {
m_text = ""; m_text = "";
@@ -432,13 +469,13 @@ wxMenu::wxMenu( const wxString& title, const wxFunction func )
Append(-2, m_title); Append(-2, m_title);
AppendSeparator(); AppendSeparator();
} }
m_owner = (GtkWidget*) NULL; m_owner = (GtkWidget*) NULL;
} }
void wxMenu::SetTitle( const wxString& title ) void wxMenu::SetTitle( const wxString& title )
{ {
/* Waiting for something better. */ // TODO Waiting for something better
m_title = title; m_title = title;
} }
@@ -517,14 +554,14 @@ void wxMenu::Append( int id, const wxString &text, wxMenu *subMenu, const wxStri
void wxMenu::Append( wxMenuItem *item ) void wxMenu::Append( wxMenuItem *item )
{ {
m_items.Append( item ); m_items.Append( item );
GtkWidget *menuItem = (GtkWidget*) NULL; GtkWidget *menuItem = (GtkWidget*) NULL;
if (item->IsSeparator()) if (item->IsSeparator())
menuItem = gtk_menu_item_new(); menuItem = gtk_menu_item_new();
else if (item->IsSubMenu()) else if (item->IsSubMenu())
menuItem = gtk_menu_item_new_with_label(item->GetText()); menuItem = gtk_menu_item_new_with_label(item->GetText());
else else
menuItem = item->IsCheckable() ? gtk_check_menu_item_new_with_label(item->GetText()) menuItem = item->IsCheckable() ? gtk_check_menu_item_new_with_label(item->GetText())
: gtk_menu_item_new_with_label(item->GetText()); : gtk_menu_item_new_with_label(item->GetText());
@@ -537,15 +574,15 @@ void wxMenu::Append( wxMenuItem *item )
gtk_signal_connect( GTK_OBJECT(menuItem), "deselect", gtk_signal_connect( GTK_OBJECT(menuItem), "deselect",
GTK_SIGNAL_FUNC(gtk_menu_nolight_callback), GTK_SIGNAL_FUNC(gtk_menu_nolight_callback),
(gpointer*)this ); (gpointer*)this );
if (!item->IsSubMenu()) if (!item->IsSubMenu())
{ {
gtk_signal_connect( GTK_OBJECT(menuItem), "activate", gtk_signal_connect( GTK_OBJECT(menuItem), "activate",
GTK_SIGNAL_FUNC(gtk_menu_clicked_callback), GTK_SIGNAL_FUNC(gtk_menu_clicked_callback),
(gpointer*)this ); (gpointer*)this );
} }
} }
gtk_menu_append( GTK_MENU(m_menu), menuItem ); gtk_menu_append( GTK_MENU(m_menu), menuItem );
gtk_widget_show( menuItem ); gtk_widget_show( menuItem );
item->SetMenuItem(menuItem); item->SetMenuItem(menuItem);
@@ -556,7 +593,7 @@ int wxMenu::FindItem( const wxString itemString ) const
wxString s( itemString ); wxString s( itemString );
int pos; int pos;
do do
{ {
pos = s.First( '&' ); pos = s.First( '&' );
if (pos != -1) s.Remove( pos, 1 ); if (pos != -1) s.Remove( pos, 1 );
@@ -567,98 +604,85 @@ int wxMenu::FindItem( const wxString itemString ) const
{ {
wxMenuItem *item = (wxMenuItem*)node->Data(); wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->GetText() == s) if (item->GetText() == s)
{ {
return item->GetId(); return item->GetId();
} }
node = node->Next(); node = node->Next();
} }
return -1; return wxNOT_FOUND;
} }
void wxMenu::Enable( int id, bool enable ) void wxMenu::Enable( int id, bool enable )
{ {
wxMenuItem *item = FindItem(id); wxMenuItem *item = FindItem(id);
if (item)
{ wxCHECK_RET( item, "wxMenu::Enable: no such item" );
item->Enable(enable);
} item->Enable(enable);
} }
bool wxMenu::IsEnabled( int id ) const bool wxMenu::IsEnabled( int id ) const
{ {
wxMenuItem *item = FindItem(id); wxMenuItem *item = FindItem(id);
if (item)
{ wxCHECK_MSG( item, FALSE, "wxMenu::IsEnabled: no such item" );
return item->IsEnabled();
} return item->IsEnabled();
else
{
return FALSE;
}
} }
void wxMenu::Check( int id, bool enable ) void wxMenu::Check( int id, bool enable )
{ {
wxMenuItem *item = FindItem(id); wxMenuItem *item = FindItem(id);
if (item)
{ wxCHECK_RET( item, "wxMenu::Check: no such item" );
item->Check(enable);
} item->Check(enable);
} }
bool wxMenu::IsChecked( int id ) const bool wxMenu::IsChecked( int id ) const
{ {
wxMenuItem *item = FindItem(id); wxMenuItem *item = FindItem(id);
if (item)
{ wxCHECK_MSG( item, FALSE, "wxMenu::IsChecked: no such item" );
return item->IsChecked();
} return item->IsChecked();
else
{
return FALSE;
}
} }
void wxMenu::SetLabel( int id, const wxString &label ) void wxMenu::SetLabel( int id, const wxString &label )
{ {
wxMenuItem *item = FindItem(id); wxMenuItem *item = FindItem(id);
if (item)
{ wxCHECK_RET( item, "wxMenu::SetLabel: no such item" );
item->SetText(label);
} item->SetText(label);
} }
wxString wxMenu::GetLabel( int id ) const wxString wxMenu::GetLabel( int id ) const
{ {
wxMenuItem *item = FindItem(id); wxMenuItem *item = FindItem(id);
if (item)
{ wxCHECK_MSG( item, "", "wxMenu::GetLabel: no such item" );
return item->GetText();
} return item->GetText();
else
{
return "";
}
} }
void wxMenu::SetHelpString( int id, const wxString& helpString ) void wxMenu::SetHelpString( int id, const wxString& helpString )
{ {
wxMenuItem *item = FindItem(id); wxMenuItem *item = FindItem(id);
if (item) item->SetHelp( helpString );
wxCHECK_RET( item, "wxMenu::SetHelpString: no such item" );
item->SetHelp( helpString );
} }
wxString wxMenu::GetHelpString( int id ) const wxString wxMenu::GetHelpString( int id ) const
{ {
wxMenuItem *item = FindItem(id); wxMenuItem *item = FindItem(id);
if (item)
{ wxCHECK_MSG( item, "", "wxMenu::GetHelpString: no such item" );
return item->GetHelp();
} return item->GetHelp();
else
{
return "";
}
} }
int wxMenu::FindMenuIdByMenuItem( GtkWidget *menuItem ) const int wxMenu::FindMenuIdByMenuItem( GtkWidget *menuItem ) const
@@ -672,19 +696,19 @@ int wxMenu::FindMenuIdByMenuItem( GtkWidget *menuItem ) const
node = node->Next(); node = node->Next();
} }
return -1; return wxNOT_FOUND;
} }
wxMenuItem *wxMenu::FindItem(int id) const wxMenuItem *wxMenu::FindItem(int id) const
{ {
wxNode *node = m_items.First(); wxNode *node = m_items.First();
while (node) while (node)
{ {
wxMenuItem *item = (wxMenuItem*)node->Data(); wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->GetId() == id) if (item->GetId() == id)
{ {
return item; return item;
} }
node = node->Next(); node = node->Next();
} }
@@ -705,10 +729,9 @@ wxWindow *wxMenu::GetInvokingWindow()
return m_invokingWindow; return m_invokingWindow;
} }
// Update a menu and all submenus recursively. // Update a menu and all submenus recursively. source is the object that has
// source is the object that has the update event handlers // the update event handlers defined for it. If NULL, the menu or associated
// defined for it. If NULL, the menu or associated window // window will be used.
// will be used.
void wxMenu::UpdateUI(wxEvtHandler* source) void wxMenu::UpdateUI(wxEvtHandler* source)
{ {
if (!source && GetInvokingWindow()) if (!source && GetInvokingWindow())
@@ -745,4 +768,3 @@ void wxMenu::UpdateUI(wxEvtHandler* source)
} }
} }

View File

@@ -2750,7 +2750,7 @@ void wxWindow::InitDialog()
static void SetInvokingWindow( wxMenu *menu, wxWindow *win ) static void SetInvokingWindow( wxMenu *menu, wxWindow *win )
{ {
menu->SetInvokingWindow( win ); menu->SetInvokingWindow( win );
wxNode *node = menu->m_items.First(); wxNode *node = menu->GetItems().First();
while (node) while (node)
{ {
wxMenuItem *menuitem = (wxMenuItem*)node->Data(); wxMenuItem *menuitem = (wxMenuItem*)node->Data();

View File

@@ -514,7 +514,7 @@ void wxFrame::OnSize( wxSizeEvent &WXUNUSED(event) )
static void SetInvokingWindow( wxMenu *menu, wxWindow *win ) static void SetInvokingWindow( wxMenu *menu, wxWindow *win )
{ {
menu->SetInvokingWindow( win ); menu->SetInvokingWindow( win );
wxNode *node = menu->m_items.First(); wxNode *node = menu->GetItems().First();
while (node) while (node)
{ {
wxMenuItem *menuitem = (wxMenuItem*)node->Data(); wxMenuItem *menuitem = (wxMenuItem*)node->Data();
@@ -533,7 +533,7 @@ void wxFrame::SetMenuBar( wxMenuBar *menuBar )
if (m_frameMenuBar) if (m_frameMenuBar)
{ {
wxNode *node = m_frameMenuBar->m_menus.First(); wxNode *node = m_frameMenuBar->GetMenus().First();
while (node) while (node)
{ {
wxMenu *menu = (wxMenu*)node->Data(); wxMenu *menu = (wxMenu*)node->Data();
@@ -548,7 +548,8 @@ void wxFrame::SetMenuBar( wxMenuBar *menuBar )
m_frameMenuBar->m_widget, m_frameMenuBar->m_x, m_frameMenuBar->m_y ); m_frameMenuBar->m_widget, m_frameMenuBar->m_x, m_frameMenuBar->m_y );
/* an mdi child menu bar might be underneath */ /* an mdi child menu bar might be underneath */
if (m_mdiMenuBar) m_frameMenuBar->Show( FALSE ); if (m_mdiMenuBar)
m_frameMenuBar->Show( FALSE );
} }
} }

View File

@@ -124,7 +124,7 @@ void wxMDIParentFrame::GtkOnSize( int x, int y, int width, int height )
if (m_mdiMenuBar) if (m_mdiMenuBar)
{ {
m_mdiMenuBar->m_x = 0; m_mdiMenuBar->m_x = 0;
m_mdiMenuBar->m_y = 0; m_mdiMenuBar->m_y = 0;
m_mdiMenuBar->m_width = m_width; m_mdiMenuBar->m_width = m_width;
m_mdiMenuBar->m_height = wxMENU_HEIGHT; m_mdiMenuBar->m_height = wxMENU_HEIGHT;
@@ -137,13 +137,13 @@ void wxMDIParentFrame::SetMDIMenuBar( wxMenuBar *menu_bar )
{ {
/* hide old child menu bar */ /* hide old child menu bar */
if (m_mdiMenuBar) m_mdiMenuBar->Show( FALSE ); if (m_mdiMenuBar) m_mdiMenuBar->Show( FALSE );
m_mdiMenuBar = menu_bar; m_mdiMenuBar = menu_bar;
/* show and resize new menu child menu bar */ /* show and resize new menu child menu bar */
if (m_mdiMenuBar) if (m_mdiMenuBar)
{ {
m_mdiMenuBar->m_x = 0; m_mdiMenuBar->m_x = 0;
m_mdiMenuBar->m_y = 0; m_mdiMenuBar->m_y = 0;
m_mdiMenuBar->m_width = m_width; m_mdiMenuBar->m_width = m_width;
m_mdiMenuBar->m_height = wxMENU_HEIGHT; m_mdiMenuBar->m_height = wxMENU_HEIGHT;
@@ -151,7 +151,7 @@ void wxMDIParentFrame::SetMDIMenuBar( wxMenuBar *menu_bar )
gtk_widget_set_usize( m_mdiMenuBar->m_widget, m_width, wxMENU_HEIGHT ); gtk_widget_set_usize( m_mdiMenuBar->m_widget, m_width, wxMENU_HEIGHT );
m_mdiMenuBar->Show( TRUE ); m_mdiMenuBar->Show( TRUE );
} }
/* show/hide parent menu bar as required */ /* show/hide parent menu bar as required */
if (m_frameMenuBar) m_frameMenuBar->Show( (m_mdiMenuBar == NULL) ); if (m_frameMenuBar) m_frameMenuBar->Show( (m_mdiMenuBar == NULL) );
} }
@@ -202,7 +202,7 @@ void wxMDIParentFrame::OnSysColourChanged( wxSysColourChangedEvent& WXUNUSED(eve
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame,wxFrame) IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame,wxFrame)
BEGIN_EVENT_TABLE(wxMDIChildFrame, wxFrame) BEGIN_EVENT_TABLE(wxMDIChildFrame, wxFrame)
EVT_ACTIVATE(wxMDIChildFrame::OnActivate) EVT_ACTIVATE(wxMDIChildFrame::OnActivate)
END_EVENT_TABLE() END_EVENT_TABLE()
@@ -243,7 +243,7 @@ bool wxMDIChildFrame::Create( wxMDIParentFrame *parent,
long style, const wxString& name ) long style, const wxString& name )
{ {
m_title = title; m_title = title;
return wxWindow::Create( parent->GetClientWindow(), id, wxDefaultPosition, size, style, name ); return wxWindow::Create( parent->GetClientWindow(), id, wxDefaultPosition, size, style, name );
} }
@@ -256,11 +256,11 @@ void wxMDIChildFrame::AddChild( wxWindow *child )
{ {
wxWindow::AddChild( child ); wxWindow::AddChild( child );
} }
static void SetInvokingWindow( wxMenu *menu, wxWindow *win ) static void SetInvokingWindow( wxMenu *menu, wxWindow *win )
{ {
menu->SetInvokingWindow( win ); menu->SetInvokingWindow( win );
wxNode *node = menu->m_items.First(); wxNode *node = menu->GetItems().First();
while (node) while (node)
{ {
wxMenuItem *menuitem = (wxMenuItem*)node->Data(); wxMenuItem *menuitem = (wxMenuItem*)node->Data();
@@ -280,7 +280,7 @@ void wxMDIChildFrame::SetMenuBar( wxMenuBar *menu_bar )
if (m_menuBar->m_parent != this) if (m_menuBar->m_parent != this)
{ {
wxNode *node = m_menuBar->m_menus.First(); wxNode *node = m_menuBar->GetMenus().First();
while (node) while (node)
{ {
wxMenu *menu = (wxMenu*)node->Data(); wxMenu *menu = (wxMenu*)node->Data();
@@ -290,10 +290,10 @@ void wxMDIChildFrame::SetMenuBar( wxMenuBar *menu_bar )
m_menuBar->m_parent = mdi_frame; m_menuBar->m_parent = mdi_frame;
} }
gtk_myfixed_put( GTK_MYFIXED(mdi_frame->m_wxwindow), gtk_myfixed_put( GTK_MYFIXED(mdi_frame->m_wxwindow),
m_menuBar->m_widget, m_menuBar->m_x, m_menuBar->m_y ); m_menuBar->m_widget, m_menuBar->m_x, m_menuBar->m_y );
mdi_frame->SetMDIMenuBar( m_menuBar ); mdi_frame->SetMDIMenuBar( m_menuBar );
} }
} }
@@ -325,15 +325,15 @@ static void wxInsertChildInMDI( wxMDIClientWindow* parent, wxMDIChildFrame* chil
gtk_signal_connect( GTK_OBJECT(child->m_widget), "size_allocate", gtk_signal_connect( GTK_OBJECT(child->m_widget), "size_allocate",
GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)child ); GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)child );
GtkNotebook *notebook = GTK_NOTEBOOK(parent->m_widget); GtkNotebook *notebook = GTK_NOTEBOOK(parent->m_widget);
gtk_notebook_append_page( notebook, child->m_widget, label_widget ); gtk_notebook_append_page( notebook, child->m_widget, label_widget );
child->m_page = (GtkNotebookPage*) (g_list_last(notebook->children)->data); child->m_page = (GtkNotebookPage*) (g_list_last(notebook->children)->data);
gtk_notebook_set_page( notebook, parent->m_children.Number()-1 ); gtk_notebook_set_page( notebook, parent->m_children.Number()-1 );
gtk_page_change_callback( (GtkNotebook *) NULL, child->m_page, 0, parent ); gtk_page_change_callback( (GtkNotebook *) NULL, child->m_page, 0, parent );
} }
@@ -359,7 +359,7 @@ wxMDIClientWindow::~wxMDIClientWindow(void)
bool wxMDIClientWindow::CreateClient( wxMDIParentFrame *parent, long style ) bool wxMDIClientWindow::CreateClient( wxMDIParentFrame *parent, long style )
{ {
m_needParent = TRUE; m_needParent = TRUE;
m_insertCallback = (wxInsertChildFunction)wxInsertChildInMDI; m_insertCallback = (wxInsertChildFunction)wxInsertChildInMDI;
PreCreation( parent, -1, wxPoint(10,10), wxSize(100,100), style, "wxMDIClientWindow" ); PreCreation( parent, -1, wxPoint(10,10), wxSize(100,100), style, "wxMDIClientWindow" );
@@ -374,7 +374,7 @@ bool wxMDIClientWindow::CreateClient( wxMDIParentFrame *parent, long style )
m_parent->AddChild( this ); m_parent->AddChild( this );
(m_parent->m_insertCallback)( m_parent, this ); (m_parent->m_insertCallback)( m_parent, this );
PostCreation(); PostCreation();
Show( TRUE ); Show( TRUE );

View File

@@ -39,8 +39,8 @@ wxMenuBar::wxMenuBar( long style )
if (style & wxMB_DOCKABLE) if (style & wxMB_DOCKABLE)
{ {
m_widget = gtk_handle_box_new(); m_widget = gtk_handle_box_new();
gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_menubar) ); gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_menubar) );
gtk_widget_show( GTK_WIDGET(m_menubar) ); gtk_widget_show( GTK_WIDGET(m_menubar) );
} }
else else
{ {
@@ -72,16 +72,19 @@ wxMenuBar::wxMenuBar()
void wxMenuBar::Append( wxMenu *menu, const wxString &title ) void wxMenuBar::Append( wxMenu *menu, const wxString &title )
{ {
m_menus.Append( menu ); m_menus.Append( menu );
menu->m_title = title; wxString title2 = title;
int pos; int pos;
do do
{ {
pos = menu->m_title.First( '&' ); pos = title2.First( '&' );
if (pos != -1) menu->m_title.Remove( pos, 1 ); if (pos != wxNOT_FOUND)
} while (pos != -1); title2.Remove( pos, 1 );
} while (pos != wxNOT_FOUND);
menu->m_owner = gtk_menu_item_new_with_label( WXSTRINGCAST(menu->m_title) ); menu->SetTitle(title2);
menu->m_owner = gtk_menu_item_new_with_label( WXSTRINGCAST(title2) );
gtk_widget_show( menu->m_owner ); gtk_widget_show( menu->m_owner );
gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu ); gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu );
@@ -90,13 +93,14 @@ void wxMenuBar::Append( wxMenu *menu, const wxString &title )
static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString, const wxString &itemString ) static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString, const wxString &itemString )
{ {
if (menu->m_title == menuString) if (menu->GetTitle() == menuString)
{ {
int res = menu->FindItem( itemString ); int res = menu->FindItem( itemString );
if (res != -1) return res; if (res != wxNOT_FOUND)
return res;
} }
wxNode *node = menu->m_items.First(); wxNode *node = ((wxMenu *)menu)->GetItems().First(); // const_cast
while (node) while (node)
{ {
wxMenuItem *item = (wxMenuItem*)node->Data(); wxMenuItem *item = (wxMenuItem*)node->Data();
@@ -106,7 +110,19 @@ static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString
node = node->Next(); node = node->Next();
} }
return -1; return wxNOT_FOUND;
}
wxMenuItem *wxMenuBar::FindItemForId(int itemId, wxMenu **menuForItem = NULL) const
{
if ( menuForItem )
{
// TODO return the pointer to the menu
*menuForItem = NULL;
}
return FindItem(itemId);
} }
int wxMenuBar::FindMenuItem( const wxString &menuString, const wxString &itemString ) const int wxMenuBar::FindMenuItem( const wxString &menuString, const wxString &itemString ) const
@@ -122,26 +138,26 @@ int wxMenuBar::FindMenuItem( const wxString &menuString, const wxString &itemStr
return -1; return -1;
} }
/* Find a wxMenuItem using its id. Recurses down into sub-menus */ // Find a wxMenuItem using its id. Recurses down into sub-menus
static wxMenuItem* FindMenuItemByIdRecursive(const wxMenu* menu, int id) static wxMenuItem* FindMenuItemByIdRecursive(const wxMenu* menu, int id)
{ {
wxMenuItem* result = menu->FindItem(id); wxMenuItem* result = menu->FindItem(id);
wxNode *node = menu->m_items.First(); wxNode *node = ((wxMenu *)menu)->GetItems().First(); // const_cast
while ( node && result == NULL ) while ( node && result == NULL )
{ {
wxMenuItem *item = (wxMenuItem*)node->Data(); wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->IsSubMenu()) if (item->IsSubMenu())
{ {
result = FindMenuItemByIdRecursive( item->GetSubMenu(), id ); result = FindMenuItemByIdRecursive( item->GetSubMenu(), id );
} }
node = node->Next(); node = node->Next();
} }
return result; return result;
} }
wxMenuItem* wxMenuBar::FindMenuItemById( int id ) const wxMenuItem* wxMenuBar::FindItem( int id ) const
{ {
wxMenuItem* result = 0; wxMenuItem* result = 0;
wxNode *node = m_menus.First(); wxNode *node = m_menus.First();
@@ -151,101 +167,114 @@ wxMenuItem* wxMenuBar::FindMenuItemById( int id ) const
result = FindMenuItemByIdRecursive( menu, id ); result = FindMenuItemByIdRecursive( menu, id );
node = node->Next(); node = node->Next();
} }
return result; return result;
} }
void wxMenuBar::Check( int id, bool check ) void wxMenuBar::Check( int id, bool check )
{ {
wxMenuItem* item = FindMenuItemById( id ); wxMenuItem* item = FindMenuItemById( id );
if (item) item->Check(check);
wxCHECK_RET( item, "wxMenuBar::Check: no such item" );
item->Check(check);
} }
bool wxMenuBar::Checked( int id ) const bool wxMenuBar::IsChecked( int id ) const
{ {
wxMenuItem* item = FindMenuItemById( id ); wxMenuItem* item = FindMenuItemById( id );
if (item) return item->IsChecked();
return FALSE; wxCHECK_MSG( item, FALSE, "wxMenuBar::IsChecked: no such item" );
return item->IsChecked();
} }
void wxMenuBar::Enable( int id, bool enable ) void wxMenuBar::Enable( int id, bool enable )
{ {
wxMenuItem* item = FindMenuItemById( id ); wxMenuItem* item = FindMenuItemById( id );
if (item) item->Enable(enable);
wxCHECK_RET( item, "wxMenuBar::Enable: no such item" );
item->Enable(enable);
} }
bool wxMenuBar::Enabled( int id ) const bool wxMenuBar::IsEnabled( int id ) const
{ {
wxMenuItem* item = FindMenuItemById( id ); wxMenuItem* item = FindMenuItemById( id );
if (item) return item->IsEnabled();
wxCHECK_MSG( item, FALSE, "wxMenuBar::IsEnabled: no such item" );
return FALSE;
return item->IsEnabled();
} }
wxString wxMenuBar::GetLabel( int id ) const wxString wxMenuBar::GetLabel( int id ) const
{ {
wxMenuItem* item = FindMenuItemById( id ); wxMenuItem* item = FindMenuItemById( id );
if (item) return item->GetText(); wxCHECK_MSG( item, "", "wxMenuBar::GetLabel: no such item" );
return wxString(""); return item->GetText();
} }
void wxMenuBar::SetLabel( int id, const wxString &label ) void wxMenuBar::SetLabel( int id, const wxString &label )
{ {
wxMenuItem* item = FindMenuItemById( id ); wxMenuItem* item = FindMenuItemById( id );
if (item) item->SetText( label ); wxCHECK_RET( item, "wxMenuBar::SetLabel: no such item" );
item->SetText( label );
} }
void wxMenuBar::EnableTop( int pos, bool flag ) void wxMenuBar::EnableTop( int pos, bool flag )
{ {
wxNode *node = m_menus.Nth( pos ); wxNode *node = m_menus.Nth( pos );
wxCHECK_RET( node, "menu not found" ); wxCHECK_RET( node, "menu not found" );
wxMenu* menu = (wxMenu*)node->Data(); wxMenu* menu = (wxMenu*)node->Data();
if (menu->m_owner) gtk_widget_set_sensitive( menu->m_owner, flag ); if (menu->m_owner)
gtk_widget_set_sensitive( menu->m_owner, flag );
} }
wxString wxMenuBar::GetLabelTop( int pos ) const wxString wxMenuBar::GetLabelTop( int pos ) const
{ {
wxNode *node = m_menus.Nth( pos ); wxNode *node = m_menus.Nth( pos );
wxCHECK_MSG( node, "invalid", "menu not found" ); wxCHECK_MSG( node, "invalid", "menu not found" );
wxMenu* menu = (wxMenu*)node->Data(); wxMenu* menu = (wxMenu*)node->Data();
return menu->GetTitle(); return menu->GetTitle();
} }
void wxMenuBar::SetLabelTop( int pos, const wxString& label ) void wxMenuBar::SetLabelTop( int pos, const wxString& label )
{ {
wxNode *node = m_menus.Nth( pos ); wxNode *node = m_menus.Nth( pos );
wxCHECK_RET( node, "menu not found" ); wxCHECK_RET( node, "menu not found" );
wxMenu* menu = (wxMenu*)node->Data(); wxMenu* menu = (wxMenu*)node->Data();
menu->SetTitle( label ); menu->SetTitle( label );
} }
void wxMenuBar::SetHelpString( int id, const wxString& helpString ) void wxMenuBar::SetHelpString( int id, const wxString& helpString )
{ {
wxMenuItem* item = FindMenuItemById( id ); wxMenuItem* item = FindMenuItemById( id );
if (item) item->SetHelp( helpString ); wxCHECK_RET( item, "wxMenuBar::SetHelpString: no such item" );
item->SetHelp( helpString );
} }
wxString wxMenuBar::GetHelpString( int id ) const wxString wxMenuBar::GetHelpString( int id ) const
{ {
wxMenuItem* item = FindMenuItemById( id ); wxMenuItem* item = FindMenuItemById( id );
if (item) wxCHECK_MSG( item, "", "wxMenuBar::GetHelpString: no such item" );
return item->GetHelp();
else return item->GetHelp();
return wxString("");
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -257,41 +286,44 @@ static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu )
int id = menu->FindMenuIdByMenuItem(widget); int id = menu->FindMenuIdByMenuItem(widget);
/* should find it for normal (not popup) menu */ /* should find it for normal (not popup) menu */
wxASSERT( (id != -1) || (menu->GetInvokingWindow() != NULL) ); wxASSERT( (id != -1) || (menu->GetInvokingWindow() != NULL) );
if (!menu->IsEnabled(id)) return; if (!menu->IsEnabled(id))
return;
wxMenuItem* item = menu->FindItem( id ); wxMenuItem* item = menu->FindItem( id );
wxCHECK_RET( item, "error in menu item callback" ); wxCHECK_RET( item, "error in menu item callback" );
if (item->m_isCheckMenu) if (item->IsCheckable())
{ {
if (item->m_isChecked == item->IsChecked()) if (item->GetCheckedFlag() == item->IsChecked())
{ {
/* the menu item has been checked by calling wxMenuItem->Check() */ /* the menu item has been checked by calling wxMenuItem->Check() */
return; return;
} }
else else
{ {
/* the user pressed on the menu item -> report */ /* the user pressed on the menu item -> report */
item->m_isChecked = item->IsChecked(); /* make consistent again */ item->SetCheckedFlag(item->IsChecked()); /* make consistent again */
} }
} }
wxCommandEvent event( wxEVT_COMMAND_MENU_SELECTED, id ); wxCommandEvent event( wxEVT_COMMAND_MENU_SELECTED, id );
event.SetEventObject( menu ); event.SetEventObject( menu );
event.SetInt(id ); event.SetInt(id );
if (menu->m_callback) if (menu->GetCallback())
{ {
(void) (*(menu->m_callback)) (*menu, event); (void) (*(menu->GetCallback())) (*menu, event);
return; return;
} }
if (menu->GetEventHandler()->ProcessEvent(event)) return; if (menu->GetEventHandler()->ProcessEvent(event))
return;
wxWindow *win = menu->GetInvokingWindow(); wxWindow *win = menu->GetInvokingWindow();
if (win) win->GetEventHandler()->ProcessEvent( event ); if (win)
win->GetEventHandler()->ProcessEvent( event );
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -304,7 +336,8 @@ static void gtk_menu_hilight_callback( GtkWidget *widget, wxMenu *menu )
wxASSERT( id != -1 ); // should find it! wxASSERT( id != -1 ); // should find it!
if (!menu->IsEnabled(id)) return; if (!menu->IsEnabled(id))
return;
wxMenuEvent event( wxEVT_MENU_HIGHLIGHT, id ); wxMenuEvent event( wxEVT_MENU_HIGHLIGHT, id );
event.SetEventObject( menu ); event.SetEventObject( menu );
@@ -318,7 +351,8 @@ static void gtk_menu_hilight_callback( GtkWidget *widget, wxMenu *menu )
} }
*/ */
if (menu->GetEventHandler()->ProcessEvent(event)) return; if (menu->GetEventHandler()->ProcessEvent(event))
return;
wxWindow *win = menu->GetInvokingWindow(); wxWindow *win = menu->GetInvokingWindow();
if (win) win->GetEventHandler()->ProcessEvent( event ); if (win) win->GetEventHandler()->ProcessEvent( event );
@@ -334,15 +368,18 @@ static void gtk_menu_nolight_callback( GtkWidget *widget, wxMenu *menu )
wxASSERT( id != -1 ); // should find it! wxASSERT( id != -1 ); // should find it!
if (!menu->IsEnabled(id)) return; if (!menu->IsEnabled(id))
return;
wxMenuEvent event( wxEVT_MENU_HIGHLIGHT, -1 ); wxMenuEvent event( wxEVT_MENU_HIGHLIGHT, -1 );
event.SetEventObject( menu ); event.SetEventObject( menu );
if (menu->GetEventHandler()->ProcessEvent(event)) return; if (menu->GetEventHandler()->ProcessEvent(event))
return;
wxWindow *win = menu->GetInvokingWindow(); wxWindow *win = menu->GetInvokingWindow();
if (win) win->GetEventHandler()->ProcessEvent( event ); if (win)
win->GetEventHandler()->ProcessEvent( event );
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -361,7 +398,7 @@ wxMenuItem::wxMenuItem()
m_menuItem = (GtkWidget *) NULL; m_menuItem = (GtkWidget *) NULL;
} }
/* it's valid for this function to be called even if m_menuItem == NULL */ // it's valid for this function to be called even if m_menuItem == NULL
void wxMenuItem::SetName( const wxString& str ) void wxMenuItem::SetName( const wxString& str )
{ {
m_text = ""; m_text = "";
@@ -432,13 +469,13 @@ wxMenu::wxMenu( const wxString& title, const wxFunction func )
Append(-2, m_title); Append(-2, m_title);
AppendSeparator(); AppendSeparator();
} }
m_owner = (GtkWidget*) NULL; m_owner = (GtkWidget*) NULL;
} }
void wxMenu::SetTitle( const wxString& title ) void wxMenu::SetTitle( const wxString& title )
{ {
/* Waiting for something better. */ // TODO Waiting for something better
m_title = title; m_title = title;
} }
@@ -517,14 +554,14 @@ void wxMenu::Append( int id, const wxString &text, wxMenu *subMenu, const wxStri
void wxMenu::Append( wxMenuItem *item ) void wxMenu::Append( wxMenuItem *item )
{ {
m_items.Append( item ); m_items.Append( item );
GtkWidget *menuItem = (GtkWidget*) NULL; GtkWidget *menuItem = (GtkWidget*) NULL;
if (item->IsSeparator()) if (item->IsSeparator())
menuItem = gtk_menu_item_new(); menuItem = gtk_menu_item_new();
else if (item->IsSubMenu()) else if (item->IsSubMenu())
menuItem = gtk_menu_item_new_with_label(item->GetText()); menuItem = gtk_menu_item_new_with_label(item->GetText());
else else
menuItem = item->IsCheckable() ? gtk_check_menu_item_new_with_label(item->GetText()) menuItem = item->IsCheckable() ? gtk_check_menu_item_new_with_label(item->GetText())
: gtk_menu_item_new_with_label(item->GetText()); : gtk_menu_item_new_with_label(item->GetText());
@@ -537,15 +574,15 @@ void wxMenu::Append( wxMenuItem *item )
gtk_signal_connect( GTK_OBJECT(menuItem), "deselect", gtk_signal_connect( GTK_OBJECT(menuItem), "deselect",
GTK_SIGNAL_FUNC(gtk_menu_nolight_callback), GTK_SIGNAL_FUNC(gtk_menu_nolight_callback),
(gpointer*)this ); (gpointer*)this );
if (!item->IsSubMenu()) if (!item->IsSubMenu())
{ {
gtk_signal_connect( GTK_OBJECT(menuItem), "activate", gtk_signal_connect( GTK_OBJECT(menuItem), "activate",
GTK_SIGNAL_FUNC(gtk_menu_clicked_callback), GTK_SIGNAL_FUNC(gtk_menu_clicked_callback),
(gpointer*)this ); (gpointer*)this );
} }
} }
gtk_menu_append( GTK_MENU(m_menu), menuItem ); gtk_menu_append( GTK_MENU(m_menu), menuItem );
gtk_widget_show( menuItem ); gtk_widget_show( menuItem );
item->SetMenuItem(menuItem); item->SetMenuItem(menuItem);
@@ -556,7 +593,7 @@ int wxMenu::FindItem( const wxString itemString ) const
wxString s( itemString ); wxString s( itemString );
int pos; int pos;
do do
{ {
pos = s.First( '&' ); pos = s.First( '&' );
if (pos != -1) s.Remove( pos, 1 ); if (pos != -1) s.Remove( pos, 1 );
@@ -567,98 +604,85 @@ int wxMenu::FindItem( const wxString itemString ) const
{ {
wxMenuItem *item = (wxMenuItem*)node->Data(); wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->GetText() == s) if (item->GetText() == s)
{ {
return item->GetId(); return item->GetId();
} }
node = node->Next(); node = node->Next();
} }
return -1; return wxNOT_FOUND;
} }
void wxMenu::Enable( int id, bool enable ) void wxMenu::Enable( int id, bool enable )
{ {
wxMenuItem *item = FindItem(id); wxMenuItem *item = FindItem(id);
if (item)
{ wxCHECK_RET( item, "wxMenu::Enable: no such item" );
item->Enable(enable);
} item->Enable(enable);
} }
bool wxMenu::IsEnabled( int id ) const bool wxMenu::IsEnabled( int id ) const
{ {
wxMenuItem *item = FindItem(id); wxMenuItem *item = FindItem(id);
if (item)
{ wxCHECK_MSG( item, FALSE, "wxMenu::IsEnabled: no such item" );
return item->IsEnabled();
} return item->IsEnabled();
else
{
return FALSE;
}
} }
void wxMenu::Check( int id, bool enable ) void wxMenu::Check( int id, bool enable )
{ {
wxMenuItem *item = FindItem(id); wxMenuItem *item = FindItem(id);
if (item)
{ wxCHECK_RET( item, "wxMenu::Check: no such item" );
item->Check(enable);
} item->Check(enable);
} }
bool wxMenu::IsChecked( int id ) const bool wxMenu::IsChecked( int id ) const
{ {
wxMenuItem *item = FindItem(id); wxMenuItem *item = FindItem(id);
if (item)
{ wxCHECK_MSG( item, FALSE, "wxMenu::IsChecked: no such item" );
return item->IsChecked();
} return item->IsChecked();
else
{
return FALSE;
}
} }
void wxMenu::SetLabel( int id, const wxString &label ) void wxMenu::SetLabel( int id, const wxString &label )
{ {
wxMenuItem *item = FindItem(id); wxMenuItem *item = FindItem(id);
if (item)
{ wxCHECK_RET( item, "wxMenu::SetLabel: no such item" );
item->SetText(label);
} item->SetText(label);
} }
wxString wxMenu::GetLabel( int id ) const wxString wxMenu::GetLabel( int id ) const
{ {
wxMenuItem *item = FindItem(id); wxMenuItem *item = FindItem(id);
if (item)
{ wxCHECK_MSG( item, "", "wxMenu::GetLabel: no such item" );
return item->GetText();
} return item->GetText();
else
{
return "";
}
} }
void wxMenu::SetHelpString( int id, const wxString& helpString ) void wxMenu::SetHelpString( int id, const wxString& helpString )
{ {
wxMenuItem *item = FindItem(id); wxMenuItem *item = FindItem(id);
if (item) item->SetHelp( helpString );
wxCHECK_RET( item, "wxMenu::SetHelpString: no such item" );
item->SetHelp( helpString );
} }
wxString wxMenu::GetHelpString( int id ) const wxString wxMenu::GetHelpString( int id ) const
{ {
wxMenuItem *item = FindItem(id); wxMenuItem *item = FindItem(id);
if (item)
{ wxCHECK_MSG( item, "", "wxMenu::GetHelpString: no such item" );
return item->GetHelp();
} return item->GetHelp();
else
{
return "";
}
} }
int wxMenu::FindMenuIdByMenuItem( GtkWidget *menuItem ) const int wxMenu::FindMenuIdByMenuItem( GtkWidget *menuItem ) const
@@ -672,19 +696,19 @@ int wxMenu::FindMenuIdByMenuItem( GtkWidget *menuItem ) const
node = node->Next(); node = node->Next();
} }
return -1; return wxNOT_FOUND;
} }
wxMenuItem *wxMenu::FindItem(int id) const wxMenuItem *wxMenu::FindItem(int id) const
{ {
wxNode *node = m_items.First(); wxNode *node = m_items.First();
while (node) while (node)
{ {
wxMenuItem *item = (wxMenuItem*)node->Data(); wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->GetId() == id) if (item->GetId() == id)
{ {
return item; return item;
} }
node = node->Next(); node = node->Next();
} }
@@ -705,10 +729,9 @@ wxWindow *wxMenu::GetInvokingWindow()
return m_invokingWindow; return m_invokingWindow;
} }
// Update a menu and all submenus recursively. // Update a menu and all submenus recursively. source is the object that has
// source is the object that has the update event handlers // the update event handlers defined for it. If NULL, the menu or associated
// defined for it. If NULL, the menu or associated window // window will be used.
// will be used.
void wxMenu::UpdateUI(wxEvtHandler* source) void wxMenu::UpdateUI(wxEvtHandler* source)
{ {
if (!source && GetInvokingWindow()) if (!source && GetInvokingWindow())
@@ -745,4 +768,3 @@ void wxMenu::UpdateUI(wxEvtHandler* source)
} }
} }

View File

@@ -2750,7 +2750,7 @@ void wxWindow::InitDialog()
static void SetInvokingWindow( wxMenu *menu, wxWindow *win ) static void SetInvokingWindow( wxMenu *menu, wxWindow *win )
{ {
menu->SetInvokingWindow( win ); menu->SetInvokingWindow( win );
wxNode *node = menu->m_items.First(); wxNode *node = menu->GetItems().First();
while (node) while (node)
{ {
wxMenuItem *menuitem = (wxMenuItem*)node->Data(); wxMenuItem *menuitem = (wxMenuItem*)node->Data();

File diff suppressed because it is too large Load Diff