]>
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 /////////////////////////////////////////////////////////////////////////////
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(
31 , const wxString
& rsLabel
35 , const wxString
& rsName
40 pParent
->AddChild(this);
42 SetBackgroundColour(pParent
->GetBackgroundColour()) ;
43 SetForegroundColour(pParent
->GetForegroundColour()) ;
46 m_windowId
= (int)NewControlId();
53 int nHeight
= rSize
.y
;
55 m_windowStyle
= lStyle
;
59 // Used to have DT_VCENTER but that doesn't work correctly with
60 // multiline strings and DT_WORDBREAK. Accept a reasonable
62 lSstyle
= WS_VISIBLE
| SS_TEXT
| DT_WORDBREAK
| DT_MNEMONIC
;
63 if (m_windowStyle
& wxALIGN_CENTRE
)
65 else if (m_windowStyle
& wxALIGN_RIGHT
)
70 wxString sLabel
= ::wxPMTextToLabel(rsLabel
);
72 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
73 ,WC_STATIC
// Window class
74 ,(PSZ
)sLabel
.c_str() // Initial Text
75 ,(ULONG
)lSstyle
// Style flags
76 ,0L, 0L, 0L, 0L // Origin -- 0 size
77 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
78 ,HWND_TOP
// initial z position
79 ,(ULONG
)m_windowId
// Window identifier
80 ,NULL
// no control data
81 ,NULL
// no Presentation parameters
84 wxCHECK_MSG(m_hWnd
, FALSE
, wxT("Failed to create static ctrl"));
88 vColour
.Set(wxString(wxT("BLACK")));
90 LONG lColor
= (LONG
)vColour
.GetPixel();
92 ::WinSetPresParam( m_hWnd
97 lColor
= (LONG
)m_backgroundColour
.GetPixel();
99 ::WinSetPresParam( m_hWnd
106 SetFont(*wxSMALL_FONT
);
115 } // end of wxStaticText::Create
117 wxSize
wxStaticText::DoGetBestSize() const
119 wxString
sText(wxGetWindowText(GetHWND()));
120 int nWidthTextMax
= 0;
122 int nHeightTextTotal
= 0;
123 int nHeightLineDefault
= 0;
126 bool bLastWasTilde
= FALSE
;
128 for (const wxChar
*pc
= sText
; ; pc
++)
130 if ( *pc
== wxT('\n') || *pc
== wxT('\0') )
135 // We can't use GetTextExtent - it will return 0 for both width
136 // and height and an empty line should count in height
139 if (!nHeightLineDefault
)
140 nHeightLineDefault
= nHeightLine
;
141 if (!nHeightLineDefault
)
142 GetTextExtent(_T("W"), NULL
, &nHeightLineDefault
);
143 nHeightTextTotal
+= nHeightLineDefault
;
147 GetTextExtent( sCurLine
151 if (nWidthLine
> nWidthTextMax
)
152 nWidthTextMax
= nWidthLine
;
153 nHeightTextTotal
+= nHeightLine
;
156 if ( *pc
== wxT('\n') )
168 // We shouldn't take into account the '~' which just introduces the
169 // mnemonic characters and so are not shown on the screen -- except
170 // when it is preceded by another '~' in which case it stands for a
177 bLastWasTilde
= TRUE
;
180 // Skip the statement adding pc to curLine below
186 // It is a literal tilde
188 bLastWasTilde
= FALSE
;
193 return wxSize( nWidthTextMax
196 } // end of wxStaticText::DoGetBestSize
198 void wxStaticText::DoSetSize(
207 // We need to refresh the window after changing its size as the standard
208 // control doesn't always update itself properly.
210 wxStaticTextBase::DoSetSize( nX
217 } // end of wxStaticText::DoSetSize
219 bool wxStaticText::SetFont(
223 bool bRet
= wxControl::SetFont(rFont
);
226 // Adjust the size of the window to fit to the label unless autoresizing is
229 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
231 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
234 } // end of wxStaticText::SetFont
236 void wxStaticText::SetLabel(
237 const wxString
& rsLabel
240 wxString sLabel
= ::wxPMTextToLabel(rsLabel
);
241 ::WinSetWindowText(GetHwnd(), (PSZ
)sLabel
.c_str());
244 // Adjust the size of the window to fit to the label unless autoresizing is
247 if (!(GetWindowStyle() & wxST_NO_AUTORESIZE
))
254 GetPosition(&vX
, &vY
);
255 GetSize(&vWidth
, &vHeight
);
256 if (!(vX
== -1 && vY
== -1 && vWidth
== -1 && vHeight
== -1))
257 DoSetSize(vX
, vY
, vWidth
, vHeight
, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
259 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
261 } // end of wxStaticText::SetLabel
263 MRESULT
wxStaticText::OS2WindowProc(
269 return wxWindow::OS2WindowProc( uMsg
273 } // end of wxStaticText::OS2WindowProc