fixed shutdown crashes after recent handlers creation changes
[wxWidgets.git] / utils / configtool / src / propeditor.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: propeditor.cpp
3 // Purpose: Property editor for wxWidgets configuration tool
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 2003-06-03
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence:
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _CT_PROPEDITOR_H_
13 #define _CT_PROPEDITOR_H_
14
15 #include "wx/splitter.h"
16 #include "wx/grid.h"
17
18 #include "configitem.h"
19 #include "property.h"
20
21 class WXDLLEXPORT wxHtmlWindow;
22
23 class ctPropertyEditorGrid;
24
25 /*!
26 * A container window for the property editor.
27 */
28
29 class ctPropertyEditor: public wxPanel
30 {
31 DECLARE_CLASS(ctPropertyEditor)
32 public:
33 ctPropertyEditor(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style);
34 virtual ~ctPropertyEditor(){}
35
36 // Event handlers
37
38 /// Handles detailed editing event.
39 void OnEditDetails(wxCommandEvent& event);
40
41 /// Handles detailed editing update event.
42 void OnUpdateEditDetails(wxUpdateUIEvent& event);
43
44 /// Intercept selection event.
45 void OnSelectCell(wxGridEvent& event);
46
47 /// Intercept cell data change event.
48 void OnChangeCell(wxGridEvent& event);
49
50 /// Double-click to show specialised editor.
51 void OnDClickCell(wxGridEvent& event);
52
53 // Operations
54
55 /// Creates the controls
56 void CreateControls(wxWindow* parent);
57
58 /// Clear grid editor
59 void ClearEditor();
60
61 /// Can we edit the details of the selected property?
62 bool CanEditDetails();
63
64 /// Edit the details of this cell appropriately.
65 bool EditDetails(wxWindow* parent);
66
67 /// Shows the given config item
68 void ShowItem(ctConfigItem* configItem);
69
70 /// Updates the proxy display, assuming it was already displayed.
71 void UpdateItem();
72
73 /// Display attribute at given row
74 bool DisplayProperty(int row, ctProperty* prop, bool valueOnly = false);
75
76 /// Display attribute value
77 bool DisplayProperty(ctProperty* prop);
78
79 /// Edit the default property
80 bool EditDefaultProperty(ctConfigItem* proxy);
81
82 /// Select the default property
83 bool DisplayDefaultProperty();
84
85 /// Determine background colour for this property.
86 void DeterminePropertyColour(ctProperty* prop, wxColour& colour);
87
88 /// Update the title at the top of the property editor
89 void UpdateTitle();
90
91 /// Update the description
92 void UpdateDescription(int row = -1);
93
94 /// Wraps a description string in HTML
95 wxString WrapDescription(const wxString& str);
96
97 /// Find the selected property
98 ctProperty* FindSelectedProperty(int& row);
99
100 /// Find the nth property
101 ctProperty* FindProperty(int row);
102
103 /// Apply the cell value to the property, and notify the
104 /// proxy object.
105 void ApplyCellValueToProperty(int row, int col);
106
107 /// Apply the cell value to the property, and notify the
108 /// proxy object. This will be undoable.
109 void ApplyPropertyValue(ctConfigItem* item, ctProperty* property, const wxVariant& variant);
110
111 /// Show/hide the description control
112 void ShowDescriptionWindow(bool show);
113
114 // Accessors
115
116 //// Returns the grid used as the attribute editor
117 ctPropertyEditorGrid* GetAttributeEditorGrid() const { return m_attributeEditorGrid; }
118
119 /// Returns the title text control
120 wxTextCtrl* GetElementTitleTextCtrl() const { return m_elementTitleTextCtrl; }
121
122 /// Returns the splitter window between the property grid and
123 /// the description window.
124 wxSplitterWindow* GetSplitterWindow() const { return m_splitterWindow; }
125
126 /// Returns the HTML description window
127 wxHtmlWindow* GetDescriptionWindow() const { return m_propertyDescriptionWindow; }
128
129 /// Returns the config item
130 ctConfigItem* GetItem() const { return m_item; }
131
132 /// Sets the proxy
133 void SetItem(ctConfigItem* configItem) { m_item = configItem; }
134
135 DECLARE_EVENT_TABLE()
136
137 protected:
138 // Dialog controls
139 wxButton* m_attributeEditorEditDetails;
140 ctPropertyEditorGrid* m_attributeEditorGrid;
141 wxHtmlWindow* m_propertyDescriptionWindow;
142 wxSplitterWindow* m_splitterWindow;
143
144 // Displays the title of the element being edited
145 wxTextCtrl* m_elementTitleTextCtrl;
146
147 // The config item object being edited
148 ctConfigItem* m_item;
149 };
150
151 #define ctID_ATTRIBUTE_EDITOR_INSERT 2001
152 #define ctID_ATTRIBUTE_EDITOR_GRID 2002
153 #define ctID_ATTRIBUTE_EDITOR_DESCRIPTION 2003
154 #define ctID_ATTRIBUTE_EDITOR_EDIT_DETAILS 2004
155
156 /*!
157 * Attribute editor grid
158 */
159
160 class ctPropertyEditorGrid: public wxGrid
161 {
162 DECLARE_CLASS(ctPropertyEditorGrid)
163 public:
164 ctPropertyEditorGrid(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition,
165 const wxSize& sz = wxDefaultSize, long style = wxWANTS_CHARS);
166
167 /// Intercept size event.
168 void OnSize(wxSizeEvent& event);
169
170 void SetStretchableColumn(int which) { m_stretchableColumn = which; }
171 int GetStretchableColumn() const { return m_stretchableColumn; }
172
173 /// An array denoting which columns to display,
174 /// and in what order.
175 void SetColumnsToDisplay(wxArrayString& columns) { m_columnsToDisplay = columns; }
176 wxArrayString& GetColumnsToDisplay() { return m_columnsToDisplay; }
177
178 /// Use m_columnsToDisplay to set the label strings
179 void DisplayLabels();
180
181 /// Clear attributes
182 bool ClearAttributes();
183
184 DECLARE_EVENT_TABLE()
185
186 private:
187 int m_stretchableColumn;
188 wxArrayString m_columnsToDisplay;
189 };
190
191 // Utility functions
192
193 /// Translate the value to one which can be edited in a single-line
194 /// text control
195 wxString ctConvertToSingleText(const wxString& value);
196
197 /// Translate back to 'real' characters, i.e. newlines are real
198 /// newlines.
199 wxString ctConvertToMultilineText(const wxString& value);
200
201 //----------------------------------------------------------------------------
202 // ctMultiLineTextEditor
203 //----------------------------------------------------------------------------
204
205 class ctMultiLineTextEditor: public wxDialog
206 {
207 public:
208 // constructors and destructors
209 ctMultiLineTextEditor( wxWindow *parent, wxWindowID id, const wxString &title,
210 const wxString& msg,
211 const wxString& value,
212 const wxPoint& pos = wxDefaultPosition,
213 const wxSize& size = wxDefaultSize,
214 long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
215
216 bool AddControls(wxWindow* parent, const wxString& msg);
217
218 wxString GetText() const { return m_text; }
219 void SetText(const wxString& text) { m_text = text; }
220
221 private:
222 DECLARE_EVENT_TABLE()
223 wxString m_text;
224 };
225
226 /*
227 * Special-purpose splitter window for changing sash look and
228 * also saving sash width
229 */
230
231 class ctSplitterWindow: public wxSplitterWindow
232 {
233 public:
234 ctSplitterWindow(wxWindow* parent, wxWindowID id,
235 const wxPoint& pos, const wxSize& size, long style);
236
237 // Draws the sash
238 //virtual void DrawSash(wxDC& dc);
239
240 void OnChangeSash(wxSplitterEvent& event);
241
242 void UpdateSettings(bool updateSettings) { m_updateSettings = updateSettings; }
243
244 int GetLastPosition() const { return m_position; }
245 void SetLastPosition(int pos) { m_position = pos; }
246
247 protected:
248 // Don't update settings if the window is still being created,
249 // since it could override the saved settings
250 bool m_updateSettings;
251 int m_position;
252
253 DECLARE_EVENT_TABLE()
254 };
255
256 /*!
257 * Use a single-line text control.
258 */
259
260 class ctGridCellTextEditor: public wxGridCellTextEditor
261 {
262 public:
263 virtual void Create(wxWindow* parent, wxWindowID id,
264 wxEvtHandler* evtHandler);
265 };
266
267 #define ctGRID_VALUE_STRING wxT("singlelinestring")
268
269 #define ctID_PROPERTY_EDITOR_SPLITTER 1600
270
271 #endif
272 // _WB_PROPEDITOR_H_
273