KiCad PCB EDA Suite
Loading...
Searching...
No Matches
raii.h
Go to the documentation of this file.
1
/*
2
* This program source code file is part of KiCad, a free EDA CAD application.
3
*
4
* Copyright The KiCad Developers, see AUTHORS.TXT for contributors.
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 3
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18
*/
19
20
#ifndef RAII_H
21
#define RAII_H
22
23
#include <wx/window.h>
24
25
26
/*
27
* Exception-safe (and 'return' safe) scoped handlers following the "resource allocation is
28
* initialization" pattern.
29
*/
30
31
32
// Exception-safe method for nulling a pointer
33
class
NULLER
34
{
35
public
:
36
NULLER
(
void
*& aPtr ) :
37
m_what
( aPtr )
38
{}
39
40
~NULLER
()
41
{
42
m_what
=
nullptr
;
43
}
44
45
private
:
46
void
*&
m_what
;
47
};
48
49
50
// Temporarily un-freeze a window, and then re-freeze on destruction
51
class
WINDOW_THAWER
52
{
53
public
:
54
WINDOW_THAWER
( wxWindow* aWindow )
55
{
56
m_window
= aWindow;
57
m_freezeCount
= 0;
58
59
while
(
m_window
->IsFrozen() )
60
{
61
m_window
->Thaw();
62
m_freezeCount
++;
63
}
64
}
65
66
~WINDOW_THAWER
()
67
{
68
while
(
m_freezeCount
> 0 )
69
{
70
m_window
->Freeze();
71
m_freezeCount
--;
72
}
73
}
74
75
protected
:
76
wxWindow*
m_window
;
77
int
m_freezeCount
;
78
};
79
80
82
class
WINDOW_DISABLER
83
{
84
public
:
85
WINDOW_DISABLER
( wxWindow* aWindow ) :
86
m_win
( aWindow )
87
{
88
if
(
m_win
)
89
m_win
->Disable();
90
}
91
92
~WINDOW_DISABLER
()
93
{
94
if
(
m_win
)
95
{
96
m_win
->Enable();
97
m_win
->Raise();
// let's focus back on the parent window
98
}
99
}
100
101
void
SuspendForTrueModal
()
102
{
103
if
(
m_win
)
104
m_win
->Enable();
105
}
106
107
void
ResumeAfterTrueModal
()
108
{
109
if
(
m_win
)
110
m_win
->Disable();
111
}
112
113
private
:
114
wxWindow*
m_win
;
115
};
116
117
118
#endif
// RAII_H
NULLER::NULLER
NULLER(void *&aPtr)
Definition
raii.h:36
NULLER::m_what
void *& m_what
Definition
raii.h:46
NULLER::~NULLER
~NULLER()
Definition
raii.h:40
WINDOW_DISABLER::~WINDOW_DISABLER
~WINDOW_DISABLER()
Definition
raii.h:92
WINDOW_DISABLER::SuspendForTrueModal
void SuspendForTrueModal()
Definition
raii.h:101
WINDOW_DISABLER::m_win
wxWindow * m_win
Definition
raii.h:114
WINDOW_DISABLER::ResumeAfterTrueModal
void ResumeAfterTrueModal()
Definition
raii.h:107
WINDOW_DISABLER::WINDOW_DISABLER
WINDOW_DISABLER(wxWindow *aWindow)
Definition
raii.h:85
WINDOW_THAWER::WINDOW_THAWER
WINDOW_THAWER(wxWindow *aWindow)
Definition
raii.h:54
WINDOW_THAWER::m_window
wxWindow * m_window
Definition
raii.h:76
WINDOW_THAWER::m_freezeCount
int m_freezeCount
Definition
raii.h:77
WINDOW_THAWER::~WINDOW_THAWER
~WINDOW_THAWER()
Definition
raii.h:66
src
libs
core
include
core
raii.h
Generated on Fri Jun 26 2026 00:05:37 for KiCad PCB EDA Suite by
1.13.2