]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - tools/src/tools/configtool/standalone/wxwin/configitem.h
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / tools / src / tools / configtool / standalone / wxwin / configitem.h
1 //####COPYRIGHTBEGIN####
2 //
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
5 //
6 // This program is part of the eCos host tools.
7 //
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)
11 // any later version.
12 //
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
16 // more details.
17 //
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.
21 //
22 // ----------------------------------------------------------------------------
23 //
24 //####COPYRIGHTEND####
25 // configitem.h :
26 //
27 //===========================================================================
28 //#####DESCRIPTIONBEGIN####
29 //
30 // Author(s):   julians
31 // Contact(s):  julians
32 // Date:        2000/09/01
33 // Version:     $Id$
34 // Purpose:
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.
39 // Requires:
40 // Provides:
41 // See also:
42 // Known bugs:
43 // Usage:
44 //
45 //####DESCRIPTIONEND####
46 //
47 //===========================================================================
48
49 #ifndef _ECOS_CONFIGITEM_H_
50 #define _ECOS_CONFIGITEM_H_
51
52 #ifdef __GNUG__
53 #pragma interface "configitem.h"
54 #endif
55
56 #include "wx/variant.h"
57 #include "wx/treectrl.h"
58 #include "wx/spinctrl.h"
59
60 #include "filename.h"
61 #include "cdl.hxx"
62
63 /*
64  * ecConfigType
65  * The type of item
66  */
67
68 enum ecConfigType
69 {
70     ecConfigTypeNone,
71     ecContainer,
72     ecPackage,
73     ecComponent,
74     ecOption
75 };
76
77 /*
78  * ecOptionFlavor
79  * The flavor of the option
80  */
81
82 enum ecOptionFlavor
83 {
84     ecFlavorNone,
85     ecFlavorBool,
86     ecFlavorBoolData,
87     ecFlavorData
88 };
89
90 /*
91  * ecOptionType
92  * The type of option, if this is an option
93  */
94
95 enum ecOptionType
96 {
97     ecOptionTypeNone,
98     ecDouble,
99     ecLong,
100     ecBool,
101     ecString,
102     ecEnumerated
103 };
104
105 /*
106  * ecUIHint
107  * What kind of control to use
108  */
109
110 enum ecUIHint
111 {
112     ecHintNone,
113     ecHintCheck,
114     ecHintRadio
115 };
116
117 /*
118  * Get string from where?
119  */
120
121 enum ecWhereType
122 {
123     ecInMacro = 0,
124     ecInName,
125     ecInDesc,
126     ecInCurrentValue,
127     ecInDefaultValue
128 };
129
130 /*
131  * ecConfigItem
132  * Represents a node in the configuration hierarchy.
133  * For every ecConfigItem, there is also an ecTreeItemData
134  * that points to it.
135  */
136 class ecConfigTreeCtrl;
137 class ecConfigItem: public wxObject
138 {
139 DECLARE_CLASS(ecConfigItem)
140     friend class ecConfigToolDoc;
141
142 public:
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);
149     ~ecConfigItem();
150
151 //// Accessors
152     void SetParent(ecConfigItem* parent) { m_parent = parent; }
153     ecConfigItem* GetParent() const { return m_parent; }
154
155     void SetName(const wxString& name) { m_name = name; }
156     const wxString& GetName() const { return m_name; }
157
158     void SetMacro(const wxString& name) { m_macro = name; }
159     const wxString& GetMacro() const { return m_macro; }
160
161     void SetDescription(const wxString& descr) { m_strDescr = descr; }
162     const wxString& GetDescription() const { return m_strDescr; }
163
164     void SetConfigType(ecConfigType ctype) { m_configType = ctype; }
165     ecConfigType GetConfigType() const { return m_configType; }
166
167     void SetOptionType(ecOptionType otype) { m_optionType = otype; }
168     ecOptionType GetOptionType() const { return m_optionType; }
169
170     void SetOptionFlavor(ecOptionFlavor flavor) { m_optionFlavor = flavor; }
171     ecOptionFlavor GetOptionFlavor() const { return m_optionFlavor; }
172
173     void SetValue(const wxVariant& value) { m_value = value; }
174     wxVariant& GetValue() { return m_value; }
175
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; }
179
180     // Whether greyed out or not
181     void SetActive(bool active) { m_active = active; }
182     bool GetActive() const { return m_active; }
183
184     // UI hint
185     void SetUIHint(ecUIHint hint) { m_hint = hint; }
186     ecUIHint GetUIHint() const { return m_hint; }
187
188     // Gets the value to display (often an empty string)
189     wxString GetDisplayValue() const ;
190
191     wxTreeItemId GetTreeItem() const { return m_treeItem; };
192     void SetTreeItem(wxTreeItemId id) { m_treeItem = id; };
193
194     CdlUserVisible GetCdlItem() const { return m_CdlItem; }
195     void SetCdlItem(CdlUserVisible cdlItem) { m_CdlItem = cdlItem; }
196
197     wxString GetItemNameOrMacro() const;
198
199         bool IsPackage () const { return NULL!=dynamic_cast<CdlPackage> (GetCdlItem()); }
200
201 //// Operations
202     // Sets the text and icon for this item
203     bool UpdateTreeItem(ecConfigTreeCtrl& treeCtrl);
204
205     // Handle a left click on the icon: e.g. (un)check the option
206     void OnIconLeftDown(ecConfigTreeCtrl& treeCtrl);
207
208     // Can we start editing this item?
209     bool CanEdit() const;
210
211     // Creates an edit window. It will be positioned by the caller.
212     wxWindow* CreateEditWindow(wxWindow* parent);
213     
214     // Transfers data between item and window
215     bool TransferDataToWindow(wxWindow* window);
216     bool TransferDataFromWindow(wxWindow* window);
217
218     // Convert from Cdl to internal representation
219     bool ConvertFromCdl();
220
221     // Bump by specified amount, or toggle if a boolean value
222     bool BumpItem(int nInc);
223
224 //// TAKEN FROM MFC VERSION
225
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()); }
230     bool Unload();
231     wxString GetURL () const;
232
233     bool HasRadio () const;
234     ecConfigItem *FirstRadio() const;
235
236     ecConfigItem *FirstChild() const;
237     ecConfigItem *NextSibling() const;
238
239     bool HasModifiedChildren() const;
240     bool IsEnabled() const;
241     bool IsActive() const; // Added JACS
242
243     bool Modified() const;
244
245     void DumpItem();
246
247     ecConfigItem * NextRadio() const;
248
249     bool IsDescendantOf (ecConfigItem *pAncestor);
250
251     bool ViewURL();
252     bool ViewHeader();
253
254     bool HasBool () const;
255
256     long DefaultValue() const;
257     long Value() 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;
264
265     // Convert a string representation of 'where' (e.g. "Macro names") to
266     // ecWhereType
267     static ecWhereType WhereStringToType(const wxString& whereString);
268     
269     // Convert a type representation of 'where' to a string
270     static wxString WhereTypeToString(ecWhereType whereType);
271     
272 protected:
273
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);
278     
279 protected:
280     wxString            m_name;
281     wxString            m_macro;
282     bool                m_enabled;
283     bool                m_active;
284     ecConfigType        m_configType;
285     ecOptionType        m_optionType;
286     ecOptionFlavor      m_optionFlavor;
287     ecUIHint            m_hint;
288     wxVariant           m_value;
289     ecConfigItem*       m_parent;
290     wxTreeItemId        m_treeItem;
291     CdlUserVisible      m_CdlItem;
292     wxString            m_strDescr; // Description
293 };
294
295
296 //// TODO: put these in separate file
297
298 /*
299  * ecTextEditorCtrl
300  * A specialised wxTextCtrl, for editing string config values
301  */
302
303 class ecTextEditorCtrl: public wxTextCtrl
304 {
305 DECLARE_CLASS(ecTextEditorCtrl)
306 public:
307 // Ctor(s)
308     ecTextEditorCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
309         long style = 0);
310
311 //// Event handlers
312
313     void OnEnter(wxCommandEvent& event);
314     void OnKillFocus(wxFocusEvent& event);
315     void OnLeftDClick(wxMouseEvent& event);
316
317 DECLARE_EVENT_TABLE()
318
319 private:
320 };
321
322 /*
323  * ecDoubleEditorCtrl
324  * A specialised wxTextCtrl, for editing double config values
325  */
326
327 class ecDoubleEditorCtrl: public wxTextCtrl
328 {
329 DECLARE_CLASS(ecDoubleEditorCtrl)
330 public:
331 // Ctor(s)
332     ecDoubleEditorCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
333         long style = 0);
334
335 //// Event handlers
336
337     void OnEnter(wxCommandEvent& event);
338     void OnKillFocus(wxFocusEvent& event);
339
340 DECLARE_EVENT_TABLE()
341 };
342
343 /*
344  * ecIntegerEditorCtrl
345  * A specialised wxSpinCtrl, for editing integer config values
346  */
347
348 class ecIntegerEditorCtrl: public wxSpinCtrl
349 {
350 DECLARE_CLASS(ecIntegerEditorCtrl)
351 public:
352 // Ctor(s)
353     ecIntegerEditorCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
354         long style = 0);
355
356 //// Event handlers
357
358     void OnEnter(wxCommandEvent& event);
359     void OnKillFocus(wxFocusEvent& event);
360
361 DECLARE_EVENT_TABLE()
362 };
363
364 /*
365  * ecEnumEditorCtrl
366  * A specialised wxChoice, for editing enumerated config values
367  */
368
369 class ecEnumEditorCtrl: public wxChoice
370 {
371 DECLARE_CLASS(ecEnumEditorCtrl)
372 public:
373 // Ctor(s)
374     ecEnumEditorCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
375         long style = 0);
376
377 //// Event handlers
378
379     void OnChar(wxKeyEvent& event);
380     void OnKillFocus(wxFocusEvent& event);
381
382 DECLARE_EVENT_TABLE()
383 };
384
385 /*
386  * ecEditStringDialog
387  * Pops up to make it easier to edit large string values
388  */
389
390 class ecEditStringDialog : public ecDialog
391 {
392 public:
393 // Ctor(s)
394         ecEditStringDialog(const wxString& initialValue, wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
395         long style = 0);
396     ~ecEditStringDialog();
397
398 //// Event handlers
399
400     void OnOK(wxCommandEvent& event);
401
402 //// Operations
403     void CreateControls(wxWindow* parent);
404
405 //// Accessors
406     wxString GetValue() const { return m_value; }
407
408 //// Member variables
409 protected:
410     DECLARE_EVENT_TABLE()
411
412     wxString    m_value;
413 };
414
415 #endif
416         // _ECOS_CONFIGITEM_H_