Debian Codegraph @

wxcrafter/src/designer_container_panel.cpp

raw
1 #include "CaptionBar.h"
2 #include "allocator_mgr.h"
3 #include "designer_container_panel.h"
4 #include "wxcTreeView.h"
5 #include "wxguicraft_main_view.h"
6 #include <event_notifier.h>
7 #include <wx/dcbuffer.h>
8 #include <wx/settings.h>
9
10 DesignerContainerPanel::DesignerContainerPanel(wxWindow* parent)
11 : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(-1, -1), wxTAB_TRAVERSAL | wxBORDER_RAISED)
12 , m_mainPanel(NULL)
13 , m_height(-1)
14 , m_width(-1)
15 , m_topLevelType(ID_WXPANEL_TOPLEVEL)
16 , m_caption(NULL)
17 {
18 Bind(wxEVT_SIZE, &DesignerContainerPanel::OnSize, this);
19 wxBoxSizer* sz = new wxBoxSizer(wxVERTICAL);
20 SetSizer(sz);
21 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
22 }
23
24 DesignerContainerPanel::~DesignerContainerPanel() { Unbind(wxEVT_SIZE, &DesignerContainerPanel::OnSize, this); }
25
26 void DesignerContainerPanel::EnableCaption(const wxString& caption, const wxString& style, const wxBitmap& icon)
27 {
28 m_caption = new CaptionBar(this, caption, style, icon);
29 GetSizer()->Insert(0, m_caption, 0, wxEXPAND | wxALL, 2);
30 m_height += m_caption->GetSize().GetHeight();
31 }
32
33 void DesignerContainerPanel::SetMenuBar(MenuBar* mb)
34 {
35 mb->Connect(wxEVT_RIGHT_DOWN, wxMouseEventHandler(DesignerContainerPanel::OnRightDown), NULL, this);
36
37 // Make sure that the caption is on top of the menu bar
38 GetSizer()->Insert(m_caption ? 1 : 0, mb, 0, wxEXPAND);
39 m_height += mb->GetSize().GetHeight();
40 }
41
42 void DesignerContainerPanel::SetStatusBar(wxStatusBar* mb)
43 {
44 mb->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(DesignerContainerPanel::OnLeftDown), NULL, this);
45 mb->Connect(wxEVT_RIGHT_DOWN, wxMouseEventHandler(DesignerContainerPanel::OnRightDown), NULL, this);
46 GetSizer()->Add(mb, 0, wxEXPAND);
47 m_height += mb->GetSize().GetHeight();
48 }
49
50 void DesignerContainerPanel::SetToolbar(ToolBar* tb)
51 {
52 tb->Connect(wxEVT_RIGHT_DOWN, wxMouseEventHandler(DesignerContainerPanel::OnRightDown), NULL, this);
53 GetSizer()->Add(tb, 0, wxEXPAND);
54 m_height += tb->GetSize().GetHeight();
55 }
56
57 void DesignerContainerPanel::AddMainView(wxPanel* panel)
58 {
59 m_width = panel->GetSize().x;
60 GetSizer()->Add(panel, 1, wxEXPAND);
61 m_mainPanel = panel;
62 m_height += m_mainPanel->GetSize().GetHeight();
63
64 DoConnectCharEvent(this);
65 }
66
67 void DesignerContainerPanel::CalcBestSize(int winType)
68 {
69 wxcWidget* page = GUICraftMainPanel::m_MainPanel->GetActiveWizardPage();
70 wxcWidget* topWin = GUICraftMainPanel::m_MainPanel->GetActiveTopLevelWin();
71
72 if(winType != ID_WXWIZARD || !page) {
73
74 if(topWin)
75 SetSizeHints(topWin->GetSize());
76 else
77 SetSizeHints(m_width, m_height);
78
79 GetSizer()->Fit(this);
80
81 } else {
82
83 wxSize sz = page->GetSize();
84 SetSizeHints(sz);
85 GetSizer()->Fit(this);
86 }
87 }
88
89 void DesignerContainerPanel::OnLeftDown(wxMouseEvent& e) { wxUnusedVar(e); }
90
91 void DesignerContainerPanel::OnRightDown(wxMouseEvent& e)
92 {
93 e.Skip();
94 wxCommandEvent contextEvent(wxEVT_SHOW_CONTEXT_MENU);
95 EventNotifier::Get()->AddPendingEvent(contextEvent);
96 }
97
98 void DesignerContainerPanel::DoConnectCharEvent(wxWindow* win)
99 {
100 if(win) {
101 m_windows.insert(win);
102
103 wxWindowList::compatibility_iterator pclNode = win->GetChildren().GetFirst();
104 while(pclNode) {
105 wxWindow* pclChild = pclNode->GetData();
106 this->DoConnectCharEvent(pclChild);
107 pclNode = pclNode->GetNext();
108 }
109 }
110 }
111
112 void DesignerContainerPanel::OnSize(wxSizeEvent& event)
113 {
114 event.Skip();
115 Refresh();
116 }