]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/persist/window.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/persist/window.h
3 // Purpose: wxPersistentWindow declaration
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_PERSIST_WINDOW_H_
12 #define _WX_PERSIST_WINDOW_H_
14 #include "wx/persist.h"
16 #include "wx/window.h"
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 // ----------------------------------------------------------------------------
24 // type-independent part of wxPersistentWindow
25 class wxPersistentWindowBase
:
26 #if wxEVENTS_COMPATIBILITY_2_8
27 // in compatibility mode we need to derive from wxEvtHandler to be able to
31 public wxPersistentObject
34 wxPersistentWindowBase(wxWindow
*win
)
35 : wxPersistentObject(win
)
40 wxWindowDestroyEventHandler(
41 wxPersistentWindowBase::HandleDestroy
),
47 virtual wxString
GetName() const
49 const wxString name
= GetWindow()->GetName();
50 wxASSERT_MSG( !name
.empty(), "persistent windows should be named!" );
56 wxWindow
*GetWindow() const { return static_cast<wxWindow
*>(GetObject()); }
59 void HandleDestroy(wxWindowDestroyEvent
& event
)
63 // only react to the destruction of this object itself, not of any of
65 if ( event
.GetEventObject() == GetObject() )
67 // this will delete this object itself
68 wxPersistenceManager::Get().SaveAndUnregister(GetWindow());
72 wxDECLARE_NO_COPY_CLASS(wxPersistentWindowBase
);
76 class wxPersistentWindow
: public wxPersistentWindowBase
81 wxPersistentWindow(WindowType
*win
)
82 : wxPersistentWindowBase(win
)
86 WindowType
*Get() const { return static_cast<WindowType
*>(GetWindow()); }
89 #endif // _WX_PERSIST_WINDOW_H_