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}
\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.
\wxheading{Parameters}
\docparam{id}{Menu item identifier.}
\docparam{menuForItem}{will be filled with the menu for this item if not NULL.}
\wxheading{Return value}

View File

@ -39,118 +39,148 @@ class wxMenu;
// wxMenuBar
//-----------------------------------------------------------------------------
class wxMenuBar: public wxWindow
class wxMenuBar : public wxWindow
{
DECLARE_DYNAMIC_CLASS(wxMenuBar)
DECLARE_DYNAMIC_CLASS(wxMenuBar)
public:
wxMenuBar( long style );
wxMenuBar();
void Append( wxMenu *menu, const wxString &title );
// ctors
wxMenuBar();
wxMenuBar(long style);
wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
int FindMenuItem( const wxString &menuString, const wxString &itemString ) const;
wxMenuItem* FindMenuItemById( int id ) const;
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;
// menubar construction
void Append( wxMenu *menu, const wxString &title );
virtual void SetHelpString( int id, const wxString& helpString );
virtual wxString GetHelpString( int id ) const;
inline int GetMenuCount() const { return m_menus.Number(); }
inline wxMenu *GetMenu( int n ) const { return (wxMenu *)m_menus.Nth(n)->Data(); }
// item search
// by menu and item names, returns wxNOT_FOUND if not found
virtual int FindMenuItem(const wxString& menuString,
const wxString& itemString) const;
// 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;
GtkWidget *m_menubar;
// state control
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
//-----------------------------------------------------------------------------
class wxMenu: public wxEvtHandler
class wxMenu : public wxEvtHandler
{
DECLARE_DYNAMIC_CLASS(wxMenu)
DECLARE_DYNAMIC_CLASS(wxMenu)
public:
// construction
wxMenu( const wxString& title = wxEmptyString, const wxFunction func = (wxFunction) NULL );
// construction
wxMenu( const wxString& title = wxEmptyString,
const wxFunction func = (wxFunction) NULL );
// operations
// title
void SetTitle(const wxString& label);
const wxString GetTitle() const;
// menu creation
void AppendSeparator();
void Append(int id, const wxString &item,
const wxString &helpStr = "", bool checkable = FALSE);
void Append(int id, const wxString &item,
wxMenu *subMenu, const wxString &helpStr = "" );
void Append(wxMenuItem *pItem);
void Break() {};
// operations
// title
void SetTitle(const wxString& label);
const wxString GetTitle() const;
// menu creation
void AppendSeparator();
void Append(int id, const wxString &item,
const wxString &helpStr = "", bool checkable = FALSE);
void Append(int id, const wxString &item,
wxMenu *subMenu, const wxString &helpStr = "" );
void Append(wxMenuItem *pItem);
void Break() { }
// find item by name/id
int FindItem( const wxString itemString ) const;
wxMenuItem *FindItem( int id ) const;
wxMenuItem *FindItemForId( int id ) const { return FindItem( id ); }
int FindItem( const wxString itemString ) const;
wxMenuItem *FindItem( int id ) const;
// get/set item's state
void Enable( int id, bool enable );
bool IsEnabled( int id ) const;
void Check( int id, bool check );
bool IsChecked( int id ) const;
void Enable( int id, bool enable );
bool IsEnabled( int id ) const;
void Check( int id, bool check );
bool IsChecked( int id ) const;
void SetLabel( int id, const wxString &label );
wxString GetLabel( int id ) const;
void SetLabel( int id, const wxString &label );
wxString GetLabel( int id ) const;
// helpstring
virtual void SetHelpString(int id, const wxString& helpString);
virtual wxString GetHelpString(int id) const ;
// accessors
wxList& GetItems() { return m_items; }
// helpstring
virtual void SetHelpString(int id, const wxString& helpString);
virtual wxString GetHelpString(int id) const ;
inline void Callback(const wxFunction func) { m_callback = func; }
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);
// accessors
wxList& GetItems() { return m_items; }
// implementation
int FindMenuIdByMenuItem( GtkWidget *menuItem ) const;
void SetInvokingWindow( wxWindow *win );
wxWindow *GetInvokingWindow();
void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
wxEvtHandler *GetEventHandler() { return m_eventHandler; }
wxString m_title;
wxList m_items;
wxWindow *m_invokingWindow;
wxFunction m_callback;
wxEvtHandler *m_eventHandler;
void *m_clientData;
void SetClientData( void* clientData ) { m_clientData = clientData; }
void* GetClientData() const { return m_clientData; }
GtkWidget *m_menu; // GtkMenu
GtkWidget *m_owner;
// 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);
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__

View File

@ -28,63 +28,65 @@
//-----------------------------------------------------------------------------
class wxMenuItem;
class wxMenu;
//-----------------------------------------------------------------------------
// wxMenuItem
//-----------------------------------------------------------------------------
class wxMenuItem: public wxObject
class wxMenuItem : public wxObject
{
DECLARE_DYNAMIC_CLASS(wxMenuItem)
public:
wxMenuItem();
wxMenuItem();
// accessors
// id
void SetId(int id) { m_id = id; }
int GetId() const { return m_id; }
bool IsSeparator() const { return m_id == ID_SEPARATOR; }
// accessors
// id
void SetId(int id) { m_id = id; }
int GetId() const { return m_id; }
bool IsSeparator() const { return m_id == ID_SEPARATOR; }
// the item's text = name
void SetName(const wxString& str);
void SetText(const wxString& str) { SetName(str); } // compatibility
const wxString& GetName() const { return m_text; }
const wxString& GetText() const { return GetName(); }
// the item's text = name
void SetName(const wxString& str);
void SetText(const wxString& str) { SetName(str); } // compatibility
const wxString& GetName() const { return m_text; }
const wxString& GetText() const { return GetName(); }
// what kind of menu item we are
void SetCheckable(bool checkable) { m_isCheckMenu = checkable; }
bool IsCheckable() const { return m_isCheckMenu; }
void SetSubMenu(wxMenu *menu) { m_subMenu = menu; }
wxMenu *GetSubMenu() const { return m_subMenu; }
bool IsSubMenu() const { return m_subMenu != NULL; }
// what kind of menu item we are
void SetCheckable(bool checkable) { m_isCheckMenu = checkable; }
bool IsCheckable() const { return m_isCheckMenu; }
void SetSubMenu(wxMenu *menu) { m_subMenu = menu; }
wxMenu *GetSubMenu() const { return m_subMenu; }
bool IsSubMenu() const { return m_subMenu != NULL; }
// state
void Enable( bool enable = TRUE );
bool IsEnabled() const { return m_isEnabled; }
void Check( bool check = TRUE );
bool IsChecked() const;
// state
void Enable( bool enable = TRUE );
bool IsEnabled() const { return m_isEnabled; }
void Check( bool check = TRUE );
bool IsChecked() const;
// help string (displayed in the status bar by default)
void SetHelp(const wxString& str) { m_helpStr = str; }
const wxString& GetHelp() const { return m_helpStr; }
// help string (displayed in the status bar by default)
void SetHelp(const wxString& str) { m_helpStr = str; }
const wxString& GetHelp() const { return m_helpStr; }
// implementation
void SetMenuItem(GtkWidget *menuItem) { m_menuItem = menuItem; }
GtkWidget *GetMenuItem() const { return m_menuItem; }
// implementation
void SetMenuItem(GtkWidget *menuItem) { m_menuItem = menuItem; }
GtkWidget *GetMenuItem() const { return m_menuItem; }
int m_id;
wxString m_text;
bool m_isCheckMenu;
bool m_isChecked;
bool m_isEnabled;
wxMenu *m_subMenu;
wxString m_helpStr;
void SetCheckedFlag(bool checked) { m_isChecked = checked; }
bool GetCheckedFlag() const { return m_isChecked; }
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
//-----------------------------------------------------------------------------
class wxMenuBar: public wxWindow
class wxMenuBar : public wxWindow
{
DECLARE_DYNAMIC_CLASS(wxMenuBar)
DECLARE_DYNAMIC_CLASS(wxMenuBar)
public:
wxMenuBar( long style );
wxMenuBar();
void Append( wxMenu *menu, const wxString &title );
// ctors
wxMenuBar();
wxMenuBar(long style);
wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
int FindMenuItem( const wxString &menuString, const wxString &itemString ) const;
wxMenuItem* FindMenuItemById( int id ) const;
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;
// menubar construction
void Append( wxMenu *menu, const wxString &title );
virtual void SetHelpString( int id, const wxString& helpString );
virtual wxString GetHelpString( int id ) const;
inline int GetMenuCount() const { return m_menus.Number(); }
inline wxMenu *GetMenu( int n ) const { return (wxMenu *)m_menus.Nth(n)->Data(); }
// item search
// by menu and item names, returns wxNOT_FOUND if not found
virtual int FindMenuItem(const wxString& menuString,
const wxString& itemString) const;
// 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;
GtkWidget *m_menubar;
// state control
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
//-----------------------------------------------------------------------------
class wxMenu: public wxEvtHandler
class wxMenu : public wxEvtHandler
{
DECLARE_DYNAMIC_CLASS(wxMenu)
DECLARE_DYNAMIC_CLASS(wxMenu)
public:
// construction
wxMenu( const wxString& title = wxEmptyString, const wxFunction func = (wxFunction) NULL );
// construction
wxMenu( const wxString& title = wxEmptyString,
const wxFunction func = (wxFunction) NULL );
// operations
// title
void SetTitle(const wxString& label);
const wxString GetTitle() const;
// menu creation
void AppendSeparator();
void Append(int id, const wxString &item,
const wxString &helpStr = "", bool checkable = FALSE);
void Append(int id, const wxString &item,
wxMenu *subMenu, const wxString &helpStr = "" );
void Append(wxMenuItem *pItem);
void Break() {};
// operations
// title
void SetTitle(const wxString& label);
const wxString GetTitle() const;
// menu creation
void AppendSeparator();
void Append(int id, const wxString &item,
const wxString &helpStr = "", bool checkable = FALSE);
void Append(int id, const wxString &item,
wxMenu *subMenu, const wxString &helpStr = "" );
void Append(wxMenuItem *pItem);
void Break() { }
// find item by name/id
int FindItem( const wxString itemString ) const;
wxMenuItem *FindItem( int id ) const;
wxMenuItem *FindItemForId( int id ) const { return FindItem( id ); }
int FindItem( const wxString itemString ) const;
wxMenuItem *FindItem( int id ) const;
// get/set item's state
void Enable( int id, bool enable );
bool IsEnabled( int id ) const;
void Check( int id, bool check );
bool IsChecked( int id ) const;
void Enable( int id, bool enable );
bool IsEnabled( int id ) const;
void Check( int id, bool check );
bool IsChecked( int id ) const;
void SetLabel( int id, const wxString &label );
wxString GetLabel( int id ) const;
void SetLabel( int id, const wxString &label );
wxString GetLabel( int id ) const;
// helpstring
virtual void SetHelpString(int id, const wxString& helpString);
virtual wxString GetHelpString(int id) const ;
// accessors
wxList& GetItems() { return m_items; }
// helpstring
virtual void SetHelpString(int id, const wxString& helpString);
virtual wxString GetHelpString(int id) const ;
inline void Callback(const wxFunction func) { m_callback = func; }
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);
// accessors
wxList& GetItems() { return m_items; }
// implementation
int FindMenuIdByMenuItem( GtkWidget *menuItem ) const;
void SetInvokingWindow( wxWindow *win );
wxWindow *GetInvokingWindow();
void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
wxEvtHandler *GetEventHandler() { return m_eventHandler; }
wxString m_title;
wxList m_items;
wxWindow *m_invokingWindow;
wxFunction m_callback;
wxEvtHandler *m_eventHandler;
void *m_clientData;
void SetClientData( void* clientData ) { m_clientData = clientData; }
void* GetClientData() const { return m_clientData; }
GtkWidget *m_menu; // GtkMenu
GtkWidget *m_owner;
// 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);
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__

View File

@ -28,63 +28,65 @@
//-----------------------------------------------------------------------------
class wxMenuItem;
class wxMenu;
//-----------------------------------------------------------------------------
// wxMenuItem
//-----------------------------------------------------------------------------
class wxMenuItem: public wxObject
class wxMenuItem : public wxObject
{
DECLARE_DYNAMIC_CLASS(wxMenuItem)
public:
wxMenuItem();
wxMenuItem();
// accessors
// id
void SetId(int id) { m_id = id; }
int GetId() const { return m_id; }
bool IsSeparator() const { return m_id == ID_SEPARATOR; }
// accessors
// id
void SetId(int id) { m_id = id; }
int GetId() const { return m_id; }
bool IsSeparator() const { return m_id == ID_SEPARATOR; }
// the item's text = name
void SetName(const wxString& str);
void SetText(const wxString& str) { SetName(str); } // compatibility
const wxString& GetName() const { return m_text; }
const wxString& GetText() const { return GetName(); }
// the item's text = name
void SetName(const wxString& str);
void SetText(const wxString& str) { SetName(str); } // compatibility
const wxString& GetName() const { return m_text; }
const wxString& GetText() const { return GetName(); }
// what kind of menu item we are
void SetCheckable(bool checkable) { m_isCheckMenu = checkable; }
bool IsCheckable() const { return m_isCheckMenu; }
void SetSubMenu(wxMenu *menu) { m_subMenu = menu; }
wxMenu *GetSubMenu() const { return m_subMenu; }
bool IsSubMenu() const { return m_subMenu != NULL; }
// what kind of menu item we are
void SetCheckable(bool checkable) { m_isCheckMenu = checkable; }
bool IsCheckable() const { return m_isCheckMenu; }
void SetSubMenu(wxMenu *menu) { m_subMenu = menu; }
wxMenu *GetSubMenu() const { return m_subMenu; }
bool IsSubMenu() const { return m_subMenu != NULL; }
// state
void Enable( bool enable = TRUE );
bool IsEnabled() const { return m_isEnabled; }
void Check( bool check = TRUE );
bool IsChecked() const;
// state
void Enable( bool enable = TRUE );
bool IsEnabled() const { return m_isEnabled; }
void Check( bool check = TRUE );
bool IsChecked() const;
// help string (displayed in the status bar by default)
void SetHelp(const wxString& str) { m_helpStr = str; }
const wxString& GetHelp() const { return m_helpStr; }
// help string (displayed in the status bar by default)
void SetHelp(const wxString& str) { m_helpStr = str; }
const wxString& GetHelp() const { return m_helpStr; }
// implementation
void SetMenuItem(GtkWidget *menuItem) { m_menuItem = menuItem; }
GtkWidget *GetMenuItem() const { return m_menuItem; }
// implementation
void SetMenuItem(GtkWidget *menuItem) { m_menuItem = menuItem; }
GtkWidget *GetMenuItem() const { return m_menuItem; }
int m_id;
wxString m_text;
bool m_isCheckMenu;
bool m_isChecked;
bool m_isEnabled;
wxMenu *m_subMenu;
wxString m_helpStr;
void SetCheckedFlag(bool checked) { m_isChecked = checked; }
bool GetCheckedFlag() const { return m_isChecked; }
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_
#ifdef __GNUG__
#pragma interface "menu.h"
#pragma interface "menu.h"
#endif
#include "wx/defs.h"
@ -22,171 +22,212 @@
class WXDLLEXPORT wxMenuItem;
class WXDLLEXPORT wxMenuBar;
class WXDLLEXPORT wxMenu;
class WXDLLEXPORT wxFrame;
WXDLLEXPORT_DATA(extern const char*) wxEmptyString;
// ----------------------------------------------------------------------------
// Menu
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxMenu: public wxEvtHandler
class WXDLLEXPORT wxMenu : public wxEvtHandler
{
DECLARE_DYNAMIC_CLASS(wxMenu)
DECLARE_DYNAMIC_CLASS(wxMenu)
public:
// ctor & dtor
wxMenu(const wxString& title = wxEmptyString, const wxFunction func = NULL);
~wxMenu();
// ctor & dtor
wxMenu(const wxString& title = wxEmptyString, const wxFunction func = NULL);
virtual ~wxMenu();
// construct menu
// append items to the menu
// separator line
void AppendSeparator();
// normal item
void Append(int id, const wxString& Label, const wxString& helpString = wxEmptyString,
bool checkable = FALSE);
// a submenu
void Append(int id, const wxString& Label, wxMenu *SubMenu,
const wxString& helpString = wxEmptyString);
// the most generic form (create wxMenuItem first and use it's functions)
void Append(wxMenuItem *pItem);
// insert a break in the menu
void Break();
// delete an item
void Delete(int id); /* If it's a submenu, menu is not destroyed. VZ: why? */
// construct menu
// append a separator to the menu
void AppendSeparator();
// append a normal item to the menu
void Append(int id, const wxString& label,
const wxString& helpString = wxEmptyString,
bool checkable = FALSE);
// append a submenu
void Append(int id, const wxString& label,
wxMenu *submenu,
const wxString& helpString = wxEmptyString);
// append anything (create wxMenuItem first)
void Append(wxMenuItem *pItem);
// Client data
inline void SetClientData(void* clientData) { m_clientData = clientData; }
inline void* GetClientData() const { return m_clientData; }
// insert a break in the menu
void Break();
// menu item control
void Enable(int id, bool Flag);
bool Enabled(int id) const;
inline bool IsEnabled(int id) const { return Enabled(id); };
void Check(int id, bool Flag);
bool Checked(int id) const;
inline bool IsChecked(int id) const { return Checked(id); };
// delete an item
// If it's a submenu, menu is not destroyed.
// VZ: why? shouldn't it return "wxMenu *" then?
void Delete(int id);
// item properties
// title
void SetTitle(const wxString& label);
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 ;
// client data
void SetClientData(void* clientData) { m_clientData = clientData; }
void* GetClientData() const { return m_clientData; }
// find item
// Finds the item id matching the given string, wxNOT_FOUND if not found.
virtual int FindItem(const wxString& itemString) const ;
// Find wxMenuItem by ID, and item's menu too if itemMenu is !NULL.
wxMenuItem *FindItemForId(int itemId, wxMenu **itemMenu = NULL) const;
// menu item control
// enable/disable item
void Enable(int id, bool enable);
// TRUE if enabled
bool IsEnabled(int id) const;
// 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);
// check/uncheck item - only for checkable items, of course
void Check(int id, bool check);
// TRUE if checked
bool IsChecked(int id) const;
void ProcessCommand(wxCommandEvent& event);
inline void Callback(const wxFunction func) { m_callback = func; }
// other properties
// 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; }
inline void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
inline wxEvtHandler *GetEventHandler() { return m_eventHandler; }
// get the list of items
wxList& GetItems() const { return (wxList &)m_menuItems; }
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
bool MSWCommand(WXUINT param, WXWORD id);
// 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);
void SetInvokingWindow(wxWindow *pWin) { m_pInvokingWindow = pWin; }
wxWindow *GetInvokingWindow() const { return m_pInvokingWindow; }
void ProcessCommand(wxCommandEvent& event);
// semi-private accessors
// get the window which contains this menu
wxWindow *GetWindow() const;
// get the menu handle
WXHMENU GetHMenu() const;
virtual void SetParent(wxEvtHandler *parent) { m_parent = parent; }
void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
wxEvtHandler *GetEventHandler() const { return m_eventHandler; }
#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:
bool m_doBreak ;
bool m_doBreak ;
public:
// 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).
// But we'll still need the handle for other purposes.
// Might be better to have a flag saying whether it's deleteable or not.
WXHMENU m_savehMenu ; // Used for Enable() on popup
WXHMENU m_hMenu;
wxFunction m_callback;
// 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).
// But we'll still need the handle for other purposes.
// Might be better to have a flag saying whether it's deleteable or not.
WXHMENU m_savehMenu ; // Used for Enable() on popup
WXHMENU m_hMenu;
wxFunction m_callback;
int m_noItems;
wxString m_title;
wxMenu * m_topLevelMenu;
wxMenuBar * m_menuBar;
wxList m_menuItems;
wxEvtHandler * m_parent;
wxEvtHandler * m_eventHandler;
wxWindow *m_pInvokingWindow;
void* m_clientData;
int m_noItems;
wxString m_title;
wxMenu * m_topLevelMenu;
wxMenuBar * m_menuBar;
wxList m_menuItems;
wxEvtHandler * m_parent;
wxEvtHandler * m_eventHandler;
wxWindow *m_pInvokingWindow;
void* m_clientData;
};
// ----------------------------------------------------------------------------
// 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:
wxMenuBar();
wxMenuBar( long style );
wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
~wxMenuBar();
// ctors & dtor
wxMenuBar();
wxMenuBar(long style);
wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
virtual ~wxMenuBar();
void Append(wxMenu *menu, const wxString& title);
// Must only be used AFTER menu has been attached to frame,
// otherwise use individual menus to enable/disable items
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);
// menubar construction
void Append(wxMenu *menu, const wxString& title);
virtual void Delete(wxMenu *menu, int index = 0); /* Menu not destroyed */
virtual void SetHelpString(int Id, const wxString& helpString);
virtual wxString GetHelpString(int Id) const ;
// state control
// 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
// menu too if itemMenu is non-NULL.
wxMenuItem *FindItemForId(int itemId, wxMenu **menuForItem = NULL) const ;
void SetLabel(int id, const wxString& label) ;
wxString GetLabel(int id) const ;
inline void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
inline wxEvtHandler *GetEventHandler() { return m_eventHandler; }
virtual void SetHelpString(int id, const wxString& helpString);
virtual wxString GetHelpString(int id) const ;
inline int GetMenuCount() const { return m_menuCount; }
inline wxMenu* GetMenu(int i) const { return m_menus[i]; }
void SetLabelTop(int pos, const wxString& label) ;
wxString GetLabelTop(int pos) const ;
public:
wxEvtHandler * m_eventHandler;
int m_menuCount;
wxMenu ** m_menus;
wxString * m_titles;
wxFrame * m_menuBarFrame;
WXHMENU m_hMenu;
// notifications
virtual bool OnAppend(wxMenu *menu, const char *title);
virtual bool OnDelete(wxMenu *menu, int index);
// item search
// by menu and item names, returns wxNOT_FOUND if not found
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_

View File

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

View File

@ -514,7 +514,7 @@ void wxFrame::OnSize( wxSizeEvent &WXUNUSED(event) )
static void SetInvokingWindow( wxMenu *menu, wxWindow *win )
{
menu->SetInvokingWindow( win );
wxNode *node = menu->m_items.First();
wxNode *node = menu->GetItems().First();
while (node)
{
wxMenuItem *menuitem = (wxMenuItem*)node->Data();
@ -533,7 +533,7 @@ void wxFrame::SetMenuBar( wxMenuBar *menuBar )
if (m_frameMenuBar)
{
wxNode *node = m_frameMenuBar->m_menus.First();
wxNode *node = m_frameMenuBar->GetMenus().First();
while (node)
{
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 );
/* 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)
{
m_mdiMenuBar->m_x = 0;
m_mdiMenuBar->m_x = 0;
m_mdiMenuBar->m_y = 0;
m_mdiMenuBar->m_width = m_width;
m_mdiMenuBar->m_height = wxMENU_HEIGHT;
@ -137,13 +137,13 @@ void wxMDIParentFrame::SetMDIMenuBar( wxMenuBar *menu_bar )
{
/* hide old child menu bar */
if (m_mdiMenuBar) m_mdiMenuBar->Show( FALSE );
m_mdiMenuBar = menu_bar;
/* show and resize new menu child menu bar */
if (m_mdiMenuBar)
{
m_mdiMenuBar->m_x = 0;
m_mdiMenuBar->m_x = 0;
m_mdiMenuBar->m_y = 0;
m_mdiMenuBar->m_width = m_width;
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 );
m_mdiMenuBar->Show( TRUE );
}
/* show/hide parent menu bar as required */
if (m_frameMenuBar) m_frameMenuBar->Show( (m_mdiMenuBar == NULL) );
}
@ -202,7 +202,7 @@ void wxMDIParentFrame::OnSysColourChanged( wxSysColourChangedEvent& WXUNUSED(eve
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame,wxFrame)
BEGIN_EVENT_TABLE(wxMDIChildFrame, wxFrame)
EVT_ACTIVATE(wxMDIChildFrame::OnActivate)
END_EVENT_TABLE()
@ -243,7 +243,7 @@ bool wxMDIChildFrame::Create( wxMDIParentFrame *parent,
long style, const wxString& name )
{
m_title = title;
return wxWindow::Create( parent->GetClientWindow(), id, wxDefaultPosition, size, style, name );
}
@ -256,11 +256,11 @@ void wxMDIChildFrame::AddChild( wxWindow *child )
{
wxWindow::AddChild( child );
}
static void SetInvokingWindow( wxMenu *menu, wxWindow *win )
{
menu->SetInvokingWindow( win );
wxNode *node = menu->m_items.First();
wxNode *node = menu->GetItems().First();
while (node)
{
wxMenuItem *menuitem = (wxMenuItem*)node->Data();
@ -280,7 +280,7 @@ void wxMDIChildFrame::SetMenuBar( wxMenuBar *menu_bar )
if (m_menuBar->m_parent != this)
{
wxNode *node = m_menuBar->m_menus.First();
wxNode *node = m_menuBar->GetMenus().First();
while (node)
{
wxMenu *menu = (wxMenu*)node->Data();
@ -290,10 +290,10 @@ void wxMDIChildFrame::SetMenuBar( wxMenuBar *menu_bar )
m_menuBar->m_parent = mdi_frame;
}
gtk_myfixed_put( GTK_MYFIXED(mdi_frame->m_wxwindow),
m_menuBar->m_widget, m_menuBar->m_x, m_menuBar->m_y );
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_FUNC(gtk_page_size_callback), (gpointer)child );
GtkNotebook *notebook = GTK_NOTEBOOK(parent->m_widget);
gtk_notebook_append_page( notebook, child->m_widget, label_widget );
child->m_page = (GtkNotebookPage*) (g_list_last(notebook->children)->data);
gtk_notebook_set_page( notebook, parent->m_children.Number()-1 );
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 )
{
m_needParent = TRUE;
m_insertCallback = (wxInsertChildFunction)wxInsertChildInMDI;
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->m_insertCallback)( m_parent, this );
PostCreation();
Show( TRUE );

View File

@ -39,8 +39,8 @@ wxMenuBar::wxMenuBar( long style )
if (style & wxMB_DOCKABLE)
{
m_widget = gtk_handle_box_new();
gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_menubar) );
gtk_widget_show( GTK_WIDGET(m_menubar) );
gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_menubar) );
gtk_widget_show( GTK_WIDGET(m_menubar) );
}
else
{
@ -72,16 +72,19 @@ wxMenuBar::wxMenuBar()
void wxMenuBar::Append( wxMenu *menu, const wxString &title )
{
m_menus.Append( menu );
menu->m_title = title;
wxString title2 = title;
int pos;
do
do
{
pos = menu->m_title.First( '&' );
if (pos != -1) menu->m_title.Remove( pos, 1 );
} while (pos != -1);
pos = title2.First( '&' );
if (pos != wxNOT_FOUND)
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_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 )
{
if (menu->m_title == menuString)
if (menu->GetTitle() == menuString)
{
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)
{
wxMenuItem *item = (wxMenuItem*)node->Data();
@ -106,7 +110,19 @@ static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString
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
@ -122,26 +138,26 @@ int wxMenuBar::FindMenuItem( const wxString &menuString, const wxString &itemStr
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)
{
wxMenuItem* result = menu->FindItem(id);
wxNode *node = menu->m_items.First();
while ( node && result == NULL )
wxNode *node = ((wxMenu *)menu)->GetItems().First(); // const_cast
while ( node && result == NULL )
{
wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->IsSubMenu())
{
{
result = FindMenuItemByIdRecursive( item->GetSubMenu(), id );
}
}
node = node->Next();
}
return result;
}
wxMenuItem* wxMenuBar::FindMenuItemById( int id ) const
wxMenuItem* wxMenuBar::FindItem( int id ) const
{
wxMenuItem* result = 0;
wxNode *node = m_menus.First();
@ -151,101 +167,114 @@ wxMenuItem* wxMenuBar::FindMenuItemById( int id ) const
result = FindMenuItemByIdRecursive( menu, id );
node = node->Next();
}
return result;
}
void wxMenuBar::Check( int id, bool check )
{
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 );
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 )
{
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 );
if (item) return item->IsEnabled();
return FALSE;
wxCHECK_MSG( item, FALSE, "wxMenuBar::IsEnabled: no such item" );
return item->IsEnabled();
}
wxString wxMenuBar::GetLabel( int id ) const
{
wxMenuItem* item = FindMenuItemById( id );
if (item) return item->GetText();
return wxString("");
wxCHECK_MSG( item, "", "wxMenuBar::GetLabel: no such item" );
return item->GetText();
}
void wxMenuBar::SetLabel( int id, const wxString &label )
{
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 )
{
wxNode *node = m_menus.Nth( pos );
wxCHECK_RET( node, "menu not found" );
wxMenu* menu = (wxMenu*)node->Data();
if (menu->m_owner) gtk_widget_set_sensitive( menu->m_owner, flag );
if (menu->m_owner)
gtk_widget_set_sensitive( menu->m_owner, flag );
}
wxString wxMenuBar::GetLabelTop( int pos ) const
{
wxNode *node = m_menus.Nth( pos );
wxCHECK_MSG( node, "invalid", "menu not found" );
wxMenu* menu = (wxMenu*)node->Data();
return menu->GetTitle();
}
void wxMenuBar::SetLabelTop( int pos, const wxString& label )
{
wxNode *node = m_menus.Nth( pos );
wxCHECK_RET( node, "menu not found" );
wxMenu* menu = (wxMenu*)node->Data();
menu->SetTitle( label );
}
void wxMenuBar::SetHelpString( int id, const wxString& helpString )
{
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
{
wxMenuItem* item = FindMenuItemById( id );
if (item)
return item->GetHelp();
else
return wxString("");
wxCHECK_MSG( item, "", "wxMenuBar::GetHelpString: no such item" );
return item->GetHelp();
}
//-----------------------------------------------------------------------------
@ -257,41 +286,44 @@ static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu )
int id = menu->FindMenuIdByMenuItem(widget);
/* 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 );
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;
}
else
{
/* the user pressed on the menu item -> report */
item->m_isChecked = item->IsChecked(); /* make consistent again */
}
}
else
{
/* the user pressed on the menu item -> report */
item->SetCheckedFlag(item->IsChecked()); /* make consistent again */
}
}
wxCommandEvent event( wxEVT_COMMAND_MENU_SELECTED, id );
event.SetEventObject( menu );
event.SetInt(id );
if (menu->m_callback)
if (menu->GetCallback())
{
(void) (*(menu->m_callback)) (*menu, event);
(void) (*(menu->GetCallback())) (*menu, event);
return;
}
if (menu->GetEventHandler()->ProcessEvent(event)) return;
if (menu->GetEventHandler()->ProcessEvent(event))
return;
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!
if (!menu->IsEnabled(id)) return;
if (!menu->IsEnabled(id))
return;
wxMenuEvent event( wxEVT_MENU_HIGHLIGHT, id );
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();
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!
if (!menu->IsEnabled(id)) return;
if (!menu->IsEnabled(id))
return;
wxMenuEvent event( wxEVT_MENU_HIGHLIGHT, -1 );
event.SetEventObject( menu );
if (menu->GetEventHandler()->ProcessEvent(event)) return;
if (menu->GetEventHandler()->ProcessEvent(event))
return;
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;
}
/* 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 )
{
m_text = "";
@ -432,13 +469,13 @@ wxMenu::wxMenu( const wxString& title, const wxFunction func )
Append(-2, m_title);
AppendSeparator();
}
m_owner = (GtkWidget*) NULL;
}
void wxMenu::SetTitle( const wxString& title )
{
/* Waiting for something better. */
// TODO Waiting for something better
m_title = title;
}
@ -517,14 +554,14 @@ void wxMenu::Append( int id, const wxString &text, wxMenu *subMenu, const wxStri
void wxMenu::Append( wxMenuItem *item )
{
m_items.Append( item );
GtkWidget *menuItem = (GtkWidget*) NULL;
if (item->IsSeparator())
if (item->IsSeparator())
menuItem = gtk_menu_item_new();
else if (item->IsSubMenu())
else if (item->IsSubMenu())
menuItem = gtk_menu_item_new_with_label(item->GetText());
else
else
menuItem = item->IsCheckable() ? gtk_check_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_FUNC(gtk_menu_nolight_callback),
(gpointer*)this );
if (!item->IsSubMenu())
{
if (!item->IsSubMenu())
{
gtk_signal_connect( GTK_OBJECT(menuItem), "activate",
GTK_SIGNAL_FUNC(gtk_menu_clicked_callback),
(gpointer*)this );
}
}
}
gtk_menu_append( GTK_MENU(m_menu), menuItem );
gtk_widget_show( menuItem );
item->SetMenuItem(menuItem);
@ -556,7 +593,7 @@ int wxMenu::FindItem( const wxString itemString ) const
wxString s( itemString );
int pos;
do
do
{
pos = s.First( '&' );
if (pos != -1) s.Remove( pos, 1 );
@ -567,98 +604,85 @@ int wxMenu::FindItem( const wxString itemString ) const
{
wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->GetText() == s)
{
{
return item->GetId();
}
}
node = node->Next();
}
return -1;
return wxNOT_FOUND;
}
void wxMenu::Enable( int id, bool enable )
{
wxMenuItem *item = FindItem(id);
if (item)
{
item->Enable(enable);
}
wxCHECK_RET( item, "wxMenu::Enable: no such item" );
item->Enable(enable);
}
bool wxMenu::IsEnabled( int id ) const
{
wxMenuItem *item = FindItem(id);
if (item)
{
return item->IsEnabled();
}
else
{
return FALSE;
}
wxCHECK_MSG( item, FALSE, "wxMenu::IsEnabled: no such item" );
return item->IsEnabled();
}
void wxMenu::Check( int id, bool enable )
{
wxMenuItem *item = FindItem(id);
if (item)
{
item->Check(enable);
}
wxCHECK_RET( item, "wxMenu::Check: no such item" );
item->Check(enable);
}
bool wxMenu::IsChecked( int id ) const
{
wxMenuItem *item = FindItem(id);
if (item)
{
return item->IsChecked();
}
else
{
return FALSE;
}
wxCHECK_MSG( item, FALSE, "wxMenu::IsChecked: no such item" );
return item->IsChecked();
}
void wxMenu::SetLabel( int id, const wxString &label )
{
wxMenuItem *item = FindItem(id);
if (item)
{
item->SetText(label);
}
wxCHECK_RET( item, "wxMenu::SetLabel: no such item" );
item->SetText(label);
}
wxString wxMenu::GetLabel( int id ) const
{
wxMenuItem *item = FindItem(id);
if (item)
{
return item->GetText();
}
else
{
return "";
}
wxCHECK_MSG( item, "", "wxMenu::GetLabel: no such item" );
return item->GetText();
}
void wxMenu::SetHelpString( int id, const wxString& helpString )
{
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
{
wxMenuItem *item = FindItem(id);
if (item)
{
return item->GetHelp();
}
else
{
return "";
}
wxCHECK_MSG( item, "", "wxMenu::GetHelpString: no such item" );
return item->GetHelp();
}
int wxMenu::FindMenuIdByMenuItem( GtkWidget *menuItem ) const
@ -672,19 +696,19 @@ int wxMenu::FindMenuIdByMenuItem( GtkWidget *menuItem ) const
node = node->Next();
}
return -1;
return wxNOT_FOUND;
}
wxMenuItem *wxMenu::FindItem(int id) const
{
wxNode *node = m_items.First();
while (node)
while (node)
{
wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->GetId() == id)
{
{
return item;
}
}
node = node->Next();
}
@ -705,10 +729,9 @@ wxWindow *wxMenu::GetInvokingWindow()
return m_invokingWindow;
}
// Update 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.
// Update 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 wxMenu::UpdateUI(wxEvtHandler* source)
{
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 )
{
menu->SetInvokingWindow( win );
wxNode *node = menu->m_items.First();
wxNode *node = menu->GetItems().First();
while (node)
{
wxMenuItem *menuitem = (wxMenuItem*)node->Data();

View File

@ -514,7 +514,7 @@ void wxFrame::OnSize( wxSizeEvent &WXUNUSED(event) )
static void SetInvokingWindow( wxMenu *menu, wxWindow *win )
{
menu->SetInvokingWindow( win );
wxNode *node = menu->m_items.First();
wxNode *node = menu->GetItems().First();
while (node)
{
wxMenuItem *menuitem = (wxMenuItem*)node->Data();
@ -533,7 +533,7 @@ void wxFrame::SetMenuBar( wxMenuBar *menuBar )
if (m_frameMenuBar)
{
wxNode *node = m_frameMenuBar->m_menus.First();
wxNode *node = m_frameMenuBar->GetMenus().First();
while (node)
{
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 );
/* 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)
{
m_mdiMenuBar->m_x = 0;
m_mdiMenuBar->m_x = 0;
m_mdiMenuBar->m_y = 0;
m_mdiMenuBar->m_width = m_width;
m_mdiMenuBar->m_height = wxMENU_HEIGHT;
@ -137,13 +137,13 @@ void wxMDIParentFrame::SetMDIMenuBar( wxMenuBar *menu_bar )
{
/* hide old child menu bar */
if (m_mdiMenuBar) m_mdiMenuBar->Show( FALSE );
m_mdiMenuBar = menu_bar;
/* show and resize new menu child menu bar */
if (m_mdiMenuBar)
{
m_mdiMenuBar->m_x = 0;
m_mdiMenuBar->m_x = 0;
m_mdiMenuBar->m_y = 0;
m_mdiMenuBar->m_width = m_width;
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 );
m_mdiMenuBar->Show( TRUE );
}
/* show/hide parent menu bar as required */
if (m_frameMenuBar) m_frameMenuBar->Show( (m_mdiMenuBar == NULL) );
}
@ -202,7 +202,7 @@ void wxMDIParentFrame::OnSysColourChanged( wxSysColourChangedEvent& WXUNUSED(eve
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame,wxFrame)
BEGIN_EVENT_TABLE(wxMDIChildFrame, wxFrame)
EVT_ACTIVATE(wxMDIChildFrame::OnActivate)
END_EVENT_TABLE()
@ -243,7 +243,7 @@ bool wxMDIChildFrame::Create( wxMDIParentFrame *parent,
long style, const wxString& name )
{
m_title = title;
return wxWindow::Create( parent->GetClientWindow(), id, wxDefaultPosition, size, style, name );
}
@ -256,11 +256,11 @@ void wxMDIChildFrame::AddChild( wxWindow *child )
{
wxWindow::AddChild( child );
}
static void SetInvokingWindow( wxMenu *menu, wxWindow *win )
{
menu->SetInvokingWindow( win );
wxNode *node = menu->m_items.First();
wxNode *node = menu->GetItems().First();
while (node)
{
wxMenuItem *menuitem = (wxMenuItem*)node->Data();
@ -280,7 +280,7 @@ void wxMDIChildFrame::SetMenuBar( wxMenuBar *menu_bar )
if (m_menuBar->m_parent != this)
{
wxNode *node = m_menuBar->m_menus.First();
wxNode *node = m_menuBar->GetMenus().First();
while (node)
{
wxMenu *menu = (wxMenu*)node->Data();
@ -290,10 +290,10 @@ void wxMDIChildFrame::SetMenuBar( wxMenuBar *menu_bar )
m_menuBar->m_parent = mdi_frame;
}
gtk_myfixed_put( GTK_MYFIXED(mdi_frame->m_wxwindow),
m_menuBar->m_widget, m_menuBar->m_x, m_menuBar->m_y );
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_FUNC(gtk_page_size_callback), (gpointer)child );
GtkNotebook *notebook = GTK_NOTEBOOK(parent->m_widget);
gtk_notebook_append_page( notebook, child->m_widget, label_widget );
child->m_page = (GtkNotebookPage*) (g_list_last(notebook->children)->data);
gtk_notebook_set_page( notebook, parent->m_children.Number()-1 );
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 )
{
m_needParent = TRUE;
m_insertCallback = (wxInsertChildFunction)wxInsertChildInMDI;
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->m_insertCallback)( m_parent, this );
PostCreation();
Show( TRUE );

View File

@ -39,8 +39,8 @@ wxMenuBar::wxMenuBar( long style )
if (style & wxMB_DOCKABLE)
{
m_widget = gtk_handle_box_new();
gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_menubar) );
gtk_widget_show( GTK_WIDGET(m_menubar) );
gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_menubar) );
gtk_widget_show( GTK_WIDGET(m_menubar) );
}
else
{
@ -72,16 +72,19 @@ wxMenuBar::wxMenuBar()
void wxMenuBar::Append( wxMenu *menu, const wxString &title )
{
m_menus.Append( menu );
menu->m_title = title;
wxString title2 = title;
int pos;
do
do
{
pos = menu->m_title.First( '&' );
if (pos != -1) menu->m_title.Remove( pos, 1 );
} while (pos != -1);
pos = title2.First( '&' );
if (pos != wxNOT_FOUND)
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_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 )
{
if (menu->m_title == menuString)
if (menu->GetTitle() == menuString)
{
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)
{
wxMenuItem *item = (wxMenuItem*)node->Data();
@ -106,7 +110,19 @@ static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString
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
@ -122,26 +138,26 @@ int wxMenuBar::FindMenuItem( const wxString &menuString, const wxString &itemStr
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)
{
wxMenuItem* result = menu->FindItem(id);
wxNode *node = menu->m_items.First();
while ( node && result == NULL )
wxNode *node = ((wxMenu *)menu)->GetItems().First(); // const_cast
while ( node && result == NULL )
{
wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->IsSubMenu())
{
{
result = FindMenuItemByIdRecursive( item->GetSubMenu(), id );
}
}
node = node->Next();
}
return result;
}
wxMenuItem* wxMenuBar::FindMenuItemById( int id ) const
wxMenuItem* wxMenuBar::FindItem( int id ) const
{
wxMenuItem* result = 0;
wxNode *node = m_menus.First();
@ -151,101 +167,114 @@ wxMenuItem* wxMenuBar::FindMenuItemById( int id ) const
result = FindMenuItemByIdRecursive( menu, id );
node = node->Next();
}
return result;
}
void wxMenuBar::Check( int id, bool check )
{
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 );
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 )
{
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 );
if (item) return item->IsEnabled();
return FALSE;
wxCHECK_MSG( item, FALSE, "wxMenuBar::IsEnabled: no such item" );
return item->IsEnabled();
}
wxString wxMenuBar::GetLabel( int id ) const
{
wxMenuItem* item = FindMenuItemById( id );
if (item) return item->GetText();
return wxString("");
wxCHECK_MSG( item, "", "wxMenuBar::GetLabel: no such item" );
return item->GetText();
}
void wxMenuBar::SetLabel( int id, const wxString &label )
{
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 )
{
wxNode *node = m_menus.Nth( pos );
wxCHECK_RET( node, "menu not found" );
wxMenu* menu = (wxMenu*)node->Data();
if (menu->m_owner) gtk_widget_set_sensitive( menu->m_owner, flag );
if (menu->m_owner)
gtk_widget_set_sensitive( menu->m_owner, flag );
}
wxString wxMenuBar::GetLabelTop( int pos ) const
{
wxNode *node = m_menus.Nth( pos );
wxCHECK_MSG( node, "invalid", "menu not found" );
wxMenu* menu = (wxMenu*)node->Data();
return menu->GetTitle();
}
void wxMenuBar::SetLabelTop( int pos, const wxString& label )
{
wxNode *node = m_menus.Nth( pos );
wxCHECK_RET( node, "menu not found" );
wxMenu* menu = (wxMenu*)node->Data();
menu->SetTitle( label );
}
void wxMenuBar::SetHelpString( int id, const wxString& helpString )
{
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
{
wxMenuItem* item = FindMenuItemById( id );
if (item)
return item->GetHelp();
else
return wxString("");
wxCHECK_MSG( item, "", "wxMenuBar::GetHelpString: no such item" );
return item->GetHelp();
}
//-----------------------------------------------------------------------------
@ -257,41 +286,44 @@ static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu )
int id = menu->FindMenuIdByMenuItem(widget);
/* 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 );
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;
}
else
{
/* the user pressed on the menu item -> report */
item->m_isChecked = item->IsChecked(); /* make consistent again */
}
}
else
{
/* the user pressed on the menu item -> report */
item->SetCheckedFlag(item->IsChecked()); /* make consistent again */
}
}
wxCommandEvent event( wxEVT_COMMAND_MENU_SELECTED, id );
event.SetEventObject( menu );
event.SetInt(id );
if (menu->m_callback)
if (menu->GetCallback())
{
(void) (*(menu->m_callback)) (*menu, event);
(void) (*(menu->GetCallback())) (*menu, event);
return;
}
if (menu->GetEventHandler()->ProcessEvent(event)) return;
if (menu->GetEventHandler()->ProcessEvent(event))
return;
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!
if (!menu->IsEnabled(id)) return;
if (!menu->IsEnabled(id))
return;
wxMenuEvent event( wxEVT_MENU_HIGHLIGHT, id );
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();
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!
if (!menu->IsEnabled(id)) return;
if (!menu->IsEnabled(id))
return;
wxMenuEvent event( wxEVT_MENU_HIGHLIGHT, -1 );
event.SetEventObject( menu );
if (menu->GetEventHandler()->ProcessEvent(event)) return;
if (menu->GetEventHandler()->ProcessEvent(event))
return;
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;
}
/* 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 )
{
m_text = "";
@ -432,13 +469,13 @@ wxMenu::wxMenu( const wxString& title, const wxFunction func )
Append(-2, m_title);
AppendSeparator();
}
m_owner = (GtkWidget*) NULL;
}
void wxMenu::SetTitle( const wxString& title )
{
/* Waiting for something better. */
// TODO Waiting for something better
m_title = title;
}
@ -517,14 +554,14 @@ void wxMenu::Append( int id, const wxString &text, wxMenu *subMenu, const wxStri
void wxMenu::Append( wxMenuItem *item )
{
m_items.Append( item );
GtkWidget *menuItem = (GtkWidget*) NULL;
if (item->IsSeparator())
if (item->IsSeparator())
menuItem = gtk_menu_item_new();
else if (item->IsSubMenu())
else if (item->IsSubMenu())
menuItem = gtk_menu_item_new_with_label(item->GetText());
else
else
menuItem = item->IsCheckable() ? gtk_check_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_FUNC(gtk_menu_nolight_callback),
(gpointer*)this );
if (!item->IsSubMenu())
{
if (!item->IsSubMenu())
{
gtk_signal_connect( GTK_OBJECT(menuItem), "activate",
GTK_SIGNAL_FUNC(gtk_menu_clicked_callback),
(gpointer*)this );
}
}
}
gtk_menu_append( GTK_MENU(m_menu), menuItem );
gtk_widget_show( menuItem );
item->SetMenuItem(menuItem);
@ -556,7 +593,7 @@ int wxMenu::FindItem( const wxString itemString ) const
wxString s( itemString );
int pos;
do
do
{
pos = s.First( '&' );
if (pos != -1) s.Remove( pos, 1 );
@ -567,98 +604,85 @@ int wxMenu::FindItem( const wxString itemString ) const
{
wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->GetText() == s)
{
{
return item->GetId();
}
}
node = node->Next();
}
return -1;
return wxNOT_FOUND;
}
void wxMenu::Enable( int id, bool enable )
{
wxMenuItem *item = FindItem(id);
if (item)
{
item->Enable(enable);
}
wxCHECK_RET( item, "wxMenu::Enable: no such item" );
item->Enable(enable);
}
bool wxMenu::IsEnabled( int id ) const
{
wxMenuItem *item = FindItem(id);
if (item)
{
return item->IsEnabled();
}
else
{
return FALSE;
}
wxCHECK_MSG( item, FALSE, "wxMenu::IsEnabled: no such item" );
return item->IsEnabled();
}
void wxMenu::Check( int id, bool enable )
{
wxMenuItem *item = FindItem(id);
if (item)
{
item->Check(enable);
}
wxCHECK_RET( item, "wxMenu::Check: no such item" );
item->Check(enable);
}
bool wxMenu::IsChecked( int id ) const
{
wxMenuItem *item = FindItem(id);
if (item)
{
return item->IsChecked();
}
else
{
return FALSE;
}
wxCHECK_MSG( item, FALSE, "wxMenu::IsChecked: no such item" );
return item->IsChecked();
}
void wxMenu::SetLabel( int id, const wxString &label )
{
wxMenuItem *item = FindItem(id);
if (item)
{
item->SetText(label);
}
wxCHECK_RET( item, "wxMenu::SetLabel: no such item" );
item->SetText(label);
}
wxString wxMenu::GetLabel( int id ) const
{
wxMenuItem *item = FindItem(id);
if (item)
{
return item->GetText();
}
else
{
return "";
}
wxCHECK_MSG( item, "", "wxMenu::GetLabel: no such item" );
return item->GetText();
}
void wxMenu::SetHelpString( int id, const wxString& helpString )
{
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
{
wxMenuItem *item = FindItem(id);
if (item)
{
return item->GetHelp();
}
else
{
return "";
}
wxCHECK_MSG( item, "", "wxMenu::GetHelpString: no such item" );
return item->GetHelp();
}
int wxMenu::FindMenuIdByMenuItem( GtkWidget *menuItem ) const
@ -672,19 +696,19 @@ int wxMenu::FindMenuIdByMenuItem( GtkWidget *menuItem ) const
node = node->Next();
}
return -1;
return wxNOT_FOUND;
}
wxMenuItem *wxMenu::FindItem(int id) const
{
wxNode *node = m_items.First();
while (node)
while (node)
{
wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->GetId() == id)
{
{
return item;
}
}
node = node->Next();
}
@ -705,10 +729,9 @@ wxWindow *wxMenu::GetInvokingWindow()
return m_invokingWindow;
}
// Update 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.
// Update 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 wxMenu::UpdateUI(wxEvtHandler* source)
{
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 )
{
menu->SetInvokingWindow( win );
wxNode *node = menu->m_items.First();
wxNode *node = menu->GetItems().First();
while (node)
{
wxMenuItem *menuitem = (wxMenuItem*)node->Data();

File diff suppressed because it is too large Load Diff