]> git.saurik.com Git - wxWidgets.git/blame - src/msw/toplevel.cpp
removed obsolete file
[wxWidgets.git] / src / msw / toplevel.cpp
CommitLineData
82c9f85c
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: msw/toplevel.cpp
3// Purpose: implements wxTopLevelWindow for MSW
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 24.09.01
7// RCS-ID: $Id$
8// Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
9// License: wxWindows license
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20#ifdef __GNUG__
21 #pragma implementation "toplevel.h"
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
28 #pragma hdrstop
29#endif
30
31#ifndef WX_PRECOMP
3a922bb4
RL
32 #include "wx/app.h"
33 #include "wx/toplevel.h"
82c9f85c
VZ
34 #include "wx/string.h"
35 #include "wx/log.h"
36 #include "wx/intl.h"
37#endif //WX_PRECOMP
38
39#include "wx/msw/private.h"
40
41// ----------------------------------------------------------------------------
42// stubs for missing functions under MicroWindows
43// ----------------------------------------------------------------------------
44
45#ifdef __WXMICROWIN__
46
47static inline bool IsIconic(HWND WXUNUSED(hwnd)) { return FALSE; }
48static inline bool IsZoomed(HWND WXUNUSED(hwnd)) { return FALSE; }
49
50#endif // __WXMICROWIN__
51
52// ----------------------------------------------------------------------------
53// globals
54// ----------------------------------------------------------------------------
55
56// list of all frames and modeless dialogs
57wxWindowList wxModelessWindows;
58
59// ============================================================================
60// wxTopLevelWindowMSW implementation
61// ============================================================================
62
63// ----------------------------------------------------------------------------
64// wxTopLevelWindowMSW creation
65// ----------------------------------------------------------------------------
66
67void wxTopLevelWindowMSW::Init()
68{
69 m_iconized =
70 m_maximizeOnShow = FALSE;
71}
72
73bool wxTopLevelWindowMSW::Create(wxWindow *parent,
74 wxWindowID id,
75 const wxString& title,
76 const wxPoint& pos,
77 const wxSize& size,
78 long style,
79 const wxString& name)
80{
81 // init our fields
82 Init();
83
84 m_windowStyle = style;
85
86 SetName(name);
87
88 m_windowId = id == -1 ? NewControlId() : id;
89
90 wxTopLevelWindows.Append(this);
91
92 if ( parent )
93 parent->AddChild(this);
94
95 return TRUE;
96}
97
98wxTopLevelWindowMSW::~wxTopLevelWindowMSW()
99{
100 wxTopLevelWindows.DeleteObject(this);
101
102 if ( wxModelessWindows.Find(this) )
103 wxModelessWindows.DeleteObject(this);
104
105 // If this is the last top-level window, exit.
106 if ( wxTheApp && (wxTopLevelWindows.Number() == 0) )
107 {
108 wxTheApp->SetTopWindow(NULL);
109
110 if ( wxTheApp->GetExitOnFrameDelete() )
111 {
112 ::PostQuitMessage(0);
113 }
114 }
115}
116
117// ----------------------------------------------------------------------------
118// wxTopLevelWindowMSW geometry
119// ----------------------------------------------------------------------------
120
121void wxTopLevelWindowMSW::DoSetClientSize(int width, int height)
122{
123 HWND hWnd = GetHwnd();
124
125 RECT rectClient;
126 ::GetClientRect(hWnd, &rectClient);
127
128 RECT rectTotal;
129 ::GetWindowRect(hWnd, &rectTotal);
130
131 // Find the difference between the entire window (title bar and all)
132 // and the client area; add this to the new client size to move the
133 // window
134 width += rectTotal.right - rectTotal.left - rectClient.right;
135 height += rectTotal.bottom - rectTotal.top - rectClient.bottom;
136
137 // note that calling GetClientAreaOrigin() takes the toolbar into account
138 wxPoint pt = GetClientAreaOrigin();
139 width += pt.x;
140 height += pt.y;
141
142 if ( !::MoveWindow(hWnd, rectTotal.left, rectTotal.top,
143 width, height, TRUE /* redraw */) )
144 {
145 wxLogLastError(_T("MoveWindow"));
146 }
147
148 wxSizeEvent event(wxSize(width, height), m_windowId);
149 event.SetEventObject(this);
150 (void)GetEventHandler()->ProcessEvent(event);
151}
152
153// ----------------------------------------------------------------------------
154// wxTopLevelWindowMSW showing
155// ----------------------------------------------------------------------------
156
157void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd)
158{
159 ::ShowWindow(GetHwnd(), nShowCmd);
160
161 m_iconized = nShowCmd == SW_MINIMIZE;
162}
163
164bool wxTopLevelWindowMSW::Show(bool show)
165{
166 // don't use wxWindow version as we want to call DoShowWindow() ourselves
167 if ( !wxWindowBase::Show(show) )
168 return FALSE;
169
170 int nShowCmd;
171 if ( show )
172 {
173 if ( m_maximizeOnShow )
174 {
175 // show and maximize
176 nShowCmd = SW_MAXIMIZE;
177
178 m_maximizeOnShow = FALSE;
179 }
180 else // just show
181 {
182 nShowCmd = SW_SHOW;
183 }
184 }
185 else // hide
186 {
187 nShowCmd = SW_HIDE;
188 }
189
190 DoShowWindow(nShowCmd);
191
192 if ( show )
193 {
194 ::BringWindowToTop(GetHwnd());
195
196 wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_windowId);
197 event.SetEventObject( this );
198 GetEventHandler()->ProcessEvent(event);
199 }
200 else // hide
201 {
202 // Try to highlight the correct window (the parent)
203 if ( GetParent() )
204 {
205 HWND hWndParent = GetHwndOf(GetParent());
206 if (hWndParent)
207 ::BringWindowToTop(hWndParent);
208 }
209 }
210
211 return TRUE;
212}
213
214// ----------------------------------------------------------------------------
215// wxTopLevelWindowMSW maximize/minimize
216// ----------------------------------------------------------------------------
217
218void wxTopLevelWindowMSW::Maximize(bool maximize)
219{
220 if ( IsShown() )
221 {
222 // just maximize it directly
223 DoShowWindow(maximize ? SW_MAXIMIZE : SW_RESTORE);
224 }
225 else // hidden
226 {
227 // we can't maximize the hidden frame because it shows it as well, so
228 // just remember that we should do it later in this case
229 m_maximizeOnShow = TRUE;
230 }
231}
232
233bool wxTopLevelWindowMSW::IsMaximized() const
234{
235 return ::IsZoomed(GetHwnd()) != 0;
236}
237
238void wxTopLevelWindowMSW::Iconize(bool iconize)
239{
240 DoShowWindow(iconize ? SW_MINIMIZE : SW_RESTORE);
241}
242
243bool wxTopLevelWindowMSW::IsIconized() const
244{
245 // also update the current state
246 ((wxTopLevelWindowMSW *)this)->m_iconized = ::IsIconic(GetHwnd()) != 0;
247
248 return m_iconized;
249}
250
251void wxTopLevelWindowMSW::Restore()
252{
253 DoShowWindow(SW_RESTORE);
254}
255
256// ----------------------------------------------------------------------------
257// wxTopLevelWindowMSW misc
258// ----------------------------------------------------------------------------
259
260void wxTopLevelWindowMSW::SetIcon(const wxIcon& icon)
261{
262 // this sets m_icon
263 wxTopLevelWindowBase::SetIcon(icon);
264
265#if defined(__WIN95__) && !defined(__WXMICROWIN__)
266 if ( m_icon.Ok() )
267 {
268 ::SendMessage(GetHwnd(), WM_SETICON,
269 (WPARAM)TRUE, (LPARAM)GetHiconOf(m_icon));
270 }
271#endif // __WIN95__
272}