]>
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"
23 #include "wx/scrolwin.h"
26 #include "wx/stattext.h"
27 #include "wx/os2/private.h"
30 IMPLEMENT_DYNAMIC_CLASS(wxStaticText
, wxControl
)
32 bool wxStaticText::Create(
35 , const wxString
& rsLabel
39 , const wxString
& rsName
44 pParent
->AddChild(this);
46 SetBackgroundColour(pParent
->GetBackgroundColour()) ;
47 SetForegroundColour(pParent
->GetForegroundColour()) ;
50 m_windowId
= (int)NewControlId();
57 int nHeight
= rSize
.y
;
59 m_windowStyle
= lStyle
;
63 lSstyle
= WS_VISIBLE
| SS_TEXT
| DT_VCENTER
;
64 if (m_windowStyle
& wxALIGN_CENTRE
)
66 else if (m_windowStyle
& wxALIGN_RIGHT
)
71 // If the parent is a scrolled window the controls must
72 // have this style or they will overlap the scrollbars
75 if (pParent
->IsKindOf(CLASSINFO(wxScrolledWindow
)) ||
76 pParent
->IsKindOf(CLASSINFO(wxGenericScrolledWindow
)))
77 lSstyle
|= WS_CLIPSIBLINGS
;
79 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
80 ,WC_STATIC
// Window class
81 ,(PSZ
)rsLabel
.c_str() // Initial Text
82 ,(ULONG
)lSstyle
// Style flags
83 ,0L, 0L, 0L, 0L // Origin -- 0 size
84 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
85 ,HWND_TOP
// initial z position
86 ,(ULONG
)m_windowId
// Window identifier
87 ,NULL
// no control data
88 ,NULL
// no Presentation parameters
91 wxCHECK_MSG(m_hWnd
, FALSE
, wxT("Failed to create static ctrl"));
95 vColour
.Set(wxString("BLACK"));
97 LONG lColor
= (LONG
)vColour
.GetPixel();
99 ::WinSetPresParam( m_hWnd
104 lColor
= (LONG
)m_backgroundColour
.GetPixel();
106 ::WinSetPresParam( m_hWnd
113 wxControl::SetFont(*wxSMALL_FONT
);
120 } // end of wxStaticText::Create
122 wxSize
wxStaticText::DoGetBestSize() const
124 wxString
sText(wxGetWindowText(GetHWND()));
125 int nWidthTextMax
= 0;
127 int nHeightTextTotal
= 0;
128 int nHeightLineDefault
= 0;
132 for (const wxChar
*pc
= sText
; ; pc
++)
134 if ( *pc
== wxT('\n') || *pc
== wxT('\0') )
139 // We can't use GetTextExtent - it will return 0 for both width
140 // and height and an empty line should count in height
143 if (!nHeightLineDefault
)
144 nHeightLineDefault
= nHeightLine
;
145 if (!nHeightLineDefault
)
146 GetTextExtent(_T("W"), NULL
, &nHeightLineDefault
);
147 nHeightTextTotal
+= nHeightLineDefault
;
151 GetTextExtent( sCurLine
155 if (nWidthLine
> nWidthTextMax
)
156 nWidthTextMax
= nWidthLine
;
157 nHeightTextTotal
+= nHeightLine
;
160 if ( *pc
== wxT('\n') )
174 return wxSize( nWidthTextMax
177 } // end of wxStaticText::DoGetBestSize
179 void wxStaticText::DoSetSize(
188 // We need to refresh the window after changing its size as the standard
189 // control doesn't always update itself properly.
191 wxStaticTextBase::DoSetSize( nX
198 } // end of wxStaticText::DoSetSize
200 bool wxStaticText::SetFont(
204 bool bRet
= wxControl::SetFont(rFont
);
207 // Adjust the size of the window to fit to the label unless autoresizing is
210 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
212 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
215 } // end of wxStaticText::SetFont
217 void wxStaticText::SetLabel(
218 const wxString
& rsLabel
221 ::WinSetWindowText(GetHwnd(), rsLabel
.c_str());
224 // Adjust the size of the window to fit to the label unless autoresizing is
227 if (!(GetWindowStyle() & wxST_NO_AUTORESIZE
))
229 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
231 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
232 } // end of wxStaticText::SetLabel
234 MRESULT
wxStaticText::OS2WindowProc(
240 return wxWindow::OS2WindowProc( uMsg
244 } // end of wxStaticText::OS2WindowProc