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