]> git.saurik.com Git - wxWidgets.git/blame - src/mgl/toplevel.cpp
initialize send_event field of GdkEventExpose we generate (bug 1245864) (Robert,...
[wxWidgets.git] / src / mgl / toplevel.cpp
CommitLineData
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
14f355c2 18#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
7d9f12f3
VS
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"
2343d81b 31#include "wx/app.h"
5465a788 32#include "wx/mgl/private.h"
7d9f12f3
VS
33
34// ----------------------------------------------------------------------------
35// idle system
36// ----------------------------------------------------------------------------
37
7d9f12f3
VS
38extern int g_openDialogs;
39
40// ----------------------------------------------------------------------------
41// event tables
42// ----------------------------------------------------------------------------
43
44#ifndef __WXUNIVERSAL__
45 IMPLEMENT_DYNAMIC_CLASS(wxTopLevelWindow, wxWindow)
46#endif
47
7d9f12f3
VS
48
49// ============================================================================
50// implementation
51// ============================================================================
52
53void wxTopLevelWindowMGL::Init()
54{
2343d81b 55 m_isShown = FALSE;
7d9f12f3
VS
56 m_isIconized = FALSE;
57 m_isMaximized = FALSE;
58 m_fsIsShowing = FALSE;
f41ed3c4 59 m_sizeSet = FALSE;
7d9f12f3
VS
60}
61
62bool wxTopLevelWindowMGL::Create(wxWindow *parent,
63 wxWindowID id,
64 const wxString& title,
6807396f 65 const wxPoint& posOrig,
7d9f12f3
VS
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 {
6807396f 75 wxSize sizeDefault = GetDefaultSize();
7d9f12f3 76 if ( size.x == -1 )
6807396f 77 size.x = sizeDefault.x;
7d9f12f3 78 if ( size.y == -1 )
6807396f 79 size.y = sizeDefault.y;
7d9f12f3 80 }
2343d81b 81
6807396f
MW
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);
b8c0528d
VS
103 SetParent(parent);
104 if ( parent )
105 parent->AddChild(this);
7d9f12f3
VS
106
107 wxTopLevelWindows.Append(this);
7d9f12f3 108 m_title = title;
7d9f12f3
VS
109
110 return TRUE;
111}
112
113wxTopLevelWindowMGL::~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
129bool 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 )
038072e2 143 m_windowStyle &= ~wxCAPTION;
7d9f12f3
VS
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
917afc7b
VS
161bool wxTopLevelWindowMGL::Show(bool show)
162{
163 bool ret = wxTopLevelWindowBase::Show(show);
f41ed3c4
VS
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
61bd618f 175 if ( ret && show && AcceptsFocus() )
917afc7b 176 SetFocus();
61bd618f 177 // FIXME_MGL -- don't do this for popup windows?
917afc7b
VS
178 return ret;
179}
180
7d9f12f3
VS
181void wxTopLevelWindowMGL::Maximize(bool maximize)
182{
5465a788
VS
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
7d9f12f3
VS
189 if ( maximize && !m_isMaximized )
190 {
15678bec
VS
191 m_isMaximized = TRUE;
192
7d9f12f3
VS
193 GetPosition(&m_savedFrame.x, &m_savedFrame.y);
194 GetSize(&m_savedFrame.width, &m_savedFrame.height);
195
7d9f12f3 196 SetSize(x, y, w, h);
7d9f12f3
VS
197 }
198 else if ( !maximize && m_isMaximized )
199 {
15678bec 200 m_isMaximized = FALSE;
7d9f12f3
VS
201 SetSize(m_savedFrame.x, m_savedFrame.y,
202 m_savedFrame.width, m_savedFrame.height);
7d9f12f3
VS
203 }
204}
205
206bool wxTopLevelWindowMGL::IsMaximized() const
207{
208 return m_isMaximized;
209}
210
211void wxTopLevelWindowMGL::Restore()
212{
7cdbf02c 213 if ( IsIconized() )
7d9f12f3
VS
214 {
215 Iconize(FALSE);
216 }
7cdbf02c 217 if ( IsMaximized() )
7d9f12f3
VS
218 {
219 Maximize(FALSE);
220 }
221}
222
58061670 223void wxTopLevelWindowMGL::Iconize(bool WXUNUSED(iconize))
7d9f12f3 224{
58061670
VS
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...)
7d9f12f3
VS
228}
229
230bool wxTopLevelWindowMGL::IsIconized() const
231{
232 return m_isIconized;
233}