/
DialogBase.cpp
46 lines (37 loc) · 1.06 KB
/
DialogBase.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
#include "DialogBase.h"
namespace wxutil
{
void DialogBase::_onDelete(wxCloseEvent& ev)
{
if (_onDeleteEvent())
{
ev.Veto();
}
else
{
EndModal(wxID_CANCEL);
}
}
DialogBase::DialogBase(const std::string& title, wxWindow* parent)
: wxDialog(parent ? parent : GlobalMainFrame().getWxTopLevelWindow(),
wxID_ANY, title, wxDefaultPosition, wxDefaultSize,
wxCAPTION | wxSYSTEM_MENU | wxRESIZE_BORDER)
{
Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(DialogBase::_onDelete),
nullptr, this);
}
void DialogBase::FitToScreen(float xProp, float yProp)
{
int curDisplayIdx = 0;
if (GlobalMainFrame().getWxTopLevelWindow() != NULL)
{
curDisplayIdx = wxDisplay::GetFromWindow(GlobalMainFrame().getWxTopLevelWindow());
}
wxDisplay curDisplay(curDisplayIdx);
wxRect rect = curDisplay.GetGeometry();
int newWidth = static_cast<int>(rect.GetWidth() * xProp);
int newHeight = static_cast<int>(rect.GetHeight() * yProp);
SetSize(newWidth, newHeight);
CenterOnScreen();
}
}