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, you may find one here:
18
* http://www.gnu.org/licenses/old-licenses/gpl-3.0.html
19
* or you may search the http://www.gnu.org website for the version 3 license,
20
* or you may write to the Free Software Foundation, Inc.,
21
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22
*/
23
24
#ifndef RAII_H
25
#define RAII_H
26
27
#include <wx/window.h>
28
29
30
/*
31
* Exception-safe (and 'return' safe) scoped handlers following the "resource allocation is
32
* initialization" pattern.
33
*/
34
35
36
// Exception-safe method for nulling a pointer
37
class
NULLER
38
{
39
public
:
40
NULLER
(
void
*& aPtr )
41
:
m_what
( aPtr )
42
{}
43
44
~NULLER
()
45
{
46
m_what
=
nullptr
;
47
}
48
49
private
:
50
void
*&
m_what
;
51
};
52
53
54
// Temporarily un-freeze a window, and then re-freeze on destruction
55
class
WINDOW_THAWER
56
{
57
public
:
58
WINDOW_THAWER
( wxWindow* aWindow )
59
{
60
m_window
= aWindow;
61
m_freezeCount
= 0;
62
63
while
(
m_window
->IsFrozen() )
64
{
65
m_window
->Thaw();
66
m_freezeCount
++;
67
}
68
}
69
70
~WINDOW_THAWER
()
71
{
72
while
(
m_freezeCount
> 0 )
73
{
74
m_window
->Freeze();
75
m_freezeCount
--;
76
}
77
}
78
79
protected
:
80
wxWindow*
m_window
;
81
int
m_freezeCount
;
82
};
83
84
86
class
WINDOW_DISABLER
87
{
88
public
:
89
WINDOW_DISABLER
( wxWindow* aWindow ) :
90
m_win
( aWindow )
91
{
92
if
(
m_win
)
93
m_win
->Disable();
94
}
95
96
~WINDOW_DISABLER
()
97
{
98
if
(
m_win
)
99
{
100
m_win
->Enable();
101
m_win
->Raise();
// let's focus back on the parent window
102
}
103
}
104
105
void
SuspendForTrueModal
()
106
{
107
if
(
m_win
)
108
m_win
->Enable();
109
}
110
111
void
ResumeAfterTrueModal
()
112
{
113
if
(
m_win
)
114
m_win
->Disable();
115
}
116
117
private
:
118
wxWindow*
m_win
;
119
};
120
121
122
#endif
// RAII_H
NULLER
Definition:
raii.h:38
NULLER::NULLER
NULLER(void *&aPtr)
Definition:
raii.h:40
NULLER::m_what
void *& m_what
Definition:
raii.h:50
NULLER::~NULLER
~NULLER()
Definition:
raii.h:44
WINDOW_DISABLER
Temporarily disable a window, and then re-enable on destruction.
Definition:
raii.h:87
WINDOW_DISABLER::~WINDOW_DISABLER
~WINDOW_DISABLER()
Definition:
raii.h:96
WINDOW_DISABLER::SuspendForTrueModal
void SuspendForTrueModal()
Definition:
raii.h:105
WINDOW_DISABLER::m_win
wxWindow * m_win
Definition:
raii.h:118
WINDOW_DISABLER::ResumeAfterTrueModal
void ResumeAfterTrueModal()
Definition:
raii.h:111
WINDOW_DISABLER::WINDOW_DISABLER
WINDOW_DISABLER(wxWindow *aWindow)
Definition:
raii.h:89
WINDOW_THAWER
Definition:
raii.h:56
WINDOW_THAWER::WINDOW_THAWER
WINDOW_THAWER(wxWindow *aWindow)
Definition:
raii.h:58
WINDOW_THAWER::m_window
wxWindow * m_window
Definition:
raii.h:80
WINDOW_THAWER::m_freezeCount
int m_freezeCount
Definition:
raii.h:81
WINDOW_THAWER::~WINDOW_THAWER
~WINDOW_THAWER()
Definition:
raii.h:70
src
libs
core
include
core
raii.h
Generated on Sun Mar 9 2025 00:05:30 for KiCad PCB EDA Suite by
1.9.6