From 57ec523b6f5c5ae638e4ddcfe8ea13482cd4b9d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C4=83t=C4=83lin=20R=C4=83ceanu?= Date: Mon, 31 Aug 2015 21:08:34 +0300 Subject: [PATCH 1/4] Fix "Print" tool handling in the toolbar sample Ensure that the count of the Print tools is always correct, even if more tools were inserted and then the toolbar was recreated (in a different position). --- samples/toolbar/toolbar.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/samples/toolbar/toolbar.cpp b/samples/toolbar/toolbar.cpp index ffdbdf3b92..57e6c2757e 100644 --- a/samples/toolbar/toolbar.cpp +++ b/samples/toolbar/toolbar.cpp @@ -481,6 +481,8 @@ void MyFrame::PopulateToolbar(wxToolBarBase* toolBar) wxT("Delete this tool. This is a very long tooltip to test whether it does the right thing when the tooltip is more than Windows can cope with.")); } + m_nPrint = 1; + // add a stretchable space before the "Help" button to make it // right-aligned toolBar->AddStretchableSpace(); @@ -530,7 +532,7 @@ MyFrame::MyFrame(wxFrame* parent, m_searchTool = NULL; m_rows = 1; - m_nPrint = 1; + m_nPrint = 0; // set to 1 in PopulateToolbar() #if wxUSE_STATUSBAR // Give it a status line From 826296efc3f6cbcd2a309e4143ee3c794d9c9564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C4=83t=C4=83lin=20R=C4=83ceanu?= Date: Mon, 31 Aug 2015 21:08:34 +0300 Subject: [PATCH 2/4] Make the text control in the toolbar sample read-only This text control is used only for logging messages, so don't allow modifying it. --- samples/toolbar/toolbar.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/samples/toolbar/toolbar.cpp b/samples/toolbar/toolbar.cpp index 57e6c2757e..6464a9fe41 100644 --- a/samples/toolbar/toolbar.cpp +++ b/samples/toolbar/toolbar.cpp @@ -640,7 +640,8 @@ MyFrame::MyFrame(wxFrame* parent, PopulateToolbar(m_extraToolBar); #endif - m_textWindow = new wxTextCtrl(m_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE); + // Use a read-only text control; Cut tool will not cut selected text anyway. + m_textWindow = new wxTextCtrl(m_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY); wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); m_panel->SetSizer(sizer); From 0d45559975329d03017c4f181908134bc69a7363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C4=83t=C4=83lin=20R=C4=83ceanu?= Date: Mon, 31 Aug 2015 21:08:34 +0300 Subject: [PATCH 3/4] Append log messages to the end of the text in the toolbar sample This ensures that the messages always appear in the correct order, even if the user clicked somewhere in the middle of the control -- which would previously result in inserting the next message at the cursor position, not the end. --- samples/toolbar/toolbar.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/toolbar/toolbar.cpp b/samples/toolbar/toolbar.cpp index 6464a9fe41..e9a0d04514 100644 --- a/samples/toolbar/toolbar.cpp +++ b/samples/toolbar/toolbar.cpp @@ -813,9 +813,9 @@ void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnAbout(wxCommandEvent& event) { if ( event.IsChecked() ) - m_textWindow->WriteText( wxT("Help button down now.\n") ); + m_textWindow->AppendText( wxT("Help button down now.\n") ); else - m_textWindow->WriteText( wxT("Help button up now.\n") ); + m_textWindow->AppendText( wxT("Help button up now.\n") ); (void)wxMessageBox(wxT("wxWidgets toolbar sample"), wxT("About wxToolBar")); } @@ -824,7 +824,7 @@ void MyFrame::OnToolLeftClick(wxCommandEvent& event) { wxString str; str.Printf( wxT("Clicked on tool %d\n"), event.GetId()); - m_textWindow->WriteText( str ); + m_textWindow->AppendText( str ); if (event.GetId() == wxID_COPY) { @@ -998,7 +998,7 @@ void MyFrame::OnToolDropdown(wxCommandEvent& event) { wxString str; str.Printf( wxT("Dropdown on tool %d\n"), event.GetId()); - m_textWindow->WriteText( str ); + m_textWindow->AppendText( str ); event.Skip(); } From 2e103dfe953ebd108ce208d3e46173e5f92bd774 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C4=83t=C4=83lin=20R=C4=83ceanu?= Date: Mon, 31 Aug 2015 21:08:34 +0300 Subject: [PATCH 4/4] Explain toolbar sample actions better Added messages to show that Copy tool intentionally influences Print tool and Cut tool influences Help tool, as this is rather unexpected behaviour and could be seen as a bug. --- samples/toolbar/toolbar.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/samples/toolbar/toolbar.cpp b/samples/toolbar/toolbar.cpp index e9a0d04514..3c50615e55 100644 --- a/samples/toolbar/toolbar.cpp +++ b/samples/toolbar/toolbar.cpp @@ -861,6 +861,7 @@ void MyFrame::DoEnablePrint() wxToolBarBase *tb = GetToolBar(); tb->EnableTool(wxID_PRINT, !tb->GetToolEnabled(wxID_PRINT)); + m_textWindow->AppendText("Print tool state changed.\n"); } void MyFrame::DoDeletePrint() @@ -870,6 +871,7 @@ void MyFrame::DoDeletePrint() wxToolBarBase *tb = GetToolBar(); tb->DeleteTool( wxID_PRINT ); + m_textWindow->AppendText("Print tool was deleted.\n"); m_nPrint--; } @@ -878,6 +880,7 @@ void MyFrame::DoToggleHelp() { wxToolBarBase *tb = GetToolBar(); tb->ToggleTool( wxID_HELP, !tb->GetToolState( wxID_HELP ) ); + m_textWindow->AppendText("Help tool was toggled.\n"); } void MyFrame::OnToggleSearch(wxCommandEvent& WXUNUSED(event))