]> git.saurik.com Git - wxWidgets.git/blob - include/wx/persist/splitter.h
Fix wxPropertyGrid::GetPropertyRect when the last item is collapsed.
[wxWidgets.git] / include / wx / persist / splitter.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/persist/splitter.h
3 // Purpose: Persistence support for wxSplitterWindow.
4 // Author: Vadim Zeitlin
5 // Created: 2011-08-31
6 // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #ifndef _WX_PERSIST_SPLITTER_H_
11 #define _WX_PERSIST_SPLITTER_H_
12
13 #include "wx/persist/window.h"
14
15 #include "wx/splitter.h"
16
17 // ----------------------------------------------------------------------------
18 // string constants used by wxPersistentSplitter
19 // ----------------------------------------------------------------------------
20
21 #define wxPERSIST_SPLITTER_KIND "Splitter"
22
23 // Special position value of -1 means the splitter is not split at all.
24 #define wxPERSIST_SPLITTER_POSITION "Position"
25
26 // ----------------------------------------------------------------------------
27 // wxPersistentSplitter: supports saving/restoring splitter position
28 // ----------------------------------------------------------------------------
29
30 class wxPersistentSplitter : public wxPersistentWindow<wxSplitterWindow>
31 {
32 public:
33 wxPersistentSplitter(wxSplitterWindow* splitter)
34 : wxPersistentWindow<wxSplitterWindow>(splitter)
35 {
36 }
37
38 virtual void Save() const
39 {
40 wxSplitterWindow* const splitter = Get();
41
42 int pos = splitter->IsSplit() ? splitter->GetSashPosition() : -1;
43 SaveValue(wxPERSIST_SPLITTER_POSITION, pos);
44 }
45
46 virtual bool Restore()
47 {
48 int pos;
49 if ( !RestoreValue(wxPERSIST_SPLITTER_POSITION, &pos) )
50 return false;
51
52 if ( pos == -1 )
53 Get()->Unsplit();
54 else
55 Get()->SetSashPosition(pos);
56
57 return true;
58 }
59
60 virtual wxString GetKind() const { return wxPERSIST_SPLITTER_KIND; }
61 };
62
63 inline wxPersistentObject *wxCreatePersistentObject(wxSplitterWindow* splitter)
64 {
65 return new wxPersistentSplitter(splitter);
66 }
67
68 #endif // _WX_PERSIST_SPLITTER_H_