X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0a4c16d6c4c05f01a72d2a7b0db45c539045e3e0..4997d3014cd76b41f2d4036dfd168ad886972f35:/samples/ownerdrw/ownerdrw.cpp diff --git a/samples/ownerdrw/ownerdrw.cpp b/samples/ownerdrw/ownerdrw.cpp index 18c3ed7c02..79aa7c65e4 100644 --- a/samples/ownerdrw/ownerdrw.cpp +++ b/samples/ownerdrw/ownerdrw.cpp @@ -26,7 +26,6 @@ #include "wx/ownerdrw.h" #include "wx/menuitem.h" -#include "wx/image.h" #include "wx/msw/checklst.h" // Define a new application type @@ -46,6 +45,7 @@ public: // notifications void OnQuit (wxCommandEvent& event); + void OnMenuToggle (wxCommandEvent& event); void OnAbout (wxCommandEvent& event); void OnListboxSelect (wxCommandEvent& event); void OnCheckboxToggle (wxCommandEvent& event); @@ -58,6 +58,7 @@ private: void InitMenu(); wxCheckListBox *m_pListBox; + wxMenuItem *pAboutItem; }; enum @@ -67,11 +68,14 @@ enum Menu_Test1, Menu_Test2, Menu_Test3, Menu_Bitmap, Menu_Bitmap2, Menu_Submenu, Menu_Sub1, Menu_Sub2, Menu_Sub3, + Menu_Toggle, Menu_About, Control_First = 1000, Control_Listbox, Control_Listbox2, }; BEGIN_EVENT_TABLE(OwnerDrawnFrame, wxFrame) + EVT_MENU(Menu_Toggle, OwnerDrawnFrame::OnMenuToggle) + EVT_MENU(Menu_About, OwnerDrawnFrame::OnAbout) EVT_MENU(Menu_Quit, OwnerDrawnFrame::OnQuit) EVT_LISTBOX(Control_Listbox, OwnerDrawnFrame::OnListboxSelect) EVT_CHECKLISTBOX(Control_Listbox, OwnerDrawnFrame::OnCheckboxToggle) @@ -84,7 +88,6 @@ IMPLEMENT_APP(OwnerDrawnApp); // init our app: create windows bool OwnerDrawnApp::OnInit(void) { - wxInitAllImageHandlers(); OwnerDrawnFrame *pFrame = new OwnerDrawnFrame(NULL, _T("wxWindows Ownerdraw Sample"), 50, 50, 450, 340); @@ -110,9 +113,11 @@ void OwnerDrawnFrame::InitMenu() fontBmp(14, wxDEFAULT, wxNORMAL, wxNORMAL, FALSE); // sorry for my artistic skills... - wxBitmap bmpBell(_T("bell")); - wxBitmap bmpSound(_T("sound.png"), wxBITMAP_TYPE_PNG); - wxBitmap bmpNoSound(_T("nosound.png"), wxBITMAP_TYPE_PNG); + wxBitmap bmpBell(_T("bell")), + bmpSound(_T("sound")), + bmpNoSound(_T("nosound")), + bmpInfo(_T("info")), + bmpInfo_mono(_T("info_mono")); // construct submenu pItem = new wxMenuItem(sub_menu, Menu_Sub1, _T("Submenu &first"), _T("large")); @@ -134,7 +139,6 @@ void OwnerDrawnFrame::InitMenu() pItem = new wxMenuItem(file_menu, Menu_Test1, _T("&Uncheckable"), _T("red item")); pItem->SetFont(*wxITALIC_FONT); pItem->SetTextColour(wxColor(255, 0, 0)); - pItem->SetMarginWidth(23); file_menu->Append(pItem); pItem = new wxMenuItem(file_menu, Menu_Test2, _T("&Checkable"), @@ -169,10 +173,22 @@ void OwnerDrawnFrame::InitMenu() pItem->SetFont(*wxSWISS_FONT); file_menu->Append(pItem); + file_menu->AppendSeparator(); + pItem = new wxMenuItem(file_menu, Menu_Toggle, _T("&Disable/Enable\tCtrl+D"), + _T("enables/disables the About-Item"), wxITEM_NORMAL); + pItem->SetFont(*wxNORMAL_FONT); + file_menu->Append(pItem); + + // Of course Ctrl+RatherLongAccel will not work in this example: + pAboutItem = new wxMenuItem(file_menu, Menu_About, _T("&About\tCtrl+RatherLongAccel"), + _T("display program information"), wxITEM_NORMAL); + pAboutItem->SetBitmap(bmpInfo); + pAboutItem->SetDisabledBitmap(bmpInfo_mono); + file_menu->Append(pAboutItem); + file_menu->AppendSeparator(); pItem = new wxMenuItem(file_menu, Menu_Quit, _T("&Quit"), _T("Normal item"), wxITEM_NORMAL); - pItem->SetFont(*wxNORMAL_FONT); file_menu->Append(pItem); wxMenuBar *menu_bar = new wxMenuBar; @@ -199,8 +215,7 @@ OwnerDrawnFrame::OwnerDrawnFrame(wxFrame *frame, wxChar *title, SetStatusText(_T("no selection"), 0); // make a panel with some controls - wxPanel *pPanel = new wxPanel(this, -1, wxPoint(0, 0), - wxSize(400, 200), wxTAB_TRAVERSAL); + wxPanel *pPanel = new wxPanel(this); // check list box static const wxChar* aszChoices[] = { _T("Hello"), _T("world"), _T("and"), @@ -254,12 +269,10 @@ OwnerDrawnFrame::OwnerDrawnFrame(wxFrame *frame, wxChar *title, pPanel, // parent Control_Listbox2, // control id wxPoint(220, 10), // listbox position - wxDefaultSize, // listbox size - WXSIZEOF(aszColors), // number of strings + wxSize(200, 200), // listbox size + WXSIZEOF(aszColors), // number of strings astrChoices, // array of strings - wxLB_OWNERDRAW, // owner-drawn - wxDefaultValidator, // - wxListBoxNameStr + wxLB_OWNERDRAW // owner-drawn ); for ( ui = 0; ui < WXSIZEOF(aszColors); ui++ ) @@ -284,12 +297,20 @@ OwnerDrawnFrame::~OwnerDrawnFrame() { } -void OwnerDrawnFrame::OnQuit(wxCommandEvent& event) +void OwnerDrawnFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) { Close(TRUE); } -void OwnerDrawnFrame::OnAbout(wxCommandEvent& event) +void OwnerDrawnFrame::OnMenuToggle(wxCommandEvent& WXUNUSED(event)) +{ + // This example shows the use of bitmaps in ownerdrawn menuitems and is not a good + // example on how to enable and disable menuitems - this should be done with the help of + // EVT_UPDATE_UI and EVT_UPDATE_UI_RANGE ! + pAboutItem->Enable( pAboutItem->IsEnabled() ? FALSE : TRUE ); +} + +void OwnerDrawnFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) { wxMessageDialog dialog(this, _T("Demo of owner-drawn controls\n"), @@ -306,7 +327,7 @@ void OwnerDrawnFrame::OnListboxSelect(wxCommandEvent& event) SetStatusText(strSelection); } -void OwnerDrawnFrame::OnListboxDblClick(wxCommandEvent& event) +void OwnerDrawnFrame::OnListboxDblClick(wxCommandEvent& WXUNUSED(event)) { wxString strSelection; strSelection.Printf(wxT("item %d double clicked"),