]> git.saurik.com Git - wxWidgets.git/blob - src/mgl/toplevel.cpp
Get/SetTitle only for wxTopLevelWindow (wxMGL part).
[wxWidgets.git] / src / mgl / toplevel.cpp
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 // ============================================================================
11 // declarations
12 // ============================================================================
13
14 // ----------------------------------------------------------------------------
15 // headers
16 // ----------------------------------------------------------------------------
17
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"
27 #include "wx/app.h"
28 #include "wx/mgl/private.h"
29
30 // ----------------------------------------------------------------------------
31 // idle system
32 // ----------------------------------------------------------------------------
33
34 extern int g_openDialogs;
35
36 // ----------------------------------------------------------------------------
37 // event tables
38 // ----------------------------------------------------------------------------
39
40 #ifndef __WXUNIVERSAL__
41 IMPLEMENT_DYNAMIC_CLASS(wxTopLevelWindow, wxWindow)
42 #endif
43
44
45 // ============================================================================
46 // implementation
47 // ============================================================================
48
49 void wxTopLevelWindowMGL::Init()
50 {
51 m_isShown = false;
52 m_isIconized = false;
53 m_isMaximized = false;
54 m_fsIsShowing = false;
55 m_sizeSet = false;
56 }
57
58 bool wxTopLevelWindowMGL::Create(wxWindow *parent,
59 wxWindowID id,
60 const wxString& title,
61 const wxPoint& posOrig,
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 == wxDefaultCoord || size.y == wxDefaultCoord )
70 {
71 wxSize sizeDefault = GetDefaultSize();
72 if ( size.x == wxDefaultCoord )
73 size.x = sizeDefault.x;
74 if ( size.y == wxDefaultCoord )
75 size.y = sizeDefault.y;
76 }
77
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 == wxDefaultCoord || pos.y == wxDefaultCoord )
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 == wxDefaultCoord )
88 pos.x = nextPos.x;
89 if ( pos.y == wxDefaultCoord )
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);
99 SetParent(parent);
100 if ( parent )
101 parent->AddChild(this);
102
103 wxTopLevelWindows.Append(this);
104 m_title = title;
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 )
139 m_windowStyle &= ~wxCAPTION;
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
157 bool wxTopLevelWindowMGL::Show(bool show)
158 {
159 bool ret = wxTopLevelWindowBase::Show(show);
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
171 if ( ret && show && AcceptsFocus() )
172 SetFocus();
173 // FIXME_MGL -- don't do this for popup windows?
174 return ret;
175 }
176
177 void wxTopLevelWindowMGL::Maximize(bool maximize)
178 {
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
185 if ( maximize && !m_isMaximized )
186 {
187 m_isMaximized = true;
188
189 GetPosition(&m_savedFrame.x, &m_savedFrame.y);
190 GetSize(&m_savedFrame.width, &m_savedFrame.height);
191
192 SetSize(x, y, w, h);
193 }
194 else if ( !maximize && m_isMaximized )
195 {
196 m_isMaximized = false;
197 SetSize(m_savedFrame.x, m_savedFrame.y,
198 m_savedFrame.width, m_savedFrame.height);
199 }
200 }
201
202 bool wxTopLevelWindowMGL::IsMaximized() const
203 {
204 return m_isMaximized;
205 }
206
207 void wxTopLevelWindowMGL::Restore()
208 {
209 if ( IsIconized() )
210 {
211 Iconize(false);
212 }
213 if ( IsMaximized() )
214 {
215 Maximize(false);
216 }
217 }
218
219 void wxTopLevelWindowMGL::Iconize(bool WXUNUSED(iconize))
220 {
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...)
224 }
225
226 bool wxTopLevelWindowMGL::IsIconized() const
227 {
228 return m_isIconized;
229 }