1 /////////////////////////////////////////////////////////////////////////////
2 // Name: propeditor.cpp
3 // Purpose: Property editor for wxWidgets configuration tool
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _CT_PROPEDITOR_H_
13 #define _CT_PROPEDITOR_H_
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "propeditor.cpp"
19 #include "wx/splitter.h"
22 #include "configitem.h"
25 class WXDLLEXPORT wxHtmlWindow
;
27 class ctPropertyEditorGrid
;
30 * A container window for the property editor.
33 class ctPropertyEditor
: public wxPanel
35 DECLARE_CLASS(ctPropertyEditor
)
37 ctPropertyEditor(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
);
38 ~ctPropertyEditor(){};
42 /// Handles detailed editing event.
43 void OnEditDetails(wxCommandEvent
& event
);
45 /// Handles detailed editing update event.
46 void OnUpdateEditDetails(wxUpdateUIEvent
& event
);
48 /// Intercept selection event.
49 void OnSelectCell(wxGridEvent
& event
);
51 /// Intercept cell data change event.
52 void OnChangeCell(wxGridEvent
& event
);
54 /// Double-click to show specialised editor.
55 void OnDClickCell(wxGridEvent
& event
);
59 /// Creates the controls
60 void CreateControls(wxWindow
* parent
);
65 /// Can we edit the details of the selected property?
66 bool CanEditDetails();
68 /// Edit the details of this cell appropriately.
69 bool EditDetails(wxWindow
* parent
);
71 /// Shows the given config item
72 void ShowItem(ctConfigItem
* configItem
);
74 /// Updates the proxy display, assuming it was already displayed.
77 /// Display attribute at given row
78 bool DisplayProperty(int row
, ctProperty
* prop
, bool valueOnly
= false);
80 /// Display attribute value
81 bool DisplayProperty(ctProperty
* prop
);
83 /// Edit the default property
84 bool EditDefaultProperty(ctConfigItem
* proxy
);
86 /// Select the default property
87 bool DisplayDefaultProperty();
89 /// Determine background colour for this property.
90 void DeterminePropertyColour(ctProperty
* prop
, wxColour
& colour
);
92 /// Update the title at the top of the property editor
95 /// Update the description
96 void UpdateDescription(int row
= -1);
98 /// Wraps a description string in HTML
99 wxString
WrapDescription(const wxString
& str
);
101 /// Find the selected property
102 ctProperty
* FindSelectedProperty(int& row
);
104 /// Find the nth property
105 ctProperty
* FindProperty(int row
);
107 /// Apply the cell value to the property, and notify the
109 void ApplyCellValueToProperty(int row
, int col
);
111 /// Apply the cell value to the property, and notify the
112 /// proxy object. This will be undoable.
113 void ApplyPropertyValue(ctConfigItem
* item
, ctProperty
* property
, const wxVariant
& variant
);
115 /// Show/hide the description control
116 void ShowDescriptionWindow(bool show
);
120 //// Returns the grid used as the attribute editor
121 ctPropertyEditorGrid
* GetAttributeEditorGrid() const { return m_attributeEditorGrid
; }
123 /// Returns the title text control
124 wxTextCtrl
* GetElementTitleTextCtrl() const { return m_elementTitleTextCtrl
; }
126 /// Returns the splitter window between the property grid and
127 /// the description window.
128 wxSplitterWindow
* GetSplitterWindow() const { return m_splitterWindow
; }
130 /// Returns the HTML description window
131 wxHtmlWindow
* GetDescriptionWindow() const { return m_propertyDescriptionWindow
; }
133 /// Returns the config item
134 ctConfigItem
* GetItem() const { return m_item
; }
137 void SetItem(ctConfigItem
* configItem
) { m_item
= configItem
; }
139 DECLARE_EVENT_TABLE()
143 wxButton
* m_attributeEditorEditDetails
;
144 ctPropertyEditorGrid
* m_attributeEditorGrid
;
145 wxHtmlWindow
* m_propertyDescriptionWindow
;
146 wxSplitterWindow
* m_splitterWindow
;
148 // Displays the title of the element being edited
149 wxTextCtrl
* m_elementTitleTextCtrl
;
151 // The config item object being edited
152 ctConfigItem
* m_item
;
155 #define ctID_ATTRIBUTE_EDITOR_INSERT 2001
156 #define ctID_ATTRIBUTE_EDITOR_GRID 2002
157 #define ctID_ATTRIBUTE_EDITOR_DESCRIPTION 2003
158 #define ctID_ATTRIBUTE_EDITOR_EDIT_DETAILS 2004
161 * Attribute editor grid
164 class ctPropertyEditorGrid
: public wxGrid
166 DECLARE_CLASS(ctPropertyEditorGrid
)
168 ctPropertyEditorGrid(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
,
169 const wxSize
& sz
= wxDefaultSize
, long style
= wxWANTS_CHARS
);
171 /// Intercept size event.
172 void OnSize(wxSizeEvent
& event
);
174 void SetStretchableColumn(int which
) { m_stretchableColumn
= which
; }
175 int GetStretchableColumn() const { return m_stretchableColumn
; }
177 /// An array denoting which columns to display,
178 /// and in what order.
179 void SetColumnsToDisplay(wxArrayString
& columns
) { m_columnsToDisplay
= columns
; }
180 wxArrayString
& GetColumnsToDisplay() { return m_columnsToDisplay
; }
182 /// Use m_columnsToDisplay to set the label strings
183 void DisplayLabels();
186 bool ClearAttributes();
188 DECLARE_EVENT_TABLE()
191 int m_stretchableColumn
;
192 wxArrayString m_columnsToDisplay
;
197 /// Translate the value to one which can be edited in a single-line
199 wxString
ctConvertToSingleText(const wxString
& value
);
201 /// Translate back to 'real' characters, i.e. newlines are real
203 wxString
ctConvertToMultilineText(const wxString
& value
);
205 //----------------------------------------------------------------------------
206 // ctMultiLineTextEditor
207 //----------------------------------------------------------------------------
209 class ctMultiLineTextEditor
: public wxDialog
212 // constructors and destructors
213 ctMultiLineTextEditor( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
215 const wxString
& value
,
216 const wxPoint
& pos
= wxDefaultPosition
,
217 const wxSize
& size
= wxDefaultSize
,
218 long style
= wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
220 bool AddControls(wxWindow
* parent
, const wxString
& msg
);
222 wxString
GetText() const { return m_text
; }
223 void SetText(const wxString
& text
) { m_text
= text
; }
226 DECLARE_EVENT_TABLE()
231 * Special-purpose splitter window for changing sash look and
232 * also saving sash width
235 class ctSplitterWindow
: public wxSplitterWindow
238 ctSplitterWindow(wxWindow
* parent
, wxWindowID id
,
239 const wxPoint
& pos
, const wxSize
& size
, long style
);
242 //virtual void DrawSash(wxDC& dc);
244 void OnChangeSash(wxSplitterEvent
& event
);
246 void UpdateSettings(bool updateSettings
) { m_updateSettings
= updateSettings
; }
248 int GetLastPosition() const { return m_position
; }
249 void SetLastPosition(int pos
) { m_position
= pos
; }
252 // Don't update settings if the window is still being created,
253 // since it could override the saved settings
254 bool m_updateSettings
;
257 DECLARE_EVENT_TABLE()
261 * Use a single-line text control.
264 class ctGridCellTextEditor
: public wxGridCellTextEditor
267 virtual void Create(wxWindow
* parent
, wxWindowID id
,
268 wxEvtHandler
* evtHandler
);
271 #define ctGRID_VALUE_STRING wxT("singlelinestring")
273 #define ctID_PROPERTY_EDITOR_SPLITTER 1600