]>
Commit | Line | Data |
---|---|---|
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 | #ifdef __GNUG__ | |
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& pos, | |
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 sizeDpy = wxGetDisplaySize(); | |
76 | if ( size.x == -1 ) | |
77 | size.x = sizeDpy.x / 3; | |
78 | if ( size.y == -1 ) | |
79 | size.y = sizeDpy.y / 5; | |
80 | } | |
81 | ||
82 | wxWindow::Create(NULL, id, pos, sizeOrig, style, name); | |
83 | SetParent(parent); | |
84 | if ( parent ) | |
85 | parent->AddChild(this); | |
86 | ||
87 | wxTopLevelWindows.Append(this); | |
88 | m_title = title; | |
89 | ||
90 | return TRUE; | |
91 | } | |
92 | ||
93 | wxTopLevelWindowMGL::~wxTopLevelWindowMGL() | |
94 | { | |
95 | m_isBeingDeleted = TRUE; | |
96 | ||
97 | wxTopLevelWindows.DeleteObject(this); | |
98 | ||
99 | if (wxTheApp->GetTopWindow() == this) | |
100 | wxTheApp->SetTopWindow(NULL); | |
101 | ||
102 | if ((wxTopLevelWindows.Number() == 0) && | |
103 | (wxTheApp->GetExitOnFrameDelete())) | |
104 | { | |
105 | wxTheApp->ExitMainLoop(); | |
106 | } | |
107 | } | |
108 | ||
109 | bool wxTopLevelWindowMGL::ShowFullScreen(bool show, long style) | |
110 | { | |
111 | if (show == m_fsIsShowing) return FALSE; // return what? | |
112 | ||
113 | m_fsIsShowing = show; | |
114 | ||
115 | if (show) | |
116 | { | |
117 | m_fsSaveStyle = m_windowStyle; | |
118 | m_fsSaveFlag = style; | |
119 | GetPosition(&m_fsSaveFrame.x, &m_fsSaveFrame.y); | |
120 | GetSize(&m_fsSaveFrame.width, &m_fsSaveFrame.height); | |
121 | ||
122 | if ( style & wxFULLSCREEN_NOCAPTION ) | |
123 | m_windowStyle &= ~wxCAPTION; | |
124 | if ( style & wxFULLSCREEN_NOBORDER ) | |
125 | m_windowStyle = wxSIMPLE_BORDER; | |
126 | ||
127 | int x, y; | |
128 | wxDisplaySize(&x, &y); | |
129 | SetSize(0, 0, x, y); | |
130 | } | |
131 | else | |
132 | { | |
133 | m_windowStyle = m_fsSaveStyle; | |
134 | SetSize(m_fsSaveFrame.x, m_fsSaveFrame.y, | |
135 | m_fsSaveFrame.width, m_fsSaveFrame.height); | |
136 | } | |
137 | ||
138 | return TRUE; | |
139 | } | |
140 | ||
141 | bool wxTopLevelWindowMGL::Show(bool show) | |
142 | { | |
143 | bool ret = wxTopLevelWindowBase::Show(show); | |
144 | ||
145 | // If this is the first time Show was called, send size event, | |
146 | // so that the frame can adjust itself (think auto layout or single child) | |
147 | if ( !m_sizeSet ) | |
148 | { | |
149 | m_sizeSet = TRUE; | |
150 | wxSizeEvent event(GetSize(), GetId()); | |
151 | event.SetEventObject(this); | |
152 | GetEventHandler()->ProcessEvent(event); | |
153 | } | |
154 | ||
155 | if ( ret && show && AcceptsFocus() ) | |
156 | SetFocus(); | |
157 | // FIXME_MGL -- don't do this for popup windows? | |
158 | return ret; | |
159 | } | |
160 | ||
161 | void wxTopLevelWindowMGL::Maximize(bool maximize) | |
162 | { | |
163 | int x, y, w, h; | |
164 | wxClientDisplayRect(&x, &y, &w, &h); | |
165 | ||
166 | rect_t screenRect = MGL_defRect(x, y, w, h); | |
167 | MGL_wmInvalidateRect(g_winMng, &screenRect); | |
168 | ||
169 | if ( maximize && !m_isMaximized ) | |
170 | { | |
171 | m_isMaximized = TRUE; | |
172 | ||
173 | GetPosition(&m_savedFrame.x, &m_savedFrame.y); | |
174 | GetSize(&m_savedFrame.width, &m_savedFrame.height); | |
175 | ||
176 | SetSize(x, y, w, h); | |
177 | } | |
178 | else if ( !maximize && m_isMaximized ) | |
179 | { | |
180 | m_isMaximized = FALSE; | |
181 | SetSize(m_savedFrame.x, m_savedFrame.y, | |
182 | m_savedFrame.width, m_savedFrame.height); | |
183 | } | |
184 | } | |
185 | ||
186 | bool wxTopLevelWindowMGL::IsMaximized() const | |
187 | { | |
188 | return m_isMaximized; | |
189 | } | |
190 | ||
191 | void wxTopLevelWindowMGL::Restore() | |
192 | { | |
193 | if ( IsIconized() ) | |
194 | { | |
195 | Iconize(FALSE); | |
196 | } | |
197 | if ( IsMaximized() ) | |
198 | { | |
199 | Maximize(FALSE); | |
200 | } | |
201 | } | |
202 | ||
203 | void wxTopLevelWindowMGL::Iconize(bool WXUNUSED(iconize)) | |
204 | { | |
205 | wxFAIL_MSG(wxT("Iconize not supported under wxMGL")); | |
206 | // FIXME_MGL - Iconize is not supported in fullscreen mode. | |
207 | // It will be supported in windowed mode (if ever implemented in MGL...) | |
208 | } | |
209 | ||
210 | bool wxTopLevelWindowMGL::IsIconized() const | |
211 | { | |
212 | return m_isIconized; | |
213 | } |