X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/55cd5d10cd919f9cd50f9e9403f5f74a03c6f057..e3276230de335908f70232b2a5ede43665bd8d9d:/src/msw/window.cpp diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 1f4fe79892..7dfd87df99 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -716,15 +716,27 @@ bool wxWindowMSW::Show(bool show) ::ShowWindow(hWnd, show ? SW_SHOW : SW_HIDE); } + if ( IsFrozen() ) + { + // DoFreeze/DoThaw don't do anything if the window is not shown, so + // we have to call them from here now + if ( show ) + DoFreeze(); + else + DoThaw(); + } + return true; } bool wxWindowMSW::MSWShowWithEffect(bool show, wxShowEffect effect, - unsigned timeout, - wxDirection dir) + unsigned timeout) { + if ( !wxWindowBase::Show(show) ) + return false; + typedef BOOL (WINAPI *AnimateWindow_t)(HWND, DWORD, DWORD); static AnimateWindow_t s_pfnAnimateWindow = NULL; @@ -749,16 +761,39 @@ wxWindowMSW::MSWShowWithEffect(bool show, timeout = 200; // this is the default animation timeout, per MSDN DWORD dwFlags = show ? 0 : AW_HIDE; - bool needsDir = false; + switch ( effect ) { - case wxSHOW_EFFECT_ROLL: - needsDir = true; + case wxSHOW_EFFECT_ROLL_TO_LEFT: + dwFlags |= AW_HOR_NEGATIVE; break; - case wxSHOW_EFFECT_SLIDE: - needsDir = true; - dwFlags |= AW_SLIDE; + case wxSHOW_EFFECT_ROLL_TO_RIGHT: + dwFlags |= AW_HOR_POSITIVE; + break; + + case wxSHOW_EFFECT_ROLL_TO_TOP: + dwFlags |= AW_VER_NEGATIVE; + break; + + case wxSHOW_EFFECT_ROLL_TO_BOTTOM: + dwFlags |= AW_VER_POSITIVE; + break; + + case wxSHOW_EFFECT_SLIDE_TO_LEFT: + dwFlags |= AW_SLIDE | AW_HOR_NEGATIVE; + break; + + case wxSHOW_EFFECT_SLIDE_TO_RIGHT: + dwFlags |= AW_SLIDE | AW_HOR_POSITIVE; + break; + + case wxSHOW_EFFECT_SLIDE_TO_TOP: + dwFlags |= AW_SLIDE | AW_VER_NEGATIVE; + break; + + case wxSHOW_EFFECT_SLIDE_TO_BOTTOM: + dwFlags |= AW_SLIDE | AW_VER_POSITIVE; break; case wxSHOW_EFFECT_BLEND: @@ -779,38 +814,6 @@ wxWindowMSW::MSWShowWithEffect(bool show, return false; } - if ( needsDir ) - { - switch ( dir ) - { - case wxTOP: - dwFlags |= AW_VER_NEGATIVE; - break; - - case wxBOTTOM: - dwFlags |= AW_VER_POSITIVE; - break; - - case wxLEFT: - dwFlags |= AW_HOR_NEGATIVE; - break; - - case wxRIGHT: - dwFlags |= AW_HOR_POSITIVE; - break; - - default: - wxFAIL_MSG( _T("unknown window effect direction") ); - return false; - } - } - else // animation effect which doesn't need the direction - { - wxASSERT_MSG( dir == wxBOTTOM, - _T("non-default direction used unnecessarily") ); - } - - if ( !(*s_pfnAnimateWindow)(GetHwnd(), timeout, dwFlags) ) { wxLogLastError(_T("AnimateWindow")); @@ -868,7 +871,11 @@ bool wxWindowMSW::SetFont(const wxFont& font) HWND hWnd = GetHwnd(); if ( hWnd != 0 ) { - WXHANDLE hFont = m_font.GetResourceHandle(); + // note the use of GetFont() instead of m_font: our own font could have + // just been reset and in this case we need to change the font used by + // the native window to the default for this class, i.e. exactly what + // GetFont() returns + WXHANDLE hFont = GetFont().GetResourceHandle(); wxASSERT_MSG( hFont, wxT("should have valid font") ); @@ -1612,20 +1619,22 @@ static inline void SendSetRedraw(HWND hwnd, bool on) void wxWindowMSW::DoFreeze() { - if ( IsShown() ) - SendSetRedraw(GetHwnd(), false); + if ( !IsShown() ) + return; // no point in freezing hidden window + + SendSetRedraw(GetHwnd(), false); } void wxWindowMSW::DoThaw() { - if ( IsShown() ) - { - SendSetRedraw(GetHwnd(), true); + if ( !IsShown() ) + return; // hidden windows aren't frozen by DoFreeze - // we need to refresh everything or otherwise the invalidated area - // is not going to be repainted - Refresh(); - } + SendSetRedraw(GetHwnd(), true); + + // we need to refresh everything or otherwise the invalidated area + // is not going to be repainted + Refresh(); } void wxWindowMSW::Refresh(bool eraseBack, const wxRect *rect) @@ -3664,6 +3673,12 @@ bool wxWindowMSW::MSWCreate(const wxChar *wclass, WXDWORD style, WXDWORD extendedStyle) { + // check a common bug in the user code: if the window is created with a + // non-default ctor and Create() is called too, we'd create 2 HWND for a + // single wxWindow object and this results in all sorts of trouble, + // especially for wxTLWs + wxCHECK_MSG( !m_hWnd, true, "window can't be recreated" ); + // choose the position/size for the new window int x, y, w, h; (void)MSWGetCreateWindowCoords(pos, size, x, y, w, h); @@ -3903,7 +3918,7 @@ bool wxWindowMSW::HandleEndSession(bool endSession, long logOff) wxCloseEvent event(wxEVT_END_SESSION, wxID_ANY); event.SetEventObject(wxTheApp); event.SetCanVeto(false); - event.SetLoggingOff( (logOff == (long)ENDSESSION_LOGOFF) ); + event.SetLoggingOff((logOff & ENDSESSION_LOGOFF) != 0); return wxTheApp->ProcessEvent(event); #else @@ -4246,17 +4261,32 @@ bool wxWindowMSW::HandlePower(WXWPARAM WXUNUSED_IN_WINCE(wParam), bool wxWindowMSW::IsDoubleBuffered() const { - for ( const wxWindowMSW *wnd = this; - wnd && !wnd->IsTopLevel(); wnd = - wnd->GetParent() ) - { - if ( ::GetWindowLong(GetHwndOf(wnd), GWL_EXSTYLE) & WS_EX_COMPOSITED ) + const wxWindowMSW *wnd = this; + do { + long style = ::GetWindowLong(GetHwndOf(wnd), GWL_EXSTYLE); + if ( (style & WS_EX_COMPOSITED) != 0 ) return true; - } - + wnd = wnd->GetParent(); + } while ( wnd && !wnd->IsTopLevel() ); + return false; } +void wxWindowMSW::SetDoubleBuffered(bool on) +{ + // Get the current extended style bits + long exstyle = ::GetWindowLong(GetHwnd(), GWL_EXSTYLE); + + // Twiddle the bit as needed + if ( on ) + exstyle |= WS_EX_COMPOSITED; + else + exstyle &= ~WS_EX_COMPOSITED; + + // put it back + ::SetWindowLong(GetHwnd(), GWL_EXSTYLE, exstyle); +} + // --------------------------------------------------------------------------- // owner drawn stuff // --------------------------------------------------------------------------- @@ -5067,12 +5097,8 @@ bool wxWindowMSW::HandleCommand(WXWORD id_, WXWORD cmd, WXHWND control) // coming from a control to wxEVT_COMMAND_MENU_SELECTED if ( !control ) { - // If no child window, it may be an accelerator, e.g. for a popup menu - // command - - wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED); + wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, id); event.SetEventObject(this); - event.SetId(id); event.SetInt(id); return HandleWindowEvent(event); @@ -5609,18 +5635,19 @@ int wxWindowMSW::HandleMenuChar(int WXUNUSED_IN_WINCE(chAccel), return wxNOT_FOUND; } -bool wxWindowMSW::HandleClipboardEvent( WXUINT nMsg ) +#endif // wxUSE_MENUS + +bool wxWindowMSW::HandleClipboardEvent(WXUINT nMsg) { - const wxEventType type = ( nMsg == WM_CUT ) ? wxEVT_COMMAND_TEXT_CUT : - ( nMsg == WM_COPY ) ? wxEVT_COMMAND_TEXT_COPY : - /*( nMsg == WM_PASTE ) ? */ wxEVT_COMMAND_TEXT_PASTE; + const wxEventType type = nMsg == WM_CUT ? wxEVT_COMMAND_TEXT_CUT + : nMsg == WM_COPY ? wxEVT_COMMAND_TEXT_COPY + : /* nMsg == WM_PASTE */ wxEVT_COMMAND_TEXT_PASTE; wxClipboardTextEvent evt(type, GetId()); evt.SetEventObject(this); return HandleWindowEvent(evt); } -#endif // wxUSE_MENUS // --------------------------------------------------------------------------- // joystick