1 ///////////////////////////////////////////////////////////////////////////////
2 // Name:        wx/gtk/private/eventsdisabler.h
3 // Purpose:     Helper for temporarily disabling events.
4 // Author:      Vadim Zeitlin
5 // Created:     2016-02-06
6 // Copyright:   (c) 2016 Vadim Zeitlin <vadim@wxwidgets.org>
7 // Licence:     wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
9 
10 #ifndef _GTK_PRIVATE_EVENTSDISABLER_H_
11 #define _GTK_PRIVATE_EVENTSDISABLER_H_
12 
13 // ----------------------------------------------------------------------------
14 // wxGtkEventsDisabler: calls GTKDisableEvents() and GTKEnableEvents() in dtor.
15 // ----------------------------------------------------------------------------
16 
17 // Template parameter T must be a wxGTK class providing the required methods,
18 // e.g. wxCheckBox, wxChoice, ...
19 template <typename T>
20 class wxGtkEventsDisabler
21 {
22 public:
23     // Disable the events for the specified (non-NULL, having lifetime greater
24     // than ours) window for the lifetime of this object.
wxGtkEventsDisabler(T * win)25     explicit wxGtkEventsDisabler(T* win) : m_win(win)
26     {
27         m_win->GTKDisableEvents();
28     }
29 
~wxGtkEventsDisabler()30     ~wxGtkEventsDisabler()
31     {
32         m_win->GTKEnableEvents();
33     }
34 
35 private:
36     T* const m_win;
37 
38     wxDECLARE_NO_COPY_TEMPLATE_CLASS(wxGtkEventsDisabler, T);
39 };
40 
41 #endif // _GTK_PRIVATE_EVENTSDISABLER_H_
42