// ----------------------------------------------------------------------------
// For compilers that support precompilation, includes "wx/wx.h".
-#include <wx/wxprec.h>
+#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
- #include <wx/app.h>
- #include <wx/frame.h>
- #include <wx/menu.h>
- #include <wx/msgdlg.h>
- #include <wx/log.h>
- #include <wx/textctrl.h>
+ #include "wx/app.h"
+ #include "wx/frame.h"
+ #include "wx/menu.h"
+ #include "wx/msgdlg.h"
+ #include "wx/log.h"
+ #include "wx/textctrl.h"
+ #include "wx/textdlg.h"
#endif
#if !wxUSE_MENUS
// Define my frame constructor
MyFrame::MyFrame()
: wxFrame((wxFrame *)NULL, -1, "wxWindows menu sample",
- wxDefaultPosition, wxSize(300, 200))
+ wxDefaultPosition, wxSize(400, 250))
{
+ m_textctrl = NULL;
m_menu = NULL;
m_countDummy = 0;
m_logOld = NULL;
wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE);
m_textctrl->SetEditable(FALSE);
+
+ wxLog::SetTimestamp(NULL);
m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_textctrl));
- wxLogMessage(_T("Brief explanations: the commands or the \"Menu\" menu\n")
+ wxLogMessage(_T("Brief explanations: the commands or the \"Menu\" menu ")
_T("append/insert/delete items to/from the last menu.\n")
- _T("The commands from \"Menubar\" menu work with the\n")
- _T("menubar itself.\n")
+ _T("The commands from \"Menubar\" menu work with the ")
+ _T("menubar itself.\n\n")
_T("Right click the band below to test popup menus.\n"));
}
if ( title )
{
- title->Printf("Dummy menu &%d", ++m_countDummy);
+ title->Printf(wxT("Dummy menu &%d"), ++m_countDummy);
}
return menu;
wxMenuItemList::Node *node = menu->GetMenuItems().GetLast();
if ( !node )
{
- wxLogWarning("No last item in the last menu!");
+ wxLogWarning(wxT("No last item in the last menu!"));
return NULL;
}
if ( !GetMenuBar()->FindItem(id) )
return;
- wxString msg = wxString::Format("Menu command %d", id);
+ wxString msg = wxString::Format(wxT("Menu command %d"), id);
if ( GetMenuBar()->FindItem(id)->IsCheckable() )
{
- msg += wxString::Format(" (the item is currently %schecked)",
+ msg += wxString::Format(wxT(" (the item is currently %schecked)"),
event.IsChecked() ? "" : "not ");
}
if ( count == 2 )
{
// don't let delete the first 2 menus
- wxLogError("Can't delete any more menus");
+ wxLogError(wxT("Can't delete any more menus"));
}
else
{
wxMenuBar *mbar = GetMenuBar();
size_t count = mbar->GetMenuCount();
- wxLogMessage("The label of the last menu item is '%s'",
+ wxCHECK_RET( count, _T("no last menu?") );
+
+ wxLogMessage(wxT("The label of the last menu item is '%s'"),
mbar->GetLabelTop(count - 1).c_str());
}
wxMenuBar *mbar = GetMenuBar();
size_t count = mbar->GetMenuCount();
- mbar->SetLabelTop(count - 1, "Dummy label &0");
+ wxCHECK_RET( count, _T("no last menu?") );
+
+ wxString label = wxGetTextFromUser
+ (
+ _T("Enter new label: "),
+ _T("Change last menu text"),
+ mbar->GetLabelTop(count - 1),
+ this
+ );
+
+ if ( !label.empty() )
+ {
+ mbar->SetLabelTop(count - 1, label);
+ }
}
void MyFrame::OnDummy(wxCommandEvent& event)
{
- wxLogMessage("Dummy item #%d", event.GetId() - Menu_Dummy_First + 1);
+ wxLogMessage(wxT("Dummy item #%d"), event.GetId() - Menu_Dummy_First + 1);
}
void MyFrame::OnAppendMenuItem(wxCommandEvent& WXUNUSED(event))
size_t count = menu->GetMenuItemCount();
if ( !count )
{
- wxLogWarning("No items to delete!");
+ wxLogWarning(wxT("No items to delete!"));
}
else
{
if ( item )
{
- wxLogMessage("The label of the last menu item is '%s'",
+ wxLogMessage(wxT("The label of the last menu item is '%s'"),
item->GetLabel().c_str());
}
}
if ( item )
{
- item->SetText("Dummy menu item text");
+ wxString label = wxGetTextFromUser
+ (
+ _T("Enter new label: "),
+ _T("Change last menu item text"),
+ item->GetLabel(),
+ this
+ );
+
+ if ( !label.empty() )
+ {
+ item->SetText(label);
+ }
}
}
void MyFrame::OnSize(wxSizeEvent& event)
{
+ if ( !m_textctrl )
+ return;
+
// leave a band below for popup menu testing
wxSize size = GetClientSize();
m_textctrl->SetSize(0, 0, size.x, (3*size.y)/4);