]> git.saurik.com Git - wxWidgets.git/blob - contrib/utils/wxrcedit/propedit.cpp
removed SetAutoLayout(true) calls when a corresponding SetSizer() was also called...
[wxWidgets.git] / contrib / utils / wxrcedit / propedit.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Author: Vaclav Slavik
3 // Created: 2000/05/05
4 // RCS-ID: $Id$
5 // Copyright: (c) 2000 Vaclav Slavik
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
8
9 #ifdef __GNUG__
10 #pragma implementation "propedit.h"
11 #endif
12
13 // For compilers that support precompilation, includes "wx/wx.h".
14 #include "wx/wxprec.h"
15
16 #ifdef __BORLANDC__
17 #pragma hdrstop
18 #endif
19
20 #include "wx/wx.h"
21 #include "wx/xml/xml.h"
22 #include "propframe.h"
23 #include "propedit.h"
24 #include "xmlhelpr.h"
25 #include "editor.h"
26
27 enum
28 {
29 ID_CLEAR = wxID_HIGHEST + 1,
30 ID_DETAILS
31 };
32
33
34
35 BEGIN_EVENT_TABLE(PropEditCtrl, wxPanel)
36 EVT_BUTTON(ID_CLEAR, PropEditCtrl::OnButtonClear)
37 EVT_BUTTON(ID_DETAILS, PropEditCtrl::OnButtonDetails)
38 END_EVENT_TABLE()
39
40 void PropEditCtrl::OnButtonDetails(wxCommandEvent& WXUNUSED(event))
41 {
42 OnDetails();
43 }
44
45 void PropEditCtrl::OnButtonClear(wxCommandEvent& WXUNUSED(event))
46 {
47 Clear();
48 EditorFrame::Get()->NotifyChanged(CHANGED_PROPS);
49 }
50
51
52 void PropEditCtrl::BeginEdit(const wxRect& rect, wxTreeItemId ti)
53 {
54 m_PropInfo = &(((PETreeData*)m_TreeCtrl->GetItemData(ti))->PropInfo);
55 m_TreeItem = ti;
56
57 m_CanSave = false;
58 if (!m_Created)
59 {
60 wxSizer *sz = new wxBoxSizer(wxHORIZONTAL);
61 m_TheCtrl = CreateEditCtrl();
62 sz->Add(m_TheCtrl, 1);
63 if (HasDetails())
64 sz->Add(new wxButton(this, ID_DETAILS, _T("..."), wxDefaultPosition,
65 wxSize(16,wxDefaultSize.y)));
66 if (HasClearButton())
67 sz->Add(new wxButton(this, ID_CLEAR, _T("X"), wxDefaultPosition,
68 wxSize(16,wxDefaultSize.y)));
69 SetSizer(sz);
70 m_Created = true;
71 }
72
73 m_TheCtrl->SetFocus();
74
75 SetSize(rect.x, rect.y, rect.width, rect.height);
76 Show(true);
77 ReadValue();
78 m_CanSave = true;
79 }
80
81
82
83 void PropEditCtrl::EndEdit()
84 {
85 Show(false);
86 }
87
88
89
90 wxTreeItemId PropEditCtrl::CreateTreeEntry(wxTreeItemId parent, const PropertyInfo& pinfo)
91 {
92 wxTreeItemId t = m_TreeCtrl->AppendItem(parent, GetPropName(pinfo));
93 m_TreeCtrl->SetItemData(t, new PETreeData(this, pinfo));
94 if (IsPresent(pinfo))
95 m_TreeCtrl->SetItemBold(t, true);
96 return t;
97 }
98
99 bool PropEditCtrl::IsPresent(const PropertyInfo& pinfo)
100 {
101 return XmlFindNode(GetNode(), pinfo.Name) != NULL;
102 }
103
104
105
106 void PropEditCtrl::Clear()
107 {
108 EndEdit();
109
110 wxXmlNode *n = XmlFindNode(GetNode(), m_PropInfo->Name);
111 if (n)
112 {
113 n->GetParent()->RemoveChild(n);
114 delete n;
115 m_TreeCtrl->SetItemBold(m_TreeItem, false);
116 }
117 }
118
119
120
121 wxString PropEditCtrl::GetValueAsText(wxTreeItemId ti)
122 {
123 PropertyInfo& pir = ((PETreeData*)m_TreeCtrl->GetItemData(ti))->PropInfo;
124 return XmlReadValue(GetNode(), pir.Name);
125 }
126