]>
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
| DT_MNEMONIC
;
64 if (m_windowStyle
& wxALIGN_CENTRE
)
66 else if (m_windowStyle
& wxALIGN_RIGHT
)
71 wxString sLabel
= ::wxPMTextToLabel(rsLabel
);
73 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
74 ,WC_STATIC
// Window class
75 ,(PSZ
)sLabel
.c_str() // Initial Text
76 ,(ULONG
)lSstyle
// Style flags
77 ,0L, 0L, 0L, 0L // Origin -- 0 size
78 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
79 ,HWND_TOP
// initial z position
80 ,(ULONG
)m_windowId
// Window identifier
81 ,NULL
// no control data
82 ,NULL
// no Presentation parameters
85 wxCHECK_MSG(m_hWnd
, FALSE
, wxT("Failed to create static ctrl"));
89 vColour
.Set(wxString(wxT("BLACK")));
91 LONG lColor
= (LONG
)vColour
.GetPixel();
93 ::WinSetPresParam( m_hWnd
98 lColor
= (LONG
)m_backgroundColour
.GetPixel();
100 ::WinSetPresParam( m_hWnd
107 SetFont(*wxSMALL_FONT
);
116 } // end of wxStaticText::Create
118 wxSize
wxStaticText::DoGetBestSize() const
120 wxString
sText(wxGetWindowText(GetHWND()));
121 int nWidthTextMax
= 0;
123 int nHeightTextTotal
= 0;
124 int nHeightLineDefault
= 0;
127 bool bLastWasTilde
= FALSE
;
129 for (const wxChar
*pc
= sText
; ; pc
++)
131 if ( *pc
== wxT('\n') || *pc
== wxT('\0') )
136 // We can't use GetTextExtent - it will return 0 for both width
137 // and height and an empty line should count in height
140 if (!nHeightLineDefault
)
141 nHeightLineDefault
= nHeightLine
;
142 if (!nHeightLineDefault
)
143 GetTextExtent(_T("W"), NULL
, &nHeightLineDefault
);
144 nHeightTextTotal
+= nHeightLineDefault
;
148 GetTextExtent( sCurLine
152 if (nWidthLine
> nWidthTextMax
)
153 nWidthTextMax
= nWidthLine
;
154 nHeightTextTotal
+= nHeightLine
;
157 if ( *pc
== wxT('\n') )
169 // We shouldn't take into account the '~' which just introduces the
170 // mnemonic characters and so are not shown on the screen -- except
171 // when it is preceded by another '~' in which case it stands for a
178 bLastWasTilde
= TRUE
;
181 // Skip the statement adding pc to curLine below
187 // It is a literal tilde
189 bLastWasTilde
= FALSE
;
194 return wxSize( nWidthTextMax
197 } // end of wxStaticText::DoGetBestSize
199 void wxStaticText::DoSetSize(
208 // We need to refresh the window after changing its size as the standard
209 // control doesn't always update itself properly.
211 wxStaticTextBase::DoSetSize( nX
218 } // end of wxStaticText::DoSetSize
220 bool wxStaticText::SetFont(
224 bool bRet
= wxControl::SetFont(rFont
);
227 // Adjust the size of the window to fit to the label unless autoresizing is
230 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
232 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
235 } // end of wxStaticText::SetFont
237 void wxStaticText::SetLabel(
238 const wxString
& rsLabel
241 wxString sLabel
= ::wxPMTextToLabel(rsLabel
);
242 ::WinSetWindowText(GetHwnd(), (PSZ
)sLabel
.c_str());
245 // Adjust the size of the window to fit to the label unless autoresizing is
248 if (!(GetWindowStyle() & wxST_NO_AUTORESIZE
))
255 GetPosition(&vX
, &vY
);
256 GetSize(&vWidth
, &vHeight
);
257 if (!(vX
== -1 && vY
== -1 && vWidth
== -1 && vHeight
== -1))
258 DoSetSize(vX
, vY
, vWidth
, vHeight
, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
260 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
262 } // end of wxStaticText::SetLabel
264 MRESULT
wxStaticText::OS2WindowProc(
270 return wxWindow::OS2WindowProc( uMsg
274 } // end of wxStaticText::OS2WindowProc