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