]>
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
)
70 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
71 ,WC_STATIC
// Window class
72 ,(PSZ
)rsLabel
.c_str() // Initial Text
73 ,(ULONG
)lSstyle
// Style flags
74 ,0L, 0L, 0L, 0L // Origin -- 0 size
75 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
76 ,HWND_TOP
// initial z position
77 ,(ULONG
)m_windowId
// Window identifier
78 ,NULL
// no control data
79 ,NULL
// no Presentation parameters
82 wxCHECK_MSG(m_hWnd
, FALSE
, wxT("Failed to create static ctrl"));
86 vColour
.Set(wxString("BLACK"));
88 LONG lColor
= (LONG
)vColour
.GetPixel();
90 ::WinSetPresParam( m_hWnd
95 lColor
= (LONG
)m_backgroundColour
.GetPixel();
97 ::WinSetPresParam( m_hWnd
104 SetFont(*wxSMALL_FONT
);
113 } // end of wxStaticText::Create
115 wxSize
wxStaticText::DoGetBestSize() const
117 wxString
sText(wxGetWindowText(GetHWND()));
118 int nWidthTextMax
= 0;
120 int nHeightTextTotal
= 0;
121 int nHeightLineDefault
= 0;
125 for (const wxChar
*pc
= sText
; ; pc
++)
127 if ( *pc
== wxT('\n') || *pc
== wxT('\0') )
132 // We can't use GetTextExtent - it will return 0 for both width
133 // and height and an empty line should count in height
136 if (!nHeightLineDefault
)
137 nHeightLineDefault
= nHeightLine
;
138 if (!nHeightLineDefault
)
139 GetTextExtent(_T("W"), NULL
, &nHeightLineDefault
);
140 nHeightTextTotal
+= nHeightLineDefault
;
144 GetTextExtent( sCurLine
148 if (nWidthLine
> nWidthTextMax
)
149 nWidthTextMax
= nWidthLine
;
150 nHeightTextTotal
+= nHeightLine
;
153 if ( *pc
== wxT('\n') )
167 return wxSize( nWidthTextMax
170 } // end of wxStaticText::DoGetBestSize
172 void wxStaticText::DoSetSize(
181 // We need to refresh the window after changing its size as the standard
182 // control doesn't always update itself properly.
184 wxStaticTextBase::DoSetSize( nX
191 } // end of wxStaticText::DoSetSize
193 bool wxStaticText::SetFont(
197 bool bRet
= wxControl::SetFont(rFont
);
200 // Adjust the size of the window to fit to the label unless autoresizing is
203 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
205 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
208 } // end of wxStaticText::SetFont
210 void wxStaticText::SetLabel(
211 const wxString
& rsLabel
214 ::WinSetWindowText(GetHwnd(), rsLabel
.c_str());
217 // Adjust the size of the window to fit to the label unless autoresizing is
220 if (!(GetWindowStyle() & wxST_NO_AUTORESIZE
))
227 GetPosition(&vX
, &vY
);
228 GetSize(&vWidth
, &vHeight
);
229 if (!(vX
== -1 && vY
== -1 && vWidth
== -1 && vHeight
== -1))
230 DoSetSize(vX
, vY
, vWidth
, vHeight
, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
232 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
234 } // end of wxStaticText::SetLabel
236 MRESULT
wxStaticText::OS2WindowProc(
242 return wxWindow::OS2WindowProc( uMsg
246 } // end of wxStaticText::OS2WindowProc