X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/33c9645172ef847710ac4c04e3160a93e692087a..f96012e7da821a35d5bb4fd248de08a5f5050891:/samples/ownerdrw/ownerdrw.cpp?ds=sidebyside diff --git a/samples/ownerdrw/ownerdrw.cpp b/samples/ownerdrw/ownerdrw.cpp index d50f6207fe..cfaadcc756 100644 --- a/samples/ownerdrw/ownerdrw.cpp +++ b/samples/ownerdrw/ownerdrw.cpp @@ -26,7 +26,7 @@ #include "wx/ownerdrw.h" #include "wx/menuitem.h" -#include "wx/msw/checklst.h" +#include "wx/checklst.h" // Define a new application type class OwnerDrawnApp: public wxApp @@ -50,7 +50,7 @@ public: void OnListboxSelect (wxCommandEvent& event); void OnCheckboxToggle (wxCommandEvent& event); void OnListboxDblClick (wxCommandEvent& event); - bool OnClose () { return TRUE; } + bool OnClose () { return true; } DECLARE_EVENT_TABLE() @@ -89,32 +89,37 @@ IMPLEMENT_APP(OwnerDrawnApp); bool OwnerDrawnApp::OnInit(void) { OwnerDrawnFrame *pFrame - = new OwnerDrawnFrame(NULL, _T("wxWindows Ownerdraw Sample"), + = new OwnerDrawnFrame(NULL, _T("wxWidgets Ownerdraw Sample"), 50, 50, 450, 340); SetTopWindow(pFrame); - return TRUE; + return true; } // create the menu bar for the main frame void OwnerDrawnFrame::InitMenu() { // Make a menubar - wxMenu *file_menu = new wxMenu, - *sub_menu = new wxMenu; + wxMenuItem *pItem; + wxMenu *file_menu = new wxMenu; + +#ifndef __WXUNIVERSAL__ + wxMenu *sub_menu = new wxMenu; // vars used for menu construction - wxMenuItem *pItem; - wxFont fontLarge(18, wxROMAN, wxNORMAL, wxBOLD, FALSE), - fontUlined(12, wxDEFAULT, wxNORMAL, wxNORMAL, TRUE), - fontItalic(12, wxMODERN, wxITALIC, wxBOLD, FALSE), + wxFont fontLarge(18, wxROMAN, wxNORMAL, wxBOLD, false), + fontUlined(12, wxDEFAULT, wxNORMAL, wxNORMAL, true), + fontItalic(12, wxMODERN, wxITALIC, wxBOLD, false), // should be at least of the size of bitmaps - fontBmp(14, wxDEFAULT, wxNORMAL, wxNORMAL, FALSE); + fontBmp(14, wxDEFAULT, wxNORMAL, wxNORMAL, false); // sorry for my artistic skills... - wxBitmap bmpBell(_T("bell")), bmpSound(_T("sound")), bmpNoSound(_T("nosound")); - wxBitmap bmpInfo(_T("info")), bmpInfo_mono(_T("info_mono")); + 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")); @@ -136,19 +141,18 @@ 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"), _T("checkable item"), wxITEM_CHECK); pItem->SetFont(*wxSMALL_FONT); file_menu->Append(pItem); - file_menu->Check(Menu_Test2, TRUE); + file_menu->Check(Menu_Test2, true); pItem = new wxMenuItem(file_menu, Menu_Test3, _T("&Disabled"), _T("disabled item")); pItem->SetFont(*wxNORMAL_FONT); file_menu->Append(pItem); - file_menu->Enable(Menu_Test3, FALSE); + file_menu->Enable(Menu_Test3, false); file_menu->AppendSeparator(); @@ -182,13 +186,13 @@ void OwnerDrawnFrame::InitMenu() _T("display program information"), wxITEM_NORMAL); pAboutItem->SetBitmap(bmpInfo); pAboutItem->SetDisabledBitmap(bmpInfo_mono); - pAboutItem->SetOwnerDrawn(TRUE); file_menu->Append(pAboutItem); file_menu->AppendSeparator(); +#endif + 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; @@ -200,7 +204,7 @@ void OwnerDrawnFrame::InitMenu() // main frame constructor OwnerDrawnFrame::OwnerDrawnFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h) - : wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h)) + : wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h)) { // set the icon SetIcon(wxIcon(_T("mondrian"))); @@ -208,15 +212,16 @@ OwnerDrawnFrame::OwnerDrawnFrame(wxFrame *frame, wxChar *title, // create the menu InitMenu(); +#if wxUSE_STATUSBAR // create the status line const int widths[] = { -1, 60 }; CreateStatusBar(2); SetStatusWidths(2, widths); SetStatusText(_T("no selection"), 0); +#endif // wxUSE_STATUSBAR // 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"), @@ -242,7 +247,9 @@ OwnerDrawnFrame::OwnerDrawnFrame(wxFrame *frame, wxChar *title, for ( ui = 0; ui < WXSIZEOF(aszChoices); ui += 2 ) { +#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__) m_pListBox->GetItem(ui)->SetBackgroundColour(wxColor(200, 200, 200)); +#endif } m_pListBox->Check(2); @@ -251,12 +258,6 @@ OwnerDrawnFrame::OwnerDrawnFrame(wxFrame *frame, wxChar *title, static const wxChar* aszColors[] = { _T("Red"), _T("Blue"), _T("Pink"), _T("Green"), _T("Yellow"), _T("Black"), _T("Violet") }; - struct { unsigned int r, g, b; } aColors[] = - { - {255,0,0}, {0,0,255}, {255,128,192}, - {0,255,0}, {255,255,128}, - {0,0,0}, {128,0,255} - }; astrChoices = new wxString[WXSIZEOF(aszColors)]; @@ -270,14 +271,21 @@ 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 ); +#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__) + + struct { unsigned int r, g, b; } aColors[] = + { + {255,0,0}, {0,0,255}, {255,128,192}, + {0,255,0}, {255,255,128}, + {0,0,0}, {128,0,255} + }; + for ( ui = 0; ui < WXSIZEOF(aszColors); ui++ ) { pListBox->GetItem(ui)->SetTextColour(wxColor(aColors[ui].r, @@ -288,12 +296,15 @@ OwnerDrawnFrame::OwnerDrawnFrame(wxFrame *frame, wxChar *title, { pListBox->GetItem(ui)->SetBackgroundColour(wxColor(0, 0, 0)); } - } +#else + wxUnusedVar( pListBox ); +#endif + delete[] astrChoices; - Show(TRUE); + Show(true); } OwnerDrawnFrame::~OwnerDrawnFrame() @@ -302,7 +313,7 @@ OwnerDrawnFrame::~OwnerDrawnFrame() void OwnerDrawnFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) { - Close(TRUE); + Close(true); } void OwnerDrawnFrame::OnMenuToggle(wxCommandEvent& WXUNUSED(event)) @@ -310,7 +321,7 @@ 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 ); + pAboutItem->Enable( pAboutItem->IsEnabled() ? false : true ); } void OwnerDrawnFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) @@ -323,11 +334,15 @@ void OwnerDrawnFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) void OwnerDrawnFrame::OnListboxSelect(wxCommandEvent& event) { +#if wxUSE_STATUSBAR wxString strSelection; unsigned int nSel = event.GetSelection(); strSelection.Printf(wxT("item %d selected (%schecked)"), nSel, m_pListBox->IsChecked(nSel) ? wxT("") : wxT("not ")); SetStatusText(strSelection); +#else + wxUnusedVar(event); +#endif // wxUSE_STATUSBAR } void OwnerDrawnFrame::OnListboxDblClick(wxCommandEvent& WXUNUSED(event)) @@ -341,9 +356,13 @@ void OwnerDrawnFrame::OnListboxDblClick(wxCommandEvent& WXUNUSED(event)) void OwnerDrawnFrame::OnCheckboxToggle(wxCommandEvent& event) { +#if wxUSE_STATUSBAR wxString strSelection; unsigned int nItem = event.GetInt(); strSelection.Printf(wxT("item %d was %schecked"), nItem, m_pListBox->IsChecked(nItem) ? wxT("") : wxT("un")); SetStatusText(strSelection); +#else + wxUnusedVar(event); +#endif // wxUSE_STATUSBAR }