-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCNewRulerLengthDialog.cpp
More file actions
116 lines (96 loc) · 3.17 KB
/
CNewRulerLengthDialog.cpp
File metadata and controls
116 lines (96 loc) · 3.17 KB
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
/**
* Copyright © 2024-2025 Piotr Domanski
* Licensed under the MIT license.
**/
#include "CNewRulerLengthDialog.h"
#include "CMainFrame.h"
namespace WinRuler
{
BEGIN_EVENT_TABLE(CNewRulerLengthDialog, wxDialog)
EVT_CLOSE(CNewRulerLengthDialog::OnClose)
EVT_BUTTON(wxID_OK, CNewRulerLengthDialog::OnOKButtonClicked)
END_EVENT_TABLE()
CNewRulerLengthDialog::CNewRulerLengthDialog(
wxWindow* Parent, wxWindowID Id,
const wxString& Title, const wxPoint& Pos, const wxSize& Size,
long Style) :
wxDialog(Parent, Id, Title, Pos, Size, Style)
{
// Initialize class.
Init();
// Create class controls.
CreateControls();
// Setup sizers.
SetupSizers();
// Centre dialog.
Centre();
}
CNewRulerLengthDialog::~CNewRulerLengthDialog()
{
// Release all instances from heap.
wxDELETE(m_pOKButton);
wxDELETE(m_pSpinCtrl);
wxDELETE(m_pChooseStaticText);
}
void CNewRulerLengthDialog::Init()
{
// Set all class instances as NULL.
m_pChooseStaticText = NULL;
m_pSpinCtrl = NULL;
m_pOKButton = NULL;
}
void CNewRulerLengthDialog::CreateControls()
{
// Retrieve our MainFrame.
CMainFrame* pMainFrame = static_cast<CMainFrame*>(this->GetParent());
// Set client size.
SetClientSize(400, 200);
// Create Choose static text.
m_pChooseStaticText =
new wxStaticText(
this, wxID_ANY,
wxString(
"Please enter the new length of the ruler (in pixels):"));
// Create Spin control.
m_pSpinCtrl =
new wxSpinCtrl(
this, wxID_ANY,
wxString::Format(
"%d", static_cast<int>(pMainFrame->m_iRulerLength)),
wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS,
pMainFrame->m_iRulerMinimumLengthLimit, 2000);
// Create OK button.
m_pOKButton = new wxButton(this, wxID_OK, "&OK");
}
void CNewRulerLengthDialog::SetupSizers()
{
// Create wxBoxSizer and fit all components.
wxBoxSizer* pBoxSizer = new wxBoxSizer(wxVERTICAL);
pBoxSizer->Add(
m_pChooseStaticText,
wxSizerFlags().Proportion(0).Expand().Border(wxALL, 5));
pBoxSizer->Add(
m_pSpinCtrl,
wxSizerFlags().Proportion(1).Expand().Border(wxALL, 5));
pBoxSizer->AddSpacer(8);
pBoxSizer->Add(
m_pOKButton,
wxSizerFlags().Proportion(0).Center().Border(wxALL, 5));
SetSizerAndFit(pBoxSizer);
}
void CNewRulerLengthDialog::OnOKButtonClicked(
wxCommandEvent& WXUNUSED(Event))
{
// Retrieve CMainFrame instance.
CMainFrame* pMainFrame = static_cast<CMainFrame*>(this->GetParent());
// Change ruler's length.
pMainFrame->ChangeRulerLength(m_pSpinCtrl->GetValue());
// Close this dialog.
Close(true);
}
void CNewRulerLengthDialog::OnClose(wxCloseEvent& Event)
{
// Destroy class.
Destroy();
}
} // end namespace WinRuler