]>
Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: stattext.cpp | |
3 | // Purpose: wxStaticText | |
d90895ac | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
d90895ac | 6 | // Created: 10/17/99 |
0e320a79 | 7 | // RCS-ID: $Id$ |
d90895ac DW |
8 | // Copyright: (c) David Webster |
9 | // Licence: wxWindows licence | |
0e320a79 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
aa213887 SN |
12 | #ifdef __GNUG__ |
13 | #pragma implementation "stattext.h" | |
14 | #endif | |
15 | ||
d90895ac DW |
16 | // For compilers that support precompilation, includes "wx.h". |
17 | #include "wx/wxprec.h" | |
0e320a79 | 18 | |
d90895ac DW |
19 | #ifndef WX_PRECOMP |
20 | #include "wx/event.h" | |
0e320a79 | 21 | #include "wx/app.h" |
d90895ac DW |
22 | #include "wx/brush.h" |
23 | #endif | |
0e320a79 | 24 | |
d90895ac DW |
25 | #include "wx/stattext.h" |
26 | #include "wx/os2/private.h" | |
0e320a79 DW |
27 | #include <stdio.h> |
28 | ||
0e320a79 | 29 | IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl) |
0e320a79 | 30 | |
1f3154c8 DW |
31 | bool wxStaticText::Create( |
32 | wxWindow* pParent | |
33 | , wxWindowID vId | |
34 | , const wxString& rsLabel | |
35 | , const wxPoint& rPos | |
36 | , const wxSize& rSize | |
37 | , long lStyle | |
38 | , const wxString& rsName | |
39 | ) | |
0e320a79 | 40 | { |
1f3154c8 DW |
41 | SetName(rsName); |
42 | if (pParent) | |
43 | pParent->AddChild(this); | |
d90895ac | 44 | |
1f3154c8 DW |
45 | SetBackgroundColour(pParent->GetBackgroundColour()) ; |
46 | SetForegroundColour(pParent->GetForegroundColour()) ; | |
0e320a79 | 47 | |
f15b4952 | 48 | if ( vId == -1 ) |
d90895ac DW |
49 | m_windowId = (int)NewControlId(); |
50 | else | |
1f3154c8 | 51 | m_windowId = vId; |
0e320a79 | 52 | |
1f3154c8 DW |
53 | int nX = rPos.x; |
54 | int nY = rPos.y; | |
55 | int nWidth = rSize.x; | |
56 | int nHeight = rSize.y; | |
0e320a79 | 57 | |
1f3154c8 | 58 | m_windowStyle = lStyle; |
0e320a79 | 59 | |
1f3154c8 | 60 | long lSstyle = 0L; |
0e320a79 | 61 | |
1f3154c8 DW |
62 | lSstyle = WS_VISIBLE | SS_TEXT | DT_VCENTER; |
63 | if (m_windowStyle & wxALIGN_CENTRE) | |
64 | lSstyle |= DT_CENTER; | |
65 | else if (m_windowStyle & wxALIGN_RIGHT) | |
66 | lSstyle |= DT_RIGHT; | |
67 | else | |
68 | lSstyle |= DT_LEFT; | |
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 | |
79 | ); | |
80 | ||
81 | wxCHECK_MSG(m_hWnd, FALSE, wxT("Failed to create static ctrl")); | |
d90895ac | 82 | |
3c299c3a DW |
83 | wxColour vColour; |
84 | ||
85 | vColour.Set(wxString("BLACK")); | |
86 | ||
87 | LONG lColor = (LONG)vColour.GetPixel(); | |
88 | ||
89 | ::WinSetPresParam( m_hWnd | |
90 | ,PP_FOREGROUNDCOLOR | |
91 | ,sizeof(LONG) | |
92 | ,(PVOID)&lColor | |
93 | ); | |
94 | ||
1f3154c8 DW |
95 | SubclassWin(m_hWnd); |
96 | wxControl::SetFont(pParent->GetFont()); | |
3c299c3a DW |
97 | SetSize( nX |
98 | ,nY | |
99 | ,nWidth | |
100 | ,nHeight | |
101 | ); | |
102 | return TRUE; | |
1f3154c8 | 103 | } // end of wxStaticText::Create |
0e320a79 | 104 | |
e78c4d50 | 105 | wxSize wxStaticText::DoGetBestSize() const |
0e320a79 | 106 | { |
1f3154c8 DW |
107 | wxString sText(wxGetWindowText(GetHWND())); |
108 | int nWidthTextMax = 0; | |
109 | int nWidthLine = 0; | |
110 | int nHeightTextTotal = 0; | |
111 | int nHeightLineDefault = 0; | |
112 | int nHeightLine = 0; | |
113 | wxString sCurLine; | |
114 | ||
3c299c3a | 115 | for (const wxChar *pc = sText; ; pc++) |
1f3154c8 DW |
116 | { |
117 | if ( *pc == wxT('\n') || *pc == wxT('\0') ) | |
118 | { | |
119 | if (!sCurLine ) | |
120 | { | |
121 | // | |
122 | // We can't use GetTextExtent - it will return 0 for both width | |
e78c4d50 DW |
123 | // and height and an empty line should count in height |
124 | // calculation | |
1f3154c8 DW |
125 | // |
126 | if (!nHeightLineDefault) | |
127 | nHeightLineDefault = nHeightLine; | |
128 | if (!nHeightLineDefault) | |
129 | GetTextExtent(_T("W"), NULL, &nHeightLineDefault); | |
130 | nHeightTextTotal += nHeightLineDefault; | |
e78c4d50 | 131 | } |
1f3154c8 DW |
132 | else |
133 | { | |
134 | GetTextExtent( sCurLine | |
135 | ,&nWidthLine | |
136 | ,&nHeightLine | |
137 | ); | |
138 | if (nWidthLine > nWidthTextMax) | |
139 | nWidthTextMax = nWidthLine; | |
140 | nHeightTextTotal += nHeightLine; | |
e78c4d50 | 141 | } |
d90895ac | 142 | |
1f3154c8 DW |
143 | if ( *pc == wxT('\n') ) |
144 | { | |
145 | sCurLine.Empty(); | |
d90895ac | 146 | } |
1f3154c8 DW |
147 | else |
148 | { | |
d90895ac DW |
149 | break; |
150 | } | |
151 | } | |
1f3154c8 DW |
152 | else |
153 | { | |
154 | sCurLine += *pc; | |
d90895ac DW |
155 | } |
156 | } | |
1f3154c8 DW |
157 | return wxSize( nWidthTextMax |
158 | ,nHeightTextTotal | |
159 | ); | |
160 | } // end of wxStaticText::DoGetBestSize | |
161 | ||
3c299c3a DW |
162 | bool wxStaticText::SetFont( |
163 | const wxFont& rFont | |
1f3154c8 | 164 | ) |
0e320a79 | 165 | { |
3c299c3a | 166 | bool bRet = wxControl::SetFont(rFont); |
1f3154c8 DW |
167 | |
168 | // | |
169 | // Adjust the size of the window to fit to the label unless autoresizing is | |
170 | // disabled | |
171 | // | |
3c299c3a | 172 | if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) |
1f3154c8 DW |
173 | { |
174 | DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT); | |
175 | } | |
3c299c3a DW |
176 | return bRet; |
177 | } // end of wxStaticText::SetFont | |
d90895ac | 178 | |
3c299c3a DW |
179 | void wxStaticText::SetLabel( |
180 | const wxString& rsLabel | |
1f3154c8 | 181 | ) |
d90895ac | 182 | { |
3c299c3a | 183 | ::WinSetWindowText(GetHwnd(), rsLabel.c_str()); |
1f3154c8 DW |
184 | |
185 | // | |
186 | // Adjust the size of the window to fit to the label unless autoresizing is | |
187 | // disabled | |
188 | // | |
3c299c3a | 189 | if (!(GetWindowStyle() & wxST_NO_AUTORESIZE)) |
1f3154c8 DW |
190 | { |
191 | DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT); | |
192 | } | |
3c299c3a DW |
193 | DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT); |
194 | } // end of wxStaticText::SetLabel | |
1f3154c8 DW |
195 | |
196 | MRESULT wxStaticText::OS2WindowProc( | |
197 | WXUINT uMsg | |
198 | , WXWPARAM wParam | |
199 | , WXLPARAM lParam | |
200 | ) | |
d90895ac | 201 | { |
1f3154c8 DW |
202 | return wxWindow::OS2WindowProc( uMsg |
203 | ,wParam | |
204 | ,lParam | |
205 | ); | |
206 | } // end of wxStaticText::OS2WindowProc | |
207 | ||
0e320a79 | 208 |