X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1542ea396a625766c59d683adbb1d613c1344d50..8f4d9fcd9a1133442aa733e978231b01956e641b:/src/msw/toplevel.cpp diff --git a/src/msw/toplevel.cpp b/src/msw/toplevel.cpp index 7d0164a3c0..e3dccf8050 100644 --- a/src/msw/toplevel.cpp +++ b/src/msw/toplevel.cpp @@ -17,7 +17,7 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "toplevel.h" #endif @@ -41,6 +41,17 @@ #include "wx/module.h" #include "wx/msw/private.h" +#if defined(__WXWINCE__) + #include + #include + #if _WIN32_WCE < 400 + #include + #endif +#include "wx/msw/wince/missing.h" +#endif + +#include "wx/msw/missing.h" +#include "wx/msw/winundef.h" #include "wx/display.h" @@ -122,9 +133,6 @@ void wxTopLevelWindowMSW::Init() m_iconized = m_maximizeOnShow = FALSE; - // unlike (almost?) all other windows, frames are created hidden - m_isShown = FALSE; - // Data to save/restore when calling ShowFullScreen m_fsStyle = 0; m_fsOldWindowStyle = 0; @@ -141,7 +149,7 @@ WXDWORD wxTopLevelWindowMSW::MSWGetStyle(long style, WXDWORD *exflags) const WXDWORD msflags = wxWindow::MSWGetStyle ( (style & ~wxBORDER_MASK) | wxBORDER_NONE, exflags - ) & ~WS_CHILD; + ) & ~WS_CHILD & ~WS_VISIBLE; // first select the kind of window being created // @@ -151,11 +159,16 @@ WXDWORD wxTopLevelWindowMSW::MSWGetStyle(long style, WXDWORD *exflags) const if ( style & wxFRAME_TOOL_WINDOW ) msflags |= WS_POPUP; else - msflags |= WS_OVERLAPPED; + { + if (msflags & WS_BORDER) + msflags |= WS_OVERLAPPED; + } // border and caption styles if ( style & wxRESIZE_BORDER ) msflags |= WS_THICKFRAME; + else if ( exflags && ((style & wxBORDER_DOUBLE) || (style & wxBORDER_RAISED)) ) + *exflags |= WS_EX_DLGMODALFRAME; else if ( !(style & wxBORDER_NONE) ) msflags |= WS_BORDER; else @@ -173,33 +186,36 @@ WXDWORD wxTopLevelWindowMSW::MSWGetStyle(long style, WXDWORD *exflags) const msflags |= WS_MAXIMIZEBOX; if ( style & wxSYSTEM_MENU ) msflags |= WS_SYSMENU; + + // under CE these 2 styles are not defined currently +#ifdef WS_MINIMIZE if ( style & wxMINIMIZE ) msflags |= WS_MINIMIZE; +#endif // WS_MINIMIZE +#ifdef WS_MAXIMIZE if ( style & wxMAXIMIZE ) msflags |= WS_MAXIMIZE; +#endif // WS_MAXIMIZE // Keep this here because it saves recoding this function in wxTinyFrame -#if wxUSE_ITSY_BITSY && !defined(__WIN32__) - if ( style & wxTINY_CAPTION_VERT ) - msflags |= IBS_VERTCAPTION; - if ( style & wxTINY_CAPTION_HORIZ ) - msflags |= IBS_HORZCAPTION; -#else if ( style & (wxTINY_CAPTION_VERT | wxTINY_CAPTION_HORIZ) ) msflags |= WS_CAPTION; -#endif if ( exflags ) { -#if !defined(__WIN16__) && !defined(__SC__) if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) ) { if ( style & wxFRAME_TOOL_WINDOW ) { // create the palette-like window *exflags |= WS_EX_TOOLWINDOW; + + // tool windows shouldn't appear on the taskbar (as documented) + style |= wxFRAME_NO_TASKBAR; } + // again, support for this is missing under CE +#ifdef WS_EX_APPWINDOW // We have to solve 2 different problems here: // // 1. frames with wxFRAME_NO_TASKBAR flag shouldn't appear in the @@ -218,16 +234,14 @@ WXDWORD wxTopLevelWindowMSW::MSWGetStyle(long style, WXDWORD *exflags) const *exflags |= WS_EX_APPWINDOW; } //else: nothing to do [here] +#endif // WS_EX_APPWINDOW } -#endif // !Win16 if ( style & wxSTAY_ON_TOP ) *exflags |= WS_EX_TOPMOST; -#ifdef __WIN32__ if ( GetExtraStyle() & wxFRAME_EX_CONTEXTHELP ) *exflags |= WS_EX_CONTEXTHELP; -#endif // __WIN32__ } return msflags; @@ -323,10 +337,12 @@ bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate, if ( exflags ) { ::SetWindowLong(GetHwnd(), GWL_EXSTYLE, exflags); - ::SetWindowPos(GetHwnd(), NULL, 0, 0, 0, 0, + ::SetWindowPos(GetHwnd(), + exflags & WS_EX_TOPMOST ? HWND_TOPMOST : 0, + 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | - SWP_NOZORDER | + (exflags & WS_EX_TOPMOST ? 0 : SWP_NOZORDER) | SWP_NOACTIVATE); } @@ -351,25 +367,7 @@ bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate, // move the dialog to its initial position without forcing repainting int x, y, w, h; - if ( !MSWGetCreateWindowCoords(pos, size, x, y, w, h) ) - { - x = - w = (int)CW_USEDEFAULT; - } - - // we can't use CW_USEDEFAULT here as we're not calling CreateWindow() - // and passing CW_USEDEFAULT to MoveWindow() results in resizing the - // window to (0, 0) size which breaks quite a lot of things, e.g. the - // sizer calculation in wxSizer::Fit() - if ( w == (int)CW_USEDEFAULT ) - { - // the exact number doesn't matter, the dialog will be resized - // again soon anyhow but it should be big enough to allow - // calculation relying on "totalSize - clientSize > 0" work, i.e. - // at least greater than the title bar height - w = - h = 100; - } + (void)MSWGetCreateWindowCoords(pos, size, x, y, w, h); if ( x == (int)CW_USEDEFAULT ) { @@ -414,11 +412,17 @@ bool wxTopLevelWindowMSW::Create(wxWindow *parent, long style, const wxString& name) { - bool ret = false; + bool ret wxDUMMY_INITIALIZE(false); // init our fields Init(); + wxSize sizeReal = size; + if ( !sizeReal.IsFullySpecified() ) + { + sizeReal.SetDefaults(GetDefaultSize()); + } + m_windowStyle = style; SetName(name); @@ -460,12 +464,12 @@ bool wxTopLevelWindowMSW::Create(wxWindow *parent, if ( style & (wxRESIZE_BORDER | wxCAPTION) ) dlgTemplate->style |= DS_MODALFRAME; - ret = CreateDialog(dlgTemplate, title, pos, size); + ret = CreateDialog(dlgTemplate, title, pos, sizeReal); free(dlgTemplate); } else // !dialog { - ret = CreateFrame(title, pos, size); + ret = CreateFrame(title, pos, sizeReal); } if ( ret && !(GetWindowStyleFlag() & wxCLOSE_BOX) ) @@ -473,6 +477,23 @@ bool wxTopLevelWindowMSW::Create(wxWindow *parent, EnableCloseButton(false); } + // for some reason we need to manually send ourselves this message as + // otherwise the mnemonics are always shown -- even if they're configured + // to be hidden until "Alt" is pressed in the control panel + // + // this could indicate a bug somewhere else but for now this is the only + // fix we have + if ( ret ) + { + SendMessage + ( + GetHwnd(), + WM_UPDATEUISTATE, + MAKEWPARAM(UIS_INITIALIZE, UISF_HIDEFOCUS | UISF_HIDEACCEL), + 0 + ); + } + return ret; } @@ -580,7 +601,11 @@ void wxTopLevelWindowMSW::Maximize(bool maximize) bool wxTopLevelWindowMSW::IsMaximized() const { +#ifdef __WXWINCE__ + return FALSE; +#else return ::IsZoomed(GetHwnd()) != 0; +#endif } void wxTopLevelWindowMSW::Iconize(bool iconize) @@ -590,10 +615,14 @@ void wxTopLevelWindowMSW::Iconize(bool iconize) bool wxTopLevelWindowMSW::IsIconized() const { +#ifdef __WXWINCE__ + return FALSE; +#else // also update the current state ((wxTopLevelWindowMSW *)this)->m_iconized = ::IsIconic(GetHwnd()) != 0; return m_iconized; +#endif } void wxTopLevelWindowMSW::Restore() @@ -633,7 +662,12 @@ bool wxTopLevelWindowMSW::ShowFullScreen(bool show, long style) LONG offFlags = 0; if (style & wxFULLSCREEN_NOBORDER) - offFlags |= WS_BORDER | WS_THICKFRAME; + { + offFlags |= WS_BORDER; +#ifndef __WXWINCE__ + offFlags |= WS_THICKFRAME; +#endif + } if (style & wxFULLSCREEN_NOCAPTION) offFlags |= WS_CAPTION | WS_SYSMENU; @@ -655,6 +689,12 @@ bool wxTopLevelWindowMSW::ShowFullScreen(bool show, long style) { // resize to the size of the desktop wxCopyRECTToRect(wxGetWindowRect(::GetDesktopWindow()), rect); +#ifdef __WXWINCE__ + // FIXME: size of the bottom menu (toolbar) + // should be taken in account + rect.height += rect.y; + rect.y = 0; +#endif } #endif // wxUSE_DISPLAY @@ -680,12 +720,19 @@ bool wxTopLevelWindowMSW::ShowFullScreen(bool show, long style) rect.x, rect.y, rect.width, rect.height, flags); +#if defined(__WXWINCE__) && _WIN32_WCE < 400 + ::SHFullScreen(GetHwnd(), SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON); +#endif + // finally send an event allowing the window to relayout itself &c wxSizeEvent event(rect.GetSize(), GetId()); GetEventHandler()->ProcessEvent(event); } else // stop showing full screen { +#if defined(__WXWINCE__) && _WIN32_WCE < 400 + ::SHFullScreen(GetHwnd(), SHFS_SHOWTASKBAR | SHFS_SHOWSIPBUTTON); +#endif Maximize(m_fsIsMaximized); SetWindowLong(GetHwnd(),GWL_STYLE, m_fsOldWindowStyle); SetWindowPos(GetHwnd(),HWND_TOP,m_fsOldSize.x, m_fsOldSize.y, @@ -727,14 +774,14 @@ void wxTopLevelWindowMSW::SetIcons(const wxIconBundle& icons) bool wxTopLevelWindowMSW::EnableCloseButton(bool enable) { -#ifndef __WXMICROWIN__ +#if !defined(__WXMICROWIN__) // get system (a.k.a. window) menu - HMENU hmenu = ::GetSystemMenu(GetHwnd(), FALSE /* get it */); + HMENU hmenu = GetSystemMenu(GetHwnd(), FALSE /* get it */); if ( !hmenu ) { - wxLogLastError(_T("GetSystemMenu")); - - return FALSE; + // no system menu at all -- ok if we want to remove the close button + // anyhow, but bad if we want to show it + return !enable; } // enabling/disabling the close item from it also automatically @@ -758,8 +805,13 @@ bool wxTopLevelWindowMSW::EnableCloseButton(bool enable) return TRUE; } +#ifndef __WXWINCE__ + bool wxTopLevelWindowMSW::SetShape(const wxRegion& region) { + wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), FALSE, + _T("Shaped windows must be created with the wxFRAME_SHAPED style.")); + // The empty region signifies that the shape should be removed from the // window. if ( region.IsEmpty() ) @@ -799,6 +851,8 @@ bool wxTopLevelWindowMSW::SetShape(const wxRegion& region) return TRUE; } +#endif // !__WXWINCE__ + // ---------------------------------------------------------------------------- // wxTopLevelWindow event handling // ---------------------------------------------------------------------------- @@ -809,17 +863,22 @@ void wxTopLevelWindowMSW::OnActivate(wxActivateEvent& event) { if ( event.GetActive() ) { - // restore focus to the child which was last focused + // restore focus to the child which was last focused unless we already + // have it wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd); - wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent() - : NULL; - if ( !parent ) + wxWindow *winFocus = FindFocus(); + if ( !winFocus || wxGetTopLevelParent(winFocus) != this ) { - parent = this; - } + wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent() + : NULL; + if ( !parent ) + { + parent = this; + } - wxSetFocusToChild(parent, &m_winLastFocused); + wxSetFocusToChild(parent, &m_winLastFocused); + } } else // deactivating { @@ -830,23 +889,12 @@ void wxTopLevelWindowMSW::OnActivate(wxActivateEvent& event) { // let it know that it doesn't have focus any more m_winLastFocused->HandleKillFocus((WXHWND)NULL); - } - // so we NULL it out if it's a child from some other frame - wxWindow *win = m_winLastFocused; - while ( win ) - { - if ( win->IsTopLevel() ) + // and don't remember it if it's a child from some other frame + if ( wxGetTopLevelParent(m_winLastFocused) != this ) { - if ( win != this ) - { - m_winLastFocused = NULL; - } - - break; + m_winLastFocused = NULL; } - - win = win->GetParent(); } wxLogTrace(_T("focus"), @@ -861,7 +909,10 @@ void wxTopLevelWindowMSW::OnActivate(wxActivateEvent& event) // the DialogProc for all wxWindows dialogs LONG APIENTRY _EXPORT -wxDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +wxDlgProc(HWND WXUNUSED(hDlg), + UINT message, + WPARAM WXUNUSED(wParam), + LPARAM WXUNUSED(lParam)) { switch ( message ) { @@ -942,7 +993,7 @@ HWND wxTLWHiddenParentModule::GetHWND() } } - ms_hwnd = ::CreateWindow(ms_className, _T(""), 0, 0, 0, 0, 0, NULL, + ms_hwnd = ::CreateWindow(ms_className, wxEmptyString, 0, 0, 0, 0, 0, NULL, (HMENU)NULL, wxGetInstance(), NULL); if ( !ms_hwnd ) {