1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
6 // This program is part of the eCos host tools.
8 // This program is free software; you can redistribute it and/or modify it
9 // under the terms of the GNU General Public License as published by the Free
10 // Software Foundation; either version 2 of the License, or (at your option)
13 // This program is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 // You should have received a copy of the GNU General Public License along with
19 // this program; if not, write to the Free Software Foundation, Inc.,
20 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 // ----------------------------------------------------------------------------
24 //####COPYRIGHTEND####
27 //===========================================================================
28 //#####DESCRIPTIONBEGIN####
31 // Contact(s): julians
35 // Description: Header file for ecConfigItem, which describes a config item
36 // from this tool's perspective. Note that this duplicates
37 // some of the CDL data structures in order to be able to test the
38 // UI independently; we may eliminate some of the duplication later.
45 //####DESCRIPTIONEND####
47 //===========================================================================
49 #ifndef _ECOS_CONFIGITEM_H_
50 #define _ECOS_CONFIGITEM_H_
53 #pragma interface "configitem.h"
56 #include "wx/variant.h"
57 #include "wx/treectrl.h"
58 #include "wx/spinctrl.h"
79 * The flavor of the option
92 * The type of option, if this is an option
107 * What kind of control to use
118 * Get string from where?
132 * Represents a node in the configuration hierarchy.
133 * For every ecConfigItem, there is also an ecTreeItemData
136 class ecConfigTreeCtrl;
137 class ecConfigItem: public wxObject
139 DECLARE_CLASS(ecConfigItem)
140 friend class ecConfigToolDoc;
143 // active: whether greyed out or not
144 // enabled: only if this is a Bool or BoolData: whether enabled/disabled (checked/unchecked)
145 ecConfigItem(ecConfigItem* parent, const wxString& name, ecConfigType ctype = ecConfigTypeNone,
146 ecOptionFlavor flavor = ecFlavorNone, ecOptionType otype = ecOptionTypeNone,
147 bool active = TRUE, bool enabled = TRUE, ecUIHint hint = ecHintNone);
148 ecConfigItem(ecConfigItem* parent, CdlUserVisible vitem);
152 void SetParent(ecConfigItem* parent) { m_parent = parent; }
153 ecConfigItem* GetParent() const { return m_parent; }
155 void SetName(const wxString& name) { m_name = name; }
156 const wxString& GetName() const { return m_name; }
158 void SetMacro(const wxString& name) { m_macro = name; }
159 const wxString& GetMacro() const { return m_macro; }
161 void SetDescription(const wxString& descr) { m_strDescr = descr; }
162 const wxString& GetDescription() const { return m_strDescr; }
164 void SetConfigType(ecConfigType ctype) { m_configType = ctype; }
165 ecConfigType GetConfigType() const { return m_configType; }
167 void SetOptionType(ecOptionType otype) { m_optionType = otype; }
168 ecOptionType GetOptionType() const { return m_optionType; }
170 void SetOptionFlavor(ecOptionFlavor flavor) { m_optionFlavor = flavor; }
171 ecOptionFlavor GetOptionFlavor() const { return m_optionFlavor; }
173 void SetValue(const wxVariant& value) { m_value = value; }
174 wxVariant& GetValue() { return m_value; }
176 // Only appropriate if Bool or BoolData. Otherwise, assume always enabled.
177 void SetEnabled(bool enabled) { m_enabled = enabled; }
178 bool GetEnabled() const { return m_enabled; }
180 // Whether greyed out or not
181 void SetActive(bool active) { m_active = active; }
182 bool GetActive() const { return m_active; }
185 void SetUIHint(ecUIHint hint) { m_hint = hint; }
186 ecUIHint GetUIHint() const { return m_hint; }
188 // Gets the value to display (often an empty string)
189 wxString GetDisplayValue() const ;
191 wxTreeItemId GetTreeItem() const { return m_treeItem; };
192 void SetTreeItem(wxTreeItemId id) { m_treeItem = id; };
194 CdlUserVisible GetCdlItem() const { return m_CdlItem; }
195 void SetCdlItem(CdlUserVisible cdlItem) { m_CdlItem = cdlItem; }
197 wxString GetItemNameOrMacro() const;
199 bool IsPackage () const { return NULL!=dynamic_cast<CdlPackage> (GetCdlItem()); }
202 // Sets the text and icon for this item
203 bool UpdateTreeItem(ecConfigTreeCtrl& treeCtrl);
205 // Handle a left click on the icon: e.g. (un)check the option
206 void OnIconLeftDown(ecConfigTreeCtrl& treeCtrl);
208 // Can we start editing this item?
209 bool CanEdit() const;
211 // Creates an edit window. It will be positioned by the caller.
212 wxWindow* CreateEditWindow(wxWindow* parent);
214 // Transfers data between item and window
215 bool TransferDataToWindow(wxWindow* window);
216 bool TransferDataFromWindow(wxWindow* window);
218 // Convert from Cdl to internal representation
219 bool ConvertFromCdl();
221 // Bump by specified amount, or toggle if a boolean value
222 bool BumpItem(int nInc);
224 //// TAKEN FROM MFC VERSION
226 const ecFileName GetFilename () const;
227 CdlPackage GetOwnerPackage() const { return GetCdlItem()?(dynamic_cast<CdlPackage> (GetCdlItem()->get_owner ())):NULL; }
228 bool ChangeVersion (const wxString &strVersion);
229 CdlValuable GetCdlValuable() const { return dynamic_cast<CdlValuable> (GetCdlItem()); }
231 wxString GetURL () const;
233 bool HasRadio () const;
234 ecConfigItem *FirstRadio() const;
236 ecConfigItem *FirstChild() const;
237 ecConfigItem *NextSibling() const;
239 bool HasModifiedChildren() const;
240 bool IsEnabled() const;
241 bool IsActive() const; // Added JACS
243 bool Modified() const;
247 ecConfigItem * NextRadio() const;
249 bool IsDescendantOf (ecConfigItem *pAncestor);
254 bool HasBool () const;
256 long DefaultValue() const;
258 const wxString StringValue (CdlValueSource source = CdlValueSource_Current) const;
259 const wxString StringValue(ecWhereType where) const;
260 const double DoubleValue (CdlValueSource source = CdlValueSource_Current) const;
261 const wxString StringDefaultValue() const { return StringValue (CdlValueSource_Default); }
262 const double DoubleDefaultValue () const { return DoubleValue (CdlValueSource_Default); }
263 int EvalEnumStrings (wxArrayString &arEnumStrings) const;
265 // Convert a string representation of 'where' (e.g. "Macro names") to
267 static ecWhereType WhereStringToType(const wxString& whereString);
269 // Convert a type representation of 'where' to a string
270 static wxString WhereTypeToString(ecWhereType whereType);
274 bool SetValue (const wxString& value, CdlTransaction transaction=NULL);
275 bool SetValue (double dValue, CdlTransaction transaction=NULL);
276 bool SetValue (long nValue, CdlTransaction transaction=NULL);
277 bool SetEnabled (bool bEnabled, CdlTransaction transaction=NULL);
284 ecConfigType m_configType;
285 ecOptionType m_optionType;
286 ecOptionFlavor m_optionFlavor;
289 ecConfigItem* m_parent;
290 wxTreeItemId m_treeItem;
291 CdlUserVisible m_CdlItem;
292 wxString m_strDescr; // Description
296 //// TODO: put these in separate file
300 * A specialised wxTextCtrl, for editing string config values
303 class ecTextEditorCtrl: public wxTextCtrl
305 DECLARE_CLASS(ecTextEditorCtrl)
308 ecTextEditorCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
313 void OnEnter(wxCommandEvent& event);
314 void OnKillFocus(wxFocusEvent& event);
315 void OnLeftDClick(wxMouseEvent& event);
317 DECLARE_EVENT_TABLE()
324 * A specialised wxTextCtrl, for editing double config values
327 class ecDoubleEditorCtrl: public wxTextCtrl
329 DECLARE_CLASS(ecDoubleEditorCtrl)
332 ecDoubleEditorCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
337 void OnEnter(wxCommandEvent& event);
338 void OnKillFocus(wxFocusEvent& event);
340 DECLARE_EVENT_TABLE()
344 * ecIntegerEditorCtrl
345 * A specialised wxSpinCtrl, for editing integer config values
348 class ecIntegerEditorCtrl: public wxSpinCtrl
350 DECLARE_CLASS(ecIntegerEditorCtrl)
353 ecIntegerEditorCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
358 void OnEnter(wxCommandEvent& event);
359 void OnKillFocus(wxFocusEvent& event);
361 DECLARE_EVENT_TABLE()
366 * A specialised wxChoice, for editing enumerated config values
369 class ecEnumEditorCtrl: public wxChoice
371 DECLARE_CLASS(ecEnumEditorCtrl)
374 ecEnumEditorCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
379 void OnChar(wxKeyEvent& event);
380 void OnKillFocus(wxFocusEvent& event);
382 DECLARE_EVENT_TABLE()
387 * Pops up to make it easier to edit large string values
390 class ecEditStringDialog : public ecDialog
394 ecEditStringDialog(const wxString& initialValue, wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
396 ~ecEditStringDialog();
400 void OnOK(wxCommandEvent& event);
403 void CreateControls(wxWindow* parent);
406 wxString GetValue() const { return m_value; }
408 //// Member variables
410 DECLARE_EVENT_TABLE()
416 // _ECOS_CONFIGITEM_H_