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