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