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