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