wxMotif compiles (and runs minimal sample) again after wxMenu changes

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4311 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1999-11-02 17:23:29 +00:00
parent d76e994a28
commit c71830c3b6
6 changed files with 212 additions and 455 deletions

View File

@@ -21,10 +21,38 @@
class WXDLLEXPORT wxSpinCtrl : public wxTextCtrl class WXDLLEXPORT wxSpinCtrl : public wxTextCtrl
{ {
public: public:
wxSpinCtrlBase() { Init(); } wxSpinCtrl() { Init(); }
wxSpinCtrl(wxWindow *parent,
wxWindowID id = -1,
const wxString& value = wxEmptyString,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxSP_ARROW_KEYS,
int min = 0, int max = 100, int initial = 0,
const wxString& name = _T("wxSpinCtrl"))
{
Create(parent, id, value, pos, size, style, min, max, initial, name);
}
bool Create(wxWindow *parent,
wxWindowID id = -1,
const wxString& value = wxEmptyString,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxSP_ARROW_KEYS,
int min = 0, int max = 100, int initial = 0,
const wxString& name = _T("wxSpinCtrl"))
{
SetValue(initial);
SetRange(min, max);
return wxTextCtrl::Create(parent, id, value, pos, size, style,
wxDefaultValidator, name);
}
// accessors // accessors
int GetValue() const int GetValue(int WXUNUSED(dummy) = 1) const
{ {
int n; int n;
if ( (wxSscanf(wxTextCtrl::GetValue(), wxT("%d"), &n) != 1) ) if ( (wxSscanf(wxTextCtrl::GetValue(), wxT("%d"), &n) != 1) )

View File

@@ -25,107 +25,56 @@ class wxFrame;
// Menu // Menu
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class wxMenu : public wxEvtHandler class wxMenu : public wxMenuBase
{ {
DECLARE_DYNAMIC_CLASS(wxMenu)
public: public:
// ctor & dtor // ctors & dtor
#ifdef WXWIN_COMPATIBILITY wxMenu(const wxString& title, long style = 0)
wxMenu( const wxString& title, const wxFunction func) : wxMenuBase(title, style) { Init(); }
{
Init(title, 0, func); wxMenu(long style = 0) : wxMenuBase(style) { Init(); }
}
#endif // WXWIN_COMPATIBILITY
wxMenu( const wxString& title = wxEmptyString, long style = 0 )
{
Init(title, style);
}
virtual ~wxMenu(); virtual ~wxMenu();
// construct menu // implement base class virtuals
// append items to the menu virtual bool DoAppend(wxMenuItem *item);
// separator line virtual bool DoInsert(size_t pos, wxMenuItem *item);
void AppendSeparator(); virtual wxMenuItem *DoRemove(wxMenuItem *item);
// 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);
// menu item control virtual void Break();
void Enable(int id, bool Flag);
bool Enabled(int id) const;
bool IsEnabled(int id) const { return Enabled(id); };
void Check(int id, bool Flag);
bool Checked(int id) const;
bool IsChecked(int id) const { return IsChecked(id); };
// Client data virtual void SetTitle(const wxString& title);
void SetClientData(void* clientData) { m_clientData = clientData; }
void* GetClientData() const { return m_clientData; }
// item properties bool ProcessCommand(wxCommandEvent& event);
// 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 ;
// find item #if WXWIN_COMPATIBILITY
// Finds the item id matching the given string, -1 if not found. wxMenu(const wxString& title, const wxFunction func)
virtual int FindItem(const wxString& itemString) const ; : wxMenuBase(title)
// Find wxMenuItem by ID, and item's menu too if itemMenu is !NULL. {
wxMenuItem *FindItemForId(int itemId, wxMenu **itemMenu = NULL) const; Callback(func);
}
// 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 ProcessCommand(wxCommandEvent& event);
#ifdef WXWIN_COMPATIBILITY
void Callback(const wxFunction func) { m_callback = func; }
#endif // WXWIN_COMPATIBILITY #endif // WXWIN_COMPATIBILITY
void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
wxEvtHandler *GetEventHandler() { return m_eventHandler; }
wxList& GetItems() const { return (wxList&) m_menuItems; }
void SetInvokingWindow(wxWindow *pWin) { m_pInvokingWindow = pWin; }
wxWindow *GetInvokingWindow() const { return m_pInvokingWindow; }
//// Motif-specific //// Motif-specific
WXWidget GetButtonWidget() const { return m_buttonWidget; } WXWidget GetButtonWidget() const { return m_buttonWidget; }
void SetButtonWidget(WXWidget buttonWidget) { m_buttonWidget = buttonWidget; } void SetButtonWidget(WXWidget buttonWidget) { m_buttonWidget = buttonWidget; }
WXWidget GetMainWidget() const { return m_menuWidget; } WXWidget GetMainWidget() const { return m_menuWidget; }
wxMenu* GetParent() const { return m_menuParent; }
int GetId() const { return m_menuId; } int GetId() const { return m_menuId; }
void SetId(int id) { m_menuId = id; } void SetId(int id) { m_menuId = id; }
void SetMenuBar(wxMenuBar* menuBar) { m_menuBar = menuBar; } void SetMenuBar(wxMenuBar* menuBar) { m_menuBar = menuBar; }
wxMenuBar* GetMenuBar() const { return m_menuBar; } wxMenuBar* GetMenuBar() const { return m_menuBar; }
void CreatePopup(WXWidget logicalParent, int x, int y); void CreatePopup(WXWidget logicalParent, int x, int y);
void DestroyPopup (void); void DestroyPopup();
void ShowPopup(int x, int y); void ShowPopup(int x, int y);
void HidePopup (void); void HidePopup();
WXWidget CreateMenu(wxMenuBar *menuBar, WXWidget parent, wxMenu *topMenu, WXWidget CreateMenu(wxMenuBar *menuBar, WXWidget parent, wxMenu *topMenu,
const wxString& title = "", bool isPulldown = FALSE); const wxString& title = wxEmptyString,
bool isPulldown = FALSE);
// For popups, need to destroy, then recreate menu for a different (or // For popups, need to destroy, then recreate menu for a different (or
// possibly same) window, since the parent may change. // possibly same) window, since the parent may change.
@@ -141,33 +90,18 @@ public:
void SetFont(const wxFont& colour); void SetFont(const wxFont& colour);
void ChangeFont(bool keepOriginalSize = FALSE); void ChangeFont(bool keepOriginalSize = FALSE);
// implementation from now on
WXWidget GetHandle() const { return m_menuWidget; } WXWidget GetHandle() const { return m_menuWidget; }
bool IsTearOff() const { return (m_style & wxMENU_TEAROFF) != 0; } bool IsTearOff() const { return (m_style & wxMENU_TEAROFF) != 0; }
public: public:
#ifdef WXWIN_COMPATIBILITY // Motif-specific data
wxFunction m_callback;
#endif // WXWIN_COMPATIBILITY
int m_noItems;
wxString m_title;
wxMenuBar * m_menuBar;
wxList m_menuItems;
wxEvtHandler * m_eventHandler;
void* m_clientData;
wxWindow* m_pInvokingWindow;
long m_style;
//// Motif-specific
int m_numColumns; int m_numColumns;
WXWidget m_menuWidget; WXWidget m_menuWidget;
WXWidget m_popupShell; // For holding the popup shell widget WXWidget m_popupShell; // For holding the popup shell widget
WXWidget m_buttonWidget; // The actual string, so we can grey it etc. WXWidget m_buttonWidget; // The actual string, so we can grey it etc.
int m_menuId; int m_menuId;
wxMenu* m_topLevelMenu ; wxMenu* m_topLevelMenu ;
wxMenu* m_menuParent;
bool m_ownedByMenuBar; bool m_ownedByMenuBar;
wxColour m_foregroundColour; wxColour m_foregroundColour;
wxColour m_backgroundColour; wxColour m_backgroundColour;
@@ -175,12 +109,9 @@ public:
private: private:
// common code for both constructors: // common code for both constructors:
void Init( const wxString& title, void Init();
long style
#ifdef WXWIN_COMPATIBILITY DECLARE_DYNAMIC_CLASS(wxMenu)
, const wxFunction func = (wxFunction) NULL
#endif
);
}; };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -16,11 +16,13 @@
#pragma interface "menuitem.h" #pragma interface "menuitem.h"
#endif #endif
class WXDLLEXPORT wxMenuBar;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxMenuItem: an item in the menu, optionally implements owner-drawn behaviour // wxMenuItem: an item in the menu, optionally implements owner-drawn behaviour
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class WXDLLEXPORT wxMenuItem: public wxMenuItemBase class wxMenuItem : public wxMenuItemBase
{ {
public: public:
// ctor & dtor // ctor & dtor
@@ -34,6 +36,7 @@ public:
// accessors (some more are inherited from wxOwnerDrawn or are below) // accessors (some more are inherited from wxOwnerDrawn or are below)
virtual void SetText(const wxString& label); virtual void SetText(const wxString& label);
virtual wxString GetLabel() const;
virtual void Enable(bool enable = TRUE); virtual void Enable(bool enable = TRUE);
virtual void Check(bool check = TRUE); virtual void Check(bool check = TRUE);

View File

@@ -59,21 +59,9 @@ IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxEvtHandler)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Construct a menu with optional title (then use append) // Construct a menu with optional title (then use append)
void wxMenu::Init(const wxString& title, void wxMenu::Init()
long style
#ifdef WXWIN_COMPATIBILITY
, const wxFunction func
#endif
)
{ {
m_title = title; // Motif-specific members
m_eventHandler = this;
m_noItems = 0;
m_menuBar = NULL;
m_pInvokingWindow = NULL;
m_style = style;
//// Motif-specific members
m_numColumns = 1; m_numColumns = 1;
m_menuWidget = (WXWidget) NULL; m_menuWidget = (WXWidget) NULL;
m_popupShell = (WXWidget) NULL; m_popupShell = (WXWidget) NULL;
@@ -81,21 +69,16 @@ void wxMenu::Init(const wxString& title,
m_menuId = 0; m_menuId = 0;
m_topLevelMenu = (wxMenu*) NULL; m_topLevelMenu = (wxMenu*) NULL;
m_ownedByMenuBar = FALSE; m_ownedByMenuBar = FALSE;
m_menuParent = (wxMenu*) NULL;
m_clientData = (void*) NULL;
if (m_title != "") if ( !!m_title )
{ {
Append(ID_SEPARATOR, m_title) ; Append(wxID_SEPARATOR, m_title) ;
AppendSeparator() ; AppendSeparator() ;
} }
m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENU); m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENU);
m_foregroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENUTEXT); m_foregroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENUTEXT);
m_font = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT); m_font = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT);
#ifdef WXWIN_COMPATIBILITY
Callback(func);
#endif
} }
// The wxWindow destructor will take care of deleting the submenus. // The wxWindow destructor will take care of deleting the submenus.
@@ -115,22 +98,6 @@ wxMenu::~wxMenu()
m_menuParent = NULL; m_menuParent = NULL;
// m_menuBar = NULL; // m_menuBar = NULL;
} }
wxNode *node = m_menuItems.First();
while (node)
{
wxMenuItem *item = (wxMenuItem *)node->Data();
/*
if (item->GetSubMenu())
item->DeleteSubMenu();
*/
wxNode *next = node->Next();
delete item;
delete node;
node = next;
}
} }
void wxMenu::Break() void wxMenu::Break()
@@ -139,249 +106,70 @@ void wxMenu::Break()
} }
// function appends a new item or submenu to the menu // function appends a new item or submenu to the menu
void wxMenu::Append(wxMenuItem *pItem) bool wxMenu::DoAppend(wxMenuItem *pItem)
{ {
wxCHECK_RET( pItem != NULL, "can't append NULL item to the menu" );
m_menuItems.Append(pItem);
if (m_menuWidget) if (m_menuWidget)
pItem->CreateItem (m_menuWidget, m_menuBar, m_topLevelMenu); // this is a dynamic Append {
// this is a dynamic Append
m_noItems++; pItem->CreateItem(m_menuWidget, m_menuBar, m_topLevelMenu);
} }
void wxMenu::AppendSeparator() if ( pItem->IsSubMenu() )
{ {
Append(new wxMenuItem(this, ID_SEPARATOR)); pItem->GetSubMenu()->m_topLevelMenu = m_topLevelMenu;
} }
// Pullright item return wxMenuBase::DoAppend(pItem);
// N.B.: difference between old and new code.
// Old code stores subMenu in 'children' for later deletion,
// as well as in m_menuItems, whereas we only store it in
// m_menuItems here. What implications does this have?
void wxMenu::Append(int id, const wxString& label, wxMenu *subMenu,
const wxString& helpString)
{
Append(new wxMenuItem(this, id, label, helpString, FALSE, subMenu));
subMenu->m_topLevelMenu = m_topLevelMenu;
} }
// Ordinary menu item wxMenuItem *wxMenu::DoRemove(wxMenuItem *item)
void wxMenu::Append(int id, const wxString& label,
const wxString& helpString, bool checkable)
{ {
// 'checkable' parameter is useless for Windows.
Append(new wxMenuItem(this, id, label, helpString, checkable));
}
void wxMenu::Delete(int id)
{
wxNode *node;
wxMenuItem *item;
int pos;
for (pos = 0, node = m_menuItems.First(); node; node = node->Next(), pos++)
{
item = (wxMenuItem *)node->Data();
if (item->GetId() == id)
break;
}
if (!node)
return;
item->DestroyItem(TRUE); item->DestroyItem(TRUE);
// See also old code - don't know if this is needed (seems redundant). return wxMenuBase::DoRemove(item);
/*
if (item->GetSubMenu()) {
item->subMenu->top_level_menu = item->GetSubMenu();
item->subMenu->window_parent = NULL;
children->DeleteObject(item->GetSubMenu());
}
*/
m_menuItems.DeleteNode(node);
delete item;
} }
void wxMenu::Enable(int id, bool flag) bool wxMenu::DoInsert(size_t pos, wxMenuItem *item)
{ {
wxMenuItem *item = FindItemForId(id); if ( !wxMenuBase::DoInsert(pos, item) )
wxCHECK_RET( item != NULL, "can't enable non-existing menu item" ); return FALSE;
item->Enable(flag); wxFAIL_MSG(wxT("not implemented"));
}
bool wxMenu::Enabled(int Id) const return FALSE;
{
wxMenuItem *item = FindItemForId(Id);
wxCHECK( item != NULL, FALSE );
return item->IsEnabled();
}
void wxMenu::Check(int Id, bool Flag)
{
wxMenuItem *item = FindItemForId(Id);
wxCHECK_RET( item != NULL, "can't get status of non-existing menu item" );
item->Check(Flag);
}
bool wxMenu::Checked(int id) const
{
wxMenuItem *item = FindItemForId(id);
wxCHECK( item != NULL, FALSE );
return item->IsChecked();
} }
void wxMenu::SetTitle(const wxString& label) void wxMenu::SetTitle(const wxString& label)
{ {
m_title = label; m_title = label;
wxNode *node = m_menuItems.First (); wxMenuItemList::Node *node = GetMenuItems().GetFirst();
if ( !node ) if ( !node )
return; return;
wxMenuItem *item = (wxMenuItem *) node->Data (); wxMenuItem *item = node->GetData ();
Widget widget = (Widget) item->GetButtonWidget(); Widget widget = (Widget) item->GetButtonWidget();
if ( !widget ) if ( !widget )
return; return;
XmString title_str = XmStringCreateSimple ((char*) (const char*) label); wxXmString title_str(label);
XtVaSetValues(widget, XtVaSetValues(widget,
XmNlabelString, title_str, XmNlabelString, title_str(),
NULL); NULL);
// TODO: should we delete title_str now?
} }
const wxString wxMenu::GetTitle() const bool wxMenu::ProcessCommand(wxCommandEvent & event)
{
return m_title;
}
void wxMenu::SetLabel(int id, const wxString& label)
{
wxMenuItem *item = FindItemForId(id);
if (item == (wxMenuItem*) NULL)
return;
item->SetText(label);
}
wxString wxMenu::GetLabel(int id) const
{
wxMenuItem *it = NULL;
WXWidget w = FindMenuItem (id, &it);
if (w)
{
XmString text;
char *s;
XtVaGetValues ((Widget) w,
XmNlabelString, &text,
NULL);
if (XmStringGetLtoR (text, XmSTRING_DEFAULT_CHARSET, &s))
{
wxString str(s);
XtFree (s);
return str;
}
else
{
XmStringFree (text);
return wxEmptyString;
}
}
else
return wxEmptyString;
}
// Finds the item id matching the given string, -1 if not found.
int wxMenu::FindItem (const wxString& itemString) const
{
char buf1[200];
char buf2[200];
wxStripMenuCodes ((char *)(const char *)itemString, buf1);
for (wxNode * node = m_menuItems.First (); node; node = node->Next ())
{
wxMenuItem *item = (wxMenuItem *) node->Data ();
if (item->GetSubMenu())
{
int ans = item->GetSubMenu()->FindItem(itemString);
if (ans > -1)
return ans;
}
if ( !item->IsSeparator() )
{
wxStripMenuCodes((char *)item->GetName().c_str(), buf2);
if (strcmp(buf1, buf2) == 0)
return item->GetId();
}
}
return -1;
}
wxMenuItem *wxMenu::FindItemForId(int itemId, wxMenu ** itemMenu) const
{
if (itemMenu)
*itemMenu = NULL;
for (wxNode * node = m_menuItems.First (); node; node = node->Next ())
{
wxMenuItem *item = (wxMenuItem *) node->Data ();
if (item->GetId() == itemId)
{
if (itemMenu)
*itemMenu = (wxMenu *) this;
return item;
}
if (item->GetSubMenu())
{
wxMenuItem *ans = item->GetSubMenu()->FindItemForId (itemId, itemMenu);
if (ans)
return ans;
}
}
if (itemMenu)
*itemMenu = NULL;
return NULL;
}
void wxMenu::SetHelpString(int itemId, const wxString& helpString)
{
wxMenuItem *item = FindItemForId (itemId);
if (item)
item->SetHelp(helpString);
}
wxString wxMenu::GetHelpString (int itemId) const
{
wxMenuItem *item = FindItemForId (itemId);
wxString str("");
return (item == NULL) ? str : item->GetHelp();
}
void wxMenu::ProcessCommand(wxCommandEvent & event)
{ {
bool processed = FALSE; bool processed = FALSE;
#if WXWIN_COMPATIBILITY
// Try a callback // Try a callback
if (m_callback) if (m_callback)
{ {
(void) (*(m_callback)) (*this, event); (void) (*(m_callback)) (*this, event);
processed = TRUE; processed = TRUE;
} }
#endif // WXWIN_COMPATIBILITY
// Try the menu's event handler // Try the menu's event handler
if ( !processed && GetEventHandler()) if ( !processed && GetEventHandler())
@@ -392,46 +180,8 @@ void wxMenu::ProcessCommand(wxCommandEvent & event)
// through the hierarchy) // through the hierarchy)
if ( !processed && GetInvokingWindow()) if ( !processed && GetInvokingWindow())
processed = GetInvokingWindow()->ProcessEvent(event); processed = GetInvokingWindow()->ProcessEvent(event);
}
// Update a menu and all submenus recursively. return processed;
// 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())
source = GetInvokingWindow()->GetEventHandler();
if (!source)
source = GetEventHandler();
if (!source)
source = this;
wxNode* node = GetItems().First();
while (node)
{
wxMenuItem* item = (wxMenuItem*) node->Data();
if ( !item->IsSeparator() )
{
wxWindowID id = item->GetId();
wxUpdateUIEvent event(id);
event.SetEventObject( source );
if (source->ProcessEvent(event))
{
if (event.GetSetText())
SetLabel(id, event.GetText());
if (event.GetSetChecked())
Check(id, event.GetChecked());
if (event.GetSetEnabled())
Enable(id, event.GetEnabled());
}
if (item->GetSubMenu())
item->GetSubMenu()->UpdateUI(source);
}
node = node->Next();
}
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -596,7 +346,7 @@ wxMenuItem *wxMenuBar::FindItem(int id, wxMenu ** itemMenu) const
wxMenuItem *item = NULL; wxMenuItem *item = NULL;
size_t menuCount = GetMenuCount(); size_t menuCount = GetMenuCount();
for (size_t i = 0; i < menuCount; i++) for (size_t i = 0; i < menuCount; i++)
if ((item = m_menus[i]->FindItemForId (id, itemMenu))) if ((item = m_menus[i]->FindItem(id, itemMenu)))
return item; return item;
return NULL; return NULL;
} }
@@ -691,16 +441,31 @@ int PostDeletionOfMenu( XtPointer* clientData )
XtRemoveWorkProc(WorkProcMenuId); XtRemoveWorkProc(WorkProcMenuId);
wxMenu *menu = (wxMenu *)clientData; wxMenu *menu = (wxMenu *)clientData;
if (menu->GetMainWidget()) { if (menu->GetMainWidget())
if (menu->GetParent())
{ {
wxList& list = menu->GetParent()->GetItems(); wxMenu *menuParent = menu->GetParent();
list.DeleteObject(menu); if ( menuParent )
{
wxMenuItemList::Node *node = menuParent->GetMenuItems().GetFirst();
while ( node )
{
if ( node->GetData()->GetSubMenu() == menu )
{
menuParent->GetMenuItems().DeleteNode(node);
break;
} }
node = node->GetNext();
}
}
menu->DestroyMenu(TRUE); menu->DestroyMenu(TRUE);
} }
/* Mark as no longer popped up */
// Mark as no longer popped up
menu->m_menuId = -1; menu->m_menuId = -1;
return TRUE; return TRUE;
} }
@@ -774,9 +539,12 @@ WXWidget wxMenu::CreateMenu (wxMenuBar * menuBar, WXWidget parent, wxMenu * topM
m_menuBar = menuBar; m_menuBar = menuBar;
m_topLevelMenu = topMenu; m_topLevelMenu = topMenu;
for (wxNode * node = m_menuItems.First (); node; node = node->Next ()) for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst();
node;
node = node->GetNext() )
{ {
wxMenuItem *item = (wxMenuItem *) node->Data (); wxMenuItem *item = node->GetData();
item->CreateItem(menu, menuBar, topMenu); item->CreateItem(menu, menuBar, topMenu);
} }
@@ -792,13 +560,15 @@ WXWidget wxMenu::CreateMenu (wxMenuBar * menuBar, WXWidget parent, wxMenu * topM
// do a CreateMenu again. // do a CreateMenu again.
void wxMenu::DestroyMenu (bool full) void wxMenu::DestroyMenu (bool full)
{ {
for (wxNode * node = m_menuItems.First (); node; node = node->Next ()) for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst();
node;
node = node->GetNext() )
{ {
wxMenuItem *item = (wxMenuItem *) node->Data (); wxMenuItem *item = node->GetData();
item->SetMenuBar((wxMenuBar*) NULL); item->SetMenuBar((wxMenuBar*) NULL);
item->DestroyItem(full); item->DestroyItem(full);
}// for() }
if (m_buttonWidget) if (m_buttonWidget)
{ {
@@ -825,9 +595,11 @@ WXWidget wxMenu::FindMenuItem (int id, wxMenuItem ** it) const
return m_buttonWidget; return m_buttonWidget;
} }
for (wxNode * node = m_menuItems.First (); node; node = node->Next ()) for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst();
node;
node = node->GetNext() )
{ {
wxMenuItem *item = (wxMenuItem *) node->Data (); wxMenuItem *item = node->GetData ();
if (item->GetId() == id) if (item->GetId() == id)
{ {
if (it) if (it)
@@ -843,7 +615,7 @@ WXWidget wxMenu::FindMenuItem (int id, wxMenuItem ** it) const
return w; return w;
} }
} }
}// for() }
if (it) if (it)
*it = (wxMenuItem*) NULL; *it = (wxMenuItem*) NULL;
@@ -858,10 +630,11 @@ void wxMenu::SetBackgroundColour(const wxColour& col)
if (m_buttonWidget) if (m_buttonWidget)
wxDoChangeBackgroundColour(m_buttonWidget, (wxColour&) col, TRUE); wxDoChangeBackgroundColour(m_buttonWidget, (wxColour&) col, TRUE);
wxNode* node = m_menuItems.First(); for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst();
while (node) node;
node = node->GetNext() )
{ {
wxMenuItem* item = (wxMenuItem*) node->Data(); wxMenuItem* item = node->GetData();
if (item->GetButtonWidget()) if (item->GetButtonWidget())
{ {
// This crashes because it uses gadgets // This crashes because it uses gadgets
@@ -869,7 +642,6 @@ void wxMenu::SetBackgroundColour(const wxColour& col)
} }
if (item->GetSubMenu()) if (item->GetSubMenu())
item->GetSubMenu()->SetBackgroundColour((wxColour&) col); item->GetSubMenu()->SetBackgroundColour((wxColour&) col);
node = node->Next();
} }
} }
@@ -881,10 +653,11 @@ void wxMenu::SetForegroundColour(const wxColour& col)
if (m_buttonWidget) if (m_buttonWidget)
wxDoChangeForegroundColour(m_buttonWidget, (wxColour&) col); wxDoChangeForegroundColour(m_buttonWidget, (wxColour&) col);
wxNode* node = m_menuItems.First(); for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst();
while (node) node;
node = node->GetNext() )
{ {
wxMenuItem* item = (wxMenuItem*) node->Data(); wxMenuItem* item = node->GetData();
if (item->GetButtonWidget()) if (item->GetButtonWidget())
{ {
// This crashes because it uses gadgets // This crashes because it uses gadgets
@@ -892,7 +665,6 @@ void wxMenu::SetForegroundColour(const wxColour& col)
} }
if (item->GetSubMenu()) if (item->GetSubMenu())
item->GetSubMenu()->SetForegroundColour((wxColour&) col); item->GetSubMenu()->SetForegroundColour((wxColour&) col);
node = node->Next();
} }
} }
@@ -914,10 +686,12 @@ void wxMenu::ChangeFont(bool keepOriginalSize)
XmNfontList, fontList, XmNfontList, fontList,
NULL); NULL);
} }
wxNode* node = m_menuItems.First();
while (node) for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst();
node;
node = node->GetNext() )
{ {
wxMenuItem* item = (wxMenuItem*) node->Data(); wxMenuItem* item = node->GetData();
if (m_menuWidget && item->GetButtonWidget() && m_font.Ok()) if (m_menuWidget && item->GetButtonWidget() && m_font.Ok())
{ {
XtVaSetValues ((Widget) item->GetButtonWidget(), XtVaSetValues ((Widget) item->GetButtonWidget(),
@@ -926,7 +700,6 @@ void wxMenu::ChangeFont(bool keepOriginalSize)
} }
if (item->GetSubMenu()) if (item->GetSubMenu())
item->GetSubMenu()->ChangeFont(keepOriginalSize); item->GetSubMenu()->ChangeFont(keepOriginalSize);
node = node->Next();
} }
#endif #endif
} }

