]> git.saurik.com Git - wxWidgets.git/blame - src/os2/control.cpp
VTK wrapper of vtkRenderWindow for wxPython. Tested on MSW so far.
[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
27#if !USE_SHARED_LIBRARY
28IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
29
30BEGIN_EVENT_TABLE(wxControl, wxWindow)
45fcbf3b 31 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground)
0e320a79
DW
32END_EVENT_TABLE()
33#endif
34
35// Item members
36wxControl::wxControl()
37{
45fcbf3b
DW
38 m_backgroundColour = *wxWHITE;
39 m_foregroundColour = *wxBLACK;
40
41#if WXWIN_COMPATIBILITY
42 m_callback = 0;
43#endif // WXWIN_COMPATIBILITY
0e320a79
DW
44}
45
46wxControl::~wxControl()
47{
45fcbf3b 48 m_isBeingDeleted = TRUE;
0e320a79
DW
49}
50
45fcbf3b 51bool wxControl::OS2CreateControl(const wxChar *classname, WXDWORD style)
0e320a79 52{
86de7616
DW
53 m_hWnd = (WXHWND)::WinCreateWindow( GetHwndOf(GetParent())
54 ,classname
55 ,NULL
56 ,style
57 ,0,0,0,0
58 ,NULLHANDLE
59 ,HWND_TOP
60 ,(HMENU)GetId()
61 ,NULL
62 ,NULL
63 );
64
45fcbf3b
DW
65
66 if ( !m_hWnd )
67 {
68#ifdef __WXDEBUG__
223d09f6 69 wxLogError(wxT("Failed to create a control of class '%s'"), classname);
45fcbf3b
DW
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;
0e320a79
DW
82}
83
45fcbf3b 84wxSize wxControl::DoGetBestSize()
0e320a79 85{
45fcbf3b 86 return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT);
0e320a79
DW
87}
88
45fcbf3b 89bool wxControl::ProcessCommand(wxCommandEvent& event)
0e320a79 90{
45fcbf3b
DW
91#if WXWIN_COMPATIBILITY
92 if ( m_callback )
0e320a79 93 {
45fcbf3b
DW
94 (void)(*m_callback)(this, event);
95
96 return TRUE;
0e320a79
DW
97 }
98 else
45fcbf3b
DW
99#endif // WXWIN_COMPATIBILITY
100
101 return GetEventHandler()->ProcessEvent(event);
102}
103
104bool wxControl::OS2OnNotify(int idCtrl,
105 WXLPARAM lParam,
106 WXLPARAM* result)
107{
108 wxCommandEvent event(wxEVT_NULL, m_windowId);
109 wxEventType eventType = wxEVT_NULL;
86de7616 110/* TODO:
45fcbf3b
DW
111 NMHDR *hdr1 = (NMHDR*) lParam;
112 switch ( hdr1->code )
0e320a79 113 {
45fcbf3b
DW
114 case NM_CLICK:
115 eventType = wxEVT_COMMAND_LEFT_CLICK;
116 break;
117
118 case NM_DBLCLK:
119 eventType = wxEVT_COMMAND_LEFT_DCLICK;
120 break;
121
122 case NM_RCLICK:
123 eventType = wxEVT_COMMAND_RIGHT_CLICK;
124 break;
125
126 case NM_RDBLCLK:
127 eventType = wxEVT_COMMAND_RIGHT_DCLICK;
128 break;
129
130 case NM_SETFOCUS:
131 eventType = wxEVT_COMMAND_SET_FOCUS;
132 break;
133
134 case NM_KILLFOCUS:
135 eventType = wxEVT_COMMAND_KILL_FOCUS;
136 break;
137
138 case NM_RETURN:
139 eventType = wxEVT_COMMAND_ENTER;
140 break;
141
142 default:
143 return wxWindow::OS2OnNotify(idCtrl, lParam, result);
0e320a79 144 }
86de7616 145*/
45fcbf3b
DW
146 event.SetEventType(eventType);
147 event.SetEventObject(this);
148
149 return GetEventHandler()->ProcessEvent(event);
0e320a79
DW
150}
151
45fcbf3b
DW
152void wxControl::OnEraseBackground(wxEraseEvent& event)
153{
154 // In general, you don't want to erase the background of a control,
155 // or you'll get a flicker.
156 // TODO: move this 'null' function into each control that
157 // might flicker.
158
159 RECT rect;
160/*
161* below is msw code.
162* TODO: convert to PM Code
163* ::GetClientRect((HWND) GetHWND(), &rect);
164*
165* HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(),
166* GetBackgroundColour().Green(),
167* GetBackgroundColour().Blue()));
168* int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
169*
170* ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
171* ::DeleteObject(hBrush);
172* ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
173*/
174}
175
176WXDWORD wxControl::GetExStyle(WXDWORD& style) const
177{
178 bool want3D;
179 WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ;
180
86de7616
DW
181 // Even with extended styles, need to combine with FS_BORDER
182 // for them to look right. Check it out later, base window style does
183 // not designate BORDERS. Down in Frame and And controls.
184
45fcbf3b 185 if ( want3D || wxStyleHasBorder(m_windowStyle) )
86de7616 186 style |= FS_BORDER;
45fcbf3b
DW
187
188 return exStyle;
189}
190
191// ---------------------------------------------------------------------------
192// global functions
193// ---------------------------------------------------------------------------
194
195// Call this repeatedly for several wnds to find the overall size
196// of the widget.
197// Call it initially with -1 for all values in rect.
198// Keep calling for other widgets, and rect will be modified
199// to calculate largest bounding rectangle.
200void wxFindMaxSize(WXHWND wnd, RECT *rect)
0e320a79 201{
86de7616
DW
202 int left = rect->xLeft;
203 int right = rect->xRight;
204 int top = rect->yTop;
205 int bottom = rect->yBottom;
0e320a79 206
86de7616 207 ::WinQueryWindowRect((HWND) wnd, rect);
0e320a79 208
45fcbf3b
DW
209 if (left < 0)
210 return;
0e320a79 211
86de7616
DW
212 if (left < rect->xLeft)
213 rect->xLeft = left;
0e320a79 214
86de7616
DW
215 if (right > rect->xRight)
216 rect->xRight = right;
0e320a79 217
86de7616
DW
218 if (top < rect->yTop)
219 rect->yTop = top;
0e320a79 220
86de7616
DW
221 if (bottom > rect->yBottom)
222 rect->yBottom = bottom;
0e320a79
DW
223}
224