]>
Commit | Line | Data |
---|---|---|
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" | |
14dd645e | 37 | #include "wx/frame.h" |
82c9f85c VZ |
38 | #endif //WX_PRECOMP |
39 | ||
40 | #include "wx/msw/private.h" | |
41 | ||
e121a72a MB |
42 | #ifndef ICON_BIG |
43 | #define ICON_BIG 1 | |
44 | #endif | |
45 | ||
46 | #ifndef ICON_SMALL | |
47 | #define ICON_SMALL 0 | |
48 | #endif | |
49 | ||
82c9f85c VZ |
50 | // ---------------------------------------------------------------------------- |
51 | // stubs for missing functions under MicroWindows | |
52 | // ---------------------------------------------------------------------------- | |
53 | ||
54 | #ifdef __WXMICROWIN__ | |
55 | ||
c67d6888 | 56 | // static inline bool IsIconic(HWND WXUNUSED(hwnd)) { return FALSE; } |
82c9f85c VZ |
57 | static inline bool IsZoomed(HWND WXUNUSED(hwnd)) { return FALSE; } |
58 | ||
59 | #endif // __WXMICROWIN__ | |
60 | ||
61 | // ---------------------------------------------------------------------------- | |
62 | // globals | |
63 | // ---------------------------------------------------------------------------- | |
64 | ||
65 | // list of all frames and modeless dialogs | |
66 | wxWindowList wxModelessWindows; | |
67 | ||
b225f659 VZ |
68 | // the name of the default wxWindows class |
69 | extern const wxChar *wxCanvasClassName; | |
70 | ||
82c9f85c VZ |
71 | // ============================================================================ |
72 | // wxTopLevelWindowMSW implementation | |
73 | // ============================================================================ | |
74 | ||
b225f659 VZ |
75 | // Dialog window proc |
76 | LONG APIENTRY _EXPORT | |
77 | wxDlgProc(HWND WXUNUSED(hWnd), UINT message, WPARAM WXUNUSED(wParam), LPARAM WXUNUSED(lParam)) | |
78 | { | |
79 | if ( message == WM_INITDIALOG ) | |
80 | { | |
81 | // for this message, returning TRUE tells system to set focus to the | |
82 | // first control in the dialog box | |
83 | return TRUE; | |
84 | } | |
85 | else | |
86 | { | |
87 | // for all the other ones, FALSE means that we didn't process the | |
88 | // message | |
89 | return FALSE; | |
90 | } | |
91 | } | |
92 | ||
82c9f85c VZ |
93 | // ---------------------------------------------------------------------------- |
94 | // wxTopLevelWindowMSW creation | |
95 | // ---------------------------------------------------------------------------- | |
96 | ||
97 | void wxTopLevelWindowMSW::Init() | |
98 | { | |
99 | m_iconized = | |
100 | m_maximizeOnShow = FALSE; | |
b225f659 VZ |
101 | |
102 | // unlike (almost?) all other windows, frames are created hidden | |
103 | m_isShown = FALSE; | |
c641b1d2 VS |
104 | |
105 | // Data to save/restore when calling ShowFullScreen | |
106 | m_fsStyle = 0; | |
107 | m_fsOldWindowStyle = 0; | |
108 | m_fsIsMaximized = FALSE; | |
109 | m_fsIsShowing = FALSE; | |
b225f659 VZ |
110 | } |
111 | ||
b2d5a7ee | 112 | WXDWORD wxTopLevelWindowMSW::MSWGetStyle(long style, WXDWORD *exflags) const |
b225f659 | 113 | { |
b2d5a7ee VZ |
114 | // let the base class deal with the common styles but fix the ones which |
115 | // don't make sense for us (we also deal with the borders ourselves) | |
116 | WXDWORD msflags = wxWindow::MSWGetStyle | |
117 | ( | |
118 | (style & ~wxBORDER_MASK) | wxBORDER_NONE, exflags | |
119 | ) & ~WS_CHILD; | |
b225f659 VZ |
120 | |
121 | // first select the kind of window being created | |
dfb06c62 VZ |
122 | // |
123 | // note that if we don't set WS_POPUP, Windows assumes WS_OVERLAPPED and | |
124 | // creates a window with both caption and border, hence we also test it | |
125 | // below in some other cases | |
0e082993 | 126 | if ( style & wxFRAME_TOOL_WINDOW ) |
b2d5a7ee | 127 | msflags |= WS_POPUP; |
b225f659 | 128 | else |
b2d5a7ee | 129 | msflags |= WS_OVERLAPPED; |
0e082993 VZ |
130 | |
131 | // border and caption styles | |
132 | if ( style & wxRESIZE_BORDER ) | |
133 | msflags |= WS_THICKFRAME; | |
134 | else if ( !(style & wxBORDER_NONE) ) | |
135 | msflags |= WS_BORDER; | |
dfb06c62 VZ |
136 | else |
137 | msflags |= WS_POPUP; | |
0e082993 VZ |
138 | |
139 | if ( style & wxCAPTION ) | |
140 | msflags |= WS_CAPTION; | |
dfb06c62 | 141 | else |
b225f659 | 142 | msflags |= WS_POPUP; |
b225f659 VZ |
143 | |
144 | // next translate the individual flags | |
145 | if ( style & wxMINIMIZE_BOX ) | |
146 | msflags |= WS_MINIMIZEBOX; | |
147 | if ( style & wxMAXIMIZE_BOX ) | |
148 | msflags |= WS_MAXIMIZEBOX; | |
b225f659 VZ |
149 | if ( style & wxSYSTEM_MENU ) |
150 | msflags |= WS_SYSMENU; | |
151 | if ( style & wxMINIMIZE ) | |
152 | msflags |= WS_MINIMIZE; | |
153 | if ( style & wxMAXIMIZE ) | |
154 | msflags |= WS_MAXIMIZE; | |
0e082993 | 155 | |
b225f659 VZ |
156 | // Keep this here because it saves recoding this function in wxTinyFrame |
157 | #if wxUSE_ITSY_BITSY && !defined(__WIN32__) | |
158 | if ( style & wxTINY_CAPTION_VERT ) | |
159 | msflags |= IBS_VERTCAPTION; | |
160 | if ( style & wxTINY_CAPTION_HORIZ ) | |
161 | msflags |= IBS_HORZCAPTION; | |
162 | #else | |
163 | if ( style & (wxTINY_CAPTION_VERT | wxTINY_CAPTION_HORIZ) ) | |
164 | msflags |= WS_CAPTION; | |
165 | #endif | |
166 | ||
167 | if ( exflags ) | |
168 | { | |
b225f659 | 169 | #if !defined(__WIN16__) && !defined(__SC__) |
35bf863b VZ |
170 | if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) ) |
171 | { | |
172 | // make all frames appear in the win9x shell taskbar unless | |
173 | // wxFRAME_TOOL_WINDOW or wxFRAME_NO_TASKBAR is given - without | |
174 | // giving them WS_EX_APPWINDOW style, the child (i.e. owned) frames | |
175 | // wouldn't appear in it | |
176 | if ( (style & wxFRAME_TOOL_WINDOW) || (style & wxFRAME_NO_TASKBAR) ) | |
177 | *exflags |= WS_EX_TOOLWINDOW; | |
178 | else if ( !(style & wxFRAME_NO_TASKBAR) ) | |
179 | *exflags |= WS_EX_APPWINDOW; | |
180 | } | |
181 | #endif // !Win16 | |
b225f659 VZ |
182 | |
183 | if ( style & wxSTAY_ON_TOP ) | |
184 | *exflags |= WS_EX_TOPMOST; | |
185 | ||
186 | #ifdef __WIN32__ | |
b2d5a7ee | 187 | if ( GetExtraStyle() & wxFRAME_EX_CONTEXTHELP ) |
68d02db3 | 188 | *exflags |= WS_EX_CONTEXTHELP; |
b225f659 VZ |
189 | #endif // __WIN32__ |
190 | } | |
191 | ||
192 | return msflags; | |
193 | } | |
194 | ||
6e8515a3 | 195 | bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate, |
b225f659 VZ |
196 | const wxString& title, |
197 | const wxPoint& pos, | |
198 | const wxSize& size) | |
199 | { | |
200 | #ifdef __WXMICROWIN__ | |
201 | // no dialogs support under MicroWin yet | |
202 | return CreateFrame(title, pos, size); | |
203 | #else // !__WXMICROWIN__ | |
204 | wxWindow *parent = GetParent(); | |
205 | ||
206 | // for the dialogs without wxDIALOG_NO_PARENT style, use the top level | |
207 | // app window as parent - this avoids creating modal dialogs without | |
208 | // parent | |
209 | if ( !parent && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT) ) | |
210 | { | |
211 | parent = wxTheApp->GetTopWindow(); | |
e058b98d | 212 | |
39cc7a0b | 213 | if ( parent ) |
e058b98d | 214 | { |
39cc7a0b VZ |
215 | // don't use transient windows as parents, this is dangerous as it |
216 | // can lead to a crash if the parent is destroyed before the child | |
217 | // | |
218 | // also don't use the window which is currently hidden as then the | |
219 | // dialog would be hidden as well | |
220 | if ( (parent->GetExtraStyle() & wxWS_EX_TRANSIENT) || | |
221 | !parent->IsShown() ) | |
222 | { | |
223 | parent = NULL; | |
224 | } | |
e058b98d | 225 | } |
b225f659 VZ |
226 | } |
227 | ||
434005ca VZ |
228 | m_hWnd = (WXHWND)::CreateDialogIndirect |
229 | ( | |
230 | wxGetInstance(), | |
231 | (DLGTEMPLATE*)dlgTemplate, | |
232 | parent ? GetHwndOf(parent) : NULL, | |
233 | (DLGPROC)wxDlgProc | |
234 | ); | |
b225f659 VZ |
235 | |
236 | if ( !m_hWnd ) | |
237 | { | |
6e8515a3 | 238 | wxFAIL_MSG(_("Failed to create dialog. Incorrect DLGTEMPLATE?")); |
b225f659 | 239 | |
6e8515a3 | 240 | wxLogSysError(_("Can't create dialog using memory template")); |
b225f659 VZ |
241 | |
242 | return FALSE; | |
243 | } | |
244 | ||
b2d5a7ee | 245 | WXDWORD exflags; |
b225f659 VZ |
246 | (void)MSWGetCreateWindowFlags(&exflags); |
247 | ||
248 | if ( exflags ) | |
249 | { | |
250 | ::SetWindowLong(GetHwnd(), GWL_EXSTYLE, exflags); | |
251 | ::SetWindowPos(GetHwnd(), NULL, 0, 0, 0, 0, | |
252 | SWP_NOSIZE | | |
253 | SWP_NOMOVE | | |
254 | SWP_NOZORDER | | |
255 | SWP_NOACTIVATE); | |
256 | } | |
257 | ||
258 | #if defined(__WIN95__) | |
259 | // For some reason, the system menu is activated when we use the | |
260 | // WS_EX_CONTEXTHELP style, so let's set a reasonable icon | |
261 | if ( exflags & WS_EX_CONTEXTHELP ) | |
262 | { | |
263 | wxFrame *winTop = wxDynamicCast(wxTheApp->GetTopWindow(), wxFrame); | |
264 | if ( winTop ) | |
265 | { | |
266 | wxIcon icon = winTop->GetIcon(); | |
267 | if ( icon.Ok() ) | |
268 | { | |
269 | ::SendMessage(GetHwnd(), WM_SETICON, | |
270 | (WPARAM)TRUE, | |
271 | (LPARAM)GetHiconOf(icon)); | |
272 | } | |
273 | } | |
274 | } | |
275 | #endif // __WIN95__ | |
276 | ||
277 | // move the dialog to its initial position without forcing repainting | |
278 | int x, y, w, h; | |
4c53c743 | 279 | if ( !MSWGetCreateWindowCoords(pos, size, x, y, w, h) ) |
b225f659 | 280 | { |
4c53c743 VZ |
281 | x = |
282 | w = (int)CW_USEDEFAULT; | |
283 | } | |
f04a0744 | 284 | |
4c53c743 VZ |
285 | // we can't use CW_USEDEFAULT here as we're not calling CreateWindow() |
286 | // and passing CW_USEDEFAULT to MoveWindow() results in resizing the | |
287 | // window to (0, 0) size which breaks quite a lot of things, e.g. the | |
288 | // sizer calculation in wxSizer::Fit() | |
289 | if ( w == (int)CW_USEDEFAULT ) | |
290 | { | |
291 | // the exact number doesn't matter, the dialog will be resized | |
292 | // again soon anyhow but it should be big enough to allow | |
293 | // calculation relying on "totalSize - clientSize > 0" work, i.e. | |
294 | // at least greater than the title bar height | |
295 | w = | |
296 | h = 100; | |
297 | } | |
f0adbe0f | 298 | |
4c53c743 VZ |
299 | if ( x == (int)CW_USEDEFAULT ) |
300 | { | |
301 | // centre it on the screen - what else can we do? | |
302 | wxSize sizeDpy = wxGetDisplaySize(); | |
303 | ||
304 | x = (sizeDpy.x - w) / 2; | |
305 | y = (sizeDpy.y - h) / 2; | |
306 | } | |
307 | ||
308 | if ( !::MoveWindow(GetHwnd(), x, y, w, h, FALSE) ) | |
309 | { | |
310 | wxLogLastError(wxT("MoveWindow")); | |
b225f659 | 311 | } |
b225f659 VZ |
312 | |
313 | if ( !title.empty() ) | |
314 | { | |
315 | ::SetWindowText(GetHwnd(), title); | |
316 | } | |
317 | ||
318 | SubclassWin(m_hWnd); | |
319 | ||
320 | return TRUE; | |
321 | #endif // __WXMICROWIN__/!__WXMICROWIN__ | |
322 | } | |
323 | ||
324 | bool wxTopLevelWindowMSW::CreateFrame(const wxString& title, | |
325 | const wxPoint& pos, | |
326 | const wxSize& size) | |
327 | { | |
b2d5a7ee VZ |
328 | WXDWORD exflags; |
329 | WXDWORD flags = MSWGetCreateWindowFlags(&exflags); | |
b225f659 VZ |
330 | |
331 | return MSWCreate(wxCanvasClassName, title, pos, size, flags, exflags); | |
82c9f85c VZ |
332 | } |
333 | ||
334 | bool wxTopLevelWindowMSW::Create(wxWindow *parent, | |
335 | wxWindowID id, | |
336 | const wxString& title, | |
337 | const wxPoint& pos, | |
338 | const wxSize& size, | |
339 | long style, | |
340 | const wxString& name) | |
341 | { | |
342 | // init our fields | |
343 | Init(); | |
344 | ||
345 | m_windowStyle = style; | |
346 | ||
347 | SetName(name); | |
348 | ||
349 | m_windowId = id == -1 ? NewControlId() : id; | |
350 | ||
351 | wxTopLevelWindows.Append(this); | |
352 | ||
353 | if ( parent ) | |
354 | parent->AddChild(this); | |
355 | ||
b225f659 VZ |
356 | if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG ) |
357 | { | |
b225f659 VZ |
358 | // we have different dialog templates to allows creation of dialogs |
359 | // with & without captions under MSWindows, resizeable or not (but a | |
360 | // resizeable dialog always has caption - otherwise it would look too | |
361 | // strange) | |
434005ca VZ |
362 | |
363 | // we need 3 additional WORDs for dialog menu, class and title (as we | |
364 | // don't use DS_SETFONT we don't need the fourth WORD for the font) | |
365 | static const int dlgsize = sizeof(DLGTEMPLATE) + (sizeof(WORD) * 3); | |
366 | DLGTEMPLATE *dlgTemplate = (DLGTEMPLATE *)malloc(dlgsize); | |
367 | memset(dlgTemplate, 0, dlgsize); | |
368 | ||
369 | // these values are arbitrary, they won't be used normally anyhow | |
6e8515a3 JS |
370 | dlgTemplate->x = 34; |
371 | dlgTemplate->y = 22; | |
372 | dlgTemplate->cx = 144; | |
373 | dlgTemplate->cy = 75; | |
374 | ||
434005ca VZ |
375 | // reuse the code in MSWGetStyle() but correct the results slightly for |
376 | // the dialog | |
377 | dlgTemplate->style = MSWGetStyle(style, NULL); | |
378 | ||
379 | // all dialogs are popups | |
380 | dlgTemplate->style |= WS_POPUP; | |
381 | ||
382 | // force 3D-look if necessary, it looks impossibly ugly otherwise | |
383 | if ( style & (wxRESIZE_BORDER | wxCAPTION) ) | |
384 | dlgTemplate->style |= DS_MODALFRAME; | |
b225f659 | 385 | |
6e8515a3 JS |
386 | bool ret = CreateDialog(dlgTemplate, title, pos, size); |
387 | free(dlgTemplate); | |
434005ca | 388 | |
6e8515a3 | 389 | return ret; |
b225f659 VZ |
390 | } |
391 | else // !dialog | |
392 | { | |
393 | return CreateFrame(title, pos, size); | |
394 | } | |
82c9f85c VZ |
395 | } |
396 | ||
397 | wxTopLevelWindowMSW::~wxTopLevelWindowMSW() | |
398 | { | |
399 | wxTopLevelWindows.DeleteObject(this); | |
400 | ||
401 | if ( wxModelessWindows.Find(this) ) | |
402 | wxModelessWindows.DeleteObject(this); | |
403 | ||
404 | // If this is the last top-level window, exit. | |
405 | if ( wxTheApp && (wxTopLevelWindows.Number() == 0) ) | |
406 | { | |
407 | wxTheApp->SetTopWindow(NULL); | |
408 | ||
409 | if ( wxTheApp->GetExitOnFrameDelete() ) | |
410 | { | |
411 | ::PostQuitMessage(0); | |
412 | } | |
413 | } | |
414 | } | |
415 | ||
82c9f85c VZ |
416 | // ---------------------------------------------------------------------------- |
417 | // wxTopLevelWindowMSW showing | |
418 | // ---------------------------------------------------------------------------- | |
419 | ||
420 | void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd) | |
421 | { | |
422 | ::ShowWindow(GetHwnd(), nShowCmd); | |
423 | ||
424 | m_iconized = nShowCmd == SW_MINIMIZE; | |
425 | } | |
426 | ||
427 | bool wxTopLevelWindowMSW::Show(bool show) | |
428 | { | |
429 | // don't use wxWindow version as we want to call DoShowWindow() ourselves | |
430 | if ( !wxWindowBase::Show(show) ) | |
431 | return FALSE; | |
432 | ||
433 | int nShowCmd; | |
434 | if ( show ) | |
435 | { | |
436 | if ( m_maximizeOnShow ) | |
437 | { | |
438 | // show and maximize | |
439 | nShowCmd = SW_MAXIMIZE; | |
440 | ||
441 | m_maximizeOnShow = FALSE; | |
442 | } | |
443 | else // just show | |
444 | { | |
445 | nShowCmd = SW_SHOW; | |
446 | } | |
447 | } | |
448 | else // hide | |
449 | { | |
450 | nShowCmd = SW_HIDE; | |
451 | } | |
452 | ||
453 | DoShowWindow(nShowCmd); | |
454 | ||
455 | if ( show ) | |
456 | { | |
457 | ::BringWindowToTop(GetHwnd()); | |
458 | ||
459 | wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_windowId); | |
460 | event.SetEventObject( this ); | |
461 | GetEventHandler()->ProcessEvent(event); | |
462 | } | |
463 | else // hide | |
464 | { | |
465 | // Try to highlight the correct window (the parent) | |
466 | if ( GetParent() ) | |
467 | { | |
468 | HWND hWndParent = GetHwndOf(GetParent()); | |
469 | if (hWndParent) | |
470 | ::BringWindowToTop(hWndParent); | |
471 | } | |
472 | } | |
473 | ||
474 | return TRUE; | |
475 | } | |
476 | ||
477 | // ---------------------------------------------------------------------------- | |
478 | // wxTopLevelWindowMSW maximize/minimize | |
479 | // ---------------------------------------------------------------------------- | |
480 | ||
481 | void wxTopLevelWindowMSW::Maximize(bool maximize) | |
482 | { | |
483 | if ( IsShown() ) | |
484 | { | |
485 | // just maximize it directly | |
486 | DoShowWindow(maximize ? SW_MAXIMIZE : SW_RESTORE); | |
487 | } | |
488 | else // hidden | |
489 | { | |
490 | // we can't maximize the hidden frame because it shows it as well, so | |
491 | // just remember that we should do it later in this case | |
492 | m_maximizeOnShow = TRUE; | |
493 | } | |
494 | } | |
495 | ||
496 | bool wxTopLevelWindowMSW::IsMaximized() const | |
497 | { | |
498 | return ::IsZoomed(GetHwnd()) != 0; | |
499 | } | |
500 | ||
501 | void wxTopLevelWindowMSW::Iconize(bool iconize) | |
502 | { | |
503 | DoShowWindow(iconize ? SW_MINIMIZE : SW_RESTORE); | |
504 | } | |
505 | ||
506 | bool wxTopLevelWindowMSW::IsIconized() const | |
507 | { | |
508 | // also update the current state | |
509 | ((wxTopLevelWindowMSW *)this)->m_iconized = ::IsIconic(GetHwnd()) != 0; | |
510 | ||
511 | return m_iconized; | |
512 | } | |
513 | ||
514 | void wxTopLevelWindowMSW::Restore() | |
515 | { | |
516 | DoShowWindow(SW_RESTORE); | |
517 | } | |
518 | ||
c641b1d2 VS |
519 | // ---------------------------------------------------------------------------- |
520 | // wxTopLevelWindowMSW fullscreen | |
521 | // ---------------------------------------------------------------------------- | |
522 | ||
523 | bool wxTopLevelWindowMSW::ShowFullScreen(bool show, long style) | |
524 | { | |
525 | if (show) | |
526 | { | |
527 | if (IsFullScreen()) | |
528 | return FALSE; | |
529 | ||
530 | m_fsIsShowing = TRUE; | |
531 | m_fsStyle = style; | |
532 | ||
533 | // zap the frame borders | |
534 | ||
535 | // save the 'normal' window style | |
536 | m_fsOldWindowStyle = GetWindowLong((HWND)GetHWND(), GWL_STYLE); | |
537 | ||
538 | // save the old position, width & height, maximize state | |
539 | m_fsOldSize = GetRect(); | |
540 | m_fsIsMaximized = IsMaximized(); | |
541 | ||
542 | // decide which window style flags to turn off | |
543 | LONG newStyle = m_fsOldWindowStyle; | |
544 | LONG offFlags = 0; | |
545 | ||
546 | if (style & wxFULLSCREEN_NOBORDER) | |
547 | offFlags |= WS_BORDER | WS_THICKFRAME; | |
548 | if (style & wxFULLSCREEN_NOCAPTION) | |
549 | offFlags |= (WS_CAPTION | WS_SYSMENU); | |
550 | ||
551 | newStyle &= (~offFlags); | |
552 | ||
553 | // change our window style to be compatible with full-screen mode | |
554 | ::SetWindowLong((HWND)GetHWND(), GWL_STYLE, newStyle); | |
555 | ||
556 | // resize to the size of the desktop | |
557 | int width, height; | |
558 | ||
559 | RECT rect = wxGetWindowRect(::GetDesktopWindow()); | |
560 | width = rect.right - rect.left; | |
561 | height = rect.bottom - rect.top; | |
562 | ||
563 | SetSize(width, height); | |
564 | ||
565 | // now flush the window style cache and actually go full-screen | |
566 | SetWindowPos((HWND)GetHWND(), HWND_TOP, 0, 0, width, height, SWP_FRAMECHANGED); | |
567 | ||
568 | wxSizeEvent event(wxSize(width, height), GetId()); | |
569 | GetEventHandler()->ProcessEvent(event); | |
570 | ||
571 | return TRUE; | |
572 | } | |
573 | else | |
574 | { | |
575 | if (!IsFullScreen()) | |
576 | return FALSE; | |
577 | ||
578 | m_fsIsShowing = FALSE; | |
579 | ||
580 | Maximize(m_fsIsMaximized); | |
581 | SetWindowLong((HWND)GetHWND(),GWL_STYLE, m_fsOldWindowStyle); | |
582 | SetWindowPos((HWND)GetHWND(),HWND_TOP,m_fsOldSize.x, m_fsOldSize.y, | |
583 | m_fsOldSize.width, m_fsOldSize.height, SWP_FRAMECHANGED); | |
584 | ||
585 | return TRUE; | |
586 | } | |
587 | } | |
588 | ||
82c9f85c VZ |
589 | // ---------------------------------------------------------------------------- |
590 | // wxTopLevelWindowMSW misc | |
591 | // ---------------------------------------------------------------------------- | |
592 | ||
593 | void wxTopLevelWindowMSW::SetIcon(const wxIcon& icon) | |
594 | { | |
f618020a MB |
595 | SetIcons( wxIconBundle( icon ) ); |
596 | } | |
597 | ||
598 | void wxTopLevelWindowMSW::SetIcons(const wxIconBundle& icons) | |
599 | { | |
600 | wxTopLevelWindowBase::SetIcons(icons); | |
82c9f85c VZ |
601 | |
602 | #if defined(__WIN95__) && !defined(__WXMICROWIN__) | |
f618020a MB |
603 | const wxIcon& sml = icons.GetIcon( wxSize( 16, 16 ) ); |
604 | if( sml.Ok() && sml.GetWidth() == 16 && sml.GetHeight() == 16 ) | |
605 | { | |
606 | ::SendMessage( GetHwndOf( this ), WM_SETICON, ICON_SMALL, | |
607 | (LPARAM)GetHiconOf(sml) ); | |
608 | } | |
609 | ||
610 | const wxIcon& big = icons.GetIcon( wxSize( 32, 32 ) ); | |
611 | if( big.Ok() && big.GetWidth() == 32 && big.GetHeight() == 32 ) | |
82c9f85c | 612 | { |
f618020a MB |
613 | ::SendMessage( GetHwndOf( this ), WM_SETICON, ICON_BIG, |
614 | (LPARAM)GetHiconOf(big) ); | |
82c9f85c VZ |
615 | } |
616 | #endif // __WIN95__ | |
617 | } | |
a91cf80c VZ |
618 | |
619 | bool wxTopLevelWindowMSW::EnableCloseButton(bool enable) | |
620 | { | |
621 | #ifndef __WXMICROWIN__ | |
622 | // get system (a.k.a. window) menu | |
623 | HMENU hmenu = ::GetSystemMenu(GetHwnd(), FALSE /* get it */); | |
624 | if ( !hmenu ) | |
625 | { | |
626 | wxLogLastError(_T("GetSystemMenu")); | |
627 | ||
628 | return FALSE; | |
629 | } | |
630 | ||
631 | // enabling/disabling the close item from it also automatically | |
632 | // disables/enables the close title bar button | |
aaf765a5 VZ |
633 | if ( ::EnableMenuItem(hmenu, SC_CLOSE, |
634 | MF_BYCOMMAND | | |
635 | (enable ? MF_ENABLED : MF_GRAYED)) == -1 ) | |
a91cf80c VZ |
636 | { |
637 | wxLogLastError(_T("EnableMenuItem(SC_CLOSE)")); | |
638 | ||
639 | return FALSE; | |
640 | } | |
641 | ||
642 | // update appearance immediately | |
643 | if ( !::DrawMenuBar(GetHwnd()) ) | |
644 | { | |
645 | wxLogLastError(_T("DrawMenuBar")); | |
646 | } | |
647 | #endif // !__WXMICROWIN__ | |
648 | ||
649 | return TRUE; | |
650 | } | |
651 |