bool ProcessCommand(wxCommandEvent& event);
- virtual void SetParent(wxEvtHandler *parent) { m_parent = parent; }
void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
wxEvtHandler *GetEventHandler() const { return m_eventHandler; }
wxMenu * m_topLevelMenu;
wxMenuBar * m_menuBar;
wxList m_menuItems;
- wxEvtHandler * m_parent;
wxEvtHandler * m_eventHandler;
wxWindow *m_pInvokingWindow;
void* m_clientData;
virtual void SetLabelTop( size_t pos, const wxString& label );
virtual wxString GetLabelTop( size_t pos ) const;
- // notifications: return FALSE to prevent the menu from being
- // appended/deleted
- virtual bool OnAppend(wxMenu *menu, const wxChar *title);
- virtual bool OnDelete(wxMenu *menu, int index);
-
// compatibility: these functions are deprecated
#ifdef WXWIN_COMPATIBILITY
void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
-// Licence: wxWindows licence
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
+// ============================================================================
+// declarations
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
// For compilers that support precompilation, includes "wx/wx.h".
-#include "wx/wxprec.h"
+#include <wx/wxprec.h>
#ifdef __BORLANDC__
-#pragma hdrstop
+ #pragma hdrstop
#endif
#ifndef WX_PRECOMP
-#include "wx/wx.h"
+ #include <wx/wx.h>
#endif
-#include "wx/toolbar.h"
+#include <wx/toolbar.h>
#include <wx/log.h>
-#include "test.h"
+// ----------------------------------------------------------------------------
+// resources
+// ----------------------------------------------------------------------------
#if defined(__WXGTK__) || defined(__WXMOTIF__)
-#include "mondrian.xpm"
-#include "bitmaps/new.xpm"
-#include "bitmaps/open.xpm"
-#include "bitmaps/save.xpm"
-#include "bitmaps/copy.xpm"
-#include "bitmaps/cut.xpm"
-// #include "bitmaps/paste.xpm"
-#include "bitmaps/print.xpm"
-#include "bitmaps/preview.xpm"
-#include "bitmaps/help.xpm"
-#endif
+ #include "mondrian.xpm"
+ #include "bitmaps/new.xpm"
+ #include "bitmaps/open.xpm"
+ #include "bitmaps/save.xpm"
+ #include "bitmaps/copy.xpm"
+ #include "bitmaps/cut.xpm"
+ // #include "bitmaps/paste.xpm"
+ #include "bitmaps/print.xpm"
+ #include "bitmaps/preview.xpm"
+ #include "bitmaps/help.xpm"
+#endif // GTK or Motif
+
+// ----------------------------------------------------------------------------
+// classes
+// ----------------------------------------------------------------------------
+
+// Define a new application
+class MyApp: public wxApp
+{
+public:
+ bool OnInit();
+ bool InitToolbar(wxToolBar* toolBar, bool smallicons = FALSE);
+};
-IMPLEMENT_APP(MyApp)
+// Define a new frame
+class MyFrame: public wxFrame
+{
+public:
+ MyFrame(wxFrame *parent,
+ wxWindowID id = -1,
+ const wxString& title = "wxToolBar Sample",
+ const wxPoint& pos = wxDefaultPosition,
+ const wxSize& size = wxDefaultSize,
+ long style = wxDEFAULT_FRAME_STYLE);
-// The `main program' equivalent, creating the windows and returning the
-// main frame
-bool MyApp::OnInit()
+ virtual ~MyFrame() { delete m_menu; }
+
+ void OnQuit(wxCommandEvent& event);
+ void OnAbout(wxCommandEvent& event);
+
+ void OnToggleToolbar(wxCommandEvent& event);
+ void OnEnablePrint(wxCommandEvent& event) { DoEnablePrint(); }
+ void OnToggleHelp(wxCommandEvent& event) { DoToggleHelp(); }
+
+ void OnAppendMenu(wxCommandEvent& event);
+ void OnDeleteMenu(wxCommandEvent& event);
+ void OnToggleMenu(wxCommandEvent& event);
+
+ void OnToolLeftClick(wxCommandEvent& event);
+ void OnToolEnter(wxCommandEvent& event);
+
+private:
+ void DoEnablePrint();
+ void DoToggleHelp();
+
+ bool m_smallToolbar;
+ wxTextCtrl* m_textWindow;
+
+ wxMenu *m_menu;
+
+ DECLARE_EVENT_TABLE()
+};
+
+// ----------------------------------------------------------------------------
+// constants
+// ----------------------------------------------------------------------------
+
+const int ID_TOOLBAR = 500;
+
+enum
{
- // Create the main frame window
- MyFrame* frame = new MyFrame((wxFrame *) NULL, -1, (const wxString) "wxToolBar Sample",
- wxPoint(100, 100), wxSize(450, 300));
+ IDM_TOOLBAR_TOGGLETOOLBAR = 200,
+ IDM_TOOLBAR_ENABLEPRINT,
+ IDM_TOOLBAR_TOGGLEHELP,
+ IDM_MENU_TOGGLE,
+ IDM_MENU_APPEND,
+ IDM_MENU_DELETE
+};
- // Give it a status line
- frame->CreateStatusBar();
+// ----------------------------------------------------------------------------
+// event tables
+// ----------------------------------------------------------------------------
- // Give it an icon
- frame->SetIcon(wxICON(mondrian));
+// Notice that wxID_HELP will be processed for the 'About' menu and the toolbar
+// help button.
- // Make a menubar
- wxMenu *tbarMenu = new wxMenu;
- tbarMenu->Append(IDM_TOOLBAR_TOGGLETOOLBAR, "&Toggle toolbar", "Change the toolbar kind");
- tbarMenu->Append(IDM_TOOLBAR_ENABLEPRINT, "&Enable print button", "");
- tbarMenu->Append(IDM_TOOLBAR_TOGGLEHELP, "Toggle &help button", "");
+BEGIN_EVENT_TABLE(MyFrame, wxFrame)
+ EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
+ EVT_MENU(wxID_HELP, MyFrame::OnAbout)
- wxMenu *fileMenu = new wxMenu;
- fileMenu->Append(wxID_EXIT, "E&xit", "Quit toolbar sample" );
+ EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBAR, MyFrame::OnToggleToolbar)
+ EVT_MENU(IDM_TOOLBAR_ENABLEPRINT, MyFrame::OnEnablePrint)
+ EVT_MENU(IDM_TOOLBAR_TOGGLEHELP, MyFrame::OnToggleHelp)
- wxMenu *helpMenu = new wxMenu;
- helpMenu->Append(wxID_HELP, "&About", "About toolbar sample");
+ EVT_MENU(IDM_MENU_TOGGLE, MyFrame::OnToggleMenu)
+ EVT_MENU(IDM_MENU_APPEND, MyFrame::OnAppendMenu)
+ EVT_MENU(IDM_MENU_DELETE, MyFrame::OnDeleteMenu)
- wxMenuBar* menuBar = new wxMenuBar( wxMB_DOCKABLE );
+ EVT_MENU(-1, MyFrame::OnToolLeftClick)
- menuBar->Append(fileMenu, "&File");
- menuBar->Append(tbarMenu, "&Toolbar");
- menuBar->Append(helpMenu, "&Help");
+ EVT_TOOL_ENTER(ID_TOOLBAR, MyFrame::OnToolEnter)
+END_EVENT_TABLE()
- // Associate the menu bar with the frame
- frame->SetMenuBar(menuBar);
+// ============================================================================
+// implementation
+// ============================================================================
- // Create the toolbar
- frame->CreateToolBar(wxNO_BORDER|wxTB_HORIZONTAL|wxTB_FLAT|wxTB_DOCKABLE, ID_TOOLBAR);
+// ----------------------------------------------------------------------------
+// MyApp
+// ----------------------------------------------------------------------------
- frame->GetToolBar()->SetMargins( 2, 2 );
+IMPLEMENT_APP(MyApp)
- InitToolbar(frame->GetToolBar());
+// The `main program' equivalent, creating the windows and returning the
+// main frame
+bool MyApp::OnInit()
+{
+ // Create the main frame window
+ MyFrame* frame = new MyFrame((wxFrame *) NULL, -1,
+ "wxToolBar Sample",
+ wxPoint(100, 100), wxSize(450, 300));
+ // VZ: what's this for??
+#if 0
// Force a resize. This should probably be replaced by a call to a wxFrame
// function that lays out default decorations and the remaining content window.
wxSizeEvent event(wxSize(-1, -1), frame->GetId());
frame->OnSize(event);
+#endif // 0
+
frame->Show(TRUE);
frame->SetStatusText("Hello, wxWindows");
currentX += width + 5;
toolBar->AddSeparator();
toolBar->AddTool(wxID_HELP, *(toolBarBitmaps[7]), *(toolBarBitmaps[6]), TRUE, currentX, -1, (wxObject *) NULL, "Help");
-
+
toolBar->EnableTool( wxID_PRINT, FALSE );
}
return TRUE;
}
-// wxID_HELP will be processed for the 'About' menu and the toolbar help button.
-
-BEGIN_EVENT_TABLE(MyFrame, wxFrame)
- EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
- EVT_MENU(wxID_HELP, MyFrame::OnAbout)
-
- EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBAR, MyFrame::OnToggleToolbar)
- EVT_MENU(IDM_TOOLBAR_ENABLEPRINT, MyFrame::OnEnablePrint)
- EVT_MENU(IDM_TOOLBAR_TOGGLEHELP, MyFrame::OnToggleHelp)
-
- EVT_MENU(-1, MyFrame::OnToolLeftClick)
- EVT_TOOL_ENTER(ID_TOOLBAR, MyFrame::OnToolEnter)
-END_EVENT_TABLE()
+// ----------------------------------------------------------------------------
+// MyFrame
+// ----------------------------------------------------------------------------
// Define my frame constructor
MyFrame::MyFrame(wxFrame* parent,
long style)
: wxFrame(parent, id, title, pos, size, style)
{
+ m_menu = NULL;
m_textWindow = new wxTextCtrl(this, -1, "", wxPoint(0, 0), wxSize(-1, -1), wxTE_MULTILINE);
m_smallToolbar = FALSE;
+
+ // Give it a status line
+ CreateStatusBar();
+
+ // Give it an icon
+ SetIcon(wxICON(mondrian));
+
+ // Make a menubar
+ wxMenu *tbarMenu = new wxMenu;
+ tbarMenu->Append(IDM_TOOLBAR_TOGGLETOOLBAR, "&Toggle toolbar", "Change the toolbar kind");
+ tbarMenu->Append(IDM_TOOLBAR_ENABLEPRINT, "&Enable print button", "");
+ tbarMenu->Append(IDM_TOOLBAR_TOGGLEHELP, "Toggle &help button", "");
+
+ wxMenu *fileMenu = new wxMenu;
+ fileMenu->Append(wxID_EXIT, "E&xit", "Quit toolbar sample" );
+
+ wxMenu *menuMenu = new wxMenu;
+ menuMenu->Append(IDM_MENU_APPEND, "&Append menu");
+ menuMenu->Append(IDM_MENU_DELETE, "&Delete menu");
+ menuMenu->Append(IDM_MENU_TOGGLE, "&Toggle menu", "", TRUE);
+
+ wxMenu *helpMenu = new wxMenu;
+ helpMenu->Append(wxID_HELP, "&About", "About toolbar sample");
+
+ wxMenuBar* menuBar = new wxMenuBar( wxMB_DOCKABLE );
+
+ menuBar->Append(fileMenu, "&File");
+ menuBar->Append(tbarMenu, "&Toolbar");
+ menuBar->Append(menuMenu, "&Menubar");
+ menuBar->Append(helpMenu, "&Help");
+
+ // Associate the menu bar with the frame
+ SetMenuBar(menuBar);
+
+ // Create the toolbar
+ wxToolBar *tbar = CreateToolBar(wxNO_BORDER | wxTB_HORIZONTAL |
+ wxTB_FLAT | wxTB_DOCKABLE,
+ ID_TOOLBAR);
+
+ tbar->SetMargins( 2, 2 );
+
+ wxGetApp().InitToolbar(tbar);
}
-void MyFrame::OnToggleToolbar(wxCommandEvent& event)
+void MyFrame::OnToggleToolbar(wxCommandEvent& WXUNUSED(event))
{
- delete GetToolBar();
+ // delete and recreate the toolbar
+ wxToolBar *tbar = GetToolBar();
+ delete tbar;
+
SetToolBar(NULL);
- CreateToolBar(wxNO_BORDER|wxTB_HORIZONTAL|wxTB_FLAT|wxTB_DOCKABLE, ID_TOOLBAR);
+ tbar = CreateToolBar(wxNO_BORDER | wxTB_HORIZONTAL |
+ wxTB_FLAT | wxTB_DOCKABLE,
+ ID_TOOLBAR);
m_smallToolbar = !m_smallToolbar;
- wxGetApp().InitToolbar(GetToolBar(), m_smallToolbar);
+ wxGetApp().InitToolbar(tbar, m_smallToolbar);
}
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
(void)wxMessageBox("wxWindows toolbar sample", "About wxToolBar");
}
+void MyFrame::OnDeleteMenu(wxCommandEvent& WXUNUSED(event))
+{
+ wxMenuBar *mbar = GetMenuBar();
+
+ size_t count = mbar->GetMenuCount();
+ if ( count == 3 )
+ {
+ // don't let delete the first 3 menus
+ wxLogError("Can't delete any more menus");
+ }
+ else
+ {
+ delete mbar->Remove(count - 1);
+ }
+}
+
+void MyFrame::OnAppendMenu(wxCommandEvent& WXUNUSED(event))
+{
+ static s_count = 0;
+
+ wxMenu *menu = new wxMenu;
+ menu->Append(0, "First item");
+ menu->AppendSeparator();
+ menu->Append(0, "Second item");
+
+ wxString title;
+ title.Printf("Dummy menu &%d", ++s_count);
+
+ GetMenuBar()->Append(menu, title);
+}
+
+void MyFrame::OnToggleMenu(wxCommandEvent& WXUNUSED(event))
+{
+ wxMenuBar *mbar = GetMenuBar();
+ if ( !m_menu )
+ {
+ // hide the menu
+ m_menu = mbar->Remove(1);
+ }
+ else
+ {
+ // restore it
+ mbar->Insert(1, m_menu, "&Toolbar");
+ m_menu = NULL;
+ }
+}
+
void MyFrame::OnToolLeftClick(wxCommandEvent& event)
{
wxString str;
str.Printf( _T("Clicked on tool %d\n"), event.GetId());
m_textWindow->WriteText( str );
-
+
if (event.GetId() == wxID_HELP)
{
- if ((bool)event.GetExtraLong())
+ if ( event.GetExtraLong() != 0 )
m_textWindow->WriteText( _T("Help button down now.\n") );
else
m_textWindow->WriteText( _T("Help button up now.\n") );
}
-
+
if (event.GetId() == wxID_COPY)
{
DoEnablePrint();
}
-
+
if (event.GetId() == wxID_CUT)
{
DoToggleHelp();
+++ /dev/null
-/////////////////////////////////////////////////////////////////////////////
-// Name: test.h
-// Purpose: wxToolBar sample
-// Author: Julian Smart
-// Modified by:
-// Created: 23/07/98
-// RCS-ID: $Id$
-// Copyright: (c) Julian Smart
-// Licence: wxWindows licence
-/////////////////////////////////////////////////////////////////////////////
-
-// Define a new application
-class MyApp: public wxApp
-{
-public:
- bool OnInit();
- bool InitToolbar(wxToolBar* toolBar, bool smallicons = FALSE);
-};
-
-// Define a new frame
-class MyFrame: public wxFrame
-{
-public:
- MyFrame(wxFrame *parent,
- wxWindowID id = -1,
- const wxString& title = "wxToolBar Sample",
- const wxPoint& pos = wxDefaultPosition,
- const wxSize& size = wxDefaultSize,
- long style = wxDEFAULT_FRAME_STYLE);
-
- void OnQuit(wxCommandEvent& event);
- void OnAbout(wxCommandEvent& event);
-
- void OnToggleToolbar(wxCommandEvent& event);
- void OnEnablePrint(wxCommandEvent& event) { DoEnablePrint(); }
- void OnToggleHelp(wxCommandEvent& event) { DoToggleHelp(); }
-
- void OnToolLeftClick(wxCommandEvent& event);
- void OnToolEnter(wxCommandEvent& event);
-
-private:
- void DoEnablePrint();
- void DoToggleHelp();
-
- bool m_smallToolbar;
- wxTextCtrl* m_textWindow;
-
- DECLARE_EVENT_TABLE()
-};
-
-// ----------------------------------------------------------------------------
-// constants
-// ----------------------------------------------------------------------------
-
-const int ID_TOOLBAR = 500;
-
-enum
-{
- IDM_TOOLBAR_TOGGLETOOLBAR = 200,
- IDM_TOOLBAR_ENABLEPRINT,
- IDM_TOOLBAR_TOGGLEHELP
-};
-# This file was automatically generated by tmake at 14:33, 1999/10/23
+# This file was automatically generated by tmake at 01:16, 1999/10/27
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE B32.T!
#
$(MSWDIR)\list.obj \
$(MSWDIR)\log.obj \
$(MSWDIR)\memory.obj \
+ $(MSWDIR)\menucmn.obj \
$(MSWDIR)\mimetype.obj \
$(MSWDIR)\module.obj \
$(MSWDIR)\mstream.obj \
$(MSWDIR)\memory.obj: $(COMMDIR)\memory.$(SRCSUFF)
+$(MSWDIR)\menucmn.obj: $(COMMDIR)\menucmn.$(SRCSUFF)
+
$(MSWDIR)\mimetype.obj: $(COMMDIR)\mimetype.$(SRCSUFF)
$(MSWDIR)\module.obj: $(COMMDIR)\module.$(SRCSUFF)
-# This file was automatically generated by tmake at 09:40, 1999/10/25
+# This file was automatically generated by tmake at 01:16, 1999/10/27
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE BCC.T!
#
$(MSWDIR)\list.obj \
$(MSWDIR)\log.obj \
$(MSWDIR)\memory.obj \
+ $(MSWDIR)\menucmn.obj \
$(MSWDIR)\module.obj \
$(MSWDIR)\mstream.obj \
$(MSWDIR)\object.obj \
$(MSWDIR)\memory.obj: $(COMMDIR)\memory.$(SRCSUFF)
+$(MSWDIR)\menucmn.obj: $(COMMDIR)\menucmn.$(SRCSUFF)
+
$(MSWDIR)\module.obj: $(COMMDIR)\module.$(SRCSUFF)
$(MSWDIR)\mstream.obj: $(COMMDIR)\mstream.$(SRCSUFF)
-# This file was automatically generated by tmake at 09:37, 1999/10/25
+# This file was automatically generated by tmake at 01:16, 1999/10/27
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE DOS.T!
#
$(COMMDIR)\list.obj \
$(COMMDIR)\log.obj \
$(COMMDIR)\memory.obj \
+ $(COMMDIR)\menucmn.obj \
$(COMMDIR)\module.obj \
$(COMMDIR)\mstream.obj \
$(COMMDIR)\object.obj \
$(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF)
<<
+$(COMMDIR)/menucmn.obj: $*.$(SRCSUFF)
+ cl @<<
+$(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF)
+<<
+
$(COMMDIR)/module.obj: $*.$(SRCSUFF)
cl @<<
$(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF)
-# This file was automatically generated by tmake at 18:37, 1999/10/22
+# This file was automatically generated by tmake at 01:16, 1999/10/27
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE G95.T!
#
$(COMMDIR)/list.$(OBJSUFF) \
$(COMMDIR)/log.$(OBJSUFF) \
$(COMMDIR)/memory.$(OBJSUFF) \
+ $(COMMDIR)/menucmn.$(OBJSUFF) \
$(COMMDIR)/mimetype.$(OBJSUFF) \
$(COMMDIR)/module.$(OBJSUFF) \
$(COMMDIR)/mstream.$(OBJSUFF) \
-# This file was automatically generated by tmake at 09:21, 1999/10/25
+# This file was automatically generated by tmake at 01:16, 1999/10/27
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE SC.T!
# Symantec C++ makefile for the msw objects
$(COMMDIR)\list.obj \
$(COMMDIR)\log.obj \
$(COMMDIR)\memory.obj \
+ $(COMMDIR)\menucmn.obj \
$(COMMDIR)\mimetype.obj \
$(COMMDIR)\module.obj \
$(COMMDIR)\mstream.obj \
-# This file was automatically generated by tmake at 18:37, 1999/10/22
+# This file was automatically generated by tmake at 01:16, 1999/10/27
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE VC.T!
# File: makefile.vc
..\common\$D\list.obj \
..\common\$D\log.obj \
..\common\$D\memory.obj \
+ ..\common\$D\menucmn.obj \
..\common\$D\mimetype.obj \
..\common\$D\module.obj \
..\common\$D\mstream.obj \
#!/binb/wmake.exe
-# This file was automatically generated by tmake at 09:14, 1999/10/25
+# This file was automatically generated by tmake at 01:16, 1999/10/27
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE WAT.T!
#
list.obj &
log.obj &
memory.obj &
+ menucmn.obj &
mimetype.obj &
module.obj &
mstream.obj &
memory.obj: $(COMMDIR)\memory.cpp
*$(CCC) $(CPPFLAGS) $(IFLAGS) $<
+menucmn.obj: $(COMMDIR)\menucmn.cpp
+ *$(CCC) $(CPPFLAGS) $(IFLAGS) $<
+
mimetype.obj: $(COMMDIR)\mimetype.cpp
*$(CCC) $(CPPFLAGS) $(IFLAGS) $<
void wxMenu::Init(const wxString& title, const wxFunction func )
{
m_title = title;
- m_parent = NULL;
m_eventHandler = this;
m_pInvokingWindow = NULL;
- m_doBreak = FALSE ;
+ m_doBreak = FALSE;
m_noItems = 0;
m_menuBar = NULL;
m_hMenu = (WXHMENU) CreatePopupMenu();
- m_savehMenu = 0 ;
+ m_savehMenu = 0;
m_topLevelMenu = this;
m_clientData = (void*) NULL;
if ( !!m_title )
{
- Append(idMenuTitle, m_title) ;
- AppendSeparator() ;
+ Append(idMenuTitle, m_title);
+ AppendSeparator();
}
Callback(func);
// free Windows resources
if ( m_hMenu )
{
- ::DestroyMenu((HMENU)m_hMenu);
- m_hMenu = 0;
+ if ( !::DestroyMenu(GetHmenu()) )
+ {
+ wxLogLastError("DestroyMenu");
+ }
}
// delete submenus
delete node;
node = next;
}
+
+#if wxUSE_ACCEL
+ // delete accels
+ WX_CLEAR_ARRAY(m_accels);
+#endif // wxUSE_ACCEL
}
void wxMenu::Break()
id = (UINT)submenu->GetHMenu();
submenu->m_topLevelMenu = m_topLevelMenu;
- submenu->m_parent = this;
submenu->m_savehMenu = (WXHMENU)id;
submenu->m_hMenu = 0;
RemoveMenu(menu, (UINT)pos, MF_BYPOSITION);
pSubMenu->m_hMenu = pSubMenu->m_savehMenu;
pSubMenu->m_savehMenu = 0;
- pSubMenu->m_parent = NULL;
// RemoveChild(item->subMenu);
pSubMenu->m_topLevelMenu = NULL;
// TODO: Why isn't subMenu deleted here???
void wxMenu::SetLabel(int id, const wxString& label)
{
- wxMenuItem *item = FindItemForId(id) ;
+ wxMenuItem *item = FindItemForId(id);
wxCHECK_RET( item, wxT("wxMenu::SetLabel: no such item") );
item->SetText(label);
wxString wxMenu::GetLabel(int id) const
{
wxString label;
- wxMenuItem *pItem = FindItemForId(id) ;
+ wxMenuItem *pItem = FindItemForId(id);
if (pItem)
- label = pItem->GetText() ;
+ label = pItem->GetText();
else
wxFAIL_MSG(wxT("wxMenu::GetLabel: item doesn't exist"));
{
wxASSERT_MSG( m_menuBar, wxT("can't detach menu if it's not attached") );
+ m_menuBar = NULL;
m_hMenu = m_savehMenu;
m_savehMenu = 0;
}
void wxMenuBar::Init()
{
m_eventHandler = this;
- m_titles = NULL;
m_menuBarFrame = NULL;
m_hMenu = 0;
}
void wxMenuBar::Refresh()
{
- wxCHECK_RET( m_menuBarFrame, wxT("can't refresh a menubar withotu a frame") );
+ wxCHECK_RET( IsAttached(), wxT("can't refresh unatteched menubar") );
- DrawMenuBar((HWND)m_menuBarFrame->GetHWND()) ;
+ DrawMenuBar(GetHwndOf(m_menuBarFrame));
}
WXHMENU wxMenuBar::Create()
if ( flagsOld & MF_POPUP )
{
// HIBYTE contains the number of items in the submenu in this case
- flagsOld &= 0xff ;
- id = (UINT)::GetSubMenu((HMENU)m_hMenu, pos) ;
+ flagsOld &= 0xff;
+ id = (UINT)::GetSubMenu((HMENU)m_hMenu, pos);
}
else
{
return label;
}
-// ---------------------------------------------------------------------------
-// wxMenuBar notifications
-// ---------------------------------------------------------------------------
-
-bool wxMenuBar::OnDelete(wxMenu *a_menu, int pos)
-{
- if ( !m_menuBarFrame )
- return TRUE;
-
- if ( ::RemoveMenu((HMENU)m_hMenu, (UINT)pos, MF_BYPOSITION) )
- {
- // VZ: I'm not sure about what's going on here, so I leave an assert
- wxASSERT_MSG( m_menus[pos] == a_menu, wxT("what is this parameter for??") );
-
- a_menu->Detach();
-
- if ( m_menuBarFrame )
- Refresh();
-
- return TRUE;
- }
- else
- {
- wxLogLastError("RemoveMenu");
- }
-
- return FALSE;
-}
-
-bool wxMenuBar::OnAppend(wxMenu *a_menu, const wxChar *title)
-{
- WXHMENU submenu = a_menu->GetHMenu();
- if ( !submenu )
- return FALSE;
-
- if ( !m_menuBarFrame )
- return TRUE;
-
- a_menu->Attach(this);
-
- if ( !::AppendMenu(GetHmenu(), MF_POPUP | MF_STRING,
- (UINT)submenu, title) )
- {
- wxLogLastError(wxT("AppendMenu"));
- }
-
- Refresh();
-
- return TRUE;
-}
-
-// ---------------------------------------------------------------------------
-// wxMenuBar construction
-// ---------------------------------------------------------------------------
-
int wxMenuBar::FindMenu(const wxString& title)
{
wxString menuTitle = wxStripMenuCodes(title);
}
+// ---------------------------------------------------------------------------
+// wxMenuBar construction
+// ---------------------------------------------------------------------------
+
wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
{
- if ( m_menuBarFrame )
- {
- wxFAIL_MSG(wxT("not implemented"));
+ wxMenu *menuOld = wxMenuBarBase::Replace(pos, menu, title);
+ if ( !menuOld )
+ return FALSE;
+ m_titles[pos] = title;
- return NULL;
- }
- else
+ if ( IsAttached() )
{
- wxMenu *menuOld = wxMenuBarBase::Replace(pos, menu, title);
- if ( menuOld )
+ // can't use ModifyMenu() because it deletes the submenu it replaces
+ if ( !::RemoveMenu(GetHmenu(), (UINT)pos, MF_BYPOSITION) )
{
- m_titles[pos] = title;
+ wxLogLastError("RemoveMenu");
}
- return menuOld;
+ if ( !::InsertMenu(GetHmenu(), (UINT)pos,
+ MF_BYPOSITION | MF_POPUP | MF_STRING,
+ (UINT)GetHmenuOf(menu), title) )
+ {
+ wxLogLastError("InsertMenu");
+ }
+
+ Refresh();
}
+
+ return menuOld;
}
bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
{
- if ( m_menuBarFrame )
- {
- wxFAIL_MSG(wxT("not implemented"));
-
+ if ( !wxMenuBarBase::Insert(pos, menu, title) )
return FALSE;
- }
- else
- {
- if ( !wxMenuBarBase::Insert(pos, menu, title) )
- return FALSE;
- m_titles.Insert(title, pos);
+ m_titles.Insert(title, pos);
+
+ menu->Attach(this);
- return TRUE;
+ if ( IsAttached() )
+ {
+ if ( !::InsertMenu(GetHmenu(), pos,
+ MF_BYPOSITION | MF_POPUP | MF_STRING,
+ (UINT)GetHmenuOf(menu), title) )
+ {
+ wxLogLastError("InsertMenu");
+ }
+
+ Refresh();
}
+
+ return TRUE;
}
-bool wxMenuBar::Append(wxMenu * menu, const wxString& title)
+bool wxMenuBar::Append(wxMenu *menu, const wxString& title)
{
- if ( !wxMenuBarBase::Append(menu, title) )
- return FALSE;
+ WXHMENU submenu = menu ? menu->GetHMenu() : 0;
+ wxCHECK_MSG( submenu, FALSE, wxT("can't append invalid menu to menubar") );
- // menu is already appended, ignore errors
- (void)OnAppend(menu, title);
+ menu->Attach(this);
- m_titles.Add(title);
+ if ( IsAttached() )
+ {
+ if ( !::AppendMenu(GetHmenu(), MF_POPUP | MF_STRING,
+ (UINT)submenu, title) )
+ {
+ wxLogLastError(wxT("AppendMenu"));
+ }
+
+ Refresh();
+ }
- menu->SetParent(this);
+ wxMenuBarBase::Append(menu, title);
+
+ m_titles.Add(title);
return TRUE;
}
if ( !menu )
return NULL;
- menu->SetParent(NULL);
+ if ( IsAttached() )
+ {
+ if ( !::RemoveMenu(GetHmenu(), (UINT)pos, MF_BYPOSITION) )
+ {
+ wxLogLastError("RemoveMenu");
+ }
- // the menu is deleted from the list anyhow, so we have to ignore all
- // possible errors here
- (void)OnDelete(menu, pos);
+ menu->Detach();
+
+ Refresh();
+ }
m_titles.Remove(pos);
void wxMenuBar::Attach(wxFrame *frame)
{
- wxASSERT_MSG( !m_menuBarFrame, wxT("menubar already attached!") );
+ wxASSERT_MSG( !IsAttached(), wxT("menubar already attached!") );
m_menuBarFrame = frame;
// and now it has the data
wxDragResult rc = ConvertDragEffectToResult(GetDropEffect(grfKeyState));
- m_pTarget->OnData(pt.x, pt.y);//, rc);
-/*
+ m_pTarget->OnData(pt.x, pt.y, rc);
if ( wxIsDragResultOk(rc) ) {
// operation succeeded
*pdwEffect = ConvertDragResultToEffect(rc);
}
-*/
-
//else: *pdwEffect is already DROPEFFECT_NONE
}
//else: OnDrop() returned FALSE, no need to copy data