8
8
#include " GOMidiListDialog.h"
9
9
10
10
#include < wx/button.h>
11
- #include < wx/listctrl.h>
12
11
#include < wx/sizer.h>
13
12
13
+ #include " gui/size/GOAdditionalSizeKeeperProxy.h"
14
+ #include " gui/wxcontrols/GOGrid.h"
14
15
#include " midi/objects/GOMidiObject.h"
15
16
16
17
#include " GOEvent.h"
17
18
19
+ enum {
20
+ ID_LIST = 200 ,
21
+ ID_EDIT,
22
+ ID_STATUS,
23
+ ID_BUTTON,
24
+ ID_BUTTON_LAST = ID_BUTTON + 2 ,
25
+ };
26
+
18
27
BEGIN_EVENT_TABLE (GOMidiListDialog, GOSimpleDialog)
19
- EVT_LIST_ITEM_SELECTED (ID_LIST, GOMidiListDialog::OnObjectClick)
20
- EVT_LIST_ITEM_ACTIVATED (ID_LIST, GOMidiListDialog::OnObjectDoubleClick)
28
+ EVT_GRID_CMD_SELECT_CELL (ID_LIST, GOMidiListDialog::OnObjectClick)
29
+ EVT_GRID_CMD_CELL_LEFT_DCLICK (ID_LIST, GOMidiListDialog::OnObjectDoubleClick)
21
30
EVT_BUTTON(ID_STATUS, GOMidiListDialog::OnStatus)
22
31
EVT_BUTTON(ID_EDIT, GOMidiListDialog::OnEdit)
23
32
EVT_COMMAND_RANGE(
24
33
ID_BUTTON, ID_BUTTON_LAST, wxEVT_BUTTON, GOMidiListDialog::OnButton)
25
34
END_EVENT_TABLE()
26
35
36
+ enum { GRID_COL_TYPE = 0 , GRID_COL_ELEMENT };
37
+
27
38
GOMidiListDialog::GOMidiListDialog (
28
39
GODocumentBase *doc,
29
40
wxWindow *parent,
30
41
GODialogSizeSet &dialogSizes,
31
- const std::vector<GOMidiObject *> &midi_elements )
42
+ const std::vector<GOMidiObject *> &midiObjects )
32
43
: GOSimpleDialog(
33
44
parent,
34
45
wxT (" MIDI Objects" ),
35
46
_(" MIDI Objects" ),
36
47
dialogSizes,
37
48
wxEmptyString,
38
49
0,
39
- wxOK | wxHELP),
40
- GOView(doc, this ) {
50
+ wxCLOSE | wxHELP),
51
+ GOView(doc, this ),
52
+ r_MidiObjects(midiObjects) {
41
53
wxBoxSizer *topSizer = new wxBoxSizer (wxVERTICAL);
42
54
topSizer->AddSpacer (5 );
43
55
44
- m_Objects = new wxListView (
45
- this ,
46
- ID_LIST,
47
- wxDefaultPosition,
48
- wxSize (300 , 600 ),
49
- wxLC_REPORT | wxLC_SINGLE_SEL | wxLC_HRULES | wxLC_VRULES);
50
- m_Objects->InsertColumn (0 , _ (" Type" ));
51
- m_Objects->InsertColumn (1 , _ (" Element" ));
56
+ m_Objects = new GOGrid (this , ID_LIST, wxDefaultPosition, wxSize (250 , 200 ));
57
+ m_Objects->CreateGrid (0 , 2 , wxGrid::wxGridSelectRows);
58
+ m_Objects->HideRowLabels ();
59
+ m_Objects->EnableEditing (false );
60
+ m_Objects->SetColLabelValue (GRID_COL_TYPE, _ (" Type" ));
61
+ m_Objects->SetColLabelValue (GRID_COL_ELEMENT, _ (" Element" ));
62
+ m_Objects->SetColSize (GRID_COL_TYPE, 100 );
63
+ m_Objects->SetColSize (GRID_COL_ELEMENT, 100 );
64
+
52
65
topSizer->Add (m_Objects, 1 , wxEXPAND | wxALL, 5 );
53
66
54
67
wxBoxSizer *sizer = new wxBoxSizer (wxHORIZONTAL);
@@ -69,61 +82,93 @@ GOMidiListDialog::GOMidiListDialog(
69
82
buttons->Add (m_Status);
70
83
topSizer->Add (buttons, 0 , wxALIGN_RIGHT | wxALL, 1 );
71
84
72
- for (unsigned i = 0 ; i < midi_elements.size (); i++) {
73
- GOMidiObject *obj = midi_elements[i];
85
+ topSizer->AddSpacer (5 );
86
+ LayoutWithInnerSizer (topSizer);
87
+ }
74
88
75
- m_Objects->InsertItem (i, obj->GetMidiTypeName ());
76
- m_Objects->SetItemPtrData (i, (wxUIntPtr)obj);
77
- m_Objects->SetItem (i, 1 , obj->GetName ());
78
- }
89
+ static const wxString WX_GRID_MIDI_OBJECTS = wxT(" GridMidiObjects" );
79
90
80
- m_Objects->SetColumnWidth (0 , wxLIST_AUTOSIZE);
81
- m_Objects->SetColumnWidth (1 , wxLIST_AUTOSIZE);
91
+ void GOMidiListDialog::ApplyAdditionalSizes (
92
+ const GOAdditionalSizeKeeper &sizeKeeper) {
93
+ GOAdditionalSizeKeeperProxy proxyMidiObjects (
94
+ const_cast <GOAdditionalSizeKeeper &>(sizeKeeper), WX_GRID_MIDI_OBJECTS);
82
95
83
- topSizer->AddSpacer (5 );
84
- LayoutWithInnerSizer (topSizer);
96
+ m_Objects->ApplyColumnSizes (proxyMidiObjects);
97
+ }
98
+
99
+ void GOMidiListDialog::CaptureAdditionalSizes (
100
+ GOAdditionalSizeKeeper &sizeKeeper) const {
101
+ GOAdditionalSizeKeeperProxy proxyMidiObjects (
102
+ sizeKeeper, WX_GRID_MIDI_OBJECTS);
103
+
104
+ m_Objects->CaptureColumnSizes (proxyMidiObjects);
105
+ }
106
+
107
+ bool GOMidiListDialog::TransferDataToWindow () {
108
+ unsigned oldRowCnt = m_Objects->GetNumberRows ();
109
+ unsigned newRowCnt = r_MidiObjects.size ();
110
+
111
+ if (oldRowCnt)
112
+ m_Objects->DeleteRows (0 , oldRowCnt);
113
+
114
+ m_Objects->AppendRows (newRowCnt);
115
+ for (unsigned i = 0 ; i < newRowCnt; i++) {
116
+ GOMidiObject *obj = r_MidiObjects[i];
117
+
118
+ m_Objects->SetCellValue (i, GRID_COL_TYPE, obj->GetMidiTypeName ());
119
+ m_Objects->SetCellValue (i, GRID_COL_ELEMENT, obj->GetName ());
120
+ }
121
+ return true ;
85
122
}
86
123
87
- GOMidiListDialog::~GOMidiListDialog () {}
124
+ GOMidiObject *GOMidiListDialog::GetSelectedObject () const {
125
+ return r_MidiObjects[m_Objects->GetGridCursorRow ()];
126
+ }
88
127
89
128
void GOMidiListDialog::OnButton (wxCommandEvent &event) {
90
- GOMidiObject *obj
91
- = (GOMidiObject *)m_Objects->GetItemData (m_Objects->GetFirstSelected ());
129
+ GOMidiObject *obj = GetSelectedObject ();
92
130
obj->TriggerElementActions (event.GetId () - ID_BUTTON);
93
131
}
94
132
133
+ void GOMidiListDialog::OnObjectClick (wxGridEvent &event) {
134
+ int index = event.GetRow ();
135
+ bool isAnySelected = index >= 0 ;
136
+
137
+ m_Edit->Enable (isAnySelected);
138
+ m_Status->Enable (isAnySelected);
139
+ if (isAnySelected) {
140
+ m_Objects->SelectRow (index );
141
+ GOMidiObject *obj = r_MidiObjects[index ];
142
+ std::vector<wxString> actions = obj->GetElementActions ();
143
+
144
+ for (unsigned i = 0 ; i < m_Buttons.size (); i++)
145
+ if (i < actions.size ()) {
146
+ m_Buttons[i]->SetLabel (actions[i]);
147
+ m_Buttons[i]->Show ();
148
+ } else
149
+ m_Buttons[i]->Hide ();
150
+ }
151
+ Layout ();
152
+ event.StopPropagation ();
153
+ }
154
+
155
+ void GOMidiListDialog::OnObjectDoubleClick (wxGridEvent &event) {
156
+ GOMidiObject *obj = GetSelectedObject ();
157
+
158
+ obj->ShowConfigDialog ();
159
+ }
160
+
95
161
void GOMidiListDialog::OnStatus (wxCommandEvent &event) {
96
- GOMidiObject *obj
97
- = (GOMidiObject *)m_Objects->GetItemData (m_Objects->GetFirstSelected ());
162
+ GOMidiObject *obj = GetSelectedObject ();
98
163
wxString status = obj->GetElementStatus ();
164
+
99
165
GOMessageBox (
100
166
wxString::Format (_ (" Status: %s" ), status),
101
167
obj->GetMidiTypeName () + _ (" " ) + obj->GetName (),
102
168
wxOK);
103
169
}
104
170
105
- void GOMidiListDialog::OnObjectClick (wxListEvent &event) {
106
- m_Edit->Enable ();
107
- m_Status->Enable ();
108
- GOMidiObject *obj
109
- = (GOMidiObject *)m_Objects->GetItemData (m_Objects->GetFirstSelected ());
110
- std::vector<wxString> actions = obj->GetElementActions ();
111
- for (unsigned i = 0 ; i < m_Buttons.size (); i++)
112
- if (i < actions.size ()) {
113
- m_Buttons[i]->SetLabel (actions[i]);
114
- m_Buttons[i]->Show ();
115
- } else
116
- m_Buttons[i]->Hide ();
117
- Layout ();
118
- }
119
-
120
- void GOMidiListDialog::OnObjectDoubleClick (wxListEvent &event) {
121
- GOMidiObject *obj
122
- = (GOMidiObject *)m_Objects->GetItemData (m_Objects->GetFirstSelected ());
123
- obj->ShowConfigDialog ();
124
- }
125
-
126
171
void GOMidiListDialog::OnEdit (wxCommandEvent &event) {
127
- wxListEvent listevent;
172
+ wxGridEvent listevent;
128
173
OnObjectDoubleClick (listevent);
129
174
}
0 commit comments