]> git.saurik.com Git - wxWidgets.git/blame - include/wx/persist/window.h
Clarified wxPropertyGrid::HitTest() docs
[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 :
26#if wxEVENTS_COMPATIBILITY_2_8
27 // in compatibility mode we need to derive from wxEvtHandler to be able to
28 // handle events
29 public wxEvtHandler ,
30#endif
31 public wxPersistentObject
32{
33public:
34 wxPersistentWindowBase(wxWindow *win)
35 : wxPersistentObject(win)
36 {
37 win->Connect
38 (
39 wxEVT_DESTROY,
40 wxWindowDestroyEventHandler(
41 wxPersistentWindowBase::HandleDestroy),
42 NULL,
43 this
44 );
45 }
46
47 virtual wxString GetName() const
48 {
49 const wxString name = GetWindow()->GetName();
50 wxASSERT_MSG( !name.empty(), "persistent windows should be named!" );
51
52 return name;
53 }
54
55protected:
56 wxWindow *GetWindow() const { return static_cast<wxWindow *>(GetObject()); }
57
58private:
59 void HandleDestroy(wxWindowDestroyEvent& event)
60 {
61 event.Skip();
62
f61ea946
VZ
63 // only react to the destruction of this object itself, not of any of
64 // its children
65 if ( event.GetEventObject() == GetObject() )
66 {
67 // this will delete this object itself
68 wxPersistenceManager::Get().SaveAndUnregister(GetWindow());
69 }
0fa541e8
VZ
70 }
71
c0c133e1 72 wxDECLARE_NO_COPY_CLASS(wxPersistentWindowBase);
0fa541e8
VZ
73};
74
75template <class T>
76class wxPersistentWindow : public wxPersistentWindowBase
77{
78public:
79 typedef T WindowType;
80
81 wxPersistentWindow(WindowType *win)
82 : wxPersistentWindowBase(win)
83 {
84 }
85
86 WindowType *Get() const { return static_cast<WindowType *>(GetWindow()); }
87};
88
89#endif // _WX_PERSIST_WINDOW_H_
90