]>
Commit | Line | Data |
---|---|---|
7d9f12f3 | 1 | ///////////////////////////////////////////////////////////////////////////// |
46ae103b | 2 | // Name: src/mgl/toplevel.cpp |
7d9f12f3 VS |
3 | // Purpose: |
4 | // Author: Vaclav Slavik | |
5 | // Id: $Id$ | |
c41c20a5 | 6 | // Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com) |
65571936 | 7 | // Licence: wxWindows licence |
7d9f12f3 VS |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
7520f3da WS |
10 | // For compilers that support precompilation, includes "wx.h". |
11 | #include "wx/wxprec.h" | |
12 | ||
13 | #ifdef __BORLANDC__ | |
14 | #pragma hdrstop | |
15 | #endif | |
16 | ||
7d9f12f3 VS |
17 | // ============================================================================ |
18 | // declarations | |
19 | // ============================================================================ | |
20 | ||
21 | // ---------------------------------------------------------------------------- | |
22 | // headers | |
23 | // ---------------------------------------------------------------------------- | |
24 | ||
1832043f WS |
25 | #include "wx/toplevel.h" |
26 | ||
78f93365 | 27 | #ifndef WX_PRECOMP |
78f93365 WS |
28 | #include "wx/app.h" |
29 | #endif // WX_PRECOMP | |
30 | ||
5465a788 | 31 | #include "wx/mgl/private.h" |
7d9f12f3 VS |
32 | |
33 | // ---------------------------------------------------------------------------- | |
34 | // idle system | |
35 | // ---------------------------------------------------------------------------- | |
36 | ||
7d9f12f3 VS |
37 | extern int g_openDialogs; |
38 | ||
39 | // ---------------------------------------------------------------------------- | |
40 | // event tables | |
41 | // ---------------------------------------------------------------------------- | |
42 | ||
43 | #ifndef __WXUNIVERSAL__ | |
44 | IMPLEMENT_DYNAMIC_CLASS(wxTopLevelWindow, wxWindow) | |
45 | #endif | |
46 | ||
7d9f12f3 VS |
47 | |
48 | // ============================================================================ | |
49 | // implementation | |
50 | // ============================================================================ | |
51 | ||
52 | void wxTopLevelWindowMGL::Init() | |
53 | { | |
46ae103b WS |
54 | m_isShown = false; |
55 | m_isIconized = false; | |
56 | m_isMaximized = false; | |
57 | m_fsIsShowing = false; | |
58 | m_sizeSet = false; | |
7d9f12f3 VS |
59 | } |
60 | ||
61 | bool wxTopLevelWindowMGL::Create(wxWindow *parent, | |
62 | wxWindowID id, | |
63 | const wxString& title, | |
6807396f | 64 | const wxPoint& posOrig, |
7d9f12f3 VS |
65 | const wxSize& sizeOrig, |
66 | long style, | |
67 | const wxString &name) | |
68 | { | |
69 | // always create a frame of some reasonable, even if arbitrary, size (at | |
70 | // least for MSW compatibility) | |
71 | wxSize size = sizeOrig; | |
46ae103b | 72 | if ( size.x == wxDefaultCoord || size.y == wxDefaultCoord ) |
7d9f12f3 | 73 | { |
6807396f | 74 | wxSize sizeDefault = GetDefaultSize(); |
46ae103b | 75 | if ( size.x == wxDefaultCoord ) |
6807396f | 76 | size.x = sizeDefault.x; |
46ae103b | 77 | if ( size.y == wxDefaultCoord ) |
6807396f | 78 | size.y = sizeDefault.y; |
7d9f12f3 | 79 | } |
46ae103b | 80 | |
6807396f MW |
81 | // for default positioning, centre the first top level window and |
82 | // cascade any addtional ones from there. | |
83 | wxPoint pos = posOrig; | |
46ae103b | 84 | if ( pos.x == wxDefaultCoord || pos.y == wxDefaultCoord ) |
6807396f MW |
85 | { |
86 | wxSize sizeDisplay = wxGetDisplaySize(); | |
87 | static wxPoint nextPos((sizeDisplay.x - size.x) / 2, | |
88 | (sizeDisplay.y - size.y) / 2); | |
89 | ||
46ae103b | 90 | if ( pos.x == wxDefaultCoord ) |
6807396f | 91 | pos.x = nextPos.x; |
46ae103b | 92 | if ( pos.y == wxDefaultCoord ) |
6807396f MW |
93 | pos.y = nextPos.y; |
94 | if ( pos.x + size.x > sizeDisplay.x || pos.y + size.y > sizeDisplay.y ) | |
95 | pos = wxPoint(); | |
96 | ||
97 | const wxSize cascadeOffset(16, 20); | |
98 | nextPos = pos + cascadeOffset; | |
99 | } | |
100 | ||
101 | wxWindow::Create(NULL, id, pos, size, style, name); | |
b8c0528d VS |
102 | SetParent(parent); |
103 | if ( parent ) | |
104 | parent->AddChild(this); | |
7d9f12f3 VS |
105 | |
106 | wxTopLevelWindows.Append(this); | |
7d9f12f3 | 107 | m_title = title; |
7d9f12f3 | 108 | |
46ae103b | 109 | return true; |
7d9f12f3 VS |
110 | } |
111 | ||
7d9f12f3 VS |
112 | bool wxTopLevelWindowMGL::ShowFullScreen(bool show, long style) |
113 | { | |
46ae103b | 114 | if (show == m_fsIsShowing) return false; // return what? |
7d9f12f3 VS |
115 | |
116 | m_fsIsShowing = show; | |
117 | ||
118 | if (show) | |
119 | { | |
120 | m_fsSaveStyle = m_windowStyle; | |
121 | m_fsSaveFlag = style; | |
122 | GetPosition(&m_fsSaveFrame.x, &m_fsSaveFrame.y); | |
123 | GetSize(&m_fsSaveFrame.width, &m_fsSaveFrame.height); | |
124 | ||
125 | if ( style & wxFULLSCREEN_NOCAPTION ) | |
038072e2 | 126 | m_windowStyle &= ~wxCAPTION; |
7d9f12f3 VS |
127 | if ( style & wxFULLSCREEN_NOBORDER ) |
128 | m_windowStyle = wxSIMPLE_BORDER; | |
129 | ||
130 | int x, y; | |
131 | wxDisplaySize(&x, &y); | |
132 | SetSize(0, 0, x, y); | |
133 | } | |
134 | else | |
135 | { | |
136 | m_windowStyle = m_fsSaveStyle; | |
46ae103b | 137 | SetSize(m_fsSaveFrame.x, m_fsSaveFrame.y, |
7d9f12f3 VS |
138 | m_fsSaveFrame.width, m_fsSaveFrame.height); |
139 | } | |
140 | ||
46ae103b | 141 | return true; |
7d9f12f3 VS |
142 | } |
143 | ||
917afc7b VS |
144 | bool wxTopLevelWindowMGL::Show(bool show) |
145 | { | |
146 | bool ret = wxTopLevelWindowBase::Show(show); | |
f41ed3c4 VS |
147 | |
148 | // If this is the first time Show was called, send size event, | |
149 | // so that the frame can adjust itself (think auto layout or single child) | |
150 | if ( !m_sizeSet ) | |
151 | { | |
46ae103b | 152 | m_sizeSet = true; |
f41ed3c4 VS |
153 | wxSizeEvent event(GetSize(), GetId()); |
154 | event.SetEventObject(this); | |
937013e0 | 155 | HandleWindowEvent(event); |
f41ed3c4 VS |
156 | } |
157 | ||
ad02525d | 158 | if ( ret && show && CanAcceptFocus() ) |
917afc7b | 159 | SetFocus(); |
61bd618f | 160 | // FIXME_MGL -- don't do this for popup windows? |
917afc7b VS |
161 | return ret; |
162 | } | |
163 | ||
7d9f12f3 VS |
164 | void wxTopLevelWindowMGL::Maximize(bool maximize) |
165 | { | |
5465a788 VS |
166 | int x, y, w, h; |
167 | wxClientDisplayRect(&x, &y, &w, &h); | |
168 | ||
169 | rect_t screenRect = MGL_defRect(x, y, w, h); | |
170 | MGL_wmInvalidateRect(g_winMng, &screenRect); | |
171 | ||
7d9f12f3 VS |
172 | if ( maximize && !m_isMaximized ) |
173 | { | |
46ae103b | 174 | m_isMaximized = true; |
15678bec | 175 | |
7d9f12f3 VS |
176 | GetPosition(&m_savedFrame.x, &m_savedFrame.y); |
177 | GetSize(&m_savedFrame.width, &m_savedFrame.height); | |
178 | ||
7d9f12f3 | 179 | SetSize(x, y, w, h); |
7d9f12f3 VS |
180 | } |
181 | else if ( !maximize && m_isMaximized ) | |
182 | { | |
46ae103b WS |
183 | m_isMaximized = false; |
184 | SetSize(m_savedFrame.x, m_savedFrame.y, | |
7d9f12f3 | 185 | m_savedFrame.width, m_savedFrame.height); |
7d9f12f3 VS |
186 | } |
187 | } | |
188 | ||
189 | bool wxTopLevelWindowMGL::IsMaximized() const | |
190 | { | |
191 | return m_isMaximized; | |
192 | } | |
193 | ||
194 | void wxTopLevelWindowMGL::Restore() | |
195 | { | |
7cdbf02c | 196 | if ( IsIconized() ) |
7d9f12f3 | 197 | { |
46ae103b | 198 | Iconize(false); |
7d9f12f3 | 199 | } |
7cdbf02c | 200 | if ( IsMaximized() ) |
7d9f12f3 | 201 | { |
46ae103b | 202 | Maximize(false); |
7d9f12f3 VS |
203 | } |
204 | } | |
205 | ||
58061670 | 206 | void wxTopLevelWindowMGL::Iconize(bool WXUNUSED(iconize)) |
7d9f12f3 | 207 | { |
58061670 VS |
208 | wxFAIL_MSG(wxT("Iconize not supported under wxMGL")); |
209 | // FIXME_MGL - Iconize is not supported in fullscreen mode. | |
210 | // It will be supported in windowed mode (if ever implemented in MGL...) | |
7d9f12f3 VS |
211 | } |
212 | ||
213 | bool wxTopLevelWindowMGL::IsIconized() const | |
214 | { | |
215 | return m_isIconized; | |
216 | } |