]> git.saurik.com Git - wxWidgets.git/blob - include/wx/persist/splitter.h
More s/loose/lose/ in wxEncodingConverter comments.
[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 // RCS-ID: $Id: wxhead.h,v 1.12 2010-04-22 12:44:51 zeitlin Exp $
7 // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_PERSIST_SPLITTER_H_
12 #define _WX_PERSIST_SPLITTER_H_
13
14 #include "wx/persist/window.h"
15
16 #include "wx/splitter.h"
17
18 // ----------------------------------------------------------------------------
19 // string constants used by wxPersistentSplitter
20 // ----------------------------------------------------------------------------
21
22 #define wxPERSIST_SPLITTER_KIND "Splitter"
23
24 // Special position value of -1 means the splitter is not split at all.
25 #define wxPERSIST_SPLITTER_POSITION "Position"
26
27 // ----------------------------------------------------------------------------
28 // wxPersistentSplitter: supports saving/restoring splitter position
29 // ----------------------------------------------------------------------------
30
31 class wxPersistentSplitter : public wxPersistentWindow<wxSplitterWindow>
32 {
33 public:
34 wxPersistentSplitter(wxSplitterWindow* splitter)
35 : wxPersistentWindow<wxSplitterWindow>(splitter)
36 {
37 }
38
39 virtual void Save() const
40 {
41 wxSplitterWindow* const splitter = Get();
42
43 int pos = splitter->IsSplit() ? splitter->GetSashPosition() : -1;
44 SaveValue(wxPERSIST_SPLITTER_POSITION, pos);
45 }
46
47 virtual bool Restore()
48 {
49 int pos;
50 if ( !RestoreValue(wxPERSIST_SPLITTER_POSITION, &pos) )
51 return false;
52
53 if ( pos == -1 )
54 Get()->Unsplit();
55 else
56 Get()->SetSashPosition(pos);
57
58 return true;
59 }
60
61 virtual wxString GetKind() const { return wxPERSIST_SPLITTER_KIND; }
62 };
63
64 inline wxPersistentObject *wxCreatePersistentObject(wxSplitterWindow* splitter)
65 {
66 return new wxPersistentSplitter(splitter);
67 }
68
69 #endif // _WX_PERSIST_SPLITTER_H_