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