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