]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/xrc/xh_unkwn.cpp
Better alphabetized the event handler macros
[wxWidgets.git] / src / xrc / xh_unkwn.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: xh_unkwn.cpp
3// Purpose: XRC resource for unknown widget
4// Author: Vaclav Slavik
5// Created: 2000/09/09
6// RCS-ID: $Id$
7// Copyright: (c) 2000 Vaclav Slavik
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11#ifdef __GNUG__
12#pragma implementation "xh_unkwn.h"
13#endif
14
15// For compilers that support precompilation, includes "wx.h".
16#include "wx/wxprec.h"
17
18#ifdef __BORLANDC__
19 #pragma hdrstop
20#endif
21
22#if wxUSE_XRC
23
24#include "wx/xrc/xh_unkwn.h"
25#include "wx/window.h"
26#include "wx/log.h"
27#include "wx/sizer.h"
28#include "wx/panel.h"
29
30
31class wxUnknownControlContainer : public wxPanel
32{
33public:
34 wxUnknownControlContainer(wxWindow *parent,
35 const wxString& controlName,
36 wxWindowID id = wxID_ANY,
37 const wxPoint& pos = wxDefaultPosition,
38 const wxSize& size = wxDefaultSize,
39 long style = 0)
40 // Always add the wxTAB_TRAVERSAL and wxNO_BORDER styles to what comes
41 // from the XRC if anything.
42 : wxPanel(parent, id, pos, size, style | wxTAB_TRAVERSAL | wxNO_BORDER,
43 controlName + wxT("_container")),
44 m_controlName(controlName), m_controlAdded(false)
45 {
46 m_bg = GetBackgroundColour();
47 SetBackgroundColour(wxColour(255, 0, 255));
48 }
49
50 virtual void AddChild(wxWindowBase *child);
51 virtual void RemoveChild(wxWindowBase *child);
52
53protected:
54 wxString m_controlName;
55 bool m_controlAdded;
56 wxColour m_bg;
57};
58
59void wxUnknownControlContainer::AddChild(wxWindowBase *child)
60{
61 wxASSERT_MSG( !m_controlAdded, wxT("Couldn't add two unknown controls to the same container!") );
62
63 wxPanel::AddChild(child);
64
65 SetBackgroundColour(m_bg);
66 child->SetName(m_controlName);
67 child->SetId(wxXmlResource::GetXRCID(m_controlName));
68 m_controlAdded = true;
69
70 wxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
71 sizer->Add((wxWindow*)child, 1, wxEXPAND);
72 SetSizer(sizer);
73 Layout();
74}
75
76void wxUnknownControlContainer::RemoveChild(wxWindowBase *child)
77{
78 wxPanel::RemoveChild(child);
79 m_controlAdded = false;
80 GetSizer()->Detach((wxWindow*)child);
81}
82
83
84IMPLEMENT_DYNAMIC_CLASS(wxUnknownWidgetXmlHandler, wxXmlResourceHandler)
85
86wxUnknownWidgetXmlHandler::wxUnknownWidgetXmlHandler()
87: wxXmlResourceHandler()
88{
89 XRC_ADD_STYLE(wxNO_FULL_REPAINT_ON_RESIZE);
90}
91
92wxObject *wxUnknownWidgetXmlHandler::DoCreateResource()
93{
94 wxASSERT_MSG( m_instance == NULL,
95 _T("'unknown' controls can't be subclassed, use wxXmlResource::AttachUnknownControl") );
96
97 wxPanel *panel =
98 new wxUnknownControlContainer(m_parentAsWindow,
99 GetName(), wxID_ANY,
100 GetPosition(), GetSize(),
101 GetStyle(wxT("style")));
102 SetupWindow(panel);
103 return panel;
104}
105
106bool wxUnknownWidgetXmlHandler::CanHandle(wxXmlNode *node)
107{
108 return IsOfClass(node, wxT("unknown"));
109}
110
111#endif // wxUSE_XRC