|
| 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 | + |
0 commit comments