]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/stattext.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/stattext.cpp
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"
19 #include "wx/scrolwin.h"
22 #include "wx/stattext.h"
23 #include "wx/os2/private.h"
26 IMPLEMENT_DYNAMIC_CLASS(wxStaticText
, wxControl
)
28 bool wxStaticText::Create( wxWindow
* pParent
,
30 const wxString
& rsLabel
,
34 const wxString
& rsName
)
38 pParent
->AddChild(this);
40 SetBackgroundColour(pParent
->GetBackgroundColour()) ;
41 SetForegroundColour(pParent
->GetForegroundColour()) ;
43 if ( vId
== wxID_ANY
)
44 m_windowId
= (int)NewControlId();
51 int nHeight
= rSize
.y
;
53 m_windowStyle
= lStyle
;
57 // Used to have DT_VCENTER but that doesn't work correctly with
58 // multiline strings and DT_WORDBREAK. Accept a reasonable
60 lSstyle
= WS_VISIBLE
| SS_TEXT
| DT_WORDBREAK
| DT_MNEMONIC
;
61 if (m_windowStyle
& wxALIGN_CENTRE
)
63 else if (m_windowStyle
& wxALIGN_RIGHT
)
68 wxString sLabel
= ::wxPMTextToLabel(rsLabel
);
70 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
71 ,WC_STATIC
// Window class
72 ,(PSZ
)sLabel
.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"));
84 LONG lColor
= (LONG
)wxBLACK
->GetPixel();
86 ::WinSetPresParam( m_hWnd
91 lColor
= (LONG
)m_backgroundColour
.GetPixel();
93 ::WinSetPresParam( m_hWnd
100 SetFont(*wxSMALL_FONT
);
103 SetSize( nX
, nY
, nWidth
, nHeight
);
106 } // end of wxStaticText::Create
108 wxSize
wxStaticText::DoGetBestSize() const
110 wxString
sText(wxGetWindowText(GetHWND()));
111 int nWidthTextMax
= 0;
113 int nHeightTextTotal
= 0;
114 int nHeightLineDefault
= 0;
117 bool bLastWasTilde
= false;
119 for (const wxChar
*pc
= sText
; ; pc
++)
121 if ( *pc
== wxT('\n') || *pc
== wxT('\0') )
126 // We can't use GetTextExtent - it will return 0 for both width
127 // and height and an empty line should count in height
130 if (!nHeightLineDefault
)
131 nHeightLineDefault
= nHeightLine
;
132 if (!nHeightLineDefault
)
133 GetTextExtent(_T("W"), NULL
, &nHeightLineDefault
);
134 nHeightTextTotal
+= nHeightLineDefault
;
138 GetTextExtent( sCurLine
142 if (nWidthLine
> nWidthTextMax
)
143 nWidthTextMax
= nWidthLine
;
144 nHeightTextTotal
+= nHeightLine
;
147 if ( *pc
== wxT('\n') )
159 // We shouldn't take into account the '~' which just introduces the
160 // mnemonic characters and so are not shown on the screen -- except
161 // when it is preceded by another '~' in which case it stands for a
168 bLastWasTilde
= true;
171 // Skip the statement adding pc to curLine below
177 // It is a literal tilde
179 bLastWasTilde
= false;
184 return wxSize( nWidthTextMax
187 } // end of wxStaticText::DoGetBestSize
189 void wxStaticText::DoSetSize(
198 // We need to refresh the window after changing its size as the standard
199 // control doesn't always update itself properly.
201 wxStaticTextBase::DoSetSize( nX
208 } // end of wxStaticText::DoSetSize
210 bool wxStaticText::SetFont(
214 bool bRet
= wxControl::SetFont(rFont
);
217 // Adjust the size of the window to fit to the label unless autoresizing is
220 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
222 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
225 } // end of wxStaticText::SetFont
227 void wxStaticText::SetLabel(
228 const wxString
& rsLabel
231 wxString sLabel
= ::wxPMTextToLabel(rsLabel
);
232 ::WinSetWindowText(GetHwnd(), (PSZ
)sLabel
.c_str());
235 // Adjust the size of the window to fit to the label unless autoresizing is
238 if (!(GetWindowStyle() & wxST_NO_AUTORESIZE
))
245 GetPosition(&vX
, &vY
);
246 GetSize(&vWidth
, &vHeight
);
247 if (!(vX
== -1 && vY
== -1 && vWidth
== -1 && vHeight
== -1))
248 DoSetSize(vX
, vY
, vWidth
, vHeight
, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
250 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
252 } // end of wxStaticText::SetLabel
254 MRESULT
wxStaticText::OS2WindowProc(
260 return wxWindow::OS2WindowProc( uMsg
264 } // end of wxStaticText::OS2WindowProc