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