]> git.saurik.com Git - wxWidgets.git/blob - include/wx/persist/window.h
Somehow, setting a tint color makes gauge work :/.
[wxWidgets.git] / include / wx / persist / window.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/persist/window.h
3 // Purpose: wxPersistentWindow declaration
4 // Author: Vadim Zeitlin
5 // Created: 2009-01-23
6 // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #ifndef _WX_PERSIST_WINDOW_H_
11 #define _WX_PERSIST_WINDOW_H_
12
13 #include "wx/persist.h"
14
15 #include "wx/window.h"
16
17 // ----------------------------------------------------------------------------
18 // wxPersistentWindow: base class for persistent windows, uses the window name
19 // as persistent name by default and automatically reacts
20 // to the window destruction
21 // ----------------------------------------------------------------------------
22
23 // type-independent part of wxPersistentWindow
24 class wxPersistentWindowBase :
25 wxBIND_OR_CONNECT_HACK_BASE_CLASS
26 public wxPersistentObject
27 {
28 public:
29 wxPersistentWindowBase(wxWindow *win)
30 : wxPersistentObject(win)
31 {
32 wxBIND_OR_CONNECT_HACK(win, wxEVT_DESTROY, wxWindowDestroyEventHandler,
33 wxPersistentWindowBase::HandleDestroy, this);
34 }
35
36 virtual wxString GetName() const
37 {
38 const wxString name = GetWindow()->GetName();
39 wxASSERT_MSG( !name.empty(), "persistent windows should be named!" );
40
41 return name;
42 }
43
44 protected:
45 wxWindow *GetWindow() const { return static_cast<wxWindow *>(GetObject()); }
46
47 private:
48 void HandleDestroy(wxWindowDestroyEvent& event)
49 {
50 event.Skip();
51
52 // only react to the destruction of this object itself, not of any of
53 // its children
54 if ( event.GetEventObject() == GetObject() )
55 {
56 // this will delete this object itself
57 wxPersistenceManager::Get().SaveAndUnregister(GetWindow());
58 }
59 }
60
61 wxDECLARE_NO_COPY_CLASS(wxPersistentWindowBase);
62 };
63
64 template <class T>
65 class wxPersistentWindow : public wxPersistentWindowBase
66 {
67 public:
68 typedef T WindowType;
69
70 wxPersistentWindow(WindowType *win)
71 : wxPersistentWindowBase(win)
72 {
73 }
74
75 WindowType *Get() const { return static_cast<WindowType *>(GetWindow()); }
76 };
77
78 #endif // _WX_PERSIST_WINDOW_H_
79