]> git.saurik.com Git - wxWidgets.git/blame - contrib/utils/wxrcedit/propedit.cpp
wxX11:
[wxWidgets.git] / contrib / utils / wxrcedit / propedit.cpp
CommitLineData
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"
999d9a9f 21#include "wx/xrc/xml.h"
12d9e308
VS
22#include "propframe.h"
23#include "propedit.h"
24#include "xmlhelpr.h"
26607f41 25#include "editor.h"
12d9e308
VS
26
27enum
28{
29 ID_CLEAR = wxID_HIGHEST + 1,
30 ID_DETAILS
31};
32
33
34
35BEGIN_EVENT_TABLE(PropEditCtrl, wxPanel)
36 EVT_BUTTON(ID_CLEAR, PropEditCtrl::OnButtonClear)
37 EVT_BUTTON(ID_DETAILS, PropEditCtrl::OnButtonDetails)
38END_EVENT_TABLE()
39
40void PropEditCtrl::OnButtonDetails(wxCommandEvent& event)
41{
42 OnDetails();
43}
44
45void PropEditCtrl::OnButtonClear(wxCommandEvent& event)
46{
47 Clear();
26607f41 48 EditorFrame::Get()->NotifyChanged(CHANGED_PROPS);
12d9e308
VS
49}
50
51
52void PropEditCtrl::BeginEdit(const wxRect& rect, wxTreeItemId ti)
53{
a62da4c5
VS
54 m_PropInfo = &(((PETreeData*)m_TreeCtrl->GetItemData(ti))->PropInfo);
55 m_TreeItem = ti;
56
12d9e308
VS
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
12d9e308
VS
76 SetSize(rect.x, rect.y, rect.width, rect.height);
77 Show(TRUE);
78 ReadValue();
79 m_CanSave = TRUE;
80}
81
82
83
84void PropEditCtrl::EndEdit()
85{
86 Show(FALSE);
87}
88
89
90
91wxTreeItemId 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
100bool PropEditCtrl::IsPresent(const PropertyInfo& pinfo)
101{
102 return XmlFindNode(GetNode(), pinfo.Name) != NULL;
103}
104
105
106
107void 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
122wxString PropEditCtrl::GetValueAsText(wxTreeItemId ti)
123{
124 PropertyInfo& pir = ((PETreeData*)m_TreeCtrl->GetItemData(ti))->PropInfo;
125 return XmlReadValue(GetNode(), pir.Name);
126}
127