X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4438caf41af49f00f3c8137ac801871f59cce386..0c96db12c4e325093c4962aab9c51cc128cd7709:/src/msw/stattext.cpp?ds=sidebyside diff --git a/src/msw/stattext.cpp b/src/msw/stattext.cpp index 31c7c0141b..c4a61fd113 100644 --- a/src/msw/stattext.cpp +++ b/src/msw/stattext.cpp @@ -30,9 +30,7 @@ #include "wx/msw/private.h" #include -#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl) -#endif bool wxStaticText::Create(wxWindow *parent, wxWindowID id, const wxString& label, @@ -59,7 +57,7 @@ bool wxStaticText::Create(wxWindow *parent, wxWindowID id, m_windowStyle = style; - long msStyle = WS_CHILD|WS_VISIBLE; + long msStyle = WS_CHILD | WS_VISIBLE /* | WS_CLIPSIBLINGS */ ; if (m_windowStyle & wxALIGN_CENTRE) msStyle |= SS_CENTER; else if (m_windowStyle & wxALIGN_RIGHT) @@ -72,12 +70,12 @@ bool wxStaticText::Create(wxWindow *parent, wxWindowID id, if ( wxStyleHasBorder(m_windowStyle) ) msStyle |= WS_BORDER; - m_hWnd = (WXHWND)::CreateWindowEx(MakeExtendedStyle(m_windowStyle), _T("STATIC"), (const wxChar *)label, + m_hWnd = (WXHWND)::CreateWindowEx(MakeExtendedStyle(m_windowStyle), wxT("STATIC"), (const wxChar *)label, msStyle, 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL); - wxCHECK_MSG( m_hWnd, FALSE, _T("Failed to create static ctrl") ); + wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create static ctrl") ); #if wxUSE_CTL3D /* @@ -88,28 +86,41 @@ bool wxStaticText::Create(wxWindow *parent, wxWindowID id, SubclassWin(m_hWnd); - SetFont(parent->GetFont()); + wxControl::SetFont(parent->GetFont()); SetSize(x, y, width, height); return TRUE; } -wxSize wxStaticText::DoGetBestSize() +wxSize wxStaticText::DoGetBestSize() const { wxString text(wxGetWindowText(GetHWND())); int widthTextMax = 0, widthLine, - heightTextTotal = 0, heightLine; + heightTextTotal = 0, heightLineDefault = 0, heightLine = 0; wxString curLine; - for ( const char *pc = text; ; pc++ ) { - if ( *pc == '\n' || *pc == '\0' ) { - GetTextExtent(curLine, &widthLine, &heightLine); - if ( widthLine > widthTextMax ) - widthTextMax = widthLine; - heightTextTotal += heightLine; - - if ( *pc == '\n' ) { + for ( const wxChar *pc = text; ; pc++ ) { + if ( *pc == wxT('\n') || *pc == wxT('\0') ) { + if ( !curLine ) { + // we can't use GetTextExtent - it will return 0 for both width + // and height and an empty line should count in height + // calculation + if ( !heightLineDefault ) + heightLineDefault = heightLine; + if ( !heightLineDefault ) + GetTextExtent(_T("W"), NULL, &heightLineDefault); + + heightTextTotal += heightLineDefault; + } + else { + GetTextExtent(curLine, &widthLine, &heightLine); + if ( widthLine > widthTextMax ) + widthTextMax = widthLine; + heightTextTotal += heightLine; + } + + if ( *pc == wxT('\n') ) { curLine.Empty(); } else { @@ -129,45 +140,30 @@ void wxStaticText::SetLabel(const wxString& label) { SetWindowText(GetHwnd(), label); - // adjust the size of the window to fit to the label (this behaviour is - // backward compatible and generally makes sense but we might want to still - // provide the user a way to disable it) (VZ) - DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT); + // adjust the size of the window to fit to the label unless autoresizing is + // disabled + if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) + { + DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT); + } } -WXHBRUSH wxStaticText::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, - WXUINT message, WXWPARAM wParam, WXLPARAM lParam) -{ -/* -#if wxUSE_CTL3D - if ( m_useCtl3D ) - { - HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam); - - if (hbrush != (HBRUSH) 0) - return hbrush; - else - return (HBRUSH)MSWDefWindowProc(message, wParam, lParam); - } -#endif -*/ - - if (GetParent()->GetTransparentBackground()) - SetBkMode((HDC) pDC, TRANSPARENT); - else - SetBkMode((HDC) pDC, OPAQUE); - ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue())); - ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue())); +bool wxStaticText::SetFont(const wxFont& font) +{ + bool ret = wxControl::SetFont(font); - wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID); + // adjust the size of the window to fit to the label unless autoresizing is + // disabled + if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) + { + DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT); + } - // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush - // has a zero usage count. -// backgroundBrush->RealizeResource(); - return (WXHBRUSH) backgroundBrush->GetResourceHandle(); + return ret; } + long wxStaticText::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) { // Ensure that static items get messages. Some controls don't like this