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