]>
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()
65 wxString
text(wxGetWindowText(GetHWND()));
67 int widthTextMax
= 0, widthLine
,
68 heightTextTotal
= 0, heightLine
;
71 for ( const wxChar
*pc
= text
; ; pc
++ ) {
72 if ( *pc
== wxT('\n') || *pc
== wxT('\0') ) {
73 GetTextExtent(curLine
, &widthLine
, &heightLine
);
74 if ( widthLine
> widthTextMax
)
75 widthTextMax
= widthLine
;
76 heightTextTotal
+= heightLine
;
78 if ( *pc
== wxT('\n') ) {
91 return wxSize(widthTextMax
, heightTextTotal
);
94 void wxStaticText::SetLabel(const wxString
& label
)
98 // adjust the size of the window to fit to the label (this behaviour is
99 // backward compatible and generally makes sense but we might want to still
100 // provide the user a way to disable it) (VZ)
101 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
104 WXHBRUSH
wxStaticText::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
105 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
109 if (GetParent()->GetTransparentBackground())
110 SetBkMode((HDC) pDC, TRANSPARENT);
112 SetBkMode((HDC) pDC, OPAQUE);
114 ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
115 ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
117 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
118 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
119 // has a zero usage count.
120 // backgroundBrush->RealizeResource();
121 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
126 MRESULT
wxStaticText::OS2WindowProc(HWND hwnd
, WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
128 // Ensure that static items get messages. Some controls don't like this
129 // message to be intercepted (e.g. RichEdit), hence the tests.
132 if (nMsg == WM_NCHITTEST)
133 return (long)HTCLIENT;
135 return wxWindow::OS2WindowProc(hwnd
, nMsg
, wParam
, lParam
);