]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/stattext.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxStaticText
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
21 #include "wx/stattext.h"
22 #include "wx/os2/private.h"
25 IMPLEMENT_DYNAMIC_CLASS(wxStaticText
, wxControl
)
27 bool wxStaticText::Create(wxWindow
*parent
, wxWindowID id
,
28 const wxString
& label
,
35 if (parent
) parent
->AddChild(this);
37 SetBackgroundColour(parent
->GetBackgroundColour()) ;
38 SetForegroundColour(parent
->GetForegroundColour()) ;
41 m_windowId
= (int)NewControlId();
50 m_windowStyle
= style
;
55 SetFont(parent
->GetFont());
56 SetSize(x
, y
, width
, height
);
61 wxSize
wxStaticText::DoGetBestSize() const
63 wxString
text(wxGetWindowText(GetHWND()));
65 int widthTextMax
= 0, widthLine
,
66 heightTextTotal
= 0, heightLineDefault
= 0, heightLine
= 0;
69 for ( const wxChar
*pc
= text
; ; pc
++ ) {
70 if ( *pc
== wxT('\n') || *pc
== wxT('\0') ) {
72 // we can't use GetTextExtent - it will return 0 for both width
73 // and height and an empty line should count in height
75 if ( !heightLineDefault
)
76 heightLineDefault
= heightLine
;
77 if ( !heightLineDefault
)
78 GetTextExtent(_T("W"), NULL
, &heightLineDefault
);
80 heightTextTotal
+= heightLineDefault
;
83 GetTextExtent(curLine
, &widthLine
, &heightLine
);
84 if ( widthLine
> widthTextMax
)
85 widthTextMax
= widthLine
;
86 heightTextTotal
+= heightLine
;
89 if ( *pc
== wxT('\n') ) {
102 return wxSize(widthTextMax
, heightTextTotal
);
105 void wxStaticText::SetLabel(const wxString
& label
)
109 // adjust the size of the window to fit to the label (this behaviour is
110 // backward compatible and generally makes sense but we might want to still
111 // provide the user a way to disable it) (VZ)
112 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
115 WXHBRUSH
wxStaticText::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
116 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
120 if (GetParent()->GetTransparentBackground())
121 SetBkMode((HDC) pDC, TRANSPARENT);
123 SetBkMode((HDC) pDC, OPAQUE);
125 ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
126 ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
128 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
129 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
130 // has a zero usage count.
131 // backgroundBrush->RealizeResource();
132 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
137 MRESULT
wxStaticText::OS2WindowProc(HWND hwnd
, WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
139 // Ensure that static items get messages. Some controls don't like this
140 // message to be intercepted (e.g. RichEdit), hence the tests.
143 if (nMsg == WM_NCHITTEST)
144 return (long)HTCLIENT;
146 return wxWindow::OS2WindowProc(hwnd
, nMsg
, wParam
, lParam
);