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