]> git.saurik.com Git - wxWidgets.git/blame - include/wx/persist/window.h
Extract conversion from wx to GtkMessageType in a separate file.
[wxWidgets.git] / include / wx / persist / window.h
CommitLineData
0fa541e8
VZ
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
25class wxPersistentWindowBase :
23172836 26 wxBIND_OR_CONNECT_HACK_BASE_CLASS
0fa541e8
VZ
27 public wxPersistentObject
28{
29public:
30 wxPersistentWindowBase(wxWindow *win)
31 : wxPersistentObject(win)
32 {
23172836
VZ
33 wxBIND_OR_CONNECT_HACK(win, wxEVT_DESTROY, wxWindowDestroyEventHandler,
34 wxPersistentWindowBase::HandleDestroy, this);
0fa541e8
VZ
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
45protected:
46 wxWindow *GetWindow() const { return static_cast<wxWindow *>(GetObject()); }
47
48private:
49 void HandleDestroy(wxWindowDestroyEvent& event)
50 {
51 event.Skip();
52
f61ea946
VZ
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 }
0fa541e8
VZ
60 }
61
c0c133e1 62 wxDECLARE_NO_COPY_CLASS(wxPersistentWindowBase);
0fa541e8
VZ
63};
64
65template <class T>
66class wxPersistentWindow : public wxPersistentWindowBase
67{
68public:
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