]> git.saurik.com Git - wxWidgets.git/blob - src/os2/stattext.cpp
debug check for infinite loop in InitializeClasses() added
[wxWidgets.git] / src / os2 / stattext.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: stattext.cpp
3 // Purpose: wxStaticText
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/17/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifndef WX_PRECOMP
16 #include "wx/event.h"
17 #include "wx/app.h"
18 #include "wx/brush.h"
19 #endif
20
21 #include "wx/stattext.h"
22 #include "wx/os2/private.h"
23 #include <stdio.h>
24
25 #if !USE_SHARED_LIBRARY
26 IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
27 #endif
28
29 bool wxStaticText::Create(wxWindow *parent, wxWindowID id,
30 const wxString& label,
31 const wxPoint& pos,
32 const wxSize& size,
33 long style,
34 const wxString& name)
35 {
36 SetName(name);
37 if (parent) parent->AddChild(this);
38
39 SetBackgroundColour(parent->GetBackgroundColour()) ;
40 SetForegroundColour(parent->GetForegroundColour()) ;
41
42 if ( id == -1 )
43 m_windowId = (int)NewControlId();
44 else
45 m_windowId = id;
46
47 int x = pos.x;
48 int y = pos.y;
49 int width = size.x;
50 int height = size.y;
51
52 m_windowStyle = style;
53
54 // TODO
55 SubclassWin(m_hWnd);
56
57 SetFont(parent->GetFont());
58 SetSize(x, y, width, height);
59
60 return FALSE;
61 }
62
63 wxSize wxStaticText::DoGetBestSize() const
64 {
65 wxString text(wxGetWindowText(GetHWND()));
66
67 int widthTextMax = 0, widthLine,
68 heightTextTotal = 0, heightLineDefault = 0, heightLine = 0;
69
70 wxString curLine;
71 for ( const wxChar *pc = text; ; pc++ ) {
72 if ( *pc == wxT('\n') || *pc == wxT('\0') ) {
73 if ( !curLine ) {
74 // we can't use GetTextExtent - it will return 0 for both width
75 // and height and an empty line should count in height
76 // calculation
77 if ( !heightLineDefault )
78 heightLineDefault = heightLine;
79 if ( !heightLineDefault )
80 GetTextExtent(_T("W"), NULL, &heightLineDefault);
81
82 heightTextTotal += heightLineDefault;
83 }
84 else {
85 GetTextExtent(curLine, &widthLine, &heightLine);
86 if ( widthLine > widthTextMax )
87 widthTextMax = widthLine;
88 heightTextTotal += heightLine;
89 }
90
91 if ( *pc == wxT('\n') ) {
92 curLine.Empty();
93 }
94 else {
95 // the end of string
96 break;
97 }
98 }
99 else {
100 curLine += *pc;
101 }
102 }
103
104 return wxSize(widthTextMax, heightTextTotal);
105 }
106
107 void wxStaticText::SetLabel(const wxString& label)
108 {
109 // TODO
110
111 // adjust the size of the window to fit to the label (this behaviour is
112 // backward compatible and generally makes sense but we might want to still
113 // provide the user a way to disable it) (VZ)
114 DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
115 }
116
117 WXHBRUSH wxStaticText::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
118 WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
119 {
120 // TODO:
121 /*
122 if (GetParent()->GetTransparentBackground())
123 SetBkMode((HDC) pDC, TRANSPARENT);
124 else
125 SetBkMode((HDC) pDC, OPAQUE);
126
127 ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
128 ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
129
130 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
131 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
132 // has a zero usage count.
133 // backgroundBrush->RealizeResource();
134 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
135 */
136 return (WXHBRUSH)0;
137 }
138
139 MRESULT wxStaticText::OS2WindowProc(HWND hwnd, WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
140 {
141 // Ensure that static items get messages. Some controls don't like this
142 // message to be intercepted (e.g. RichEdit), hence the tests.
143 // TODO:
144 /*
145 if (nMsg == WM_NCHITTEST)
146 return (long)HTCLIENT;
147 */
148 return wxWindow::OS2WindowProc(hwnd, nMsg, wParam, lParam);
149 }
150