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 #include "wx/splitter.h"
18 #include "configitem.h"
21 class WXDLLEXPORT wxHtmlWindow
;
23 class ctPropertyEditorGrid
;
26 * A container window for the property editor.
29 class ctPropertyEditor
: public wxPanel
31 DECLARE_CLASS(ctPropertyEditor
)
33 ctPropertyEditor(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
);
34 ~ctPropertyEditor(){};
38 /// Handles detailed editing event.
39 void OnEditDetails(wxCommandEvent
& event
);
41 /// Handles detailed editing update event.
42 void OnUpdateEditDetails(wxUpdateUIEvent
& event
);
44 /// Intercept selection event.
45 void OnSelectCell(wxGridEvent
& event
);
47 /// Intercept cell data change event.
48 void OnChangeCell(wxGridEvent
& event
);
50 /// Double-click to show specialised editor.
51 void OnDClickCell(wxGridEvent
& event
);
55 /// Creates the controls
56 void CreateControls(wxWindow
* parent
);
61 /// Can we edit the details of the selected property?
62 bool CanEditDetails();
64 /// Edit the details of this cell appropriately.
65 bool EditDetails(wxWindow
* parent
);
67 /// Shows the given config item
68 void ShowItem(ctConfigItem
* configItem
);
70 /// Updates the proxy display, assuming it was already displayed.
73 /// Display attribute at given row
74 bool DisplayProperty(int row
, ctProperty
* prop
, bool valueOnly
= false);
76 /// Display attribute value
77 bool DisplayProperty(ctProperty
* prop
);
79 /// Edit the default property
80 bool EditDefaultProperty(ctConfigItem
* proxy
);
82 /// Select the default property
83 bool DisplayDefaultProperty();
85 /// Determine background colour for this property.
86 void DeterminePropertyColour(ctProperty
* prop
, wxColour
& colour
);
88 /// Update the title at the top of the property editor
91 /// Update the description
92 void UpdateDescription(int row
= -1);
94 /// Wraps a description string in HTML
95 wxString
WrapDescription(const wxString
& str
);
97 /// Find the selected property
98 ctProperty
* FindSelectedProperty(int& row
);
100 /// Find the nth property
101 ctProperty
* FindProperty(int row
);
103 /// Apply the cell value to the property, and notify the
105 void ApplyCellValueToProperty(int row
, int col
);
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
);
111 /// Show/hide the description control
112 void ShowDescriptionWindow(bool show
);
116 //// Returns the grid used as the attribute editor
117 ctPropertyEditorGrid
* GetAttributeEditorGrid() const { return m_attributeEditorGrid
; }
119 /// Returns the title text control
120 wxTextCtrl
* GetElementTitleTextCtrl() const { return m_elementTitleTextCtrl
; }
122 /// Returns the splitter window between the property grid and
123 /// the description window.
124 wxSplitterWindow
* GetSplitterWindow() const { return m_splitterWindow
; }
126 /// Returns the HTML description window
127 wxHtmlWindow
* GetDescriptionWindow() const { return m_propertyDescriptionWindow
; }
129 /// Returns the config item
130 ctConfigItem
* GetItem() const { return m_item
; }
133 void SetItem(ctConfigItem
* configItem
) { m_item
= configItem
; }
135 DECLARE_EVENT_TABLE()
139 wxButton
* m_attributeEditorEditDetails
;
140 ctPropertyEditorGrid
* m_attributeEditorGrid
;
141 wxHtmlWindow
* m_propertyDescriptionWindow
;
142 wxSplitterWindow
* m_splitterWindow
;
144 // Displays the title of the element being edited
145 wxTextCtrl
* m_elementTitleTextCtrl
;
147 // The config item object being edited
148 ctConfigItem
* m_item
;
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
157 * Attribute editor grid
160 class ctPropertyEditorGrid
: public wxGrid
162 DECLARE_CLASS(ctPropertyEditorGrid
)
164 ctPropertyEditorGrid(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
,
165 const wxSize
& sz
= wxDefaultSize
, long style
= wxWANTS_CHARS
);
167 /// Intercept size event.
168 void OnSize(wxSizeEvent
& event
);
170 void SetStretchableColumn(int which
) { m_stretchableColumn
= which
; }
171 int GetStretchableColumn() const { return m_stretchableColumn
; }
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
; }
178 /// Use m_columnsToDisplay to set the label strings
179 void DisplayLabels();
182 bool ClearAttributes();
184 DECLARE_EVENT_TABLE()
187 int m_stretchableColumn
;
188 wxArrayString m_columnsToDisplay
;
193 /// Translate the value to one which can be edited in a single-line
195 wxString
ctConvertToSingleText(const wxString
& value
);
197 /// Translate back to 'real' characters, i.e. newlines are real
199 wxString
ctConvertToMultilineText(const wxString
& value
);
201 //----------------------------------------------------------------------------
202 // ctMultiLineTextEditor
203 //----------------------------------------------------------------------------
205 class ctMultiLineTextEditor
: public wxDialog
208 // constructors and destructors
209 ctMultiLineTextEditor( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
211 const wxString
& value
,
212 const wxPoint
& pos
= wxDefaultPosition
,
213 const wxSize
& size
= wxDefaultSize
,
214 long style
= wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
216 bool AddControls(wxWindow
* parent
, const wxString
& msg
);
218 wxString
GetText() const { return m_text
; }
219 void SetText(const wxString
& text
) { m_text
= text
; }
222 DECLARE_EVENT_TABLE()
227 * Special-purpose splitter window for changing sash look and
228 * also saving sash width
231 class ctSplitterWindow
: public wxSplitterWindow
234 ctSplitterWindow(wxWindow
* parent
, wxWindowID id
,
235 const wxPoint
& pos
, const wxSize
& size
, long style
);
238 //virtual void DrawSash(wxDC& dc);
240 void OnChangeSash(wxSplitterEvent
& event
);
242 void UpdateSettings(bool updateSettings
) { m_updateSettings
= updateSettings
; }
244 int GetLastPosition() const { return m_position
; }
245 void SetLastPosition(int pos
) { m_position
= pos
; }
248 // Don't update settings if the window is still being created,
249 // since it could override the saved settings
250 bool m_updateSettings
;
253 DECLARE_EVENT_TABLE()
257 * Use a single-line text control.
260 class ctGridCellTextEditor
: public wxGridCellTextEditor
263 virtual void Create(wxWindow
* parent
, wxWindowID id
,
264 wxEvtHandler
* evtHandler
);
267 #define ctGRID_VALUE_STRING wxT("singlelinestring")
269 #define ctID_PROPERTY_EDITOR_SPLITTER 1600