]>
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 | |
d90895ac DW |
48 | if ( id == -1 ) |
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 | |
1f3154c8 DW |
83 | SubclassWin(m_hWnd); |
84 | wxControl::SetFont(pParent->GetFont()); | |
85 | SetSize(nX, nY, nWidth, nHeight); | |
d90895ac | 86 | return FALSE; |
1f3154c8 | 87 | } // end of wxStaticText::Create |
0e320a79 | 88 | |
e78c4d50 | 89 | wxSize wxStaticText::DoGetBestSize() const |
0e320a79 | 90 | { |
1f3154c8 DW |
91 | wxString sText(wxGetWindowText(GetHWND())); |
92 | int nWidthTextMax = 0; | |
93 | int nWidthLine = 0; | |
94 | int nHeightTextTotal = 0; | |
95 | int nHeightLineDefault = 0; | |
96 | int nHeightLine = 0; | |
97 | wxString sCurLine; | |
98 | ||
99 | for ( const wxChar *pc = sText; ; pc++ ) | |
100 | { | |
101 | if ( *pc == wxT('\n') || *pc == wxT('\0') ) | |
102 | { | |
103 | if (!sCurLine ) | |
104 | { | |
105 | // | |
106 | // We can't use GetTextExtent - it will return 0 for both width | |
e78c4d50 DW |
107 | // and height and an empty line should count in height |
108 | // calculation | |
1f3154c8 DW |
109 | // |
110 | if (!nHeightLineDefault) | |
111 | nHeightLineDefault = nHeightLine; | |
112 | if (!nHeightLineDefault) | |
113 | GetTextExtent(_T("W"), NULL, &nHeightLineDefault); | |
114 | nHeightTextTotal += nHeightLineDefault; | |
e78c4d50 | 115 | } |
1f3154c8 DW |
116 | else |
117 | { | |
118 | GetTextExtent( sCurLine | |
119 | ,&nWidthLine | |
120 | ,&nHeightLine | |
121 | ); | |
122 | if (nWidthLine > nWidthTextMax) | |
123 | nWidthTextMax = nWidthLine; | |
124 | nHeightTextTotal += nHeightLine; | |
e78c4d50 | 125 | } |
d90895ac | 126 | |
1f3154c8 DW |
127 | if ( *pc == wxT('\n') ) |
128 | { | |
129 | sCurLine.Empty(); | |
d90895ac | 130 | } |
1f3154c8 DW |
131 | else |
132 | { | |
d90895ac DW |
133 | break; |
134 | } | |
135 | } | |
1f3154c8 DW |
136 | else |
137 | { | |
138 | sCurLine += *pc; | |
d90895ac DW |
139 | } |
140 | } | |
1f3154c8 DW |
141 | return wxSize( nWidthTextMax |
142 | ,nHeightTextTotal | |
143 | ); | |
144 | } // end of wxStaticText::DoGetBestSize | |
145 | ||
146 | void wxStaticText::SetLabel( | |
147 | const wxString& rsLabel | |
148 | ) | |
0e320a79 | 149 | { |
1f3154c8 DW |
150 | ::WinSetWindowText(GetHwnd(), rsLabel.c_str()); |
151 | ||
152 | // | |
153 | // Adjust the size of the window to fit to the label unless autoresizing is | |
154 | // disabled | |
155 | // | |
156 | if (!(GetWindowStyle() & wxST_NO_AUTORESIZE)) | |
157 | { | |
158 | DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT); | |
159 | } | |
d90895ac | 160 | DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT); |
1f3154c8 | 161 | } // end of wxStaticText::SetLabel |
d90895ac | 162 | |
1f3154c8 DW |
163 | bool wxStaticText::SetFont( |
164 | const wxFont& rFont | |
165 | ) | |
d90895ac | 166 | { |
1f3154c8 DW |
167 | bool bRet = wxControl::SetFont(rFont); |
168 | ||
169 | // | |
170 | // Adjust the size of the window to fit to the label unless autoresizing is | |
171 | // disabled | |
172 | // | |
173 | if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) | |
174 | { | |
175 | DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT); | |
176 | } | |
177 | return bRet; | |
178 | } // end of wxStaticText::SetFont | |
179 | ||
180 | MRESULT wxStaticText::OS2WindowProc( | |
181 | WXUINT uMsg | |
182 | , WXWPARAM wParam | |
183 | , WXLPARAM lParam | |
184 | ) | |
d90895ac | 185 | { |
1f3154c8 DW |
186 | return wxWindow::OS2WindowProc( uMsg |
187 | ,wParam | |
188 | ,lParam | |
189 | ); | |
190 | } // end of wxStaticText::OS2WindowProc | |
191 | ||
0e320a79 | 192 |