1 /////////////////////////////////////////////////////////////////////////////
2 // Name: propeditor.cpp
3 // Purpose: Property editor for wxWindows 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
);
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()
142 ctPropertyEditorGrid
* m_attributeEditorGrid
;
143 wxHtmlWindow
* m_propertyDescriptionWindow
;
144 wxSplitterWindow
* m_splitterWindow
;
146 // Displays the title of the element being edited
147 wxTextCtrl
* m_elementTitleTextCtrl
;
149 // The config item object being edited
150 ctConfigItem
* m_item
;
153 #define ctID_ATTRIBUTE_EDITOR_INSERT 2001
154 #define ctID_ATTRIBUTE_EDITOR_GRID 2002
155 #define ctID_ATTRIBUTE_EDITOR_DESCRIPTION 2003
156 #define ctID_ATTRIBUTE_EDITOR_EDIT_DETAILS 2004
159 * Attribute editor grid
162 class ctPropertyEditorGrid
: public wxGrid
164 DECLARE_CLASS(ctPropertyEditorGrid
)
166 ctPropertyEditorGrid(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
,
167 const wxSize
& sz
= wxDefaultSize
, long style
= wxWANTS_CHARS
);
169 /// Intercept size event.
170 void OnSize(wxSizeEvent
& event
);
172 void SetStretchableColumn(int which
) { m_stretchableColumn
= which
; }
173 int GetStretchableColumn() const { return m_stretchableColumn
; }
175 /// An array denoting which columns to display,
176 /// and in what order.
177 void SetColumnsToDisplay(wxArrayString
& columns
) { m_columnsToDisplay
= columns
; }
178 wxArrayString
& GetColumnsToDisplay() { return m_columnsToDisplay
; }
180 /// Use m_columnsToDisplay to set the label strings
181 void DisplayLabels();
184 bool ClearAttributes();
186 DECLARE_EVENT_TABLE()
189 int m_stretchableColumn
;
190 wxArrayString m_columnsToDisplay
;
195 /// Translate the value to one which can be edited in a single-line
197 wxString
ctConvertToSingleText(const wxString
& value
);
199 /// Translate back to 'real' characters, i.e. newlines are real
201 wxString
ctConvertToMultilineText(const wxString
& value
);
203 //----------------------------------------------------------------------------
204 // ctMultiLineTextEditor
205 //----------------------------------------------------------------------------
207 class ctMultiLineTextEditor
: public wxDialog
210 // constructors and destructors
211 ctMultiLineTextEditor( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
213 const wxString
& value
,
214 const wxPoint
& pos
= wxDefaultPosition
,
215 const wxSize
& size
= wxDefaultSize
,
216 long style
= wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
218 bool AddControls(wxWindow
* parent
, const wxString
& msg
);
220 wxString
GetText() const { return m_text
; }
221 void SetText(const wxString
& text
) { m_text
= text
; }
224 DECLARE_EVENT_TABLE()
229 * Special-purpose splitter window for changing sash look and
230 * also saving sash width
233 class ctSplitterWindow
: public wxSplitterWindow
236 ctSplitterWindow(wxWindow
* parent
, wxWindowID id
,
237 const wxPoint
& pos
, const wxSize
& size
, long style
);
240 //virtual void DrawSash(wxDC& dc);
242 void OnChangeSash(wxSplitterEvent
& event
);
244 void UpdateSettings(bool updateSettings
) { m_updateSettings
= updateSettings
; }
246 int GetLastPosition() const { return m_position
; }
247 void SetLastPosition(int pos
) { m_position
= pos
; }
250 // Don't update settings if the window is still being created,
251 // since it could override the saved settings
252 bool m_updateSettings
;
255 DECLARE_EVENT_TABLE()
259 * Use a single-line text control.
262 class ctGridCellTextEditor
: public wxGridCellTextEditor
265 virtual void Create(wxWindow
* parent
, wxWindowID id
,
266 wxEvtHandler
* evtHandler
);
269 #define ctGRID_VALUE_STRING wxT("singlelinestring")
271 #define ctID_PROPERTY_EDITOR_SPLITTER 1600