]>
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 | ||
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 | { | |
46ae103b WS |
51 | m_isShown = false; |
52 | m_isIconized = false; | |
53 | m_isMaximized = false; | |
54 | m_fsIsShowing = false; | |
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; | |
46ae103b | 69 | if ( size.x == wxDefaultCoord || size.y == wxDefaultCoord ) |
7d9f12f3 | 70 | { |
6807396f | 71 | wxSize sizeDefault = GetDefaultSize(); |
46ae103b | 72 | if ( size.x == wxDefaultCoord ) |
6807396f | 73 | size.x = sizeDefault.x; |
46ae103b | 74 | if ( size.y == wxDefaultCoord ) |
6807396f | 75 | size.y = sizeDefault.y; |
7d9f12f3 | 76 | } |
46ae103b | 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; | |
46ae103b | 81 | if ( pos.x == wxDefaultCoord || pos.y == wxDefaultCoord ) |
6807396f MW |
82 | { |
83 | wxSize sizeDisplay = wxGetDisplaySize(); | |
84 | static wxPoint nextPos((sizeDisplay.x - size.x) / 2, | |
85 | (sizeDisplay.y - size.y) / 2); | |
86 | ||
46ae103b | 87 | if ( pos.x == wxDefaultCoord ) |
6807396f | 88 | pos.x = nextPos.x; |
46ae103b | 89 | if ( pos.y == wxDefaultCoord ) |
6807396f MW |
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 | 105 | |
46ae103b | 106 | return true; |
7d9f12f3 VS |
107 | } |
108 | ||
109 | wxTopLevelWindowMGL::~wxTopLevelWindowMGL() | |
110 | { | |
46ae103b | 111 | m_isBeingDeleted = true; |
7d9f12f3 VS |
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 | { | |
46ae103b | 127 | if (show == m_fsIsShowing) return false; // return what? |
7d9f12f3 VS |
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; | |
46ae103b | 150 | SetSize(m_fsSaveFrame.x, m_fsSaveFrame.y, |
7d9f12f3 VS |
151 | m_fsSaveFrame.width, m_fsSaveFrame.height); |
152 | } | |
153 | ||
46ae103b | 154 | return true; |
7d9f12f3 VS |
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 | { | |
46ae103b | 165 | m_sizeSet = true; |
f41ed3c4 VS |
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 | { | |
46ae103b | 187 | m_isMaximized = true; |
15678bec | 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 | { | |
46ae103b WS |
196 | m_isMaximized = false; |
197 | SetSize(m_savedFrame.x, m_savedFrame.y, | |
7d9f12f3 | 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 | 210 | { |
46ae103b | 211 | Iconize(false); |
7d9f12f3 | 212 | } |
7cdbf02c | 213 | if ( IsMaximized() ) |
7d9f12f3 | 214 | { |
46ae103b | 215 | Maximize(false); |
7d9f12f3 VS |
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 | } |