]>
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"));
84 wxControl::SetFont(pParent
->GetFont());
85 SetSize(nX
, nY
, nWidth
, nHeight
);
87 } // end of wxStaticText::Create
89 wxSize
wxStaticText::DoGetBestSize() const
91 wxString
sText(wxGetWindowText(GetHWND()));
92 int nWidthTextMax
= 0;
94 int nHeightTextTotal
= 0;
95 int nHeightLineDefault
= 0;
99 for ( const wxChar
*pc
= sText
; ; pc
++ )
101 if ( *pc
== wxT('\n') || *pc
== wxT('\0') )
106 // We can't use GetTextExtent - it will return 0 for both width
107 // and height and an empty line should count in height
110 if (!nHeightLineDefault
)
111 nHeightLineDefault
= nHeightLine
;
112 if (!nHeightLineDefault
)
113 GetTextExtent(_T("W"), NULL
, &nHeightLineDefault
);
114 nHeightTextTotal
+= nHeightLineDefault
;
118 GetTextExtent( sCurLine
122 if (nWidthLine
> nWidthTextMax
)
123 nWidthTextMax
= nWidthLine
;
124 nHeightTextTotal
+= nHeightLine
;
127 if ( *pc
== wxT('\n') )
141 return wxSize( nWidthTextMax
144 } // end of wxStaticText::DoGetBestSize
146 void wxStaticText::SetLabel(
147 const wxString
& rsLabel
150 ::WinSetWindowText(GetHwnd(), rsLabel
.c_str());
153 // Adjust the size of the window to fit to the label unless autoresizing is
156 if (!(GetWindowStyle() & wxST_NO_AUTORESIZE
))
158 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
160 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
161 } // end of wxStaticText::SetLabel
163 bool wxStaticText::SetFont(
167 bool bRet
= wxControl::SetFont(rFont
);
170 // Adjust the size of the window to fit to the label unless autoresizing is
173 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE
) )
175 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
| wxSIZE_AUTO_HEIGHT
);
178 } // end of wxStaticText::SetFont
180 MRESULT
wxStaticText::OS2WindowProc(
186 return wxWindow::OS2WindowProc( uMsg
190 } // end of wxStaticText::OS2WindowProc