*** empty log message ***
[wxWidgets.git] / src / os2 / control.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: control.cpp
3 // Purpose: wxControl class
4 // Author: David Webster
5 // Modified by:
6 // Created: 09/17/99
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "control.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifndef WX_PRECOMP
20 #include "wx/event.h"
21 #include "wx/app.h"
22 #include "wx/dcclient.h"
23 #endif
24
25 #include "wx/control.h"
26
27 #if !USE_SHARED_LIBRARY
28 IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
29
30 BEGIN_EVENT_TABLE(wxControl, wxWindow)
31 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground)
32 END_EVENT_TABLE()
33 #endif
34
35 // Item members
36 wxControl::wxControl()
37 {
38 m_backgroundColour = *wxWHITE;
39 m_foregroundColour = *wxBLACK;
40
41 #if WXWIN_COMPATIBILITY
42 m_callback = 0;
43 #endif // WXWIN_COMPATIBILITY
44 }
45
46 wxControl::~wxControl()
47 {
48 m_isBeingDeleted = TRUE;
49 }
50
51 bool wxControl::OS2CreateControl(const wxChar *classname, WXDWORD style)
52 {
53 m_hWnd = (WXHWND)::CreateWindowEx
54 (
55 GetExStyle(style), // extended style
56 classname, // the kind of control to create
57 NULL, // the window name
58 style, // the window style
59 0, 0, 0, 0, // the window position and size
60 GetHwndOf(GetParent()), // parent
61 (HMENU)GetId(), // child id
62 wxGetInstance(), // app instance
63 NULL // creation parameters
64 );
65
66 if ( !m_hWnd )
67 {
68 #ifdef __WXDEBUG__
69 wxLogError(_T("Failed to create a control of class '%s'"), classname);
70 #endif // DEBUG
71
72 return FALSE;
73 }
74
75 // subclass again for purposes of dialog editing mode
76 SubclassWin(m_hWnd);
77
78 // controls use the same font and colours as their parent dialog by default
79 InheritAttributes();
80
81 return TRUE;
82 }
83
84 wxSize wxControl::DoGetBestSize()
85 {
86 return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT);
87 }
88
89 bool wxControl::ProcessCommand(wxCommandEvent& event)
90 {
91 #if WXWIN_COMPATIBILITY
92 if ( m_callback )
93 {
94 (void)(*m_callback)(this, event);
95
96 return TRUE;
97 }
98 else
99 #endif // WXWIN_COMPATIBILITY
100
101 return GetEventHandler()->ProcessEvent(event);
102 }
103
104 bool wxControl::OS2OnNotify(int idCtrl,
105 WXLPARAM lParam,
106 WXLPARAM* result)
107 {
108 wxCommandEvent event(wxEVT_NULL, m_windowId);
109 wxEventType eventType = wxEVT_NULL;
110 NMHDR *hdr1 = (NMHDR*) lParam;
111 switch ( hdr1->code )
112 {
113 case NM_CLICK:
114 eventType = wxEVT_COMMAND_LEFT_CLICK;
115 break;
116
117 case NM_DBLCLK:
118 eventType = wxEVT_COMMAND_LEFT_DCLICK;
119 break;
120
121 case NM_RCLICK:
122 eventType = wxEVT_COMMAND_RIGHT_CLICK;
123 break;
124
125 case NM_RDBLCLK:
126 eventType = wxEVT_COMMAND_RIGHT_DCLICK;
127 break;
128
129 case NM_SETFOCUS:
130 eventType = wxEVT_COMMAND_SET_FOCUS;
131 break;
132
133 case NM_KILLFOCUS:
134 eventType = wxEVT_COMMAND_KILL_FOCUS;
135 break;
136
137 case NM_RETURN:
138 eventType = wxEVT_COMMAND_ENTER;
139 break;
140
141 default:
142 return wxWindow::OS2OnNotify(idCtrl, lParam, result);
143 }
144
145 event.SetEventType(eventType);
146 event.SetEventObject(this);
147
148 return GetEventHandler()->ProcessEvent(event);
149 }
150
151 void wxControl::OnEraseBackground(wxEraseEvent& event)
152 {
153 // In general, you don't want to erase the background of a control,
154 // or you'll get a flicker.
155 // TODO: move this 'null' function into each control that
156 // might flicker.
157
158 RECT rect;
159 /*
160 * below is msw code.
161 * TODO: convert to PM Code
162 * ::GetClientRect((HWND) GetHWND(), &rect);
163 *
164 * HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(),
165 * GetBackgroundColour().Green(),
166 * GetBackgroundColour().Blue()));
167 * int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
168 *
169 * ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
170 * ::DeleteObject(hBrush);
171 * ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
172 */
173 }
174
175 WXDWORD wxControl::GetExStyle(WXDWORD& style) const
176 {
177 bool want3D;
178 WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ;
179
180 // Even with extended styles, need to combine with WS_BORDER
181 // for them to look right.
182 if ( want3D || wxStyleHasBorder(m_windowStyle) )
183 style |= WS_BORDER;
184
185 return exStyle;
186 }
187
188 // ---------------------------------------------------------------------------
189 // global functions
190 // ---------------------------------------------------------------------------
191
192 // Call this repeatedly for several wnds to find the overall size
193 // of the widget.
194 // Call it initially with -1 for all values in rect.
195 // Keep calling for other widgets, and rect will be modified
196 // to calculate largest bounding rectangle.
197 void wxFindMaxSize(WXHWND wnd, RECT *rect)
198 {
199 int left = rect->left;
200 int right = rect->right;
201 int top = rect->top;
202 int bottom = rect->bottom;
203
204 GetWindowRect((HWND) wnd, rect);
205
206 if (left < 0)
207 return;
208
209 if (left < rect->left)
210 rect->left = left;
211
212 if (right > rect->right)
213 rect->right = right;
214
215 if (top < rect->top)
216 rect->top = top;
217
218 if (bottom > rect->bottom)
219 rect->bottom = bottom;
220 }
221