From e2fbfb693f540a29cc10454e5b8afbb5f54b3038 Mon Sep 17 00:00:00 2001 From: Prashant Kumar Nirmal Date: Fri, 31 Mar 2017 16:55:23 +0200 Subject: [PATCH 01/12] Improve "svg" sample UI to make using it less troublesome The sample forced the user to use the menu "Open" command several (up to 8!) times to get to a particular page which was inconvenient and confusing, especially because more than 8 windows could be opened. Fix both problems by just creating a notebook with 8 pages, each corresponding to a particular test. --- samples/svg/svgtest.cpp | 312 ++++++++++++---------------------------- 1 file changed, 88 insertions(+), 224 deletions(-) diff --git a/samples/svg/svgtest.cpp b/samples/svg/svgtest.cpp index 5adf547a9d..ac9b1404f1 100644 --- a/samples/svg/svgtest.cpp +++ b/samples/svg/svgtest.cpp @@ -23,16 +23,12 @@ #ifndef WX_PRECOMP #include "wx/wx.h" -#include "wx/mdi.h" #endif -#include "wx/toolbar.h" #include "wx/dcsvg.h" #include "wx/vector.h" +#include -#include "bitmaps/new.xpm" -#include "bitmaps/save.xpm" -#include "bitmaps/help.xpm" #include "SVGlogo24.xpm" #ifndef wxHAS_IMAGES_IN_RESOURCES @@ -41,9 +37,6 @@ #include -class MyChild; -class MyCanvas; - // --------------------------------------------------------------------------- // classes // --------------------------------------------------------------------------- @@ -54,61 +47,31 @@ public: bool OnInit() wxOVERRIDE; }; -class MyFrame : public wxMDIParentFrame +class MyPage : public wxScrolledWindow +{ +public: + MyPage(wxNotebook *parent, int index); + virtual void OnDraw(wxDC& dc) wxOVERRIDE; + bool OnSave(wxString); +private: + int m_index; +}; + +class MyFrame : public wxFrame { public: MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, - const wxPoint& pos, const wxSize& size, const long style); + const wxPoint& pos, const wxSize& size); - void InitToolBar(wxToolBar* toolBar); + MyPage *CreateNewPage(int index); - void OnSize(wxSizeEvent& event); + void FileSavePicture(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); - void OnNewWindow(wxCommandEvent& event); void OnQuit(wxCommandEvent& event); - void FileSavePicture (wxCommandEvent& event); - - unsigned int GetCountOfChildren() const - { return m_nWinCreated; } - private: - unsigned int m_nWinCreated; - - wxDECLARE_EVENT_TABLE(); -}; - -class MyChild: public wxMDIChildFrame -{ -public: - MyChild(wxMDIParentFrame *parent, const wxString& title, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - const long style = wxDEFAULT_FRAME_STYLE); - ~MyChild(); - - void OnActivate(wxActivateEvent& event); - void OnQuit(wxCommandEvent& event); - bool OnSave(wxString filename); - - MyFrame* GetFrame() - { return m_frame; } - -private: - MyCanvas *m_canvas; - MyFrame *m_frame; - - wxDECLARE_EVENT_TABLE(); -}; - -class MyCanvas : public wxScrolledWindow -{ -public: - MyCanvas(MyChild *parent, const wxPoint& pos, const wxSize& size); - virtual void OnDraw(wxDC& dc) wxOVERRIDE; - -private: - int m_index; - MyChild* m_child; + wxNotebook *m_notebook; + wxPanel *m_panel; + wxBoxSizer *m_sizerFrame; wxDECLARE_EVENT_TABLE(); }; @@ -118,27 +81,22 @@ private: // --------------------------------------------------------------------------- // menu items ids + enum { - MDI_QUIT = 100, - MDI_NEW_WINDOW, - MDI_SAVE, - MDI_REFRESH, - MDI_CHILD_QUIT, - MDI_ABOUT + ID_SAVE = 100, + ID_ABOUT, + ID_QUIT }; // --------------------------------------------------------------------------- // event tables // --------------------------------------------------------------------------- -wxBEGIN_EVENT_TABLE(MyFrame, wxMDIParentFrame) - EVT_MENU(MDI_ABOUT, MyFrame::OnAbout) - EVT_MENU(MDI_NEW_WINDOW, MyFrame::OnNewWindow) - EVT_MENU(MDI_QUIT, MyFrame::OnQuit) - EVT_MENU (MDI_SAVE, MyFrame::FileSavePicture) - - EVT_SIZE(MyFrame::OnSize) +wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) + EVT_MENU(ID_ABOUT, MyFrame::OnAbout) + EVT_MENU(ID_QUIT, MyFrame::OnQuit) + EVT_MENU(ID_SAVE, MyFrame::FileSavePicture) wxEND_EVENT_TABLE() // =========================================================================== @@ -155,37 +113,38 @@ bool MyApp::OnInit() { // Create the main frame window - MyFrame* frame = new MyFrame((wxFrame *)NULL, -1, wxT("SVG Demo"), - wxDefaultPosition, wxSize(500, 400), - wxDEFAULT_FRAME_STYLE | wxHSCROLL | wxVSCROLL); + MyFrame* frame = new MyFrame(NULL, -1, wxT("SVG Demo"), + wxDefaultPosition, wxSize(500, 400)); frame->Show(true); return true; } - // --------------------------------------------------------------------------- // MyFrame // --------------------------------------------------------------------------- // Define my frame constructor -MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, - const wxPoint& pos, const wxSize& size, const long style) - : wxMDIParentFrame(parent, id, title, pos, size, style) -{ - m_nWinCreated = 0; +MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, + const wxPoint& pos, const wxSize& size) + : wxFrame(parent, id, title, pos, size) +{ SetIcon(wxICON(sample)); + #if wxUSE_STATUSBAR + CreateStatusBar(); + #endif // wxUSE_STATUSBAR + // Make a menubar wxMenu *file_menu = new wxMenu; - file_menu->Append(MDI_NEW_WINDOW, wxT("&New test\tCtrl+N")); - file_menu->Append(MDI_QUIT, wxT("&Exit\tAlt+X")); + file_menu->Append(ID_SAVE, wxT("&Save As..\tCtrl+S")); + file_menu->Append(ID_QUIT, wxT("&Exit\tAlt+X")); wxMenu *help_menu = new wxMenu; - help_menu->Append(MDI_ABOUT, wxT("&About")); + help_menu->Append(ID_ABOUT, wxT("&About")); wxMenuBar *menu_bar = new wxMenuBar; @@ -195,12 +154,33 @@ MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, // Associate the menu bar with the frame SetMenuBar(menu_bar); -#if wxUSE_STATUSBAR - CreateStatusBar(); -#endif // wxUSE_STATUSBAR + //Panel containing a notebook + m_panel = new wxPanel(this); + m_sizerFrame= new wxBoxSizer(wxVERTICAL); + m_panel->SetSizer(m_sizerFrame); - CreateToolBar(wxNO_BORDER | wxTB_FLAT | wxTB_HORIZONTAL); - InitToolBar(GetToolBar()); + //Create a notebook + m_notebook = new wxNotebook(m_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBK_TOP); + + //Add SVG Windows to a notebook + for (int i = 0; i <= 8; ++i) + { + wxString svgTitle; + svgTitle.Printf(wxT("SVG Test %d"), i); + m_notebook->AddPage(CreateNewPage(i), svgTitle, true); + + } + + //Add a notebook + m_sizerFrame->Insert(0, m_notebook, wxSizerFlags(5).Expand().Border()); + m_notebook->ChangeSelection(0); + m_sizerFrame->Layout(); +} + +MyPage *MyFrame::CreateNewPage(int index) +{ + MyPage *page = new MyPage(m_notebook, index); + return page; } void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) @@ -208,97 +188,31 @@ void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) Close(); } -void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) ) +void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) { (void)wxMessageBox(wxT("wxWidgets SVG sample\n") wxT("Author: Chris Elliott (c) 2002-2009\n") - wxT("Usage: click File|New to show tests"), + wxT("Usage: click File|Save As.. to Save the Selected SVG Test"), wxT("About SVG Test")); } -void MyFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event) ) -{ - // Make another frame, containing a canvas - MyChild *subframe = new MyChild(this, wxT("SVG Frame")); - - wxString title; - title.Printf(wxT("SVG Test Window %d"), m_nWinCreated ); - - // counts number of children previously, even if now closed - m_nWinCreated ++; - - // Give it a title and icon - subframe->SetTitle(title); - subframe->SetIcon(wxICON(sample)); - - // Make a menubar - wxMenu *file_menu = new wxMenu; - - file_menu->Append(MDI_NEW_WINDOW, wxT("&Another test\tCtrl+N")); - file_menu->Append(MDI_SAVE, wxT("&Save\tCtrl+S"), wxT("Save in SVG format")); - file_menu->Append(MDI_CHILD_QUIT, wxT("&Close child\tCtrl+F4")); - file_menu->Append(MDI_QUIT, wxT("&Exit\tAlt+X")); - - wxMenu *help_menu = new wxMenu; - help_menu->Append(MDI_ABOUT, wxT("&About")); - - wxMenuBar *menu_bar = new wxMenuBar; - - menu_bar->Append(file_menu, wxT("&File")); - menu_bar->Append(help_menu, wxT("&Help")); - - // Associate the menu bar with the frame - subframe->SetMenuBar(menu_bar); - - subframe->Show(true); -} - -void MyFrame::OnSize(wxSizeEvent& event) -{ - int w, h; - GetClientSize(&w, &h); - - GetClientWindow()->SetSize(0, 0, w, h); - event.Skip(); -} - -void MyFrame::InitToolBar(wxToolBar* toolBar) -{ - const int maxBitmaps = 3; - wxBitmap* bitmaps[maxBitmaps]; - - bitmaps[0] = new wxBitmap( new_xpm ); - bitmaps[1] = new wxBitmap( save_xpm ); - bitmaps[2] = new wxBitmap( help_xpm ); - - toolBar->AddTool(MDI_NEW_WINDOW, wxEmptyString, *(bitmaps[0]), wxS("New SVG test window")); - toolBar->AddTool(MDI_SAVE, wxEmptyString, *bitmaps[1], wxS("Save test in SVG format")); - toolBar->AddSeparator(); - toolBar->AddTool(MDI_ABOUT, wxEmptyString, *bitmaps[2], wxS("Help")); - - toolBar->Realize(); - - int i; - for (i = 0; i < maxBitmaps; i++) - delete bitmaps[i]; -} - -void MyFrame::FileSavePicture (wxCommandEvent & WXUNUSED(event) ) +void MyFrame::FileSavePicture(wxCommandEvent& WXUNUSED(event)) { #if wxUSE_FILEDLG - MyChild * pChild = (MyChild *)GetActiveChild(); - if (pChild == NULL) + MyPage *page = (MyPage *) m_notebook->GetCurrentPage(); + if (page == NULL) { return; } - wxFileDialog dialog(this, wxT("Save Picture as"), wxEmptyString, pChild->GetTitle(), + wxFileDialog dialog(this, wxT("Save Picture as"), wxEmptyString, + m_notebook->GetPageText(m_notebook->GetSelection()), wxT("SVG vector picture files (*.svg)|*.svg"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT); if (dialog.ShowModal() == wxID_OK) { - if (!pChild->OnSave ( dialog.GetPath() )) + if (!page->OnSave ( dialog.GetPath() )) { return; } @@ -307,28 +221,30 @@ void MyFrame::FileSavePicture (wxCommandEvent & WXUNUSED(event) ) #endif // wxUSE_FILEDLG } - // --------------------------------------------------------------------------- -// MyCanvas +// MyPage // --------------------------------------------------------------------------- -wxBEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) -wxEND_EVENT_TABLE() - -// Define a constructor for my canvas -MyCanvas::MyCanvas(MyChild *parent, const wxPoint& pos, const wxSize& size) - : wxScrolledWindow(parent, wxID_ANY, pos, size, wxSUNKEN_BORDER|wxVSCROLL|wxHSCROLL) +// Define a constructor for my page +MyPage::MyPage(wxNotebook *parent, int index) + : wxScrolledWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL|wxHSCROLL) { SetBackgroundColour(*wxWHITE); + SetScrollbars(20, 20, 50, 50); + m_index = index; +} - m_child = parent; - m_index = m_child->GetFrame()->GetCountOfChildren() % 9; +bool MyPage::OnSave(wxString filename) +{ + wxSVGFileDC svgDC (filename, 600, 650); + OnDraw (svgDC); + return svgDC.IsOk(); } // Define the repainting behaviour -void MyCanvas::OnDraw(wxDC& dc) +void MyPage::OnDraw(wxDC& dc) { - // vars to use ... + // vars to use ... #if wxUSE_STATUSBAR wxString s; #endif // wxUSE_STATUSBAR @@ -604,59 +520,7 @@ void MyCanvas::OnDraw(wxDC& dc) break; } #if wxUSE_STATUSBAR - m_child->SetStatusText(s); + ( (wxFrame *)wxGetTopLevelParent(this) )->SetStatusText(s); #endif // wxUSE_STATUSBAR } - -// --------------------------------------------------------------------------- -// MyChild -// --------------------------------------------------------------------------- - -// Note that MDI_NEW_WINDOW and MDI_ABOUT commands get passed -// to the parent window for processing, so no need to -// duplicate event handlers here. -wxBEGIN_EVENT_TABLE(MyChild, wxMDIChildFrame) - EVT_MENU(MDI_CHILD_QUIT, MyChild::OnQuit) -wxEND_EVENT_TABLE() - -MyChild::MyChild(wxMDIParentFrame *parent, const wxString& title, - const wxPoint& pos, const wxSize& size, - const long style) - : wxMDIChildFrame(parent, wxID_ANY, title, pos, size, style) -{ - m_frame = (MyFrame *) parent; - -#if wxUSE_STATUSBAR - CreateStatusBar(); - SetStatusText(title); -#endif // wxUSE_STATUSBAR - - m_canvas = new MyCanvas(this, wxPoint(0, 0), GetClientSize()); - - // Give it scrollbars - m_canvas->SetScrollbars(20, 20, 50, 50); -} - -MyChild::~MyChild() -{ -} - -void MyChild::OnQuit(wxCommandEvent& WXUNUSED(event)) -{ - Close(true); -} - -bool MyChild::OnSave(wxString filename) -{ - wxSVGFileDC svgDC (filename, 600, 650); - m_canvas->OnDraw (svgDC); - return svgDC.IsOk(); -} - -void MyChild::OnActivate(wxActivateEvent& event) -{ - if ( event.GetActive() && m_canvas ) - m_canvas->SetFocus(); -} - From 4aa2a84ac5e7b9bd4a37441a3327c1c5b1d4171b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 31 Mar 2017 16:58:19 +0200 Subject: [PATCH 02/12] Remove the now unused icons from the svg sample Since these bitmaps are not used in the sample toolbar any more, they're not needed at all now. --- samples/svg/bitmaps/help.xpm | 71 ------------------------------------ samples/svg/bitmaps/new.xpm | 52 -------------------------- samples/svg/bitmaps/save.xpm | 42 --------------------- 3 files changed, 165 deletions(-) delete mode 100644 samples/svg/bitmaps/help.xpm delete mode 100644 samples/svg/bitmaps/new.xpm delete mode 100644 samples/svg/bitmaps/save.xpm diff --git a/samples/svg/bitmaps/help.xpm b/samples/svg/bitmaps/help.xpm deleted file mode 100644 index eebb5b518d..0000000000 --- a/samples/svg/bitmaps/help.xpm +++ /dev/null @@ -1,71 +0,0 @@ -/* XPM */ -static const char *const help_xpm[] = { -/* columns rows colors chars-per-pixel */ -"16 15 50 1", -"j c #4E7FD0", -"8 c #EDF2FB", -", c #7198D9", -"e c #DCE6F6", -"y c #FFFFFF", -"5 c #95B2E3", -"$ c #9AB6E4", -"g c #EAF0FA", -"1 c #2D59A3", -"@ c #B1C7EB", -"> c #6992D7", -"a c #D9E4F5", -"r c #356AC1", -"6 c #9BB7E5", -"= c #F7F9FD", -"+ c #BED0EE", -"z c #F0F5FC", -"f c #ADC4E9", -"# c #A8C0E8", -"7 c #CBD9F1", -"u c #366BC2", -" c None", -"c c #FDFEFF", -"w c #274D8D", -"t c #C4D5F0", -"% c #7CA0DC", -"h c #E2EAF8", -"p c #487BCE", -"o c #4377CD", -"4 c #2A549A", -"< c #254A87", -"O c #CCDAF2", -"& c #89A9DF", -"9 c #2B559B", -"* c #D2DFF4", -". c #3366BB", -": c #2E5CA8", -"x c #FAFCFE", -"l c #F5F8FD", -"2 c #799EDB", -"d c #DFE8F7", -"; c #A6BFE8", -"3 c #638ED5", -"- c #5282D0", -"X c #2A5398", -"0 c #B8CCEC", -"s c #376EC9", -"q c #2D5AA5", -"i c #285092", -"k c #8CACE0", -/* pixels */ -" .......Xo ", -" .O+@#$%.&o ", -" .*O+@#$.=&- ", -" ;:::>#@#.==&: ", -" ,<1234<>@....: ", -"5 c #3366BB", -"$ c #2E5CA8", -"9 c #FAFCFE", -"4 c #F5F8FD", -"q c #638ED5", -"o c #5282D0", -"& c #B8CCEC", -"X c #376EC9", -"< c #ACE95B", -/* pixels */ -" .XoO+@#$. ", -" .%%&*=-O;: ", -" >>>>%&*=O,=o ", -" ><<>%%&*O,,=o", -">>><<>>>%&OOo+@", -"><<<<<<>1%&*=-@", -"><<<<<<>21%&*=@", -">>><<>>>321%&*+", -" ><<>456321%&O", -" >>>>7456321%o", -" .,8974563210", -" .,,897456320", -" .,,,8974563q", -" .,,,,897456w", -" ............" -}; diff --git a/samples/svg/bitmaps/save.xpm b/samples/svg/bitmaps/save.xpm deleted file mode 100644 index 452a06b6fa..0000000000 --- a/samples/svg/bitmaps/save.xpm +++ /dev/null @@ -1,42 +0,0 @@ -/* XPM */ -static const char *const save_xpm[] = { -/* columns rows colors chars-per-pixel */ -"16 15 21 1", -": c #AAC1E8", -"1 c #B9CDED", -"O c #FFFFFF", -" c #2C58A0", -"* c #B0C6EA", -"; c #2D59A3", -"X c #1C3866", -"= c #C3D4EF", -"2 c #CBD9F1", -"- c #DAE5F6", -"# c #97B4E3", -". c None", -"$ c #274D8B", -"& c #9FB9E5", -"@ c #5584D1", -"% c #82A5DE", -"o c #3A70CA", -"< c #A5BEE7", -", c #D2DFF4", -"+ c #3467BC", -"> c #C0D1EE", -/* pixels */ -" .", -" XoOOOOOOOOO+X .", -" @oO#######O+@ .", -" @oOOOOOOOOO+@ .", -" @oO#######O+@ .", -" @oOOOOOOOOO+@ .", -" @@+++++++++@@ .", -" @@@@@@@@@@@@@ .", -" @@@$$$$$$$$@@ .", -" @@$%%%&*=-O$@ .", -" @@$%X;;*=-O$@ .", -" @@$%X;;:>,O$@ .", -" @@$%X;;<12O$@ .", -" @@$<<2OOOOO$@ .", -". .." -}; From 4b7d3561d98881b0c2021285bae866cc625983d4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 31 Mar 2017 17:01:10 +0200 Subject: [PATCH 03/12] Use standard menu IDs in the "svg" sample Don't define our own ID_XXX when the standard ones will do. Use wxID_SAVE instead of wxID_SAVEAS just because the former has a standard accelerator (Ctrl-S) while the latter does not, at least under MSW, and it's convenient to have one. --- samples/svg/svgtest.cpp | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/samples/svg/svgtest.cpp b/samples/svg/svgtest.cpp index ac9b1404f1..b5cc272e5c 100644 --- a/samples/svg/svgtest.cpp +++ b/samples/svg/svgtest.cpp @@ -76,27 +76,14 @@ private: wxDECLARE_EVENT_TABLE(); }; -// --------------------------------------------------------------------------- -// constants -// --------------------------------------------------------------------------- - -// menu items ids - -enum -{ - ID_SAVE = 100, - ID_ABOUT, - ID_QUIT -}; - // --------------------------------------------------------------------------- // event tables // --------------------------------------------------------------------------- wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) - EVT_MENU(ID_ABOUT, MyFrame::OnAbout) - EVT_MENU(ID_QUIT, MyFrame::OnQuit) - EVT_MENU(ID_SAVE, MyFrame::FileSavePicture) + EVT_MENU(wxID_ABOUT, MyFrame::OnAbout) + EVT_MENU(wxID_EXIT, MyFrame::OnQuit) + EVT_MENU(wxID_SAVE, MyFrame::FileSavePicture) wxEND_EVENT_TABLE() // =========================================================================== @@ -140,11 +127,11 @@ MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, // Make a menubar wxMenu *file_menu = new wxMenu; - file_menu->Append(ID_SAVE, wxT("&Save As..\tCtrl+S")); - file_menu->Append(ID_QUIT, wxT("&Exit\tAlt+X")); + file_menu->Append(wxID_SAVE); + file_menu->Append(wxID_EXIT); wxMenu *help_menu = new wxMenu; - help_menu->Append(ID_ABOUT, wxT("&About")); + help_menu->Append(wxID_ABOUT); wxMenuBar *menu_bar = new wxMenuBar; @@ -192,7 +179,7 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) { (void)wxMessageBox(wxT("wxWidgets SVG sample\n") wxT("Author: Chris Elliott (c) 2002-2009\n") - wxT("Usage: click File|Save As.. to Save the Selected SVG Test"), + wxT("Usage: click File|Save to Save the Selected SVG Test"), wxT("About SVG Test")); } From 331ba71d4e23d5a277dd2aeab60a9961050c0a5f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 31 Mar 2017 17:03:33 +0200 Subject: [PATCH 04/12] Remove unnecessary wx/vector.h inclusion from the svg sample Nothing uses wxVector<> here. --- samples/svg/svgtest.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/svg/svgtest.cpp b/samples/svg/svgtest.cpp index b5cc272e5c..383cc2133e 100644 --- a/samples/svg/svgtest.cpp +++ b/samples/svg/svgtest.cpp @@ -26,7 +26,6 @@ #endif #include "wx/dcsvg.h" -#include "wx/vector.h" #include #include "SVGlogo24.xpm" From 70e01a6849ea6e7128dbe07359d7b7cde057560d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 31 Mar 2017 17:04:56 +0200 Subject: [PATCH 05/12] Use quotes, not angle brackets, for wx header in svg sample Samples are part of wxWidgets and use quotes for including wx headers to indicate that they're part of the same tree and not global headers, so just follow the same convention here. --- samples/svg/svgtest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/svg/svgtest.cpp b/samples/svg/svgtest.cpp index 383cc2133e..b652460be5 100644 --- a/samples/svg/svgtest.cpp +++ b/samples/svg/svgtest.cpp @@ -26,7 +26,7 @@ #endif #include "wx/dcsvg.h" -#include +#include "wx/notebook.h" #include "SVGlogo24.xpm" From 367cf2da5c75870e16110c3048cc2e977d9578aa Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 31 Mar 2017 17:07:12 +0200 Subject: [PATCH 06/12] Fix a few whitespace problems in the svg sample No real changes, just consistently use spaces after "//" and on both sides of the assignment operator. --- samples/svg/svgtest.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/svg/svgtest.cpp b/samples/svg/svgtest.cpp index b652460be5..37e7d1f8b9 100644 --- a/samples/svg/svgtest.cpp +++ b/samples/svg/svgtest.cpp @@ -140,12 +140,12 @@ MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, // Associate the menu bar with the frame SetMenuBar(menu_bar); - //Panel containing a notebook + // Panel containing a notebook m_panel = new wxPanel(this); - m_sizerFrame= new wxBoxSizer(wxVERTICAL); + m_sizerFrame = new wxBoxSizer(wxVERTICAL); m_panel->SetSizer(m_sizerFrame); - //Create a notebook + // Create a notebook m_notebook = new wxNotebook(m_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBK_TOP); //Add SVG Windows to a notebook @@ -157,7 +157,7 @@ MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, } - //Add a notebook + // Add a notebook m_sizerFrame->Insert(0, m_notebook, wxSizerFlags(5).Expand().Border()); m_notebook->ChangeSelection(0); m_sizerFrame->Layout(); From fe562d8bcdb1bfa2fc216267565bb33aa2410a89 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 31 Mar 2017 17:09:04 +0200 Subject: [PATCH 07/12] Avoid ugly cast in the svg sample Just use wxLogStatus() instead of manually setting the status text, as this also allows to get rid of wxUSE_STATUSBAR checks (wxLogStatus() is always declared and just does nothing in this case). --- samples/svg/svgtest.cpp | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/samples/svg/svgtest.cpp b/samples/svg/svgtest.cpp index 37e7d1f8b9..e0bdbfb64d 100644 --- a/samples/svg/svgtest.cpp +++ b/samples/svg/svgtest.cpp @@ -231,9 +231,7 @@ bool MyPage::OnSave(wxString filename) void MyPage::OnDraw(wxDC& dc) { // vars to use ... -#if wxUSE_STATUSBAR wxString s; -#endif // wxUSE_STATUSBAR wxPen wP; wxBrush wB; wxPoint points[6]; @@ -257,9 +255,7 @@ void MyPage::OnDraw(wxDC& dc) dc.DrawPoint (25,15); dc.DrawLine(50, 30, 200, 30); dc.DrawSpline(50, 200, 50, 100, 200, 10); -#if wxUSE_STATUSBAR s = wxT("Green Cross, Cyan Line and spline"); -#endif // wxUSE_STATUSBAR break; case 1: @@ -282,9 +278,7 @@ void MyPage::OnDraw(wxDC& dc) dc.DrawPolygon(5, points); dc.DrawLines (6, points, 160); -#if wxUSE_STATUSBAR s = wxT("Blue rectangle, red edge, clear rounded rectangle, gold ellipse, gold and clear stars"); -#endif // wxUSE_STATUSBAR break; case 2: @@ -306,9 +300,7 @@ void MyPage::OnDraw(wxDC& dc) .Italic().Bold()); dc.SetTextForeground (wC); dc.DrawText(wxT("This is a Times-style string"), 50, 60); -#if wxUSE_STATUSBAR s = wxT("Swiss, Times text; red text, rotated and colored orange"); -#endif // wxUSE_STATUSBAR break; case 3 : @@ -342,9 +334,7 @@ void MyPage::OnDraw(wxDC& dc) dc.DrawEllipticArc(300, 50,200,100,90.0,145.0); dc.DrawEllipticArc(300,100,200,100,90.0,345.0); -#if wxUSE_STATUSBAR s = wxT("This is an arc test page"); -#endif // wxUSE_STATUSBAR break; case 4: @@ -352,9 +342,7 @@ void MyPage::OnDraw(wxDC& dc) dc.SetBrush (wxBrush (wxT("SALMON"),wxBRUSHSTYLE_TRANSPARENT)); dc.DrawCheckMark ( 80,50,75,75); dc.DrawRectangle ( 80,50,75,75); -#if wxUSE_STATUSBAR s = wxT("Two check marks"); -#endif // wxUSE_STATUSBAR break; case 5: @@ -386,17 +374,13 @@ void MyPage::OnDraw(wxDC& dc) dc.DrawLine(0, 0, 200, 200); dc.DrawLine(200, 0, 0, 200); dc.DrawText(wxT("This is an 18pt string in MapMode"), 50, 60); -#if wxUSE_STATUSBAR s = wxT("Scaling test page"); -#endif // wxUSE_STATUSBAR break; case 6: dc.DrawIcon( wxICON(sample), 10, 10 ); dc.DrawBitmap ( wxBitmap(svgbitmap_xpm), 50,15); -#if wxUSE_STATUSBAR s = wxT("Icon and Bitmap "); -#endif // wxUSE_STATUSBAR break; case 7: @@ -456,9 +440,7 @@ void MyPage::OnDraw(wxDC& dc) dc.DestroyClippingRegion(); */ -#if wxUSE_STATUSBAR s = wxT("Clipping region"); -#endif // wxUSE_STATUSBAR break; case 8: @@ -500,13 +482,10 @@ void MyPage::OnDraw(wxDC& dc) dc.DrawLine(txtX - padding, txtY, txtX - padding + lenH, txtY + lenH); dc.DrawLine(txtX - padding + lenH, txtY + lenH, txtX - padding + lenH + lenW, txtY + (lenH - lenW)); // bottom dc.DrawRotatedText(txtStr, txtX, txtY, 45); -#if wxUSE_STATUSBAR s = wxT("Text position test page"); -#endif // wxUSE_STATUSBAR break; } -#if wxUSE_STATUSBAR - ( (wxFrame *)wxGetTopLevelParent(this) )->SetStatusText(s); -#endif // wxUSE_STATUSBAR + + wxLogStatus("%s", s); } From 9eb62000f9695841da4b20af8e3b755fc12f961e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 31 Mar 2017 17:12:39 +0200 Subject: [PATCH 08/12] Simplify layout of the svg sample Get rid of the panel and the sizer, neither of them are necessary when we have a single control (wxNotebook in this case) taking up the entire frame client area. --- samples/svg/svgtest.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/samples/svg/svgtest.cpp b/samples/svg/svgtest.cpp index e0bdbfb64d..4563474ab1 100644 --- a/samples/svg/svgtest.cpp +++ b/samples/svg/svgtest.cpp @@ -140,27 +140,17 @@ MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, // Associate the menu bar with the frame SetMenuBar(menu_bar); - // Panel containing a notebook - m_panel = new wxPanel(this); - m_sizerFrame = new wxBoxSizer(wxVERTICAL); - m_panel->SetSizer(m_sizerFrame); - // Create a notebook - m_notebook = new wxNotebook(m_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBK_TOP); + m_notebook = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBK_TOP); //Add SVG Windows to a notebook for (int i = 0; i <= 8; ++i) { wxString svgTitle; svgTitle.Printf(wxT("SVG Test %d"), i); - m_notebook->AddPage(CreateNewPage(i), svgTitle, true); + m_notebook->AddPage(CreateNewPage(i), svgTitle); } - - // Add a notebook - m_sizerFrame->Insert(0, m_notebook, wxSizerFlags(5).Expand().Border()); - m_notebook->ChangeSelection(0); - m_sizerFrame->Layout(); } MyPage *MyFrame::CreateNewPage(int index) From 3745f2c7715c24d2ca05dcb5a1e3d71c9f4bb49b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 31 Mar 2017 17:13:44 +0200 Subject: [PATCH 09/12] Remove unnecessary check for null notebook page A non-empty notebook always has a non-null current page. --- samples/svg/svgtest.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/samples/svg/svgtest.cpp b/samples/svg/svgtest.cpp index 4563474ab1..c9abc61363 100644 --- a/samples/svg/svgtest.cpp +++ b/samples/svg/svgtest.cpp @@ -175,11 +175,7 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) void MyFrame::FileSavePicture(wxCommandEvent& WXUNUSED(event)) { #if wxUSE_FILEDLG - MyPage *page = (MyPage *) m_notebook->GetCurrentPage(); - if (page == NULL) - { - return; - } + MyPage * const page = (MyPage *) m_notebook->GetCurrentPage(); wxFileDialog dialog(this, wxT("Save Picture as"), wxEmptyString, m_notebook->GetPageText(m_notebook->GetSelection()), From b7822ff511d3570336386e0ccd529c110eb150cd Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 31 Mar 2017 17:15:03 +0200 Subject: [PATCH 10/12] Get rid of unnecessary helper function in the svg sample No real changes, just remove the trivial CreateNewPage() function which made the code less clear without any real gain. --- samples/svg/svgtest.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/samples/svg/svgtest.cpp b/samples/svg/svgtest.cpp index c9abc61363..d2a534e282 100644 --- a/samples/svg/svgtest.cpp +++ b/samples/svg/svgtest.cpp @@ -62,8 +62,6 @@ public: MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size); - MyPage *CreateNewPage(int index); - void FileSavePicture(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); void OnQuit(wxCommandEvent& event); @@ -148,17 +146,11 @@ MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, { wxString svgTitle; svgTitle.Printf(wxT("SVG Test %d"), i); - m_notebook->AddPage(CreateNewPage(i), svgTitle); + m_notebook->AddPage(new MyPage(m_notebook, i), svgTitle); } } -MyPage *MyFrame::CreateNewPage(int index) -{ - MyPage *page = new MyPage(m_notebook, index); - return page; -} - void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) { Close(); From 5fb77c4c78fd54217a2a2b0c1746641fc610f4b7 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 31 Mar 2017 17:17:11 +0200 Subject: [PATCH 11/12] Credit Prashant Kumar Nirmal as svg sample author --- samples/svg/svgtest.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/samples/svg/svgtest.cpp b/samples/svg/svgtest.cpp index d2a534e282..90c3fcdbed 100644 --- a/samples/svg/svgtest.cpp +++ b/samples/svg/svgtest.cpp @@ -2,7 +2,6 @@ // Name: svgtest.cpp // Purpose: SVG sample // Author: Chris Elliott -// Modified by: // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -159,7 +158,9 @@ void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) { (void)wxMessageBox(wxT("wxWidgets SVG sample\n") - wxT("Author: Chris Elliott (c) 2002-2009\n") + wxT("Authors:\n") + wxT(" Chris Elliott (c) 2002-2009\n") + wxT(" Prashant Kumar Nirmal (c) 2017\n") wxT("Usage: click File|Save to Save the Selected SVG Test"), wxT("About SVG Test")); } From 4325472e97029ea6f274a5d1e8bcfa6b472ee0f9 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 1 Apr 2017 18:26:16 +0200 Subject: [PATCH 12/12] Use symbolic constants instead of hardcoded numbers in svn sample It would arguably be even better to use different derived classes for different operations instead of doing everything inside a single class with a big "switch", but this would require more time, so for now at least make the code slightly more understandable and maintainable. This also results in using useful names for the files being saved by default instead of just "SVG Test #" used before. --- samples/svg/svgtest.cpp | 82 ++++++++++++++++++++++++++++------------- 1 file changed, 57 insertions(+), 25 deletions(-) diff --git a/samples/svg/svgtest.cpp b/samples/svg/svgtest.cpp index 90c3fcdbed..5a759b3fec 100644 --- a/samples/svg/svgtest.cpp +++ b/samples/svg/svgtest.cpp @@ -45,6 +45,51 @@ public: bool OnInit() wxOVERRIDE; }; +// Existing pages: +enum Page +{ + Page_Lines, + Page_Polygons, + Page_Text, + Page_Arcs, + Page_Checkmarks, + Page_ScaledText, + Page_Bitmaps, + Page_Clipping, + Page_TextPos, + Page_Max +}; + +static const char* pageNames[] = +{ + "Lines", + "Polygons", + "Text", + "Arcs", + "Checkmarks", + "Scaled text", + "Bitmaps", + "Clipping", + "Text position", +}; + +wxCOMPILE_TIME_ASSERT( WXSIZEOF(pageNames) == Page_Max, PageNamesMismatch ); + +static const char* pageDescriptions[] = +{ + "Green Cross, Cyan Line and spline", + "Blue rectangle, red edge, clear rounded rectangle, gold ellipse, gold and clear stars", + "Swiss, Times text; red text, rotated and colored orange", + "This is an arc test page", + "Two check marks", + "Scaling test page", + "Icon and Bitmap ", + "Clipping region", + "Text position test page", +}; + +wxCOMPILE_TIME_ASSERT( WXSIZEOF(pageDescriptions) == Page_Max, PageDescriptionsMismatch ); + class MyPage : public wxScrolledWindow { public: @@ -141,11 +186,9 @@ MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, m_notebook = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBK_TOP); //Add SVG Windows to a notebook - for (int i = 0; i <= 8; ++i) + for (int i = 0; i < Page_Max; ++i) { - wxString svgTitle; - svgTitle.Printf(wxT("SVG Test %d"), i); - m_notebook->AddPage(new MyPage(m_notebook, i), svgTitle); + m_notebook->AddPage(new MyPage(m_notebook, i), pageNames[i]); } } @@ -210,7 +253,6 @@ bool MyPage::OnSave(wxString filename) void MyPage::OnDraw(wxDC& dc) { // vars to use ... - wxString s; wxPen wP; wxBrush wB; wxPoint points[6]; @@ -221,8 +263,7 @@ void MyPage::OnDraw(wxDC& dc) switch (m_index) { - default: - case 0: + case Page_Lines: // draw lines to make a cross dc.DrawLine(0, 0, 200, 200); dc.DrawLine(200, 0, 0, 200); @@ -234,10 +275,9 @@ void MyPage::OnDraw(wxDC& dc) dc.DrawPoint (25,15); dc.DrawLine(50, 30, 200, 30); dc.DrawSpline(50, 200, 50, 100, 200, 10); - s = wxT("Green Cross, Cyan Line and spline"); break; - case 1: + case Page_Polygons: // draw standard shapes dc.SetBrush(*wxCYAN_BRUSH); dc.SetPen(*wxRED_PEN); @@ -257,10 +297,9 @@ void MyPage::OnDraw(wxDC& dc) dc.DrawPolygon(5, points); dc.DrawLines (6, points, 160); - s = wxT("Blue rectangle, red edge, clear rounded rectangle, gold ellipse, gold and clear stars"); break; - case 2: + case Page_Text: // draw text in Arial or similar font dc.DrawLine(50,25,50,35); dc.DrawLine(45,30,55,30); @@ -279,10 +318,9 @@ void MyPage::OnDraw(wxDC& dc) .Italic().Bold()); dc.SetTextForeground (wC); dc.DrawText(wxT("This is a Times-style string"), 50, 60); - s = wxT("Swiss, Times text; red text, rotated and colored orange"); break; - case 3 : + case Page_Arcs: // four arcs start and end points, center dc.SetBrush(*wxGREEN_BRUSH); dc.DrawArc ( 200,300, 370,230, 300,300 ); @@ -313,18 +351,16 @@ void MyPage::OnDraw(wxDC& dc) dc.DrawEllipticArc(300, 50,200,100,90.0,145.0); dc.DrawEllipticArc(300,100,200,100,90.0,345.0); - s = wxT("This is an arc test page"); break; - case 4: + case Page_Checkmarks: dc.DrawCheckMark ( 30,30,25,25); dc.SetBrush (wxBrush (wxT("SALMON"),wxBRUSHSTYLE_TRANSPARENT)); dc.DrawCheckMark ( 80,50,75,75); dc.DrawRectangle ( 80,50,75,75); - s = wxT("Two check marks"); break; - case 5: + case Page_ScaledText: dc.SetFont(wxFontInfo(18) .FaceName("Times New Roman") .Family(wxFONTFAMILY_ROMAN) @@ -353,16 +389,14 @@ void MyPage::OnDraw(wxDC& dc) dc.DrawLine(0, 0, 200, 200); dc.DrawLine(200, 0, 0, 200); dc.DrawText(wxT("This is an 18pt string in MapMode"), 50, 60); - s = wxT("Scaling test page"); break; - case 6: + case Page_Bitmaps: dc.DrawIcon( wxICON(sample), 10, 10 ); dc.DrawBitmap ( wxBitmap(svgbitmap_xpm), 50,15); - s = wxT("Icon and Bitmap "); break; - case 7: + case Page_Clipping: dc.SetTextForeground(wxT("RED")); dc.DrawText(wxT("Red = Clipping Off"), 30, 5); dc.SetTextForeground(wxT("GREEN")); @@ -419,10 +453,9 @@ void MyPage::OnDraw(wxDC& dc) dc.DestroyClippingRegion(); */ - s = wxT("Clipping region"); break; - case 8: + case Page_TextPos: wxString txtStr; wxCoord txtX, txtY, txtW, txtH, txtDescent, txtEL; wxCoord txtPad = 0; @@ -461,10 +494,9 @@ void MyPage::OnDraw(wxDC& dc) dc.DrawLine(txtX - padding, txtY, txtX - padding + lenH, txtY + lenH); dc.DrawLine(txtX - padding + lenH, txtY + lenH, txtX - padding + lenH + lenW, txtY + (lenH - lenW)); // bottom dc.DrawRotatedText(txtStr, txtX, txtY, 45); - s = wxT("Text position test page"); break; } - wxLogStatus("%s", s); + wxLogStatus("%s", pageDescriptions[m_index]); }