]>
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 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "stattext.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
25 #include "wx/stattext.h"
26 #include "wx/os2/private.h"
29 IMPLEMENT_DYNAMIC_CLASS(wxStaticText
, wxControl
)
31 bool wxStaticText::Create(wxWindow
*parent
, wxWindowID id
,
32 const wxString
& label
,
39 if (parent
) parent
->AddChild(this);
41 SetBackgroundColour(parent
->GetBackgroundColour()) ;
42 SetForegroundColour(parent
->GetForegroundColour()) ;
45 m_windowId
= (int)NewControlId();
54 m_windowStyle
= style
;
59 SetFont(parent
->GetFont());
60 SetSize(x
, y
, width
, height
);
65 wxSize
wxStaticText::DoGetBestSize() const
67 wxString
text(wxGetWindowText(GetHWND()));
69 int widthTextMax
= 0, widthLine
,
70 heightTextTotal
= 0, heightLineDefault
= 0, heightLine
= 0;
73 for ( const wxChar
*pc
= text
; ; pc
++ ) {
74 if ( *pc
== wxT('\n') || *pc
== wxT('\0') ) {
76 // we can't use GetTextExtent - it will return 0 for both width
77 // and height and an empty line should count in height
79 if ( !heightLineDefault
)
80 heightLineDefault
= heightLine
;
81 if ( !heightLineDefault
)
82 GetTextExtent(_T("W"), NULL
, &heightLineDefault
);
84 heightTextTotal
+= heightLineDefault
;
87 GetTextExtent(curLine
, &widthLine
, &heightLine
);
88 if ( widthLine
> widthTextMax
)
89 widthTextMax
= widthLine
;
90 heightTextTotal
+= heightLine
;
93 if ( *pc
== wxT('\n') ) {
106 return wxSize(widthTextMax
, heightTextTotal
);
109 void wxStaticText::SetLabel(const wxString
& label
)
113 // adjust the size of the window to fit to the label (this behaviour is
114 // backward compatible and generally makes sense but we might want to still
115 // provide the user a way to disable it) (VZ)
116 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
119 WXHBRUSH
wxStaticText::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
120 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
124 if (GetParent()->GetTransparentBackground())
125 SetBkMode((HDC) pDC, TRANSPARENT);
127 SetBkMode((HDC) pDC, OPAQUE);
129 ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
130 ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
132 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
133 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
134 // has a zero usage count.
135 // backgroundBrush->RealizeResource();
136 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
141 MRESULT
wxStaticText::OS2WindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
143 // Ensure that static items get messages. Some controls don't like this
144 // message to be intercepted (e.g. RichEdit), hence the tests.
147 if (nMsg == WM_NCHITTEST)
148 return (long)HTCLIENT;
150 return wxWindow::OS2WindowProc(nMsg
, wParam
, lParam
);