]> git.saurik.com Git - wxWidgets.git/blame - src/os2/control.cpp
OS/2 Updates
[wxWidgets.git] / src / os2 / control.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: control.cpp
3// Purpose: wxControl class
45fcbf3b 4// Author: David Webster
0e320a79 5// Modified by:
45fcbf3b 6// Created: 09/17/99
0e320a79 7// RCS-ID: $Id$
45fcbf3b
DW
8// Copyright: (c) Julian Smart and Markus Holzem
9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "control.h"
14#endif
15
45fcbf3b
DW
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
86de7616 24#include "wx/os2/private.h"
0e320a79
DW
25#include "wx/control.h"
26
0e320a79
DW
27IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
28
29BEGIN_EVENT_TABLE(wxControl, wxWindow)
45fcbf3b 30 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground)
0e320a79 31END_EVENT_TABLE()
0e320a79
DW
32
33// Item members
34wxControl::wxControl()
35{
45fcbf3b
DW
36 m_backgroundColour = *wxWHITE;
37 m_foregroundColour = *wxBLACK;
38
39#if WXWIN_COMPATIBILITY
40 m_callback = 0;
41#endif // WXWIN_COMPATIBILITY
0e320a79
DW
42}
43
3d62dcb6
DW
44bool wxControl::Create(wxWindow *parent, wxWindowID id,
45 const wxPoint& pos,
46 const wxSize& size, long style,
47#if wxUSE_VALIDATORS
48 const wxValidator& validator,
49#endif
50 const wxString& name)
51{
52 bool rval = wxWindow::Create(parent, id, pos, size, style, name);
53 if (rval) {
54#if wxUSE_VALIDATORS
55 SetValidator(validator);
56#endif
57 }
58 return rval;
59}
60
0e320a79
DW
61wxControl::~wxControl()
62{
45fcbf3b 63 m_isBeingDeleted = TRUE;
0e320a79
DW
64}
65
3d62dcb6
DW
66bool wxControl::OS2CreateControl(const wxChar *classname,
67 WXDWORD style,
68 const wxPoint& pos,
69 const wxSize& size,
70 const wxString& label,
71 WXDWORD exstyle)
0e320a79 72{
3d62dcb6
DW
73 // VZ: if someone could put a comment here explaining what exactly this is
74 // needed for, it would be nice...
75 bool want3D;
86de7616 76
3d62dcb6
DW
77 // if no extended style given, determine it ourselves
78 if ( exstyle == (WXDWORD)-1 )
79 {
80 exstyle = GetExStyle(style);
81 }
82
83// TODO:
84/*
85 // all controls have these childs (wxWindows creates all controls visible
86 // by default)
87 style |= WS_CHILD | WS_VISIBLE;
88
89 m_hWnd = (WXHWND)::CreateWindowEx
90 (
91 exstyle, // extended style
92 classname, // the kind of control to create
93 label, // the window name
94 style, // the window style
95 pos.x, pos.y, // the window position
96 size.x, size.y, // and size
97 GetHwndOf(GetParent()), // parent
98 (HMENU)GetId(), // child id
99 wxGetInstance(), // app instance
100 NULL // creation parameters
101 );
45fcbf3b
DW
102
103 if ( !m_hWnd )
104 {
105#ifdef __WXDEBUG__
223d09f6 106 wxLogError(wxT("Failed to create a control of class '%s'"), classname);
45fcbf3b
DW
107#endif // DEBUG
108
109 return FALSE;
110 }
111
3d62dcb6
DW
112#if wxUSE_CTL3D
113 if ( want3D )
114 {
115 Ctl3dSubclassCtl(GetHwnd());
116 m_useCtl3D = TRUE;
117 }
118#endif // wxUSE_CTL3D
119
45fcbf3b
DW
120 // subclass again for purposes of dialog editing mode
121 SubclassWin(m_hWnd);
122
123 // controls use the same font and colours as their parent dialog by default
124 InheritAttributes();
3d62dcb6 125*/
45fcbf3b 126 return TRUE;
0e320a79
DW
127}
128
e78c4d50 129wxSize wxControl::DoGetBestSize() const
0e320a79 130{
45fcbf3b 131 return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT);
0e320a79
DW
132}
133
45fcbf3b 134bool wxControl::ProcessCommand(wxCommandEvent& event)
0e320a79 135{
45fcbf3b
DW
136#if WXWIN_COMPATIBILITY
137 if ( m_callback )
0e320a79 138 {
45fcbf3b
DW
139 (void)(*m_callback)(this, event);
140
141 return TRUE;
0e320a79
DW
142 }
143 else
45fcbf3b
DW
144#endif // WXWIN_COMPATIBILITY
145
146 return GetEventHandler()->ProcessEvent(event);
147}
148
149bool wxControl::OS2OnNotify(int idCtrl,
150 WXLPARAM lParam,
151 WXLPARAM* result)
152{
153 wxCommandEvent event(wxEVT_NULL, m_windowId);
154 wxEventType eventType = wxEVT_NULL;
86de7616 155/* TODO:
45fcbf3b
DW
156 NMHDR *hdr1 = (NMHDR*) lParam;
157 switch ( hdr1->code )
0e320a79 158 {
45fcbf3b
DW
159 case NM_CLICK:
160 eventType = wxEVT_COMMAND_LEFT_CLICK;
161 break;
162
163 case NM_DBLCLK:
164 eventType = wxEVT_COMMAND_LEFT_DCLICK;
165 break;
166
167 case NM_RCLICK:
168 eventType = wxEVT_COMMAND_RIGHT_CLICK;
169 break;
170
171 case NM_RDBLCLK:
172 eventType = wxEVT_COMMAND_RIGHT_DCLICK;
173 break;
174
175 case NM_SETFOCUS:
176 eventType = wxEVT_COMMAND_SET_FOCUS;
177 break;
178
179 case NM_KILLFOCUS:
180 eventType = wxEVT_COMMAND_KILL_FOCUS;
181 break;
182
183 case NM_RETURN:
184 eventType = wxEVT_COMMAND_ENTER;
185 break;
186
187 default:
188 return wxWindow::OS2OnNotify(idCtrl, lParam, result);
0e320a79 189 }
86de7616 190*/
45fcbf3b
DW
191 event.SetEventType(eventType);
192 event.SetEventObject(this);
193
194 return GetEventHandler()->ProcessEvent(event);
0e320a79
DW
195}
196
45fcbf3b
DW
197void wxControl::OnEraseBackground(wxEraseEvent& event)
198{
199 // In general, you don't want to erase the background of a control,
200 // or you'll get a flicker.
201 // TODO: move this 'null' function into each control that
202 // might flicker.
203
204 RECT rect;
205/*
206* below is msw code.
207* TODO: convert to PM Code
208* ::GetClientRect((HWND) GetHWND(), &rect);
209*
210* HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(),
211* GetBackgroundColour().Green(),
212* GetBackgroundColour().Blue()));
213* int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
214*
215* ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
216* ::DeleteObject(hBrush);
217* ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
218*/
219}
220
221WXDWORD wxControl::GetExStyle(WXDWORD& style) const
222{
223 bool want3D;
224 WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ;
225
86de7616
DW
226 // Even with extended styles, need to combine with FS_BORDER
227 // for them to look right. Check it out later, base window style does
228 // not designate BORDERS. Down in Frame and And controls.
229
45fcbf3b 230 if ( want3D || wxStyleHasBorder(m_windowStyle) )
86de7616 231 style |= FS_BORDER;
45fcbf3b
DW
232
233 return exStyle;
234}
235
236// ---------------------------------------------------------------------------
237// global functions
238// ---------------------------------------------------------------------------
239
240// Call this repeatedly for several wnds to find the overall size
241// of the widget.
242// Call it initially with -1 for all values in rect.
243// Keep calling for other widgets, and rect will be modified
244// to calculate largest bounding rectangle.
245void wxFindMaxSize(WXHWND wnd, RECT *rect)
0e320a79 246{
86de7616
DW
247 int left = rect->xLeft;
248 int right = rect->xRight;
249 int top = rect->yTop;
250 int bottom = rect->yBottom;
0e320a79 251
86de7616 252 ::WinQueryWindowRect((HWND) wnd, rect);
0e320a79 253
45fcbf3b
DW
254 if (left < 0)
255 return;
0e320a79 256
86de7616
DW
257 if (left < rect->xLeft)
258 rect->xLeft = left;
0e320a79 259
86de7616
DW
260 if (right > rect->xRight)
261 rect->xRight = right;
0e320a79 262
86de7616
DW
263 if (top < rect->yTop)
264 rect->yTop = top;
0e320a79 265
86de7616
DW
266 if (bottom > rect->yBottom)
267 rect->yBottom = bottom;
0e320a79
DW
268}
269