]>
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
)
37 #if wxEVENTS_COMPATIBILITY_2_8
41 wxWindowDestroyEventHandler(
42 wxPersistentWindowBase::HandleDestroy
),
46 #else // !wxEVENTS_COMPATIBILITY_2_8
47 win
->Bind(wxEVT_DESTROY
, &wxPersistentWindowBase::HandleDestroy
, this);
48 #endif // wxEVENTS_COMPATIBILITY_2_8/!wxEVENTS_COMPATIBILITY_2_8
51 virtual wxString
GetName() const
53 const wxString name
= GetWindow()->GetName();
54 wxASSERT_MSG( !name
.empty(), "persistent windows should be named!" );
60 wxWindow
*GetWindow() const { return static_cast<wxWindow
*>(GetObject()); }
63 void HandleDestroy(wxWindowDestroyEvent
& event
)
67 // only react to the destruction of this object itself, not of any of
69 if ( event
.GetEventObject() == GetObject() )
71 // this will delete this object itself
72 wxPersistenceManager::Get().SaveAndUnregister(GetWindow());
76 wxDECLARE_NO_COPY_CLASS(wxPersistentWindowBase
);
80 class wxPersistentWindow
: public wxPersistentWindowBase
85 wxPersistentWindow(WindowType
*win
)
86 : wxPersistentWindowBase(win
)
90 WindowType
*Get() const { return static_cast<WindowType
*>(GetWindow()); }
93 #endif // _WX_PERSIST_WINDOW_H_