]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: windows.cpp | |
3 | // Purpose: wxWindow | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
a3622daa | 9 | // Licence: wxWindows license |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "window.h" | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
09914df7 | 20 | #pragma hdrstop |
2bda0e17 KB |
21 | #endif |
22 | ||
23 | #ifndef WX_PRECOMP | |
3a19e16d VZ |
24 | #include "wx/setup.h" |
25 | #include "wx/menu.h" | |
26 | #include "wx/dc.h" | |
27 | #include "wx/dcclient.h" | |
28 | #include "wx/utils.h" | |
29 | #include "wx/app.h" | |
30 | #include "wx/panel.h" | |
31 | #include "wx/layout.h" | |
32 | #include "wx/dialog.h" | |
33 | #include "wx/frame.h" | |
34 | #include "wx/listbox.h" | |
35 | #include "wx/button.h" | |
36 | #include "wx/settings.h" | |
37 | #include "wx/msgdlg.h" | |
341c92a8 VZ |
38 | |
39 | #include <stdio.h> | |
2bda0e17 KB |
40 | #endif |
41 | ||
47d67540 | 42 | #if wxUSE_OWNER_DRAWN |
09914df7 | 43 | #include "wx/ownerdrw.h" |
2bda0e17 KB |
44 | #endif |
45 | ||
47d67540 | 46 | #if wxUSE_DRAG_AND_DROP |
09914df7 | 47 | #include "wx/msw/ole/droptgt.h" |
2bda0e17 KB |
48 | #endif |
49 | ||
50 | #include "wx/menuitem.h" | |
47cbd6da | 51 | #include "wx/log.h" |
750b78ba JS |
52 | |
53 | #if wxUSE_TOOLTIPS | |
3a19e16d | 54 | #include "wx/tooltip.h" |
750b78ba JS |
55 | #endif |
56 | ||
dbda9e86 JS |
57 | #include "wx/intl.h" |
58 | #include "wx/log.h" | |
3a19e16d | 59 | |
2bda0e17 KB |
60 | #include "wx/msw/private.h" |
61 | ||
62 | #include <string.h> | |
63 | ||
64 | #ifndef __GNUWIN32__ | |
3a19e16d VZ |
65 | #include <shellapi.h> |
66 | #include <mmsystem.h> | |
2bda0e17 KB |
67 | #endif |
68 | ||
69 | #ifdef __WIN32__ | |
3a19e16d | 70 | #include <windowsx.h> |
2bda0e17 KB |
71 | #endif |
72 | ||
acbd13a3 | 73 | #if (defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__) |
3a19e16d | 74 | #include <commctrl.h> |
acbd13a3 | 75 | #endif |
3a19e16d | 76 | |
57c208c5 | 77 | #ifndef __TWIN32__ |
3a19e16d VZ |
78 | #ifdef __GNUWIN32__ |
79 | #include <wx/msw/gnuwin32/extra.h> | |
80 | #endif | |
57c208c5 | 81 | #endif |
2bda0e17 | 82 | |
3a19e16d | 83 | // all these are defined in <windows.h> |
2bda0e17 KB |
84 | #ifdef GetCharWidth |
85 | #undef GetCharWidth | |
86 | #endif | |
87 | ||
88 | #ifdef FindWindow | |
89 | #undef FindWindow | |
90 | #endif | |
91 | ||
92 | #ifdef GetClassName | |
93 | #undef GetClassName | |
94 | #endif | |
95 | ||
96 | #ifdef GetClassInfo | |
97 | #undef GetClassInfo | |
98 | #endif | |
99 | ||
b2aef89b | 100 | #ifdef __WXDEBUG__ |
09914df7 | 101 | const char *wxGetMessageName(int message); |
ea57084d | 102 | #endif //__WXDEBUG__ |
47cbd6da | 103 | |
f54f3bff | 104 | #define WINDOW_MARGIN 3 // This defines sensitivity of Leave events |
2bda0e17 KB |
105 | |
106 | wxMenu *wxCurrentPopupMenu = NULL; | |
cde9f08e | 107 | extern wxList WXDLLEXPORT wxPendingDelete; |
2bda0e17 KB |
108 | |
109 | void wxRemoveHandleAssociation(wxWindow *win); | |
110 | void wxAssociateWinWithHandle(HWND hWnd, wxWindow *win); | |
111 | wxWindow *wxFindWinFromHandle(WXHWND hWnd); | |
112 | ||
113 | #if !USE_SHARED_LIBRARY | |
3a19e16d | 114 | IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxEvtHandler) |
cf65ad8d | 115 | #endif |
2bda0e17 KB |
116 | |
117 | BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler) | |
cf65ad8d VZ |
118 | EVT_CHAR(wxWindow::OnChar) |
119 | EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground) | |
120 | EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged) | |
121 | EVT_INIT_DIALOG(wxWindow::OnInitDialog) | |
122 | EVT_IDLE(wxWindow::OnIdle) | |
2bda0e17 KB |
123 | END_EVENT_TABLE() |
124 | ||
2bda0e17 | 125 | // Find an item given the MS Windows id |
debe6624 | 126 | wxWindow *wxWindow::FindItem(int id) const |
2bda0e17 | 127 | { |
c0ed460c JS |
128 | // if (!GetChildren()) |
129 | // return NULL; | |
130 | wxNode *current = GetChildren().First(); | |
2d0a075d JS |
131 | while (current) |
132 | { | |
133 | wxWindow *childWin = (wxWindow *)current->Data(); | |
2bda0e17 | 134 | |
2d0a075d JS |
135 | wxWindow *wnd = childWin->FindItem(id) ; |
136 | if (wnd) | |
137 | return wnd ; | |
2bda0e17 | 138 | |
2d0a075d JS |
139 | if (childWin->IsKindOf(CLASSINFO(wxControl))) |
140 | { | |
141 | wxControl *item = (wxControl *)childWin; | |
ce3ed50d | 142 | if (item->GetId() == id) |
2d0a075d JS |
143 | return item; |
144 | else | |
145 | { | |
146 | // In case it's a 'virtual' control (e.g. radiobox) | |
147 | if (item->GetSubcontrols().Member((wxObject *)id)) | |
148 | return item; | |
149 | } | |
150 | } | |
151 | current = current->Next(); | |
2bda0e17 | 152 | } |
2d0a075d | 153 | return NULL; |
2bda0e17 KB |
154 | } |
155 | ||
156 | // Find an item given the MS Windows handle | |
debe6624 | 157 | wxWindow *wxWindow::FindItemByHWND(WXHWND hWnd, bool controlOnly) const |
2bda0e17 | 158 | { |
c0ed460c JS |
159 | // if (!GetChildren()) |
160 | // return NULL; | |
161 | wxNode *current = GetChildren().First(); | |
2d0a075d | 162 | while (current) |
2bda0e17 | 163 | { |
2d0a075d JS |
164 | wxObject *obj = (wxObject *)current->Data() ; |
165 | // Do a recursive search. | |
166 | wxWindow *parent = (wxWindow *)obj ; | |
167 | wxWindow *wnd = parent->FindItemByHWND(hWnd) ; | |
168 | if (wnd) | |
169 | return wnd ; | |
170 | ||
171 | if ((!controlOnly) || obj->IsKindOf(CLASSINFO(wxControl))) | |
172 | { | |
173 | wxWindow *item = (wxWindow *)current->Data(); | |
174 | if ((HWND)(item->GetHWND()) == (HWND) hWnd) | |
175 | return item; | |
176 | else | |
177 | { | |
178 | if ( item->ContainsHWND(hWnd) ) | |
179 | return item; | |
180 | } | |
181 | } | |
182 | current = current->Next(); | |
2bda0e17 | 183 | } |
2d0a075d | 184 | return NULL; |
2bda0e17 KB |
185 | } |
186 | ||
187 | // Default command handler | |
debe6624 | 188 | bool wxWindow::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id)) |
2bda0e17 | 189 | { |
2d0a075d | 190 | return FALSE; |
2bda0e17 KB |
191 | } |
192 | ||
fd3f686c | 193 | bool wxWindow::MSWNotify(WXWPARAM WXUNUSED(wParam), |
3a19e16d | 194 | WXLPARAM lParam, |
fd3f686c | 195 | WXLPARAM* WXUNUSED(result)) |
2bda0e17 | 196 | { |
acbd13a3 | 197 | #ifdef __WIN95__ |
cb1a1dc9 | 198 | #if wxUSE_TOOLTIPS |
3a19e16d VZ |
199 | NMHDR* hdr = (NMHDR *)lParam; |
200 | if ( hdr->code == TTN_NEEDTEXT && m_tooltip ) | |
201 | { | |
202 | TOOLTIPTEXT *ttt = (TOOLTIPTEXT *)lParam; | |
203 | ttt->lpszText = (char *)m_tooltip->GetTip().c_str(); | |
204 | ||
205 | // processed | |
206 | return TRUE; | |
207 | } | |
cb1a1dc9 | 208 | #endif |
acbd13a3 | 209 | #endif |
3a19e16d | 210 | |
2d0a075d | 211 | return FALSE; |
2bda0e17 KB |
212 | } |
213 | ||
debe6624 | 214 | void wxWindow::PreDelete(WXHDC WXUNUSED(dc)) |
2bda0e17 KB |
215 | { |
216 | } | |
217 | ||
218 | WXHWND wxWindow::GetHWND(void) const | |
219 | { | |
2d0a075d | 220 | return (WXHWND) m_hWnd; |
2bda0e17 KB |
221 | } |
222 | ||
223 | void wxWindow::SetHWND(WXHWND hWnd) | |
224 | { | |
2d0a075d | 225 | m_hWnd = hWnd; |
2bda0e17 KB |
226 | } |
227 | ||
fd3f686c VZ |
228 | // ---------------------------------------------------------------------------- |
229 | // constructors and such | |
230 | // ---------------------------------------------------------------------------- | |
231 | ||
232 | void wxWindow::Init() | |
2bda0e17 | 233 | { |
2d0a075d JS |
234 | // Generic |
235 | m_windowId = 0; | |
236 | m_isShown = TRUE; | |
237 | m_windowStyle = 0; | |
238 | m_windowParent = NULL; | |
239 | m_windowEventHandler = this; | |
2d0a075d JS |
240 | m_windowCursor = *wxSTANDARD_CURSOR; |
241 | m_children = new wxList; | |
242 | m_doubleClickAllowed = 0 ; | |
243 | m_winCaptured = FALSE; | |
244 | m_constraints = NULL; | |
245 | m_constraintsInvolvedIn = NULL; | |
246 | m_windowSizer = NULL; | |
247 | m_sizerParent = NULL; | |
248 | m_autoLayout = FALSE; | |
249 | m_windowValidator = NULL; | |
250 | ||
251 | // MSW-specific | |
252 | m_hWnd = 0; | |
253 | m_winEnabled = TRUE; | |
fd3f686c VZ |
254 | m_caretWidth = m_caretHeight = 0; |
255 | m_caretEnabled = | |
2d0a075d JS |
256 | m_caretShown = FALSE; |
257 | m_inOnSize = FALSE; | |
fd3f686c VZ |
258 | m_minSizeX = |
259 | m_minSizeY = | |
260 | m_maxSizeX = | |
2d0a075d | 261 | m_maxSizeY = -1; |
fd3f686c | 262 | |
2d0a075d JS |
263 | m_isBeingDeleted = FALSE; |
264 | m_oldWndProc = 0; | |
2bda0e17 | 265 | #ifndef __WIN32__ |
2d0a075d | 266 | m_globalHandle = 0; |
2bda0e17 | 267 | #endif |
2d0a075d | 268 | m_useCtl3D = FALSE; |
fd3f686c | 269 | m_mouseInWindow = FALSE; |
2bda0e17 | 270 | |
fd3f686c | 271 | m_windowParent = NULL; |
2d0a075d | 272 | m_defaultItem = NULL; |
2bda0e17 | 273 | |
2d0a075d | 274 | wxSystemSettings settings; |
2bda0e17 | 275 | |
2d0a075d | 276 | m_backgroundColour = settings.GetSystemColour(wxSYS_COLOUR_3DFACE) ; |
2d0a075d | 277 | m_foregroundColour = *wxBLACK; |
2bda0e17 | 278 | |
2d0a075d JS |
279 | // wxWnd |
280 | m_lastMsg = 0; | |
281 | m_lastWParam = 0; | |
282 | m_lastLParam = 0; | |
2d0a075d | 283 | m_hMenu = 0; |
2bda0e17 | 284 | |
2d0a075d JS |
285 | m_xThumbSize = 0; |
286 | m_yThumbSize = 0; | |
287 | m_backgroundTransparent = FALSE; | |
2bda0e17 | 288 | |
2d0a075d JS |
289 | m_lastXPos = (float)-1.0; |
290 | m_lastYPos = (float)-1.0; | |
291 | m_lastEvent = -1; | |
292 | m_returnCode = 0; | |
2bda0e17 | 293 | |
47d67540 | 294 | #if wxUSE_DRAG_AND_DROP |
2d0a075d | 295 | m_pDropTarget = NULL; |
2bda0e17 | 296 | #endif |
3a19e16d | 297 | |
cb1a1dc9 | 298 | #if wxUSE_TOOLTIPS |
3a19e16d | 299 | m_tooltip = NULL; |
cb1a1dc9 | 300 | #endif |
2bda0e17 KB |
301 | } |
302 | ||
fd3f686c VZ |
303 | wxWindow::wxWindow() |
304 | { | |
305 | Init(); | |
306 | } | |
307 | ||
2bda0e17 | 308 | // Destructor |
fd3f686c | 309 | wxWindow::~wxWindow() |
2bda0e17 | 310 | { |
2d0a075d | 311 | m_isBeingDeleted = TRUE; |
2bda0e17 | 312 | |
3a19e16d VZ |
313 | // first of all, delete the things on which nothing else depends |
314 | ||
cb1a1dc9 | 315 | #if wxUSE_TOOLTIPS |
3a19e16d | 316 | wxDELETE(m_tooltip); |
cb1a1dc9 | 317 | #endif |
3a19e16d | 318 | |
2d0a075d JS |
319 | // JACS - if behaviour is odd, restore this |
320 | // to the start of ~wxWindow. Vadim has changed | |
321 | // it to nearer the end. Unsure of side-effects | |
322 | // e.g. when deleting associated global data. | |
323 | // Restore old Window proc, if required | |
324 | // UnsubclassWin(); | |
2bda0e17 | 325 | |
2d0a075d JS |
326 | // Have to delete constraints/sizer FIRST otherwise |
327 | // sizers may try to look at deleted windows as they | |
328 | // delete themselves. | |
47d67540 | 329 | #if wxUSE_CONSTRAINTS |
2d0a075d | 330 | DeleteRelatedConstraints(); |
3a19e16d | 331 | |
2d0a075d JS |
332 | if (m_constraints) |
333 | { | |
334 | // This removes any dangling pointers to this window | |
335 | // in other windows' constraintsInvolvedIn lists. | |
336 | UnsetConstraints(m_constraints); | |
337 | delete m_constraints; | |
338 | m_constraints = NULL; | |
339 | } | |
3a19e16d VZ |
340 | |
341 | wxDELETE(m_windowSizer); | |
342 | ||
2d0a075d JS |
343 | // If this is a child of a sizer, remove self from parent |
344 | if (m_sizerParent) | |
345 | m_sizerParent->RemoveChild((wxWindow *)this); | |
2bda0e17 | 346 | #endif |
c085e333 | 347 | |
2d0a075d JS |
348 | // wxWnd |
349 | MSWDetachWindowMenu(); | |
2bda0e17 | 350 | |
2d0a075d JS |
351 | if (m_windowParent) |
352 | m_windowParent->RemoveChild(this); | |
2bda0e17 | 353 | |
2d0a075d | 354 | DestroyChildren(); |
2bda0e17 | 355 | |
2d0a075d JS |
356 | if (m_hWnd) |
357 | ::DestroyWindow((HWND)m_hWnd); | |
195896c7 | 358 | |
2d0a075d JS |
359 | wxRemoveHandleAssociation(this); |
360 | m_hWnd = 0; | |
2bda0e17 | 361 | #ifndef __WIN32__ |
2d0a075d JS |
362 | if (m_globalHandle) |
363 | { | |
364 | GlobalFree((HGLOBAL) m_globalHandle); | |
365 | m_globalHandle = 0; | |
366 | } | |
2bda0e17 | 367 | #endif |
c085e333 | 368 | |
2d0a075d JS |
369 | delete m_children; |
370 | m_children = NULL; | |
2bda0e17 | 371 | |
2d0a075d JS |
372 | // Just in case the window has been Closed, but |
373 | // we're then deleting immediately: don't leave | |
374 | // dangling pointers. | |
375 | wxPendingDelete.DeleteObject(this); | |
2bda0e17 | 376 | |
2d0a075d JS |
377 | // Just in case we've loaded a top-level window via |
378 | // wxWindow::LoadNativeDialog but we weren't a dialog | |
379 | // class | |
380 | wxTopLevelWindows.DeleteObject(this); | |
2bda0e17 | 381 | |
2d0a075d JS |
382 | if ( m_windowValidator ) |
383 | delete m_windowValidator; | |
2bda0e17 | 384 | |
c085e333 | 385 | // Restore old Window proc, if required |
2d0a075d JS |
386 | // and remove hWnd <-> wxWindow association |
387 | UnsubclassWin(); | |
2bda0e17 KB |
388 | } |
389 | ||
390 | // Destroy the window (delayed, if a managed window) | |
fd3f686c | 391 | bool wxWindow::Destroy() |
2bda0e17 KB |
392 | { |
393 | delete this; | |
394 | return TRUE; | |
395 | } | |
396 | ||
397 | extern char wxCanvasClassName[]; | |
398 | ||
fd3f686c | 399 | // real construction (Init() must have been called before!) |
debe6624 | 400 | bool wxWindow::Create(wxWindow *parent, wxWindowID id, |
2d0a075d JS |
401 | const wxPoint& pos, |
402 | const wxSize& size, | |
403 | long style, | |
404 | const wxString& name) | |
405 | { | |
fd3f686c | 406 | wxCHECK_MSG( parent, FALSE, "can't create wxWindow without parent" ); |
2bda0e17 | 407 | |
fd3f686c | 408 | parent->AddChild(this); |
2bda0e17 | 409 | |
2d0a075d | 410 | SetName(name); |
2bda0e17 | 411 | |
2d0a075d JS |
412 | if ( id == -1 ) |
413 | m_windowId = (int)NewControlId(); | |
414 | else | |
415 | m_windowId = id; | |
2bda0e17 | 416 | |
2d0a075d JS |
417 | int x = pos.x; |
418 | int y = pos.y; | |
419 | int width = size.x; | |
420 | int height = size.y; | |
2bda0e17 | 421 | |
386af6a2 JS |
422 | // To be consistent with wxGTK |
423 | if (width == -1) | |
424 | width = 20; | |
425 | if (height == -1) | |
426 | height = 20; | |
427 | ||
2d0a075d | 428 | wxSystemSettings settings; |
2bda0e17 | 429 | |
2d0a075d | 430 | m_windowStyle = style; |
2bda0e17 | 431 | |
2d0a075d JS |
432 | DWORD msflags = 0; |
433 | if (style & wxBORDER) | |
434 | msflags |= WS_BORDER; | |
435 | if (style & wxTHICK_FRAME) | |
436 | msflags |= WS_THICKFRAME; | |
1c089c47 | 437 | |
2d0a075d JS |
438 | msflags |= WS_CHILD | WS_VISIBLE; |
439 | if (style & wxCLIP_CHILDREN) | |
440 | msflags |= WS_CLIPCHILDREN; | |
2bda0e17 | 441 | |
2d0a075d JS |
442 | bool want3D; |
443 | WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ; | |
2bda0e17 | 444 | |
2d0a075d JS |
445 | // Even with extended styles, need to combine with WS_BORDER |
446 | // for them to look right. | |
447 | if (want3D || (m_windowStyle & wxSIMPLE_BORDER) || (m_windowStyle & wxRAISED_BORDER) || | |
448 | (m_windowStyle & wxSUNKEN_BORDER) || (m_windowStyle & wxDOUBLE_BORDER)) | |
449 | msflags |= WS_BORDER; | |
2bda0e17 | 450 | |
2d0a075d | 451 | MSWCreate(m_windowId, parent, wxCanvasClassName, this, NULL, |
fd3f686c | 452 | x, y, width, height, msflags, NULL, exStyle); |
2bda0e17 | 453 | |
2d0a075d | 454 | return TRUE; |
2bda0e17 KB |
455 | } |
456 | ||
fd3f686c | 457 | void wxWindow::SetFocus() |
2bda0e17 | 458 | { |
2d0a075d JS |
459 | HWND hWnd = (HWND) GetHWND(); |
460 | if (hWnd) | |
461 | ::SetFocus(hWnd); | |
2bda0e17 KB |
462 | } |
463 | ||
debe6624 | 464 | void wxWindow::Enable(bool enable) |
2bda0e17 | 465 | { |
2d0a075d JS |
466 | m_winEnabled = enable; |
467 | HWND hWnd = (HWND) GetHWND(); | |
468 | if (hWnd) | |
469 | ::EnableWindow(hWnd, (BOOL)enable); | |
2bda0e17 KB |
470 | } |
471 | ||
fd3f686c | 472 | void wxWindow::CaptureMouse() |
2bda0e17 | 473 | { |
2d0a075d JS |
474 | HWND hWnd = (HWND) GetHWND(); |
475 | if (hWnd && !m_winCaptured) | |
476 | { | |
477 | SetCapture(hWnd); | |
478 | m_winCaptured = TRUE; | |
479 | } | |
2bda0e17 KB |
480 | } |
481 | ||
fd3f686c | 482 | void wxWindow::ReleaseMouse() |
2bda0e17 | 483 | { |
2d0a075d JS |
484 | if (m_winCaptured) |
485 | { | |
486 | ReleaseCapture(); | |
487 | m_winCaptured = FALSE; | |
488 | } | |
2bda0e17 KB |
489 | } |
490 | ||
088a95f5 JS |
491 | void wxWindow::SetAcceleratorTable(const wxAcceleratorTable& accel) |
492 | { | |
493 | m_acceleratorTable = accel; | |
494 | } | |
495 | ||
496 | ||
2bda0e17 KB |
497 | // Push/pop event handler (i.e. allow a chain of event handlers |
498 | // be searched) | |
499 | void wxWindow::PushEventHandler(wxEvtHandler *handler) | |
500 | { | |
2d0a075d JS |
501 | handler->SetNextHandler(GetEventHandler()); |
502 | SetEventHandler(handler); | |
2bda0e17 KB |
503 | } |
504 | ||
505 | wxEvtHandler *wxWindow::PopEventHandler(bool deleteHandler) | |
506 | { | |
2d0a075d | 507 | if ( GetEventHandler() ) |
564b2609 | 508 | { |
2d0a075d JS |
509 | wxEvtHandler *handlerA = GetEventHandler(); |
510 | wxEvtHandler *handlerB = handlerA->GetNextHandler(); | |
511 | handlerA->SetNextHandler(NULL); | |
512 | SetEventHandler(handlerB); | |
513 | if ( deleteHandler ) | |
514 | { | |
515 | delete handlerA; | |
516 | return NULL; | |
517 | } | |
518 | else | |
519 | return handlerA; | |
564b2609 VZ |
520 | } |
521 | else | |
2d0a075d | 522 | return NULL; |
2bda0e17 KB |
523 | } |
524 | ||
47d67540 | 525 | #if wxUSE_DRAG_AND_DROP |
2bda0e17 KB |
526 | |
527 | void wxWindow::SetDropTarget(wxDropTarget *pDropTarget) | |
528 | { | |
2d0a075d JS |
529 | if ( m_pDropTarget != 0 ) { |
530 | m_pDropTarget->Revoke(m_hWnd); | |
531 | delete m_pDropTarget; | |
532 | } | |
195896c7 | 533 | |
2d0a075d JS |
534 | m_pDropTarget = pDropTarget; |
535 | if ( m_pDropTarget != 0 ) | |
536 | m_pDropTarget->Register(m_hWnd); | |
2bda0e17 KB |
537 | } |
538 | ||
3a19e16d VZ |
539 | #endif // wxUSE_DRAG_AND_DROP |
540 | ||
2bda0e17 KB |
541 | |
542 | //old style file-manager drag&drop support | |
543 | // I think we should retain the old-style | |
544 | // DragAcceptFiles in parallel with SetDropTarget. | |
545 | // JACS | |
debe6624 | 546 | void wxWindow::DragAcceptFiles(bool accept) |
2bda0e17 | 547 | { |
2d0a075d JS |
548 | HWND hWnd = (HWND) GetHWND(); |
549 | if (hWnd) | |
550 | ::DragAcceptFiles(hWnd, (BOOL)accept); | |
2bda0e17 KB |
551 | } |
552 | ||
3a19e16d VZ |
553 | // ---------------------------------------------------------------------------- |
554 | // tooltips | |
555 | // ---------------------------------------------------------------------------- | |
556 | ||
cb1a1dc9 VZ |
557 | #if wxUSE_TOOLTIPS |
558 | ||
3a19e16d VZ |
559 | void wxWindow::SetToolTip(const wxString &tip) |
560 | { | |
561 | SetToolTip(new wxToolTip(tip)); | |
562 | } | |
563 | ||
564 | void wxWindow::SetToolTip(wxToolTip *tooltip) | |
565 | { | |
566 | if ( m_tooltip ) | |
567 | delete m_tooltip; | |
568 | ||
569 | m_tooltip = tooltip; | |
570 | m_tooltip->SetWindow(this); | |
571 | } | |
572 | ||
cb1a1dc9 VZ |
573 | #endif // wxUSE_TOOLTIPS |
574 | ||
2bda0e17 KB |
575 | // Get total size |
576 | void wxWindow::GetSize(int *x, int *y) const | |
577 | { | |
2d0a075d JS |
578 | HWND hWnd = (HWND) GetHWND(); |
579 | RECT rect; | |
580 | GetWindowRect(hWnd, &rect); | |
581 | *x = rect.right - rect.left; | |
582 | *y = rect.bottom - rect.top; | |
2bda0e17 KB |
583 | } |
584 | ||
585 | void wxWindow::GetPosition(int *x, int *y) const | |
586 | { | |
2d0a075d JS |
587 | HWND hWnd = (HWND) GetHWND(); |
588 | HWND hParentWnd = 0; | |
589 | if (GetParent()) | |
590 | hParentWnd = (HWND) GetParent()->GetHWND(); | |
81d66cf3 | 591 | |
2d0a075d JS |
592 | RECT rect; |
593 | GetWindowRect(hWnd, &rect); | |
594 | ||
595 | // Since we now have the absolute screen coords, | |
596 | // if there's a parent we must subtract its top left corner | |
597 | POINT point; | |
598 | point.x = rect.left; | |
599 | point.y = rect.top; | |
600 | if (hParentWnd) | |
601 | { | |
602 | ::ScreenToClient(hParentWnd, &point); | |
603 | } | |
604 | ||
605 | // We may be faking the client origin. | |
606 | // So a window that's really at (0, 30) may appear | |
607 | // (to wxWin apps) to be at (0, 0). | |
608 | if (GetParent()) | |
609 | { | |
610 | wxPoint pt(GetParent()->GetClientAreaOrigin()); | |
611 | point.x -= pt.x; | |
612 | point.y -= pt.y; | |
613 | } | |
614 | *x = point.x; | |
615 | *y = point.y; | |
2bda0e17 KB |
616 | } |
617 | ||
618 | void wxWindow::ScreenToClient(int *x, int *y) const | |
619 | { | |
2d0a075d JS |
620 | HWND hWnd = (HWND) GetHWND(); |
621 | POINT pt; | |
622 | pt.x = *x; | |
623 | pt.y = *y; | |
2d0a075d | 624 | |
87d1e11f | 625 | ::ScreenToClient(hWnd, &pt); |
0757d27c | 626 | |
2d0a075d JS |
627 | *x = pt.x; |
628 | *y = pt.y; | |
2bda0e17 KB |
629 | } |
630 | ||
631 | void wxWindow::ClientToScreen(int *x, int *y) const | |
632 | { | |
2d0a075d JS |
633 | HWND hWnd = (HWND) GetHWND(); |
634 | POINT pt; | |
635 | pt.x = *x; | |
636 | pt.y = *y; | |
637 | ||
2d0a075d | 638 | ::ClientToScreen(hWnd, &pt); |
2bda0e17 | 639 | |
2d0a075d JS |
640 | *x = pt.x; |
641 | *y = pt.y; | |
2bda0e17 KB |
642 | } |
643 | ||
644 | void wxWindow::SetCursor(const wxCursor& cursor) | |
645 | { | |
2d0a075d JS |
646 | m_windowCursor = cursor; |
647 | if (m_windowCursor.Ok()) | |
648 | { | |
649 | HWND hWnd = (HWND) GetHWND(); | |
2bda0e17 | 650 | |
2d0a075d JS |
651 | // Change the cursor NOW if we're within the correct window |
652 | POINT point; | |
653 | ::GetCursorPos(&point); | |
2bda0e17 | 654 | |
2d0a075d JS |
655 | RECT rect; |
656 | ::GetWindowRect(hWnd, &rect); | |
2bda0e17 | 657 | |
2d0a075d JS |
658 | if (::PtInRect(&rect, point) && !wxIsBusy()) |
659 | ::SetCursor((HCURSOR) m_windowCursor.GetHCURSOR()); | |
660 | } | |
2bda0e17 | 661 | |
2d0a075d JS |
662 | // This will cause big reentrancy problems if wxFlushEvents is implemented. |
663 | // wxFlushEvents(); | |
664 | // return old_cursor; | |
2bda0e17 KB |
665 | } |
666 | ||
667 | ||
668 | // Get size *available for subwindows* i.e. excluding menu bar etc. | |
2bda0e17 KB |
669 | void wxWindow::GetClientSize(int *x, int *y) const |
670 | { | |
2d0a075d JS |
671 | HWND hWnd = (HWND) GetHWND(); |
672 | RECT rect; | |
673 | GetClientRect(hWnd, &rect); | |
674 | *x = rect.right; | |
675 | *y = rect.bottom; | |
2bda0e17 KB |
676 | } |
677 | ||
debe6624 | 678 | void wxWindow::SetSize(int x, int y, int width, int height, int sizeFlags) |
2bda0e17 | 679 | { |
2d0a075d JS |
680 | int currentX, currentY; |
681 | GetPosition(¤tX, ¤tY); | |
72fd19a1 JS |
682 | int currentW,currentH; |
683 | GetSize(¤tW, ¤tH); | |
684 | ||
685 | if (x == currentX && y == currentY && width == currentW && height == currentH) | |
686 | return; | |
687 | ||
2d0a075d JS |
688 | int actualWidth = width; |
689 | int actualHeight = height; | |
690 | int actualX = x; | |
691 | int actualY = y; | |
692 | if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
693 | actualX = currentX; | |
694 | if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
695 | actualY = currentY; | |
696 | ||
697 | AdjustForParentClientOrigin(actualX, actualY, sizeFlags); | |
698 | ||
2d0a075d JS |
699 | if (width == -1) |
700 | actualWidth = currentW ; | |
701 | if (height == -1) | |
702 | actualHeight = currentH ; | |
81d66cf3 | 703 | |
2d0a075d JS |
704 | HWND hWnd = (HWND) GetHWND(); |
705 | if (hWnd) | |
706 | MoveWindow(hWnd, actualX, actualY, actualWidth, actualHeight, (BOOL)TRUE); | |
2bda0e17 KB |
707 | } |
708 | ||
debe6624 | 709 | void wxWindow::SetClientSize(int width, int height) |
2bda0e17 | 710 | { |
2d0a075d JS |
711 | wxWindow *parent = GetParent(); |
712 | HWND hWnd = (HWND) GetHWND(); | |
713 | HWND hParentWnd = (HWND) (HWND) parent->GetHWND(); | |
2bda0e17 | 714 | |
2d0a075d JS |
715 | RECT rect; |
716 | GetClientRect(hWnd, &rect); | |
2bda0e17 | 717 | |
2d0a075d JS |
718 | RECT rect2; |
719 | GetWindowRect(hWnd, &rect2); | |
2bda0e17 | 720 | |
2d0a075d JS |
721 | // Find the difference between the entire window (title bar and all) |
722 | // and the client area; add this to the new client size to move the | |
723 | // window | |
724 | int actual_width = rect2.right - rect2.left - rect.right + width; | |
725 | int actual_height = rect2.bottom - rect2.top - rect.bottom + height; | |
2bda0e17 | 726 | |
2d0a075d JS |
727 | // If there's a parent, must subtract the parent's top left corner |
728 | // since MoveWindow moves relative to the parent | |
2bda0e17 | 729 | |
2d0a075d JS |
730 | POINT point; |
731 | point.x = rect2.left; | |
732 | point.y = rect2.top; | |
733 | if (parent) | |
734 | { | |
735 | ::ScreenToClient(hParentWnd, &point); | |
736 | } | |
2bda0e17 | 737 | |
2d0a075d | 738 | MoveWindow(hWnd, point.x, point.y, actual_width, actual_height, (BOOL)TRUE); |
debe6624 | 739 | |
2d0a075d JS |
740 | wxSizeEvent event(wxSize(width, height), m_windowId); |
741 | event.SetEventObject(this); | |
742 | GetEventHandler()->ProcessEvent(event); | |
2bda0e17 KB |
743 | } |
744 | ||
81d66cf3 JS |
745 | // For implementation purposes - sometimes decorations make the client area |
746 | // smaller | |
747 | wxPoint wxWindow::GetClientAreaOrigin() const | |
748 | { | |
749 | return wxPoint(0, 0); | |
750 | } | |
751 | ||
752 | // Makes an adjustment to the window position (for example, a frame that has | |
753 | // a toolbar that it manages itself). | |
754 | void wxWindow::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) | |
755 | { | |
756 | if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent()) | |
757 | { | |
758 | wxPoint pt(GetParent()->GetClientAreaOrigin()); | |
759 | x += pt.x; y += pt.y; | |
760 | } | |
761 | } | |
762 | ||
debe6624 | 763 | bool wxWindow::Show(bool show) |
2bda0e17 | 764 | { |
aed0ed3c | 765 | m_isShown = show; |
2d0a075d JS |
766 | HWND hWnd = (HWND) GetHWND(); |
767 | int cshow; | |
768 | if (show) | |
769 | cshow = SW_SHOW; | |
770 | else | |
771 | cshow = SW_HIDE; | |
aed0ed3c | 772 | ShowWindow(hWnd, cshow); |
2d0a075d JS |
773 | if (show) |
774 | { | |
775 | BringWindowToTop(hWnd); | |
776 | // Next line causes a crash on NT, apparently. | |
777 | // UpdateWindow(hWnd); // Should this be here or will it cause inefficiency? | |
778 | } | |
779 | return TRUE; | |
2bda0e17 KB |
780 | } |
781 | ||
782 | bool wxWindow::IsShown(void) const | |
783 | { | |
aed0ed3c JS |
784 | // Can't rely on IsWindowVisible, since it will return FALSE |
785 | // if the parent is not visible. | |
786 | return m_isShown; | |
787 | // int ret = ::IsWindowVisible((HWND) GetHWND()) ; | |
788 | // return (ret != 0); | |
2bda0e17 KB |
789 | } |
790 | ||
791 | int wxWindow::GetCharHeight(void) const | |
792 | { | |
2d0a075d JS |
793 | TEXTMETRIC lpTextMetric; |
794 | HWND hWnd = (HWND) GetHWND(); | |
795 | HDC dc = ::GetDC(hWnd); | |
2bda0e17 | 796 | |
2d0a075d JS |
797 | GetTextMetrics(dc, &lpTextMetric); |
798 | ::ReleaseDC(hWnd, dc); | |
2bda0e17 | 799 | |
2d0a075d | 800 | return lpTextMetric.tmHeight; |
2bda0e17 KB |
801 | } |
802 | ||
803 | int wxWindow::GetCharWidth(void) const | |
804 | { | |
2d0a075d JS |
805 | TEXTMETRIC lpTextMetric; |
806 | HWND hWnd = (HWND) GetHWND(); | |
807 | HDC dc = ::GetDC(hWnd); | |
2bda0e17 | 808 | |
2d0a075d JS |
809 | GetTextMetrics(dc, &lpTextMetric); |
810 | ::ReleaseDC(hWnd, dc); | |
2bda0e17 | 811 | |
2d0a075d | 812 | return lpTextMetric.tmAveCharWidth; |
2bda0e17 KB |
813 | } |
814 | ||
815 | void wxWindow::GetTextExtent(const wxString& string, int *x, int *y, | |
2d0a075d | 816 | int *descent, int *externalLeading, const wxFont *theFont, bool) const |
2bda0e17 | 817 | { |
2d0a075d JS |
818 | wxFont *fontToUse = (wxFont *)theFont; |
819 | if (!fontToUse) | |
820 | fontToUse = (wxFont *) & m_windowFont; | |
2bda0e17 | 821 | |
2d0a075d JS |
822 | HWND hWnd = (HWND) GetHWND(); |
823 | HDC dc = ::GetDC(hWnd); | |
2bda0e17 | 824 | |
c085e333 | 825 | HFONT fnt = 0; |
2d0a075d JS |
826 | HFONT was = 0; |
827 | if (fontToUse && fontToUse->Ok()) | |
828 | { | |
fd3f686c VZ |
829 | fnt = (HFONT)fontToUse->GetResourceHandle(); |
830 | if ( fnt ) | |
2d0a075d JS |
831 | was = (HFONT) SelectObject(dc,fnt) ; |
832 | } | |
2bda0e17 | 833 | |
2d0a075d JS |
834 | SIZE sizeRect; |
835 | TEXTMETRIC tm; | |
836 | GetTextExtentPoint(dc, (const char *)string, (int)string.Length(), &sizeRect); | |
837 | GetTextMetrics(dc, &tm); | |
2bda0e17 | 838 | |
c085e333 | 839 | if (fontToUse && fnt && was) |
2d0a075d | 840 | SelectObject(dc,was) ; |
2bda0e17 | 841 | |
2d0a075d | 842 | ReleaseDC(hWnd, dc); |
2bda0e17 | 843 | |
2d0a075d JS |
844 | *x = sizeRect.cx; |
845 | *y = sizeRect.cy; | |
846 | if (descent) *descent = tm.tmDescent; | |
847 | if (externalLeading) *externalLeading = tm.tmExternalLeading; | |
2bda0e17 | 848 | |
2d0a075d JS |
849 | // if (fontToUse) |
850 | // fontToUse->ReleaseResource(); | |
2bda0e17 KB |
851 | } |
852 | ||
16e93305 | 853 | void wxWindow::Refresh(bool eraseBack, const wxRect *rect) |
2bda0e17 | 854 | { |
2d0a075d JS |
855 | HWND hWnd = (HWND) GetHWND(); |
856 | if (hWnd) | |
2bda0e17 | 857 | { |
2d0a075d JS |
858 | if (rect) |
859 | { | |
860 | RECT mswRect; | |
861 | mswRect.left = rect->x; | |
862 | mswRect.top = rect->y; | |
863 | mswRect.right = rect->x + rect->width; | |
864 | mswRect.bottom = rect->y + rect->height; | |
865 | ||
866 | ::InvalidateRect(hWnd, &mswRect, eraseBack); | |
867 | } | |
868 | else | |
869 | ::InvalidateRect(hWnd, NULL, eraseBack); | |
2bda0e17 | 870 | } |
2bda0e17 KB |
871 | } |
872 | ||
a02eb1d2 VZ |
873 | bool wxWindow::ProcessEvent(wxEvent& event) |
874 | { | |
2d0a075d JS |
875 | // we save here the information about the last message because it might be |
876 | // overwritten if the event handler sends any messages to our window (case | |
877 | // in point: wxNotebook::OnSize) - and then if we call Default() later | |
878 | // (which is done quite often if the message is not processed) it will use | |
879 | // incorrect values for m_lastXXX variables | |
880 | WXUINT lastMsg = m_lastMsg; | |
881 | WXWPARAM lastWParam = m_lastWParam; | |
882 | WXLPARAM lastLParam = m_lastLParam; | |
a02eb1d2 | 883 | |
2d0a075d JS |
884 | // call the base version |
885 | bool bProcessed = wxEvtHandler::ProcessEvent(event); | |
a02eb1d2 | 886 | |
2d0a075d JS |
887 | // restore |
888 | m_lastMsg = lastMsg; | |
889 | m_lastWParam = lastWParam; | |
890 | m_lastLParam = lastLParam; | |
a02eb1d2 | 891 | |
2d0a075d | 892 | return bProcessed; |
a02eb1d2 VZ |
893 | } |
894 | ||
2bda0e17 KB |
895 | // Hook for new window just as it's being created, |
896 | // when the window isn't yet associated with the handle | |
897 | wxWindow *wxWndHook = NULL; | |
898 | ||
1c089c47 | 899 | // Main window proc |
2bda0e17 KB |
900 | LRESULT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) |
901 | { | |
2d0a075d | 902 | wxWindow *wnd = wxFindWinFromHandle((WXHWND) hWnd); |
2bda0e17 | 903 | |
2d0a075d JS |
904 | if (!wnd && wxWndHook) |
905 | { | |
906 | wxAssociateWinWithHandle(hWnd, wxWndHook); | |
907 | wnd = wxWndHook; | |
908 | wxWndHook = NULL; | |
909 | wnd->m_hWnd = (WXHWND) hWnd; | |
910 | } | |
ea57084d | 911 | |
341c92a8 | 912 | // Stop right here if we don't have a valid handle in our wxWindow object. |
2d0a075d | 913 | if (wnd && !wnd->m_hWnd) { |
2d0a075d JS |
914 | wnd->m_hWnd = (WXHWND) hWnd; |
915 | long res = wnd->MSWDefWindowProc(message, wParam, lParam ); | |
916 | wnd->m_hWnd = 0; | |
917 | return res; | |
918 | } | |
2bda0e17 | 919 | |
2d0a075d JS |
920 | if (wnd) { |
921 | wnd->m_lastMsg = message; | |
922 | wnd->m_lastWParam = wParam; | |
923 | wnd->m_lastLParam = lParam; | |
924 | } | |
925 | if (wnd) | |
926 | return wnd->MSWWindowProc(message, wParam, lParam); | |
927 | else | |
928 | return DefWindowProc( hWnd, message, wParam, lParam ); | |
2bda0e17 KB |
929 | } |
930 | ||
931 | // Should probably have a test for 'genuine' NT | |
932 | #if defined(__WIN32__) | |
09914df7 | 933 | #define DIMENSION_TYPE short |
2bda0e17 | 934 | #else |
09914df7 | 935 | #define DIMENSION_TYPE int |
2bda0e17 KB |
936 | #endif |
937 | ||
938 | // Main Windows 3 window proc | |
939 | long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) | |
940 | { | |
2d0a075d | 941 | wxASSERT( m_lastMsg == message && |
09914df7 | 942 | m_lastWParam == wParam && m_lastLParam == lParam ); |
5de76427 | 943 | |
2d0a075d | 944 | #ifdef __WXDEBUG__ |
a02eb1d2 | 945 | wxLogTrace(wxTraceMessages, "Processing %s(%lx, %lx)", |
3a19e16d | 946 | wxGetMessageName(message), wParam, lParam); |
ea57084d | 947 | #endif // __WXDEBUG__ |
c085e333 | 948 | |
2d0a075d | 949 | HWND hWnd = (HWND)m_hWnd; |
2bda0e17 | 950 | |
2d0a075d JS |
951 | switch (message) |
952 | { | |
953 | case WM_ACTIVATE: | |
2bda0e17 KB |
954 | { |
955 | #ifdef __WIN32__ | |
956 | WORD state = LOWORD(wParam); | |
957 | WORD minimized = HIWORD(wParam); | |
958 | HWND hwnd = (HWND)lParam; | |
959 | #else | |
960 | WORD state = (WORD)wParam; | |
961 | WORD minimized = LOWORD(lParam); | |
962 | HWND hwnd = (HWND)HIWORD(lParam); | |
963 | #endif | |
964 | MSWOnActivate(state, (minimized != 0), (WXHWND) hwnd); | |
965 | return 0; | |
966 | break; | |
967 | } | |
2d0a075d | 968 | case WM_SETFOCUS: |
2bda0e17 KB |
969 | { |
970 | HWND hwnd = (HWND)wParam; | |
2d0a075d | 971 | // return OnSetFocus(hwnd); |
2bda0e17 KB |
972 | |
973 | if (MSWOnSetFocus((WXHWND) hwnd)) | |
2d0a075d | 974 | return 0; |
2bda0e17 KB |
975 | else return MSWDefWindowProc(message, wParam, lParam ); |
976 | break; | |
977 | } | |
2d0a075d | 978 | case WM_KILLFOCUS: |
2bda0e17 KB |
979 | { |
980 | HWND hwnd = (HWND)lParam; | |
2d0a075d | 981 | // return OnKillFocus(hwnd); |
2bda0e17 | 982 | if (MSWOnKillFocus((WXHWND) hwnd)) |
2d0a075d | 983 | return 0; |
2bda0e17 | 984 | else |
2d0a075d | 985 | return MSWDefWindowProc(message, wParam, lParam ); |
2bda0e17 KB |
986 | break; |
987 | } | |
2d0a075d | 988 | case WM_CREATE: |
47cbd6da | 989 | { |
2d0a075d JS |
990 | MSWOnCreate((WXLPCREATESTRUCT) (LPCREATESTRUCT)lParam); |
991 | return 0; | |
992 | break; | |
47cbd6da | 993 | } |
2d0a075d | 994 | case WM_SHOWWINDOW: |
47cbd6da | 995 | { |
2d0a075d JS |
996 | MSWOnShow((wParam != 0), (int) lParam); |
997 | break; | |
47cbd6da | 998 | } |
2d0a075d | 999 | case WM_PAINT: |
47cbd6da | 1000 | { |
2d0a075d JS |
1001 | if (MSWOnPaint()) |
1002 | return 0; | |
1003 | else return MSWDefWindowProc(message, wParam, lParam ); | |
1004 | break; | |
2bda0e17 | 1005 | } |
2d0a075d | 1006 | case WM_QUERYDRAGICON: |
47cbd6da | 1007 | { |
fd3f686c VZ |
1008 | HICON hIcon = (HICON)MSWOnQueryDragIcon(); |
1009 | if ( hIcon ) | |
2d0a075d | 1010 | return (long)hIcon; |
fd3f686c VZ |
1011 | else |
1012 | return MSWDefWindowProc(message, wParam, lParam ); | |
2d0a075d | 1013 | break; |
2bda0e17 | 1014 | } |
c085e333 | 1015 | |
2d0a075d | 1016 | case WM_SIZE: |
2bda0e17 | 1017 | { |
2d0a075d JS |
1018 | int width = LOWORD(lParam); |
1019 | int height = HIWORD(lParam); | |
1020 | MSWOnSize(width, height, wParam); | |
1021 | break; | |
2bda0e17 | 1022 | } |
c085e333 | 1023 | |
2d0a075d JS |
1024 | case WM_MOVE: |
1025 | { | |
568cb543 | 1026 | wxMoveEvent event(wxPoint(LOWORD(lParam), HIWORD(lParam)), |
2d0a075d | 1027 | m_windowId); |
568cb543 VZ |
1028 | event.SetEventObject(this); |
1029 | if ( !GetEventHandler()->ProcessEvent(event) ) | |
2d0a075d JS |
1030 | Default(); |
1031 | } | |
1032 | break; | |
568cb543 | 1033 | |
2d0a075d | 1034 | case WM_WINDOWPOSCHANGING: |
2bda0e17 | 1035 | { |
2d0a075d JS |
1036 | MSWOnWindowPosChanging((void *)lParam); |
1037 | break; | |
2bda0e17 | 1038 | } |
c085e333 | 1039 | |
2d0a075d | 1040 | case WM_RBUTTONDOWN: |
2bda0e17 KB |
1041 | { |
1042 | int x = (DIMENSION_TYPE) LOWORD(lParam); | |
1043 | int y = (DIMENSION_TYPE) HIWORD(lParam); | |
1044 | MSWOnRButtonDown(x, y, wParam); | |
1045 | break; | |
1046 | } | |
2d0a075d | 1047 | case WM_RBUTTONUP: |
2bda0e17 KB |
1048 | { |
1049 | int x = (DIMENSION_TYPE) LOWORD(lParam); | |
1050 | int y = (DIMENSION_TYPE) HIWORD(lParam); | |
1051 | MSWOnRButtonUp(x, y, wParam); | |
1052 | break; | |
1053 | } | |
2d0a075d | 1054 | case WM_RBUTTONDBLCLK: |
2bda0e17 KB |
1055 | { |
1056 | int x = (DIMENSION_TYPE) LOWORD(lParam); | |
1057 | int y = (DIMENSION_TYPE) HIWORD(lParam); | |
1058 | MSWOnRButtonDClick(x, y, wParam); | |
1059 | break; | |
1060 | } | |
2d0a075d | 1061 | case WM_MBUTTONDOWN: |
2bda0e17 KB |
1062 | { |
1063 | int x = (DIMENSION_TYPE) LOWORD(lParam); | |
1064 | int y = (DIMENSION_TYPE) HIWORD(lParam); | |
1065 | MSWOnMButtonDown(x, y, wParam); | |
1066 | break; | |
1067 | } | |
2d0a075d | 1068 | case WM_MBUTTONUP: |
2bda0e17 KB |
1069 | { |
1070 | int x = (DIMENSION_TYPE) LOWORD(lParam); | |
1071 | int y = (DIMENSION_TYPE) HIWORD(lParam); | |
1072 | MSWOnMButtonUp(x, y, wParam); | |
1073 | break; | |
1074 | } | |
2d0a075d | 1075 | case WM_MBUTTONDBLCLK: |
2bda0e17 KB |
1076 | { |
1077 | int x = (DIMENSION_TYPE) LOWORD(lParam); | |
1078 | int y = (DIMENSION_TYPE) HIWORD(lParam); | |
1079 | MSWOnMButtonDClick(x, y, wParam); | |
1080 | break; | |
1081 | } | |
2d0a075d | 1082 | case WM_LBUTTONDOWN: |
2bda0e17 KB |
1083 | { |
1084 | int x = (DIMENSION_TYPE) LOWORD(lParam); | |
1085 | int y = (DIMENSION_TYPE) HIWORD(lParam); | |
1086 | MSWOnLButtonDown(x, y, wParam); | |
1087 | break; | |
1088 | } | |
2d0a075d | 1089 | case WM_LBUTTONUP: |
2bda0e17 KB |
1090 | { |
1091 | int x = (DIMENSION_TYPE) LOWORD(lParam); | |
1092 | int y = (DIMENSION_TYPE) HIWORD(lParam); | |
1093 | MSWOnLButtonUp(x, y, wParam); | |
1094 | break; | |
1095 | } | |
2d0a075d | 1096 | case WM_LBUTTONDBLCLK: |
2bda0e17 KB |
1097 | { |
1098 | int x = (DIMENSION_TYPE) LOWORD(lParam); | |
1099 | int y = (DIMENSION_TYPE) HIWORD(lParam); | |
1100 | MSWOnLButtonDClick(x, y, wParam); | |
1101 | break; | |
1102 | } | |
2d0a075d | 1103 | case WM_MOUSEMOVE: |
2bda0e17 KB |
1104 | { |
1105 | int x = (DIMENSION_TYPE) LOWORD(lParam); | |
1106 | int y = (DIMENSION_TYPE) HIWORD(lParam); | |
1107 | MSWOnMouseMove(x, y, wParam); | |
1108 | break; | |
1109 | } | |
2d0a075d | 1110 | case MM_JOY1BUTTONDOWN: |
2bda0e17 KB |
1111 | { |
1112 | int x = LOWORD(lParam); | |
1113 | int y = HIWORD(lParam); | |
1114 | MSWOnJoyDown(wxJOYSTICK1, x, y, wParam); | |
1115 | break; | |
1116 | } | |
2d0a075d | 1117 | case MM_JOY2BUTTONDOWN: |
2bda0e17 KB |
1118 | { |
1119 | int x = LOWORD(lParam); | |
1120 | int y = HIWORD(lParam); | |
1121 | MSWOnJoyDown(wxJOYSTICK2, x, y, wParam); | |
1122 | break; | |
1123 | } | |
2d0a075d | 1124 | case MM_JOY1BUTTONUP: |
2bda0e17 KB |
1125 | { |
1126 | int x = LOWORD(lParam); | |
1127 | int y = HIWORD(lParam); | |
1128 | MSWOnJoyUp(wxJOYSTICK1, x, y, wParam); | |
1129 | break; | |
1130 | } | |
2d0a075d | 1131 | case MM_JOY2BUTTONUP: |
2bda0e17 KB |
1132 | { |
1133 | int x = LOWORD(lParam); | |
1134 | int y = HIWORD(lParam); | |
1135 | MSWOnJoyUp(wxJOYSTICK2, x, y, wParam); | |
1136 | break; | |
1137 | } | |
2d0a075d | 1138 | case MM_JOY1MOVE: |
2bda0e17 KB |
1139 | { |
1140 | int x = LOWORD(lParam); | |
1141 | int y = HIWORD(lParam); | |
1142 | MSWOnJoyMove(wxJOYSTICK1, x, y, wParam); | |
1143 | break; | |
1144 | } | |
2d0a075d | 1145 | case MM_JOY2MOVE: |
2bda0e17 KB |
1146 | { |
1147 | int x = LOWORD(lParam); | |
1148 | int y = HIWORD(lParam); | |
1149 | MSWOnJoyMove(wxJOYSTICK2, x, y, wParam); | |
1150 | break; | |
1151 | } | |
2d0a075d | 1152 | case MM_JOY1ZMOVE: |
2bda0e17 KB |
1153 | { |
1154 | int z = LOWORD(lParam); | |
1155 | MSWOnJoyZMove(wxJOYSTICK1, z, wParam); | |
1156 | break; | |
1157 | } | |
2d0a075d | 1158 | case MM_JOY2ZMOVE: |
2bda0e17 KB |
1159 | { |
1160 | int z = LOWORD(lParam); | |
1161 | MSWOnJoyZMove(wxJOYSTICK2, z, wParam); | |
1162 | break; | |
1163 | } | |
2d0a075d | 1164 | case WM_DESTROY: |
2bda0e17 | 1165 | { |
2d0a075d JS |
1166 | if (MSWOnDestroy()) |
1167 | return 0; | |
1168 | else return MSWDefWindowProc(message, wParam, lParam ); | |
1169 | break; | |
2bda0e17 | 1170 | } |
2d0a075d | 1171 | case WM_SYSCOMMAND: |
2bda0e17 KB |
1172 | { |
1173 | return MSWOnSysCommand(wParam, lParam); | |
1174 | break; | |
1175 | } | |
2d0a075d | 1176 | case WM_COMMAND: |
47cbd6da | 1177 | { |
2bda0e17 KB |
1178 | #ifdef __WIN32__ |
1179 | WORD id = LOWORD(wParam); | |
1180 | HWND hwnd = (HWND)lParam; | |
1181 | WORD cmd = HIWORD(wParam); | |
1182 | #else | |
1183 | WORD id = (WORD)wParam; | |
1184 | HWND hwnd = (HWND)LOWORD(lParam) ; | |
1185 | WORD cmd = HIWORD(lParam); | |
1186 | #endif | |
1187 | if (!MSWOnCommand(id, cmd, (WXHWND) hwnd)) | |
2d0a075d | 1188 | return MSWDefWindowProc(message, wParam, lParam ); |
2bda0e17 | 1189 | break; |
47cbd6da | 1190 | } |
2bda0e17 | 1191 | #if defined(__WIN95__) |
2d0a075d | 1192 | case WM_NOTIFY: |
47cbd6da | 1193 | { |
fd3f686c VZ |
1194 | // for some messages (TVN_ITEMEXPANDING for example), the return |
1195 | // value of WM_NOTIFY handler is important, so don't just return 0 | |
1196 | // if we processed the message | |
1197 | return MSWOnNotify(wParam, lParam); | |
2bda0e17 KB |
1198 | } |
1199 | #endif | |
2d0a075d | 1200 | case WM_MENUSELECT: |
2bda0e17 KB |
1201 | { |
1202 | #ifdef __WIN32__ | |
1203 | WORD flags = HIWORD(wParam); | |
1204 | HMENU sysmenu = (HMENU)lParam; | |
1205 | #else | |
1206 | WORD flags = LOWORD(lParam); | |
1207 | HMENU sysmenu = (HMENU)HIWORD(lParam); | |
1208 | #endif | |
1209 | MSWOnMenuHighlight((WORD)wParam, flags, (WXHMENU) sysmenu); | |
1210 | break; | |
1211 | } | |
2d0a075d | 1212 | case WM_INITMENUPOPUP: |
2bda0e17 KB |
1213 | { |
1214 | MSWOnInitMenuPopup((WXHMENU) (HMENU)wParam, (int)LOWORD(lParam), (HIWORD(lParam) != 0)); | |
1215 | break; | |
1216 | } | |
2d0a075d | 1217 | case WM_DRAWITEM: |
2bda0e17 | 1218 | { |
2d0a075d JS |
1219 | return MSWOnDrawItem((int)wParam, (WXDRAWITEMSTRUCT *)lParam); |
1220 | break; | |
2bda0e17 | 1221 | } |
2d0a075d | 1222 | case WM_MEASUREITEM: |
2bda0e17 | 1223 | { |
2d0a075d JS |
1224 | return MSWOnMeasureItem((int)wParam, (WXMEASUREITEMSTRUCT *)lParam); |
1225 | break; | |
2bda0e17 | 1226 | } |
c085e333 | 1227 | |
2d0a075d | 1228 | case WM_KEYDOWN: |
dbda9e86 JS |
1229 | { |
1230 | // If this has been processed by an event handler, | |
1231 | // return 0 now (we've handled it). | |
1232 | if (MSWOnKeyDown((WORD) wParam, lParam)) | |
1233 | { | |
1234 | return 0; | |
1235 | } | |
1236 | ||
1237 | // we consider these message "not interesting" to OnChar | |
2d0a075d | 1238 | if ( wParam == VK_SHIFT || wParam == VK_CONTROL ) |
dbda9e86 | 1239 | { |
2d0a075d | 1240 | return Default(); |
dbda9e86 | 1241 | } |
2d0a075d | 1242 | |
341c92a8 VZ |
1243 | // Avoid duplicate messages to OnChar for these special keys |
1244 | switch ( wParam ) | |
2d0a075d | 1245 | { |
341c92a8 VZ |
1246 | case VK_ESCAPE: |
1247 | case VK_SPACE: | |
1248 | case VK_RETURN: | |
1249 | case VK_BACK: | |
1250 | case VK_TAB: | |
1251 | case VK_LEFT: | |
1252 | case VK_RIGHT: | |
1253 | case VK_DOWN: | |
1254 | case VK_UP: | |
dbda9e86 JS |
1255 | /* |
1256 | // if ( ::GetKeyState(VK_CONTROL) & 0x100 ) // Don't understand purpose of this test | |
1257 | if (!MSWOnChar((WORD)wParam, lParam)) | |
1258 | return Default(); | |
341c92a8 | 1259 | break; |
dbda9e86 | 1260 | */ |
341c92a8 | 1261 | default: |
dbda9e86 JS |
1262 | if (!MSWOnChar((WORD)wParam, lParam)) |
1263 | { | |
1264 | return Default(); | |
1265 | } | |
1266 | /* | |
341c92a8 VZ |
1267 | if ( ::GetKeyState(VK_CONTROL) & 0x100 ) |
1268 | return Default(); | |
dbda9e86 | 1269 | */ |
341c92a8 | 1270 | break; |
2d0a075d | 1271 | } |
341c92a8 | 1272 | |
2d0a075d | 1273 | break; |
dbda9e86 | 1274 | } |
4ce81a75 JS |
1275 | case WM_KEYUP: |
1276 | { | |
dbda9e86 JS |
1277 | if (!MSWOnKeyUp((WORD) wParam, lParam)) |
1278 | return Default(); | |
4ce81a75 JS |
1279 | break; |
1280 | } | |
2d0a075d JS |
1281 | case WM_CHAR: // Always an ASCII character |
1282 | { | |
dbda9e86 JS |
1283 | if (!MSWOnChar((WORD)wParam, lParam, TRUE)) |
1284 | return Default(); | |
47cbd6da | 1285 | break; |
2d0a075d | 1286 | } |
f54f3bff | 1287 | |
2d0a075d | 1288 | case WM_HSCROLL: |
2bda0e17 KB |
1289 | { |
1290 | #ifdef __WIN32__ | |
1291 | WORD code = LOWORD(wParam); | |
1292 | WORD pos = HIWORD(wParam); | |
1293 | HWND control = (HWND)lParam; | |
1294 | #else | |
1295 | WORD code = (WORD)wParam; | |
1296 | WORD pos = LOWORD(lParam); | |
1297 | HWND control = (HWND)HIWORD(lParam); | |
1298 | #endif | |
1299 | MSWOnHScroll(code, pos, (WXHWND) control); | |
1300 | break; | |
1301 | } | |
2d0a075d | 1302 | case WM_VSCROLL: |
2bda0e17 KB |
1303 | { |
1304 | #ifdef __WIN32__ | |
1305 | WORD code = LOWORD(wParam); | |
1306 | WORD pos = HIWORD(wParam); | |
1307 | HWND control = (HWND)lParam; | |
1308 | #else | |
1309 | WORD code = (WORD)wParam; | |
1310 | WORD pos = LOWORD(lParam); | |
1311 | HWND control = (HWND)HIWORD(lParam); | |
1312 | #endif | |
1313 | MSWOnVScroll(code, pos, (WXHWND) control); | |
1314 | break; | |
1315 | } | |
1316 | #ifdef __WIN32__ | |
2d0a075d | 1317 | case WM_CTLCOLORBTN: |
47cbd6da | 1318 | { |
2d0a075d JS |
1319 | int nCtlColor = CTLCOLOR_BTN; |
1320 | HWND control = (HWND)lParam; | |
1321 | HDC pDC = (HDC)wParam; | |
1322 | return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor, | |
1323 | message, wParam, lParam); | |
1324 | break; | |
47cbd6da | 1325 | } |
2d0a075d | 1326 | case WM_CTLCOLORDLG: |
47cbd6da | 1327 | { |
2d0a075d JS |
1328 | int nCtlColor = CTLCOLOR_DLG; |
1329 | HWND control = (HWND)lParam; | |
1330 | HDC pDC = (HDC)wParam; | |
1331 | return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor, | |
1332 | message, wParam, lParam);\ | |
1333 | break; | |
47cbd6da | 1334 | } |
2d0a075d | 1335 | case WM_CTLCOLORLISTBOX: |
47cbd6da | 1336 | { |
2d0a075d JS |
1337 | int nCtlColor = CTLCOLOR_LISTBOX; |
1338 | HWND control = (HWND)lParam; | |
1339 | HDC pDC = (HDC)wParam; | |
1340 | return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor, | |
1341 | message, wParam, lParam); | |
1342 | break; | |
47cbd6da | 1343 | } |
2d0a075d | 1344 | case WM_CTLCOLORMSGBOX: |
47cbd6da | 1345 | { |
2d0a075d JS |
1346 | int nCtlColor = CTLCOLOR_MSGBOX; |
1347 | HWND control = (HWND)lParam; | |
1348 | HDC pDC = (HDC)wParam; | |
1349 | return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor, | |
1350 | message, wParam, lParam); | |
1351 | break; | |
47cbd6da | 1352 | } |
2d0a075d | 1353 | case WM_CTLCOLORSCROLLBAR: |
47cbd6da | 1354 | { |
2d0a075d JS |
1355 | int nCtlColor = CTLCOLOR_SCROLLBAR; |
1356 | HWND control = (HWND)lParam; | |
1357 | HDC pDC = (HDC)wParam; | |
1358 | return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor, | |
1359 | message, wParam, lParam); | |
1360 | break; | |
47cbd6da | 1361 | } |
2d0a075d | 1362 | case WM_CTLCOLORSTATIC: |
47cbd6da | 1363 | { |
2d0a075d JS |
1364 | int nCtlColor = CTLCOLOR_STATIC; |
1365 | HWND control = (HWND)lParam; | |
1366 | HDC pDC = (HDC)wParam; | |
1367 | return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor, | |
1368 | message, wParam, lParam); | |
1369 | break; | |
47cbd6da | 1370 | } |
2d0a075d | 1371 | case WM_CTLCOLOREDIT: |
47cbd6da | 1372 | { |
2d0a075d JS |
1373 | int nCtlColor = CTLCOLOR_EDIT; |
1374 | HWND control = (HWND)lParam; | |
1375 | HDC pDC = (HDC)wParam; | |
1376 | return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor, | |
1377 | message, wParam, lParam); | |
1378 | break; | |
47cbd6da | 1379 | } |
2bda0e17 | 1380 | #else |
2d0a075d | 1381 | case WM_CTLCOLOR: |
2bda0e17 | 1382 | { |
2d0a075d JS |
1383 | HWND control = (HWND)LOWORD(lParam); |
1384 | int nCtlColor = (int)HIWORD(lParam); | |
1385 | HDC pDC = (HDC)wParam; | |
1386 | return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor, | |
1387 | message, wParam, lParam); | |
1388 | break; | |
2bda0e17 KB |
1389 | } |
1390 | #endif | |
2d0a075d | 1391 | case WM_SYSCOLORCHANGE: |
2bda0e17 | 1392 | { |
2d0a075d JS |
1393 | // Return value of 0 means, we processed it. |
1394 | if (MSWOnColorChange((WXHWND) hWnd, message, wParam, lParam) == 0) | |
1395 | return 0; | |
1396 | else | |
1397 | return MSWDefWindowProc(message, wParam, lParam ); | |
1398 | break; | |
2bda0e17 | 1399 | } |
2d0a075d | 1400 | case WM_PALETTECHANGED: |
f7bd2698 JS |
1401 | { |
1402 | return MSWOnPaletteChanged((WXHWND) (HWND) wParam); | |
1403 | break; | |
1404 | } | |
2d0a075d | 1405 | case WM_QUERYNEWPALETTE: |
f7bd2698 JS |
1406 | { |
1407 | return MSWOnQueryNewPalette(); | |
1408 | break; | |
1409 | } | |
2d0a075d | 1410 | case WM_ERASEBKGND: |
2bda0e17 | 1411 | { |
2d0a075d JS |
1412 | // Prevents flicker when dragging |
1413 | if (IsIconic(hWnd)) return 1; | |
2bda0e17 | 1414 | |
2d0a075d JS |
1415 | if (!MSWOnEraseBkgnd((WXHDC) (HDC)wParam)) |
1416 | return 0; // Default(); MSWDefWindowProc(message, wParam, lParam ); | |
1417 | else return 1; | |
1418 | break; | |
2bda0e17 | 1419 | } |
2d0a075d | 1420 | case WM_MDIACTIVATE: |
2bda0e17 KB |
1421 | { |
1422 | #ifdef __WIN32__ | |
1423 | HWND hWndActivate = GET_WM_MDIACTIVATE_HWNDACTIVATE(wParam,lParam); | |
1424 | HWND hWndDeactivate = GET_WM_MDIACTIVATE_HWNDDEACT(wParam,lParam); | |
1425 | BOOL activate = GET_WM_MDIACTIVATE_FACTIVATE(hWnd,wParam,lParam); | |
1426 | return MSWOnMDIActivate((long) activate, (WXHWND) hWndActivate, (WXHWND) hWndDeactivate); | |
1427 | #else | |
1428 | return MSWOnMDIActivate((BOOL)wParam, (HWND)LOWORD(lParam), | |
2d0a075d | 1429 | (HWND)HIWORD(lParam)); |
2bda0e17 KB |
1430 | #endif |
1431 | } | |
2d0a075d | 1432 | case WM_DROPFILES: |
2bda0e17 KB |
1433 | { |
1434 | MSWOnDropFiles(wParam); | |
1435 | break; | |
47cbd6da | 1436 | } |
2d0a075d | 1437 | case WM_INITDIALOG: |
2bda0e17 KB |
1438 | { |
1439 | return 0; // MSWOnInitDialog((WXHWND)(HWND)wParam); | |
1440 | break; | |
47cbd6da | 1441 | } |
2d0a075d | 1442 | case WM_QUERYENDSESSION: |
2bda0e17 | 1443 | { |
47cbd6da | 1444 | // Same as WM_CLOSE, but inverted results. Thx Microsoft :-) |
2d0a075d | 1445 | // return MSWOnClose(); |
387a3b02 JS |
1446 | |
1447 | return MSWOnQueryEndSession(lParam); | |
1448 | break; | |
1449 | } | |
2d0a075d | 1450 | case WM_ENDSESSION: |
387a3b02 JS |
1451 | { |
1452 | // Same as WM_CLOSE, but inverted results. Thx Microsoft :-) | |
1453 | MSWOnEndSession((wParam != 0), lParam); | |
1454 | return 0L; | |
2bda0e17 KB |
1455 | break; |
1456 | } | |
2d0a075d | 1457 | case WM_CLOSE: |
2bda0e17 KB |
1458 | { |
1459 | if (MSWOnClose()) | |
2d0a075d | 1460 | return 0L; |
2bda0e17 | 1461 | else |
2d0a075d | 1462 | return 1L; |
2bda0e17 KB |
1463 | break; |
1464 | } | |
c085e333 | 1465 | |
2d0a075d | 1466 | case WM_GETMINMAXINFO: |
2bda0e17 | 1467 | { |
2d0a075d JS |
1468 | MINMAXINFO *info = (MINMAXINFO *)lParam; |
1469 | if (m_minSizeX != -1) | |
1470 | info->ptMinTrackSize.x = (int)m_minSizeX; | |
1471 | if (m_minSizeY != -1) | |
1472 | info->ptMinTrackSize.y = (int)m_minSizeY; | |
1473 | if (m_maxSizeX != -1) | |
1474 | info->ptMaxTrackSize.x = (int)m_maxSizeX; | |
1475 | if (m_maxSizeY != -1) | |
1476 | info->ptMaxTrackSize.y = (int)m_maxSizeY; | |
1477 | return MSWDefWindowProc(message, wParam, lParam ); | |
1478 | break; | |
2bda0e17 | 1479 | } |
c085e333 | 1480 | |
2d0a075d JS |
1481 | case WM_GETDLGCODE: |
1482 | return MSWGetDlgCode(); | |
2bda0e17 | 1483 | |
2d0a075d JS |
1484 | default: |
1485 | return MSWDefWindowProc(message, wParam, lParam ); | |
2bda0e17 | 1486 | } |
341c92a8 | 1487 | |
2bda0e17 KB |
1488 | return 0; // Success: we processed this command. |
1489 | } | |
1490 | ||
1491 | // Dialog window proc | |
1492 | LONG APIENTRY _EXPORT | |
2d0a075d | 1493 | wxDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) |
2bda0e17 | 1494 | { |
2d0a075d | 1495 | return 0; |
2bda0e17 KB |
1496 | } |
1497 | ||
1498 | wxList *wxWinHandleList = NULL; | |
1499 | wxWindow *wxFindWinFromHandle(WXHWND hWnd) | |
1500 | { | |
2d0a075d JS |
1501 | wxNode *node = wxWinHandleList->Find((long)hWnd); |
1502 | if (!node) | |
1503 | return NULL; | |
1504 | return (wxWindow *)node->Data(); | |
2bda0e17 KB |
1505 | } |
1506 | ||
1507 | void wxAssociateWinWithHandle(HWND hWnd, wxWindow *win) | |
1508 | { | |
2d0a075d JS |
1509 | // adding NULL hWnd is (first) surely a result of an error and |
1510 | // (secondly) breaks menu command processing | |
57c208c5 | 1511 | wxCHECK_RET( hWnd != (HWND) NULL, "attempt to add a NULL hWnd to window list" ); |
195896c7 | 1512 | |
2d0a075d JS |
1513 | if ( !wxWinHandleList->Find((long)hWnd) ) |
1514 | wxWinHandleList->Append((long)hWnd, win); | |
2bda0e17 KB |
1515 | } |
1516 | ||
1517 | void wxRemoveHandleAssociation(wxWindow *win) | |
1518 | { | |
2d0a075d | 1519 | wxWinHandleList->DeleteObject(win); |
2bda0e17 KB |
1520 | } |
1521 | ||
1522 | // Default destroyer - override if you destroy it in some other way | |
1523 | // (e.g. with MDI child windows) | |
fd3f686c | 1524 | void wxWindow::MSWDestroyWindow() |
2bda0e17 | 1525 | { |
2bda0e17 KB |
1526 | } |
1527 | ||
debe6624 | 1528 | void wxWindow::MSWCreate(int id, wxWindow *parent, const char *wclass, wxWindow *wx_win, const char *title, |
2d0a075d JS |
1529 | int x, int y, int width, int height, |
1530 | WXDWORD style, const char *dialog_template, WXDWORD extendedStyle) | |
1531 | { | |
1532 | bool is_dialog = (dialog_template != NULL); | |
1533 | int x1 = CW_USEDEFAULT; | |
1534 | int y1 = 0; | |
1535 | int width1 = CW_USEDEFAULT; | |
1536 | int height1 = 100; | |
1537 | ||
1538 | // Find parent's size, if it exists, to set up a possible default | |
1539 | // panel size the size of the parent window | |
1540 | RECT parent_rect; | |
1541 | if (parent) | |
1542 | { | |
1543 | // Was GetWindowRect: JACS 5/5/95 | |
1544 | ::GetClientRect((HWND) parent->GetHWND(), &parent_rect); | |
2bda0e17 | 1545 | |
2d0a075d JS |
1546 | width1 = parent_rect.right - parent_rect.left; |
1547 | height1 = parent_rect.bottom - parent_rect.top; | |
1548 | } | |
2bda0e17 | 1549 | |
2d0a075d JS |
1550 | if (x > -1) x1 = x; |
1551 | if (y > -1) y1 = y; | |
1552 | if (width > -1) width1 = width; | |
1553 | if (height > -1) height1 = height; | |
2bda0e17 | 1554 | |
2d0a075d JS |
1555 | HWND hParent = NULL; |
1556 | if (parent) | |
1557 | hParent = (HWND) parent->GetHWND(); | |
2bda0e17 | 1558 | |
2d0a075d | 1559 | wxWndHook = this; |
2bda0e17 | 1560 | |
2d0a075d JS |
1561 | if (is_dialog) |
1562 | { | |
1563 | // MakeProcInstance doesn't seem to be needed in C7. Is it needed for | |
1564 | // other compilers??? | |
1565 | // VZ: it's always needed for Win16 and never for Win32 | |
2bda0e17 | 1566 | #ifdef __WIN32__ |
2d0a075d JS |
1567 | m_hWnd = (WXHWND) ::CreateDialog(wxGetInstance(), dialog_template, hParent, |
1568 | (DLGPROC)wxDlgProc); | |
2bda0e17 | 1569 | #else |
f60d0f94 JS |
1570 | // N.B.: if we _don't_ use this form, |
1571 | // then with VC++ 1.5, it crashes horribly. | |
1572 | #if 1 | |
1573 | m_hWnd = (WXHWND) ::CreateDialog(wxGetInstance(), dialog_template, hParent, | |
1574 | (DLGPROC)wxDlgProc); | |
1575 | #else | |
1576 | // Crashes when we use this. | |
2d0a075d | 1577 | DLGPROC dlgproc = (DLGPROC)MakeProcInstance((DLGPROC)wxWndProc, wxGetInstance()); |
2bda0e17 | 1578 | |
2d0a075d JS |
1579 | m_hWnd = (WXHWND) ::CreateDialog(wxGetInstance(), dialog_template, hParent, |
1580 | (DLGPROC)dlgproc); | |
f60d0f94 | 1581 | #endif |
2bda0e17 | 1582 | #endif |
c085e333 | 1583 | |
2d0a075d JS |
1584 | if (m_hWnd == 0) |
1585 | MessageBox(NULL, "Can't find dummy dialog template!\nCheck resource include path for finding wx.rc.", | |
1586 | "wxWindows Error", MB_ICONEXCLAMATION | MB_OK); | |
1587 | else MoveWindow((HWND) m_hWnd, x1, y1, width1, height1, FALSE); | |
1588 | } | |
1589 | else | |
1590 | { | |
1591 | int controlId = 0; | |
1592 | if (style & WS_CHILD) | |
1593 | controlId = id; | |
1594 | if (!title) | |
1595 | title = ""; | |
1596 | ||
1597 | m_hWnd = (WXHWND)CreateWindowEx(extendedStyle, wclass, | |
1598 | title, | |
1599 | style, | |
1600 | x1, y1, | |
1601 | width1, height1, | |
1602 | hParent, (HMENU)controlId, wxGetInstance(), | |
1603 | NULL); | |
1604 | ||
1605 | if ( !m_hWnd ) { | |
1606 | wxLogError("Can't create window of class %s!\n" | |
1607 | "Possible Windows 3.x compatibility problem?", wclass); | |
1608 | } | |
2bda0e17 | 1609 | } |
a02eb1d2 | 1610 | |
2d0a075d JS |
1611 | wxWndHook = NULL; |
1612 | wxWinHandleList->Append((long)m_hWnd, this); | |
2bda0e17 KB |
1613 | } |
1614 | ||
1615 | void wxWindow::MSWOnCreate(WXLPCREATESTRUCT WXUNUSED(cs)) | |
1616 | { | |
1617 | } | |
1618 | ||
fd3f686c | 1619 | bool wxWindow::MSWOnClose() |
2bda0e17 | 1620 | { |
2d0a075d | 1621 | return FALSE; |
2bda0e17 KB |
1622 | } |
1623 | ||
3572173c JS |
1624 | // Some compilers don't define this |
1625 | #ifndef ENDSESSION_LOGOFF | |
1626 | #define ENDSESSION_LOGOFF 0x80000000 | |
1627 | #endif | |
1628 | ||
387a3b02 JS |
1629 | // Return TRUE to end session, FALSE to veto end session. |
1630 | bool wxWindow::MSWOnQueryEndSession(long logOff) | |
1631 | { | |
1632 | wxCloseEvent event(wxEVT_QUERY_END_SESSION, -1); | |
1633 | event.SetEventObject(wxTheApp); | |
1634 | event.SetCanVeto(TRUE); | |
1635 | event.SetLoggingOff( (logOff == ENDSESSION_LOGOFF) ); | |
1636 | if ((this == wxTheApp->GetTopWindow()) && // Only send once | |
2d0a075d | 1637 | wxTheApp->ProcessEvent(event) && event.GetVeto()) |
387a3b02 JS |
1638 | { |
1639 | return FALSE; // Veto! | |
1640 | } | |
1641 | else | |
1642 | { | |
1643 | return TRUE; // Don't veto | |
1644 | } | |
1645 | } | |
1646 | ||
1647 | bool wxWindow::MSWOnEndSession(bool endSession, long logOff) | |
1648 | { | |
1649 | wxCloseEvent event(wxEVT_END_SESSION, -1); | |
1650 | event.SetEventObject(wxTheApp); | |
1651 | event.SetCanVeto(FALSE); | |
1652 | event.SetLoggingOff( (logOff == ENDSESSION_LOGOFF) ); | |
1653 | if (endSession && // No need to send if the session isn't ending | |
1654 | (this == wxTheApp->GetTopWindow()) && // Only send once | |
2d0a075d | 1655 | wxTheApp->ProcessEvent(event)) |
387a3b02 JS |
1656 | { |
1657 | } | |
1658 | return TRUE; | |
1659 | } | |
1660 | ||
fd3f686c | 1661 | bool wxWindow::MSWOnDestroy() |
2bda0e17 | 1662 | { |
2d0a075d JS |
1663 | // delete our drop target if we've got one |
1664 | #if wxUSE_DRAG_AND_DROP | |
195896c7 | 1665 | if ( m_pDropTarget != NULL ) { |
2d0a075d | 1666 | m_pDropTarget->Revoke(m_hWnd); |
2bda0e17 | 1667 | |
2d0a075d JS |
1668 | delete m_pDropTarget; |
1669 | m_pDropTarget = NULL; | |
2bda0e17 | 1670 | } |
2d0a075d | 1671 | #endif |
c085e333 | 1672 | |
2d0a075d | 1673 | return TRUE; |
2bda0e17 KB |
1674 | } |
1675 | ||
1676 | // Deal with child commands from buttons etc. | |
1677 | ||
fd3f686c | 1678 | long wxWindow::MSWOnNotify(WXWPARAM wParam, WXLPARAM lParam) |
2bda0e17 KB |
1679 | { |
1680 | #if defined(__WIN95__) | |
1681 | // Find a child window to send the notification to, e.g. a toolbar. | |
1682 | // There's a problem here. NMHDR::hwndFrom doesn't give us the | |
1683 | // handle of the toolbar; it's probably the handle of the tooltip | |
1684 | // window (anyway, it's parent is also the toolbar's parent). | |
1685 | // So, since we don't know which hWnd or wxWindow originated the | |
1686 | // WM_NOTIFY, we'll need to go through all the children of this window | |
1687 | // trying out MSWNotify. | |
2d0a075d JS |
1688 | // This won't work now, though, because any number of controls |
1689 | // could respond to the same generic messages :-( | |
2bda0e17 | 1690 | |
2d0a075d JS |
1691 | /* This doesn't work for toolbars, but try for other controls first. |
1692 | */ | |
2bda0e17 KB |
1693 | NMHDR *hdr = (NMHDR *)lParam; |
1694 | HWND hWnd = (HWND)hdr->hwndFrom; | |
1695 | wxWindow *win = wxFindWinFromHandle((WXHWND) hWnd); | |
c085e333 | 1696 | |
fd3f686c VZ |
1697 | WXLPARAM result = 0; |
1698 | ||
2d0a075d | 1699 | if ( win ) |
fd3f686c | 1700 | { |
cf65ad8d VZ |
1701 | if ( win->MSWNotify(wParam, lParam, &result) ) |
1702 | return result; | |
fd3f686c | 1703 | } |
2d0a075d JS |
1704 | else |
1705 | { | |
564b2609 | 1706 | // Rely on MSWNotify to check whether the message |
2d0a075d | 1707 | // belongs to the window or not |
c0ed460c | 1708 | wxNode *node = GetChildren().First(); |
564b2609 VZ |
1709 | while (node) |
1710 | { | |
1711 | wxWindow *child = (wxWindow *)node->Data(); | |
fd3f686c | 1712 | if ( child->MSWNotify(wParam, lParam, &result) ) |
cf65ad8d | 1713 | return result; |
2d0a075d | 1714 | node = node->Next(); |
564b2609 | 1715 | } |
2bda0e17 | 1716 | |
cf65ad8d VZ |
1717 | // finally try this window too (catches toolbar case) |
1718 | if ( MSWNotify(wParam, lParam, &result) ) | |
1719 | return result; | |
1720 | } | |
fd3f686c | 1721 | #endif // Win95 |
c085e333 | 1722 | |
cf65ad8d | 1723 | // not processed |
2d0a075d | 1724 | return FALSE; |
2bda0e17 KB |
1725 | } |
1726 | ||
debe6624 | 1727 | void wxWindow::MSWOnMenuHighlight(WXWORD WXUNUSED(item), WXWORD WXUNUSED(flags), WXHMENU WXUNUSED(sysmenu)) |
2bda0e17 | 1728 | { |
2bda0e17 KB |
1729 | } |
1730 | ||
debe6624 | 1731 | void wxWindow::MSWOnInitMenuPopup(WXHMENU menu, int pos, bool isSystem) |
2bda0e17 | 1732 | { |
2bda0e17 KB |
1733 | } |
1734 | ||
debe6624 | 1735 | bool wxWindow::MSWOnActivate(int state, bool WXUNUSED(minimized), WXHWND WXUNUSED(activate)) |
2bda0e17 | 1736 | { |
2d0a075d JS |
1737 | wxActivateEvent event(wxEVT_ACTIVATE, ((state == WA_ACTIVE) || (state == WA_CLICKACTIVE)), |
1738 | m_windowId); | |
1739 | event.SetEventObject(this); | |
1740 | GetEventHandler()->ProcessEvent(event); | |
1741 | return 0; | |
2bda0e17 KB |
1742 | } |
1743 | ||
debe6624 | 1744 | bool wxWindow::MSWOnSetFocus(WXHWND WXUNUSED(hwnd)) |
2bda0e17 | 1745 | { |
2bda0e17 KB |
1746 | // Deal with caret |
1747 | if (m_caretEnabled && (m_caretWidth > 0) && (m_caretHeight > 0)) | |
1748 | { | |
2d0a075d JS |
1749 | ::CreateCaret((HWND) GetHWND(), NULL, m_caretWidth, m_caretHeight); |
1750 | if (m_caretShown) | |
1751 | ::ShowCaret((HWND) GetHWND()); | |
2bda0e17 | 1752 | } |
c085e333 | 1753 | |
341c92a8 VZ |
1754 | // panel wants to track the window which was the last to have focus in it |
1755 | wxWindow *parent = GetParent(); | |
1756 | if ( parent && parent->IsKindOf(CLASSINFO(wxPanel)) ) | |
1757 | { | |
0492c5a0 | 1758 | ((wxPanel *)parent)->SetLastFocus(GetId()); |
341c92a8 VZ |
1759 | } |
1760 | ||
2d0a075d JS |
1761 | wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId); |
1762 | event.SetEventObject(this); | |
1763 | if (!GetEventHandler()->ProcessEvent(event)) | |
1764 | Default(); | |
1765 | return TRUE; | |
2bda0e17 KB |
1766 | } |
1767 | ||
debe6624 | 1768 | bool wxWindow::MSWOnKillFocus(WXHWND WXUNUSED(hwnd)) |
2bda0e17 | 1769 | { |
2bda0e17 KB |
1770 | // Deal with caret |
1771 | if (m_caretEnabled) | |
1772 | { | |
2d0a075d | 1773 | ::DestroyCaret(); |
2bda0e17 | 1774 | } |
c085e333 | 1775 | |
2d0a075d JS |
1776 | wxFocusEvent event(wxEVT_KILL_FOCUS, m_windowId); |
1777 | event.SetEventObject(this); | |
1778 | if (!GetEventHandler()->ProcessEvent(event)) | |
1779 | Default(); | |
1780 | return TRUE; | |
2bda0e17 KB |
1781 | } |
1782 | ||
debe6624 | 1783 | void wxWindow::MSWOnDropFiles(WXWPARAM wParam) |
2bda0e17 | 1784 | { |
c085e333 | 1785 | |
2d0a075d JS |
1786 | HDROP hFilesInfo = (HDROP) wParam; |
1787 | POINT dropPoint; | |
1788 | DragQueryPoint(hFilesInfo, (LPPOINT) &dropPoint); | |
1789 | ||
1790 | // Get the total number of files dropped | |
1791 | WORD gwFilesDropped = (WORD)DragQueryFile ((HDROP)hFilesInfo, | |
1792 | (UINT)-1, | |
1793 | (LPSTR)0, | |
1794 | (UINT)0); | |
1795 | ||
1796 | wxString *files = new wxString[gwFilesDropped]; | |
1797 | int wIndex; | |
1798 | for (wIndex=0; wIndex < (int)gwFilesDropped; wIndex++) | |
1799 | { | |
1800 | DragQueryFile (hFilesInfo, wIndex, (LPSTR) wxBuffer, 1000); | |
1801 | files[wIndex] = wxBuffer; | |
1802 | } | |
1803 | DragFinish (hFilesInfo); | |
2bda0e17 | 1804 | |
2d0a075d JS |
1805 | wxDropFilesEvent event(wxEVT_DROP_FILES, gwFilesDropped, files); |
1806 | event.m_eventObject = this; | |
1807 | event.m_pos.x = dropPoint.x; event.m_pos.x = dropPoint.y; | |
2bda0e17 | 1808 | |
2d0a075d JS |
1809 | if (!GetEventHandler()->ProcessEvent(event)) |
1810 | Default(); | |
2bda0e17 | 1811 | |
2d0a075d | 1812 | delete[] files; |
2bda0e17 KB |
1813 | } |
1814 | ||
debe6624 | 1815 | bool wxWindow::MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *itemStruct) |
2bda0e17 | 1816 | { |
47d67540 | 1817 | #if wxUSE_OWNER_DRAWN |
2bda0e17 | 1818 | if ( id == 0 ) { // is it a menu item? |
2d0a075d JS |
1819 | DRAWITEMSTRUCT *pDrawStruct = (DRAWITEMSTRUCT *)itemStruct; |
1820 | wxMenuItem *pMenuItem = (wxMenuItem *)(pDrawStruct->itemData); | |
1821 | wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE ); | |
1822 | ||
1823 | // prepare to call OnDrawItem() | |
1824 | wxDC dc; | |
1825 | dc.SetHDC((WXHDC)pDrawStruct->hDC, FALSE); | |
1826 | wxRect rect(pDrawStruct->rcItem.left, pDrawStruct->rcItem.top, | |
1827 | pDrawStruct->rcItem.right - pDrawStruct->rcItem.left, | |
1828 | pDrawStruct->rcItem.bottom - pDrawStruct->rcItem.top); | |
1829 | return pMenuItem->OnDrawItem( | |
1830 | dc, rect, | |
1831 | (wxOwnerDrawn::wxODAction)pDrawStruct->itemAction, | |
1832 | (wxOwnerDrawn::wxODStatus)pDrawStruct->itemState | |
1833 | ); | |
2bda0e17 KB |
1834 | } |
1835 | #endif // owner-drawn menus | |
c085e333 | 1836 | |
2d0a075d | 1837 | wxWindow *item = FindItem(id); |
47d67540 | 1838 | #if wxUSE_DYNAMIC_CLASSES |
2d0a075d JS |
1839 | if (item && item->IsKindOf(CLASSINFO(wxControl))) |
1840 | { | |
1841 | return ((wxControl *)item)->MSWOnDraw(itemStruct); | |
1842 | } | |
1843 | else | |
2bda0e17 | 1844 | #endif |
2d0a075d | 1845 | return FALSE; |
2bda0e17 KB |
1846 | } |
1847 | ||
debe6624 | 1848 | bool wxWindow::MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *itemStruct) |
2bda0e17 | 1849 | { |
47d67540 | 1850 | #if wxUSE_OWNER_DRAWN |
2bda0e17 | 1851 | if ( id == 0 ) { // is it a menu item? |
2d0a075d JS |
1852 | MEASUREITEMSTRUCT *pMeasureStruct = (MEASUREITEMSTRUCT *)itemStruct; |
1853 | wxMenuItem *pMenuItem = (wxMenuItem *)(pMeasureStruct->itemData); | |
1854 | wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE ); | |
2bda0e17 | 1855 | |
c085e333 | 1856 | return pMenuItem->OnMeasureItem(&pMeasureStruct->itemWidth, |
2d0a075d | 1857 | &pMeasureStruct->itemHeight); |
2bda0e17 KB |
1858 | } |
1859 | #endif // owner-drawn menus | |
c085e333 | 1860 | |
2d0a075d | 1861 | wxWindow *item = FindItem(id); |
47d67540 | 1862 | #if wxUSE_DYNAMIC_CLASSES |
2d0a075d JS |
1863 | if (item && item->IsKindOf(CLASSINFO(wxControl))) |
1864 | { | |
1865 | return ((wxControl *)item)->MSWOnMeasure(itemStruct); | |
1866 | } | |
1867 | else | |
2bda0e17 | 1868 | #endif |
2d0a075d | 1869 | return FALSE; |
2bda0e17 KB |
1870 | } |
1871 | ||
debe6624 | 1872 | WXHBRUSH wxWindow::MSWOnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, |
2d0a075d | 1873 | WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
2bda0e17 | 1874 | { |
2d0a075d JS |
1875 | if (nCtlColor == CTLCOLOR_DLG) |
1876 | { | |
1877 | return OnCtlColor(pDC, pWnd, nCtlColor, message, wParam, lParam); | |
1878 | } | |
2bda0e17 | 1879 | |
2d0a075d | 1880 | wxControl *item = (wxControl *)FindItemByHWND(pWnd, TRUE); |
2bda0e17 | 1881 | |
2d0a075d | 1882 | WXHBRUSH hBrush = 0; |
2bda0e17 | 1883 | |
2d0a075d JS |
1884 | if ( item ) |
1885 | hBrush = item->OnCtlColor(pDC, pWnd, nCtlColor, message, wParam, lParam); | |
2bda0e17 | 1886 | |
2d0a075d JS |
1887 | // I think that even for dialogs, we may need to call DefWindowProc (?) |
1888 | // Or maybe just rely on the usual default behaviour. | |
1889 | if ( !hBrush ) | |
1890 | hBrush = (WXHBRUSH) MSWDefWindowProc(message, wParam, lParam); | |
2bda0e17 | 1891 | |
2d0a075d | 1892 | return hBrush ; |
2bda0e17 KB |
1893 | } |
1894 | ||
1895 | // Define for each class of dialog and control | |
debe6624 | 1896 | WXHBRUSH wxWindow::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, |
2d0a075d | 1897 | WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
2bda0e17 KB |
1898 | { |
1899 | return (WXHBRUSH) MSWDefWindowProc(message, wParam, lParam); | |
1900 | } | |
1901 | ||
debe6624 | 1902 | bool wxWindow::MSWOnColorChange(WXHWND hWnd, WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
2bda0e17 | 1903 | { |
2d0a075d JS |
1904 | wxSysColourChangedEvent event; |
1905 | event.SetEventObject(this); | |
2bda0e17 | 1906 | |
2d0a075d JS |
1907 | // Check if app handles this. |
1908 | if (GetEventHandler()->ProcessEvent(event)) | |
1909 | return 0; | |
2bda0e17 | 1910 | |
2d0a075d JS |
1911 | // We didn't process it |
1912 | return 1; | |
2bda0e17 KB |
1913 | } |
1914 | ||
f7bd2698 JS |
1915 | long wxWindow::MSWOnPaletteChanged(WXHWND hWndPalChange) |
1916 | { | |
1917 | wxPaletteChangedEvent event(GetId()); | |
1918 | event.SetEventObject(this); | |
1919 | event.SetChangedWindow(wxFindWinFromHandle(hWndPalChange)); | |
1920 | GetEventHandler()->ProcessEvent(event); | |
1921 | return 0; | |
1922 | } | |
1923 | ||
1924 | long wxWindow::MSWOnQueryNewPalette() | |
1925 | { | |
1926 | wxQueryNewPaletteEvent event(GetId()); | |
1927 | event.SetEventObject(this); | |
1928 | if (!GetEventHandler()->ProcessEvent(event) || !event.GetPaletteRealized()) | |
1929 | { | |
1930 | return (long) FALSE; | |
1931 | } | |
1932 | else | |
1933 | return (long) TRUE; | |
1934 | } | |
1935 | ||
2bda0e17 KB |
1936 | // Responds to colour changes: passes event on to children. |
1937 | void wxWindow::OnSysColourChanged(wxSysColourChangedEvent& event) | |
1938 | { | |
c0ed460c | 1939 | wxNode *node = GetChildren().First(); |
2bda0e17 KB |
1940 | while ( node ) |
1941 | { | |
1942 | // Only propagate to non-top-level windows | |
1943 | wxWindow *win = (wxWindow *)node->Data(); | |
1944 | if ( win->GetParent() ) | |
1945 | { | |
1946 | wxSysColourChangedEvent event2; | |
1947 | event.m_eventObject = win; | |
1948 | win->GetEventHandler()->ProcessEvent(event2); | |
1949 | } | |
c085e333 | 1950 | |
2bda0e17 KB |
1951 | node = node->Next(); |
1952 | } | |
1953 | } | |
1954 | ||
1955 | long wxWindow::MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) | |
1956 | { | |
2d0a075d JS |
1957 | if ( m_oldWndProc ) |
1958 | return ::CallWindowProc(CASTWNDPROC m_oldWndProc, (HWND) GetHWND(), (UINT) nMsg, (WPARAM) wParam, (LPARAM) lParam); | |
1959 | else | |
1960 | return ::DefWindowProc((HWND) GetHWND(), nMsg, wParam, lParam); | |
2bda0e17 KB |
1961 | } |
1962 | ||
1963 | long wxWindow::Default() | |
1964 | { | |
46851318 JS |
1965 | // Ignore 'fake' events (perhaps generated as a result of a separate real event) |
1966 | if (m_lastMsg == 0) | |
1c089c47 | 1967 | return 0; |
c085e333 | 1968 | |
2d0a075d JS |
1969 | #ifdef __WXDEBUG__ |
1970 | wxLogTrace(wxTraceMessages, "Forwarding %s to DefWindowProc.", | |
1971 | wxGetMessageName(m_lastMsg)); | |
ea57084d | 1972 | #endif // __WXDEBUG__ |
c085e333 | 1973 | |
46851318 | 1974 | return this->MSWDefWindowProc(m_lastMsg, m_lastWParam, m_lastLParam); |
2bda0e17 KB |
1975 | } |
1976 | ||
1977 | bool wxWindow::MSWProcessMessage(WXMSG* pMsg) | |
1978 | { | |
2d0a075d JS |
1979 | if ( m_hWnd != 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL) ) { |
1980 | // intercept dialog navigation keys | |
1981 | MSG *msg = (MSG *)pMsg; | |
1982 | bool bProcess = TRUE; | |
1983 | if ( msg->message != WM_KEYDOWN ) | |
1984 | bProcess = FALSE; | |
47cbd6da | 1985 | |
341c92a8 | 1986 | if ( bProcess && (HIWORD(msg->lParam) & KF_ALTDOWN) == KF_ALTDOWN ) |
2d0a075d | 1987 | bProcess = FALSE; |
47cbd6da | 1988 | |
341c92a8 VZ |
1989 | if ( bProcess ) |
1990 | { | |
1991 | bool bCtrlDown = (::GetKeyState(VK_CONTROL) & 0x100) != 0; | |
47cbd6da | 1992 | |
341c92a8 VZ |
1993 | // WM_GETDLGCODE: ask the control if it wants the key for itself, |
1994 | // don't process it if it's the case (except for Ctrl-Tab/Enter | |
1995 | // combinations which are always processed) | |
1996 | LONG lDlgCode = 0; | |
1997 | if ( !bCtrlDown ) | |
1998 | { | |
1999 | lDlgCode = ::SendMessage(msg->hwnd, WM_GETDLGCODE, 0, 0); | |
2000 | } | |
2001 | ||
2002 | bool bForward = TRUE, | |
2003 | bWindowChange = FALSE; | |
47cbd6da | 2004 | |
341c92a8 VZ |
2005 | switch ( msg->wParam ) |
2006 | { | |
fd3f686c | 2007 | case VK_TAB: |
3a19e16d | 2008 | if ( lDlgCode & DLGC_WANTTAB ) { |
fd3f686c | 2009 | bProcess = FALSE; |
3a19e16d VZ |
2010 | } |
2011 | else { | |
2012 | // Ctrl-Tab cycles thru notebook pages | |
2013 | bWindowChange = bCtrlDown; | |
fd3f686c | 2014 | bForward = !(::GetKeyState(VK_SHIFT) & 0x100); |
3a19e16d | 2015 | } |
fd3f686c | 2016 | break; |
47cbd6da | 2017 | |
fd3f686c VZ |
2018 | case VK_UP: |
2019 | case VK_LEFT: | |
2020 | if ( (lDlgCode & DLGC_WANTARROWS) || bCtrlDown ) | |
2021 | bProcess = FALSE; | |
2022 | else | |
2023 | bForward = FALSE; | |
2024 | break; | |
47cbd6da | 2025 | |
fd3f686c VZ |
2026 | case VK_DOWN: |
2027 | case VK_RIGHT: | |
2028 | if ( (lDlgCode & DLGC_WANTARROWS) || bCtrlDown ) | |
2029 | bProcess = FALSE; | |
2030 | break; | |
47cbd6da | 2031 | |
3a19e16d | 2032 | case VK_RETURN: |
341c92a8 VZ |
2033 | { |
2034 | if ( lDlgCode & DLGC_WANTMESSAGE ) | |
5fb9fcfc VZ |
2035 | { |
2036 | // control wants to process Enter itself, don't | |
2037 | // call IsDialogMessage() which would interpret | |
2038 | // it | |
2039 | return FALSE; | |
2040 | } | |
750b78ba | 2041 | #ifndef __WIN16__ |
341c92a8 VZ |
2042 | wxButton *btnDefault = GetDefaultItem(); |
2043 | if ( btnDefault && !bCtrlDown ) | |
2044 | { | |
2045 | // if there is a default button, Enter should | |
2046 | // press it | |
2047 | (void)::SendMessage((HWND)btnDefault->GetHWND(), | |
2048 | BM_CLICK, 0, 0); | |
2049 | return TRUE; | |
2050 | } | |
2051 | // else: but if there is not it makes sense to make it | |
2052 | // work like a TAB - and that's what we do. | |
2053 | // Note that Ctrl-Enter always works this way. | |
750b78ba | 2054 | #endif |
3a19e16d | 2055 | } |
341c92a8 | 2056 | break; |
3a19e16d | 2057 | |
fd3f686c VZ |
2058 | default: |
2059 | bProcess = FALSE; | |
2d0a075d | 2060 | } |
47cbd6da | 2061 | |
341c92a8 VZ |
2062 | if ( bProcess ) |
2063 | { | |
2064 | wxNavigationKeyEvent event; | |
2065 | event.SetDirection(bForward); | |
2066 | event.SetWindowChange(bWindowChange); | |
2067 | event.SetEventObject(this); | |
47cbd6da | 2068 | |
341c92a8 VZ |
2069 | if ( GetEventHandler()->ProcessEvent(event) ) |
2070 | return TRUE; | |
2071 | } | |
2d0a075d | 2072 | } |
47cbd6da | 2073 | |
341c92a8 VZ |
2074 | if ( ::IsDialogMessage((HWND)GetHWND(), msg) ) |
2075 | return TRUE; | |
2d0a075d | 2076 | } |
3a19e16d | 2077 | #if wxUSE_TOOLTIPS |
341c92a8 VZ |
2078 | if ( m_tooltip ) |
2079 | { | |
3a19e16d VZ |
2080 | // relay mouse move events to the tooltip control |
2081 | MSG *msg = (MSG *)pMsg; | |
2082 | if ( msg->message == WM_MOUSEMOVE ) | |
2083 | m_tooltip->RelayEvent(pMsg); | |
2084 | } | |
2085 | #endif // wxUSE_TOOLTIPS | |
47cbd6da | 2086 | |
2d0a075d | 2087 | return FALSE; |
2bda0e17 KB |
2088 | } |
2089 | ||
088a95f5 | 2090 | bool wxWindow::MSWTranslateMessage(WXMSG* pMsg) |
57a7b7c1 | 2091 | { |
088a95f5 | 2092 | if (m_acceleratorTable.Ok() && |
2d0a075d | 2093 | ::TranslateAccelerator((HWND) GetHWND(), (HACCEL) m_acceleratorTable.GetHACCEL(), (MSG *)pMsg)) |
088a95f5 JS |
2094 | return TRUE; |
2095 | else | |
2096 | return FALSE; | |
57a7b7c1 JS |
2097 | } |
2098 | ||
debe6624 | 2099 | long wxWindow::MSWOnMDIActivate(long WXUNUSED(flag), WXHWND WXUNUSED(activate), WXHWND WXUNUSED(deactivate)) |
2bda0e17 | 2100 | { |
2d0a075d | 2101 | return 1; |
2bda0e17 KB |
2102 | } |
2103 | ||
fd3f686c | 2104 | void wxWindow::MSWDetachWindowMenu() |
2bda0e17 | 2105 | { |
2d0a075d | 2106 | if (m_hMenu) |
2bda0e17 | 2107 | { |
2d0a075d JS |
2108 | int N = GetMenuItemCount((HMENU) m_hMenu); |
2109 | int i; | |
2110 | for (i = 0; i < N; i++) | |
2111 | { | |
2112 | char buf[100]; | |
2113 | int chars = GetMenuString((HMENU) m_hMenu, i, buf, 100, MF_BYPOSITION); | |
2114 | if ((chars > 0) && (strcmp(buf, "&Window") == 0)) | |
2115 | { | |
2116 | RemoveMenu((HMENU) m_hMenu, i, MF_BYPOSITION); | |
2117 | break; | |
2118 | } | |
2119 | } | |
2bda0e17 | 2120 | } |
2bda0e17 KB |
2121 | } |
2122 | ||
fd3f686c | 2123 | bool wxWindow::MSWOnPaint() |
2bda0e17 | 2124 | { |
81d66cf3 | 2125 | #ifdef __WIN32__ |
2d0a075d JS |
2126 | HRGN hRegion = ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle |
2127 | ::GetUpdateRgn((HWND) GetHWND(), hRegion, FALSE); | |
81d66cf3 | 2128 | |
2d0a075d | 2129 | m_updateRegion = wxRegion((WXHRGN) hRegion); |
81d66cf3 | 2130 | #else |
2d0a075d JS |
2131 | RECT updateRect; |
2132 | ::GetUpdateRect((HWND) GetHWND(), & updateRect, FALSE); | |
81d66cf3 | 2133 | |
2d0a075d JS |
2134 | m_updateRegion = wxRegion(updateRect.left, updateRect.top, |
2135 | updateRect.right - updateRect.left, updateRect.bottom - updateRect.top); | |
81d66cf3 | 2136 | #endif |
c085e333 | 2137 | |
2d0a075d JS |
2138 | wxPaintEvent event(m_windowId); |
2139 | event.SetEventObject(this); | |
2140 | if (!GetEventHandler()->ProcessEvent(event)) | |
2141 | Default(); | |
2142 | return TRUE; | |
2bda0e17 KB |
2143 | } |
2144 | ||
debe6624 | 2145 | void wxWindow::MSWOnSize(int w, int h, WXUINT WXUNUSED(flag)) |
2bda0e17 | 2146 | { |
2d0a075d JS |
2147 | if (m_inOnSize) |
2148 | return; | |
2149 | ||
2d0a075d JS |
2150 | if (!m_hWnd) |
2151 | return; | |
2bda0e17 | 2152 | |
2d0a075d | 2153 | m_inOnSize = TRUE; |
2bda0e17 | 2154 | |
2d0a075d JS |
2155 | wxSizeEvent event(wxSize(w, h), m_windowId); |
2156 | event.SetEventObject(this); | |
2157 | if (!GetEventHandler()->ProcessEvent(event)) | |
2158 | Default(); | |
2bda0e17 | 2159 | |
2d0a075d | 2160 | m_inOnSize = FALSE; |
2bda0e17 KB |
2161 | } |
2162 | ||
2163 | void wxWindow::MSWOnWindowPosChanging(void *WXUNUSED(lpPos)) | |
2164 | { | |
2165 | Default(); | |
2166 | } | |
2167 | ||
2168 | // Deal with child commands from buttons etc. | |
34138703 | 2169 | bool wxWindow::MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control) |
2bda0e17 | 2170 | { |
2d0a075d JS |
2171 | if (wxCurrentPopupMenu) |
2172 | { | |
2173 | wxMenu *popupMenu = wxCurrentPopupMenu; | |
2174 | wxCurrentPopupMenu = NULL; | |
2175 | bool succ = popupMenu->MSWCommand(cmd, id); | |
2176 | return succ; | |
2177 | } | |
c085e333 | 2178 | |
2d0a075d JS |
2179 | wxWindow *item = FindItem(id); |
2180 | if (item) | |
2181 | { | |
2182 | bool value = item->MSWCommand(cmd, id); | |
2d0a075d JS |
2183 | return value; |
2184 | } | |
2185 | else | |
2186 | { | |
2187 | wxWindow *win = wxFindWinFromHandle(control); | |
2188 | if (win) | |
2189 | return win->MSWCommand(cmd, id); | |
2190 | } | |
2191 | return FALSE; | |
2bda0e17 KB |
2192 | } |
2193 | ||
2194 | long wxWindow::MSWOnSysCommand(WXWPARAM wParam, WXLPARAM lParam) | |
2195 | { | |
0492c5a0 | 2196 | switch (wParam & 0xFFFFFFF0) |
2bda0e17 | 2197 | { |
2d0a075d | 2198 | case SC_MAXIMIZE: |
2bda0e17 KB |
2199 | { |
2200 | wxMaximizeEvent event(m_windowId); | |
2201 | event.SetEventObject(this); | |
2202 | if (!GetEventHandler()->ProcessEvent(event)) | |
2203 | return Default(); | |
2204 | else | |
2205 | return 0; | |
2206 | break; | |
2207 | } | |
2d0a075d | 2208 | case SC_MINIMIZE: |
2bda0e17 KB |
2209 | { |
2210 | wxIconizeEvent event(m_windowId); | |
2211 | event.SetEventObject(this); | |
2212 | if (!GetEventHandler()->ProcessEvent(event)) | |
2213 | return Default(); | |
2214 | else | |
2215 | return 0; | |
2216 | break; | |
2217 | } | |
2d0a075d JS |
2218 | default: |
2219 | return Default(); | |
2bda0e17 KB |
2220 | } |
2221 | return 0; | |
2222 | } | |
2223 | ||
debe6624 | 2224 | void wxWindow::MSWOnLButtonDown(int x, int y, WXUINT flags) |
2bda0e17 | 2225 | { |
2d0a075d | 2226 | wxMouseEvent event(wxEVT_LEFT_DOWN); |
2bda0e17 | 2227 | |
2d0a075d JS |
2228 | event.m_x = x; event.m_y = y; |
2229 | event.m_shiftDown = ((flags & MK_SHIFT) != 0); | |
2230 | event.m_controlDown = ((flags & MK_CONTROL) != 0); | |
2231 | event.m_leftDown = ((flags & MK_LBUTTON) != 0); | |
2232 | event.m_middleDown = ((flags & MK_MBUTTON) != 0); | |
2233 | event.m_rightDown = ((flags & MK_RBUTTON) != 0); | |
2234 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2235 | event.m_eventObject = this; | |
2bda0e17 | 2236 | |
f5419957 | 2237 | m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_LEFT_DOWN; |
debe6624 | 2238 | |
2d0a075d JS |
2239 | if (!GetEventHandler()->ProcessEvent(event)) |
2240 | Default(); | |
2bda0e17 KB |
2241 | } |
2242 | ||
debe6624 | 2243 | void wxWindow::MSWOnLButtonUp(int x, int y, WXUINT flags) |
2bda0e17 | 2244 | { |
2d0a075d | 2245 | wxMouseEvent event(wxEVT_LEFT_UP); |
2bda0e17 | 2246 | |
2d0a075d JS |
2247 | event.m_x = x; event.m_y = y; |
2248 | event.m_shiftDown = ((flags & MK_SHIFT) != 0); | |
2249 | event.m_controlDown = ((flags & MK_CONTROL) != 0); | |
2250 | event.m_leftDown = ((flags & MK_LBUTTON) != 0); | |
2251 | event.m_middleDown = ((flags & MK_MBUTTON) != 0); | |
2252 | event.m_rightDown = ((flags & MK_RBUTTON) != 0); | |
2253 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2254 | event.m_eventObject = this; | |
2bda0e17 | 2255 | |
2d0a075d | 2256 | m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_LEFT_UP; |
2bda0e17 | 2257 | |
2d0a075d JS |
2258 | if (!GetEventHandler()->ProcessEvent(event)) |
2259 | Default(); | |
2bda0e17 KB |
2260 | } |
2261 | ||
debe6624 | 2262 | void wxWindow::MSWOnLButtonDClick(int x, int y, WXUINT flags) |
2bda0e17 | 2263 | { |
2d0a075d | 2264 | wxMouseEvent event(wxEVT_LEFT_DCLICK); |
2bda0e17 | 2265 | |
2d0a075d JS |
2266 | event.m_x = x; event.m_y = y; |
2267 | event.m_shiftDown = ((flags & MK_SHIFT) != 0); | |
2268 | event.m_controlDown = ((flags & MK_CONTROL) != 0); | |
2269 | event.m_leftDown = ((flags & MK_LBUTTON) != 0); | |
2270 | event.m_middleDown = ((flags & MK_MBUTTON) != 0); | |
2271 | event.m_rightDown = ((flags & MK_RBUTTON) != 0); | |
2272 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2273 | event.m_eventObject = this; | |
2bda0e17 | 2274 | |
2d0a075d | 2275 | m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_LEFT_DCLICK; |
2bda0e17 | 2276 | |
2d0a075d JS |
2277 | if (!GetEventHandler()->ProcessEvent(event)) |
2278 | Default(); | |
2bda0e17 KB |
2279 | } |
2280 | ||
debe6624 | 2281 | void wxWindow::MSWOnMButtonDown(int x, int y, WXUINT flags) |
2bda0e17 | 2282 | { |
2d0a075d | 2283 | wxMouseEvent event(wxEVT_MIDDLE_DOWN); |
2bda0e17 | 2284 | |
2d0a075d JS |
2285 | event.m_x = x; event.m_y = y; |
2286 | event.m_shiftDown = ((flags & MK_SHIFT) != 0); | |
2287 | event.m_controlDown = ((flags & MK_CONTROL) != 0); | |
2288 | event.m_leftDown = ((flags & MK_LBUTTON) != 0); | |
2289 | event.m_middleDown = ((flags & MK_MBUTTON) != 0); | |
2290 | event.m_rightDown = ((flags & MK_RBUTTON) != 0); | |
2291 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2292 | event.m_eventObject = this; | |
2bda0e17 | 2293 | |
2d0a075d | 2294 | m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_MIDDLE_DOWN; |
debe6624 | 2295 | |
2d0a075d JS |
2296 | if (!GetEventHandler()->ProcessEvent(event)) |
2297 | Default(); | |
2bda0e17 KB |
2298 | } |
2299 | ||
debe6624 | 2300 | void wxWindow::MSWOnMButtonUp(int x, int y, WXUINT flags) |
2bda0e17 | 2301 | { |
2d0a075d | 2302 | wxMouseEvent event(wxEVT_MIDDLE_UP); |
2bda0e17 | 2303 | |
2d0a075d JS |
2304 | event.m_x = x; event.m_y = y; |
2305 | event.m_shiftDown = ((flags & MK_SHIFT) != 0); | |
2306 | event.m_controlDown = ((flags & MK_CONTROL) != 0); | |
2307 | event.m_leftDown = ((flags & MK_LBUTTON) != 0); | |
2308 | event.m_middleDown = ((flags & MK_MBUTTON) != 0); | |
2309 | event.m_rightDown = ((flags & MK_RBUTTON) != 0); | |
2310 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2311 | event.m_eventObject = this; | |
2bda0e17 | 2312 | |
2d0a075d | 2313 | m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_MIDDLE_UP; |
debe6624 | 2314 | |
2d0a075d JS |
2315 | if (!GetEventHandler()->ProcessEvent(event)) |
2316 | Default(); | |
2bda0e17 KB |
2317 | } |
2318 | ||
debe6624 | 2319 | void wxWindow::MSWOnMButtonDClick(int x, int y, WXUINT flags) |
2bda0e17 | 2320 | { |
2d0a075d | 2321 | wxMouseEvent event(wxEVT_MIDDLE_DCLICK); |
2bda0e17 | 2322 | |
2d0a075d JS |
2323 | event.m_x = x; event.m_y = y; |
2324 | event.m_shiftDown = ((flags & MK_SHIFT) != 0); | |
2325 | event.m_controlDown = ((flags & MK_CONTROL) != 0); | |
2326 | event.m_leftDown = ((flags & MK_LBUTTON) != 0); | |
2327 | event.m_middleDown = ((flags & MK_MBUTTON) != 0); | |
2328 | event.m_rightDown = ((flags & MK_RBUTTON) != 0); | |
2329 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2330 | event.m_eventObject = this; | |
2bda0e17 | 2331 | |
2d0a075d | 2332 | m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_MIDDLE_DCLICK; |
debe6624 | 2333 | |
2d0a075d JS |
2334 | if (!GetEventHandler()->ProcessEvent(event)) |
2335 | Default(); | |
2bda0e17 KB |
2336 | } |
2337 | ||
debe6624 | 2338 | void wxWindow::MSWOnRButtonDown(int x, int y, WXUINT flags) |
2bda0e17 | 2339 | { |
2d0a075d | 2340 | wxMouseEvent event(wxEVT_RIGHT_DOWN); |
2bda0e17 | 2341 | |
2d0a075d JS |
2342 | event.m_x = x; event.m_y = y; |
2343 | event.m_shiftDown = ((flags & MK_SHIFT) != 0); | |
2344 | event.m_controlDown = ((flags & MK_CONTROL) != 0); | |
2345 | event.m_leftDown = ((flags & MK_LBUTTON) != 0); | |
2346 | event.m_middleDown = ((flags & MK_MBUTTON) != 0); | |
2347 | event.m_rightDown = ((flags & MK_RBUTTON) != 0); | |
2348 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2349 | event.m_eventObject = this; | |
2bda0e17 | 2350 | |
2d0a075d | 2351 | m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_RIGHT_DOWN; |
debe6624 | 2352 | |
2d0a075d JS |
2353 | if (!GetEventHandler()->ProcessEvent(event)) |
2354 | Default(); | |
2bda0e17 KB |
2355 | } |
2356 | ||
debe6624 | 2357 | void wxWindow::MSWOnRButtonUp(int x, int y, WXUINT flags) |
2bda0e17 | 2358 | { |
2d0a075d | 2359 | wxMouseEvent event(wxEVT_RIGHT_UP); |
2bda0e17 | 2360 | |
2d0a075d JS |
2361 | event.m_x = x; event.m_y = y; |
2362 | event.m_shiftDown = ((flags & MK_SHIFT) != 0); | |
2363 | event.m_controlDown = ((flags & MK_CONTROL) != 0); | |
2364 | event.m_leftDown = ((flags & MK_LBUTTON) != 0); | |
2365 | event.m_middleDown = ((flags & MK_MBUTTON) != 0); | |
2366 | event.m_rightDown = ((flags & MK_RBUTTON) != 0); | |
2367 | event.m_eventObject = this; | |
2368 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2bda0e17 | 2369 | |
2d0a075d | 2370 | m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_RIGHT_UP; |
debe6624 | 2371 | |
2d0a075d JS |
2372 | if (!GetEventHandler()->ProcessEvent(event)) |
2373 | Default(); | |
2bda0e17 KB |
2374 | } |
2375 | ||
debe6624 | 2376 | void wxWindow::MSWOnRButtonDClick(int x, int y, WXUINT flags) |
2bda0e17 | 2377 | { |
2d0a075d | 2378 | wxMouseEvent event(wxEVT_RIGHT_DCLICK); |
2bda0e17 | 2379 | |
2d0a075d JS |
2380 | event.m_x = x; event.m_y = y; |
2381 | event.m_shiftDown = ((flags & MK_SHIFT) != 0); | |
2382 | event.m_controlDown = ((flags & MK_CONTROL) != 0); | |
2383 | event.m_leftDown = ((flags & MK_LBUTTON) != 0); | |
2384 | event.m_middleDown = ((flags & MK_MBUTTON) != 0); | |
2385 | event.m_rightDown = ((flags & MK_RBUTTON) != 0); | |
2386 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2387 | event.m_eventObject = this; | |
2bda0e17 | 2388 | |
2d0a075d | 2389 | m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_RIGHT_DCLICK; |
debe6624 | 2390 | |
2d0a075d JS |
2391 | if (!GetEventHandler()->ProcessEvent(event)) |
2392 | Default(); | |
2bda0e17 KB |
2393 | } |
2394 | ||
debe6624 | 2395 | void wxWindow::MSWOnMouseMove(int x, int y, WXUINT flags) |
2bda0e17 | 2396 | { |
2d0a075d JS |
2397 | // 'normal' move event... |
2398 | // Set cursor, but only if we're not in 'busy' mode | |
2bda0e17 | 2399 | |
2d0a075d JS |
2400 | // Trouble with this is that it sets the cursor for controls too :-( |
2401 | if (m_windowCursor.Ok() && !wxIsBusy()) | |
2402 | ::SetCursor((HCURSOR) m_windowCursor.GetHCURSOR()); | |
2bda0e17 | 2403 | |
2d0a075d JS |
2404 | if (!m_mouseInWindow) |
2405 | { | |
2406 | // Generate an ENTER event | |
2407 | m_mouseInWindow = TRUE; | |
2408 | MSWOnMouseEnter(x, y, flags); | |
2409 | } | |
2bda0e17 | 2410 | |
2d0a075d | 2411 | wxMouseEvent event(wxEVT_MOTION); |
debe6624 | 2412 | |
2d0a075d JS |
2413 | event.m_x = x; event.m_y = y; |
2414 | event.m_shiftDown = ((flags & MK_SHIFT) != 0); | |
2415 | event.m_controlDown = ((flags & MK_CONTROL) != 0); | |
2416 | event.m_leftDown = ((flags & MK_LBUTTON) != 0); | |
2417 | event.m_middleDown = ((flags & MK_MBUTTON) != 0); | |
2418 | event.m_rightDown = ((flags & MK_RBUTTON) != 0); | |
2419 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2420 | event.m_eventObject = this; | |
2421 | ||
2422 | // Window gets a click down message followed by a mouse move | |
2423 | // message even if position isn't changed! We want to discard | |
2424 | // the trailing move event if x and y are the same. | |
2425 | if ((m_lastEvent == wxEVT_RIGHT_DOWN || m_lastEvent == wxEVT_LEFT_DOWN || | |
2426 | m_lastEvent == wxEVT_MIDDLE_DOWN) && | |
2427 | (m_lastXPos == event.m_x && m_lastYPos == event.m_y)) | |
2428 | { | |
2429 | m_lastXPos = event.m_x; m_lastYPos = event.m_y; | |
2430 | m_lastEvent = wxEVT_MOTION; | |
2431 | return; | |
2432 | } | |
2433 | ||
2434 | m_lastEvent = wxEVT_MOTION; | |
2435 | m_lastXPos = event.m_x; m_lastYPos = event.m_y; | |
2436 | ||
2437 | if (!GetEventHandler()->ProcessEvent(event)) | |
2438 | Default(); | |
2bda0e17 | 2439 | } |
2bda0e17 | 2440 | |
debe6624 | 2441 | void wxWindow::MSWOnMouseEnter(int x, int y, WXUINT flags) |
2bda0e17 | 2442 | { |
2d0a075d | 2443 | wxMouseEvent event(wxEVT_ENTER_WINDOW); |
2bda0e17 | 2444 | |
2d0a075d JS |
2445 | event.m_x = x; event.m_y = y; |
2446 | event.m_shiftDown = ((flags & MK_SHIFT) != 0); | |
2447 | event.m_controlDown = ((flags & MK_CONTROL) != 0); | |
2448 | event.m_leftDown = ((flags & MK_LBUTTON) != 0); | |
2449 | event.m_middleDown = ((flags & MK_MBUTTON) != 0); | |
2450 | event.m_rightDown = ((flags & MK_RBUTTON) != 0); | |
2451 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2452 | event.m_eventObject = this; | |
2bda0e17 | 2453 | |
2d0a075d JS |
2454 | m_lastEvent = wxEVT_ENTER_WINDOW; |
2455 | m_lastXPos = event.m_x; m_lastYPos = event.m_y; | |
2456 | // No message - ensure we don't try to call the default behaviour accidentally. | |
2457 | m_lastMsg = 0; | |
2458 | GetEventHandler()->ProcessEvent(event); | |
2bda0e17 KB |
2459 | } |
2460 | ||
debe6624 | 2461 | void wxWindow::MSWOnMouseLeave(int x, int y, WXUINT flags) |
2bda0e17 | 2462 | { |
2d0a075d | 2463 | wxMouseEvent event(wxEVT_LEAVE_WINDOW); |
2bda0e17 | 2464 | |
2d0a075d JS |
2465 | event.m_x = x; event.m_y = y; |
2466 | event.m_shiftDown = ((flags & MK_SHIFT) != 0); | |
2467 | event.m_controlDown = ((flags & MK_CONTROL) != 0); | |
2468 | event.m_leftDown = ((flags & MK_LBUTTON) != 0); | |
2469 | event.m_middleDown = ((flags & MK_MBUTTON) != 0); | |
2470 | event.m_rightDown = ((flags & MK_RBUTTON) != 0); | |
2471 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2472 | event.m_eventObject = this; | |
2bda0e17 | 2473 | |
2d0a075d JS |
2474 | m_lastEvent = wxEVT_LEAVE_WINDOW; |
2475 | m_lastXPos = event.m_x; m_lastYPos = event.m_y; | |
2476 | // No message - ensure we don't try to call the default behaviour accidentally. | |
2477 | m_lastMsg = 0; | |
2478 | GetEventHandler()->ProcessEvent(event); | |
2bda0e17 KB |
2479 | } |
2480 | ||
dbda9e86 | 2481 | bool wxWindow::MSWOnChar(WXWORD wParam, WXLPARAM lParam, bool isASCII) |
2bda0e17 | 2482 | { |
2d0a075d JS |
2483 | int id; |
2484 | bool tempControlDown = FALSE; | |
2485 | if (isASCII) | |
2bda0e17 | 2486 | { |
2d0a075d JS |
2487 | // If 1 -> 26, translate to CTRL plus a letter. |
2488 | id = wParam; | |
2489 | if ((id > 0) && (id < 27)) | |
2bda0e17 | 2490 | { |
2d0a075d JS |
2491 | switch (id) |
2492 | { | |
2493 | case 13: | |
2494 | { | |
2495 | id = WXK_RETURN; | |
2496 | break; | |
2497 | } | |
2498 | case 8: | |
2499 | { | |
2500 | id = WXK_BACK; | |
2501 | break; | |
2502 | } | |
2503 | case 9: | |
2504 | { | |
2505 | id = WXK_TAB; | |
2506 | break; | |
2507 | } | |
2508 | default: | |
2509 | { | |
2510 | tempControlDown = TRUE; | |
2511 | id = id + 96; | |
2512 | } | |
2513 | } | |
2bda0e17 | 2514 | } |
2bda0e17 | 2515 | } |
2d0a075d JS |
2516 | else if ((id = wxCharCodeMSWToWX(wParam)) == 0) { |
2517 | // it's ASCII and will be processed here only when called from | |
2518 | // WM_CHAR (i.e. when isASCII = TRUE) | |
2519 | id = -1; | |
2520 | } | |
2bda0e17 | 2521 | |
2d0a075d JS |
2522 | if (id != -1) |
2523 | { | |
2524 | wxKeyEvent event(wxEVT_CHAR); | |
2525 | event.m_shiftDown = (::GetKeyState(VK_SHIFT)&0x100?TRUE:FALSE); | |
2526 | event.m_controlDown = (::GetKeyState(VK_CONTROL)&0x100?TRUE:FALSE); | |
2527 | if ((HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN) | |
2528 | event.m_altDown = TRUE; | |
2529 | ||
2530 | event.m_eventObject = this; | |
2531 | event.m_keyCode = id; | |
2532 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2533 | ||
2534 | POINT pt ; | |
2535 | GetCursorPos(&pt) ; | |
2536 | RECT rect ; | |
2537 | GetWindowRect((HWND) GetHWND(),&rect) ; | |
2538 | pt.x -= rect.left ; | |
2539 | pt.y -= rect.top ; | |
2540 | ||
2541 | event.m_x = pt.x; event.m_y = pt.y; | |
2542 | ||
dbda9e86 JS |
2543 | if (GetEventHandler()->ProcessEvent(event)) |
2544 | return TRUE; | |
2545 | else | |
2546 | return FALSE; | |
2d0a075d | 2547 | } |
dbda9e86 JS |
2548 | else |
2549 | return FALSE; | |
2bda0e17 KB |
2550 | } |
2551 | ||
dbda9e86 | 2552 | bool wxWindow::MSWOnKeyDown(WXWORD wParam, WXLPARAM lParam, bool isASCII) |
4ce81a75 JS |
2553 | { |
2554 | int id; | |
2555 | ||
2556 | if ((id = wxCharCodeMSWToWX(wParam)) == 0) { | |
2557 | id = wParam; | |
2558 | } | |
2559 | ||
2560 | if (id != -1) | |
2561 | { | |
2562 | wxKeyEvent event(wxEVT_KEY_DOWN); | |
2563 | event.m_shiftDown = (::GetKeyState(VK_SHIFT)&0x100?TRUE:FALSE); | |
2564 | event.m_controlDown = (::GetKeyState(VK_CONTROL)&0x100?TRUE:FALSE); | |
2565 | if ((HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN) | |
2566 | event.m_altDown = TRUE; | |
2567 | ||
2568 | event.m_eventObject = this; | |
2569 | event.m_keyCode = id; | |
2570 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2571 | ||
2572 | POINT pt ; | |
2573 | GetCursorPos(&pt) ; | |
2574 | RECT rect ; | |
2575 | GetWindowRect((HWND) GetHWND(),&rect) ; | |
2576 | pt.x -= rect.left ; | |
2577 | pt.y -= rect.top ; | |
2578 | ||
2579 | event.m_x = pt.x; event.m_y = pt.y; | |
2580 | ||
dbda9e86 JS |
2581 | if (GetEventHandler()->ProcessEvent(event)) |
2582 | { | |
2583 | return TRUE; | |
2584 | } | |
2585 | else return FALSE; | |
2586 | } | |
2587 | else | |
2588 | { | |
2589 | return FALSE; | |
4ce81a75 JS |
2590 | } |
2591 | } | |
2592 | ||
dbda9e86 | 2593 | bool wxWindow::MSWOnKeyUp(WXWORD wParam, WXLPARAM lParam, bool isASCII) |
4ce81a75 JS |
2594 | { |
2595 | int id; | |
2596 | ||
2597 | if ((id = wxCharCodeMSWToWX(wParam)) == 0) { | |
2598 | id = wParam; | |
2599 | } | |
2600 | ||
2601 | if (id != -1) | |
2602 | { | |
2603 | wxKeyEvent event(wxEVT_KEY_UP); | |
2604 | event.m_shiftDown = (::GetKeyState(VK_SHIFT)&0x100?TRUE:FALSE); | |
2605 | event.m_controlDown = (::GetKeyState(VK_CONTROL)&0x100?TRUE:FALSE); | |
2606 | if ((HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN) | |
2607 | event.m_altDown = TRUE; | |
2608 | ||
2609 | event.m_eventObject = this; | |
2610 | event.m_keyCode = id; | |
2611 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
2612 | ||
2613 | POINT pt ; | |
2614 | GetCursorPos(&pt) ; | |
2615 | RECT rect ; | |
2616 | GetWindowRect((HWND) GetHWND(),&rect) ; | |
2617 | pt.x -= rect.left ; | |
2618 | pt.y -= rect.top ; | |
2619 | ||
2620 | event.m_x = pt.x; event.m_y = pt.y; | |
2621 | ||
dbda9e86 JS |
2622 | if (GetEventHandler()->ProcessEvent(event)) |
2623 | return TRUE; | |
2624 | else | |
2625 | return FALSE; | |
4ce81a75 | 2626 | } |
dbda9e86 JS |
2627 | else |
2628 | return FALSE; | |
4ce81a75 JS |
2629 | } |
2630 | ||
debe6624 | 2631 | void wxWindow::MSWOnJoyDown(int joystick, int x, int y, WXUINT flags) |
2bda0e17 KB |
2632 | { |
2633 | int buttons = 0; | |
2634 | int change = 0; | |
2635 | if (flags & JOY_BUTTON1CHG) | |
2636 | change = wxJOY_BUTTON1; | |
2637 | if (flags & JOY_BUTTON2CHG) | |
2638 | change = wxJOY_BUTTON2; | |
2639 | if (flags & JOY_BUTTON3CHG) | |
2640 | change = wxJOY_BUTTON3; | |
2641 | if (flags & JOY_BUTTON4CHG) | |
2642 | change = wxJOY_BUTTON4; | |
c085e333 | 2643 | |
2bda0e17 KB |
2644 | if (flags & JOY_BUTTON1) |
2645 | buttons |= wxJOY_BUTTON1; | |
2646 | if (flags & JOY_BUTTON2) | |
2647 | buttons |= wxJOY_BUTTON2; | |
2648 | if (flags & JOY_BUTTON3) | |
2649 | buttons |= wxJOY_BUTTON3; | |
2650 | if (flags & JOY_BUTTON4) | |
2651 | buttons |= wxJOY_BUTTON4; | |
c085e333 | 2652 | |
2bda0e17 KB |
2653 | wxJoystickEvent event(wxEVT_JOY_BUTTON_DOWN, buttons, joystick, change); |
2654 | event.SetPosition(wxPoint(x, y)); | |
2655 | event.SetEventObject(this); | |
c085e333 | 2656 | |
2bda0e17 KB |
2657 | GetEventHandler()->ProcessEvent(event); |
2658 | } | |
2659 | ||
debe6624 | 2660 | void wxWindow::MSWOnJoyUp(int joystick, int x, int y, WXUINT flags) |
2bda0e17 KB |
2661 | { |
2662 | int buttons = 0; | |
2663 | int change = 0; | |
2664 | if (flags & JOY_BUTTON1CHG) | |
2665 | change = wxJOY_BUTTON1; | |
2666 | if (flags & JOY_BUTTON2CHG) | |
2667 | change = wxJOY_BUTTON2; | |
2668 | if (flags & JOY_BUTTON3CHG) | |
2669 | change = wxJOY_BUTTON3; | |
2670 | if (flags & JOY_BUTTON4CHG) | |
2671 | change = wxJOY_BUTTON4; | |
c085e333 | 2672 | |
2bda0e17 KB |
2673 | if (flags & JOY_BUTTON1) |
2674 | buttons |= wxJOY_BUTTON1; | |
2675 | if (flags & JOY_BUTTON2) | |
2676 | buttons |= wxJOY_BUTTON2; | |
2677 | if (flags & JOY_BUTTON3) | |
2678 | buttons |= wxJOY_BUTTON3; | |
2679 | if (flags & JOY_BUTTON4) | |
2680 | buttons |= wxJOY_BUTTON4; | |
c085e333 | 2681 | |
2bda0e17 KB |
2682 | wxJoystickEvent event(wxEVT_JOY_BUTTON_UP, buttons, joystick, change); |
2683 | event.SetPosition(wxPoint(x, y)); | |
2684 | event.SetEventObject(this); | |
c085e333 | 2685 | |
2bda0e17 KB |
2686 | GetEventHandler()->ProcessEvent(event); |
2687 | } | |
2688 | ||
debe6624 | 2689 | void wxWindow::MSWOnJoyMove(int joystick, int x, int y, WXUINT flags) |
2bda0e17 KB |
2690 | { |
2691 | int buttons = 0; | |
2692 | if (flags & JOY_BUTTON1) | |
2693 | buttons |= wxJOY_BUTTON1; | |
2694 | if (flags & JOY_BUTTON2) | |
2695 | buttons |= wxJOY_BUTTON2; | |
2696 | if (flags & JOY_BUTTON3) | |
2697 | buttons |= wxJOY_BUTTON3; | |
2698 | if (flags & JOY_BUTTON4) | |
2699 | buttons |= wxJOY_BUTTON4; | |
c085e333 | 2700 | |
2bda0e17 KB |
2701 | wxJoystickEvent event(wxEVT_JOY_MOVE, buttons, joystick, 0); |
2702 | event.SetPosition(wxPoint(x, y)); | |
2703 | event.SetEventObject(this); | |
c085e333 | 2704 | |
2bda0e17 KB |
2705 | GetEventHandler()->ProcessEvent(event); |
2706 | } | |
2707 | ||
debe6624 | 2708 | void wxWindow::MSWOnJoyZMove(int joystick, int z, WXUINT flags) |
2bda0e17 KB |
2709 | { |
2710 | int buttons = 0; | |
2711 | if (flags & JOY_BUTTON1) | |
2712 | buttons |= wxJOY_BUTTON1; | |
2713 | if (flags & JOY_BUTTON2) | |
2714 | buttons |= wxJOY_BUTTON2; | |
2715 | if (flags & JOY_BUTTON3) | |
2716 | buttons |= wxJOY_BUTTON3; | |
2717 | if (flags & JOY_BUTTON4) | |
2718 | buttons |= wxJOY_BUTTON4; | |
c085e333 | 2719 | |
2bda0e17 KB |
2720 | wxJoystickEvent event(wxEVT_JOY_ZMOVE, buttons, joystick, 0); |
2721 | event.SetZPosition(z); | |
2722 | event.SetEventObject(this); | |
c085e333 | 2723 | |
2bda0e17 KB |
2724 | GetEventHandler()->ProcessEvent(event); |
2725 | } | |
2726 | ||
debe6624 | 2727 | void wxWindow::MSWOnVScroll(WXWORD wParam, WXWORD pos, WXHWND control) |
2bda0e17 | 2728 | { |
2d0a075d | 2729 | if (control) |
564b2609 | 2730 | { |
2d0a075d JS |
2731 | wxWindow *child = wxFindWinFromHandle(control); |
2732 | if ( child ) | |
2733 | child->MSWOnVScroll(wParam, pos, control); | |
2734 | return; | |
564b2609 | 2735 | } |
2bda0e17 | 2736 | |
564b2609 VZ |
2737 | wxScrollEvent event; |
2738 | event.SetPosition(pos); | |
2d0a075d | 2739 | event.SetOrientation(wxVERTICAL); |
564b2609 | 2740 | event.m_eventObject = this; |
2d0a075d | 2741 | |
564b2609 VZ |
2742 | switch ( wParam ) |
2743 | { | |
2d0a075d | 2744 | case SB_TOP: |
564b2609 VZ |
2745 | event.m_eventType = wxEVT_SCROLL_TOP; |
2746 | break; | |
2d0a075d JS |
2747 | |
2748 | case SB_BOTTOM: | |
564b2609 VZ |
2749 | event.m_eventType = wxEVT_SCROLL_BOTTOM; |
2750 | break; | |
2d0a075d JS |
2751 | |
2752 | case SB_LINEUP: | |
564b2609 VZ |
2753 | event.m_eventType = wxEVT_SCROLL_LINEUP; |
2754 | break; | |
2d0a075d JS |
2755 | |
2756 | case SB_LINEDOWN: | |
564b2609 VZ |
2757 | event.m_eventType = wxEVT_SCROLL_LINEDOWN; |
2758 | break; | |
2d0a075d JS |
2759 | |
2760 | case SB_PAGEUP: | |
564b2609 VZ |
2761 | event.m_eventType = wxEVT_SCROLL_PAGEUP; |
2762 | break; | |
2d0a075d JS |
2763 | |
2764 | case SB_PAGEDOWN: | |
564b2609 VZ |
2765 | event.m_eventType = wxEVT_SCROLL_PAGEDOWN; |
2766 | break; | |
2d0a075d JS |
2767 | |
2768 | case SB_THUMBTRACK: | |
2769 | case SB_THUMBPOSITION: | |
564b2609 VZ |
2770 | event.m_eventType = wxEVT_SCROLL_THUMBTRACK; |
2771 | break; | |
2d0a075d JS |
2772 | |
2773 | default: | |
564b2609 | 2774 | return; |
2d0a075d | 2775 | break; |
564b2609 | 2776 | } |
c085e333 | 2777 | |
2d0a075d JS |
2778 | if (!GetEventHandler()->ProcessEvent(event)) |
2779 | Default(); | |
2780 | } | |
2781 | ||
2782 | void wxWindow::MSWOnHScroll( WXWORD wParam, WXWORD pos, WXHWND control) | |
2783 | { | |
2784 | if (control) | |
2785 | { | |
2786 | wxWindow *child = wxFindWinFromHandle(control); | |
2787 | if ( child ) { | |
2788 | child->MSWOnHScroll(wParam, pos, control); | |
2789 | ||
2790 | return; | |
2791 | } | |
2792 | } | |
2793 | else { | |
2794 | wxScrollEvent event; | |
2795 | event.SetPosition(pos); | |
2796 | event.SetOrientation(wxHORIZONTAL); | |
2797 | event.m_eventObject = this; | |
2798 | ||
2799 | switch ( wParam ) | |
2800 | { | |
2801 | case SB_TOP: | |
2802 | event.m_eventType = wxEVT_SCROLL_TOP; | |
2803 | break; | |
2804 | ||
2805 | case SB_BOTTOM: | |
2806 | event.m_eventType = wxEVT_SCROLL_BOTTOM; | |
2807 | break; | |
2808 | ||
2809 | case SB_LINEUP: | |
2810 | event.m_eventType = wxEVT_SCROLL_LINEUP; | |
2811 | break; | |
2bda0e17 | 2812 | |
2d0a075d JS |
2813 | case SB_LINEDOWN: |
2814 | event.m_eventType = wxEVT_SCROLL_LINEDOWN; | |
2815 | break; | |
2816 | ||
2817 | case SB_PAGEUP: | |
2818 | event.m_eventType = wxEVT_SCROLL_PAGEUP; | |
2819 | break; | |
2820 | ||
2821 | case SB_PAGEDOWN: | |
2822 | event.m_eventType = wxEVT_SCROLL_PAGEDOWN; | |
2823 | break; | |
2824 | ||
2825 | case SB_THUMBTRACK: | |
2826 | case SB_THUMBPOSITION: | |
2827 | event.m_eventType = wxEVT_SCROLL_THUMBTRACK; | |
2828 | break; | |
2829 | ||
2830 | default: | |
2831 | return; | |
2832 | } | |
2bda0e17 | 2833 | |
2d0a075d JS |
2834 | if ( GetEventHandler()->ProcessEvent(event) ) |
2835 | return; | |
2836 | } | |
2837 | ||
2838 | // call the default WM_HSCROLL handler: it's non trivial in some common | |
2839 | // controls (up-down control for example) | |
2840 | Default(); | |
2bda0e17 KB |
2841 | } |
2842 | ||
2843 | void wxWindow::MSWOnShow(bool show, int status) | |
2844 | { | |
2d0a075d JS |
2845 | wxShowEvent event(GetId(), show); |
2846 | event.m_eventObject = this; | |
2847 | GetEventHandler()->ProcessEvent(event); | |
2bda0e17 KB |
2848 | } |
2849 | ||
2850 | bool wxWindow::MSWOnInitDialog(WXHWND WXUNUSED(hWndFocus)) | |
2851 | { | |
2d0a075d JS |
2852 | wxInitDialogEvent event(GetId()); |
2853 | event.m_eventObject = this; | |
2854 | GetEventHandler()->ProcessEvent(event); | |
2855 | return TRUE; | |
2bda0e17 KB |
2856 | } |
2857 | ||
fd3f686c | 2858 | void wxWindow::InitDialog() |
2bda0e17 | 2859 | { |
2d0a075d JS |
2860 | wxInitDialogEvent event(GetId()); |
2861 | event.SetEventObject( this ); | |
2862 | GetEventHandler()->ProcessEvent(event); | |
2bda0e17 KB |
2863 | } |
2864 | ||
2865 | // Default init dialog behaviour is to transfer data to window | |
2866 | void wxWindow::OnInitDialog(wxInitDialogEvent& event) | |
2867 | { | |
2d0a075d | 2868 | TransferDataToWindow(); |
2bda0e17 KB |
2869 | } |
2870 | ||
2871 | void wxGetCharSize(WXHWND wnd, int *x, int *y,wxFont *the_font) | |
2872 | { | |
2d0a075d JS |
2873 | TEXTMETRIC tm; |
2874 | HDC dc = ::GetDC((HWND) wnd); | |
2875 | HFONT fnt =0; | |
2876 | HFONT was = 0; | |
2877 | if (the_font) | |
2878 | { | |
2d0a075d JS |
2879 | // the_font->UseResource(); |
2880 | // the_font->RealizeResource(); | |
fd3f686c VZ |
2881 | fnt = (HFONT)the_font->GetResourceHandle(); |
2882 | if ( fnt ) | |
2d0a075d JS |
2883 | was = (HFONT) SelectObject(dc,fnt) ; |
2884 | } | |
2885 | GetTextMetrics(dc, &tm); | |
2886 | if (the_font && fnt && was) | |
2887 | { | |
2d0a075d JS |
2888 | SelectObject(dc,was) ; |
2889 | } | |
2890 | ReleaseDC((HWND)wnd, dc); | |
2891 | *x = tm.tmAveCharWidth; | |
2892 | *y = tm.tmHeight + tm.tmExternalLeading; | |
2bda0e17 | 2893 | |
2d0a075d JS |
2894 | // if (the_font) |
2895 | // the_font->ReleaseResource(); | |
2bda0e17 KB |
2896 | } |
2897 | ||
2898 | // Returns 0 if was a normal ASCII value, not a special key. This indicates that | |
2899 | // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead. | |
2900 | int wxCharCodeMSWToWX(int keySym) | |
2901 | { | |
2d0a075d JS |
2902 | int id = 0; |
2903 | switch (keySym) | |
2904 | { | |
2905 | case VK_CANCEL: id = WXK_CANCEL; break; | |
2906 | case VK_BACK: id = WXK_BACK; break; | |
2907 | case VK_TAB: id = WXK_TAB; break; | |
564b2609 VZ |
2908 | case VK_CLEAR: id = WXK_CLEAR; break; |
2909 | case VK_RETURN: id = WXK_RETURN; break; | |
2910 | case VK_SHIFT: id = WXK_SHIFT; break; | |
2d0a075d | 2911 | case VK_CONTROL: id = WXK_CONTROL; break; |
564b2609 VZ |
2912 | case VK_MENU : id = WXK_MENU; break; |
2913 | case VK_PAUSE: id = WXK_PAUSE; break; | |
2914 | case VK_SPACE: id = WXK_SPACE; break; | |
2915 | case VK_ESCAPE: id = WXK_ESCAPE; break; | |
2916 | case VK_PRIOR: id = WXK_PRIOR; break; | |
2917 | case VK_NEXT : id = WXK_NEXT; break; | |
2918 | case VK_END: id = WXK_END; break; | |
2919 | case VK_HOME : id = WXK_HOME; break; | |
2920 | case VK_LEFT : id = WXK_LEFT; break; | |
2d0a075d | 2921 | case VK_UP: id = WXK_UP; break; |
564b2609 VZ |
2922 | case VK_RIGHT: id = WXK_RIGHT; break; |
2923 | case VK_DOWN : id = WXK_DOWN; break; | |
2924 | case VK_SELECT: id = WXK_SELECT; break; | |
2925 | case VK_PRINT: id = WXK_PRINT; break; | |
2d0a075d | 2926 | case VK_EXECUTE: id = WXK_EXECUTE; break; |
564b2609 VZ |
2927 | case VK_INSERT: id = WXK_INSERT; break; |
2928 | case VK_DELETE: id = WXK_DELETE; break; | |
2929 | case VK_HELP : id = WXK_HELP; break; | |
2d0a075d JS |
2930 | case VK_NUMPAD0: id = WXK_NUMPAD0; break; |
2931 | case VK_NUMPAD1: id = WXK_NUMPAD1; break; | |
2932 | case VK_NUMPAD2: id = WXK_NUMPAD2; break; | |
2933 | case VK_NUMPAD3: id = WXK_NUMPAD3; break; | |
2934 | case VK_NUMPAD4: id = WXK_NUMPAD4; break; | |
2935 | case VK_NUMPAD5: id = WXK_NUMPAD5; break; | |
2936 | case VK_NUMPAD6: id = WXK_NUMPAD6; break; | |
2937 | case VK_NUMPAD7: id = WXK_NUMPAD7; break; | |
2938 | case VK_NUMPAD8: id = WXK_NUMPAD8; break; | |
2939 | case VK_NUMPAD9: id = WXK_NUMPAD9; break; | |
2940 | case VK_MULTIPLY: id = WXK_MULTIPLY; break; | |
564b2609 | 2941 | case VK_ADD: id = WXK_ADD; break; |
2d0a075d JS |
2942 | case VK_SUBTRACT: id = WXK_SUBTRACT; break; |
2943 | case VK_DECIMAL: id = WXK_DECIMAL; break; | |
564b2609 | 2944 | case VK_DIVIDE: id = WXK_DIVIDE; break; |
2d0a075d JS |
2945 | case VK_F1: id = WXK_F1; break; |
2946 | case VK_F2: id = WXK_F2; break; | |
2947 | case VK_F3: id = WXK_F3; break; | |
2948 | case VK_F4: id = WXK_F4; break; | |
2949 | case VK_F5: id = WXK_F5; break; | |
2950 | case VK_F6: id = WXK_F6; break; | |
2951 | case VK_F7: id = WXK_F7; break; | |
2952 | case VK_F8: id = WXK_F8; break; | |
2953 | case VK_F9: id = WXK_F9; break; | |
564b2609 VZ |
2954 | case VK_F10: id = WXK_F10; break; |
2955 | case VK_F11: id = WXK_F11; break; | |
2956 | case VK_F12: id = WXK_F12; break; | |
2957 | case VK_F13: id = WXK_F13; break; | |
2958 | case VK_F14: id = WXK_F14; break; | |
2959 | case VK_F15: id = WXK_F15; break; | |
2960 | case VK_F16: id = WXK_F16; break; | |
2961 | case VK_F17: id = WXK_F17; break; | |
2962 | case VK_F18: id = WXK_F18; break; | |
2963 | case VK_F19: id = WXK_F19; break; | |
2964 | case VK_F20: id = WXK_F20; break; | |
2965 | case VK_F21: id = WXK_F21; break; | |
2966 | case VK_F22: id = WXK_F22; break; | |
2967 | case VK_F23: id = WXK_F23; break; | |
2968 | case VK_F24: id = WXK_F24; break; | |
2d0a075d | 2969 | case VK_NUMLOCK: id = WXK_NUMLOCK; break; |
564b2609 | 2970 | case VK_SCROLL: id = WXK_SCROLL; break; |
2bda0e17 | 2971 | default: |
2d0a075d JS |
2972 | { |
2973 | return 0; | |
2974 | } | |
2bda0e17 | 2975 | } |
2d0a075d | 2976 | return id; |
2bda0e17 KB |
2977 | } |
2978 | ||
2979 | int wxCharCodeWXToMSW(int id, bool *isVirtual) | |
2980 | { | |
2d0a075d JS |
2981 | *isVirtual = TRUE; |
2982 | int keySym = 0; | |
2983 | switch (id) | |
2984 | { | |
2985 | case WXK_CANCEL: keySym = VK_CANCEL; break; | |
564b2609 VZ |
2986 | case WXK_CLEAR: keySym = VK_CLEAR; break; |
2987 | case WXK_SHIFT: keySym = VK_SHIFT; break; | |
2d0a075d | 2988 | case WXK_CONTROL: keySym = VK_CONTROL; break; |
564b2609 VZ |
2989 | case WXK_MENU : keySym = VK_MENU; break; |
2990 | case WXK_PAUSE: keySym = VK_PAUSE; break; | |
2991 | case WXK_PRIOR: keySym = VK_PRIOR; break; | |
2992 | case WXK_NEXT : keySym = VK_NEXT; break; | |
2993 | case WXK_END: keySym = VK_END; break; | |
2994 | case WXK_HOME : keySym = VK_HOME; break; | |
2995 | case WXK_LEFT : keySym = VK_LEFT; break; | |
2996 | case WXK_UP: keySym = VK_UP; break; | |
2997 | case WXK_RIGHT: keySym = VK_RIGHT; break; | |
2998 | case WXK_DOWN : keySym = VK_DOWN; break; | |
2d0a075d | 2999 | case WXK_SELECT: keySym = VK_SELECT; break; |
564b2609 | 3000 | case WXK_PRINT: keySym = VK_PRINT; break; |
2d0a075d JS |
3001 | case WXK_EXECUTE: keySym = VK_EXECUTE; break; |
3002 | case WXK_INSERT: keySym = VK_INSERT; break; | |
3003 | case WXK_DELETE: keySym = VK_DELETE; break; | |
564b2609 | 3004 | case WXK_HELP : keySym = VK_HELP; break; |
2d0a075d JS |
3005 | case WXK_NUMPAD0: keySym = VK_NUMPAD0; break; |
3006 | case WXK_NUMPAD1: keySym = VK_NUMPAD1; break; | |
3007 | case WXK_NUMPAD2: keySym = VK_NUMPAD2; break; | |
3008 | case WXK_NUMPAD3: keySym = VK_NUMPAD3; break; | |
3009 | case WXK_NUMPAD4: keySym = VK_NUMPAD4; break; | |
3010 | case WXK_NUMPAD5: keySym = VK_NUMPAD5; break; | |
3011 | case WXK_NUMPAD6: keySym = VK_NUMPAD6; break; | |
3012 | case WXK_NUMPAD7: keySym = VK_NUMPAD7; break; | |
3013 | case WXK_NUMPAD8: keySym = VK_NUMPAD8; break; | |
3014 | case WXK_NUMPAD9: keySym = VK_NUMPAD9; break; | |
3015 | case WXK_MULTIPLY: keySym = VK_MULTIPLY; break; | |
564b2609 | 3016 | case WXK_ADD: keySym = VK_ADD; break; |
2d0a075d JS |
3017 | case WXK_SUBTRACT: keySym = VK_SUBTRACT; break; |
3018 | case WXK_DECIMAL: keySym = VK_DECIMAL; break; | |
3019 | case WXK_DIVIDE: keySym = VK_DIVIDE; break; | |
564b2609 VZ |
3020 | case WXK_F1: keySym = VK_F1; break; |
3021 | case WXK_F2: keySym = VK_F2; break; | |
3022 | case WXK_F3: keySym = VK_F3; break; | |
3023 | case WXK_F4: keySym = VK_F4; break; | |
3024 | case WXK_F5: keySym = VK_F5; break; | |
3025 | case WXK_F6: keySym = VK_F6; break; | |
3026 | case WXK_F7: keySym = VK_F7; break; | |
3027 | case WXK_F8: keySym = VK_F8; break; | |
3028 | case WXK_F9: keySym = VK_F9; break; | |
3029 | case WXK_F10: keySym = VK_F10; break; | |
3030 | case WXK_F11: keySym = VK_F11; break; | |
3031 | case WXK_F12: keySym = VK_F12; break; | |
3032 | case WXK_F13: keySym = VK_F13; break; | |
3033 | case WXK_F14: keySym = VK_F14; break; | |
3034 | case WXK_F15: keySym = VK_F15; break; | |
3035 | case WXK_F16: keySym = VK_F16; break; | |
3036 | case WXK_F17: keySym = VK_F17; break; | |
3037 | case WXK_F18: keySym = VK_F18; break; | |
3038 | case WXK_F19: keySym = VK_F19; break; | |
3039 | case WXK_F20: keySym = VK_F20; break; | |
3040 | case WXK_F21: keySym = VK_F21; break; | |
3041 | case WXK_F22: keySym = VK_F22; break; | |
3042 | case WXK_F23: keySym = VK_F23; break; | |
3043 | case WXK_F24: keySym = VK_F24; break; | |
2d0a075d JS |
3044 | case WXK_NUMLOCK: keySym = VK_NUMLOCK; break; |
3045 | case WXK_SCROLL: keySym = VK_SCROLL; break; | |
2bda0e17 | 3046 | default: |
2d0a075d JS |
3047 | { |
3048 | *isVirtual = FALSE; | |
3049 | keySym = id; | |
3050 | break; | |
3051 | } | |
2bda0e17 | 3052 | } |
2d0a075d | 3053 | return keySym; |
2bda0e17 KB |
3054 | } |
3055 | ||
3056 | // Caret manipulation | |
debe6624 | 3057 | void wxWindow::CreateCaret(int w, int h) |
2bda0e17 | 3058 | { |
2d0a075d JS |
3059 | m_caretWidth = w; |
3060 | m_caretHeight = h; | |
3061 | m_caretEnabled = TRUE; | |
2bda0e17 KB |
3062 | } |
3063 | ||
3064 | void wxWindow::CreateCaret(const wxBitmap *WXUNUSED(bitmap)) | |
3065 | { | |
2d0a075d | 3066 | // Not implemented |
2bda0e17 KB |
3067 | } |
3068 | ||
debe6624 | 3069 | void wxWindow::ShowCaret(bool show) |
2bda0e17 | 3070 | { |
2d0a075d JS |
3071 | if (m_caretEnabled) |
3072 | { | |
3073 | if (show) | |
3074 | ::ShowCaret((HWND) GetHWND()); | |
3075 | else | |
3076 | ::HideCaret((HWND) GetHWND()); | |
3077 | m_caretShown = show; | |
3078 | } | |
2bda0e17 KB |
3079 | } |
3080 | ||
fd3f686c | 3081 | void wxWindow::DestroyCaret() |
2bda0e17 | 3082 | { |
2d0a075d | 3083 | m_caretEnabled = FALSE; |
2bda0e17 KB |
3084 | } |
3085 | ||
debe6624 | 3086 | void wxWindow::SetCaretPos(int x, int y) |
2bda0e17 | 3087 | { |
2d0a075d | 3088 | ::SetCaretPos(x, y); |
2bda0e17 KB |
3089 | } |
3090 | ||
3091 | void wxWindow::GetCaretPos(int *x, int *y) const | |
3092 | { | |
2d0a075d JS |
3093 | POINT point; |
3094 | ::GetCaretPos(&point); | |
3095 | *x = point.x; | |
3096 | *y = point.y; | |
2bda0e17 KB |
3097 | } |
3098 | ||
fd3f686c | 3099 | wxWindow *wxGetActiveWindow() |
2bda0e17 | 3100 | { |
2d0a075d JS |
3101 | HWND hWnd = GetActiveWindow(); |
3102 | if (hWnd != 0) | |
3103 | { | |
3104 | return wxFindWinFromHandle((WXHWND) hWnd); | |
3105 | } | |
3106 | return NULL; | |
2bda0e17 KB |
3107 | } |
3108 | ||
3109 | // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE | |
3110 | // in active frames and dialogs, regardless of where the focus is. | |
3111 | static HHOOK wxTheKeyboardHook = 0; | |
3112 | static FARPROC wxTheKeyboardHookProc = 0; | |
3113 | int APIENTRY _EXPORT | |
2d0a075d | 3114 | wxKeyboardHook(int nCode, WORD wParam, DWORD lParam); |
2bda0e17 KB |
3115 | |
3116 | void wxSetKeyboardHook(bool doIt) | |
3117 | { | |
2d0a075d JS |
3118 | if (doIt) |
3119 | { | |
3120 | wxTheKeyboardHookProc = MakeProcInstance((FARPROC) wxKeyboardHook, wxGetInstance()); | |
3121 | wxTheKeyboardHook = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC) wxTheKeyboardHookProc, wxGetInstance(), | |
57c208c5 | 3122 | #if defined(__WIN32__) && !defined(__TWIN32__) |
2d0a075d JS |
3123 | GetCurrentThreadId()); |
3124 | // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right? | |
2bda0e17 | 3125 | #else |
2d0a075d | 3126 | GetCurrentTask()); |
2bda0e17 | 3127 | #endif |
2d0a075d JS |
3128 | } |
3129 | else | |
3130 | { | |
3131 | UnhookWindowsHookEx(wxTheKeyboardHook); | |
3132 | FreeProcInstance(wxTheKeyboardHookProc); | |
3133 | } | |
2bda0e17 KB |
3134 | } |
3135 | ||
3136 | int APIENTRY _EXPORT | |
2d0a075d | 3137 | wxKeyboardHook(int nCode, WORD wParam, DWORD lParam) |
2bda0e17 | 3138 | { |
2d0a075d JS |
3139 | DWORD hiWord = HIWORD(lParam); |
3140 | if (nCode != HC_NOREMOVE && ((hiWord & KF_UP) == 0)) | |
2bda0e17 | 3141 | { |
2d0a075d JS |
3142 | int id; |
3143 | if ((id = wxCharCodeMSWToWX(wParam)) != 0) | |
564b2609 | 3144 | { |
2d0a075d JS |
3145 | wxKeyEvent event(wxEVT_CHAR_HOOK); |
3146 | if ((HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN) | |
3147 | event.m_altDown = TRUE; | |
3148 | ||
3149 | event.m_eventObject = NULL; | |
3150 | event.m_keyCode = id; | |
3151 | /* begin Albert's fix for control and shift key 26.5 */ | |
3152 | event.m_shiftDown = (::GetKeyState(VK_SHIFT)&0x100?TRUE:FALSE); | |
3153 | event.m_controlDown = (::GetKeyState(VK_CONTROL)&0x100?TRUE:FALSE); | |
3154 | /* end Albert's fix for control and shift key 26.5 */ | |
3155 | event.SetTimestamp(wxApp::sm_lastMessageTime); | |
3156 | ||
3157 | wxWindow *win = wxGetActiveWindow(); | |
3158 | if (win) | |
3159 | { | |
3160 | if (win->GetEventHandler()->ProcessEvent(event)) | |
3161 | return 1; | |
3162 | } | |
3163 | else | |
3164 | { | |
3165 | if ( wxTheApp && wxTheApp->ProcessEvent(event) ) | |
3166 | return 1; | |
3167 | } | |
564b2609 | 3168 | } |
2bda0e17 | 3169 | } |
2d0a075d | 3170 | return (int)CallNextHookEx(wxTheKeyboardHook, nCode, wParam, lParam); |
2bda0e17 KB |
3171 | } |
3172 | ||
debe6624 | 3173 | void wxWindow::SetSizeHints(int minW, int minH, int maxW, int maxH, int WXUNUSED(incW), int WXUNUSED(incH)) |
2bda0e17 | 3174 | { |
2d0a075d JS |
3175 | m_minSizeX = minW; |
3176 | m_minSizeY = minH; | |
3177 | m_maxSizeX = maxW; | |
3178 | m_maxSizeY = maxH; | |
2bda0e17 KB |
3179 | } |
3180 | ||
debe6624 | 3181 | void wxWindow::Centre(int direction) |
2bda0e17 | 3182 | { |
2d0a075d | 3183 | int x, y, width, height, panel_width, panel_height, new_x, new_y; |
2bda0e17 | 3184 | |
2d0a075d JS |
3185 | wxWindow *father = (wxWindow *)GetParent(); |
3186 | if (!father) | |
3187 | return; | |
2bda0e17 | 3188 | |
2d0a075d JS |
3189 | father->GetClientSize(&panel_width, &panel_height); |
3190 | GetSize(&width, &height); | |
3191 | GetPosition(&x, &y); | |
2bda0e17 | 3192 | |
2d0a075d JS |
3193 | new_x = -1; |
3194 | new_y = -1; | |
2bda0e17 | 3195 | |
2d0a075d JS |
3196 | if (direction & wxHORIZONTAL) |
3197 | new_x = (int)((panel_width - width)/2); | |
2bda0e17 | 3198 | |
2d0a075d JS |
3199 | if (direction & wxVERTICAL) |
3200 | new_y = (int)((panel_height - height)/2); | |
2bda0e17 | 3201 | |
2d0a075d | 3202 | SetSize(new_x, new_y, -1, -1); |
2bda0e17 KB |
3203 | |
3204 | } | |
3205 | ||
debe6624 | 3206 | void wxWindow::WarpPointer (int x_pos, int y_pos) |
2bda0e17 | 3207 | { |
5de76427 JS |
3208 | // Move the pointer to (x_pos,y_pos) coordinates. They are expressed in |
3209 | // pixel coordinates, relatives to the canvas -- So, we first need to | |
3210 | // substract origin of the window, then convert to screen position | |
c085e333 | 3211 | |
5de76427 JS |
3212 | int x = x_pos; int y = y_pos; |
3213 | RECT rect; | |
3214 | GetWindowRect ((HWND) GetHWND(), &rect); | |
c085e333 | 3215 | |
5de76427 JS |
3216 | x += rect.left; |
3217 | y += rect.top; | |
c085e333 | 3218 | |
5de76427 | 3219 | SetCursorPos (x, y); |
2bda0e17 KB |
3220 | } |
3221 | ||
3222 | void wxWindow::MSWDeviceToLogical (float *x, float *y) const | |
3223 | { | |
2bda0e17 KB |
3224 | } |
3225 | ||
debe6624 | 3226 | bool wxWindow::MSWOnEraseBkgnd (WXHDC pDC) |
2bda0e17 KB |
3227 | { |
3228 | wxDC dc ; | |
c085e333 | 3229 | |
564b2609 VZ |
3230 | dc.SetHDC(pDC); |
3231 | dc.SetWindow(this); | |
3232 | dc.BeginDrawing(); | |
c085e333 | 3233 | |
2bda0e17 KB |
3234 | wxEraseEvent event(m_windowId, &dc); |
3235 | event.m_eventObject = this; | |
3236 | if (!GetEventHandler()->ProcessEvent(event)) | |
3237 | { | |
564b2609 VZ |
3238 | dc.EndDrawing(); |
3239 | dc.SelectOldObjects(pDC); | |
2bda0e17 KB |
3240 | return FALSE; |
3241 | } | |
3242 | else | |
3243 | { | |
564b2609 VZ |
3244 | dc.EndDrawing(); |
3245 | dc.SelectOldObjects(pDC); | |
2bda0e17 | 3246 | } |
c085e333 | 3247 | |
2bda0e17 KB |
3248 | dc.SetHDC((WXHDC) NULL); |
3249 | return TRUE; | |
3250 | } | |
3251 | ||
3252 | void wxWindow::OnEraseBackground(wxEraseEvent& event) | |
3253 | { | |
ce3ed50d JS |
3254 | if (!GetHWND()) |
3255 | return; | |
3256 | ||
2d0a075d JS |
3257 | RECT rect; |
3258 | ::GetClientRect((HWND) GetHWND(), &rect); | |
2bda0e17 | 3259 | |
ce3ed50d JS |
3260 | COLORREF ref = PALETTERGB(m_backgroundColour.Red(), m_backgroundColour.Green(), m_backgroundColour.Blue()) ; |
3261 | HBRUSH hBrush = ::CreateSolidBrush(ref); | |
2d0a075d | 3262 | int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT); |
2bda0e17 | 3263 | |
2d0a075d JS |
3264 | // ::GetClipBox((HDC) event.GetDC()->GetHDC(), &rect); |
3265 | ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush); | |
3266 | ::DeleteObject(hBrush); | |
3267 | ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode); | |
3268 | /* | |
3269 | // Less efficient version (and doesn't account for scrolling) | |
3270 | int w, h; | |
3271 | GetClientSize(& w, & h); | |
3272 | wxBrush *brush = wxTheBrushList->FindOrCreateBrush(& GetBackgroundColour(), wxSOLID); | |
3273 | event.GetDC()->SetBrush(brush); | |
3274 | event.GetDC()->SetPen(wxTRANSPARENT_PEN); | |
3275 | ||
3276 | event.GetDC()->DrawRectangle(0, 0, w+1, h+1); | |
3277 | */ | |
2bda0e17 KB |
3278 | } |
3279 | ||
3280 | #if WXWIN_COMPATIBILITY | |
debe6624 | 3281 | void wxWindow::SetScrollRange(int orient, int range, bool refresh) |
2bda0e17 KB |
3282 | { |
3283 | #if defined(__WIN95__) | |
c085e333 | 3284 | |
2d0a075d | 3285 | int range1 = range; |
2bda0e17 | 3286 | |
2d0a075d JS |
3287 | // Try to adjust the range to cope with page size > 1 |
3288 | // - a Windows API quirk | |
3289 | int pageSize = GetScrollPage(orient); | |
3290 | if ( pageSize > 1 && range > 0) | |
3291 | { | |
3292 | range1 += (pageSize - 1); | |
3293 | } | |
2bda0e17 | 3294 | |
2d0a075d JS |
3295 | SCROLLINFO info; |
3296 | int dir; | |
2bda0e17 | 3297 | |
2d0a075d JS |
3298 | if (orient == wxHORIZONTAL) { |
3299 | dir = SB_HORZ; | |
3300 | } else { | |
3301 | dir = SB_VERT; | |
3302 | } | |
2bda0e17 | 3303 | |
2d0a075d JS |
3304 | info.cbSize = sizeof(SCROLLINFO); |
3305 | info.nPage = pageSize; // Have to set this, or scrollbar goes awry | |
3306 | info.nMin = 0; | |
3307 | info.nMax = range1; | |
3308 | info.nPos = 0; | |
3309 | info.fMask = SIF_RANGE | SIF_PAGE; | |
2bda0e17 | 3310 | |
2d0a075d JS |
3311 | HWND hWnd = (HWND) GetHWND(); |
3312 | if (hWnd) | |
3313 | ::SetScrollInfo(hWnd, dir, &info, refresh); | |
2bda0e17 | 3314 | #else |
2d0a075d JS |
3315 | int wOrient ; |
3316 | if (orient == wxHORIZONTAL) | |
3317 | wOrient = SB_HORZ; | |
3318 | else | |
3319 | wOrient = SB_VERT; | |
3320 | ||
3321 | HWND hWnd = (HWND) GetHWND(); | |
3322 | if (hWnd) | |
3323 | ::SetScrollRange(hWnd, wOrient, 0, range, refresh); | |
2bda0e17 KB |
3324 | #endif |
3325 | } | |
3326 | ||
debe6624 | 3327 | void wxWindow::SetScrollPage(int orient, int page, bool refresh) |
2bda0e17 KB |
3328 | { |
3329 | #if defined(__WIN95__) | |
2d0a075d JS |
3330 | SCROLLINFO info; |
3331 | int dir; | |
3332 | ||
3333 | if (orient == wxHORIZONTAL) { | |
3334 | dir = SB_HORZ; | |
3335 | m_xThumbSize = page; | |
3336 | } else { | |
3337 | dir = SB_VERT; | |
3338 | m_yThumbSize = page; | |
3339 | } | |
2bda0e17 | 3340 | |
2d0a075d JS |
3341 | info.cbSize = sizeof(SCROLLINFO); |
3342 | info.nPage = page; | |
3343 | info.nMin = 0; | |
3344 | info.fMask = SIF_PAGE ; | |
2bda0e17 | 3345 | |
2d0a075d JS |
3346 | HWND hWnd = (HWND) GetHWND(); |
3347 | if (hWnd) | |
3348 | ::SetScrollInfo(hWnd, dir, &info, refresh); | |
2bda0e17 | 3349 | #else |
2d0a075d JS |
3350 | if (orient == wxHORIZONTAL) |
3351 | m_xThumbSize = page; | |
3352 | else | |
3353 | m_yThumbSize = page; | |
2bda0e17 KB |
3354 | #endif |
3355 | } | |
3356 | ||
debe6624 | 3357 | int wxWindow::OldGetScrollRange(int orient) const |
2bda0e17 | 3358 | { |
2d0a075d JS |
3359 | int wOrient ; |
3360 | if (orient == wxHORIZONTAL) | |
3361 | wOrient = SB_HORZ; | |
3362 | else | |
3363 | wOrient = SB_VERT; | |
2bda0e17 KB |
3364 | |
3365 | #if __WATCOMC__ && defined(__WINDOWS_386__) | |
2d0a075d | 3366 | short minPos, maxPos; |
2bda0e17 | 3367 | #else |
2d0a075d | 3368 | int minPos, maxPos; |
2bda0e17 | 3369 | #endif |
2d0a075d JS |
3370 | HWND hWnd = (HWND) GetHWND(); |
3371 | if (hWnd) | |
2bda0e17 | 3372 | { |
2d0a075d JS |
3373 | ::GetScrollRange(hWnd, wOrient, &minPos, &maxPos); |
3374 | #if defined(__WIN95__) | |
3375 | // Try to adjust the range to cope with page size > 1 | |
3376 | // - a Windows API quirk | |
3377 | int pageSize = GetScrollPage(orient); | |
3378 | if ( pageSize > 1 ) | |
3379 | { | |
3380 | maxPos -= (pageSize - 1); | |
3381 | } | |
2bda0e17 | 3382 | #endif |
2d0a075d JS |
3383 | return maxPos; |
3384 | } | |
3385 | else | |
3386 | return 0; | |
2bda0e17 KB |
3387 | } |
3388 | ||
debe6624 | 3389 | int wxWindow::GetScrollPage(int orient) const |
2bda0e17 | 3390 | { |
2d0a075d JS |
3391 | if (orient == wxHORIZONTAL) |
3392 | return m_xThumbSize; | |
3393 | else | |
3394 | return m_yThumbSize; | |
2bda0e17 KB |
3395 | } |
3396 | #endif | |
3397 | ||
debe6624 | 3398 | int wxWindow::GetScrollPos(int orient) const |
2bda0e17 | 3399 | { |
2d0a075d JS |
3400 | int wOrient ; |
3401 | if (orient == wxHORIZONTAL) | |
3402 | wOrient = SB_HORZ; | |
3403 | else | |
3404 | wOrient = SB_VERT; | |
3405 | HWND hWnd = (HWND) GetHWND(); | |
3406 | if (hWnd) | |
3407 | { | |
3408 | return ::GetScrollPos(hWnd, wOrient); | |
3409 | } | |
3410 | else | |
3411 | return 0; | |
2bda0e17 KB |
3412 | } |
3413 | ||
3414 | // This now returns the whole range, not just the number | |
3415 | // of positions that we can scroll. | |
debe6624 | 3416 | int wxWindow::GetScrollRange(int orient) const |
2bda0e17 | 3417 | { |
2d0a075d JS |
3418 | int wOrient ; |
3419 | if (orient == wxHORIZONTAL) | |
3420 | wOrient = SB_HORZ; | |
3421 | else | |
3422 | wOrient = SB_VERT; | |
2bda0e17 KB |
3423 | |
3424 | #if __WATCOMC__ && defined(__WINDOWS_386__) | |
2d0a075d | 3425 | short minPos, maxPos; |
2bda0e17 | 3426 | #else |
2d0a075d | 3427 | int minPos, maxPos; |
2bda0e17 | 3428 | #endif |
2d0a075d JS |
3429 | HWND hWnd = (HWND) GetHWND(); |
3430 | if (hWnd) | |
2bda0e17 | 3431 | { |
2d0a075d JS |
3432 | ::GetScrollRange(hWnd, wOrient, &minPos, &maxPos); |
3433 | #if defined(__WIN95__) | |
3434 | // Try to adjust the range to cope with page size > 1 | |
3435 | // - a Windows API quirk | |
ca5e9f67 | 3436 | int pageSize = GetScrollThumb(orient); |
2d0a075d JS |
3437 | if ( pageSize > 1 ) |
3438 | { | |
3439 | maxPos -= (pageSize - 1); | |
3440 | } | |
3441 | // October 10th: new range concept. | |
3442 | maxPos += pageSize; | |
2bda0e17 | 3443 | #endif |
c085e333 | 3444 | |
2d0a075d JS |
3445 | return maxPos; |
3446 | } | |
3447 | else | |
3448 | return 0; | |
2bda0e17 KB |
3449 | } |
3450 | ||
debe6624 | 3451 | int wxWindow::GetScrollThumb(int orient) const |
2bda0e17 | 3452 | { |
2d0a075d JS |
3453 | if (orient == wxHORIZONTAL) |
3454 | return m_xThumbSize; | |
3455 | else | |
3456 | return m_yThumbSize; | |
2bda0e17 KB |
3457 | } |
3458 | ||
debe6624 | 3459 | void wxWindow::SetScrollPos(int orient, int pos, bool refresh) |
2bda0e17 KB |
3460 | { |
3461 | #if defined(__WIN95__) | |
2d0a075d JS |
3462 | SCROLLINFO info; |
3463 | int dir; | |
2bda0e17 | 3464 | |
2d0a075d JS |
3465 | if (orient == wxHORIZONTAL) { |
3466 | dir = SB_HORZ; | |
3467 | } else { | |
3468 | dir = SB_VERT; | |
3469 | } | |
2bda0e17 | 3470 | |
2d0a075d JS |
3471 | info.cbSize = sizeof(SCROLLINFO); |
3472 | info.nPage = 0; | |
3473 | info.nMin = 0; | |
3474 | info.nPos = pos; | |
3475 | info.fMask = SIF_POS ; | |
2bda0e17 | 3476 | |
2d0a075d JS |
3477 | HWND hWnd = (HWND) GetHWND(); |
3478 | if (hWnd) | |
3479 | ::SetScrollInfo(hWnd, dir, &info, refresh); | |
2bda0e17 | 3480 | #else |
2d0a075d JS |
3481 | int wOrient ; |
3482 | if (orient == wxHORIZONTAL) | |
3483 | wOrient = SB_HORZ; | |
3484 | else | |
3485 | wOrient = SB_VERT; | |
3486 | ||
3487 | HWND hWnd = (HWND) GetHWND(); | |
3488 | if (hWnd) | |
3489 | ::SetScrollPos(hWnd, wOrient, pos, refresh); | |
2bda0e17 KB |
3490 | #endif |
3491 | } | |
3492 | ||
3493 | // New function that will replace some of the above. | |
debe6624 | 3494 | void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible, |
2d0a075d | 3495 | int range, bool refresh) |
2bda0e17 KB |
3496 | { |
3497 | /* | |
2d0a075d | 3498 | SetScrollPage(orient, thumbVisible, FALSE); |
2bda0e17 | 3499 | |
2d0a075d JS |
3500 | int oldRange = range - thumbVisible ; |
3501 | SetScrollRange(orient, oldRange, FALSE); | |
c085e333 | 3502 | |
2bda0e17 | 3503 | SetScrollPos(orient, pos, refresh); |
2d0a075d | 3504 | */ |
2bda0e17 | 3505 | #if defined(__WIN95__) |
2d0a075d | 3506 | int oldRange = range - thumbVisible ; |
2bda0e17 | 3507 | |
2d0a075d | 3508 | int range1 = oldRange; |
2bda0e17 | 3509 | |
2d0a075d JS |
3510 | // Try to adjust the range to cope with page size > 1 |
3511 | // - a Windows API quirk | |
3512 | int pageSize = thumbVisible; | |
3513 | if ( pageSize > 1 && range > 0) | |
3514 | { | |
3515 | range1 += (pageSize - 1); | |
3516 | } | |
2bda0e17 | 3517 | |
2d0a075d JS |
3518 | SCROLLINFO info; |
3519 | int dir; | |
2bda0e17 | 3520 | |
2d0a075d JS |
3521 | if (orient == wxHORIZONTAL) { |
3522 | dir = SB_HORZ; | |
3523 | } else { | |
3524 | dir = SB_VERT; | |
3525 | } | |
2bda0e17 | 3526 | |
2d0a075d JS |
3527 | info.cbSize = sizeof(SCROLLINFO); |
3528 | info.nPage = pageSize; // Have to set this, or scrollbar goes awry | |
3529 | info.nMin = 0; | |
3530 | info.nMax = range1; | |
3531 | info.nPos = pos; | |
3532 | info.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; | |
2bda0e17 | 3533 | |
2d0a075d JS |
3534 | HWND hWnd = (HWND) GetHWND(); |
3535 | if (hWnd) | |
3536 | ::SetScrollInfo(hWnd, dir, &info, refresh); | |
2bda0e17 | 3537 | #else |
2d0a075d JS |
3538 | int wOrient ; |
3539 | if (orient == wxHORIZONTAL) | |
3540 | wOrient = SB_HORZ; | |
3541 | else | |
3542 | wOrient = SB_VERT; | |
3543 | ||
3544 | HWND hWnd = (HWND) GetHWND(); | |
3545 | if (hWnd) | |
3546 | { | |
3547 | ::SetScrollRange(hWnd, wOrient, 0, range, FALSE); | |
3548 | ::SetScrollPos(hWnd, wOrient, pos, refresh); | |
3549 | } | |
2bda0e17 | 3550 | #endif |
2d0a075d JS |
3551 | if (orient == wxHORIZONTAL) { |
3552 | m_xThumbSize = thumbVisible; | |
3553 | } else { | |
3554 | m_yThumbSize = thumbVisible; | |
3555 | } | |
2bda0e17 KB |
3556 | } |
3557 | ||
16e93305 | 3558 | void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect) |
2bda0e17 | 3559 | { |
564b2609 VZ |
3560 | RECT rect2; |
3561 | if ( rect ) | |
3562 | { | |
3563 | rect2.left = rect->x; | |
3564 | rect2.top = rect->y; | |
3565 | rect2.right = rect->x + rect->width; | |
3566 | rect2.bottom = rect->y + rect->height; | |
3567 | } | |
c085e333 | 3568 | |
564b2609 VZ |
3569 | if ( rect ) |
3570 | ::ScrollWindow((HWND) GetHWND(), dx, dy, &rect2, NULL); | |
3571 | else | |
3572 | ::ScrollWindow((HWND) GetHWND(), dx, dy, NULL, NULL); | |
2bda0e17 KB |
3573 | } |
3574 | ||
2bda0e17 KB |
3575 | void wxWindow::SetFont(const wxFont& font) |
3576 | { | |
2d0a075d | 3577 | m_windowFont = font; |
2bda0e17 | 3578 | |
2d0a075d JS |
3579 | if (!m_windowFont.Ok()) |
3580 | return; | |
2bda0e17 | 3581 | |
2d0a075d JS |
3582 | HWND hWnd = (HWND) GetHWND(); |
3583 | if (hWnd != 0) | |
3584 | { | |
3585 | if (m_windowFont.GetResourceHandle()) | |
3586 | SendMessage(hWnd, WM_SETFONT, | |
3587 | (WPARAM)m_windowFont.GetResourceHandle(),TRUE); | |
3588 | } | |
2bda0e17 KB |
3589 | } |
3590 | ||
3591 | void wxWindow::SubclassWin(WXHWND hWnd) | |
3592 | { | |
2d0a075d | 3593 | wxASSERT_MSG( !m_oldWndProc, "subclassing window twice?" ); |
a02eb1d2 | 3594 | |
2d0a075d | 3595 | wxAssociateWinWithHandle((HWND)hWnd, this); |
2bda0e17 | 3596 | |
2d0a075d JS |
3597 | m_oldWndProc = (WXFARPROC) GetWindowLong((HWND) hWnd, GWL_WNDPROC); |
3598 | SetWindowLong((HWND) hWnd, GWL_WNDPROC, (LONG) wxWndProc); | |
2bda0e17 KB |
3599 | } |
3600 | ||
fd3f686c | 3601 | void wxWindow::UnsubclassWin() |
2bda0e17 | 3602 | { |
564b2609 | 3603 | wxRemoveHandleAssociation(this); |
c085e333 | 3604 | |
2d0a075d JS |
3605 | // Restore old Window proc |
3606 | if ((HWND) GetHWND()) | |
564b2609 | 3607 | { |
2d0a075d JS |
3608 | FARPROC farProc = (FARPROC) GetWindowLong((HWND) GetHWND(), GWL_WNDPROC); |
3609 | if ((m_oldWndProc != 0) && (farProc != (FARPROC) m_oldWndProc)) | |
3610 | { | |
3611 | SetWindowLong((HWND) GetHWND(), GWL_WNDPROC, (LONG) m_oldWndProc); | |
3612 | m_oldWndProc = 0; | |
3613 | } | |
564b2609 | 3614 | } |
2bda0e17 KB |
3615 | } |
3616 | ||
3617 | // Make a Windows extended style from the given wxWindows window style | |
3618 | WXDWORD wxWindow::MakeExtendedStyle(long style, bool eliminateBorders) | |
3619 | { | |
564b2609 VZ |
3620 | WXDWORD exStyle = 0; |
3621 | if ( style & wxTRANSPARENT_WINDOW ) | |
3622 | exStyle |= WS_EX_TRANSPARENT ; | |
c085e333 | 3623 | |
2d0a075d JS |
3624 | if ( !eliminateBorders ) |
3625 | { | |
3626 | if ( style & wxSUNKEN_BORDER ) | |
3627 | exStyle |= WS_EX_CLIENTEDGE ; | |
3628 | if ( style & wxDOUBLE_BORDER ) | |
3629 | exStyle |= WS_EX_DLGMODALFRAME ; | |
2bda0e17 | 3630 | #if defined(__WIN95__) |
2d0a075d JS |
3631 | if ( style & wxRAISED_BORDER ) |
3632 | exStyle |= WS_EX_WINDOWEDGE ; | |
3633 | if ( style & wxSTATIC_BORDER ) | |
3634 | exStyle |= WS_EX_STATICEDGE ; | |
2bda0e17 | 3635 | #endif |
2d0a075d JS |
3636 | } |
3637 | return exStyle; | |
2bda0e17 KB |
3638 | } |
3639 | ||
3640 | // Determines whether native 3D effects or CTL3D should be used, | |
3641 | // applying a default border style if required, and returning an extended | |
3642 | // style to pass to CreateWindowEx. | |
3643 | WXDWORD wxWindow::Determine3DEffects(WXDWORD defaultBorderStyle, bool *want3D) | |
3644 | { | |
2d0a075d JS |
3645 | // If matches certain criteria, then assume no 3D effects |
3646 | // unless specifically requested (dealt with in MakeExtendedStyle) | |
3647 | if ( !GetParent() || !IsKindOf(CLASSINFO(wxControl)) || (m_windowStyle & wxNO_BORDER) ) | |
3648 | { | |
3649 | *want3D = FALSE; | |
3650 | return MakeExtendedStyle(m_windowStyle, FALSE); | |
3651 | } | |
2bda0e17 | 3652 | |
2d0a075d JS |
3653 | // Determine whether we should be using 3D effects or not. |
3654 | bool nativeBorder = FALSE; // by default, we don't want a Win95 effect | |
2bda0e17 | 3655 | |
2d0a075d JS |
3656 | // 1) App can specify global 3D effects |
3657 | *want3D = wxTheApp->GetAuto3D(); | |
2bda0e17 | 3658 | |
2d0a075d JS |
3659 | // 2) If the parent is being drawn with user colours, or simple border specified, |
3660 | // switch effects off. TODO: replace wxUSER_COLOURS with wxNO_3D | |
3661 | if (GetParent() && (GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS) || (m_windowStyle & wxSIMPLE_BORDER)) | |
3662 | *want3D = FALSE; | |
2bda0e17 | 3663 | |
2d0a075d JS |
3664 | // 3) Control can override this global setting by defining |
3665 | // a border style, e.g. wxSUNKEN_BORDER | |
3666 | if (m_windowStyle & wxSUNKEN_BORDER ) | |
3667 | *want3D = TRUE; | |
2bda0e17 | 3668 | |
2d0a075d JS |
3669 | // 4) If it's a special border, CTL3D can't cope so we want a native border |
3670 | if ( (m_windowStyle & wxDOUBLE_BORDER) || (m_windowStyle & wxRAISED_BORDER) || | |
3671 | (m_windowStyle & wxSTATIC_BORDER) ) | |
3672 | { | |
3673 | *want3D = TRUE; | |
3674 | nativeBorder = TRUE; | |
3675 | } | |
2bda0e17 | 3676 | |
2d0a075d JS |
3677 | // 5) If this isn't a Win95 app, and we are using CTL3D, remove border |
3678 | // effects from extended style | |
1f112209 | 3679 | #if wxUSE_CTL3D |
2d0a075d JS |
3680 | if ( *want3D ) |
3681 | nativeBorder = FALSE; | |
2bda0e17 | 3682 | #endif |
c085e333 | 3683 | |
2d0a075d | 3684 | DWORD exStyle = MakeExtendedStyle(m_windowStyle, !nativeBorder); |
2bda0e17 | 3685 | |
2d0a075d JS |
3686 | // If we want 3D, but haven't specified a border here, |
3687 | // apply the default border style specified. | |
3688 | // TODO what about non-Win95 WIN32? Does it have borders? | |
1f112209 | 3689 | #if defined(__WIN95__) && !wxUSE_CTL3D |
2d0a075d | 3690 | if (defaultBorderStyle && (*want3D) && ! ((m_windowStyle & wxDOUBLE_BORDER) || (m_windowStyle & wxRAISED_BORDER) || |
2bda0e17 | 3691 | (m_windowStyle & wxSTATIC_BORDER) || (m_windowStyle & wxSIMPLE_BORDER) )) |
2d0a075d | 3692 | exStyle |= defaultBorderStyle; // WS_EX_CLIENTEDGE ; |
2bda0e17 | 3693 | #endif |
c085e333 | 3694 | |
2d0a075d | 3695 | return exStyle; |
2bda0e17 KB |
3696 | } |
3697 | ||
2bda0e17 KB |
3698 | void wxWindow::OnChar(wxKeyEvent& event) |
3699 | { | |
47cbd6da VZ |
3700 | bool isVirtual; |
3701 | int id = wxCharCodeWXToMSW((int)event.KeyCode(), &isVirtual); | |
c085e333 | 3702 | |
47cbd6da VZ |
3703 | if ( id == -1 ) |
3704 | id= m_lastWParam; | |
c085e333 | 3705 | |
dbda9e86 | 3706 | if ( !event.ControlDown() ) // Why this test? |
47cbd6da | 3707 | (void) MSWDefWindowProc(m_lastMsg, (WPARAM) id, m_lastLParam); |
2bda0e17 KB |
3708 | } |
3709 | ||
dbdb39b2 JS |
3710 | void wxWindow::OnKeyDown(wxKeyEvent& event) |
3711 | { | |
3712 | Default(); | |
3713 | } | |
3714 | ||
3715 | void wxWindow::OnKeyUp(wxKeyEvent& event) | |
3716 | { | |
3717 | Default(); | |
3718 | } | |
3719 | ||
3720 | void wxWindow::OnPaint(wxPaintEvent& event) | |
3721 | { | |
3722 | Default(); | |
3723 | } | |
3724 | ||
2bda0e17 KB |
3725 | bool wxWindow::IsEnabled(void) const |
3726 | { | |
564b2609 | 3727 | return (::IsWindowEnabled((HWND) GetHWND()) != 0); |
2bda0e17 KB |
3728 | } |
3729 | ||
3730 | // Dialog support: override these and call | |
3731 | // base class members to add functionality | |
3732 | // that can't be done using validators. | |
3733 | // NOTE: these functions assume that controls | |
3734 | // are direct children of this window, not grandchildren | |
3735 | // or other levels of descendant. | |
3736 | ||
3737 | // Transfer values to controls. If returns FALSE, | |
3738 | // it's an application error (pops up a dialog) | |
fd3f686c | 3739 | bool wxWindow::TransferDataToWindow() |
2bda0e17 | 3740 | { |
c0ed460c | 3741 | wxNode *node = GetChildren().First(); |
564b2609 VZ |
3742 | while ( node ) |
3743 | { | |
3744 | wxWindow *child = (wxWindow *)node->Data(); | |
3745 | if ( child->GetValidator() && /* child->GetValidator()->Ok() && */ | |
2d0a075d | 3746 | !child->GetValidator()->TransferToWindow() ) |
564b2609 | 3747 | { |
341c92a8 | 3748 | wxLogError(_("Could not transfer data to window")); |
564b2609 VZ |
3749 | return FALSE; |
3750 | } | |
c085e333 | 3751 | |
564b2609 VZ |
3752 | node = node->Next(); |
3753 | } | |
3754 | return TRUE; | |
2bda0e17 KB |
3755 | } |
3756 | ||
3757 | // Transfer values from controls. If returns FALSE, | |
3758 | // validation failed: don't quit | |
fd3f686c | 3759 | bool wxWindow::TransferDataFromWindow() |
2bda0e17 | 3760 | { |
c0ed460c | 3761 | wxNode *node = GetChildren().First(); |
564b2609 VZ |
3762 | while ( node ) |
3763 | { | |
3764 | wxWindow *child = (wxWindow *)node->Data(); | |
3765 | if ( child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->TransferFromWindow() ) | |
3766 | { | |
3767 | return FALSE; | |
3768 | } | |
c085e333 | 3769 | |
564b2609 VZ |
3770 | node = node->Next(); |
3771 | } | |
3772 | return TRUE; | |
2bda0e17 KB |
3773 | } |
3774 | ||
fd3f686c | 3775 | bool wxWindow::Validate() |
2bda0e17 | 3776 | { |
c0ed460c | 3777 | wxNode *node = GetChildren().First(); |
564b2609 VZ |
3778 | while ( node ) |
3779 | { | |
3780 | wxWindow *child = (wxWindow *)node->Data(); | |
3781 | if ( child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->Validate(this) ) | |
3782 | { | |
3783 | return FALSE; | |
3784 | } | |
c085e333 | 3785 | |
564b2609 VZ |
3786 | node = node->Next(); |
3787 | } | |
3788 | return TRUE; | |
2bda0e17 KB |
3789 | } |
3790 | ||
3791 | // Get the window with the focus | |
fd3f686c | 3792 | wxWindow *wxWindow::FindFocus() |
2bda0e17 KB |
3793 | { |
3794 | HWND hWnd = ::GetFocus(); | |
3795 | if ( hWnd ) | |
3796 | { | |
3797 | return wxFindWinFromHandle((WXHWND) hWnd); | |
3798 | } | |
3799 | return NULL; | |
3800 | } | |
3801 | ||
3802 | void wxWindow::AddChild(wxWindow *child) | |
3803 | { | |
c0ed460c | 3804 | GetChildren().Append(child); |
2d0a075d | 3805 | child->m_windowParent = this; |
2bda0e17 KB |
3806 | } |
3807 | ||
3808 | void wxWindow::RemoveChild(wxWindow *child) | |
3809 | { | |
c0ed460c JS |
3810 | // if (GetChildren()) |
3811 | GetChildren().DeleteObject(child); | |
2d0a075d | 3812 | child->m_windowParent = NULL; |
2bda0e17 KB |
3813 | } |
3814 | ||
fd3f686c | 3815 | void wxWindow::DestroyChildren() |
2bda0e17 | 3816 | { |
2d0a075d | 3817 | wxNode *node; |
c0ed460c | 3818 | while ((node = GetChildren().First()) != (wxNode *)NULL) { |
2d0a075d JS |
3819 | wxWindow *child; |
3820 | if ((child = (wxWindow *)node->Data()) != (wxWindow *)NULL) { | |
3821 | delete child; | |
c0ed460c | 3822 | if ( GetChildren().Member(child) ) |
2d0a075d JS |
3823 | delete node; |
3824 | } | |
3825 | } /* while */ | |
2bda0e17 KB |
3826 | } |
3827 | ||
debe6624 | 3828 | void wxWindow::MakeModal(bool modal) |
2bda0e17 | 3829 | { |
2d0a075d JS |
3830 | // Disable all other windows |
3831 | if (this->IsKindOf(CLASSINFO(wxDialog)) || this->IsKindOf(CLASSINFO(wxFrame))) | |
2bda0e17 | 3832 | { |
2d0a075d JS |
3833 | wxNode *node = wxTopLevelWindows.First(); |
3834 | while (node) | |
3835 | { | |
3836 | wxWindow *win = (wxWindow *)node->Data(); | |
3837 | if (win != this) | |
3838 | win->Enable(!modal); | |
2bda0e17 | 3839 | |
2d0a075d JS |
3840 | node = node->Next(); |
3841 | } | |
2bda0e17 | 3842 | } |
2bda0e17 KB |
3843 | } |
3844 | ||
3845 | // If nothing defined for this, try the parent. | |
3846 | // E.g. we may be a button loaded from a resource, with no callback function | |
3847 | // defined. | |
3848 | void wxWindow::OnCommand(wxWindow& win, wxCommandEvent& event) | |
3849 | { | |
2d0a075d JS |
3850 | if (GetEventHandler()->ProcessEvent(event) ) |
3851 | return; | |
3852 | if (m_windowParent) | |
3853 | m_windowParent->GetEventHandler()->OnCommand(win, event); | |
2bda0e17 KB |
3854 | } |
3855 | ||
3856 | void wxWindow::SetConstraints(wxLayoutConstraints *c) | |
3857 | { | |
2d0a075d JS |
3858 | if (m_constraints) |
3859 | { | |
3860 | UnsetConstraints(m_constraints); | |
3861 | delete m_constraints; | |
3862 | } | |
3863 | m_constraints = c; | |
3864 | if (m_constraints) | |
3865 | { | |
3866 | // Make sure other windows know they're part of a 'meaningful relationship' | |
3867 | if (m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this)) | |
3868 | m_constraints->left.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
3869 | if (m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this)) | |
3870 | m_constraints->top.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
3871 | if (m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this)) | |
3872 | m_constraints->right.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
3873 | if (m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this)) | |
3874 | m_constraints->bottom.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
3875 | if (m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this)) | |
3876 | m_constraints->width.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
3877 | if (m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this)) | |
3878 | m_constraints->height.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
3879 | if (m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this)) | |
3880 | m_constraints->centreX.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
3881 | if (m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this)) | |
3882 | m_constraints->centreY.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
3883 | } | |
2bda0e17 KB |
3884 | } |
3885 | ||
3886 | // This removes any dangling pointers to this window | |
3887 | // in other windows' constraintsInvolvedIn lists. | |
3888 | void wxWindow::UnsetConstraints(wxLayoutConstraints *c) | |
3889 | { | |
2d0a075d JS |
3890 | if (c) |
3891 | { | |
3892 | if (c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this)) | |
3893 | c->left.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
3894 | if (c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this)) | |
3895 | c->top.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
3896 | if (c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this)) | |
3897 | c->right.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
3898 | if (c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this)) | |
3899 | c->bottom.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
3900 | if (c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this)) | |
3901 | c->width.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
3902 | if (c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this)) | |
3903 | c->height.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
3904 | if (c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this)) | |
3905 | c->centreX.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
3906 | if (c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this)) | |
3907 | c->centreY.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
3908 | } | |
2bda0e17 KB |
3909 | } |
3910 | ||
3911 | // Back-pointer to other windows we're involved with, so if we delete | |
3912 | // this window, we must delete any constraints we're involved with. | |
3913 | void wxWindow::AddConstraintReference(wxWindow *otherWin) | |
3914 | { | |
2d0a075d JS |
3915 | if (!m_constraintsInvolvedIn) |
3916 | m_constraintsInvolvedIn = new wxList; | |
3917 | if (!m_constraintsInvolvedIn->Member(otherWin)) | |
3918 | m_constraintsInvolvedIn->Append(otherWin); | |
2bda0e17 KB |
3919 | } |
3920 | ||
3921 | // REMOVE back-pointer to other windows we're involved with. | |
3922 | void wxWindow::RemoveConstraintReference(wxWindow *otherWin) | |
3923 | { | |
2d0a075d JS |
3924 | if (m_constraintsInvolvedIn) |
3925 | m_constraintsInvolvedIn->DeleteObject(otherWin); | |
2bda0e17 KB |
3926 | } |
3927 | ||
3928 | // Reset any constraints that mention this window | |
fd3f686c | 3929 | void wxWindow::DeleteRelatedConstraints() |
2bda0e17 | 3930 | { |
2d0a075d | 3931 | if (m_constraintsInvolvedIn) |
2bda0e17 | 3932 | { |
2d0a075d JS |
3933 | wxNode *node = m_constraintsInvolvedIn->First(); |
3934 | while (node) | |
3935 | { | |
3936 | wxWindow *win = (wxWindow *)node->Data(); | |
3937 | wxNode *next = node->Next(); | |
3938 | wxLayoutConstraints *constr = win->GetConstraints(); | |
3939 | ||
3940 | // Reset any constraints involving this window | |
3941 | if (constr) | |
3942 | { | |
3943 | constr->left.ResetIfWin((wxWindow *)this); | |
3944 | constr->top.ResetIfWin((wxWindow *)this); | |
3945 | constr->right.ResetIfWin((wxWindow *)this); | |
3946 | constr->bottom.ResetIfWin((wxWindow *)this); | |
3947 | constr->width.ResetIfWin((wxWindow *)this); | |
3948 | constr->height.ResetIfWin((wxWindow *)this); | |
3949 | constr->centreX.ResetIfWin((wxWindow *)this); | |
3950 | constr->centreY.ResetIfWin((wxWindow *)this); | |
3951 | } | |
3952 | delete node; | |
3953 | node = next; | |
3954 | } | |
3955 | delete m_constraintsInvolvedIn; | |
3956 | m_constraintsInvolvedIn = NULL; | |
2bda0e17 | 3957 | } |
2bda0e17 KB |
3958 | } |
3959 | ||
3960 | void wxWindow::SetSizer(wxSizer *sizer) | |
3961 | { | |
2d0a075d JS |
3962 | m_windowSizer = sizer; |
3963 | if (sizer) | |
3964 | sizer->SetSizerParent((wxWindow *)this); | |
2bda0e17 KB |
3965 | } |
3966 | ||
3967 | /* | |
2d0a075d JS |
3968 | * New version |
3969 | */ | |
2bda0e17 | 3970 | |
fd3f686c | 3971 | bool wxWindow::Layout() |
2bda0e17 | 3972 | { |
2d0a075d JS |
3973 | if (GetConstraints()) |
3974 | { | |
3975 | int w, h; | |
3976 | GetClientSize(&w, &h); | |
3977 | GetConstraints()->width.SetValue(w); | |
3978 | GetConstraints()->height.SetValue(h); | |
3979 | } | |
3980 | ||
3981 | // If top level (one sizer), evaluate the sizer's constraints. | |
3982 | if (GetSizer()) | |
3983 | { | |
3984 | int noChanges; | |
3985 | GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated | |
3986 | GetSizer()->LayoutPhase1(&noChanges); | |
3987 | GetSizer()->LayoutPhase2(&noChanges); | |
3988 | GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes | |
3989 | return TRUE; | |
3990 | } | |
3991 | else | |
3992 | { | |
3993 | // Otherwise, evaluate child constraints | |
3994 | ResetConstraints(); // Mark all constraints as unevaluated | |
3995 | DoPhase(1); // Just one phase need if no sizers involved | |
3996 | DoPhase(2); | |
3997 | SetConstraintSizes(); // Recursively set the real window sizes | |
3998 | } | |
2bda0e17 | 3999 | return TRUE; |
2bda0e17 KB |
4000 | } |
4001 | ||
4002 | ||
4003 | // Do a phase of evaluating constraints: | |
4004 | // the default behaviour. wxSizers may do a similar | |
4005 | // thing, but also impose their own 'constraints' | |
4006 | // and order the evaluation differently. | |
4007 | bool wxWindow::LayoutPhase1(int *noChanges) | |
4008 | { | |
2d0a075d JS |
4009 | wxLayoutConstraints *constr = GetConstraints(); |
4010 | if (constr) | |
4011 | { | |
4012 | return constr->SatisfyConstraints((wxWindow *)this, noChanges); | |
4013 | } | |
4014 | else | |
4015 | return TRUE; | |
2bda0e17 KB |
4016 | } |
4017 | ||
4018 | bool wxWindow::LayoutPhase2(int *noChanges) | |
4019 | { | |
2d0a075d JS |
4020 | *noChanges = 0; |
4021 | ||
4022 | // Layout children | |
4023 | DoPhase(1); | |
4024 | DoPhase(2); | |
4025 | return TRUE; | |
2bda0e17 KB |
4026 | } |
4027 | ||
4028 | // Do a phase of evaluating child constraints | |
debe6624 | 4029 | bool wxWindow::DoPhase(int phase) |
2bda0e17 | 4030 | { |
2d0a075d JS |
4031 | int noIterations = 0; |
4032 | int maxIterations = 500; | |
4033 | int noChanges = 1; | |
4034 | int noFailures = 0; | |
4035 | wxList succeeded; | |
4036 | while ((noChanges > 0) && (noIterations < maxIterations)) | |
2bda0e17 | 4037 | { |
2d0a075d JS |
4038 | noChanges = 0; |
4039 | noFailures = 0; | |
c0ed460c | 4040 | wxNode *node = GetChildren().First(); |
2d0a075d | 4041 | while (node) |
2bda0e17 | 4042 | { |
2d0a075d JS |
4043 | wxWindow *child = (wxWindow *)node->Data(); |
4044 | if (!child->IsKindOf(CLASSINFO(wxFrame)) && !child->IsKindOf(CLASSINFO(wxDialog))) | |
2bda0e17 | 4045 | { |
2d0a075d JS |
4046 | wxLayoutConstraints *constr = child->GetConstraints(); |
4047 | if (constr) | |
4048 | { | |
4049 | if (succeeded.Member(child)) | |
4050 | { | |
4051 | } | |
4052 | else | |
4053 | { | |
4054 | int tempNoChanges = 0; | |
4055 | bool success = ( (phase == 1) ? child->LayoutPhase1(&tempNoChanges) : child->LayoutPhase2(&tempNoChanges) ) ; | |
4056 | noChanges += tempNoChanges; | |
4057 | if (success) | |
4058 | { | |
4059 | succeeded.Append(child); | |
4060 | } | |
4061 | } | |
4062 | } | |
2bda0e17 | 4063 | } |
2d0a075d | 4064 | node = node->Next(); |
2bda0e17 | 4065 | } |
2d0a075d | 4066 | noIterations ++; |
2bda0e17 | 4067 | } |
2d0a075d | 4068 | return TRUE; |
2bda0e17 KB |
4069 | } |
4070 | ||
fd3f686c | 4071 | void wxWindow::ResetConstraints() |
2bda0e17 | 4072 | { |
2d0a075d JS |
4073 | wxLayoutConstraints *constr = GetConstraints(); |
4074 | if (constr) | |
4075 | { | |
4076 | constr->left.SetDone(FALSE); | |
4077 | constr->top.SetDone(FALSE); | |
4078 | constr->right.SetDone(FALSE); | |
4079 | constr->bottom.SetDone(FALSE); | |
4080 | constr->width.SetDone(FALSE); | |
4081 | constr->height.SetDone(FALSE); | |
4082 | constr->centreX.SetDone(FALSE); | |
4083 | constr->centreY.SetDone(FALSE); | |
4084 | } | |
c0ed460c | 4085 | wxNode *node = GetChildren().First(); |
2d0a075d JS |
4086 | while (node) |
4087 | { | |
4088 | wxWindow *win = (wxWindow *)node->Data(); | |
4089 | if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog))) | |
4090 | win->ResetConstraints(); | |
4091 | node = node->Next(); | |
4092 | } | |
2bda0e17 KB |
4093 | } |
4094 | ||
4095 | // Need to distinguish between setting the 'fake' size for | |
4096 | // windows and sizers, and setting the real values. | |
debe6624 | 4097 | void wxWindow::SetConstraintSizes(bool recurse) |
2bda0e17 | 4098 | { |
2d0a075d JS |
4099 | wxLayoutConstraints *constr = GetConstraints(); |
4100 | if (constr && constr->left.GetDone() && constr->right.GetDone() && | |
4101 | constr->width.GetDone() && constr->height.GetDone()) | |
2bda0e17 | 4102 | { |
2d0a075d JS |
4103 | int x = constr->left.GetValue(); |
4104 | int y = constr->top.GetValue(); | |
4105 | int w = constr->width.GetValue(); | |
4106 | int h = constr->height.GetValue(); | |
4107 | ||
4108 | // If we don't want to resize this window, just move it... | |
4109 | if ((constr->width.GetRelationship() != wxAsIs) || | |
4110 | (constr->height.GetRelationship() != wxAsIs)) | |
4111 | { | |
4112 | // Calls Layout() recursively. AAAGH. How can we stop that. | |
4113 | // Simply take Layout() out of non-top level OnSizes. | |
4114 | SizerSetSize(x, y, w, h); | |
4115 | } | |
4116 | else | |
4117 | { | |
4118 | SizerMove(x, y); | |
4119 | } | |
2bda0e17 | 4120 | } |
2d0a075d | 4121 | else if (constr) |
2bda0e17 | 4122 | { |
2d0a075d | 4123 | char *windowClass = this->GetClassInfo()->GetClassName(); |
2bda0e17 | 4124 | |
2d0a075d JS |
4125 | wxString winName; |
4126 | if (GetName() == "") | |
4127 | winName = "unnamed"; | |
4128 | else | |
4129 | winName = GetName(); | |
341c92a8 VZ |
4130 | wxLogDebug("Constraint(s) not satisfied for window of type %s, name %s:", |
4131 | (const char *)windowClass, (const char *)winName); | |
2d0a075d | 4132 | if (!constr->left.GetDone()) |
341c92a8 | 4133 | wxLogDebug(" unsatisfied 'left' constraint."); |
2d0a075d | 4134 | if (!constr->right.GetDone()) |
341c92a8 | 4135 | wxLogDebug(" unsatisfied 'right' constraint."); |
2d0a075d | 4136 | if (!constr->width.GetDone()) |
341c92a8 | 4137 | wxLogDebug(" unsatisfied 'width' constraint."); |
2d0a075d | 4138 | if (!constr->height.GetDone()) |
341c92a8 VZ |
4139 | wxLogDebug(" unsatisfied 'height' constraint."); |
4140 | wxLogDebug("Please check constraints: try adding AsIs() constraints.\n"); | |
2d0a075d | 4141 | } |
2bda0e17 | 4142 | |
2d0a075d | 4143 | if (recurse) |
2bda0e17 | 4144 | { |
c0ed460c | 4145 | wxNode *node = GetChildren().First(); |
2d0a075d JS |
4146 | while (node) |
4147 | { | |
4148 | wxWindow *win = (wxWindow *)node->Data(); | |
4149 | if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog))) | |
4150 | win->SetConstraintSizes(); | |
4151 | node = node->Next(); | |
4152 | } | |
2bda0e17 | 4153 | } |
2bda0e17 KB |
4154 | } |
4155 | ||
4156 | // This assumes that all sizers are 'on' the same | |
4157 | // window, i.e. the parent of this window. | |
4158 | void wxWindow::TransformSizerToActual(int *x, int *y) const | |
4159 | { | |
2d0a075d JS |
4160 | if (!m_sizerParent || m_sizerParent->IsKindOf(CLASSINFO(wxDialog)) || |
4161 | m_sizerParent->IsKindOf(CLASSINFO(wxFrame)) ) | |
4162 | return; | |
4163 | ||
4164 | int xp, yp; | |
4165 | m_sizerParent->GetPosition(&xp, &yp); | |
4166 | m_sizerParent->TransformSizerToActual(&xp, &yp); | |
4167 | *x += xp; | |
4168 | *y += yp; | |
2bda0e17 KB |
4169 | } |
4170 | ||
debe6624 | 4171 | void wxWindow::SizerSetSize(int x, int y, int w, int h) |
2bda0e17 | 4172 | { |
564b2609 VZ |
4173 | int xx = x; |
4174 | int yy = y; | |
2d0a075d JS |
4175 | TransformSizerToActual(&xx, &yy); |
4176 | SetSize(xx, yy, w, h); | |
2bda0e17 KB |
4177 | } |
4178 | ||
debe6624 | 4179 | void wxWindow::SizerMove(int x, int y) |
2bda0e17 | 4180 | { |
564b2609 VZ |
4181 | int xx = x; |
4182 | int yy = y; | |
2d0a075d JS |
4183 | TransformSizerToActual(&xx, &yy); |
4184 | Move(xx, yy); | |
2bda0e17 KB |
4185 | } |
4186 | ||
4187 | // Only set the size/position of the constraint (if any) | |
debe6624 | 4188 | void wxWindow::SetSizeConstraint(int x, int y, int w, int h) |
2bda0e17 | 4189 | { |
2d0a075d JS |
4190 | wxLayoutConstraints *constr = GetConstraints(); |
4191 | if (constr) | |
2bda0e17 | 4192 | { |
2d0a075d JS |
4193 | if (x != -1) |
4194 | { | |
4195 | constr->left.SetValue(x); | |
4196 | constr->left.SetDone(TRUE); | |
4197 | } | |
4198 | if (y != -1) | |
4199 | { | |
4200 | constr->top.SetValue(y); | |
4201 | constr->top.SetDone(TRUE); | |
4202 | } | |
4203 | if (w != -1) | |
4204 | { | |
4205 | constr->width.SetValue(w); | |
4206 | constr->width.SetDone(TRUE); | |
4207 | } | |
4208 | if (h != -1) | |
4209 | { | |
4210 | constr->height.SetValue(h); | |
4211 | constr->height.SetDone(TRUE); | |
4212 | } | |
2bda0e17 | 4213 | } |
2bda0e17 KB |
4214 | } |
4215 | ||
debe6624 | 4216 | void wxWindow::MoveConstraint(int x, int y) |
2bda0e17 | 4217 | { |
2d0a075d JS |
4218 | wxLayoutConstraints *constr = GetConstraints(); |
4219 | if (constr) | |
2bda0e17 | 4220 | { |
2d0a075d JS |
4221 | if (x != -1) |
4222 | { | |
4223 | constr->left.SetValue(x); | |
4224 | constr->left.SetDone(TRUE); | |
4225 | } | |
4226 | if (y != -1) | |
4227 | { | |
4228 | constr->top.SetValue(y); | |
4229 | constr->top.SetDone(TRUE); | |
4230 | } | |
2bda0e17 | 4231 | } |
2bda0e17 KB |
4232 | } |
4233 | ||
4234 | void wxWindow::GetSizeConstraint(int *w, int *h) const | |
4235 | { | |
2d0a075d JS |
4236 | wxLayoutConstraints *constr = GetConstraints(); |
4237 | if (constr) | |
4238 | { | |
4239 | *w = constr->width.GetValue(); | |
4240 | *h = constr->height.GetValue(); | |
4241 | } | |
4242 | else | |
4243 | GetSize(w, h); | |
2bda0e17 KB |
4244 | } |
4245 | ||
4246 | void wxWindow::GetClientSizeConstraint(int *w, int *h) const | |
4247 | { | |
2d0a075d JS |
4248 | wxLayoutConstraints *constr = GetConstraints(); |
4249 | if (constr) | |
4250 | { | |
4251 | *w = constr->width.GetValue(); | |
4252 | *h = constr->height.GetValue(); | |
4253 | } | |
4254 | else | |
4255 | GetClientSize(w, h); | |
2bda0e17 KB |
4256 | } |
4257 | ||
4258 | void wxWindow::GetPositionConstraint(int *x, int *y) const | |
4259 | { | |
2d0a075d JS |
4260 | wxLayoutConstraints *constr = GetConstraints(); |
4261 | if (constr) | |
4262 | { | |
4263 | *x = constr->left.GetValue(); | |
4264 | *y = constr->top.GetValue(); | |
4265 | } | |
4266 | else | |
4267 | GetPosition(x, y); | |
2bda0e17 KB |
4268 | } |
4269 | ||
debe6624 | 4270 | bool wxWindow::Close(bool force) |
2bda0e17 | 4271 | { |
2d0a075d JS |
4272 | wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId); |
4273 | event.SetEventObject(this); | |
e3065973 | 4274 | #if WXWIN_COMPATIBILITY |
2d0a075d | 4275 | event.SetForce(force); |
e3065973 | 4276 | #endif |
2d0a075d | 4277 | event.SetCanVeto(!force); |
2bda0e17 | 4278 | |
2d0a075d | 4279 | return (GetEventHandler()->ProcessEvent(event) && !event.GetVeto()); |
2bda0e17 KB |
4280 | } |
4281 | ||
debe6624 | 4282 | wxObject* wxWindow::GetChild(int number) const |
2bda0e17 | 4283 | { |
2d0a075d | 4284 | // Return a pointer to the Nth object in the Panel |
c0ed460c JS |
4285 | // if (!GetChildren()) |
4286 | // return(NULL) ; | |
4287 | wxNode *node = GetChildren().First(); | |
2d0a075d JS |
4288 | int n = number; |
4289 | while (node && n--) | |
4290 | node = node->Next() ; | |
4291 | if (node) | |
4292 | { | |
4293 | wxObject *obj = (wxObject *)node->Data(); | |
4294 | return(obj) ; | |
4295 | } | |
4296 | else | |
4297 | return NULL ; | |
2bda0e17 KB |
4298 | } |
4299 | ||
4300 | void wxWindow::OnDefaultAction(wxControl *initiatingItem) | |
4301 | { | |
debe6624 | 4302 | /* This is obsolete now; if we wish to intercept listbox double-clicks, |
2d0a075d JS |
4303 | * we explicitly intercept the wxEVT_COMMAND_LISTBOX_DOUBLECLICKED |
4304 | * event. | |
debe6624 JS |
4305 | |
4306 | if (initiatingItem->IsKindOf(CLASSINFO(wxListBox))) | |
2bda0e17 | 4307 | { |
2d0a075d JS |
4308 | wxListBox *lbox = (wxListBox *)initiatingItem; |
4309 | wxCommandEvent event(wxEVT_COMMAND_LEFT_DCLICK); | |
4310 | event.m_commandInt = -1; | |
4311 | if ((lbox->GetWindowStyleFlag() & wxLB_MULTIPLE) == 0) | |
2bda0e17 | 4312 | { |
2d0a075d JS |
4313 | event.m_commandString = copystring(lbox->GetStringSelection()); |
4314 | event.m_commandInt = lbox->GetSelection(); | |
4315 | event.m_clientData = lbox->wxListBox::GetClientData(event.m_commandInt); | |
2bda0e17 | 4316 | } |
2d0a075d | 4317 | event.m_eventObject = lbox; |
c085e333 | 4318 | |
2d0a075d | 4319 | lbox->ProcessCommand(event); |
c085e333 | 4320 | |
2d0a075d JS |
4321 | if (event.m_commandString) |
4322 | delete[] event.m_commandString; | |
4323 | return; | |
4324 | } | |
4325 | ||
4326 | wxButton *but = GetDefaultItem(); | |
4327 | if (but) | |
4328 | { | |
4329 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED); | |
4330 | event.SetEventObject(but); | |
4331 | but->Command(event); | |
4332 | } | |
4333 | */ | |
2bda0e17 KB |
4334 | } |
4335 | ||
fd3f686c | 4336 | void wxWindow::Clear() |
2bda0e17 | 4337 | { |
564b2609 | 4338 | wxClientDC dc(this); |
2bda0e17 KB |
4339 | wxBrush brush(GetBackgroundColour(), wxSOLID); |
4340 | dc.SetBackground(brush); | |
4341 | dc.Clear(); | |
4342 | } | |
4343 | ||
4344 | // Fits the panel around the items | |
fd3f686c | 4345 | void wxWindow::Fit() |
2bda0e17 | 4346 | { |
564b2609 VZ |
4347 | int maxX = 0; |
4348 | int maxY = 0; | |
c0ed460c | 4349 | wxNode *node = GetChildren().First(); |
564b2609 VZ |
4350 | while ( node ) |
4351 | { | |
4352 | wxWindow *win = (wxWindow *)node->Data(); | |
4353 | int wx, wy, ww, wh; | |
4354 | win->GetPosition(&wx, &wy); | |
4355 | win->GetSize(&ww, &wh); | |
4356 | if ( wx + ww > maxX ) | |
4357 | maxX = wx + ww; | |
4358 | if ( wy + wh > maxY ) | |
4359 | maxY = wy + wh; | |
c085e333 | 4360 | |
564b2609 VZ |
4361 | node = node->Next(); |
4362 | } | |
4363 | SetClientSize(maxX + 5, maxY + 5); | |
2bda0e17 KB |
4364 | } |
4365 | ||
4366 | void wxWindow::SetValidator(const wxValidator& validator) | |
4367 | { | |
564b2609 VZ |
4368 | if ( m_windowValidator ) |
4369 | delete m_windowValidator; | |
4370 | m_windowValidator = validator.Clone(); | |
c085e333 | 4371 | |
564b2609 VZ |
4372 | if ( m_windowValidator ) |
4373 | m_windowValidator->SetWindow(this) ; | |
2bda0e17 KB |
4374 | } |
4375 | ||
4376 | // Find a window by id or name | |
debe6624 | 4377 | wxWindow *wxWindow::FindWindow(long id) |
2bda0e17 | 4378 | { |
564b2609 VZ |
4379 | if ( GetId() == id) |
4380 | return this; | |
c085e333 | 4381 | |
c0ed460c | 4382 | wxNode *node = GetChildren().First(); |
564b2609 VZ |
4383 | while ( node ) |
4384 | { | |
4385 | wxWindow *child = (wxWindow *)node->Data(); | |
4386 | wxWindow *found = child->FindWindow(id); | |
4387 | if ( found ) | |
4388 | return found; | |
4389 | node = node->Next(); | |
4390 | } | |
4391 | return NULL; | |
2bda0e17 KB |
4392 | } |
4393 | ||
4394 | wxWindow *wxWindow::FindWindow(const wxString& name) | |
4395 | { | |
564b2609 VZ |
4396 | if ( GetName() == name) |
4397 | return this; | |
c085e333 | 4398 | |
c0ed460c | 4399 | wxNode *node = GetChildren().First(); |
564b2609 VZ |
4400 | while ( node ) |
4401 | { | |
4402 | wxWindow *child = (wxWindow *)node->Data(); | |
4403 | wxWindow *found = child->FindWindow(name); | |
4404 | if ( found ) | |
4405 | return found; | |
4406 | node = node->Next(); | |
4407 | } | |
4408 | return NULL; | |
2bda0e17 KB |
4409 | } |
4410 | ||
4411 | /* TODO | |
4412 | // Default input behaviour for a scrolling canvas should be to scroll | |
4413 | // according to the cursor keys pressed | |
4414 | void wxWindow::OnChar(wxKeyEvent& event) | |
4415 | { | |
2d0a075d JS |
4416 | int x_page = 0; |
4417 | int y_page = 0; | |
4418 | int start_x = 0; | |
4419 | int start_y = 0; | |
4420 | // Bugfix Begin | |
4421 | int v_width = 0; | |
4422 | int v_height = 0; | |
4423 | int y_pages = 0; | |
4424 | // Bugfix End | |
2bda0e17 KB |
4425 | |
4426 | GetScrollUnitsPerPage(&x_page, &y_page); | |
4427 | // Bugfix Begin | |
4428 | GetVirtualSize(&v_width,&v_height); | |
4429 | // Bugfix End | |
4430 | ViewStart(&start_x, &start_y); | |
4431 | // Bugfix begin | |
4432 | if (vert_units) | |
2d0a075d | 4433 | y_pages = (int)(v_height/vert_units) - y_page; |
c085e333 | 4434 | |
2d0a075d JS |
4435 | #ifdef __WXMSW__ |
4436 | int y = 0; | |
4437 | #else | |
4438 | int y = y_page-1; | |
4439 | #endif | |
4440 | // Bugfix End | |
4441 | switch (event.keyCode) | |
4442 | { | |
4443 | case WXK_PRIOR: | |
4444 | { | |
4445 | // BugFix Begin | |
4446 | if (y_page > 0) | |
4447 | { | |
4448 | if (start_y - y_page > 0) | |
4449 | Scroll(start_x, start_y - y_page); | |
4450 | else | |
4451 | Scroll(start_x, 0); | |
4452 | } | |
4453 | // Bugfix End | |
4454 | break; | |
4455 | } | |
4456 | case WXK_NEXT: | |
4457 | { | |
4458 | // Bugfix Begin | |
4459 | if ((y_page > 0) && (start_y <= y_pages-y-1)) | |
4460 | { | |
4461 | if (y_pages + y < start_y + y_page) | |
4462 | Scroll(start_x, y_pages + y); | |
4463 | else | |
4464 | Scroll(start_x, start_y + y_page); | |
4465 | } | |
4466 | // Bugfix End | |
4467 | break; | |
4468 | } | |
4469 | case WXK_UP: | |
4470 | { | |
4471 | if ((y_page > 0) && (start_y >= 1)) | |
4472 | Scroll(start_x, start_y - 1); | |
4473 | break; | |
4474 | } | |
4475 | case WXK_DOWN: | |
4476 | { | |
4477 | // Bugfix Begin | |
4478 | if ((y_page > 0) && (start_y <= y_pages-y-1)) | |
4479 | // Bugfix End | |
4480 | { | |
4481 | Scroll(start_x, start_y + 1); | |
4482 | } | |
4483 | break; | |
4484 | } | |
4485 | case WXK_LEFT: | |
4486 | { | |
4487 | if ((x_page > 0) && (start_x >= 1)) | |
4488 | Scroll(start_x - 1, start_y); | |
4489 | break; | |
4490 | } | |
4491 | case WXK_RIGHT: | |
4492 | { | |
4493 | if (x_page > 0) | |
4494 | Scroll(start_x + 1, start_y); | |
4495 | break; | |
4496 | } | |
4497 | case WXK_HOME: | |
4498 | { | |
4499 | Scroll(0, 0); | |
4500 | break; | |
4501 | } | |
4502 | // This is new | |
4503 | case WXK_END: | |
4504 | { | |
4505 | Scroll(start_x, y_pages+y); | |
4506 | break; | |
4507 | } | |
4508 | // end | |
4509 | } | |
4510 | } | |
2bda0e17 KB |
4511 | */ |
4512 | ||
4513 | // Setup background and foreground colours correctly | |
fd3f686c | 4514 | void wxWindow::SetupColours() |
2bda0e17 | 4515 | { |
564b2609 VZ |
4516 | if (GetParent()) |
4517 | SetBackgroundColour(GetParent()->GetBackgroundColour()); | |
2bda0e17 KB |
4518 | } |
4519 | ||
2bda0e17 KB |
4520 | void wxWindow::OnIdle(wxIdleEvent& event) |
4521 | { | |
43d811ea JS |
4522 | // Check if we need to send a LEAVE event |
4523 | if (m_mouseInWindow) | |
4524 | { | |
4525 | POINT pt; | |
4526 | ::GetCursorPos(&pt); | |
4527 | if (::WindowFromPoint(pt) != (HWND) GetHWND()) | |
4528 | { | |
4529 | // Generate a LEAVE event | |
4530 | m_mouseInWindow = FALSE; | |
c085e333 | 4531 | |
2d524929 | 4532 | int state = 0; |
567da5c6 JS |
4533 | if (::GetKeyState(VK_SHIFT) != 0) |
4534 | state |= MK_SHIFT; | |
4535 | if (::GetKeyState(VK_CONTROL) != 0) | |
4536 | state |= MK_CONTROL; | |
c085e333 | 4537 | |
567da5c6 JS |
4538 | // Unfortunately the mouse button and keyboard state may have changed |
4539 | // by the time the OnIdle function is called, so 'state' may be | |
4540 | // meaningless. | |
c085e333 | 4541 | |
567da5c6 | 4542 | MSWOnMouseLeave(pt.x, pt.y, state); |
43d811ea JS |
4543 | } |
4544 | } | |
564b2609 | 4545 | UpdateWindowUI(); |
2bda0e17 KB |
4546 | } |
4547 | ||
4548 | // Raise the window to the top of the Z order | |
fd3f686c | 4549 | void wxWindow::Raise() |
2bda0e17 KB |
4550 | { |
4551 | ::BringWindowToTop((HWND) GetHWND()); | |
4552 | } | |
4553 | ||
4554 | // Lower the window to the bottom of the Z order | |
fd3f686c | 4555 | void wxWindow::Lower() |
2bda0e17 KB |
4556 | { |
4557 | ::SetWindowPos((HWND) GetHWND(), HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE); | |
4558 | } | |
4559 | ||
47cbd6da VZ |
4560 | long wxWindow::MSWGetDlgCode() |
4561 | { | |
2d0a075d JS |
4562 | // default: just forward to def window proc (the msg has no parameters) |
4563 | return MSWDefWindowProc(WM_GETDLGCODE, 0, 0); | |
47cbd6da VZ |
4564 | } |
4565 | ||
4566 | bool wxWindow::AcceptsFocus() const | |
4567 | { | |
3a19e16d | 4568 | // invisible and disabled controls don't need focus |
2d0a075d | 4569 | return IsShown() && IsEnabled(); |
47cbd6da VZ |
4570 | } |
4571 | ||
81d66cf3 JS |
4572 | // Update region access |
4573 | wxRegion wxWindow::GetUpdateRegion() const | |
4574 | { | |
4575 | return m_updateRegion; | |
4576 | } | |
4577 | ||
4578 | bool wxWindow::IsExposed(int x, int y, int w, int h) const | |
4579 | { | |
4580 | return (m_updateRegion.Contains(x, y, w, h) != wxOutRegion); | |
4581 | } | |
4582 | ||
4583 | bool wxWindow::IsExposed(const wxPoint& pt) const | |
4584 | { | |
4585 | return (m_updateRegion.Contains(pt) != wxOutRegion); | |
4586 | } | |
4587 | ||
4588 | bool wxWindow::IsExposed(const wxRect& rect) const | |
4589 | { | |
4590 | return (m_updateRegion.Contains(rect) != wxOutRegion); | |
4591 | } | |
4592 | ||
4fabb575 JS |
4593 | // Set this window to be the child of 'parent'. |
4594 | bool wxWindow::Reparent(wxWindow *parent) | |
4595 | { | |
4596 | if (parent == GetParent()) | |
4597 | return TRUE; | |
4598 | ||
4599 | // Unlink this window from the existing parent. | |
4600 | if (GetParent()) | |
4601 | { | |
4602 | GetParent()->RemoveChild(this); | |
4603 | } | |
4604 | else | |
4605 | wxTopLevelWindows.DeleteObject(this); | |
4606 | ||
4607 | HWND hWndParent = 0; | |
4608 | HWND hWndChild = (HWND) GetHWND(); | |
4609 | if (parent != (wxWindow*) NULL) | |
4610 | { | |
4611 | parent->AddChild(this); | |
4612 | hWndParent = (HWND) parent->GetHWND(); | |
4613 | } | |
4614 | else | |
4615 | wxTopLevelWindows.Append(this); | |
4616 | ||
4617 | ::SetParent(hWndChild, hWndParent); | |
4618 | ||
4619 | return TRUE; | |
4620 | } | |
4621 | ||
b2aef89b | 4622 | #ifdef __WXDEBUG__ |
f449ef69 | 4623 | const char *wxGetMessageName(int message) |
47cbd6da | 4624 | { |
2d0a075d | 4625 | switch ( message ) { |
47cbd6da VZ |
4626 | case 0x0000: return "WM_NULL"; |
4627 | case 0x0001: return "WM_CREATE"; | |
4628 | case 0x0002: return "WM_DESTROY"; | |
4629 | case 0x0003: return "WM_MOVE"; | |
4630 | case 0x0005: return "WM_SIZE"; | |
4631 | case 0x0006: return "WM_ACTIVATE"; | |
4632 | case 0x0007: return "WM_SETFOCUS"; | |
4633 | case 0x0008: return "WM_KILLFOCUS"; | |
4634 | case 0x000A: return "WM_ENABLE"; | |
4635 | case 0x000B: return "WM_SETREDRAW"; | |
4636 | case 0x000C: return "WM_SETTEXT"; | |
4637 | case 0x000D: return "WM_GETTEXT"; | |
4638 | case 0x000E: return "WM_GETTEXTLENGTH"; | |
4639 | case 0x000F: return "WM_PAINT"; | |
4640 | case 0x0010: return "WM_CLOSE"; | |
4641 | case 0x0011: return "WM_QUERYENDSESSION"; | |
4642 | case 0x0012: return "WM_QUIT"; | |
4643 | case 0x0013: return "WM_QUERYOPEN"; | |
4644 | case 0x0014: return "WM_ERASEBKGND"; | |
4645 | case 0x0015: return "WM_SYSCOLORCHANGE"; | |
4646 | case 0x0016: return "WM_ENDSESSION"; | |
4647 | case 0x0017: return "WM_SYSTEMERROR"; | |
4648 | case 0x0018: return "WM_SHOWWINDOW"; | |
4649 | case 0x0019: return "WM_CTLCOLOR"; | |
4650 | case 0x001A: return "WM_WININICHANGE"; | |
4651 | case 0x001B: return "WM_DEVMODECHANGE"; | |
4652 | case 0x001C: return "WM_ACTIVATEAPP"; | |
4653 | case 0x001D: return "WM_FONTCHANGE"; | |
4654 | case 0x001E: return "WM_TIMECHANGE"; | |
4655 | case 0x001F: return "WM_CANCELMODE"; | |
4656 | case 0x0020: return "WM_SETCURSOR"; | |
4657 | case 0x0021: return "WM_MOUSEACTIVATE"; | |
4658 | case 0x0022: return "WM_CHILDACTIVATE"; | |
4659 | case 0x0023: return "WM_QUEUESYNC"; | |
4660 | case 0x0024: return "WM_GETMINMAXINFO"; | |
4661 | case 0x0026: return "WM_PAINTICON"; | |
4662 | case 0x0027: return "WM_ICONERASEBKGND"; | |
4663 | case 0x0028: return "WM_NEXTDLGCTL"; | |
4664 | case 0x002A: return "WM_SPOOLERSTATUS"; | |
4665 | case 0x002B: return "WM_DRAWITEM"; | |
4666 | case 0x002C: return "WM_MEASUREITEM"; | |
4667 | case 0x002D: return "WM_DELETEITEM"; | |
4668 | case 0x002E: return "WM_VKEYTOITEM"; | |
4669 | case 0x002F: return "WM_CHARTOITEM"; | |
4670 | case 0x0030: return "WM_SETFONT"; | |
4671 | case 0x0031: return "WM_GETFONT"; | |
4672 | case 0x0037: return "WM_QUERYDRAGICON"; | |
4673 | case 0x0039: return "WM_COMPAREITEM"; | |
4674 | case 0x0041: return "WM_COMPACTING"; | |
4675 | case 0x0044: return "WM_COMMNOTIFY"; | |
4676 | case 0x0046: return "WM_WINDOWPOSCHANGING"; | |
4677 | case 0x0047: return "WM_WINDOWPOSCHANGED"; | |
4678 | case 0x0048: return "WM_POWER"; | |
c085e333 | 4679 | |
a02eb1d2 VZ |
4680 | #ifdef __WIN32__ |
4681 | case 0x004A: return "WM_COPYDATA"; | |
4682 | case 0x004B: return "WM_CANCELJOURNAL"; | |
4683 | case 0x004E: return "WM_NOTIFY"; | |
4684 | case 0x0050: return "WM_INPUTLANGCHANGEREQUEST"; | |
4685 | case 0x0051: return "WM_INPUTLANGCHANGE"; | |
4686 | case 0x0052: return "WM_TCARD"; | |
4687 | case 0x0053: return "WM_HELP"; | |
4688 | case 0x0054: return "WM_USERCHANGED"; | |
4689 | case 0x0055: return "WM_NOTIFYFORMAT"; | |
4690 | case 0x007B: return "WM_CONTEXTMENU"; | |
4691 | case 0x007C: return "WM_STYLECHANGING"; | |
4692 | case 0x007D: return "WM_STYLECHANGED"; | |
4693 | case 0x007E: return "WM_DISPLAYCHANGE"; | |
4694 | case 0x007F: return "WM_GETICON"; | |
4695 | case 0x0080: return "WM_SETICON"; | |
4696 | #endif //WIN32 | |
c085e333 | 4697 | |
47cbd6da VZ |
4698 | case 0x0081: return "WM_NCCREATE"; |
4699 | case 0x0082: return "WM_NCDESTROY"; | |
4700 | case 0x0083: return "WM_NCCALCSIZE"; | |
4701 | case 0x0084: return "WM_NCHITTEST"; | |
4702 | case 0x0085: return "WM_NCPAINT"; | |
4703 | case 0x0086: return "WM_NCACTIVATE"; | |
4704 | case 0x0087: return "WM_GETDLGCODE"; | |
4705 | case 0x00A0: return "WM_NCMOUSEMOVE"; | |
4706 | case 0x00A1: return "WM_NCLBUTTONDOWN"; | |
4707 | case 0x00A2: return "WM_NCLBUTTONUP"; | |
4708 | case 0x00A3: return "WM_NCLBUTTONDBLCLK"; | |
4709 | case 0x00A4: return "WM_NCRBUTTONDOWN"; | |
4710 | case 0x00A5: return "WM_NCRBUTTONUP"; | |
4711 | case 0x00A6: return "WM_NCRBUTTONDBLCLK"; | |
4712 | case 0x00A7: return "WM_NCMBUTTONDOWN"; | |
4713 | case 0x00A8: return "WM_NCMBUTTONUP"; | |
4714 | case 0x00A9: return "WM_NCMBUTTONDBLCLK"; | |
4715 | case 0x0100: return "WM_KEYDOWN"; | |
4716 | case 0x0101: return "WM_KEYUP"; | |
4717 | case 0x0102: return "WM_CHAR"; | |
4718 | case 0x0103: return "WM_DEADCHAR"; | |
4719 | case 0x0104: return "WM_SYSKEYDOWN"; | |
4720 | case 0x0105: return "WM_SYSKEYUP"; | |
4721 | case 0x0106: return "WM_SYSCHAR"; | |
4722 | case 0x0107: return "WM_SYSDEADCHAR"; | |
4723 | case 0x0108: return "WM_KEYLAST"; | |
c085e333 | 4724 | |
a02eb1d2 VZ |
4725 | #ifdef __WIN32__ |
4726 | case 0x010D: return "WM_IME_STARTCOMPOSITION"; | |
4727 | case 0x010E: return "WM_IME_ENDCOMPOSITION"; | |
4728 | case 0x010F: return "WM_IME_COMPOSITION"; | |
4729 | #endif //WIN32 | |
c085e333 | 4730 | |
47cbd6da VZ |
4731 | case 0x0110: return "WM_INITDIALOG"; |
4732 | case 0x0111: return "WM_COMMAND"; | |
4733 | case 0x0112: return "WM_SYSCOMMAND"; | |
4734 | case 0x0113: return "WM_TIMER"; | |
4735 | case 0x0114: return "WM_HSCROLL"; | |
4736 | case 0x0115: return "WM_VSCROLL"; | |
4737 | case 0x0116: return "WM_INITMENU"; | |
4738 | case 0x0117: return "WM_INITMENUPOPUP"; | |
4739 | case 0x011F: return "WM_MENUSELECT"; | |
4740 | case 0x0120: return "WM_MENUCHAR"; | |
4741 | case 0x0121: return "WM_ENTERIDLE"; | |
4742 | case 0x0200: return "WM_MOUSEMOVE"; | |
4743 | case 0x0201: return "WM_LBUTTONDOWN"; | |
4744 | case 0x0202: return "WM_LBUTTONUP"; | |
4745 | case 0x0203: return "WM_LBUTTONDBLCLK"; | |
4746 | case 0x0204: return "WM_RBUTTONDOWN"; | |
4747 | case 0x0205: return "WM_RBUTTONUP"; | |
4748 | case 0x0206: return "WM_RBUTTONDBLCLK"; | |
4749 | case 0x0207: return "WM_MBUTTONDOWN"; | |
4750 | case 0x0208: return "WM_MBUTTONUP"; | |
4751 | case 0x0209: return "WM_MBUTTONDBLCLK"; | |
4752 | case 0x0210: return "WM_PARENTNOTIFY"; | |
a02eb1d2 VZ |
4753 | case 0x0211: return "WM_ENTERMENULOOP"; |
4754 | case 0x0212: return "WM_EXITMENULOOP"; | |
c085e333 | 4755 | |
a02eb1d2 VZ |
4756 | #ifdef __WIN32__ |
4757 | case 0x0213: return "WM_NEXTMENU"; | |
4758 | case 0x0214: return "WM_SIZING"; | |
4759 | case 0x0215: return "WM_CAPTURECHANGED"; | |
4760 | case 0x0216: return "WM_MOVING"; | |
4761 | case 0x0218: return "WM_POWERBROADCAST"; | |
4762 | case 0x0219: return "WM_DEVICECHANGE"; | |
4763 | #endif //WIN32 | |
c085e333 | 4764 | |
47cbd6da VZ |
4765 | case 0x0220: return "WM_MDICREATE"; |
4766 | case 0x0221: return "WM_MDIDESTROY"; | |
4767 | case 0x0222: return "WM_MDIACTIVATE"; | |
4768 | case 0x0223: return "WM_MDIRESTORE"; | |
4769 | case 0x0224: return "WM_MDINEXT"; | |
4770 | case 0x0225: return "WM_MDIMAXIMIZE"; | |
4771 | case 0x0226: return "WM_MDITILE"; | |
4772 | case 0x0227: return "WM_MDICASCADE"; | |
4773 | case 0x0228: return "WM_MDIICONARRANGE"; | |
4774 | case 0x0229: return "WM_MDIGETACTIVE"; | |
4775 | case 0x0230: return "WM_MDISETMENU"; | |
4776 | case 0x0233: return "WM_DROPFILES"; | |
c085e333 | 4777 | |
a02eb1d2 VZ |
4778 | #ifdef __WIN32__ |
4779 | case 0x0281: return "WM_IME_SETCONTEXT"; | |
4780 | case 0x0282: return "WM_IME_NOTIFY"; | |
4781 | case 0x0283: return "WM_IME_CONTROL"; | |
4782 | case 0x0284: return "WM_IME_COMPOSITIONFULL"; | |
4783 | case 0x0285: return "WM_IME_SELECT"; | |
4784 | case 0x0286: return "WM_IME_CHAR"; | |
4785 | case 0x0290: return "WM_IME_KEYDOWN"; | |
4786 | case 0x0291: return "WM_IME_KEYUP"; | |
4787 | #endif //WIN32 | |
c085e333 | 4788 | |
47cbd6da VZ |
4789 | case 0x0300: return "WM_CUT"; |
4790 | case 0x0301: return "WM_COPY"; | |
4791 | case 0x0302: return "WM_PASTE"; | |
4792 | case 0x0303: return "WM_CLEAR"; | |
4793 | case 0x0304: return "WM_UNDO"; | |
4794 | case 0x0305: return "WM_RENDERFORMAT"; | |
4795 | case 0x0306: return "WM_RENDERALLFORMATS"; | |
4796 | case 0x0307: return "WM_DESTROYCLIPBOARD"; | |
4797 | case 0x0308: return "WM_DRAWCLIPBOARD"; | |
4798 | case 0x0309: return "WM_PAINTCLIPBOARD"; | |
4799 | case 0x030A: return "WM_VSCROLLCLIPBOARD"; | |
4800 | case 0x030B: return "WM_SIZECLIPBOARD"; | |
4801 | case 0x030C: return "WM_ASKCBFORMATNAME"; | |
4802 | case 0x030D: return "WM_CHANGECBCHAIN"; | |
4803 | case 0x030E: return "WM_HSCROLLCLIPBOARD"; | |
4804 | case 0x030F: return "WM_QUERYNEWPALETTE"; | |
4805 | case 0x0310: return "WM_PALETTEISCHANGING"; | |
4806 | case 0x0311: return "WM_PALETTECHANGED"; | |
c085e333 | 4807 | |
a02eb1d2 | 4808 | #ifdef __WIN32__ |
2d0a075d JS |
4809 | // common controls messages - although they're not strictly speaking |
4810 | // standard, it's nice to decode them nevertheless | |
a02eb1d2 | 4811 | |
2d0a075d | 4812 | // listview |
a02eb1d2 VZ |
4813 | case 0x1000 + 0: return "LVM_GETBKCOLOR"; |
4814 | case 0x1000 + 1: return "LVM_SETBKCOLOR"; | |
4815 | case 0x1000 + 2: return "LVM_GETIMAGELIST"; | |
4816 | case 0x1000 + 3: return "LVM_SETIMAGELIST"; | |
4817 | case 0x1000 + 4: return "LVM_GETITEMCOUNT"; | |
4818 | case 0x1000 + 5: return "LVM_GETITEMA"; | |
4819 | case 0x1000 + 75: return "LVM_GETITEMW"; | |
4820 | case 0x1000 + 6: return "LVM_SETITEMA"; | |
4821 | case 0x1000 + 76: return "LVM_SETITEMW"; | |
4822 | case 0x1000 + 7: return "LVM_INSERTITEMA"; | |
4823 | case 0x1000 + 77: return "LVM_INSERTITEMW"; | |
4824 | case 0x1000 + 8: return "LVM_DELETEITEM"; | |
4825 | case 0x1000 + 9: return "LVM_DELETEALLITEMS"; | |
4826 | case 0x1000 + 10: return "LVM_GETCALLBACKMASK"; | |
4827 | case 0x1000 + 11: return "LVM_SETCALLBACKMASK"; | |
4828 | case 0x1000 + 12: return "LVM_GETNEXTITEM"; | |
4829 | case 0x1000 + 13: return "LVM_FINDITEMA"; | |
4830 | case 0x1000 + 83: return "LVM_FINDITEMW"; | |
4831 | case 0x1000 + 14: return "LVM_GETITEMRECT"; | |
4832 | case 0x1000 + 15: return "LVM_SETITEMPOSITION"; | |
4833 | case 0x1000 + 16: return "LVM_GETITEMPOSITION"; | |
4834 | case 0x1000 + 17: return "LVM_GETSTRINGWIDTHA"; | |
4835 | case 0x1000 + 87: return "LVM_GETSTRINGWIDTHW"; | |
4836 | case 0x1000 + 18: return "LVM_HITTEST"; | |
4837 | case 0x1000 + 19: return "LVM_ENSUREVISIBLE"; | |
4838 | case 0x1000 + 20: return "LVM_SCROLL"; | |
4839 | case 0x1000 + 21: return "LVM_REDRAWITEMS"; | |
4840 | case 0x1000 + 22: return "LVM_ARRANGE"; | |
4841 | case 0x1000 + 23: return "LVM_EDITLABELA"; | |
4842 | case 0x1000 + 118: return "LVM_EDITLABELW"; | |
4843 | case 0x1000 + 24: return "LVM_GETEDITCONTROL"; | |
4844 | case 0x1000 + 25: return "LVM_GETCOLUMNA"; | |
4845 | case 0x1000 + 95: return "LVM_GETCOLUMNW"; | |
4846 | case 0x1000 + 26: return "LVM_SETCOLUMNA"; | |
4847 | case 0x1000 + 96: return "LVM_SETCOLUMNW"; | |
4848 | case 0x1000 + 27: return "LVM_INSERTCOLUMNA"; | |
4849 | case 0x1000 + 97: return "LVM_INSERTCOLUMNW"; | |
4850 | case 0x1000 + 28: return "LVM_DELETECOLUMN"; | |
4851 | case 0x1000 + 29: return "LVM_GETCOLUMNWIDTH"; | |
4852 | case 0x1000 + 30: return "LVM_SETCOLUMNWIDTH"; | |
4853 | case 0x1000 + 31: return "LVM_GETHEADER"; | |
4854 | case 0x1000 + 33: return "LVM_CREATEDRAGIMAGE"; | |
4855 | case 0x1000 + 34: return "LVM_GETVIEWRECT"; | |
4856 | case 0x1000 + 35: return "LVM_GETTEXTCOLOR"; | |
4857 | case 0x1000 + 36: return "LVM_SETTEXTCOLOR"; | |
4858 | case 0x1000 + 37: return "LVM_GETTEXTBKCOLOR"; | |
4859 | case 0x1000 + 38: return "LVM_SETTEXTBKCOLOR"; | |
4860 | case 0x1000 + 39: return "LVM_GETTOPINDEX"; | |
4861 | case 0x1000 + 40: return "LVM_GETCOUNTPERPAGE"; | |
4862 | case 0x1000 + 41: return "LVM_GETORIGIN"; | |
4863 | case 0x1000 + 42: return "LVM_UPDATE"; | |
4864 | case 0x1000 + 43: return "LVM_SETITEMSTATE"; | |
4865 | case 0x1000 + 44: return "LVM_GETITEMSTATE"; | |
4866 | case 0x1000 + 45: return "LVM_GETITEMTEXTA"; | |
4867 | case 0x1000 + 115: return "LVM_GETITEMTEXTW"; | |
4868 | case 0x1000 + 46: return "LVM_SETITEMTEXTA"; | |
4869 | case 0x1000 + 116: return "LVM_SETITEMTEXTW"; | |
4870 | case 0x1000 + 47: return "LVM_SETITEMCOUNT"; | |
4871 | case 0x1000 + 48: return "LVM_SORTITEMS"; | |
4872 | case 0x1000 + 49: return "LVM_SETITEMPOSITION32"; | |
4873 | case 0x1000 + 50: return "LVM_GETSELECTEDCOUNT"; | |
4874 | case 0x1000 + 51: return "LVM_GETITEMSPACING"; | |
4875 | case 0x1000 + 52: return "LVM_GETISEARCHSTRINGA"; | |
4876 | case 0x1000 + 117: return "LVM_GETISEARCHSTRINGW"; | |
4877 | case 0x1000 + 53: return "LVM_SETICONSPACING"; | |
4878 | case 0x1000 + 54: return "LVM_SETEXTENDEDLISTVIEWSTYLE"; | |
4879 | case 0x1000 + 55: return "LVM_GETEXTENDEDLISTVIEWSTYLE"; | |
4880 | case 0x1000 + 56: return "LVM_GETSUBITEMRECT"; | |
4881 | case 0x1000 + 57: return "LVM_SUBITEMHITTEST"; | |
4882 | case 0x1000 + 58: return "LVM_SETCOLUMNORDERARRAY"; | |
4883 | case 0x1000 + 59: return "LVM_GETCOLUMNORDERARRAY"; | |
4884 | case 0x1000 + 60: return "LVM_SETHOTITEM"; | |
4885 | case 0x1000 + 61: return "LVM_GETHOTITEM"; | |
4886 | case 0x1000 + 62: return "LVM_SETHOTCURSOR"; | |
4887 | case 0x1000 + 63: return "LVM_GETHOTCURSOR"; | |
4888 | case 0x1000 + 64: return "LVM_APPROXIMATEVIEWRECT"; | |
4889 | case 0x1000 + 65: return "LVM_SETWORKAREA"; | |
c085e333 | 4890 | |
2d0a075d | 4891 | // tree view |
a02eb1d2 VZ |
4892 | case 0x1100 + 0: return "TVM_INSERTITEMA"; |
4893 | case 0x1100 + 50: return "TVM_INSERTITEMW"; | |
4894 | case 0x1100 + 1: return "TVM_DELETEITEM"; | |
4895 | case 0x1100 + 2: return "TVM_EXPAND"; | |
4896 | case 0x1100 + 4: return "TVM_GETITEMRECT"; | |
4897 | case 0x1100 + 5: return "TVM_GETCOUNT"; | |
4898 | case 0x1100 + 6: return "TVM_GETINDENT"; | |
4899 | case 0x1100 + 7: return "TVM_SETINDENT"; | |
4900 | case 0x1100 + 8: return "TVM_GETIMAGELIST"; | |
4901 | case 0x1100 + 9: return "TVM_SETIMAGELIST"; | |
4902 | case 0x1100 + 10: return "TVM_GETNEXTITEM"; | |
4903 | case 0x1100 + 11: return "TVM_SELECTITEM"; | |
4904 | case 0x1100 + 12: return "TVM_GETITEMA"; | |
4905 | case 0x1100 + 62: return "TVM_GETITEMW"; | |
4906 | case 0x1100 + 13: return "TVM_SETITEMA"; | |
4907 | case 0x1100 + 63: return "TVM_SETITEMW"; | |
4908 | case 0x1100 + 14: return "TVM_EDITLABELA"; | |
4909 | case 0x1100 + 65: return "TVM_EDITLABELW"; | |
4910 | case 0x1100 + 15: return "TVM_GETEDITCONTROL"; | |
4911 | case 0x1100 + 16: return "TVM_GETVISIBLECOUNT"; | |
4912 | case 0x1100 + 17: return "TVM_HITTEST"; | |
4913 | case 0x1100 + 18: return "TVM_CREATEDRAGIMAGE"; | |
4914 | case 0x1100 + 19: return "TVM_SORTCHILDREN"; | |
4915 | case 0x1100 + 20: return "TVM_ENSUREVISIBLE"; | |
4916 | case 0x1100 + 21: return "TVM_SORTCHILDRENCB"; | |
4917 | case 0x1100 + 22: return "TVM_ENDEDITLABELNOW"; | |
4918 | case 0x1100 + 23: return "TVM_GETISEARCHSTRINGA"; | |
4919 | case 0x1100 + 64: return "TVM_GETISEARCHSTRINGW"; | |
4920 | case 0x1100 + 24: return "TVM_SETTOOLTIPS"; | |
4921 | case 0x1100 + 25: return "TVM_GETTOOLTIPS"; | |
c085e333 | 4922 | |
2d0a075d | 4923 | // header |
a02eb1d2 VZ |
4924 | case 0x1200 + 0: return "HDM_GETITEMCOUNT"; |
4925 | case 0x1200 + 1: return "HDM_INSERTITEMA"; | |
4926 | case 0x1200 + 10: return "HDM_INSERTITEMW"; | |
4927 | case 0x1200 + 2: return "HDM_DELETEITEM"; | |
4928 | case 0x1200 + 3: return "HDM_GETITEMA"; | |
4929 | case 0x1200 + 11: return "HDM_GETITEMW"; | |
4930 | case 0x1200 + 4: return "HDM_SETITEMA"; | |
4931 | case 0x1200 + 12: return "HDM_SETITEMW"; | |
4932 | case 0x1200 + 5: return "HDM_LAYOUT"; | |
4933 | case 0x1200 + 6: return "HDM_HITTEST"; | |
4934 | case 0x1200 + 7: return "HDM_GETITEMRECT"; | |
4935 | case 0x1200 + 8: return "HDM_SETIMAGELIST"; | |
4936 | case 0x1200 + 9: return "HDM_GETIMAGELIST"; | |
4937 | case 0x1200 + 15: return "HDM_ORDERTOINDEX"; | |
4938 | case 0x1200 + 16: return "HDM_CREATEDRAGIMAGE"; | |
4939 | case 0x1200 + 17: return "HDM_GETORDERARRAY"; | |
4940 | case 0x1200 + 18: return "HDM_SETORDERARRAY"; | |
4941 | case 0x1200 + 19: return "HDM_SETHOTDIVIDER"; | |
c085e333 | 4942 | |
2d0a075d | 4943 | // tab control |
a02eb1d2 VZ |
4944 | case 0x1300 + 2: return "TCM_GETIMAGELIST"; |
4945 | case 0x1300 + 3: return "TCM_SETIMAGELIST"; | |
4946 | case 0x1300 + 4: return "TCM_GETITEMCOUNT"; | |
4947 | case 0x1300 + 5: return "TCM_GETITEMA"; | |
4948 | case 0x1300 + 60: return "TCM_GETITEMW"; | |
4949 | case 0x1300 + 6: return "TCM_SETITEMA"; | |
4950 | case 0x1300 + 61: return "TCM_SETITEMW"; | |
4951 | case 0x1300 + 7: return "TCM_INSERTITEMA"; | |
4952 | case 0x1300 + 62: return "TCM_INSERTITEMW"; | |
4953 | case 0x1300 + 8: return "TCM_DELETEITEM"; | |
4954 | case 0x1300 + 9: return "TCM_DELETEALLITEMS"; | |
4955 | case 0x1300 + 10: return "TCM_GETITEMRECT"; | |
4956 | case 0x1300 + 11: return "TCM_GETCURSEL"; | |
4957 | case 0x1300 + 12: return "TCM_SETCURSEL"; | |
4958 | case 0x1300 + 13: return "TCM_HITTEST"; | |
4959 | case 0x1300 + 14: return "TCM_SETITEMEXTRA"; | |
4960 | case 0x1300 + 40: return "TCM_ADJUSTRECT"; | |
4961 | case 0x1300 + 41: return "TCM_SETITEMSIZE"; | |
4962 | case 0x1300 + 42: return "TCM_REMOVEIMAGE"; | |
4963 | case 0x1300 + 43: return "TCM_SETPADDING"; | |
4964 | case 0x1300 + 44: return "TCM_GETROWCOUNT"; | |
4965 | case 0x1300 + 45: return "TCM_GETTOOLTIPS"; | |
4966 | case 0x1300 + 46: return "TCM_SETTOOLTIPS"; | |
4967 | case 0x1300 + 47: return "TCM_GETCURFOCUS"; | |
4968 | case 0x1300 + 48: return "TCM_SETCURFOCUS"; | |
4969 | case 0x1300 + 49: return "TCM_SETMINTABWIDTH"; | |
4970 | case 0x1300 + 50: return "TCM_DESELECTALL"; | |
c085e333 | 4971 | |
2d0a075d | 4972 | // toolbar |
a02eb1d2 VZ |
4973 | case WM_USER+1: return "TB_ENABLEBUTTON"; |
4974 | case WM_USER+2: return "TB_CHECKBUTTON"; | |
4975 | case WM_USER+3: return "TB_PRESSBUTTON"; | |
4976 | case WM_USER+4: return "TB_HIDEBUTTON"; | |
4977 | case WM_USER+5: return "TB_INDETERMINATE"; | |
4978 | case WM_USER+9: return "TB_ISBUTTONENABLED"; | |
4979 | case WM_USER+10: return "TB_ISBUTTONCHECKED"; | |
4980 | case WM_USER+11: return "TB_ISBUTTONPRESSED"; | |
4981 | case WM_USER+12: return "TB_ISBUTTONHIDDEN"; | |
4982 | case WM_USER+13: return "TB_ISBUTTONINDETERMINATE"; | |
4983 | case WM_USER+17: return "TB_SETSTATE"; | |
4984 | case WM_USER+18: return "TB_GETSTATE"; | |
4985 | case WM_USER+19: return "TB_ADDBITMAP"; | |
4986 | case WM_USER+20: return "TB_ADDBUTTONS"; | |
4987 | case WM_USER+21: return "TB_INSERTBUTTON"; | |
4988 | case WM_USER+22: return "TB_DELETEBUTTON"; | |
4989 | case WM_USER+23: return "TB_GETBUTTON"; | |
4990 | case WM_USER+24: return "TB_BUTTONCOUNT"; | |
4991 | case WM_USER+25: return "TB_COMMANDTOINDEX"; | |
4992 | case WM_USER+26: return "TB_SAVERESTOREA"; | |
4993 | case WM_USER+76: return "TB_SAVERESTOREW"; | |
4994 | case WM_USER+27: return "TB_CUSTOMIZE"; | |
4995 | case WM_USER+28: return "TB_ADDSTRINGA"; | |
4996 | case WM_USER+77: return "TB_ADDSTRINGW"; | |
4997 | case WM_USER+29: return "TB_GETITEMRECT"; | |
4998 | case WM_USER+30: return "TB_BUTTONSTRUCTSIZE"; | |
4999 | case WM_USER+31: return "TB_SETBUTTONSIZE"; | |
5000 | case WM_USER+32: return "TB_SETBITMAPSIZE"; | |
5001 | case WM_USER+33: return "TB_AUTOSIZE"; | |
5002 | case WM_USER+35: return "TB_GETTOOLTIPS"; | |
5003 | case WM_USER+36: return "TB_SETTOOLTIPS"; | |
5004 | case WM_USER+37: return "TB_SETPARENT"; | |
5005 | case WM_USER+39: return "TB_SETROWS"; | |
5006 | case WM_USER+40: return "TB_GETROWS"; | |
5007 | case WM_USER+42: return "TB_SETCMDID"; | |
5008 | case WM_USER+43: return "TB_CHANGEBITMAP"; | |
5009 | case WM_USER+44: return "TB_GETBITMAP"; | |
5010 | case WM_USER+45: return "TB_GETBUTTONTEXTA"; | |
5011 | case WM_USER+75: return "TB_GETBUTTONTEXTW"; | |
5012 | case WM_USER+46: return "TB_REPLACEBITMAP"; | |
5013 | case WM_USER+47: return "TB_SETINDENT"; | |
5014 | case WM_USER+48: return "TB_SETIMAGELIST"; | |
5015 | case WM_USER+49: return "TB_GETIMAGELIST"; | |
5016 | case WM_USER+50: return "TB_LOADIMAGES"; | |
5017 | case WM_USER+51: return "TB_GETRECT"; | |
5018 | case WM_USER+52: return "TB_SETHOTIMAGELIST"; | |
5019 | case WM_USER+53: return "TB_GETHOTIMAGELIST"; | |
5020 | case WM_USER+54: return "TB_SETDISABLEDIMAGELIST"; | |
5021 | case WM_USER+55: return "TB_GETDISABLEDIMAGELIST"; | |
5022 | case WM_USER+56: return "TB_SETSTYLE"; | |
5023 | case WM_USER+57: return "TB_GETSTYLE"; | |
5024 | case WM_USER+58: return "TB_GETBUTTONSIZE"; | |
5025 | case WM_USER+59: return "TB_SETBUTTONWIDTH"; | |
5026 | case WM_USER+60: return "TB_SETMAXTEXTROWS"; | |
5027 | case WM_USER+61: return "TB_GETTEXTROWS"; | |
5028 | case WM_USER+41: return "TB_GETBITMAPFLAGS"; | |
c085e333 | 5029 | |
a02eb1d2 | 5030 | #endif //WIN32 |
c085e333 | 5031 | |
47cbd6da | 5032 | default: |
2d0a075d JS |
5033 | static char s_szBuf[128]; |
5034 | sprintf(s_szBuf, "<unknown message = %d>", message); | |
5035 | return s_szBuf; | |
47cbd6da VZ |
5036 | } |
5037 | } | |
ea57084d | 5038 | #endif //__WXDEBUG__ |