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