From 5b2f31eb30be576374064413b9d0f63a1bf8c110 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 20 Feb 2002 00:02:51 +0000 Subject: [PATCH] 1. always create the buttons with WS_CLIPSIBLINGS style, this prevetns them from overwriting each other when the main window is resized 2. more tweaks to MSWGetStyle() and related code, added a new, easier to use, version of MSWCreateControl() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14313 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + include/wx/msw/button.h | 2 + include/wx/msw/control.h | 16 ++++++-- src/msw/button.cpp | 83 +++++++++++++++++----------------------- src/msw/control.cpp | 49 ++++++++++++++++-------- src/msw/textctrl.cpp | 2 +- src/msw/window.cpp | 6 ++- 7 files changed, 89 insertions(+), 70 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 967568a938..36a00a6cc1 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -110,6 +110,7 @@ All (GUI): wxMSW: - small appearance fixes for native look under Windows XP +- refresh the buttons properly when the window is resized (Hans Van Leemputten) - huge (40*) speed up in wxMask::Create() - changing wxWindows styles also changes the underlying Windows window style - fixed flicker in wxTreeCtrl::SetItemXXX() diff --git a/include/wx/msw/button.h b/include/wx/msw/button.h index 52a68b5ab3..70f51f6fa5 100644 --- a/include/wx/msw/button.h +++ b/include/wx/msw/button.h @@ -69,7 +69,9 @@ protected: // send a notification event, return TRUE if processed bool SendClickEvent(); + // usually overridden base class virtuals virtual wxSize DoGetBestSize() const; + virtual WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const; private: DECLARE_DYNAMIC_CLASS(wxButton) diff --git a/include/wx/msw/control.h b/include/wx/msw/control.h index dc66995be7..e5e7f5c918 100644 --- a/include/wx/msw/control.h +++ b/include/wx/msw/control.h @@ -92,6 +92,17 @@ protected: virtual wxSize DoGetBestSize() const; + // create the control of the given Window class + bool MSWCreateControl(const wxChar *classname, + const wxString& label, + const wxPoint& pos, + const wxSize& size, + long style); + + // NB: the method below is deprecated now, with MSWGetStyle() the method + // above should be used instead! Once all the controls are updated to + // implement MSWGetStyle() this version will disappear. + // // create the control of the given class with the given style (combination // of WS_XXX flags, i.e. Windows style, not wxWindows one), returns // FALSE if creation failed @@ -108,9 +119,8 @@ protected: const wxString& label = wxEmptyString, WXDWORD exstyle = (WXDWORD)-1); - // determine the extended styles combination for this window (may slightly - // modify style parameter, this is why it's non const) - WXDWORD GetExStyle(WXDWORD& style, bool *want3D) const; + // default style for the control include WS_TABSTOP if it AcceptsFocus() + virtual WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const; private: DECLARE_EVENT_TABLE() diff --git a/src/msw/button.cpp b/src/msw/button.cpp index 62da82af8e..29464dda75 100644 --- a/src/msw/button.cpp +++ b/src/msw/button.cpp @@ -68,66 +68,47 @@ bool wxButton::Create(wxWindow *parent, const wxValidator& validator, const wxString& name) { - if ( !CreateBase(parent, id, pos, size, style, validator, name) ) + if ( !CreateControl(parent, id, pos, size, style, validator, name) ) return FALSE; - parent->AddChild((wxButton *)this); + return MSWCreateControl(_T("BUTTON"), label, pos, size, style); +} - m_backgroundColour = parent->GetBackgroundColour(); - m_foregroundColour = parent->GetForegroundColour(); +wxButton::~wxButton() +{ +} - long msStyle = WS_VISIBLE | WS_TABSTOP | WS_CHILD /* | WS_CLIPSIBLINGS */ ; +// ---------------------------------------------------------------------------- +// flags +// ---------------------------------------------------------------------------- - if ( m_windowStyle & wxCLIP_SIBLINGS ) - msStyle |= WS_CLIPSIBLINGS; +WXDWORD wxButton::MSWGetStyle(long style, WXDWORD *exstyle) const +{ + // buttons never have an external border, they draw their own one + WXDWORD msStyle = wxControl::MSWGetStyle + ( + (style & ~wxBORDER_MASK) | wxBORDER_NONE, exstyle + ); + + // we must use WS_CLIPSIBLINGS with the buttons or they would draw over + // each other in any resizeable dialog which has more than one button in + // the bottom + msStyle |= WS_CLIPSIBLINGS; #ifdef __WIN32__ - if(m_windowStyle & wxBU_LEFT) + // don't use "else if" here: weird as it is, but you may combine wxBU_LEFT + // and wxBU_RIGHT to get BS_CENTER! + if ( style & wxBU_LEFT ) msStyle |= BS_LEFT; - if(m_windowStyle & wxBU_RIGHT) + if ( style & wxBU_RIGHT ) msStyle |= BS_RIGHT; - if(m_windowStyle & wxBU_TOP) + if ( style & wxBU_TOP ) msStyle |= BS_TOP; - if(m_windowStyle & wxBU_BOTTOM) + if ( style & wxBU_BOTTOM ) msStyle |= BS_BOTTOM; -#endif - - m_hWnd = (WXHWND)CreateWindowEx - ( - MakeExtendedStyle(m_windowStyle), - wxT("BUTTON"), - label, - msStyle, - 0, 0, 0, 0, - GetWinHwnd(parent), - (HMENU)m_windowId, - wxGetInstance(), - NULL - ); - - if (m_hWnd == 0) - { - wxString msg; -#ifdef __WIN16__ - msg.Printf(wxT("CreateWindowEx failed")); -#else - msg.Printf(wxT("CreateWindowEx failed with error number %ld"), (long) GetLastError()); -#endif - wxFAIL_MSG(msg); - } - - // Subclass again for purposes of dialog editing mode - SubclassWin(m_hWnd); - - SetFont(parent->GetFont()); - - SetSize(pos.x, pos.y, size.x, size.y); - - return TRUE; -} +#endif // __WIN32__ -wxButton::~wxButton() -{ + return msStyle; } // ---------------------------------------------------------------------------- @@ -284,6 +265,12 @@ long wxButton::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) // and conitnue with processing the message normally as well } +#if 0 + else if ( nMsg == WM_MOVE ) + { + Refresh(); + } +#endif // let the base class do all real processing return wxControl::MSWWindowProc(nMsg, wParam, lParam); diff --git a/src/msw/control.cpp b/src/msw/control.cpp index 5454e029f9..930d7542ce 100644 --- a/src/msw/control.cpp +++ b/src/msw/control.cpp @@ -57,19 +57,34 @@ wxControl::~wxControl() } -bool wxControl::Create(wxWindow *parent, wxWindowID id, +bool wxControl::Create(wxWindow *parent, + wxWindowID id, const wxPoint& pos, - const wxSize& size, long style, + const wxSize& size, + long style, const wxValidator& validator, const wxString& name) { - bool rval = wxWindow::Create(parent, id, pos, size, style, name); - if (rval) { + if ( !wxWindow::Create(parent, id, pos, size, style, name) ) + return FALSE; + #if wxUSE_VALIDATORS - SetValidator(validator); + SetValidator(validator); #endif - } - return rval; + + return TRUE; +} + +bool wxControl::MSWCreateControl(const wxChar *classname, + const wxString& label, + const wxPoint& pos, + const wxSize& size, + long style) +{ + WXDWORD exstyle; + WXDWORD msStyle = MSWGetStyle(style, &exstyle); + + return MSWCreateControl(classname, msStyle, pos, size, label, exstyle); } bool wxControl::MSWCreateControl(const wxChar *classname, @@ -88,11 +103,11 @@ bool wxControl::MSWCreateControl(const wxChar *classname, // if no extended style given, determine it ourselves if ( exstyle == (WXDWORD)-1 ) { - exstyle = GetExStyle(style, &want3D); + exstyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D); } - // all controls have these styles (wxWindows creates all controls visible - // by default) + // all controls should have these styles (wxWindows creates all controls + // visible by default) style |= WS_CHILD | WS_VISIBLE; int x = pos.x == -1 ? 0 : pos.x, @@ -269,16 +284,16 @@ WXHBRUSH wxControl::OnCtlColor(WXHDC pDC, WXHWND WXUNUSED(pWnd), WXUINT WXUNUSED return (WXHBRUSH)brush->GetResourceHandle(); } -WXDWORD wxControl::GetExStyle(WXDWORD& style, bool *want3D) const +WXDWORD wxControl::MSWGetStyle(long style, WXDWORD *exstyle) const { - WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, want3D); + long msStyle = wxWindow::MSWGetStyle(style, exstyle); - // Even with extended styles, need to combine with WS_BORDER for them to - // look right. - if ( *want3D || wxStyleHasBorder(m_windowStyle) ) - style |= WS_BORDER; + if ( AcceptsFocus() ) + { + msStyle |= WS_TABSTOP; + } - return exStyle; + return msStyle; } // --------------------------------------------------------------------------- diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index b5a07c4239..4ecf1d2019 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -360,7 +360,7 @@ WXDWORD wxTextCtrl::MSWGetStyle(long style, WXDWORD *exstyle) const long msStyle = wxControl::MSWGetStyle(style, exstyle); // default styles - msStyle |= ES_LEFT | WS_TABSTOP; + msStyle |= ES_LEFT; if ( style & wxTE_MULTILINE ) { diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 1f157a7511..a189e89dcc 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -1027,7 +1027,11 @@ void wxWindowMSW::SetWindowStyleFlag(long flags) // update the internal variable wxWindowBase::SetWindowStyleFlag(flags); - // now update the Windows style as well if needed + // now update the Windows style as well if needed - and if the window had + // been already created + if ( !GetHwnd() ) + return; + WXDWORD exstyle, exstyleOld; long style = MSWGetStyle(flags, &exstyle), styleOld = MSWGetStyle(flagsOld, &exstyleOld); -- 2.45.2