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
This commit is contained in:
Vadim Zeitlin 2002-02-20 00:02:51 +00:00
parent f7b0208507
commit 5b2f31eb30
7 changed files with 95 additions and 76 deletions

View File

@ -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()

View File

@ -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)

View File

@ -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()

View File

@ -68,68 +68,49 @@ 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);
m_backgroundColour = parent->GetBackgroundColour();
m_foregroundColour = parent->GetForegroundColour();
long msStyle = WS_VISIBLE | WS_TABSTOP | WS_CHILD /* | WS_CLIPSIBLINGS */ ;
if ( m_windowStyle & wxCLIP_SIBLINGS )
msStyle |= WS_CLIPSIBLINGS;
#ifdef __WIN32__
if(m_windowStyle & wxBU_LEFT)
msStyle |= BS_LEFT;
if(m_windowStyle & wxBU_RIGHT)
msStyle |= BS_RIGHT;
if(m_windowStyle & wxBU_TOP)
msStyle |= BS_TOP;
if(m_windowStyle & 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;
return MSWCreateControl(_T("BUTTON"), label, pos, size, style);
}
wxButton::~wxButton()
{
}
// ----------------------------------------------------------------------------
// flags
// ----------------------------------------------------------------------------
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__
// 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 ( style & wxBU_RIGHT )
msStyle |= BS_RIGHT;
if ( style & wxBU_TOP )
msStyle |= BS_TOP;
if ( style & wxBU_BOTTOM )
msStyle |= BS_BOTTOM;
#endif // __WIN32__
return msStyle;
}
// ----------------------------------------------------------------------------
// size management including autosizing
// ----------------------------------------------------------------------------
@ -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);

View File

@ -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;
}
// ---------------------------------------------------------------------------

View File

@ -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 )
{

View File

@ -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);