]>
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"
25 #include "wx/stattext.h"
26 #include "wx/os2/private.h"
29 IMPLEMENT_DYNAMIC_CLASS(wxStaticText
, wxControl
)
31 bool wxStaticText::Create(
34 , const wxString
& rsLabel
38 , const wxString
& rsName
43 pParent
->AddChild(this);
45 SetBackgroundColour(pParent
->GetBackgroundColour()) ;
46 SetForegroundColour(pParent
->GetForegroundColour()) ;
49 m_windowId
= (int)NewControlId();
56 int nHeight
= rSize
.y
;
58 m_windowStyle
= lStyle
;
62 lSstyle
= WS_VISIBLE
| SS_TEXT
| DT_VCENTER
;
63 if (m_windowStyle
& wxALIGN_CENTRE
)
65 else if (m_windowStyle
& wxALIGN_RIGHT
)
69 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
70 ,WC_STATIC
// Window class
71 ,(PSZ
)rsLabel
.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("BLACK"));
87 LONG lColor
= (LONG
)vColour
.GetPixel();
89 ::WinSetPresParam( m_hWnd
96 wxControl::SetFont(pParent
->GetFont());
103 } // end of wxStaticText::Create
105 wxSize
wxStaticText::DoGetBestSize() const
107 wxString
sText(wxGetWindowText(GetHWND()));
108 int nWidthTextMax
= 0;
110 int nHeightTextTotal
= 0;
111 int nHeightLineDefault
= 0;
115 for (const wxChar
*pc
= sText
; ; pc
++)
117 if ( *pc
== wxT('\n') || *pc
== wxT('\0') )
122 // We can't use GetTextExtent - it will return 0 for both width
123 // and height and an empty line should count in height
126 if (!nHeightLineDefault
)
127 nHeightLineDefault
= nHeightLine
;
128 if (!nHeightLineDefault
)
129 GetTextExtent(_T("W"), NULL
, &nHeightLineDefault
);
130 nHeightTextTotal
+= nHeightLineDefault
;
134 GetTextExtent( sCurLine
138 if (nWidthLine
> nWidthTextMax
)
139 nWidthTextMax
= nWidthLine
;
140 nHeightTextTotal
+= nHeightLine
;
143 if ( *pc
== wxT('\n') )
157 return wxSize( nWidthTextMax
160 } // end of wxStaticText::DoGetBestSize
162 bool wxStaticText::SetFont(
166 bool bRet
= wxControl::SetFont(rFont
);
169 // Adjust the size of the window to fit to the label unless autoresizing is
172 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
174 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
177 } // end of wxStaticText::SetFont
179 void wxStaticText::SetLabel(
180 const wxString
& rsLabel
183 ::WinSetWindowText(GetHwnd(), rsLabel
.c_str());
186 // Adjust the size of the window to fit to the label unless autoresizing is
189 if (!(GetWindowStyle() & wxST_NO_AUTORESIZE
))
191 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
193 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
194 } // end of wxStaticText::SetLabel
196 MRESULT
wxStaticText::OS2WindowProc(
202 return wxWindow::OS2WindowProc( uMsg
206 } // end of wxStaticText::OS2WindowProc