]>
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
7 // Copyright: (c) David Webster
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
14 #include "wx/stattext.h"
20 #include "wx/scrolwin.h"
23 #include "wx/os2/private.h"
26 bool wxStaticText::Create( wxWindow
* pParent
,
28 const wxString
& rsLabel
,
32 const wxString
& rsName
)
36 pParent
->AddChild(this);
38 SetBackgroundColour(pParent
->GetBackgroundColour()) ;
39 SetForegroundColour(pParent
->GetForegroundColour()) ;
41 if ( vId
== wxID_ANY
)
42 m_windowId
= (int)NewControlId();
49 int nHeight
= rSize
.y
;
51 m_windowStyle
= lStyle
;
55 // Used to have DT_VCENTER but that doesn't work correctly with
56 // multiline strings and DT_WORDBREAK. Accept a reasonable
58 lSstyle
= WS_VISIBLE
| SS_TEXT
| DT_WORDBREAK
| DT_MNEMONIC
;
59 if (m_windowStyle
& wxALIGN_CENTRE
)
61 else if (m_windowStyle
& wxALIGN_RIGHT
)
66 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
67 ,WC_STATIC
// Window class
69 ,(ULONG
)lSstyle
// Style flags
70 ,0L, 0L, 0L, 0L // Origin -- 0 size
71 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
72 ,HWND_TOP
// initial z position
73 ,(ULONG
)m_windowId
// Window identifier
74 ,NULL
// no control data
75 ,NULL
// no Presentation parameters
78 wxCHECK_MSG(m_hWnd
, false, wxT("Failed to create static ctrl"));
80 LONG lColor
= (LONG
)wxBLACK
->GetPixel();
82 ::WinSetPresParam( m_hWnd
87 lColor
= (LONG
)m_backgroundColour
.GetPixel();
89 ::WinSetPresParam( m_hWnd
96 SetFont(*wxSMALL_FONT
);
99 SetSize( nX
, nY
, nWidth
, nHeight
);
104 } // end of wxStaticText::Create
106 wxSize
wxStaticText::DoGetBestSize() const
108 wxString
sText(GetLabel());
109 int nWidthTextMax
= 0;
111 int nHeightTextTotal
= 0;
112 int nHeightLineDefault
= 0;
115 bool bLastWasTilde
= false;
117 for (const wxChar
*pc
= sText
; ; pc
++)
119 if ( *pc
== wxT('\n') || *pc
== wxT('\0') )
124 // We can't use GetTextExtent - it will return 0 for both width
125 // and height and an empty line should count in height
128 if (!nHeightLineDefault
)
129 nHeightLineDefault
= nHeightLine
;
130 if (!nHeightLineDefault
)
131 GetTextExtent(wxT("W"), NULL
, &nHeightLineDefault
);
132 nHeightTextTotal
+= nHeightLineDefault
;
136 GetTextExtent( sCurLine
140 if (nWidthLine
> nWidthTextMax
)
141 nWidthTextMax
= nWidthLine
;
142 nHeightTextTotal
+= nHeightLine
;
145 if ( *pc
== wxT('\n') )
157 // We shouldn't take into account the '~' which just introduces the
158 // mnemonic characters and so are not shown on the screen -- except
159 // when it is preceded by another '~' in which case it stands for a
166 bLastWasTilde
= true;
169 // Skip the statement adding pc to curLine below
175 // It is a literal tilde
177 bLastWasTilde
= false;
182 return wxSize( nWidthTextMax
185 } // end of wxStaticText::DoGetBestSize
187 void wxStaticText::DoSetSize(
196 // We need to refresh the window after changing its size as the standard
197 // control doesn't always update itself properly.
199 wxStaticTextBase::DoSetSize( nX
206 // eventually update label (if ellipsizing is on):
210 } // end of wxStaticText::DoSetSize
212 bool wxStaticText::SetFont(
216 bool bRet
= wxControl::SetFont(rFont
);
219 // Adjust the size of the window to fit to the label unless autoresizing is
222 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
224 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
227 } // end of wxStaticText::SetFont
229 void wxStaticText::SetLabel(
230 const wxString
& rsLabel
233 m_labelOrig
= rsLabel
; // save original label
235 // OS/2 does not support ellipsized labels in static text:
236 DoSetLabel(GetEllipsizedLabel());
239 // Adjust the size of the window to fit to the label unless autoresizing is
242 if (!(GetWindowStyle() & wxST_NO_AUTORESIZE
) &&
250 GetPosition(&vX
, &vY
);
251 GetSize(&vWidth
, &vHeight
);
252 if (!(vX
== -1 && vY
== -1 && vWidth
== -1 && vHeight
== -1))
253 DoSetSize(vX
, vY
, vWidth
, vHeight
, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
255 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
257 } // end of wxStaticText::SetLabel
259 MRESULT
wxStaticText::OS2WindowProc(
265 return wxWindow::OS2WindowProc( uMsg
269 } // end of wxStaticText::OS2WindowProc
272 // for wxST_ELLIPSIZE_* support:
274 void wxStaticText::DoSetLabel(const wxString
& str
)
276 wxString sLabel
= ::wxPMTextToLabel(str
);
277 ::WinSetWindowText(GetHwnd(), sLabel
.c_str());
280 wxString
wxStaticText::DoGetLabel() const
282 return wxGetWindowText(GetHwnd());