Advertisement
josuegomes

Untitled

Sep 11th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.90 KB | None | 0 0
  1.  
  2. #include <wx/wx.h>
  3.  
  4. #include <wx/dataview.h>
  5.  
  6. const int ID_SHOW_DIALOG = wxID_HIGHEST + 1;
  7. const int ID_MY_LIST = wxID_HIGHEST + 2;
  8. const int ID_ADD_BUTTON = wxID_HIGHEST + 3;
  9. const int ID_CLOSE_BUTTON = wxID_HIGHEST + 4;
  10.  
  11. class MyDialog: public wxDialog
  12. {
  13.     DECLARE_CLASS(MyDialog)
  14.     DECLARE_EVENT_TABLE()
  15. public:
  16.     MyDialog();
  17.     MyDialog(wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& caption = _T("Error"),
  18.         const wxPoint& pos = wxDefaultPosition,
  19.         const wxSize& size = wxSize(640, 480),
  20.         long style = wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU);
  21.  
  22.     bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& caption = _T("Error"),
  23.         const wxPoint& pos = wxDefaultPosition,
  24.         const wxSize& size = wxSize(640, 480),
  25.         long style = wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU);
  26.  
  27. protected:
  28.     void OnAdd(wxCommandEvent& event);
  29.     void OnClose(wxCommandEvent& event);
  30.  
  31.     wxDataViewListCtrl* listCtrl;
  32.     wxDataViewColumn *col1;
  33.     wxDataViewColumn *col2;
  34. };
  35.  
  36. IMPLEMENT_CLASS(MyDialog, wxDialog);
  37.  
  38. BEGIN_EVENT_TABLE(MyDialog, wxDialog)
  39.     EVT_BUTTON(ID_ADD_BUTTON, MyDialog::OnAdd)
  40.     EVT_BUTTON(ID_CLOSE_BUTTON, MyDialog::OnClose)
  41. END_EVENT_TABLE()
  42.  
  43. MyDialog::MyDialog(wxWindow* parent, wxWindowID id, const wxString& caption,
  44.         const wxPoint& pos, const wxSize& size, long style)
  45. {
  46.     Create(parent, id, caption, pos, size, style);
  47. }
  48.  
  49. bool MyDialog::Create(wxWindow* parent, wxWindowID id, const wxString& caption,
  50.         const wxPoint& pos, const wxSize& size, long style)
  51. {
  52.     if (!wxDialog::Create(parent, id, caption, pos, size, style))
  53.         return false;
  54.    
  55.     wxBoxSizer* sizer1 = new wxBoxSizer(wxVERTICAL);
  56.     this->SetSizer(sizer1);
  57.  
  58.     wxBoxSizer* sizer2 = new wxBoxSizer(wxVERTICAL);
  59.     sizer1->Add(sizer2, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
  60.  
  61.     listCtrl = new wxDataViewListCtrl(this, ID_MY_LIST, wxDefaultPosition, wxSize(300, 300));
  62.     col1 = listCtrl->AppendTextColumn(_T("Col1"), wxDATAVIEW_CELL_EDITABLE, 300, wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE);
  63.     col2 = listCtrl->AppendTextColumn(_T("Col2"), wxDATAVIEW_CELL_EDITABLE, -1, wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE);
  64.     sizer2->Add(listCtrl);
  65.  
  66.     wxButton* addButton = new wxButton(this, ID_ADD_BUTTON, _T("Add"));
  67.     sizer2->Add(addButton);
  68.  
  69.     wxButton* closeButton = new wxButton(this, ID_CLOSE_BUTTON, _T("Close"));
  70.     sizer2->Add(closeButton);
  71.  
  72.     return true;
  73. }
  74.  
  75. void MyDialog::OnAdd(wxCommandEvent& event)
  76. {
  77.     wxVector<wxVariant> mapping;
  78.     mapping.push_back("");
  79.     mapping.push_back("");
  80.    
  81.     listCtrl->AppendItem(mapping);
  82.  
  83.     int index = listCtrl->GetItemCount() - 1;
  84.     if (index != wxNOT_FOUND) {
  85.         wxDataViewItem item = listCtrl->RowToItem(index);
  86.         // listCtrl->EnsureVisible(item);
  87.         listCtrl->EditItem(item, col1);
  88.     }
  89. }
  90.  
  91. void MyDialog::OnClose(wxCommandEvent& event)
  92. {
  93.     Close();
  94. }
  95.  
  96. class MainApp: public wxApp
  97. {
  98. public:
  99.     virtual bool OnInit();
  100. };
  101.  
  102. IMPLEMENT_APP(MainApp)
  103.  
  104. class MainFrame: public wxFrame
  105. {
  106. public:
  107.     MainFrame(const wxString &title, const wxPoint &pos, const wxSize &size);
  108.  
  109.     void ShowDialog(wxCommandEvent& event);
  110.  
  111.     wxMenuBar *MainMenu;
  112.  
  113.     DECLARE_EVENT_TABLE()
  114. };
  115.  
  116. BEGIN_EVENT_TABLE (MainFrame, wxFrame)
  117.     EVT_MENU(ID_SHOW_DIALOG, MainFrame::ShowDialog)
  118. END_EVENT_TABLE()
  119.  
  120. bool MainApp::OnInit()
  121. {
  122.     MainFrame *MainWin = new MainFrame(
  123.         _("Bug"), wxPoint(1, 1), wxSize(300, 200));
  124.     MainWin->Show(TRUE);
  125.     SetTopWindow(MainWin);
  126.     return TRUE;
  127. }
  128.  
  129. MainFrame::MainFrame(const wxString &title, const wxPoint &pos, const wxSize &size)
  130. : wxFrame((wxFrame*) 0, -1, title, pos, size)
  131. {
  132.     CreateStatusBar(2);
  133.  
  134.     MainMenu = new wxMenuBar();
  135.     wxMenu *menu = new wxMenu();
  136.  
  137.     menu->Append(ID_SHOW_DIALOG,
  138.         _("&Show Dialog"), _("Show fault dialog"));
  139.  
  140.     MainMenu->Append(menu, _("&Menu"));
  141.     SetMenuBar(MainMenu);
  142. }
  143.  
  144.  
  145. void MainFrame::ShowDialog(wxCommandEvent& WXUNUSED(event))
  146. {
  147.     MyDialog *dialog = new MyDialog(this);
  148.     dialog->ShowModal();
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement