]>
Commit | Line | Data |
---|---|---|
12d9e308 VS |
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 | ||
26 | enum | |
27 | { | |
28 | ID_CLEAR = wxID_HIGHEST + 1, | |
29 | ID_DETAILS | |
30 | }; | |
31 | ||
32 | ||
33 | ||
34 | BEGIN_EVENT_TABLE(PropEditCtrl, wxPanel) | |
35 | EVT_BUTTON(ID_CLEAR, PropEditCtrl::OnButtonClear) | |
36 | EVT_BUTTON(ID_DETAILS, PropEditCtrl::OnButtonDetails) | |
37 | END_EVENT_TABLE() | |
38 | ||
39 | void PropEditCtrl::OnButtonDetails(wxCommandEvent& event) | |
40 | { | |
41 | OnDetails(); | |
42 | } | |
43 | ||
44 | void PropEditCtrl::OnButtonClear(wxCommandEvent& event) | |
45 | { | |
46 | Clear(); | |
47 | } | |
48 | ||
49 | ||
50 | void PropEditCtrl::BeginEdit(const wxRect& rect, wxTreeItemId ti) | |
51 | { | |
a62da4c5 VS |
52 | m_PropInfo = &(((PETreeData*)m_TreeCtrl->GetItemData(ti))->PropInfo); |
53 | m_TreeItem = ti; | |
54 | ||
12d9e308 VS |
55 | m_CanSave = FALSE; |
56 | if (!m_Created) | |
57 | { | |
58 | wxSizer *sz = new wxBoxSizer(wxHORIZONTAL); | |
59 | m_TheCtrl = CreateEditCtrl(); | |
60 | sz->Add(m_TheCtrl, 1); | |
61 | if (HasDetails()) | |
62 | sz->Add(new wxButton(this, ID_DETAILS, _T("..."), wxDefaultPosition, | |
63 | wxSize(16,-1))); | |
64 | if (HasClearButton()) | |
65 | sz->Add(new wxButton(this, ID_CLEAR, _T("X"), wxDefaultPosition, | |
66 | wxSize(16,-1))); | |
67 | SetAutoLayout(TRUE); | |
68 | SetSizer(sz); | |
69 | m_Created = TRUE; | |
70 | } | |
71 | ||
72 | m_TheCtrl->SetFocus(); | |
73 | ||
12d9e308 VS |
74 | SetSize(rect.x, rect.y, rect.width, rect.height); |
75 | Show(TRUE); | |
76 | ReadValue(); | |
77 | m_CanSave = TRUE; | |
78 | } | |
79 | ||
80 | ||
81 | ||
82 | void PropEditCtrl::EndEdit() | |
83 | { | |
84 | Show(FALSE); | |
85 | } | |
86 | ||
87 | ||
88 | ||
89 | wxTreeItemId PropEditCtrl::CreateTreeEntry(wxTreeItemId parent, const PropertyInfo& pinfo) | |
90 | { | |
91 | wxTreeItemId t = m_TreeCtrl->AppendItem(parent, GetPropName(pinfo)); | |
92 | m_TreeCtrl->SetItemData(t, new PETreeData(this, pinfo)); | |
93 | if (IsPresent(pinfo)) | |
94 | m_TreeCtrl->SetItemBold(t, TRUE); | |
95 | return t; | |
96 | } | |
97 | ||
98 | bool PropEditCtrl::IsPresent(const PropertyInfo& pinfo) | |
99 | { | |
100 | return XmlFindNode(GetNode(), pinfo.Name) != NULL; | |
101 | } | |
102 | ||
103 | ||
104 | ||
105 | void PropEditCtrl::Clear() | |
106 | { | |
107 | EndEdit(); | |
108 | ||
109 | wxXmlNode *n = XmlFindNode(GetNode(), m_PropInfo->Name); | |
110 | if (n) | |
111 | { | |
112 | n->GetParent()->RemoveChild(n); | |
113 | delete n; | |
114 | m_TreeCtrl->SetItemBold(m_TreeItem, FALSE); | |
115 | } | |
116 | } | |
117 | ||
118 | ||
119 | ||
120 | wxString PropEditCtrl::GetValueAsText(wxTreeItemId ti) | |
121 | { | |
122 | PropertyInfo& pir = ((PETreeData*)m_TreeCtrl->GetItemData(ti))->PropInfo; | |
123 | return XmlReadValue(GetNode(), pir.Name); | |
124 | } | |
125 |