Add option to change layout direction in dataview sample

See #19325.
This commit is contained in:
Artur Wieczorek
2021-11-21 19:06:51 +01:00
parent 18bbfd8c38
commit 838a1a7640

View File

@@ -87,6 +87,7 @@ private:
void OnSetForegroundColour(wxCommandEvent& event);
void OnIncIndent(wxCommandEvent& event);
void OnDecIndent(wxCommandEvent& event);
void OnToggleLayoutDirection(wxCommandEvent& evt);
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
@@ -408,6 +409,7 @@ enum
ID_STYLE_MENU,
ID_INC_INDENT,
ID_DEC_INDENT,
ID_LAYOUT_DIR,
// file menu
//ID_SINGLE, wxDV_SINGLE==0 so it's always present
@@ -487,6 +489,7 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
#endif // wxHAS_GENERIC_DATAVIEWCTRL
EVT_MENU( ID_INC_INDENT, MyFrame::OnIncIndent )
EVT_MENU( ID_DEC_INDENT, MyFrame::OnDecIndent )
EVT_MENU( ID_LAYOUT_DIR, MyFrame::OnToggleLayoutDirection)
EVT_NOTEBOOK_PAGE_CHANGED( wxID_ANY, MyFrame::OnPageChanged )
@@ -608,6 +611,9 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int
file_menu->Append(ID_INC_INDENT, "&Increase indent\tCtrl-I");
file_menu->Append(ID_DEC_INDENT, "&Decrease indent\tShift-Ctrl-I");
file_menu->AppendSeparator();
file_menu->AppendCheckItem(ID_LAYOUT_DIR, "Toggle &layout direction\tCtrl-L");
file_menu->Check(ID_LAYOUT_DIR, GetLayoutDirection() == wxLayout_RightToLeft);
file_menu->AppendSeparator();
file_menu->Append(ID_EXIT, "E&xit");
wxMenu *about_menu = new wxMenu;
@@ -1211,6 +1217,19 @@ void MyFrame::OnDecIndent(wxCommandEvent& WXUNUSED(event))
wxLogMessage("Indent is now %d", dvc->GetIndent());
}
void MyFrame::OnToggleLayoutDirection(wxCommandEvent& WXUNUSED(evt))
{
wxLayoutDirection dir = GetLayoutDirection() == wxLayout_LeftToRight
? wxLayout_RightToLeft : wxLayout_LeftToRight;
SetLayoutDirection(dir);
GetStatusBar()->SetLayoutDirection(dir);
for ( int i = 0; i < Page_Max; i++ )
{
m_ctrl[i]->SetLayoutDirection(dir);
}
m_log->SetLayoutDirection(dir);
}
void MyFrame::OnPageChanged( wxBookCtrlEvent& WXUNUSED(event) )
{
unsigned int nPanel = m_notebook->GetSelection();