View File

@@ -150,7 +150,29 @@ void wxMenuItem::Check(bool bDoCheck)
} }
} }
//// Motif-specific wxString wxMenuItem::GetLabel() const
{
return wxStripMenuCodes(m_text);
}
// ----------------------------------------------------------------------------
// wxMenuItemBase
// ----------------------------------------------------------------------------
wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu,
int id,
const wxString& name,
const wxString& help,
bool isCheckable,
wxMenu *subMenu)
{
return new wxMenuItem(parentMenu, id, name, help, isCheckable, subMenu);
}
// ----------------------------------------------------------------------------
// Motif-specific
// ----------------------------------------------------------------------------
void wxMenuItem::CreateItem (WXWidget menu, wxMenuBar * menuBar, wxMenu * topMenu) void wxMenuItem::CreateItem (WXWidget menu, wxMenuBar * menuBar, wxMenu * topMenu)
{ {

View File

@@ -1657,7 +1657,7 @@ bool wxWindow::ProcessAccelerator(wxKeyEvent& event)
// Try for a menu command // Try for a menu command
if (frame->GetMenuBar()) if (frame->GetMenuBar())
{ {
wxMenuItem* item = frame->GetMenuBar()->FindItemForId(entry->GetCommand()); wxMenuItem* item = frame->GetMenuBar()->FindItem(entry->GetCommand());
if (item) if (item)
{ {
wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, entry->GetCommand()); wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, entry->GetCommand());