]> git.saurik.com Git - wxWidgets.git/blob - contrib/utils/wxrcedit/propedit.cpp
changed version number
[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& event)
41 {
42 OnDetails();
43 }
44
45 void PropEditCtrl::OnButtonClear(wxCommandEvent& 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,-1)));
66 if (HasClearButton())
67 sz->Add(new wxButton(this, ID_CLEAR, _T("X"), wxDefaultPosition,
68 wxSize(16,-1)));
69 SetAutoLayout(TRUE);
70 SetSizer(sz);
71 m_Created = TRUE;
72 }
73
74 m_TheCtrl->SetFocus();
75
76 SetSize(rect.x, rect.y, rect.width, rect.height);
77 Show(TRUE);
78 ReadValue();
79 m_CanSave = TRUE;
80 }
81
82
83
84 void PropEditCtrl::EndEdit()
85 {
86 Show(FALSE);
87 }
88
89
90
91 wxTreeItemId PropEditCtrl::CreateTreeEntry(wxTreeItemId parent, const PropertyInfo& pinfo)
92 {
93 wxTreeItemId t = m_TreeCtrl->AppendItem(parent, GetPropName(pinfo));
94 m_TreeCtrl->SetItemData(t, new PETreeData(this, pinfo));
95 if (IsPresent(pinfo))
96 m_TreeCtrl->SetItemBold(t, TRUE);
97 return t;
98 }
99
100 bool PropEditCtrl::IsPresent(const PropertyInfo& pinfo)
101 {
102 return XmlFindNode(GetNode(), pinfo.Name) != NULL;
103 }
104
105
106
107 void PropEditCtrl::Clear()
108 {
109 EndEdit();
110
111 wxXmlNode *n = XmlFindNode(GetNode(), m_PropInfo->Name);
112 if (n)
113 {
114 n->GetParent()->RemoveChild(n);
115 delete n;
116 m_TreeCtrl->SetItemBold(m_TreeItem, FALSE);
117 }
118 }
119
120
121
122 wxString PropEditCtrl::GetValueAsText(wxTreeItemId ti)
123 {
124 PropertyInfo& pir = ((PETreeData*)m_TreeCtrl->GetItemData(ti))->PropInfo;
125 return XmlReadValue(GetNode(), pir.Name);
126 }
127