]>
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 lSstyle
= WS_VISIBLE
| SS_TEXT
| DT_VCENTER
| DT_MNEMONIC
;
60 if (m_windowStyle
& wxALIGN_CENTRE
)
62 else if (m_windowStyle
& wxALIGN_RIGHT
)
67 wxString sLabel
= ::wxPMTextToLabel(rsLabel
);
69 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
70 ,WC_STATIC
// Window class
71 ,(PSZ
)sLabel
.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(wxT("BLACK")));
87 LONG lColor
= (LONG
)vColour
.GetPixel();
89 ::WinSetPresParam( m_hWnd
94 lColor
= (LONG
)m_backgroundColour
.GetPixel();
96 ::WinSetPresParam( m_hWnd
103 SetFont(*wxSMALL_FONT
);
112 } // end of wxStaticText::Create
114 wxSize
wxStaticText::DoGetBestSize() const
116 wxString
sText(wxGetWindowText(GetHWND()));
117 int nWidthTextMax
= 0;
119 int nHeightTextTotal
= 0;
120 int nHeightLineDefault
= 0;
123 bool bLastWasTilde
= FALSE
;
125 for (const wxChar
*pc
= sText
; ; pc
++)
127 if ( *pc
== wxT('\n') || *pc
== wxT('\0') )
132 // We can't use GetTextExtent - it will return 0 for both width
133 // and height and an empty line should count in height
136 if (!nHeightLineDefault
)
137 nHeightLineDefault
= nHeightLine
;
138 if (!nHeightLineDefault
)
139 GetTextExtent(_T("W"), NULL
, &nHeightLineDefault
);
140 nHeightTextTotal
+= nHeightLineDefault
;
144 GetTextExtent( sCurLine
148 if (nWidthLine
> nWidthTextMax
)
149 nWidthTextMax
= nWidthLine
;
150 nHeightTextTotal
+= nHeightLine
;
153 if ( *pc
== wxT('\n') )
165 // We shouldn't take into account the '~' which just introduces the
166 // mnemonic characters and so are not shown on the screen -- except
167 // when it is preceded by another '~' in which case it stands for a
174 bLastWasTilde
= TRUE
;
177 // Skip the statement adding pc to curLine below
183 // It is a literal tilde
185 bLastWasTilde
= FALSE
;
190 return wxSize( nWidthTextMax
193 } // end of wxStaticText::DoGetBestSize
195 void wxStaticText::DoSetSize(
204 // We need to refresh the window after changing its size as the standard
205 // control doesn't always update itself properly.
207 wxStaticTextBase::DoSetSize( nX
214 } // end of wxStaticText::DoSetSize
216 bool wxStaticText::SetFont(
220 bool bRet
= wxControl::SetFont(rFont
);
223 // Adjust the size of the window to fit to the label unless autoresizing is
226 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
228 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
231 } // end of wxStaticText::SetFont
233 void wxStaticText::SetLabel(
234 const wxString
& rsLabel
237 wxString sLabel
= ::wxPMTextToLabel(rsLabel
);
238 ::WinSetWindowText(GetHwnd(), (PSZ
)sLabel
.c_str());
241 // Adjust the size of the window to fit to the label unless autoresizing is
244 if (!(GetWindowStyle() & wxST_NO_AUTORESIZE
))
251 GetPosition(&vX
, &vY
);
252 GetSize(&vWidth
, &vHeight
);
253 if (!(vX
== -1 && vY
== -1 && vWidth
== -1 && vHeight
== -1))
254 DoSetSize(vX
, vY
, vWidth
, vHeight
, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
256 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
258 } // end of wxStaticText::SetLabel
260 MRESULT
wxStaticText::OS2WindowProc(
266 return wxWindow::OS2WindowProc( uMsg
270 } // end of wxStaticText::OS2WindowProc