]>
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"
15 #include "wx/stattext.h"
21 #include "wx/scrolwin.h"
24 #include "wx/os2/private.h"
27 bool wxStaticText::Create( wxWindow
* pParent
,
29 const wxString
& rsLabel
,
33 const wxString
& rsName
)
37 pParent
->AddChild(this);
39 SetBackgroundColour(pParent
->GetBackgroundColour()) ;
40 SetForegroundColour(pParent
->GetForegroundColour()) ;
42 if ( vId
== wxID_ANY
)
43 m_windowId
= (int)NewControlId();
50 int nHeight
= rSize
.y
;
52 m_windowStyle
= lStyle
;
56 // Used to have DT_VCENTER but that doesn't work correctly with
57 // multiline strings and DT_WORDBREAK. Accept a reasonable
59 lSstyle
= WS_VISIBLE
| SS_TEXT
| DT_WORDBREAK
| DT_MNEMONIC
;
60 if (m_windowStyle
& wxALIGN_CENTRE
)
62 else if (m_windowStyle
& wxALIGN_RIGHT
)
67 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
68 ,WC_STATIC
// Window class
70 ,(ULONG
)lSstyle
// Style flags
71 ,0L, 0L, 0L, 0L // Origin -- 0 size
72 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
73 ,HWND_TOP
// initial z position
74 ,(ULONG
)m_windowId
// Window identifier
75 ,NULL
// no control data
76 ,NULL
// no Presentation parameters
79 wxCHECK_MSG(m_hWnd
, false, wxT("Failed to create static ctrl"));
81 LONG lColor
= (LONG
)wxBLACK
->GetPixel();
83 ::WinSetPresParam( m_hWnd
88 lColor
= (LONG
)m_backgroundColour
.GetPixel();
90 ::WinSetPresParam( m_hWnd
97 SetFont(*wxSMALL_FONT
);
100 SetSize( nX
, nY
, nWidth
, nHeight
);
105 } // end of wxStaticText::Create
107 wxSize
wxStaticText::DoGetBestSize() const
109 wxString
sText(GetLabel());
110 int nWidthTextMax
= 0;
112 int nHeightTextTotal
= 0;
113 int nHeightLineDefault
= 0;
116 bool bLastWasTilde
= false;
118 for (const wxChar
*pc
= sText
; ; pc
++)
120 if ( *pc
== wxT('\n') || *pc
== wxT('\0') )
125 // We can't use GetTextExtent - it will return 0 for both width
126 // and height and an empty line should count in height
129 if (!nHeightLineDefault
)
130 nHeightLineDefault
= nHeightLine
;
131 if (!nHeightLineDefault
)
132 GetTextExtent(wxT("W"), NULL
, &nHeightLineDefault
);
133 nHeightTextTotal
+= nHeightLineDefault
;
137 GetTextExtent( sCurLine
141 if (nWidthLine
> nWidthTextMax
)
142 nWidthTextMax
= nWidthLine
;
143 nHeightTextTotal
+= nHeightLine
;
146 if ( *pc
== wxT('\n') )
158 // We shouldn't take into account the '~' which just introduces the
159 // mnemonic characters and so are not shown on the screen -- except
160 // when it is preceded by another '~' in which case it stands for a
167 bLastWasTilde
= true;
170 // Skip the statement adding pc to curLine below
176 // It is a literal tilde
178 bLastWasTilde
= false;
183 return wxSize( nWidthTextMax
186 } // end of wxStaticText::DoGetBestSize
188 void wxStaticText::DoSetSize(
197 // We need to refresh the window after changing its size as the standard
198 // control doesn't always update itself properly.
200 wxStaticTextBase::DoSetSize( nX
207 // eventually update label (if ellipsizing is on):
211 } // end of wxStaticText::DoSetSize
213 bool wxStaticText::SetFont(
217 bool bRet
= wxControl::SetFont(rFont
);
220 // Adjust the size of the window to fit to the label unless autoresizing is
223 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
225 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
228 } // end of wxStaticText::SetFont
230 void wxStaticText::SetLabel(
231 const wxString
& rsLabel
234 m_labelOrig
= rsLabel
; // save original label
236 // OS/2 does not support neither ellipsize nor markup in static text:
238 DoSetLabel(GetEllipsizedLabelWithoutMarkup());
241 // Adjust the size of the window to fit to the label unless autoresizing is
244 if (!(GetWindowStyle() & wxST_NO_AUTORESIZE
) &&
252 GetPosition(&vX
, &vY
);
253 GetSize(&vWidth
, &vHeight
);
254 if (!(vX
== -1 && vY
== -1 && vWidth
== -1 && vHeight
== -1))
255 DoSetSize(vX
, vY
, vWidth
, vHeight
, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
257 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
259 } // end of wxStaticText::SetLabel
261 MRESULT
wxStaticText::OS2WindowProc(
267 return wxWindow::OS2WindowProc( uMsg
271 } // end of wxStaticText::OS2WindowProc
274 // for wxST_ELLIPSIZE_* support:
276 void wxStaticText::DoSetLabel(const wxString
& str
)
278 wxString sLabel
= ::wxPMTextToLabel(str
);
279 ::WinSetWindowText(GetHwnd(), sLabel
.c_str());
282 wxString
wxStaticText::DoGetLabel() const
284 return wxGetWindowText(GetHwnd());