/
TopLevelFrame.cpp
123 lines (97 loc) · 3.01 KB
/
TopLevelFrame.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "TopLevelFrame.h"
#include "itextstream.h"
#include "i18n.h"
#include "iuimanager.h"
#include <wx/artprov.h>
#include <wx/toolbar.h>
#include <wx/menu.h>
#include <wx/app.h>
namespace ui
{
TopLevelFrame::TopLevelFrame() :
wxFrame(NULL, wxID_ANY, wxT("DarkRadiant")),
_topLevelContainer(NULL),
_mainContainer(NULL)
{
_topLevelContainer = new wxBoxSizer(wxVERTICAL);
SetSizer(_topLevelContainer);
wxMenuBar* menuBar = createMenuBar();
if (menuBar != nullptr)
{
SetMenuBar(menuBar);
}
// Instantiate the ToolbarManager and retrieve the view toolbar widget
IToolbarManager& tbCreator = GlobalUIManager().getToolbarManager();
wxToolBar* viewToolbar = tbCreator.getToolbar("view", this);
if (viewToolbar != NULL)
{
_toolbars[IMainFrame::TOOLBAR_HORIZONTAL] = viewToolbar;
// Pack it into the main window
_topLevelContainer->Add(_toolbars[IMainFrame::TOOLBAR_HORIZONTAL].get(), 0, wxEXPAND);
}
else
{
rWarning() << "TopLevelFrame: Cannot instantiate view toolbar!" << std::endl;
}
_mainContainer = new wxBoxSizer(wxHORIZONTAL);
_topLevelContainer->Add(_mainContainer, 1, wxEXPAND);
// Get the edit toolbar widget
wxToolBar* editToolbar = tbCreator.getToolbar("edit", this);
if (editToolbar != NULL)
{
_toolbars[IMainFrame::TOOLBAR_VERTICAL] = editToolbar;
// Pack it into the main window
_mainContainer->Add(_toolbars[IMainFrame::TOOLBAR_VERTICAL].get(), 0, wxEXPAND);
}
else
{
rWarning() << "MainFrame: Cannot instantiate edit toolbar!" << std::endl;
}
wxWindow* statusBar = GlobalUIManager().getStatusBarManager().getStatusBar();
statusBar->Reparent(this);
statusBar->SetCanFocus(false);
_topLevelContainer->Add(statusBar, 0, wxEXPAND);
// Set the window icon
wxIcon appIcon;
appIcon.CopyFromBitmap(wxArtProvider::GetBitmap(
GlobalUIManager().ArtIdPrefix() + "darkradiant_icon_64x64.png"));
SetIcon(appIcon);
// Redirect scroll events to the window below the cursor
_scrollEventFilter.reset(new wxutil::ScrollEventPropagationFilter);
#if (wxMAJOR_VERSION >= 3) && (wxMINOR_VERSION < 1)
// In wxWidgets < 3.1.0 we don't receive the wxEVT_MENU_OPEN event on
// the menu itself (only on the toplevel frame), so let's propagate it
Connect(wxEVT_MENU_OPEN, wxMenuEventHandler(TopLevelFrame::onMenuOpenClose), nullptr, this);
#endif
}
wxToolBar* TopLevelFrame::getToolbar(IMainFrame::Toolbar type)
{
ToolbarMap::const_iterator found = _toolbars.find(type);
return (found != _toolbars.end()) ? found->second.get() : nullptr;
}
bool TopLevelFrame::Destroy()
{
// Clear out any references to toolbars while the modules are still loaded
_toolbars.clear();
return wxFrame::Destroy();
}
wxMenuBar* TopLevelFrame::createMenuBar()
{
// Return the "main" menubar from the UIManager
return GlobalUIManager().getMenuManager().getMenuBar("main");
}
wxBoxSizer* TopLevelFrame::getMainContainer()
{
return _mainContainer;
}
void TopLevelFrame::onMenuOpenClose(wxMenuEvent& ev)
{
if (GetMenuBar() != nullptr)
{
if (!GetMenuBar()->HandleWindowEvent(ev))
{
ev.Skip();
}
}
}
} // namespace