| 1 |
#pragma once |
| 2 |
|
| 3 |
#include "SREntity.h" |
| 4 |
#include "StimTypes.h" |
| 5 |
|
| 6 |
#include <wx/event.h> |
| 7 |
#include "wxutil/dataview/TreeView.h" |
| 8 |
|
| 9 |
class wxTextCtrl; |
| 10 |
class wxButton; |
| 11 |
class wxChoice; |
| 12 |
class wxPanel; |
| 13 |
class wxComboBox; |
| 14 |
class wxBitmapComboBox; |
| 15 |
class wxControl; |
| 16 |
class wxCheckBox; |
| 17 |
class wxSpinCtrl; |
| 18 |
class wxSpinCtrlDouble; |
| 19 |
class wxSpinDoubleEvent; |
| 20 |
class wxBoxSizer; |
| 21 |
|
| 22 |
// There's a bug in the MSW implementation of wxBitmapComboBox, don't use it in 3.0.0 |
| 23 |
#if wxCHECK_VERSION(3,0,1) && defined(__WXMSW__) |
| 24 |
#define USE_BMP_COMBO_BOX |
| 25 |
#endif |
| 26 |
|
| 27 |
namespace ui |
| 28 |
{ |
| 29 |
|
| 30 |
class ClassEditor : |
| 31 |
public wxEvtHandler |
| 32 |
{ |
| 33 |
protected: |
| 34 |
typedef std::map<wxTextCtrl*, std::string> EntryMap; |
| 35 |
EntryMap _entryWidgets; |
| 36 |
|
| 37 |
typedef std::map<wxControl*, std::string> SpinCtrlMap; |
| 38 |
SpinCtrlMap _spinWidgets; |
| 39 |
|
| 40 |
wxutil::TreeView* _list; |
| 41 |
|
| 42 |
// The entity object we're editing |
| 43 |
SREntityPtr _entity; |
| 44 |
|
| 45 |
// Helper class (owned by StimResponseEditor) |
| 46 |
StimTypes& _stimTypes; |
| 47 |
|
| 48 |
// TRUE if the GTK callbacks should be disabled |
| 49 |
bool _updatesDisabled; |
| 50 |
|
| 51 |
#ifdef USE_BMP_COMBO_BOX |
| 52 |
// The combo boxes to select the stim/response type |
| 53 |
wxBitmapComboBox* _type; |
| 54 |
wxBitmapComboBox* _addType; |
| 55 |
#else |
| 56 |
wxComboBox* _type; |
| 57 |
wxComboBox* _addType; |
| 58 |
#endif |
| 59 |
|
| 60 |
// The dialog hbox to pack the editing pane into |
| 61 |
wxBoxSizer* _overallHBox; |
| 62 |
|
| 63 |
public: |
| 64 |
// Constructor is connecting the list pane |
| 65 |
ClassEditor(wxWindow* mainPanel, StimTypes& stimTypes); |
| 66 |
|
| 67 |
virtual ~ClassEditor() {} |
| 68 |
|
| 69 |
/** greebo: Sets the new entity (is called by the subclasses) |
| 70 |
*/ |
| 71 |
virtual void setEntity(const SREntityPtr& entity); |
| 72 |
|
| 73 |
/** greebo: Sets the given <key> of the current entity to <value> |
| 74 |
*/ |
| 75 |
virtual void setProperty(const std::string& key, const std::string& value); |
| 76 |
|
| 77 |
/** greebo: Updates the widgets (must be implemented by the child classes) |
| 78 |
*/ |
| 79 |
virtual void update() = 0; |
| 80 |
|
| 81 |
void reloadStimTypes(); |
| 82 |
|
| 83 |
protected: |
| 84 |
// Constructs a new list view as child to the given parent |
| 85 |
void createListView(wxWindow* parent); |
| 86 |
|
| 87 |
/** |
| 88 |
* greebo: Returns the name of the selected stim in the given combo box. |
| 89 |
* The client data behind that combo box has to be set by the |
| 90 |
* StimTypes helper class. |
| 91 |
*/ |
| 92 |
virtual std::string getStimTypeIdFromSelector(wxComboBox* comboBox); |
| 93 |
|
| 94 |
/** greebo: Adds/removes a S/R from the main list |
| 95 |
*/ |
| 96 |
virtual void addSR() = 0; |
| 97 |
virtual void removeSR(); |
| 98 |
|
| 99 |
/** greebo: Duplicates the currently selected S/R object |
| 100 |
*/ |
| 101 |
void duplicateStimResponse(); |
| 102 |
|
| 103 |
/** greebo: Gets called when a check box is toggled, this should |
| 104 |
* update the contents of possible associated entry fields. |
| 105 |
*/ |
| 106 |
virtual void checkBoxToggled(wxCheckBox* toggleButton) = 0; |
| 107 |
|
| 108 |
/** greebo: Gets called when an entry box changes, this can be |
| 109 |
* overriden by the subclasses, if this is needed |
| 110 |
*/ |
| 111 |
virtual void entryChanged(wxTextCtrl* entry); |
| 112 |
|
| 113 |
/** greebo: Gets called when a spin button changes, this can be |
| 114 |
* overriden by the subclasses, if this is needed |
| 115 |
*/ |
| 116 |
virtual void spinButtonChanged(wxSpinCtrl* ctrl); |
| 117 |
virtual void spinButtonChanged(wxSpinCtrlDouble* ctrl); |
| 118 |
|
| 119 |
/** greebo: Returns the ID of the currently selected stim/response |
| 120 |
* |
| 121 |
* @returns: the index (number) of the selected stim or -1 on failure |
| 122 |
*/ |
| 123 |
int getIndexFromSelection(); |
| 124 |
|
| 125 |
/** greebo: Selects the given index in the S/R list |
| 126 |
*/ |
| 127 |
void selectIndex(int index); |
| 128 |
|
| 129 |
/** greebo: Gets called when the list selection changes |
| 130 |
*/ |
| 131 |
virtual void selectionChanged() = 0; |
| 132 |
|
| 133 |
/** |
| 134 |
* greebo: Opens the context menu. Needs to be implemented by subclasses. |
| 135 |
*/ |
| 136 |
virtual void openSRListContextMenu() = 0; |
| 137 |
|
| 138 |
// Callback for Stim/Response selection changes |
| 139 |
void onSRSelectionChange(wxDataViewEvent& ev); |
| 140 |
|
| 141 |
// The keypress handler for catching the keys in the treeview |
| 142 |
void onTreeViewKeyPress(wxKeyEvent& ev); |
| 143 |
|
| 144 |
void onContextMenu(wxDataViewEvent& ev); |
| 145 |
|
| 146 |
// Gets called if any of the entry widget contents get changed |
| 147 |
void onEntryChanged(wxCommandEvent& ev); |
| 148 |
void onSpinCtrlChanged(wxSpinEvent& ev); |
| 149 |
void onSpinCtrlDoubleChanged(wxSpinDoubleEvent& ev); |
| 150 |
void onCheckboxToggle(wxCommandEvent& ev); |
| 151 |
|
| 152 |
// Utility function to connect a checkbutton's "toggled" signal to "onCheckBoxToggle" |
| 153 |
void connectCheckButton(wxCheckBox* checkButton); |
| 154 |
|
| 155 |
// Utility function to connect a spinbutton's "value-changed" event to "onSpinButtonChanged" |
| 156 |
// It also associates the given spin button in the SpinButton map |
| 157 |
void connectSpinButton(wxSpinCtrl* spinCtrl, const std::string& key); |
| 158 |
void connectSpinButton(wxSpinCtrlDouble* spinCtrl, const std::string& key); |
| 159 |
|
| 160 |
// Utility function to connect a entry's "changed" signal to "onEntryChanged" |
| 161 |
// It also associates the given entry in the EntryMap |
| 162 |
void connectEntry(wxTextCtrl* entry, const std::string& key); |
| 163 |
|
| 164 |
// Gets called on stim type selection change |
| 165 |
void onStimTypeSelect(wxCommandEvent& ev); |
| 166 |
void onAddTypeSelect(wxCommandEvent& ev); |
| 167 |
|
| 168 |
void onAddSR(wxCommandEvent& ev); |
| 169 |
void onRemoveSR(wxCommandEvent& ev); |
| 170 |
|
| 171 |
// Override/disable override menu items |
| 172 |
void onContextMenuEnable(wxCommandEvent& ev); |
| 173 |
void onContextMenuDisable(wxCommandEvent& ev); |
| 174 |
void onContextMenuDuplicate(wxCommandEvent& ev); |
| 175 |
}; |
| 176 |
|
| 177 |
} // namespace ui |