]> git.saurik.com Git - wxWidgets.git/blame - include/wx/persist/window.h
another wxUSE_DRAG_AND_DROP==0 compilation fix
[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
63 // this will delete this object itself
64 wxPersistenceManager::Get().SaveAndUnregister(GetWindow());
65 }
66
67 DECLARE_NO_COPY_CLASS(wxPersistentWindowBase)
68};
69
70template <class T>
71class wxPersistentWindow : public wxPersistentWindowBase
72{
73public:
74 typedef T WindowType;
75
76 wxPersistentWindow(WindowType *win)
77 : wxPersistentWindowBase(win)
78 {
79 }
80
81 WindowType *Get() const { return static_cast<WindowType *>(GetWindow()); }
82};
83
84#endif // _WX_PERSIST_WINDOW_H_
85