]> git.saurik.com Git - wxWidgets.git/blame - include/wx/persist/window.h
Somehow, setting a tint color makes gauge work :/.
[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
0fa541e8
VZ
6// Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
7// Licence: wxWindows licence
8///////////////////////////////////////////////////////////////////////////////
9
10#ifndef _WX_PERSIST_WINDOW_H_
11#define _WX_PERSIST_WINDOW_H_
12
13#include "wx/persist.h"
14
15#include "wx/window.h"
16
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// ----------------------------------------------------------------------------
22
23// type-independent part of wxPersistentWindow
24class wxPersistentWindowBase :
23172836 25 wxBIND_OR_CONNECT_HACK_BASE_CLASS
0fa541e8
VZ
26 public wxPersistentObject
27{
28public:
29 wxPersistentWindowBase(wxWindow *win)
30 : wxPersistentObject(win)
31 {
23172836
VZ
32 wxBIND_OR_CONNECT_HACK(win, wxEVT_DESTROY, wxWindowDestroyEventHandler,
33 wxPersistentWindowBase::HandleDestroy, this);
0fa541e8
VZ
34 }
35
36 virtual wxString GetName() const
37 {
38 const wxString name = GetWindow()->GetName();
39 wxASSERT_MSG( !name.empty(), "persistent windows should be named!" );
40
41 return name;
42 }
43
44protected:
45 wxWindow *GetWindow() const { return static_cast<wxWindow *>(GetObject()); }
46
47private:
48 void HandleDestroy(wxWindowDestroyEvent& event)
49 {
50 event.Skip();
51
f61ea946
VZ
52 // only react to the destruction of this object itself, not of any of
53 // its children
54 if ( event.GetEventObject() == GetObject() )
55 {
56 // this will delete this object itself
57 wxPersistenceManager::Get().SaveAndUnregister(GetWindow());
58 }
0fa541e8
VZ
59 }
60
c0c133e1 61 wxDECLARE_NO_COPY_CLASS(wxPersistentWindowBase);
0fa541e8
VZ
62};
63
64template <class T>
65class wxPersistentWindow : public wxPersistentWindowBase
66{
67public:
68 typedef T WindowType;
69
70 wxPersistentWindow(WindowType *win)
71 : wxPersistentWindowBase(win)
72 {
73 }
74
75 WindowType *Get() const { return static_cast<WindowType *>(GetWindow()); }
76};
77
78#endif // _WX_PERSIST_WINDOW_H_
79