]>
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 wxFont
* pTextFont
= new wxFont( 10
109 wxControl::SetFont(*pTextFont
);
117 } // end of wxStaticText::Create
119 wxSize
wxStaticText::DoGetBestSize() const
121 wxString
sText(wxGetWindowText(GetHWND()));
122 int nWidthTextMax
= 0;
124 int nHeightTextTotal
= 0;
125 int nHeightLineDefault
= 0;
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') )
171 return wxSize( nWidthTextMax
174 } // end of wxStaticText::DoGetBestSize
176 void wxStaticText::DoSetSize(
185 // We need to refresh the window after changing its size as the standard
186 // control doesn't always update itself properly.
188 wxStaticTextBase::DoSetSize( nX
195 } // end of wxStaticText::DoSetSize
197 bool wxStaticText::SetFont(
201 bool bRet
= wxControl::SetFont(rFont
);
204 // Adjust the size of the window to fit to the label unless autoresizing is
207 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
209 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
212 } // end of wxStaticText::SetFont
214 void wxStaticText::SetLabel(
215 const wxString
& rsLabel
218 ::WinSetWindowText(GetHwnd(), rsLabel
.c_str());
221 // Adjust the size of the window to fit to the label unless autoresizing is
224 if (!(GetWindowStyle() & wxST_NO_AUTORESIZE
))
226 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
228 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
229 } // end of wxStaticText::SetLabel
231 MRESULT
wxStaticText::OS2WindowProc(
237 return wxWindow::OS2WindowProc( uMsg
241 } // end of wxStaticText::OS2WindowProc