From 8927d7b092d6014eea7dd4d84eb72edf19c36781 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 30 Mar 2019 14:21:01 +0100 Subject: [PATCH] Update displays sample correctly when displays change wxEVT_DISPLAY_CHANGED notifies not only about the change of resolution of a display, but also about removal or addition of a new display, so we need to completely repopulate the notebook showing the displays on receiving it. --- samples/display/display.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/samples/display/display.cpp b/samples/display/display.cpp index ed5420d147..2d5b264dcb 100644 --- a/samples/display/display.cpp +++ b/samples/display/display.cpp @@ -81,6 +81,9 @@ public: void OnLeftClick(wxMouseEvent& event); private: + // Fill m_book with the information about all the displays. + void PopuplateWithDisplayInfo(); + #if wxUSE_DISPLAY // convert video mode to textual description wxString VideoModeToText(const wxVideoMode& mode); @@ -233,6 +236,11 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size, // create child controls m_book = new wxBookCtrl(this, wxID_ANY); + PopuplateWithDisplayInfo(); +} + +void MyFrame::PopuplateWithDisplayInfo() +{ const size_t countDpy = wxDisplay::GetCount(); for ( size_t nDpy = 0; nDpy < countDpy; nDpy++ ) { @@ -426,16 +434,8 @@ void MyFrame::OnLeftClick(wxMouseEvent& event) void MyFrame::OnDisplayChanged(wxDisplayChangedEvent& event) { - // update the current mode text - for ( size_t n = 0; n < m_book->GetPageCount(); n++ ) - { - wxStaticText *label = wxDynamicCast(m_book->GetPage(n)-> - FindWindow(Display_CurrentMode), - wxStaticText); - if ( label ) - label->SetLabel(VideoModeToText(wxDisplay(n).GetCurrentMode())); - } - + m_book->DeleteAllPages(); + PopuplateWithDisplayInfo(); wxLogStatus(this, "Display resolution was changed.");