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.
This commit is contained in:
@@ -81,6 +81,9 @@ public:
|
|||||||
void OnLeftClick(wxMouseEvent& event);
|
void OnLeftClick(wxMouseEvent& event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Fill m_book with the information about all the displays.
|
||||||
|
void PopuplateWithDisplayInfo();
|
||||||
|
|
||||||
#if wxUSE_DISPLAY
|
#if wxUSE_DISPLAY
|
||||||
// convert video mode to textual description
|
// convert video mode to textual description
|
||||||
wxString VideoModeToText(const wxVideoMode& mode);
|
wxString VideoModeToText(const wxVideoMode& mode);
|
||||||
@@ -233,6 +236,11 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
|
|||||||
|
|
||||||
// create child controls
|
// create child controls
|
||||||
m_book = new wxBookCtrl(this, wxID_ANY);
|
m_book = new wxBookCtrl(this, wxID_ANY);
|
||||||
|
PopuplateWithDisplayInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyFrame::PopuplateWithDisplayInfo()
|
||||||
|
{
|
||||||
const size_t countDpy = wxDisplay::GetCount();
|
const size_t countDpy = wxDisplay::GetCount();
|
||||||
for ( size_t nDpy = 0; nDpy < countDpy; nDpy++ )
|
for ( size_t nDpy = 0; nDpy < countDpy; nDpy++ )
|
||||||
{
|
{
|
||||||
@@ -426,16 +434,8 @@ void MyFrame::OnLeftClick(wxMouseEvent& event)
|
|||||||
|
|
||||||
void MyFrame::OnDisplayChanged(wxDisplayChangedEvent& event)
|
void MyFrame::OnDisplayChanged(wxDisplayChangedEvent& event)
|
||||||
{
|
{
|
||||||
// update the current mode text
|
m_book->DeleteAllPages();
|
||||||
for ( size_t n = 0; n < m_book->GetPageCount(); n++ )
|
PopuplateWithDisplayInfo();
|
||||||
{
|
|
||||||
wxStaticText *label = wxDynamicCast(m_book->GetPage(n)->
|
|
||||||
FindWindow(Display_CurrentMode),
|
|
||||||
wxStaticText);
|
|
||||||
if ( label )
|
|
||||||
label->SetLabel(VideoModeToText(wxDisplay(n).GetCurrentMode()));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
wxLogStatus(this, "Display resolution was changed.");
|
wxLogStatus(this, "Display resolution was changed.");
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user