]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/stattext.cpp
fbeefc707fe1a3ab8f959c3dd274c5ee962b49ec
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(
34 , const wxString
& rsLabel
38 , const wxString
& rsName
43 pParent
->AddChild(this);
45 SetBackgroundColour(pParent
->GetBackgroundColour()) ;
46 SetForegroundColour(pParent
->GetForegroundColour()) ;
49 m_windowId
= (int)NewControlId();
56 int nHeight
= rSize
.y
;
58 m_windowStyle
= lStyle
;
62 lSstyle
= WS_VISIBLE
| SS_TEXT
| DT_VCENTER
;
63 if (m_windowStyle
& wxALIGN_CENTRE
)
65 else if (m_windowStyle
& wxALIGN_RIGHT
)
69 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
70 ,WC_STATIC
// Window class
71 ,(PSZ
)rsLabel
.c_str() // Initial Text
72 ,(ULONG
)lSstyle
// Style flags
73 ,0L, 0L, 0L, 0L // Origin -- 0 size
74 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
75 ,HWND_TOP
// initial z position
76 ,(ULONG
)m_windowId
// Window identifier
77 ,NULL
// no control data
78 ,NULL
// no Presentation parameters
81 wxCHECK_MSG(m_hWnd
, FALSE
, wxT("Failed to create static ctrl"));
85 vColour
.Set(wxString("BLACK"));
87 LONG lColor
= (LONG
)vColour
.GetPixel();
89 ::WinSetPresParam( m_hWnd
94 lColor
= (LONG
)m_backgroundColour
.GetPixel();
96 ::WinSetPresParam( m_hWnd
103 wxControl::SetFont(pParent
->GetFont());
110 } // end of wxStaticText::Create
112 wxSize
wxStaticText::DoGetBestSize() const
114 wxString
sText(wxGetWindowText(GetHWND()));
115 int nWidthTextMax
= 0;
117 int nHeightTextTotal
= 0;
118 int nHeightLineDefault
= 0;
122 for (const wxChar
*pc
= sText
; ; pc
++)
124 if ( *pc
== wxT('\n') || *pc
== wxT('\0') )
129 // We can't use GetTextExtent - it will return 0 for both width
130 // and height and an empty line should count in height
133 if (!nHeightLineDefault
)
134 nHeightLineDefault
= nHeightLine
;
135 if (!nHeightLineDefault
)
136 GetTextExtent(_T("W"), NULL
, &nHeightLineDefault
);
137 nHeightTextTotal
+= nHeightLineDefault
;
141 GetTextExtent( sCurLine
145 if (nWidthLine
> nWidthTextMax
)
146 nWidthTextMax
= nWidthLine
;
147 nHeightTextTotal
+= nHeightLine
;
150 if ( *pc
== wxT('\n') )
164 return wxSize( nWidthTextMax
167 } // end of wxStaticText::DoGetBestSize
169 void wxStaticText::DoSetSize(
178 // We need to refresh the window after changing its size as the standard
179 // control doesn't always update itself properly.
181 wxStaticTextBase::DoSetSize( nX
188 } // end of wxStaticText::DoSetSize
190 bool wxStaticText::SetFont(
194 bool bRet
= wxControl::SetFont(rFont
);
197 // Adjust the size of the window to fit to the label unless autoresizing is
200 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
202 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
205 } // end of wxStaticText::SetFont
207 void wxStaticText::SetLabel(
208 const wxString
& rsLabel
211 ::WinSetWindowText(GetHwnd(), rsLabel
.c_str());
214 // Adjust the size of the window to fit to the label unless autoresizing is
217 if (!(GetWindowStyle() & wxST_NO_AUTORESIZE
))
219 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
221 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
222 } // end of wxStaticText::SetLabel
224 MRESULT
wxStaticText::OS2WindowProc(
230 return wxWindow::OS2WindowProc( uMsg
234 } // end of wxStaticText::OS2WindowProc