+void MyFrame::OnColumnSetting(wxCommandEvent& event)
+{
+ wxArrayInt columns;
+ int flag = 0;
+ bool header = false, minwidth = false;
+ wxString msg;
+
+ switch (event.GetId())
+ {
+ case ID_RESIZEABLE_COLUMNS:
+ flag = wxDATAVIEW_COL_RESIZABLE;
+ columns = GetFlaggedColumns(flag);
+ break;
+ case ID_SORTABLE_COLUMNS:
+ flag = wxDATAVIEW_COL_SORTABLE;
+ columns = GetFlaggedColumns(flag);
+ break;
+ case ID_HIDDEN_COLUMNS:
+ flag = wxDATAVIEW_COL_HIDDEN;
+ columns = GetFlaggedColumns(flag);
+ break;
+
+ case ID_CHOOSE_COLUMN_ALIGNMENT:
+ msg = wxT("Select the columns whose headers' alignment will be modified.");
+ header = true;
+ break;
+ case ID_CHOOSE_CONTENTS_ALIGNMENT:
+ msg = wxT("Select the columns whose contents' alignment will be modified.");
+ header = false;
+ break;
+
+ case ID_SET_MINWIDTH:
+ msg = wxT("Please provide the new minimal width:");
+ minwidth = true;
+ break;
+ case ID_SET_WIDTH:
+ msg = wxT("Please provide the new width:");
+ minwidth = false;
+ break;
+ }
+
+ // get column titles:
+
+ wxArrayString choices;
+ for (size_t i=0; i<dataview_left->GetColumnCount(); i++)
+ choices.Add(dataview_left->GetColumn(i)->GetTitle());
+
+ // ask the user
+ wxGetMultipleChoices(
+ columns,
+ wxT("Choose the columns to which apply the change."),
+ wxT("Choose the column"),
+ choices,
+ this);
+
+ switch (event.GetId())
+ {
+ case ID_RESIZEABLE_COLUMNS:
+ case ID_SORTABLE_COLUMNS:
+ case ID_HIDDEN_COLUMNS:
+ SetFlag(columns, flag);
+ break;
+
+ case ID_CHOOSE_COLUMN_ALIGNMENT:
+ case ID_CHOOSE_CONTENTS_ALIGNMENT:
+ SetAlignment(columns, header, ChooseAlign(msg, header));
+ break;
+
+ case ID_SET_MINWIDTH:
+ case ID_SET_WIDTH:
+ {
+ int def = minwidth ? wxDVC_DEFAULT_MINWIDTH : wxDVC_DEFAULT_WIDTH;
+
+ msg << wxT("\nNOTE: all non-selected columns will be reset to a width of ")
+ << def << wxT(" pixels.");
+
+ long ret =
+ wxGetNumberFromUser(msg, wxT("New value:"), wxT("Modify width"),
+ def, 0, 300, this);
+
+ if (ret != -1)
+ SetWidth(columns, minwidth, ret);
+ }
+ break;
+ }
+
+ dataview_left->Refresh();
+}
+
+wxAlignment MyFrame::ChooseAlign(const wxString &msg, bool onlyHorizontal)
+{
+ const wxString choices[] =
+ {
+ wxT("Left"),
+ wxT("Center horizontally"),
+ wxT("Right"),
+ wxT("Top"),
+ wxT("Center vertically"),
+ wxT("Bottom"),
+ wxT("Center")
+ };
+
+ wxAlignment flags[] =
+ {
+ wxALIGN_LEFT,
+ wxALIGN_CENTER_HORIZONTAL,
+ wxALIGN_RIGHT,
+ wxALIGN_TOP,
+ wxALIGN_CENTER_VERTICAL,
+ wxALIGN_BOTTOM,
+ wxALIGN_CENTER
+ };
+
+ int n = WXSIZEOF(choices);
+ if (onlyHorizontal)
+ n = 3; // show only the first three choices
+
+ int choice = wxGetSingleChoiceIndex(
+ msg + wxT("\nNOTE: _all_ non-selected column's alignment will be reset to wxALIGN_LEFT!"),
+ wxT("Alignment"),
+ n, choices,
+ this);
+
+ if (choice == wxNOT_FOUND)
+ return wxALIGN_LEFT;
+
+ return flags[choice];
+}
+
+void MyFrame::SetFlag(const wxArrayInt &idx, int toadd)
+{
+ for (size_t i=0; i<dataview_left->GetColumnCount(); i++)
+ {
+ int current = dataview_left->GetColumn(i)->GetFlags();
+
+ if (idx.Index(i) != wxNOT_FOUND)
+ dataview_left->GetColumn(i)->SetFlags(current | toadd);
+ else
+ dataview_left->GetColumn(i)->SetFlags(current & ~toadd);
+ }
+}
+
+wxArrayInt MyFrame::GetFlaggedColumns(int flag)
+{
+ wxArrayInt ret;
+ for (size_t i=0; i<dataview_left->GetColumnCount(); i++)
+ if (dataview_left->GetColumn(i)->GetFlags() & flag)
+ ret.Add(i);
+ return ret;
+}
+
+void MyFrame::SetAlignment(const wxArrayInt &idx, bool header, wxAlignment align)
+{
+ // set to DEFAULT_ALIGN all columns except those
+ // contained in 'idx' which are set to 'align'
+
+ for (size_t i=0; i<dataview_left->GetColumnCount(); i++)
+ {
+ wxAlignment toset = DEFAULT_ALIGN;
+ if (idx.Index(i) != wxNOT_FOUND)
+ toset = align;
+
+ if (header)
+ dataview_left->GetColumn(i)->SetAlignment(toset);
+ else
+ dataview_left->GetColumn(i)->GetRenderer()->SetAlignment(toset);
+ }
+}
+
+void MyFrame::SetWidth(const wxArrayInt &idx, bool minwidth, int width)
+{
+ // set to wxDVC_DEFAULT_WIDTH wide all columns except those
+ // contained in 'idx' which are set to 'width'
+
+ for (size_t i=0; i<dataview_left->GetColumnCount(); i++)
+ {
+ int toset = minwidth ? wxDVC_DEFAULT_MINWIDTH : wxDVC_DEFAULT_WIDTH;
+ if (idx.Index(i) != wxNOT_FOUND)
+ toset = width;
+
+ if (minwidth)
+ dataview_left->GetColumn(i)->SetMinWidth(toset);
+ else
+ dataview_left->GetColumn(i)->SetWidth(toset);
+ }
+}
+
+