Skip to content

Commit f6f9fcd

Browse files
committed
Fixed nested scrolling in the MidiObject dialog on macOs #1972
1 parent b831e56 commit f6f9fcd

File tree

3 files changed

+94
-70
lines changed

3 files changed

+94
-70
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
- Fixed nested scrolling in the MidiObject dialog on macOs https://github.com/GrandOrgue/grandorgue/issues/1972
12
- Increased the maximum number of user-defined temperaments to 999 https://github.com/GrandOrgue/grandorgue/issues/1982
23
# 3.15.4 (2024-12-20)
34
- Eliminated a MacOs debug alert when opening a settings dialog https://github.com/GrandOrgue/grandorgue/issues/2003

src/grandorgue/gui/dialogs/GOMidiListDialog.cpp

+76-51
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,59 @@
88
#include "GOMidiListDialog.h"
99

1010
#include <wx/button.h>
11-
#include <wx/listctrl.h>
1211
#include <wx/sizer.h>
1312

13+
#include "gui/wxcontrols/GOGrid.h"
1414
#include "midi/objects/GOMidiObject.h"
1515

1616
#include "GOEvent.h"
1717

18+
enum {
19+
ID_LIST = 200,
20+
ID_EDIT,
21+
ID_STATUS,
22+
ID_BUTTON,
23+
ID_BUTTON_LAST = ID_BUTTON + 2,
24+
};
25+
1826
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)
2129
EVT_BUTTON(ID_STATUS, GOMidiListDialog::OnStatus)
2230
EVT_BUTTON(ID_EDIT, GOMidiListDialog::OnEdit)
2331
EVT_COMMAND_RANGE(
2432
ID_BUTTON, ID_BUTTON_LAST, wxEVT_BUTTON, GOMidiListDialog::OnButton)
2533
END_EVENT_TABLE()
2634

35+
enum { GRID_COL_TYPE = 0, GRID_COL_ELEMENT };
36+
2737
GOMidiListDialog::GOMidiListDialog(
2838
GODocumentBase *doc,
2939
wxWindow *parent,
3040
GODialogSizeSet &dialogSizes,
31-
const std::vector<GOMidiObject *> &midi_elements)
41+
const std::vector<GOMidiObject *> &midiObjects)
3242
: GOSimpleDialog(
3343
parent,
3444
wxT("MIDI Objects"),
3545
_("MIDI Objects"),
3646
dialogSizes,
3747
wxEmptyString,
3848
0,
39-
wxOK | wxHELP),
40-
GOView(doc, this) {
49+
wxCLOSE | wxHELP),
50+
GOView(doc, this),
51+
r_MidiObjects(midiObjects) {
4152
wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
4253
topSizer->AddSpacer(5);
4354

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+
5264
topSizer->Add(m_Objects, 1, wxEXPAND | wxALL, 5);
5365

5466
wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
@@ -69,61 +81,74 @@ GOMidiListDialog::GOMidiListDialog(
6981
buttons->Add(m_Status);
7082
topSizer->Add(buttons, 0, wxALIGN_RIGHT | wxALL, 1);
7183

72-
for (unsigned i = 0; i < midi_elements.size(); i++) {
73-
GOMidiObject *obj = midi_elements[i];
84+
topSizer->AddSpacer(5);
85+
LayoutWithInnerSizer(topSizer);
86+
}
7487

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();
7991

80-
m_Objects->SetColumnWidth(0, wxLIST_AUTOSIZE);
81-
m_Objects->SetColumnWidth(1, wxLIST_AUTOSIZE);
92+
if (oldRowCnt)
93+
m_Objects->DeleteRows(0, oldRowCnt);
8294

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;
85103
}
86104

87-
GOMidiListDialog::~GOMidiListDialog() {}
105+
GOMidiObject *GOMidiListDialog::GetSelectedObject() const {
106+
return r_MidiObjects[m_Objects->GetGridCursorRow()];
107+
}
88108

89109
void GOMidiListDialog::OnButton(wxCommandEvent &event) {
90-
GOMidiObject *obj
91-
= (GOMidiObject *)m_Objects->GetItemData(m_Objects->GetFirstSelected());
110+
GOMidiObject *obj = GetSelectedObject();
92111
obj->TriggerElementActions(event.GetId() - ID_BUTTON);
93112
}
94113

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+
95141
void GOMidiListDialog::OnStatus(wxCommandEvent &event) {
96-
GOMidiObject *obj
97-
= (GOMidiObject *)m_Objects->GetItemData(m_Objects->GetFirstSelected());
142+
GOMidiObject *obj = GetSelectedObject();
98143
wxString status = obj->GetElementStatus();
144+
99145
GOMessageBox(
100146
wxString::Format(_("Status: %s"), status),
101147
obj->GetMidiType() + _(" ") + obj->GetMidiName(),
102148
wxOK);
103149
}
104150

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-
126151
void GOMidiListDialog::OnEdit(wxCommandEvent &event) {
127-
wxListEvent listevent;
152+
wxGridEvent listevent;
128153
OnObjectDoubleClick(listevent);
129154
}

src/grandorgue/gui/dialogs/GOMidiListDialog.h

+17-19
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,37 @@
1414
#include "document-base/GOView.h"
1515

1616
class wxButton;
17-
class wxListEvent;
18-
class wxListView;
17+
class wxGridEvent;
1918

19+
class GOGrid;
2020
class GOMidiObject;
2121

2222
class GOMidiListDialog : public GOSimpleDialog, public GOView {
2323
private:
24-
wxListView *m_Objects;
24+
const std::vector<GOMidiObject *> &r_MidiObjects;
25+
26+
GOGrid *m_Objects;
2527
wxButton *m_Edit;
2628
wxButton *m_Status;
2729
std::vector<wxButton *> m_Buttons;
2830

29-
enum {
30-
ID_LIST = 200,
31-
ID_EDIT,
32-
ID_STATUS,
33-
ID_BUTTON,
34-
ID_BUTTON_LAST = ID_BUTTON + 2,
35-
};
36-
37-
void OnObjectClick(wxListEvent &event);
38-
void OnObjectDoubleClick(wxListEvent &event);
39-
void OnEdit(wxCommandEvent &event);
40-
void OnStatus(wxCommandEvent &event);
41-
void OnButton(wxCommandEvent &event);
42-
4331
public:
4432
GOMidiListDialog(
4533
GODocumentBase *doc,
4634
wxWindow *parent,
4735
GODialogSizeSet &dialogSizes,
48-
const std::vector<GOMidiObject *> &midi_elements);
49-
~GOMidiListDialog();
36+
const std::vector<GOMidiObject *> &midiObjects);
37+
38+
private:
39+
bool TransferDataToWindow() override;
40+
41+
GOMidiObject *GetSelectedObject() const;
42+
43+
void OnObjectClick(wxGridEvent &event);
44+
void OnObjectDoubleClick(wxGridEvent &event);
45+
void OnEdit(wxCommandEvent &event);
46+
void OnStatus(wxCommandEvent &event);
47+
void OnButton(wxCommandEvent &event);
5048

5149
DECLARE_EVENT_TABLE()
5250
};

0 commit comments

Comments
 (0)