]>
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 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "stattext.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #include "wx/scrolwin.h"
26 #include "wx/stattext.h"
27 #include "wx/os2/private.h"
30 IMPLEMENT_DYNAMIC_CLASS(wxStaticText
, wxControl
)
32 bool wxStaticText::Create(
35 , const wxString
& rsLabel
39 , const wxString
& rsName
44 pParent
->AddChild(this);
46 SetBackgroundColour(pParent
->GetBackgroundColour()) ;
47 SetForegroundColour(pParent
->GetForegroundColour()) ;
50 m_windowId
= (int)NewControlId();
57 int nHeight
= rSize
.y
;
59 m_windowStyle
= lStyle
;
63 lSstyle
= WS_VISIBLE
| SS_TEXT
| DT_VCENTER
;
64 if (m_windowStyle
& wxALIGN_CENTRE
)
66 else if (m_windowStyle
& wxALIGN_RIGHT
)
70 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
71 ,WC_STATIC
// Window class
72 ,(PSZ
)rsLabel
.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"));
86 vColour
.Set(wxString("BLACK"));
88 LONG lColor
= (LONG
)vColour
.GetPixel();
90 ::WinSetPresParam( m_hWnd
95 lColor
= (LONG
)m_backgroundColour
.GetPixel();
97 ::WinSetPresParam( m_hWnd
104 SetFont(*wxSMALL_FONT
);
113 } // end of wxStaticText::Create
115 wxSize
wxStaticText::DoGetBestSize() const
117 wxString
sText(wxGetWindowText(GetHWND()));
118 int nWidthTextMax
= 0;
120 int nHeightTextTotal
= 0;
121 int nHeightLineDefault
= 0;
124 bool bLastWasAmpersand
= FALSE
;
126 for (const wxChar
*pc
= sText
; ; pc
++)
128 if ( *pc
== wxT('\n') || *pc
== wxT('\0') )
133 // We can't use GetTextExtent - it will return 0 for both width
134 // and height and an empty line should count in height
137 if (!nHeightLineDefault
)
138 nHeightLineDefault
= nHeightLine
;
139 if (!nHeightLineDefault
)
140 GetTextExtent(_T("W"), NULL
, &nHeightLineDefault
);
141 nHeightTextTotal
+= nHeightLineDefault
;
145 GetTextExtent( sCurLine
149 if (nWidthLine
> nWidthTextMax
)
150 nWidthTextMax
= nWidthLine
;
151 nHeightTextTotal
+= nHeightLine
;
154 if ( *pc
== wxT('\n') )
166 // We shouldn't take into account the '&' which just introduces the
167 // mnemonic characters and so are not shown on the screen -- except
168 // when it is preceded by another '&' in which case it stands for a
173 if (!bLastWasAmpersand
)
175 bLastWasAmpersand
= TRUE
;
178 // Skip the statement adding pc to curLine below
184 // It is a literal ampersand
186 bLastWasAmpersand
= FALSE
;
191 return wxSize( nWidthTextMax
194 } // end of wxStaticText::DoGetBestSize
196 void wxStaticText::DoSetSize(
205 // We need to refresh the window after changing its size as the standard
206 // control doesn't always update itself properly.
208 wxStaticTextBase::DoSetSize( nX
215 } // end of wxStaticText::DoSetSize
217 bool wxStaticText::SetFont(
221 bool bRet
= wxControl::SetFont(rFont
);
224 // Adjust the size of the window to fit to the label unless autoresizing is
227 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
229 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
232 } // end of wxStaticText::SetFont
234 void wxStaticText::SetLabel(
235 const wxString
& rsLabel
238 ::WinSetWindowText(GetHwnd(), rsLabel
.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