]>
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 "propframe.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 "wx/config.h" | |
23 | #include "splittree.h" | |
24 | #include "xmlhelpr.h" | |
25 | #include "propframe.h" | |
26 | #include "nodehnd.h" | |
27 | #include "propedit.h" | |
28 | #include "pe_basic.h" | |
29 | #include "pe_adv.h" | |
aaa2b34e | 30 | #include "editor.h" |
12d9e308 VS |
31 | |
32 | // ------------- support classes -------- | |
33 | ||
34 | ||
35 | class PropsTree: public wxRemotelyScrolledTreeCtrl | |
36 | { | |
37 | public: | |
38 | PropsTree(wxWindow* parent, wxWindowID id, const wxPoint& pt = wxDefaultPosition, | |
39 | const wxSize& sz = wxDefaultSize, long style = wxTR_HAS_BUTTONS) | |
40 | : wxRemotelyScrolledTreeCtrl(parent, id, pt, sz, style), | |
41 | m_EditCtrl(NULL) {} | |
42 | ||
43 | void OnPaint(wxPaintEvent& event) | |
44 | { | |
45 | wxPaintDC dc(this); | |
46 | ||
47 | wxTreeCtrl::OnPaint(event); | |
48 | ||
49 | // Reset the device origin since it may have been set | |
50 | dc.SetDeviceOrigin(0, 0); | |
51 | ||
a62da4c5 | 52 | wxPen pen(wxColour(_T("BLACK")), 1, wxSOLID); |
12d9e308 VS |
53 | dc.SetPen(pen); |
54 | ||
55 | dc.SetBrush(* wxTRANSPARENT_BRUSH); | |
56 | ||
57 | wxSize clientSize = GetClientSize(); | |
58 | wxRect itemRect; | |
59 | int cy=0; | |
60 | wxTreeItemId h, lastH; | |
61 | for(h=GetFirstVisibleItem();h;h=GetNextVisible(h)) | |
62 | { | |
63 | if (h.IsOk() && GetBoundingRect(h, itemRect)) | |
64 | { | |
65 | cy = itemRect.GetTop(); | |
66 | dc.DrawLine(0, cy, clientSize.x, cy); | |
67 | lastH = h; | |
68 | } | |
69 | } | |
70 | if (lastH.IsOk() && GetBoundingRect(lastH, itemRect)) | |
71 | { | |
72 | cy = itemRect.GetBottom(); | |
73 | dc.DrawLine(0, cy, clientSize.x, cy); | |
74 | } | |
75 | } | |
76 | ||
77 | void OnSelChange(wxTreeEvent& event) | |
78 | { | |
79 | if (m_EditCtrl != NULL) | |
80 | { | |
81 | m_EditCtrl->EndEdit(); | |
82 | m_EditCtrl = NULL; | |
83 | } | |
84 | ||
85 | wxTreeItemId item = event.GetItem(); | |
86 | PETreeData *dt = (PETreeData*)GetItemData(item); | |
87 | if (dt != NULL) | |
88 | { | |
89 | wxRect bounding; | |
90 | GetBoundingRect(item, bounding); | |
91 | bounding.SetX(0); | |
92 | bounding.SetWidth(GetCompanionWindow()->GetSize().x); | |
93 | dt->EditCtrl->BeginEdit(bounding, item); | |
94 | m_EditCtrl = dt->EditCtrl; | |
95 | } | |
96 | } | |
97 | ||
98 | void ClearProps() | |
99 | { | |
100 | DeleteAllItems(); | |
101 | AddRoot(_("Properties")); | |
102 | if (m_EditCtrl) | |
103 | { | |
104 | m_EditCtrl->EndEdit(); | |
105 | m_EditCtrl = NULL; | |
106 | } | |
107 | } | |
aaa2b34e VS |
108 | |
109 | void OnScroll(wxScrollWinEvent& event) | |
110 | { | |
111 | event.Skip(); | |
112 | if (event.GetOrientation() == wxHORIZONTAL) return; | |
113 | if (!m_EditCtrl) return; | |
114 | ||
115 | wxTreeItemId id = GetSelection(); | |
116 | wxRect bounding; | |
117 | GetBoundingRect(id, bounding); | |
118 | ||
119 | m_EditCtrl->Move(-1, bounding.y); | |
120 | } | |
12d9e308 VS |
121 | |
122 | PropEditCtrl *m_EditCtrl; | |
123 | ||
124 | DECLARE_EVENT_TABLE() | |
125 | }; | |
126 | ||
127 | BEGIN_EVENT_TABLE(PropsTree, wxRemotelyScrolledTreeCtrl) | |
128 | EVT_PAINT(PropsTree::OnPaint) | |
129 | EVT_TREE_SEL_CHANGED(-1, PropsTree::OnSelChange) | |
aaa2b34e | 130 | EVT_SCROLLWIN(PropsTree::OnScroll) |
12d9e308 VS |
131 | END_EVENT_TABLE() |
132 | ||
133 | ||
134 | class PropsValueWindow: public wxTreeCompanionWindow | |
135 | { | |
136 | public: | |
137 | PropsValueWindow(wxWindow* parent, wxWindowID id = -1, | |
138 | const wxPoint& pos = wxDefaultPosition, | |
139 | const wxSize& sz = wxDefaultSize, | |
140 | long style = 0) | |
141 | : wxTreeCompanionWindow(parent, id, pos, sz, style) {} | |
142 | ||
143 | virtual void DrawItem(wxDC& dc, wxTreeItemId id, const wxRect& rect) | |
144 | { | |
145 | if (m_treeCtrl) | |
146 | { | |
147 | PETreeData *data = (PETreeData*)m_treeCtrl->GetItemData(id); | |
148 | wxString text; | |
149 | if (data != NULL) text = data->EditCtrl->GetValueAsText(id); | |
150 | dc.SetBrush(wxBrush(GetBackgroundColour(), wxSOLID)); | |
151 | dc.DrawRectangle(rect); | |
152 | dc.SetTextForeground(* wxBLACK); | |
153 | dc.SetBackgroundMode(wxTRANSPARENT); | |
154 | ||
155 | int textW, textH; | |
156 | dc.GetTextExtent(text, & textW, & textH); | |
157 | ||
158 | int x = 5; | |
159 | int y = rect.GetY() + wxMax(0, (rect.GetHeight() - textH) / 2); | |
160 | ||
161 | dc.DrawText(text, x, y); | |
162 | } | |
163 | } | |
164 | ||
165 | void OnClick(wxMouseEvent& event) | |
166 | { | |
167 | int flags; | |
168 | wxTreeItemId item = GetTreeCtrl()->HitTest(wxPoint(1, event.GetY()), flags); | |
169 | if (item.IsOk()) | |
170 | { | |
171 | GetTreeCtrl()->ScrollTo(item); | |
172 | GetTreeCtrl()->SelectItem(item); | |
173 | } | |
174 | } | |
aaa2b34e | 175 | |
12d9e308 VS |
176 | DECLARE_EVENT_TABLE() |
177 | }; | |
178 | ||
179 | BEGIN_EVENT_TABLE(PropsValueWindow, wxTreeCompanionWindow) | |
180 | EVT_LEFT_DOWN(PropsValueWindow::OnClick) | |
181 | END_EVENT_TABLE() | |
182 | ||
183 | ||
184 | ||
185 | // ------------- properties frame -------- | |
186 | ||
187 | ||
188 | ||
189 | PropertiesFrame* PropertiesFrame::ms_Instance = NULL; | |
190 | ||
191 | PropertiesFrame *PropertiesFrame::Get() | |
192 | { | |
193 | if (ms_Instance == NULL) | |
194 | { | |
195 | (void)new PropertiesFrame; | |
196 | ms_Instance->Show(TRUE); | |
197 | } | |
198 | return ms_Instance; | |
199 | } | |
200 | ||
201 | PropertiesFrame::PropertiesFrame() | |
aaa2b34e VS |
202 | : wxFrame(EditorFrame::Get(), -1, _("Properties"), |
203 | wxDefaultPosition, wxDefaultSize, | |
204 | wxDEFAULT_FRAME_STYLE | wxFRAME_NO_TASKBAR | wxFRAME_TOOL_WINDOW) | |
12d9e308 VS |
205 | { |
206 | ms_Instance = this; | |
207 | m_Node = NULL; | |
208 | ||
209 | m_scrolledWindow = new wxSplitterScrolledWindow(this, -1, wxDefaultPosition, | |
210 | wxDefaultSize, wxNO_BORDER | wxCLIP_CHILDREN | wxVSCROLL); | |
211 | m_splitter = new wxThinSplitterWindow(m_scrolledWindow, -1, wxDefaultPosition, | |
212 | wxDefaultSize, wxSP_3DBORDER | wxCLIP_CHILDREN /* | wxSP_LIVE_UPDATE */); | |
213 | m_splitter->SetSashSize(2); | |
214 | m_tree = new PropsTree(m_splitter, -1, wxDefaultPosition, | |
215 | wxDefaultSize, wxTR_HAS_BUTTONS | wxTR_NO_LINES | wxNO_BORDER ); | |
216 | m_tree->SetIndent(2); | |
217 | ||
218 | m_valueWindow = new PropsValueWindow(m_splitter, -1, wxDefaultPosition, | |
219 | wxDefaultSize, wxNO_BORDER); | |
220 | m_valueWindow->SetBackgroundColour(m_tree->GetBackgroundColour()); | |
221 | m_splitter->SplitVertically(m_tree, m_valueWindow, wxConfig::Get()->Read(_T("propertiesframe_sash"), 100)); | |
222 | //m_splitter->AdjustScrollbars(); | |
223 | m_scrolledWindow->SetTargetWindow(m_tree); | |
224 | ||
225 | m_scrolledWindow->EnableScrolling(FALSE, FALSE); | |
226 | ||
227 | // Let the two controls know about each other | |
228 | m_valueWindow->SetTreeCtrl(m_tree); | |
229 | m_tree->SetCompanionWindow(m_valueWindow); | |
230 | ||
231 | wxConfigBase *cfg = wxConfigBase::Get(); | |
232 | SetSize(wxRect(wxPoint(cfg->Read(_T("propertiesframe_x"), -1), cfg->Read(_T("propertiesframe_y"), -1)), | |
233 | wxSize(cfg->Read(_T("propertiesframe_w"), 200), cfg->Read(_T("propertiesframe_h"), 200)))); | |
234 | ||
235 | ||
236 | m_EditCtrls.DeleteContents(TRUE); | |
237 | m_EditCtrls.Put(_T("bool"), new PropEditCtrlBool(this)); | |
238 | m_EditCtrls.Put(_T("coord"), new PropEditCtrlCoord(this)); | |
239 | m_EditCtrls.Put(_T("color"), new PropEditCtrlColor(this)); | |
240 | m_EditCtrls.Put(_T("dimension"), new PropEditCtrlDim(this)); | |
a62da4c5 | 241 | m_EditCtrls.Put(_T("flags"), new PropEditCtrlFlags(this)); |
12d9e308 VS |
242 | m_EditCtrls.Put(_T("integer"), new PropEditCtrlInt(this)); |
243 | m_EditCtrls.Put(_T("not_implemented"), new PropEditCtrlNull(this)); | |
244 | m_EditCtrls.Put(_T("text"), new PropEditCtrlTxt(this)); | |
245 | m_EditCtrls.Put(_T("xmlid"), new PropEditCtrlXMLID(this)); | |
246 | m_EditCtrls.Put(_T("font"), new PropEditCtrlFont(this)); | |
247 | m_EditCtrls.Put(_T("choice"), new PropEditCtrlChoice(this)); | |
26607f41 VS |
248 | m_EditCtrls.Put(_T("file"), new PropEditCtrlFile(this)); |
249 | m_EditCtrls.Put(_T("imagefile"), new PropEditCtrlImageFile(this)); | |
12d9e308 VS |
250 | m_EditCtrls.Put(_T(""), new PropEditCtrlNull(this)); |
251 | ||
252 | ClearProps(); | |
253 | } | |
254 | ||
255 | ||
256 | ||
257 | PropertiesFrame::~PropertiesFrame() | |
258 | { | |
259 | wxConfigBase *cfg = wxConfigBase::Get(); | |
260 | cfg->Write(_T("propertiesframe_x"), (long)GetPosition().x); | |
261 | cfg->Write(_T("propertiesframe_y"), (long)GetPosition().y); | |
262 | cfg->Write(_T("propertiesframe_w"), (long)GetSize().x); | |
263 | cfg->Write(_T("propertiesframe_h"), (long)GetSize().y); | |
264 | cfg->Write(_T("propertiesframe_sash"), (long)m_splitter->GetSashPosition()); | |
265 | ||
266 | ms_Instance = NULL; | |
267 | } | |
268 | ||
269 | ||
270 | ||
271 | void PropertiesFrame::ShowProps(wxXmlNode *node) | |
272 | { | |
273 | m_Node = node; | |
274 | ||
275 | ClearProps(); | |
276 | AddSingleProp(PropertyInfo(_T("xmlid"), _T("XMLID"), wxEmptyString)); | |
277 | AddProps(NodeHandler::Find(node)->GetPropsList(node)); | |
278 | ||
279 | m_tree->Expand(m_tree->GetRootItem()); | |
280 | m_valueWindow->Refresh(); | |
281 | } | |
282 | ||
283 | ||
284 | ||
285 | void PropertiesFrame::ClearProps() | |
286 | { | |
287 | ((PropsTree*)m_tree)->ClearProps(); | |
288 | } | |
289 | ||
290 | ||
291 | ||
292 | void PropertiesFrame::AddProps(PropertyInfoArray& plist) | |
293 | { | |
294 | for (size_t i = 0; i < plist.GetCount(); i++) | |
295 | { | |
296 | AddSingleProp(plist[i]); | |
297 | } | |
298 | } | |
299 | ||
300 | ||
301 | ||
a62da4c5 | 302 | void PropertiesFrame::AddSingleProp(const PropertyInfo& pinfo, wxTreeItemId *root) |
12d9e308 VS |
303 | { |
304 | PropEditCtrl *pec = (PropEditCtrl*)m_EditCtrls.Get(pinfo.Type); | |
a62da4c5 VS |
305 | wxTreeItemId tid; |
306 | if (root != NULL) tid = *root; | |
307 | else tid = m_tree->GetRootItem(); | |
12d9e308 VS |
308 | |
309 | if (pec == NULL) | |
310 | wxLogError(_("Unknown property type '%s'!"), pinfo.Type.c_str()); | |
311 | else | |
312 | pec->CreateTreeEntry(tid, pinfo); | |
313 | } | |
314 |