Skip to content

Commit 3ea936d

Browse files
authored
Merge pull request #330 from calband/issues/picker_crashed
Issues/picker crashed
2 parents 7c2d236 + 1bfbcfe commit 3ea936d

File tree

7 files changed

+205
-140
lines changed

7 files changed

+205
-140
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ add_executable (
228228
${CMAKE_CURRENT_SOURCE_DIR}/src/FieldControlsToolBar.h
229229
${CMAKE_CURRENT_SOURCE_DIR}/src/FieldThumbnailBrowser.cpp
230230
${CMAKE_CURRENT_SOURCE_DIR}/src/FieldThumbnailBrowser.h
231+
${CMAKE_CURRENT_SOURCE_DIR}/src/PointPicker.cpp
232+
${CMAKE_CURRENT_SOURCE_DIR}/src/PointPicker.h
231233
${CMAKE_CURRENT_SOURCE_DIR}/src/PreferencesContCellSetup.cpp
232234
${CMAKE_CURRENT_SOURCE_DIR}/src/PreferencesContCellSetup.h
233235
${CMAKE_CURRENT_SOURCE_DIR}/src/PreferencesDrawingSetup.cpp

src/CalChartFrame.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "FieldCanvas.h"
3737
#include "FieldControlsToolBar.h"
3838
#include "FieldThumbnailBrowser.h"
39+
#include "PointPicker.h"
3940
#include "PrintContinuityEditor.h"
4041
#include "TopFrame.h"
4142
#include "TransitionSolverFrame.h"

src/PointPicker.cpp

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
* show_ui.cpp
3+
* Classes for interacting with shows
4+
*/
5+
6+
/*
7+
Copyright (C) 1995-2011 Garrick Brian Meeker, Richard Michael Powell
8+
9+
This program is free software: you can redistribute it and/or modify
10+
it under the terms of the GNU General Public License as published by
11+
the Free Software Foundation, either version 3 of the License, or
12+
(at your option) any later version.
13+
14+
This program is distributed in the hope that it will be useful,
15+
but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
GNU General Public License for more details.
18+
19+
You should have received a copy of the GNU General Public License
20+
along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*/
22+
23+
#include "PointPicker.h"
24+
#include "CalChartToolBar.h"
25+
#include "basic_ui.h"
26+
#include <algorithm>
27+
#include <ctype.h>
28+
#include <wx/spinctrl.h>
29+
#include <wx/statline.h>
30+
31+
class PointPickerView : public wxView {
32+
public:
33+
PointPickerView() = default;
34+
~PointPickerView() = default;
35+
virtual void OnDraw(wxDC* dc) { }
36+
virtual void OnUpdate(wxView* sender, wxObject* hint = (wxObject*)NULL);
37+
};
38+
39+
void PointPickerView::OnUpdate(wxView* sender, wxObject* hint)
40+
{
41+
static_cast<PointPicker*>(GetFrame())->Update();
42+
}
43+
44+
enum {
45+
PointPicker_PointPickerList = 1100,
46+
};
47+
48+
BEGIN_EVENT_TABLE(PointPicker, wxDialog)
49+
EVT_LISTBOX(PointPicker_PointPickerList, PointPicker::PointPickerSelect)
50+
EVT_LISTBOX_DCLICK(PointPicker_PointPickerList, PointPicker::PointPickerAll)
51+
END_EVENT_TABLE()
52+
53+
PointPicker::PointPicker(CalChartDoc& shw, wxWindow* parent, wxWindowID id,
54+
const wxString& caption, const wxPoint& pos,
55+
const wxSize& size, long style)
56+
: super(parent, id, caption, pos, size, style)
57+
, mShow(shw)
58+
, mView(new PointPickerView)
59+
{
60+
// give this a view so it can pick up document changes
61+
mView->SetDocument(&mShow);
62+
mView->SetFrame(this);
63+
64+
CreateControls();
65+
66+
// This fits the dalog to the minimum size dictated by the sizers
67+
GetSizer()->Fit(this);
68+
// This ensures that the dialog cannot be smaller than the minimum size
69+
GetSizer()->SetSizeHints(this);
70+
71+
Center();
72+
}
73+
74+
void PointPicker::CreateControls()
75+
{
76+
SetSizer(VStack([this](auto sizer) {
77+
HStack(sizer, BasicSizerFlags(), [this](auto sizer) {
78+
auto button = CreateButton(this, sizer, BasicSizerFlags(), wxID_OK, "&Close");
79+
button->SetDefault();
80+
CreateButtonWithHandler(this, sizer, BasicSizerFlags(), "&All", [this]() {
81+
mShow.SetSelection(mShow.MakeSelectAll());
82+
});
83+
CreateButtonWithHandler(this, sizer, BasicSizerFlags(), "&None", [this]() {
84+
mShow.SetSelection(mShow.MakeUnselectAll());
85+
});
86+
});
87+
88+
HStack(sizer, BasicSizerFlags(), [this](auto sizer) {
89+
auto counter = 0;
90+
for (auto&& i : GetSymbolsBitmap()) {
91+
auto which = static_cast<SYMBOL_TYPE>(counter++);
92+
CreateBitmapButtonWithHandler(this, sizer, BasicSizerFlags(), i, [this, which]() {
93+
mShow.SetSelection(mShow.GetCurrentSheet()->MakeSelectPointsBySymbol(which));
94+
});
95+
}
96+
});
97+
98+
mList = new wxListBox(this, PointPicker_PointPickerList, wxDefaultPosition,
99+
wxSize(50, 500), 0, NULL, wxLB_EXTENDED);
100+
sizer->Add(mList, wxSizerFlags(0).Border(wxALL, 5).Center());
101+
}));
102+
103+
Update();
104+
}
105+
106+
void PointPicker::PointPickerAll(wxCommandEvent&)
107+
{
108+
mShow.SetSelection(mShow.MakeSelectAll());
109+
}
110+
111+
void PointPicker::PointPickerSelect(wxCommandEvent&)
112+
{
113+
wxArrayInt selections;
114+
size_t n = mList->GetSelections(selections);
115+
116+
mCachedSelection.clear();
117+
for (size_t i = 0; i < n; ++i)
118+
mCachedSelection.insert(selections[i]);
119+
mShow.SetSelection(mCachedSelection);
120+
}
121+
122+
void PointPicker::Update()
123+
{
124+
auto&& tshowLabels = mShow.GetPointLabels();
125+
std::vector<wxString> showLabels(tshowLabels.begin(), tshowLabels.end());
126+
if (mCachedLabels != showLabels) {
127+
mCachedLabels = showLabels;
128+
mList->Clear();
129+
mList->Set(wxArrayString{ mCachedLabels.size(), &mCachedLabels[0] });
130+
}
131+
auto showSelectionList = mShow.GetSelectionList();
132+
if (mCachedSelection != showSelectionList) {
133+
mList->DeselectAll();
134+
mCachedSelection = showSelectionList;
135+
for (auto n = mCachedSelection.begin(); n != mCachedSelection.end(); ++n) {
136+
mList->SetSelection(*n);
137+
}
138+
}
139+
}
140+

src/PointPicker.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* show_ui.h
3+
* Classes for interacting with shows
4+
*/
5+
6+
/*
7+
Copyright (C) 1995-2011 Garrick Brian Meeker, Richard Michael Powell
8+
9+
This program is free software: you can redistribute it and/or modify
10+
it under the terms of the GNU General Public License as published by
11+
the Free Software Foundation, either version 3 of the License, or
12+
(at your option) any later version.
13+
14+
This program is distributed in the hope that it will be useful,
15+
but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
GNU General Public License for more details.
18+
19+
You should have received a copy of the GNU General Public License
20+
along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*/
22+
23+
#pragma once
24+
25+
#include "CalChartDoc.h"
26+
#include <wx/docview.h>
27+
#include <wx/wizard.h>
28+
29+
#include <vector>
30+
31+
class PointPickerView;
32+
33+
class PointPicker : public wxDialog {
34+
using super = wxDialog;
35+
36+
public:
37+
PointPicker(CalChartDoc& shw, wxWindow* parent, wxWindowID id = wxID_ANY,
38+
const wxString& caption = wxT("Select Points"),
39+
const wxPoint& pos = wxDefaultPosition,
40+
const wxSize& size = wxDefaultSize,
41+
long style = wxCAPTION | wxRESIZE_BORDER | wxSYSTEM_MENU);
42+
~PointPicker() = default;
43+
44+
void Update();
45+
46+
private:
47+
CalChartDoc& mShow;
48+
PointPickerView* mView;
49+
wxListBox* mList;
50+
std::vector<wxString> mCachedLabels;
51+
SelectionList mCachedSelection;
52+
53+
void CreateControls();
54+
55+
void PointPickerAll(wxCommandEvent&);
56+
void PointPickerSelect(wxCommandEvent&);
57+
58+
DECLARE_EVENT_TABLE()
59+
};
60+

src/PreferencesGeneralSetup.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ bool GeneralSetup::ClearValuesToDefault()
107107
mConfig.Clear_FieldFramePositionX();
108108
mConfig.Clear_FieldFramePositionY();
109109
mConfig.Clear_UseSprites();
110+
mConfig.Clear_SpriteBitmapScale();
111+
mConfig.Clear_SpriteBitmapOffsetY();
110112
Init();
111113
TransferDataToWindow();
112114
return true;

src/show_ui.cpp

Lines changed: 0 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -31,116 +31,6 @@
3131

3232
static const size_t kMaxPoints = 1000;
3333

34-
class PointPickerView : public wxView {
35-
public:
36-
PointPickerView() = default;
37-
~PointPickerView() = default;
38-
virtual void OnDraw(wxDC* dc) { }
39-
virtual void OnUpdate(wxView* sender, wxObject* hint = (wxObject*)NULL);
40-
};
41-
42-
void PointPickerView::OnUpdate(wxView* sender, wxObject* hint)
43-
{
44-
static_cast<PointPicker*>(GetFrame())->Update();
45-
}
46-
47-
enum {
48-
PointPicker_PointPickerList = 1100,
49-
};
50-
51-
BEGIN_EVENT_TABLE(PointPicker, wxDialog)
52-
EVT_LISTBOX(PointPicker_PointPickerList, PointPicker::PointPickerSelect)
53-
EVT_LISTBOX_DCLICK(PointPicker_PointPickerList, PointPicker::PointPickerAll)
54-
END_EVENT_TABLE()
55-
56-
PointPicker::PointPicker(CalChartDoc& shw, wxWindow* parent, wxWindowID id,
57-
const wxString& caption, const wxPoint& pos,
58-
const wxSize& size, long style)
59-
: super(parent, id, caption, pos, size, style)
60-
, mShow(shw)
61-
, mView(std::make_unique<PointPickerView>())
62-
{
63-
// give this a view so it can pick up document changes
64-
mView->SetDocument(&mShow);
65-
mView->SetFrame(this);
66-
67-
CreateControls();
68-
69-
// This fits the dalog to the minimum size dictated by the sizers
70-
GetSizer()->Fit(this);
71-
// This ensures that the dialog cannot be smaller than the minimum size
72-
GetSizer()->SetSizeHints(this);
73-
74-
Center();
75-
}
76-
77-
void PointPicker::CreateControls()
78-
{
79-
SetSizer(VStack([this](auto sizer) {
80-
HStack(sizer, BasicSizerFlags(), [this](auto sizer) {
81-
auto button = CreateButton(this, sizer, BasicSizerFlags(), wxID_OK, "&Close");
82-
button->SetDefault();
83-
CreateButtonWithHandler(this, sizer, BasicSizerFlags(), "&All", [this]() {
84-
mShow.SetSelection(mShow.MakeSelectAll());
85-
});
86-
CreateButtonWithHandler(this, sizer, BasicSizerFlags(), "&None", [this]() {
87-
mShow.SetSelection(mShow.MakeUnselectAll());
88-
});
89-
});
90-
91-
HStack(sizer, BasicSizerFlags(), [this](auto sizer) {
92-
auto counter = 0;
93-
for (auto&& i : GetSymbolsBitmap()) {
94-
auto which = static_cast<SYMBOL_TYPE>(counter++);
95-
CreateBitmapButtonWithHandler(this, sizer, BasicSizerFlags(), i, [this, which]() {
96-
mShow.SetSelection(mShow.GetCurrentSheet()->MakeSelectPointsBySymbol(which));
97-
});
98-
}
99-
});
100-
101-
mList = new wxListBox(this, PointPicker_PointPickerList, wxDefaultPosition,
102-
wxSize(50, 500), 0, NULL, wxLB_EXTENDED);
103-
sizer->Add(mList, wxSizerFlags(0).Border(wxALL, 5).Center());
104-
}));
105-
106-
Update();
107-
}
108-
109-
void PointPicker::PointPickerAll(wxCommandEvent&)
110-
{
111-
mShow.SetSelection(mShow.MakeSelectAll());
112-
}
113-
114-
void PointPicker::PointPickerSelect(wxCommandEvent&)
115-
{
116-
wxArrayInt selections;
117-
size_t n = mList->GetSelections(selections);
118-
119-
mCachedSelection.clear();
120-
for (size_t i = 0; i < n; ++i)
121-
mCachedSelection.insert(selections[i]);
122-
mShow.SetSelection(mCachedSelection);
123-
}
124-
125-
void PointPicker::Update()
126-
{
127-
auto&& tshowLabels = mShow.GetPointLabels();
128-
std::vector<wxString> showLabels(tshowLabels.begin(), tshowLabels.end());
129-
if (mCachedLabels != showLabels) {
130-
mCachedLabels = showLabels;
131-
mList->Clear();
132-
mList->Set(wxArrayString{ mCachedLabels.size(), &mCachedLabels[0] });
133-
}
134-
auto showSelectionList = mShow.GetSelectionList();
135-
if (mCachedSelection != showSelectionList) {
136-
mList->DeselectAll();
137-
mCachedSelection = showSelectionList;
138-
for (auto n = mCachedSelection.begin(); n != mCachedSelection.end(); ++n) {
139-
mList->SetSelection(*n);
140-
}
141-
}
142-
}
143-
14434
static void CalculateLabels(const CalChartDoc& show,
14535
std::set<unsigned>& letters, bool& use_letters,
14636
long& maxnum)

src/show_ui.h

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,6 @@
2828

2929
#include <vector>
3030

31-
class PointPickerView;
32-
33-
class PointPicker : public wxDialog {
34-
using super = wxDialog;
35-
36-
public:
37-
PointPicker(CalChartDoc& shw, wxWindow* parent, wxWindowID id = wxID_ANY,
38-
const wxString& caption = wxT("Select Points"),
39-
const wxPoint& pos = wxDefaultPosition,
40-
const wxSize& size = wxDefaultSize,
41-
long style = wxCAPTION | wxRESIZE_BORDER | wxSYSTEM_MENU);
42-
~PointPicker() = default;
43-
44-
void Update();
45-
46-
private:
47-
CalChartDoc& mShow;
48-
std::unique_ptr<PointPickerView> mView;
49-
wxListBox* mList;
50-
std::vector<wxString> mCachedLabels;
51-
SelectionList mCachedSelection;
52-
53-
void CreateControls();
54-
55-
void PointPickerAll(wxCommandEvent&);
56-
void PointPickerSelect(wxCommandEvent&);
57-
58-
DECLARE_EVENT_TABLE()
59-
};
60-
6131
class ShowInfoReq : public wxDialog {
6232
DECLARE_CLASS(ShowInfoReq)
6333
DECLARE_EVENT_TABLE()

0 commit comments

Comments
 (0)