]>
Commit | Line | Data |
---|---|---|
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__) || defined(wxUSE_NORLANDER_HEADERS) | |
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::MSWCreateControl(const wxChar *classname, WXDWORD style) | |
62 | { | |
63 | // VZ: if someone could put a comment here explaining what exactly this is | |
64 | // needed for, it would be nice... | |
65 | bool want3D; | |
66 | ||
67 | // all controls have these childs (wxWindows creates all controls visible | |
68 | // by default) | |
69 | style |= WS_CHILD | WS_VISIBLE; | |
70 | ||
71 | m_hWnd = (WXHWND)::CreateWindowEx | |
72 | ( | |
73 | GetExStyle(style, &want3D), // extended style | |
74 | classname, // the kind of control to create | |
75 | NULL, // the window name | |
76 | style, // the window style | |
77 | 0, 0, 0, 0, // the window position and size | |
78 | GetHwndOf(GetParent()), // parent | |
79 | (HMENU)GetId(), // child id | |
80 | wxGetInstance(), // app instance | |
81 | NULL // creation parameters | |
82 | ); | |
83 | ||
84 | if ( !m_hWnd ) | |
85 | { | |
86 | #ifdef __WXDEBUG__ | |
87 | wxLogError(wxT("Failed to create a control of class '%s'"), classname); | |
88 | #endif // DEBUG | |
89 | ||
90 | return FALSE; | |
91 | } | |
92 | ||
93 | #if wxUSE_CTL3D | |
94 | if ( want3D ) | |
95 | { | |
96 | Ctl3dSubclassCtl(GetHwnd()); | |
97 | m_useCtl3D = TRUE; | |
98 | } | |
99 | #endif // wxUSE_CTL3D | |
100 | ||
101 | // subclass again for purposes of dialog editing mode | |
102 | SubclassWin(m_hWnd); | |
103 | ||
104 | // controls use the same font and colours as their parent dialog by default | |
105 | InheritAttributes(); | |
106 | ||
107 | return TRUE; | |
108 | } | |
109 | ||
110 | wxSize wxControl::DoGetBestSize() | |
111 | { | |
112 | return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT); | |
113 | } | |
114 | ||
115 | bool wxControl::ProcessCommand(wxCommandEvent& event) | |
116 | { | |
117 | #if WXWIN_COMPATIBILITY | |
118 | if ( m_callback ) | |
119 | { | |
120 | (void)(*m_callback)(this, event); | |
121 | ||
122 | return TRUE; | |
123 | } | |
124 | else | |
125 | #endif // WXWIN_COMPATIBILITY | |
126 | ||
127 | return GetEventHandler()->ProcessEvent(event); | |
128 | } | |
129 | ||
130 | #ifdef __WIN95__ | |
131 | bool wxControl::MSWOnNotify(int idCtrl, | |
132 | WXLPARAM lParam, | |
133 | WXLPARAM* result) | |
134 | { | |
135 | wxCommandEvent event(wxEVT_NULL, m_windowId); | |
136 | wxEventType eventType = wxEVT_NULL; | |
137 | NMHDR *hdr1 = (NMHDR*) lParam; | |
138 | switch ( hdr1->code ) | |
139 | { | |
140 | case NM_CLICK: | |
141 | eventType = wxEVT_COMMAND_LEFT_CLICK; | |
142 | break; | |
143 | ||
144 | case NM_DBLCLK: | |
145 | eventType = wxEVT_COMMAND_LEFT_DCLICK; | |
146 | break; | |
147 | ||
148 | case NM_RCLICK: | |
149 | eventType = wxEVT_COMMAND_RIGHT_CLICK; | |
150 | break; | |
151 | ||
152 | case NM_RDBLCLK: | |
153 | eventType = wxEVT_COMMAND_RIGHT_DCLICK; | |
154 | break; | |
155 | ||
156 | case NM_SETFOCUS: | |
157 | eventType = wxEVT_COMMAND_SET_FOCUS; | |
158 | break; | |
159 | ||
160 | case NM_KILLFOCUS: | |
161 | eventType = wxEVT_COMMAND_KILL_FOCUS; | |
162 | break; | |
163 | ||
164 | case NM_RETURN: | |
165 | eventType = wxEVT_COMMAND_ENTER; | |
166 | break; | |
167 | ||
168 | default: | |
169 | return wxWindow::MSWOnNotify(idCtrl, lParam, result); | |
170 | } | |
171 | ||
172 | event.SetEventType(eventType); | |
173 | event.SetEventObject(this); | |
174 | ||
175 | return GetEventHandler()->ProcessEvent(event); | |
176 | } | |
177 | #endif // Win95 | |
178 | ||
179 | void wxControl::OnEraseBackground(wxEraseEvent& event) | |
180 | { | |
181 | // In general, you don't want to erase the background of a control, | |
182 | // or you'll get a flicker. | |
183 | // TODO: move this 'null' function into each control that | |
184 | // might flicker. | |
185 | ||
186 | RECT rect; | |
187 | ::GetClientRect(GetHwnd(), &rect); | |
188 | ||
189 | HBRUSH hBrush = ::CreateSolidBrush(wxColourToRGB(GetBackgroundColour())); | |
190 | ||
191 | HDC hdc = GetHdcOf((*event.GetDC())); | |
192 | int mode = ::SetMapMode(hdc, MM_TEXT); | |
193 | ||
194 | ::FillRect(hdc, &rect, hBrush); | |
195 | ::DeleteObject(hBrush); | |
196 | ::SetMapMode(hdc, mode); | |
197 | } | |
198 | ||
199 | WXDWORD wxControl::GetExStyle(WXDWORD& style, bool *want3D) const | |
200 | { | |
201 | WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, want3D); | |
202 | ||
203 | // Even with extended styles, need to combine with WS_BORDER for them to | |
204 | // look right. | |
205 | if ( *want3D || wxStyleHasBorder(m_windowStyle) ) | |
206 | style |= WS_BORDER; | |
207 | ||
208 | return exStyle; | |
209 | } | |
210 | ||
211 | // --------------------------------------------------------------------------- | |
212 | // global functions | |
213 | // --------------------------------------------------------------------------- | |
214 | ||
215 | // Call this repeatedly for several wnds to find the overall size | |
216 | // of the widget. | |
217 | // Call it initially with -1 for all values in rect. | |
218 | // Keep calling for other widgets, and rect will be modified | |
219 | // to calculate largest bounding rectangle. | |
220 | void wxFindMaxSize(WXHWND wnd, RECT *rect) | |
221 | { | |
222 | int left = rect->left; | |
223 | int right = rect->right; | |
224 | int top = rect->top; | |
225 | int bottom = rect->bottom; | |
226 | ||
227 | GetWindowRect((HWND) wnd, rect); | |
228 | ||
229 | if (left < 0) | |
230 | return; | |
231 | ||
232 | if (left < rect->left) | |
233 | rect->left = left; | |
234 | ||
235 | if (right > rect->right) | |
236 | rect->right = right; | |
237 | ||
238 | if (top < rect->top) | |
239 | rect->top = top; | |
240 | ||
241 | if (bottom > rect->bottom) | |
242 | rect->bottom = bottom; | |
243 | } | |
244 |