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 wxBIND_OR_CONNECT_HACK_BASE_CLASS
27 public wxPersistentObject
30 wxPersistentWindowBase(wxWindow
*win
)
31 : wxPersistentObject(win
)
33 wxBIND_OR_CONNECT_HACK(win
, wxEVT_DESTROY
, wxWindowDestroyEventHandler
,
34 wxPersistentWindowBase::HandleDestroy
, this);
37 virtual wxString
GetName() const
39 const wxString name
= GetWindow()->GetName();
40 wxASSERT_MSG( !name
.empty(), "persistent windows should be named!" );
46 wxWindow
*GetWindow() const { return static_cast<wxWindow
*>(GetObject()); }
49 void HandleDestroy(wxWindowDestroyEvent
& event
)
53 // only react to the destruction of this object itself, not of any of
55 if ( event
.GetEventObject() == GetObject() )
57 // this will delete this object itself
58 wxPersistenceManager::Get().SaveAndUnregister(GetWindow());
62 wxDECLARE_NO_COPY_CLASS(wxPersistentWindowBase
);
66 class wxPersistentWindow
: public wxPersistentWindowBase
71 wxPersistentWindow(WindowType
*win
)
72 : wxPersistentWindowBase(win
)
76 WindowType
*Get() const { return static_cast<WindowType
*>(GetWindow()); }
79 #endif // _WX_PERSIST_WINDOW_H_