]> git.saurik.com Git - wxWidgets.git/blame - src/msw/control.cpp
use of div_t.quot and div_t.rem were changed to / and %
[wxWidgets.git] / src / msw / control.cpp
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: control.cpp
3// Purpose: wxControl class
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
a23fd0e1 9// Licence: wxWindows licence
2bda0e17
KB
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#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
2432b92d 24#include "wx/event.h"
2bda0e17
KB
25#include "wx/app.h"
26#include "wx/dcclient.h"
27#endif
28
2432b92d
JS
29#include "wx/control.h"
30
2bda0e17
KB
31#include "wx/msw/private.h"
32
57c208c5 33#if (defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__)
2bda0e17
KB
34#include <commctrl.h>
35#endif
36
2bda0e17
KB
37#if !USE_SHARED_LIBRARY
38IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
39
40BEGIN_EVENT_TABLE(wxControl, wxWindow)
a23fd0e1 41 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground)
2bda0e17
KB
42END_EVENT_TABLE()
43#endif
44
45// Item members
42e69d6b 46wxControl::wxControl()
2bda0e17
KB
47{
48 m_backgroundColour = *wxWHITE;
49 m_foregroundColour = *wxBLACK;
42e69d6b
VZ
50
51#if WXWIN_COMPATIBILITY
2bda0e17 52 m_callback = 0;
42e69d6b 53#endif // WXWIN_COMPATIBILITY
2bda0e17
KB
54}
55
42e69d6b 56wxControl::~wxControl()
2bda0e17 57{
42e69d6b 58 m_isBeingDeleted = TRUE;
2bda0e17
KB
59}
60
4438caf4
VZ
61wxSize wxControl::DoGetBestSize()
62{
63 return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT);
64}
65
42e69d6b 66bool wxControl::ProcessCommand(wxCommandEvent& event)
2bda0e17 67{
42e69d6b
VZ
68#if WXWIN_COMPATIBILITY
69 if ( m_callback )
70 {
71 (void)(*m_callback)(this, event);
2bda0e17 72
42e69d6b
VZ
73 return TRUE;
74 }
75 else
76#endif // WXWIN_COMPATIBILITY
2bda0e17 77
42e69d6b 78 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
79}
80
a23fd0e1
VZ
81#ifdef __WIN95__
82bool wxControl::MSWOnNotify(int idCtrl,
83 WXLPARAM lParam,
84 WXLPARAM* result)
2bda0e17 85{
a23fd0e1
VZ
86 wxCommandEvent event(wxEVT_NULL, m_windowId);
87 wxEventType eventType = wxEVT_NULL;
88 NMHDR *hdr1 = (NMHDR*) lParam;
89 switch ( hdr1->code )
90 {
91 case NM_CLICK:
92 eventType = wxEVT_COMMAND_LEFT_CLICK;
93 break;
2bda0e17 94
a23fd0e1
VZ
95 case NM_DBLCLK:
96 eventType = wxEVT_COMMAND_LEFT_DCLICK;
97 break;
2bda0e17 98
a23fd0e1
VZ
99 case NM_RCLICK:
100 eventType = wxEVT_COMMAND_RIGHT_CLICK;
101 break;
2bda0e17 102
a23fd0e1
VZ
103 case NM_RDBLCLK:
104 eventType = wxEVT_COMMAND_RIGHT_DCLICK;
105 break;
2bda0e17 106
a23fd0e1
VZ
107 case NM_SETFOCUS:
108 eventType = wxEVT_COMMAND_SET_FOCUS;
109 break;
debe6624 110
a23fd0e1
VZ
111 case NM_KILLFOCUS:
112 eventType = wxEVT_COMMAND_KILL_FOCUS;
113 break;
2bda0e17 114
a23fd0e1
VZ
115 case NM_RETURN:
116 eventType = wxEVT_COMMAND_ENTER;
117 break;
118
119 default:
120 return wxWindow::MSWOnNotify(idCtrl, lParam, result);
121 }
fd3f686c 122
2bda0e17 123 event.SetEventType(eventType);
a23fd0e1 124 event.SetEventObject(this);
2bda0e17 125
a23fd0e1 126 return GetEventHandler()->ProcessEvent(event);
2bda0e17 127}
a23fd0e1 128#endif // Win95
2bda0e17 129
2bda0e17
KB
130void wxControl::OnEraseBackground(wxEraseEvent& event)
131{
42e69d6b
VZ
132 // In general, you don't want to erase the background of a control,
133 // or you'll get a flicker.
134 // TODO: move this 'null' function into each control that
135 // might flicker.
136
137 RECT rect;
138 ::GetClientRect((HWND) GetHWND(), &rect);
139
140 HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(),
141 GetBackgroundColour().Green(),
142 GetBackgroundColour().Blue()));
143 int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
144
145 ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
146 ::DeleteObject(hBrush);
147 ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
2bda0e17
KB
148}
149
42e69d6b
VZ
150// ---------------------------------------------------------------------------
151// global functions
152// ---------------------------------------------------------------------------
2bda0e17 153
42e69d6b
VZ
154// Call this repeatedly for several wnds to find the overall size
155// of the widget.
156// Call it initially with -1 for all values in rect.
157// Keep calling for other widgets, and rect will be modified
158// to calculate largest bounding rectangle.
159void wxFindMaxSize(WXHWND wnd, RECT *rect)
2bda0e17 160{
42e69d6b
VZ
161 int left = rect->left;
162 int right = rect->right;
163 int top = rect->top;
164 int bottom = rect->bottom;
2bda0e17 165
42e69d6b 166 GetWindowRect((HWND) wnd, rect);
2bda0e17 167
42e69d6b
VZ
168 if (left < 0)
169 return;
2bda0e17 170
42e69d6b
VZ
171 if (left < rect->left)
172 rect->left = left;
2bda0e17 173
42e69d6b
VZ
174 if (right > rect->right)
175 rect->right = right;
2bda0e17 176
42e69d6b
VZ
177 if (top < rect->top)
178 rect->top = top;
2bda0e17 179
42e69d6b
VZ
180 if (bottom > rect->bottom)
181 rect->bottom = bottom;
2bda0e17
KB
182}
183