1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/persist/window.h
3 // Purpose: wxPersistentWindow declaration
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_PERSIST_WINDOW_H_
11 #define _WX_PERSIST_WINDOW_H_
13 #include "wx/persist.h"
15 #include "wx/window.h"
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 // ----------------------------------------------------------------------------
23 // type-independent part of wxPersistentWindow
24 class wxPersistentWindowBase
:
25 wxBIND_OR_CONNECT_HACK_BASE_CLASS
26 public wxPersistentObject
29 wxPersistentWindowBase(wxWindow
*win
)
30 : wxPersistentObject(win
)
32 wxBIND_OR_CONNECT_HACK(win
, wxEVT_DESTROY
, wxWindowDestroyEventHandler
,
33 wxPersistentWindowBase::HandleDestroy
, this);
36 virtual wxString
GetName() const
38 const wxString name
= GetWindow()->GetName();
39 wxASSERT_MSG( !name
.empty(), "persistent windows should be named!" );
45 wxWindow
*GetWindow() const { return static_cast<wxWindow
*>(GetObject()); }
48 void HandleDestroy(wxWindowDestroyEvent
& event
)
52 // only react to the destruction of this object itself, not of any of
54 if ( event
.GetEventObject() == GetObject() )
56 // this will delete this object itself
57 wxPersistenceManager::Get().SaveAndUnregister(GetWindow());
61 wxDECLARE_NO_COPY_CLASS(wxPersistentWindowBase
);
65 class wxPersistentWindow
: public wxPersistentWindowBase
70 wxPersistentWindow(WindowType
*win
)
71 : wxPersistentWindowBase(win
)
75 WindowType
*Get() const { return static_cast<WindowType
*>(GetWindow()); }
78 #endif // _WX_PERSIST_WINDOW_H_