]>
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 #if !USE_SHARED_LIBRARY
26 IMPLEMENT_DYNAMIC_CLASS(wxStaticText
, wxControl
)
29 bool wxStaticText::Create(wxWindow
*parent
, wxWindowID id
,
30 const wxString
& label
,
37 if (parent
) parent
->AddChild(this);
39 SetBackgroundColour(parent
->GetBackgroundColour()) ;
40 SetForegroundColour(parent
->GetForegroundColour()) ;
43 m_windowId
= (int)NewControlId();
52 m_windowStyle
= style
;
57 SetFont(parent
->GetFont());
58 SetSize(x
, y
, width
, height
);
63 wxSize
wxStaticText::DoGetBestSize() const
65 wxString
text(wxGetWindowText(GetHWND()));
67 int widthTextMax
= 0, widthLine
,
68 heightTextTotal
= 0, heightLineDefault
= 0, heightLine
= 0;
71 for ( const wxChar
*pc
= text
; ; pc
++ ) {
72 if ( *pc
== wxT('\n') || *pc
== wxT('\0') ) {
74 // we can't use GetTextExtent - it will return 0 for both width
75 // and height and an empty line should count in height
77 if ( !heightLineDefault
)
78 heightLineDefault
= heightLine
;
79 if ( !heightLineDefault
)
80 GetTextExtent(_T("W"), NULL
, &heightLineDefault
);
82 heightTextTotal
+= heightLineDefault
;
85 GetTextExtent(curLine
, &widthLine
, &heightLine
);
86 if ( widthLine
> widthTextMax
)
87 widthTextMax
= widthLine
;
88 heightTextTotal
+= heightLine
;
91 if ( *pc
== wxT('\n') ) {
104 return wxSize(widthTextMax
, heightTextTotal
);
107 void wxStaticText::SetLabel(const wxString
& label
)
111 // adjust the size of the window to fit to the label (this behaviour is
112 // backward compatible and generally makes sense but we might want to still
113 // provide the user a way to disable it) (VZ)
114 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
117 WXHBRUSH
wxStaticText::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
118 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
122 if (GetParent()->GetTransparentBackground())
123 SetBkMode((HDC) pDC, TRANSPARENT);
125 SetBkMode((HDC) pDC, OPAQUE);
127 ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
128 ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
130 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
131 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
132 // has a zero usage count.
133 // backgroundBrush->RealizeResource();
134 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
139 MRESULT
wxStaticText::OS2WindowProc(HWND hwnd
, WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
141 // Ensure that static items get messages. Some controls don't like this
142 // message to be intercepted (e.g. RichEdit), hence the tests.
145 if (nMsg == WM_NCHITTEST)
146 return (long)HTCLIENT;
148 return wxWindow::OS2WindowProc(hwnd
, nMsg
, wParam
, lParam
);