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