]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/persist/toplevel.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/persist/toplevel.h
3 // Purpose: persistence support for wxTLW
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_PERSIST_TOPLEVEL_H_
11 #define _WX_PERSIST_TOPLEVEL_H_
13 #include "wx/persist/window.h"
15 #include "wx/toplevel.h"
16 #include "wx/display.h"
18 // ----------------------------------------------------------------------------
19 // string constants used by wxPersistentTLW
20 // ----------------------------------------------------------------------------
22 // we use just "Window" to keep configuration files and such short, there
23 // should be no confusion with wxWindow itself as we don't have persistent
24 // windows, just persistent controls which have their own specific kind strings
25 #define wxPERSIST_TLW_KIND "Window"
27 // names for various persistent options
28 #define wxPERSIST_TLW_X "x"
29 #define wxPERSIST_TLW_Y "y"
30 #define wxPERSIST_TLW_W "w"
31 #define wxPERSIST_TLW_H "h"
33 #define wxPERSIST_TLW_MAXIMIZED "Maximized"
34 #define wxPERSIST_TLW_ICONIZED "Iconized"
36 // ----------------------------------------------------------------------------
37 // wxPersistentTLW: supports saving/restoring window position and size as well
38 // as maximized/iconized/restore state
39 // ----------------------------------------------------------------------------
41 class wxPersistentTLW
: public wxPersistentWindow
<wxTopLevelWindow
>
44 wxPersistentTLW(wxTopLevelWindow
*tlw
)
45 : wxPersistentWindow
<wxTopLevelWindow
>(tlw
)
49 virtual void Save() const
51 const wxTopLevelWindow
* const tlw
= Get();
53 const wxPoint pos
= tlw
->GetScreenPosition();
54 SaveValue(wxPERSIST_TLW_X
, pos
.x
);
55 SaveValue(wxPERSIST_TLW_Y
, pos
.y
);
57 // notice that we use GetSize() here and not GetClientSize() because
58 // the latter doesn't return correct results for the minimized windows
59 // (at least not under Windows)
61 // of course, it shouldn't matter anyhow usually, the client size
62 // should be preserved as well unless the size of the decorations
63 // changed between the runs
64 const wxSize size
= tlw
->GetSize();
65 SaveValue(wxPERSIST_TLW_W
, size
.x
);
66 SaveValue(wxPERSIST_TLW_H
, size
.y
);
68 SaveValue(wxPERSIST_TLW_MAXIMIZED
, tlw
->IsMaximized());
69 SaveValue(wxPERSIST_TLW_ICONIZED
, tlw
->IsIconized());
72 virtual bool Restore()
74 wxTopLevelWindow
* const tlw
= Get();
76 long x
wxDUMMY_INITIALIZE(-1),
77 y
wxDUMMY_INITIALIZE(-1),
78 w
wxDUMMY_INITIALIZE(-1),
79 h
wxDUMMY_INITIALIZE(-1);
80 const bool hasPos
= RestoreValue(wxPERSIST_TLW_X
, &x
) &&
81 RestoreValue(wxPERSIST_TLW_Y
, &y
);
82 const bool hasSize
= RestoreValue(wxPERSIST_TLW_W
, &w
) &&
83 RestoreValue(wxPERSIST_TLW_H
, &h
);
87 // to avoid making the window completely invisible if it had been
88 // shown on a monitor which was disconnected since the last run
89 // (this is pretty common for notebook with external displays)
91 // NB: we should allow window position to be (slightly) off screen,
92 // it's not uncommon to position the window so that its upper
93 // left corner has slightly negative coordinate
94 if ( wxDisplay::GetFromPoint(wxPoint(x
, y
)) != wxNOT_FOUND
||
95 (hasSize
&& wxDisplay::GetFromPoint(
96 wxPoint(x
+ w
, y
+ h
)) != wxNOT_FOUND
) )
98 tlw
->Move(x
, y
, wxSIZE_ALLOW_MINUS_ONE
);
100 //else: should we try to adjust position/size somehow?
106 // note that the window can be both maximized and iconized
108 if ( RestoreValue(wxPERSIST_TLW_MAXIMIZED
, &maximized
) && maximized
)
112 if ( RestoreValue(wxPERSIST_TLW_ICONIZED
, &iconized
) && iconized
)
115 // the most important property of the window that we restore is its
116 // size, so disregard the value of hasPos here
120 virtual wxString
GetKind() const { return wxPERSIST_TLW_KIND
; }
123 inline wxPersistentObject
*wxCreatePersistentObject(wxTopLevelWindow
*tlw
)
125 return new wxPersistentTLW(tlw
);
128 #endif // _WX_PERSIST_TOPLEVEL_H_