X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cb43b372fb1567caf7ccfa523aca10c676ceaec4..7aaacad553facca12ab17c2f2426c21a6f576345:/samples/toolbar/test.cpp diff --git a/samples/toolbar/test.cpp b/samples/toolbar/test.cpp index 07ebd62085..3385bb3e37 100644 --- a/samples/toolbar/test.cpp +++ b/samples/toolbar/test.cpp @@ -21,9 +21,11 @@ #endif #include "wx/toolbar.h" +#include + #include "test.h" -#ifdef __WXGTK__ +#if defined(__WXGTK__) || defined(__WXMOTIF__) #include "mondrian.xpm" #include "bitmaps/new.xpm" #include "bitmaps/open.xpm" @@ -38,7 +40,6 @@ IMPLEMENT_APP(MyApp) - // The `main program' equivalent, creating the windows and returning the // main frame bool MyApp::OnInit(void) @@ -51,20 +52,16 @@ bool MyApp::OnInit(void) frame->CreateStatusBar(); // Give it an icon -#ifdef __WXMSW__ - frame->SetIcon(wxIcon("mondrian")); -#else - frame->SetIcon( wxIcon(mondrian_xpm) ); -#endif + frame->SetIcon(wxICON(mondrian)); // Make a menubar wxMenu *fileMenu = new wxMenu; - fileMenu->Append(wxID_EXIT, "E&xit"); + fileMenu->Append(wxID_EXIT, "E&xit", "Quit toolbar sample" ); wxMenu *helpMenu = new wxMenu; - helpMenu->Append(wxID_HELP, "&About"); + helpMenu->Append(wxID_HELP, "&About", "About toolbar sample"); - wxMenuBar* menuBar = new wxMenuBar; + wxMenuBar* menuBar = new wxMenuBar( wxMB_DOCKABLE ); menuBar->Append(fileMenu, "&File"); menuBar->Append(helpMenu, "&Help"); @@ -73,7 +70,9 @@ bool MyApp::OnInit(void) frame->SetMenuBar(menuBar); // Create the toolbar - frame->CreateToolBar(wxNO_BORDER|wxHORIZONTAL|wxTB_FLAT, ID_TOOLBAR); + frame->CreateToolBar(wxNO_BORDER|wxTB_HORIZONTAL|wxTB_FLAT|wxTB_DOCKABLE, ID_TOOLBAR); + + frame->GetToolBar()->SetMargins( 2, 2 ); InitToolbar(frame->GetToolBar()); @@ -92,8 +91,6 @@ bool MyApp::OnInit(void) bool MyApp::InitToolbar(wxToolBar* toolBar) { - toolBar->SetMargins(5, 5); - // Set up toolbar wxBitmap* toolBarBitmaps[8]; @@ -125,24 +122,26 @@ bool MyApp::InitToolbar(wxToolBar* toolBar) #endif int currentX = 5; - toolBar->AddTool(wxID_NEW, *(toolBarBitmaps[0]), wxNullBitmap, FALSE, (float)currentX, -1, (wxObject *) NULL, "New file"); + toolBar->AddTool(wxID_NEW, *(toolBarBitmaps[0]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "New file"); currentX += width + 5; - toolBar->AddTool(wxID_OPEN, *(toolBarBitmaps[1]), wxNullBitmap, FALSE, (float)currentX, -1, (wxObject *) NULL, "Open file"); + toolBar->AddTool(wxID_OPEN, *(toolBarBitmaps[1]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Open file"); currentX += width + 5; - toolBar->AddTool(wxID_SAVE, *(toolBarBitmaps[2]), wxNullBitmap, FALSE, (float)currentX, -1, (wxObject *) NULL, "Save file"); + toolBar->AddTool(wxID_SAVE, *(toolBarBitmaps[2]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Save file"); currentX += width + 5; toolBar->AddSeparator(); - toolBar->AddTool(wxID_COPY, *(toolBarBitmaps[3]), wxNullBitmap, FALSE, (float)currentX, -1, (wxObject *) NULL, "Copy"); + toolBar->AddTool(wxID_COPY, *(toolBarBitmaps[3]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Disable/Enable print button"); currentX += width + 5; - toolBar->AddTool(wxID_CUT, *(toolBarBitmaps[4]), wxNullBitmap, FALSE, (float)currentX, -1, (wxObject *) NULL, "Cut"); + toolBar->AddTool(wxID_CUT, *(toolBarBitmaps[4]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Toggle/Untoggle help button"); currentX += width + 5; - toolBar->AddTool(wxID_PASTE, *(toolBarBitmaps[5]), wxNullBitmap, FALSE, (float)currentX, -1, (wxObject *) NULL, "Paste"); + toolBar->AddTool(wxID_PASTE, *(toolBarBitmaps[5]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Paste"); currentX += width + 5; toolBar->AddSeparator(); - toolBar->AddTool(wxID_PRINT, *(toolBarBitmaps[6]), wxNullBitmap, FALSE, (float)currentX, -1, (wxObject *) NULL, "Print"); + toolBar->AddTool(wxID_PRINT, *(toolBarBitmaps[6]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Print"); currentX += width + 5; toolBar->AddSeparator(); - toolBar->AddTool(wxID_HELP, *(toolBarBitmaps[7]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Help"); + toolBar->AddTool(wxID_HELP, *(toolBarBitmaps[7]), *(toolBarBitmaps[6]), TRUE, currentX, -1, (wxObject *) NULL, "Help"); + + toolBar->EnableTool( wxID_PRINT, FALSE ); toolBar->Realize(); @@ -160,7 +159,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(wxID_EXIT, MyFrame::OnQuit) EVT_MENU(wxID_HELP, MyFrame::OnAbout) EVT_CLOSE(MyFrame::OnCloseWindow) - EVT_TOOL_RANGE(wxID_OPEN, wxID_PASTE, MyFrame::OnToolLeftClick) + EVT_MENU(-1, MyFrame::OnToolLeftClick) EVT_TOOL_ENTER(ID_TOOLBAR, MyFrame::OnToolEnter) END_EVENT_TABLE() @@ -169,7 +168,7 @@ MyFrame::MyFrame(wxFrame* parent, wxWindowID id, const wxString& title, const wx const wxSize& size, long style): wxFrame(parent, id, title, pos, size, style) { - m_textWindow = new wxTextCtrl(this, -1, "", wxPoint(0, 0), wxSize(-1, -1), wxTE_MULTILINE); + m_textWindow = new wxTextCtrl(this, -1, "", wxPoint(0, 0), wxSize(-1, -1), wxTE_MULTILINE); } void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) @@ -179,21 +178,44 @@ void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) { - (void)wxMessageBox("wxWindows wxToolBar demo\n", "About wxToolBar"); + (void)wxMessageBox("wxWindows toolbar sample", "About wxToolBar"); } // Define the behaviour for the frame closing // - must delete all frames except for the main one. void MyFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) { - Destroy(); + Destroy(); } void MyFrame::OnToolLeftClick(wxCommandEvent& event) { - wxString str; - str.Printf("Clicked on tool %d", event.GetId()); - SetStatusText(str); + 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()) + m_textWindow->WriteText( _T("Help button down now.\n") ); + else + m_textWindow->WriteText( _T("Help button up now.\n") ); + } + + if (event.GetId() == wxID_COPY) + { + wxToolBar *tb = GetToolBar(); + if (tb->GetToolEnabled(wxID_PRINT)) + tb->EnableTool( wxID_PRINT, FALSE ); + else + tb->EnableTool( wxID_PRINT, TRUE ); + } + + if (event.GetId() == wxID_CUT) + { + wxToolBar *tb = GetToolBar(); + tb->ToggleTool( wxID_HELP, !tb->GetToolState( wxID_HELP ) ); + } } void MyFrame::OnToolEnter(wxCommandEvent& event) @@ -201,7 +223,7 @@ void MyFrame::OnToolEnter(wxCommandEvent& event) if (event.GetSelection() > -1) { wxString str; - str.Printf("This is tool number %d", event.GetSelection()); + str.Printf(_T("This is tool number %d"), event.GetSelection()); SetStatusText(str); } else