]> git.saurik.com Git - wxWidgets.git/blame - src/os2/stattext.cpp
call gtk_toolbar_set_tooltips() from GtkSetStyle(); removed erroneous wxTB_TOOLTIPS
[wxWidgets.git] / src / os2 / stattext.cpp
CommitLineData
0e320a79 1/////////////////////////////////////////////////////////////////////////////
d5da0ce7 2// Name: src/os2/stattext.cpp
0e320a79 3// Purpose: wxStaticText
d90895ac 4// Author: David Webster
0e320a79 5// Modified by:
d90895ac 6// Created: 10/17/99
0e320a79 7// RCS-ID: $Id$
d90895ac 8// Copyright: (c) David Webster
65571936 9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
d90895ac
DW
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
0e320a79 14
d90895ac 15#ifndef WX_PRECOMP
d5da0ce7
WS
16 #include "wx/event.h"
17 #include "wx/app.h"
18 #include "wx/brush.h"
19 #include "wx/scrolwin.h"
d90895ac 20#endif
0e320a79 21
d90895ac
DW
22#include "wx/stattext.h"
23#include "wx/os2/private.h"
0e320a79
DW
24#include <stdio.h>
25
0e320a79 26IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
0e320a79 27
d5da0ce7
WS
28bool wxStaticText::Create( wxWindow* pParent,
29 wxWindowID vId,
30 const wxString& rsLabel,
31 const wxPoint& rPos,
32 const wxSize& rSize,
33 long lStyle,
34 const wxString& rsName )
0e320a79 35{
1f3154c8
DW
36 SetName(rsName);
37 if (pParent)
38 pParent->AddChild(this);
d90895ac 39
1f3154c8
DW
40 SetBackgroundColour(pParent->GetBackgroundColour()) ;
41 SetForegroundColour(pParent->GetForegroundColour()) ;
0e320a79 42
d5da0ce7 43 if ( vId == wxID_ANY )
d90895ac
DW
44 m_windowId = (int)NewControlId();
45 else
1f3154c8 46 m_windowId = vId;
0e320a79 47
d5da0ce7
WS
48 int nX = rPos.x;
49 int nY = rPos.y;
50 int nWidth = rSize.x;
51 int nHeight = rSize.y;
0e320a79 52
1f3154c8 53 m_windowStyle = lStyle;
0e320a79 54
d5da0ce7 55 long lSstyle = 0L;
0e320a79 56
61cc6764
SN
57 // Used to have DT_VCENTER but that doesn't work correctly with
58 // multiline strings and DT_WORDBREAK. Accept a reasonable
59 // compromise for now
60 lSstyle = WS_VISIBLE | SS_TEXT | DT_WORDBREAK | DT_MNEMONIC;
1f3154c8
DW
61 if (m_windowStyle & wxALIGN_CENTRE)
62 lSstyle |= DT_CENTER;
63 else if (m_windowStyle & wxALIGN_RIGHT)
64 lSstyle |= DT_RIGHT;
65 else
66 lSstyle |= DT_LEFT;
e94d504d 67
d5da0ce7 68 wxString sLabel = ::wxPMTextToLabel(rsLabel);
e94d504d 69
1f3154c8
DW
70 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
71 ,WC_STATIC // Window class
e94d504d 72 ,(PSZ)sLabel.c_str() // Initial Text
1f3154c8
DW
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
80 );
81
d5da0ce7 82 wxCHECK_MSG(m_hWnd, false, wxT("Failed to create static ctrl"));
3c299c3a 83
d5da0ce7 84 LONG lColor = (LONG)wxBLACK->GetPixel();
3c299c3a
DW
85
86 ::WinSetPresParam( m_hWnd
87 ,PP_FOREGROUNDCOLOR
88 ,sizeof(LONG)
89 ,(PVOID)&lColor
90 );
7993e67c
DW
91 lColor = (LONG)m_backgroundColour.GetPixel();
92
93 ::WinSetPresParam( m_hWnd
94 ,PP_BACKGROUNDCOLOR
95 ,sizeof(LONG)
96 ,(PVOID)&lColor
97 );
3c299c3a 98
1f3154c8 99 SubclassWin(m_hWnd);
b720b24d
DW
100 SetFont(*wxSMALL_FONT);
101 SetXComp(0);
102 SetYComp(0);
d5da0ce7
WS
103 SetSize( nX, nY, nWidth, nHeight );
104
105 return true;
1f3154c8 106} // end of wxStaticText::Create
0e320a79 107
e78c4d50 108wxSize wxStaticText::DoGetBestSize() const
0e320a79 109{
d5da0ce7
WS
110 wxString sText(wxGetWindowText(GetHWND()));
111 int nWidthTextMax = 0;
112 int nWidthLine = 0;
113 int nHeightTextTotal = 0;
114 int nHeightLineDefault = 0;
115 int nHeightLine = 0;
116 wxString sCurLine;
117 bool bLastWasTilde = false;
1f3154c8 118
3c299c3a 119 for (const wxChar *pc = sText; ; pc++)
1f3154c8
DW
120 {
121 if ( *pc == wxT('\n') || *pc == wxT('\0') )
122 {
123 if (!sCurLine )
124 {
125 //
126 // We can't use GetTextExtent - it will return 0 for both width
e78c4d50
DW
127 // and height and an empty line should count in height
128 // calculation
1f3154c8
DW
129 //
130 if (!nHeightLineDefault)
131 nHeightLineDefault = nHeightLine;
132 if (!nHeightLineDefault)
133 GetTextExtent(_T("W"), NULL, &nHeightLineDefault);
134 nHeightTextTotal += nHeightLineDefault;
e78c4d50 135 }
1f3154c8
DW
136 else
137 {
138 GetTextExtent( sCurLine
139 ,&nWidthLine
140 ,&nHeightLine
141 );
142 if (nWidthLine > nWidthTextMax)
143 nWidthTextMax = nWidthLine;
144 nHeightTextTotal += nHeightLine;
e78c4d50 145 }
d90895ac 146
1f3154c8
DW
147 if ( *pc == wxT('\n') )
148 {
149 sCurLine.Empty();
d90895ac 150 }
1f3154c8
DW
151 else
152 {
d90895ac
DW
153 break;
154 }
155 }
1f3154c8
DW
156 else
157 {
6e348b12 158 //
e94d504d 159 // We shouldn't take into account the '~' which just introduces the
6e348b12 160 // mnemonic characters and so are not shown on the screen -- except
e94d504d
SN
161 // when it is preceded by another '~' in which case it stands for a
162 // literal tilde
6e348b12 163 //
e94d504d 164 if (*pc == _T('~'))
6e348b12 165 {
e94d504d 166 if (!bLastWasTilde)
6e348b12 167 {
d5da0ce7 168 bLastWasTilde = true;
6e348b12
DW
169
170 //
171 // Skip the statement adding pc to curLine below
172 //
173 continue;
174 }
175
176 //
e94d504d 177 // It is a literal tilde
6e348b12 178 //
d5da0ce7 179 bLastWasTilde = false;
6e348b12 180 }
1f3154c8 181 sCurLine += *pc;
d90895ac
DW
182 }
183 }
1f3154c8
DW
184 return wxSize( nWidthTextMax
185 ,nHeightTextTotal
186 );
187} // end of wxStaticText::DoGetBestSize
188
7993e67c
DW
189void wxStaticText::DoSetSize(
190 int nX
191, int nY
192, int nWidth
193, int nHeight
194, int nSizeFlags
195)
196{
197 //
198 // We need to refresh the window after changing its size as the standard
199 // control doesn't always update itself properly.
200 //
201 wxStaticTextBase::DoSetSize( nX
202 ,nY
203 ,nWidth
204 ,nHeight
205 ,nSizeFlags
206 );
207 Refresh();
208} // end of wxStaticText::DoSetSize
209
3c299c3a
DW
210bool wxStaticText::SetFont(
211 const wxFont& rFont
1f3154c8 212)
0e320a79 213{
3c299c3a 214 bool bRet = wxControl::SetFont(rFont);
1f3154c8
DW
215
216 //
217 // Adjust the size of the window to fit to the label unless autoresizing is
218 // disabled
219 //
3c299c3a 220 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
1f3154c8
DW
221 {
222 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
223 }
3c299c3a
DW
224 return bRet;
225} // end of wxStaticText::SetFont
d90895ac 226
3c299c3a
DW
227void wxStaticText::SetLabel(
228 const wxString& rsLabel
1f3154c8 229)
d90895ac 230{
e94d504d
SN
231 wxString sLabel = ::wxPMTextToLabel(rsLabel);
232 ::WinSetWindowText(GetHwnd(), (PSZ)sLabel.c_str());
1f3154c8
DW
233
234 //
235 // Adjust the size of the window to fit to the label unless autoresizing is
236 // disabled
237 //
3c299c3a 238 if (!(GetWindowStyle() & wxST_NO_AUTORESIZE))
1f3154c8 239 {
b720b24d
DW
240 wxCoord vX;
241 wxCoord vY;
242 wxCoord vWidth;
243 wxCoord vHeight;
244
245 GetPosition(&vX, &vY);
246 GetSize(&vWidth, &vHeight);
247 if (!(vX == -1 && vY == -1 && vWidth == -1 && vHeight == -1))
248 DoSetSize(vX, vY, vWidth, vHeight, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
249 else
250 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
1f3154c8 251 }
3c299c3a 252} // end of wxStaticText::SetLabel
1f3154c8
DW
253
254MRESULT wxStaticText::OS2WindowProc(
255 WXUINT uMsg
256, WXWPARAM wParam
257, WXLPARAM lParam
258)
d90895ac 259{
1f3154c8
DW
260 return wxWindow::OS2WindowProc( uMsg
261 ,wParam
262 ,lParam
263 );
264} // end of wxStaticText::OS2WindowProc