1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "window.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
28 #include "wx/dcclient.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"
41 #include "wx/ownerdrw.h"
45 #include "wx/msw/ole/droptgt.h"
48 #include "wx/menuitem.h"
50 #include "wx/msw/private.h"
64 #include <wx/msw/gnuwin32/extra.h>
84 static const char *GetMessageName(int message
);
87 #define WINDOW_MARGIN 3 // This defines sensitivity of Leave events
89 wxMenu
*wxCurrentPopupMenu
= NULL
;
90 extern wxList wxPendingDelete
;
92 void wxRemoveHandleAssociation(wxWindow
*win
);
93 void wxAssociateWinWithHandle(HWND hWnd
, wxWindow
*win
);
94 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
);
96 #if !USE_SHARED_LIBRARY
97 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxEvtHandler
)
99 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
100 EVT_CHAR(wxWindow::OnChar
)
101 EVT_SIZE(wxWindow::OnSize
)
102 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground
)
103 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
104 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
105 EVT_IDLE(wxWindow::OnIdle
)
110 // Find an item given the MS Windows id
111 wxWindow
*wxWindow::FindItem(int id
) const
115 wxNode
*current
= GetChildren()->First();
118 wxWindow
*childWin
= (wxWindow
*)current
->Data();
120 wxWindow
*wnd
= childWin
->FindItem(id
) ;
124 if (childWin
->IsKindOf(CLASSINFO(wxControl
)))
126 wxControl
*item
= (wxControl
*)childWin
;
127 if (item
->m_windowId
== id
)
131 // In case it's a 'virtual' control (e.g. radiobox)
132 if (item
->GetSubcontrols().Member((wxObject
*)id
))
136 current
= current
->Next();
141 // Find an item given the MS Windows handle
142 wxWindow
*wxWindow::FindItemByHWND(WXHWND hWnd
, bool controlOnly
) const
146 wxNode
*current
= GetChildren()->First();
149 wxObject
*obj
= (wxObject
*)current
->Data() ;
150 // Do a recursive search.
151 wxWindow
*parent
= (wxWindow
*)obj
;
152 wxWindow
*wnd
= parent
->FindItemByHWND(hWnd
) ;
156 if ((!controlOnly
) || obj
->IsKindOf(CLASSINFO(wxControl
)))
158 wxWindow
*item
= (wxWindow
*)current
->Data();
159 if ((HWND
)(item
->GetHWND()) == (HWND
) hWnd
)
163 if ( item
->ContainsHWND(hWnd
) )
167 current
= current
->Next();
172 // Default command handler
173 bool wxWindow::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
178 bool wxWindow::MSWNotify(WXWPARAM
WXUNUSED(wParam
), WXLPARAM
WXUNUSED(lParam
))
183 void wxWindow::PreDelete(WXHDC
WXUNUSED(dc
))
187 WXHWND
wxWindow::GetHWND(void) const
189 return (WXHWND
) m_hWnd
;
192 void wxWindow::SetHWND(WXHWND hWnd
)
198 wxWindow::wxWindow(void)
204 m_windowParent
= NULL
;
205 m_windowEventHandler
= this;
207 m_windowCursor
= *wxSTANDARD_CURSOR
;
208 m_children
= new wxList
;
209 m_doubleClickAllowed
= 0 ;
210 m_winCaptured
= FALSE
;
211 m_constraints
= NULL
;
212 m_constraintsInvolvedIn
= NULL
;
213 m_windowSizer
= NULL
;
214 m_sizerParent
= NULL
;
215 m_autoLayout
= FALSE
;
216 m_windowValidator
= NULL
;
221 m_caretWidth
= 0; m_caretHeight
= 0;
222 m_caretEnabled
= FALSE
;
223 m_caretShown
= FALSE
;
231 m_isBeingDeleted
= FALSE
;
238 m_defaultItem
= NULL
;
240 wxSystemSettings settings
;
242 m_backgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_WINDOW
) ; ;
243 m_foregroundColour
= *wxBLACK
;
244 m_defaultForegroundColour
= *wxBLACK
;
245 m_defaultBackgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
248 wxColour(GetRValue(GetSysColor(COLOR_WINDOW)),
249 GetGValue(GetSysColor(COLOR_BTNFACE)), GetBValue(GetSysColor(COLOR_BTNFACE)));
256 m_acceleratorTable
= 0;
261 m_backgroundTransparent
= FALSE
;
263 m_lastXPos
= (float)-1.0;
264 m_lastYPos
= (float)-1.0;
268 #if USE_DRAG_AND_DROP
269 m_pDropTarget
= NULL
;
274 wxWindow::~wxWindow(void)
276 m_isBeingDeleted
= TRUE
;
278 // JACS - if behaviour is odd, restore this
279 // to the start of ~wxWindow. Vadim has changed
280 // it to nearer the end. Unsure of side-effects
281 // e.g. when deleting associated global data.
282 // Restore old Window proc, if required
285 // Have to delete constraints/sizer FIRST otherwise
286 // sizers may try to look at deleted windows as they
287 // delete themselves.
289 DeleteRelatedConstraints();
292 // This removes any dangling pointers to this window
293 // in other windows' constraintsInvolvedIn lists.
294 UnsetConstraints(m_constraints
);
295 delete m_constraints
;
296 m_constraints
= NULL
;
300 delete m_windowSizer
;
301 m_windowSizer
= NULL
;
303 // If this is a child of a sizer, remove self from parent
305 m_sizerParent
->RemoveChild((wxWindow
*)this);
309 MSWDetachWindowMenu();
311 // TODO for backward compatibility
316 HWND hWnd
= (HWND
) GetHWND();
317 HDC dc
= ::GetDC(hWnd
);
318 m_windowDC
->SelectOldObjects (dc
);
325 m_windowParent
->RemoveChild(this);
330 ::DestroyWindow((HWND
)m_hWnd
);
332 wxRemoveHandleAssociation(this);
337 GlobalFree((HGLOBAL
) m_globalHandle
);
345 // Just in case the window has been Closed, but
346 // we're then deleting immediately: don't leave
347 // dangling pointers.
348 wxPendingDelete
.DeleteObject(this);
350 // Just in case we've loaded a top-level window via
351 // wxWindow::LoadNativeDialog but we weren't a dialog
353 wxTopLevelWindows
.DeleteObject(this);
355 // if (GetFont() && GetFont()->Ok())
356 // GetFont()->ReleaseResource();
358 if ( m_windowValidator
)
359 delete m_windowValidator
;
361 // Restore old Window proc, if required
362 // and remove hWnd <-> wxWindow association
366 // Destroy the window (delayed, if a managed window)
367 bool wxWindow::Destroy(void)
373 extern char wxCanvasClassName
[];
376 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
380 const wxString
& name
)
383 m_isBeingDeleted
= FALSE
;
387 m_windowParent
= NULL
;
388 m_windowEventHandler
= this;
389 // m_windowFont = NULL;
390 // We don't wish internal (potentially transient) fonts to be found
392 // wxTheFontList->RemoveFont(& m_windowFont);
394 m_windowCursor
= *wxSTANDARD_CURSOR
;
395 m_doubleClickAllowed
= 0 ;
396 m_winCaptured
= FALSE
;
397 m_constraints
= NULL
;
398 m_constraintsInvolvedIn
= NULL
;
399 m_windowSizer
= NULL
;
400 m_sizerParent
= NULL
;
401 m_autoLayout
= FALSE
;
402 m_windowValidator
= NULL
;
403 #if USE_DRAG_AND_DROP
404 m_pDropTarget
= NULL
;
410 m_caretWidth
= 0; m_caretHeight
= 0;
411 m_caretEnabled
= FALSE
;
412 m_caretShown
= FALSE
;
425 m_defaultItem
= NULL
;
426 m_windowParent
= NULL
;
427 // m_windowDC = NULL;
428 m_mouseInWindow
= FALSE
;
432 if (parent
) parent
->AddChild(this);
438 m_acceleratorTable
= 0;
443 m_backgroundTransparent
= FALSE
;
445 m_lastXPos
= (float)-1.0;
446 m_lastYPos
= (float)-1.0;
453 m_windowId
= (int)NewControlId();
462 wxSystemSettings settings
;
464 m_backgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_WINDOW
) ; ;
465 m_foregroundColour
= *wxBLACK
;
466 m_defaultForegroundColour
= *wxBLACK
;
467 m_defaultBackgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
469 m_defaultBackgroundColour = wxColour(GetRValue(GetSysColor(COLOR_BTNFACE)),
470 GetGValue(GetSysColor(COLOR_BTNFACE)), GetBValue(GetSysColor(COLOR_BTNFACE)));
473 m_windowStyle
= style
;
476 if (style
& wxBORDER
)
477 msflags
|= WS_BORDER
;
478 if (style
& wxTHICK_FRAME
)
479 msflags
|= WS_THICKFRAME
;
481 msflags
|= WS_CHILD
| WS_VISIBLE
;
482 if (style
& wxCLIP_CHILDREN
)
483 msflags
|= WS_CLIPCHILDREN
;
486 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
) ;
488 // Even with extended styles, need to combine with WS_BORDER
489 // for them to look right.
490 if (want3D
|| (m_windowStyle
& wxSIMPLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
491 (m_windowStyle
& wxSUNKEN_BORDER
) || (m_windowStyle
& wxDOUBLE_BORDER
))
492 msflags
|= WS_BORDER
;
494 m_mouseInWindow
= FALSE
;
497 m_windowId
= (int)NewControlId();
501 MSWCreate(m_windowId
, (wxWindow
*)parent
, wxCanvasClassName
, this, NULL
, x
, y
, width
, height
, msflags
,
507 void wxWindow::SetFocus(void)
509 HWND hWnd
= (HWND
) GetHWND();
514 void wxWindow::Enable(bool enable
)
516 m_winEnabled
= enable
;
517 HWND hWnd
= (HWND
) GetHWND();
519 ::EnableWindow(hWnd
, (BOOL
)enable
);
522 void wxWindow::CaptureMouse(void)
524 HWND hWnd
= (HWND
) GetHWND();
525 if (hWnd
&& !m_winCaptured
)
528 m_winCaptured
= TRUE
;
532 void wxWindow::ReleaseMouse(void)
537 m_winCaptured
= FALSE
;
541 // Push/pop event handler (i.e. allow a chain of event handlers
543 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
545 handler
->SetNextHandler(GetEventHandler());
546 SetEventHandler(handler
);
549 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
551 if ( GetEventHandler() )
553 wxEvtHandler
*handlerA
= GetEventHandler();
554 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
555 handlerA
->SetNextHandler(NULL
);
556 SetEventHandler(handlerB
);
569 #if USE_DRAG_AND_DROP
571 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
573 if ( m_pDropTarget
!= 0 ) {
574 m_pDropTarget
->Revoke(m_hWnd
);
575 delete m_pDropTarget
;
578 m_pDropTarget
= pDropTarget
;
579 if ( m_pDropTarget
!= 0 )
580 m_pDropTarget
->Register(m_hWnd
);
585 //old style file-manager drag&drop support
586 // I think we should retain the old-style
587 // DragAcceptFiles in parallel with SetDropTarget.
589 void wxWindow::DragAcceptFiles(bool accept
)
591 HWND hWnd
= (HWND
) GetHWND();
593 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
597 void wxWindow::GetSize(int *x
, int *y
) const
599 HWND hWnd
= (HWND
) GetHWND();
601 GetWindowRect(hWnd
, &rect
);
602 *x
= rect
.right
- rect
.left
;
603 *y
= rect
.bottom
- rect
.top
;
606 void wxWindow::GetPosition(int *x
, int *y
) const
608 HWND hWnd
= (HWND
) GetHWND();
611 hParentWnd
= (HWND
) GetParent()->GetHWND();
614 GetWindowRect(hWnd
, &rect
);
616 // Since we now have the absolute screen coords,
617 // if there's a parent we must subtract its top left corner
623 ::ScreenToClient(hParentWnd
, &point
);
629 void wxWindow::ScreenToClient(int *x
, int *y
) const
631 HWND hWnd
= (HWND
) GetHWND();
635 ::ScreenToClient(hWnd
, &pt
);
641 void wxWindow::ClientToScreen(int *x
, int *y
) const
643 HWND hWnd
= (HWND
) GetHWND();
647 ::ClientToScreen(hWnd
, &pt
);
653 void wxWindow::SetCursor(const wxCursor
& cursor
)
655 m_windowCursor
= cursor
;
656 if (m_windowCursor
.Ok())
658 HWND hWnd
= (HWND
) GetHWND();
660 // Change the cursor NOW if we're within the correct window
662 ::GetCursorPos(&point
);
665 ::GetWindowRect(hWnd
, &rect
);
667 if (::PtInRect(&rect
, point
) && !wxIsBusy())
668 ::SetCursor((HCURSOR
) m_windowCursor
.GetHCURSOR());
671 // This will cause big reentrancy problems if wxFlushEvents is implemented.
673 // return old_cursor;
677 // Get size *available for subwindows* i.e. excluding menu bar etc.
678 // For XView, this is the same as GetSize
679 void wxWindow::GetClientSize(int *x
, int *y
) const
681 HWND hWnd
= (HWND
) GetHWND();
683 GetClientRect(hWnd
, &rect
);
688 void wxWindow::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
690 int currentX
, currentY
;
691 GetPosition(¤tX
, ¤tY
);
692 int actualWidth
= width
;
693 int actualHeight
= height
;
696 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
698 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
701 int currentW
,currentH
;
702 GetSize(¤tW
, ¤tH
);
704 actualWidth
= currentW
;
706 actualHeight
= currentH
;
708 HWND hWnd
= (HWND
) GetHWND();
710 MoveWindow(hWnd
, actualX
, actualY
, actualWidth
, actualHeight
, (BOOL
)TRUE
);
713 void wxWindow::SetClientSize(int width
, int height
)
715 wxWindow
*parent
= GetParent();
716 HWND hWnd
= (HWND
) GetHWND();
717 HWND hParentWnd
= (HWND
) (HWND
) parent
->GetHWND();
720 GetClientRect(hWnd
, &rect
);
723 GetWindowRect(hWnd
, &rect2
);
725 // Find the difference between the entire window (title bar and all)
726 // and the client area; add this to the new client size to move the
728 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
729 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
731 // If there's a parent, must subtract the parent's top left corner
732 // since MoveWindow moves relative to the parent
735 point
.x
= rect2
.left
;
739 ::ScreenToClient(hParentWnd
, &point
);
742 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
744 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
745 event
.SetEventObject(this);
746 GetEventHandler()->ProcessEvent(event
);
749 bool wxWindow::Show(bool show
)
751 HWND hWnd
= (HWND
) GetHWND();
757 ShowWindow(hWnd
, (BOOL
)cshow
);
760 BringWindowToTop(hWnd
);
761 // Next line causes a crash on NT, apparently.
762 // UpdateWindow(hWnd); // Should this be here or will it cause inefficiency?
767 bool wxWindow::IsShown(void) const
769 return (::IsWindowVisible((HWND
) GetHWND()) != 0);
772 int wxWindow::GetCharHeight(void) const
774 TEXTMETRIC lpTextMetric
;
775 HWND hWnd
= (HWND
) GetHWND();
776 HDC dc
= ::GetDC(hWnd
);
778 GetTextMetrics(dc
, &lpTextMetric
);
779 ::ReleaseDC(hWnd
, dc
);
781 return lpTextMetric
.tmHeight
;
784 int wxWindow::GetCharWidth(void) const
786 TEXTMETRIC lpTextMetric
;
787 HWND hWnd
= (HWND
) GetHWND();
788 HDC dc
= ::GetDC(hWnd
);
790 GetTextMetrics(dc
, &lpTextMetric
);
791 ::ReleaseDC(hWnd
, dc
);
793 return lpTextMetric
.tmAveCharWidth
;
796 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
797 int *descent
, int *externalLeading
, const wxFont
*theFont
, bool) const
799 wxFont
*fontToUse
= (wxFont
*)theFont
;
801 fontToUse
= (wxFont
*) & m_windowFont
;
803 HWND hWnd
= (HWND
) GetHWND();
804 HDC dc
= ::GetDC(hWnd
);
808 if (fontToUse
&& fontToUse
->Ok())
810 if ((fnt
=(HFONT
) fontToUse
->GetResourceHandle()))
811 was
= SelectObject(dc
,fnt
) ;
816 GetTextExtentPoint(dc
, (const char *)string
, (int)string
.Length(), &sizeRect
);
817 GetTextMetrics(dc
, &tm
);
819 if (fontToUse
&& fnt
&& was
)
820 SelectObject(dc
,was
) ;
826 if (descent
) *descent
= tm
.tmDescent
;
827 if (externalLeading
) *externalLeading
= tm
.tmExternalLeading
;
830 // fontToUse->ReleaseResource();
833 void wxWindow::Refresh(bool eraseBack
, const wxRectangle
*rect
)
835 HWND hWnd
= (HWND
) GetHWND();
841 mswRect
.left
= rect
->x
;
842 mswRect
.top
= rect
->y
;
843 mswRect
.right
= rect
->x
+ rect
->width
;
844 mswRect
.bottom
= rect
->y
+ rect
->height
;
846 ::InvalidateRect(hWnd
, &mswRect
, eraseBack
);
849 ::InvalidateRect(hWnd
, NULL
, eraseBack
);
853 // Hook for new window just as it's being created,
854 // when the window isn't yet associated with the handle
855 wxWindow
*wxWndHook
= NULL
;
858 LRESULT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
860 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
862 if (!wnd
&& wxWndHook
)
864 wxAssociateWinWithHandle(hWnd
, wxWndHook
);
867 wnd
->m_hWnd
= (WXHWND
) hWnd
;
870 wxDebugMsg("hWnd = %d, m_hWnd = %d, msg = %d\n", hWnd
, m_hWnd
, message
);
872 // Stop right here if we don't have a valid handle
873 // in our wxWnd object.
874 if (wnd
&& !wnd
->m_hWnd
) {
875 // wxDebugMsg("Warning: could not find a valid handle, wx_win.cc/wxWndProc.\n");
876 wnd
->m_hWnd
= (WXHWND
) hWnd
;
877 long res
= wnd
->MSWDefWindowProc(message
, wParam
, lParam
);
883 wnd
->m_lastMsg
= message
;
884 wnd
->m_lastWParam
= wParam
;
885 wnd
->m_lastLParam
= lParam
;
888 return wnd
->MSWWindowProc(message
, wParam
, lParam
);
890 return DefWindowProc( hWnd
, message
, wParam
, lParam
);
893 // Should probably have a test for 'genuine' NT
894 #if defined(__WIN32__)
895 #define DIMENSION_TYPE short
897 #define DIMENSION_TYPE int
900 // Main Windows 3 window proc
901 long wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
904 wxLogTrace(wxTraceMessages
, "Processing %s", GetMessageName(message
));
907 HWND hWnd
= (HWND
)m_hWnd
;
914 WORD state
= LOWORD(wParam
);
915 WORD minimized
= HIWORD(wParam
);
916 HWND hwnd
= (HWND
)lParam
;
918 WORD state
= (WORD
)wParam
;
919 WORD minimized
= LOWORD(lParam
);
920 HWND hwnd
= (HWND
)HIWORD(lParam
);
922 MSWOnActivate(state
, (minimized
!= 0), (WXHWND
) hwnd
);
928 HWND hwnd
= (HWND
)wParam
;
929 // return OnSetFocus(hwnd);
931 if (MSWOnSetFocus((WXHWND
) hwnd
))
933 else return MSWDefWindowProc(message
, wParam
, lParam
);
938 HWND hwnd
= (HWND
)lParam
;
939 // return OnKillFocus(hwnd);
940 if (MSWOnKillFocus((WXHWND
) hwnd
))
943 return MSWDefWindowProc(message
, wParam
, lParam
);
948 MSWOnCreate((WXLPCREATESTRUCT
) (LPCREATESTRUCT
)lParam
);
954 MSWOnShow((wParam
!= 0), (int) lParam
);
961 else return MSWDefWindowProc(message
, wParam
, lParam
);
964 case WM_QUERYDRAGICON
:
967 if ((hIcon
= (HICON
) MSWOnQueryDragIcon()))
969 else return MSWDefWindowProc(message
, wParam
, lParam
);
975 int width
= LOWORD(lParam
);
976 int height
= HIWORD(lParam
);
977 MSWOnSize(width
, height
, wParam
);
981 case WM_WINDOWPOSCHANGING
:
983 WINDOWPOS
*pos
= (WINDOWPOS
*)lParam
;
984 MSWOnWindowPosChanging((void *)pos
);
990 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
991 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
992 MSWOnRButtonDown(x
, y
, wParam
);
997 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
998 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
999 MSWOnRButtonUp(x
, y
, wParam
);
1002 case WM_RBUTTONDBLCLK
:
1004 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1005 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1006 MSWOnRButtonDClick(x
, y
, wParam
);
1009 case WM_MBUTTONDOWN
:
1011 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1012 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1013 MSWOnMButtonDown(x
, y
, wParam
);
1018 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1019 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1020 MSWOnMButtonUp(x
, y
, wParam
);
1023 case WM_MBUTTONDBLCLK
:
1025 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1026 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1027 MSWOnMButtonDClick(x
, y
, wParam
);
1030 case WM_LBUTTONDOWN
:
1032 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1033 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1034 MSWOnLButtonDown(x
, y
, wParam
);
1039 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1040 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1041 MSWOnLButtonUp(x
, y
, wParam
);
1044 case WM_LBUTTONDBLCLK
:
1046 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1047 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1048 MSWOnLButtonDClick(x
, y
, wParam
);
1053 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1054 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1055 MSWOnMouseMove(x
, y
, wParam
);
1058 case MM_JOY1BUTTONDOWN
:
1060 int x
= LOWORD(lParam
);
1061 int y
= HIWORD(lParam
);
1062 MSWOnJoyDown(wxJOYSTICK1
, x
, y
, wParam
);
1065 case MM_JOY2BUTTONDOWN
:
1067 int x
= LOWORD(lParam
);
1068 int y
= HIWORD(lParam
);
1069 MSWOnJoyDown(wxJOYSTICK2
, x
, y
, wParam
);
1072 case MM_JOY1BUTTONUP
:
1074 int x
= LOWORD(lParam
);
1075 int y
= HIWORD(lParam
);
1076 MSWOnJoyUp(wxJOYSTICK1
, x
, y
, wParam
);
1079 case MM_JOY2BUTTONUP
:
1081 int x
= LOWORD(lParam
);
1082 int y
= HIWORD(lParam
);
1083 MSWOnJoyUp(wxJOYSTICK2
, x
, y
, wParam
);
1088 int x
= LOWORD(lParam
);
1089 int y
= HIWORD(lParam
);
1090 MSWOnJoyMove(wxJOYSTICK1
, x
, y
, wParam
);
1095 int x
= LOWORD(lParam
);
1096 int y
= HIWORD(lParam
);
1097 MSWOnJoyMove(wxJOYSTICK2
, x
, y
, wParam
);
1102 int z
= LOWORD(lParam
);
1103 MSWOnJoyZMove(wxJOYSTICK1
, z
, wParam
);
1108 int z
= LOWORD(lParam
);
1109 MSWOnJoyZMove(wxJOYSTICK2
, z
, wParam
);
1116 else return MSWDefWindowProc(message
, wParam
, lParam
);
1121 return MSWOnSysCommand(wParam
, lParam
);
1127 WORD id
= LOWORD(wParam
);
1128 HWND hwnd
= (HWND
)lParam
;
1129 WORD cmd
= HIWORD(wParam
);
1131 WORD id
= (WORD
)wParam
;
1132 HWND hwnd
= (HWND
)LOWORD(lParam
) ;
1133 WORD cmd
= HIWORD(lParam
);
1135 if (!MSWOnCommand(id
, cmd
, (WXHWND
) hwnd
))
1136 return MSWDefWindowProc(message
, wParam
, lParam
);
1139 #if defined(__WIN95__)
1142 if (!MSWOnNotify(wParam
, lParam
))
1143 return MSWDefWindowProc(message
, wParam
, lParam
);
1150 WORD flags
= HIWORD(wParam
);
1151 HMENU sysmenu
= (HMENU
)lParam
;
1153 WORD flags
= LOWORD(lParam
);
1154 HMENU sysmenu
= (HMENU
)HIWORD(lParam
);
1156 MSWOnMenuHighlight((WORD
)wParam
, flags
, (WXHMENU
) sysmenu
);
1159 case WM_INITMENUPOPUP
:
1161 MSWOnInitMenuPopup((WXHMENU
) (HMENU
)wParam
, (int)LOWORD(lParam
), (HIWORD(lParam
) != 0));
1166 return MSWOnDrawItem((int)wParam
, (WXDRAWITEMSTRUCT
*)lParam
);
1169 case WM_MEASUREITEM
:
1171 return MSWOnMeasureItem((int)wParam
, (WXMEASUREITEMSTRUCT
*)lParam
);
1176 // we consider these message "not interesting"
1177 if ( wParam
== VK_SHIFT
|| wParam
== VK_CONTROL
)
1180 // Avoid duplicate messages to OnChar
1181 if ( (wParam
!= VK_ESCAPE
) && (wParam
!= VK_SPACE
) &&
1182 (wParam
!= VK_RETURN
) && (wParam
!= VK_BACK
) &&
1183 (wParam
!= VK_TAB
) )
1185 MSWOnChar((WORD
)wParam
, lParam
);
1186 if ( ::GetKeyState(VK_CONTROL
) & 0x100 )
1189 else if ( ::GetKeyState(VK_CONTROL
) & 0x100 )
1190 MSWOnChar((WORD
)wParam
, lParam
);
1198 case WM_CHAR
: // Always an ASCII character
1200 MSWOnChar((WORD
)wParam
, lParam
, TRUE
);
1207 WORD code
= LOWORD(wParam
);
1208 WORD pos
= HIWORD(wParam
);
1209 HWND control
= (HWND
)lParam
;
1211 WORD code
= (WORD
)wParam
;
1212 WORD pos
= LOWORD(lParam
);
1213 HWND control
= (HWND
)HIWORD(lParam
);
1215 MSWOnHScroll(code
, pos
, (WXHWND
) control
);
1221 WORD code
= LOWORD(wParam
);
1222 WORD pos
= HIWORD(wParam
);
1223 HWND control
= (HWND
)lParam
;
1225 WORD code
= (WORD
)wParam
;
1226 WORD pos
= LOWORD(lParam
);
1227 HWND control
= (HWND
)HIWORD(lParam
);
1229 MSWOnVScroll(code
, pos
, (WXHWND
) control
);
1233 case WM_CTLCOLORBTN
:
1235 int nCtlColor
= CTLCOLOR_BTN
;
1236 HWND control
= (HWND
)lParam
;
1237 HDC pDC
= (HDC
)wParam
;
1238 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1239 message
, wParam
, lParam
);
1242 case WM_CTLCOLORDLG
:
1244 int nCtlColor
= CTLCOLOR_DLG
;
1245 HWND control
= (HWND
)lParam
;
1246 HDC pDC
= (HDC
)wParam
;
1247 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1248 message
, wParam
, lParam
);\
1251 case WM_CTLCOLORLISTBOX
:
1253 int nCtlColor
= CTLCOLOR_LISTBOX
;
1254 HWND control
= (HWND
)lParam
;
1255 HDC pDC
= (HDC
)wParam
;
1256 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1257 message
, wParam
, lParam
);
1260 case WM_CTLCOLORMSGBOX
:
1262 int nCtlColor
= CTLCOLOR_MSGBOX
;
1263 HWND control
= (HWND
)lParam
;
1264 HDC pDC
= (HDC
)wParam
;
1265 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1266 message
, wParam
, lParam
);
1269 case WM_CTLCOLORSCROLLBAR
:
1271 int nCtlColor
= CTLCOLOR_SCROLLBAR
;
1272 HWND control
= (HWND
)lParam
;
1273 HDC pDC
= (HDC
)wParam
;
1274 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1275 message
, wParam
, lParam
);
1278 case WM_CTLCOLORSTATIC
:
1280 int nCtlColor
= CTLCOLOR_STATIC
;
1281 HWND control
= (HWND
)lParam
;
1282 HDC pDC
= (HDC
)wParam
;
1283 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1284 message
, wParam
, lParam
);
1287 case WM_CTLCOLOREDIT
:
1289 int nCtlColor
= CTLCOLOR_EDIT
;
1290 HWND control
= (HWND
)lParam
;
1291 HDC pDC
= (HDC
)wParam
;
1292 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1293 message
, wParam
, lParam
);
1299 HWND control
= (HWND
)LOWORD(lParam
);
1300 int nCtlColor
= (int)HIWORD(lParam
);
1301 HDC pDC
= (HDC
)wParam
;
1302 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1303 message
, wParam
, lParam
);
1307 case WM_SYSCOLORCHANGE
:
1309 // Return value of 0 means, we processed it.
1310 if (MSWOnColorChange((WXHWND
) hWnd
, message
, wParam
, lParam
) == 0)
1313 return MSWDefWindowProc(message
, wParam
, lParam
);
1318 // Prevents flicker when dragging
1319 if (IsIconic(hWnd
)) return 1;
1323 if (!MSWOnEraseBkgnd((WXHDC
) (HDC
)wParam
))
1324 return 0; // Default(); MSWDefWindowProc(message, wParam, lParam );
1328 case WM_MDIACTIVATE
:
1331 HWND hWndActivate
= GET_WM_MDIACTIVATE_HWNDACTIVATE(wParam
,lParam
);
1332 HWND hWndDeactivate
= GET_WM_MDIACTIVATE_HWNDDEACT(wParam
,lParam
);
1333 BOOL activate
= GET_WM_MDIACTIVATE_FACTIVATE(hWnd
,wParam
,lParam
);
1334 return MSWOnMDIActivate((long) activate
, (WXHWND
) hWndActivate
, (WXHWND
) hWndDeactivate
);
1336 return MSWOnMDIActivate((BOOL
)wParam
, (HWND
)LOWORD(lParam
),
1337 (HWND
)HIWORD(lParam
));
1342 MSWOnDropFiles(wParam
);
1347 return 0; // MSWOnInitDialog((WXHWND)(HWND)wParam);
1350 case WM_QUERYENDSESSION
:
1352 // Same as WM_CLOSE, but inverted results. Thx Microsoft :-)
1353 return MSWOnClose();
1365 case WM_GETMINMAXINFO
:
1367 MINMAXINFO
*info
= (MINMAXINFO
*)lParam
;
1368 if (m_minSizeX
!= -1)
1369 info
->ptMinTrackSize
.x
= (int)m_minSizeX
;
1370 if (m_minSizeY
!= -1)
1371 info
->ptMinTrackSize
.y
= (int)m_minSizeY
;
1372 if (m_maxSizeX
!= -1)
1373 info
->ptMaxTrackSize
.x
= (int)m_maxSizeX
;
1374 if (m_maxSizeY
!= -1)
1375 info
->ptMaxTrackSize
.y
= (int)m_maxSizeY
;
1376 return MSWDefWindowProc(message
, wParam
, lParam
);
1381 return MSWGetDlgCode();
1387 __ddeUnblock(hWnd, wParam);
1391 case ASYNC_SELECT_MESSAGE:
1392 return ddeWindowProc(hWnd,message,wParam,lParam);
1397 return MSWDefWindowProc(message
, wParam
, lParam
);
1399 return 0; // Success: we processed this command.
1402 // Dialog window proc
1403 LONG APIENTRY _EXPORT
1404 wxDlgProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1409 wxList
*wxWinHandleList
= NULL
;
1410 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
)
1412 wxNode
*node
= wxWinHandleList
->Find((long)hWnd
);
1415 return (wxWindow
*)node
->Data();
1418 void wxAssociateWinWithHandle(HWND hWnd
, wxWindow
*win
)
1420 // adding NULL hWnd is (first) surely a result of an error and
1421 // (secondly) breaks menu command processing
1422 wxCHECK_RET( hWnd
!= NULL
, "attempt to add a NULL hWnd to window list" );
1424 if ( !wxWinHandleList
->Find((long)hWnd
) )
1425 wxWinHandleList
->Append((long)hWnd
, win
);
1428 void wxRemoveHandleAssociation(wxWindow
*win
)
1430 wxWinHandleList
->DeleteObject(win
);
1433 // Default destroyer - override if you destroy it in some other way
1434 // (e.g. with MDI child windows)
1435 void wxWindow::MSWDestroyWindow(void)
1440 wxDebugMsg("wxWindow::MSWDestroyWindow %d\n", handle
);
1442 MSWDetachWindowMenu();
1443 // SetWindowLong(handle, 0, (long)0);
1444 HWND oldHandle
= handle
;
1447 ::DestroyWindow(oldHandle
);
1449 // Menu is destroyed explicitly by wxMDIChild::DestroyWindow,
1450 // or when Windows HWND is deleted if MDI parent or
1455 ::DestroyMenu(m_hMenu);
1462 void wxWindow::MSWCreate(int id
, wxWindow
*parent
, const char *wclass
, wxWindow
*wx_win
, const char *title
,
1463 int x
, int y
, int width
, int height
,
1464 WXDWORD style
, const char *dialog_template
, WXDWORD extendedStyle
)
1466 bool is_dialog
= (dialog_template
!= NULL
);
1467 int x1
= CW_USEDEFAULT
;
1469 int width1
= CW_USEDEFAULT
;
1472 // Find parent's size, if it exists, to set up a possible default
1473 // panel size the size of the parent window
1477 // Was GetWindowRect: JACS 5/5/95
1478 ::GetClientRect((HWND
) parent
->GetHWND(), &parent_rect
);
1480 width1
= parent_rect
.right
- parent_rect
.left
;
1481 height1
= parent_rect
.bottom
- parent_rect
.top
;
1486 if (width
> -1) width1
= width
;
1487 if (height
> -1) height1
= height
;
1489 HWND hParent
= NULL
;
1491 hParent
= (HWND
) parent
->GetHWND();
1497 // MakeProcInstance doesn't seem to be needed in C7. Is it needed for
1498 // other compilers???
1499 // VZ: it's always needed for Win16 and never for Win32
1501 m_hWnd
= (WXHWND
) ::CreateDialog(wxGetInstance(), dialog_template
, hParent
,
1502 (DLGPROC
)wxDlgProc
);
1504 DLGPROC dlgproc
= (DLGPROC
)MakeProcInstance((DLGPROC
)wxWndProc
, wxGetInstance());
1506 m_hWnd
= (WXHWND
) ::CreateDialog(wxGetInstance(), dialog_template
, hParent
,
1511 MessageBox(NULL
, "Can't find dummy dialog template!\nCheck resource include path for finding wx.rc.",
1512 "wxWindows Error", MB_ICONEXCLAMATION
| MB_OK
);
1513 else MoveWindow((HWND
) m_hWnd
, x1
, y1
, width1
, height1
, FALSE
);
1518 if (style
& WS_CHILD
)
1523 m_hWnd
= (WXHWND
) CreateWindowEx(extendedStyle
, wclass
,
1528 // hParent, NULL, wxGetInstance(),
1529 hParent
, (HMENU
)controlId
, wxGetInstance(),
1535 sprintf(buf
, "Can't create window of class %s! Weird.\nPossible Windows 3.x compatibility problem?",
1538 "Fatal wxWindows Error");
1542 wxWinHandleList
->Append((long)m_hWnd
, this);
1545 wxDebugMsg("wxWindow::MSWCreate %d\n", m_hWnd
);
1549 void wxWindow::MSWOnCreate(WXLPCREATESTRUCT
WXUNUSED(cs
))
1553 bool wxWindow::MSWOnClose(void)
1556 wxDebugMsg("wxWindow::MSWOnClose %d\n", handle
);
1561 bool wxWindow::MSWOnDestroy(void)
1564 wxDebugMsg("wxWindow::MSWOnDestroy %d\n", handle
);
1566 // delete our drop target if we've got one
1567 #if USE_DRAG_AND_DROP
1568 if ( m_pDropTarget
!= NULL
) {
1569 m_pDropTarget
->Revoke(m_hWnd
);
1571 delete m_pDropTarget
;
1572 m_pDropTarget
= NULL
;
1579 // Deal with child commands from buttons etc.
1581 bool wxWindow::MSWOnNotify(WXWPARAM wParam
, WXLPARAM lParam
)
1583 #if defined(__WIN95__)
1584 // Find a child window to send the notification to, e.g. a toolbar.
1585 // There's a problem here. NMHDR::hwndFrom doesn't give us the
1586 // handle of the toolbar; it's probably the handle of the tooltip
1587 // window (anyway, it's parent is also the toolbar's parent).
1588 // So, since we don't know which hWnd or wxWindow originated the
1589 // WM_NOTIFY, we'll need to go through all the children of this window
1590 // trying out MSWNotify.
1591 // This won't work now, though, because any number of controls
1592 // could respond to the same generic messages :-(
1594 /* This doesn't work for toolbars, but try for other controls first.
1596 NMHDR
*hdr
= (NMHDR
*)lParam
;
1597 HWND hWnd
= (HWND
)hdr
->hwndFrom
;
1598 wxWindow
*win
= wxFindWinFromHandle((WXHWND
) hWnd
);
1601 return win
->MSWNotify(wParam
, lParam
);
1604 // Rely on MSWNotify to check whether the message
1605 // belongs to the window or not
1606 wxNode
*node
= GetChildren()->First();
1609 wxWindow
*child
= (wxWindow
*)node
->Data();
1610 if ( child
->MSWNotify(wParam
, lParam
) )
1612 node
= node
->Next();
1622 void wxWindow::MSWOnMenuHighlight(WXWORD
WXUNUSED(item
), WXWORD
WXUNUSED(flags
), WXHMENU
WXUNUSED(sysmenu
))
1625 wxDebugMsg("wxWindow::MSWOnMenuHighlight %d\n", handle
);
1629 void wxWindow::MSWOnInitMenuPopup(WXHMENU menu
, int pos
, bool isSystem
)
1633 bool wxWindow::MSWOnActivate(int state
, bool WXUNUSED(minimized
), WXHWND
WXUNUSED(activate
))
1636 wxDebugMsg("wxWindow::MSWOnActivate %d\n", handle
);
1639 wxActivateEvent
event(wxEVT_ACTIVATE
, ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)),
1641 event
.SetEventObject(this);
1642 GetEventHandler()->ProcessEvent(event
);
1646 bool wxWindow::MSWOnSetFocus(WXHWND
WXUNUSED(hwnd
))
1649 wxDebugMsg("wxWindow::MSWOnSetFocus %d\n", m_hWnd
);
1652 if (m_caretEnabled
&& (m_caretWidth
> 0) && (m_caretHeight
> 0))
1654 ::CreateCaret((HWND
) GetHWND(), NULL
, m_caretWidth
, m_caretHeight
);
1656 ::ShowCaret((HWND
) GetHWND());
1659 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
1660 event
.SetEventObject(this);
1661 if (!GetEventHandler()->ProcessEvent(event
))
1666 bool wxWindow::MSWOnKillFocus(WXHWND
WXUNUSED(hwnd
))
1669 wxDebugMsg("wxWindow::MSWOnKillFocus %d\n", m_hWnd
);
1677 wxFocusEvent
event(wxEVT_KILL_FOCUS
, m_windowId
);
1678 event
.SetEventObject(this);
1679 if (!GetEventHandler()->ProcessEvent(event
))
1684 void wxWindow::MSWOnDropFiles(WXWPARAM wParam
)
1687 wxDebugMsg("wxWindow::MSWOnDropFiles %d\n", m_hWnd
);
1690 HANDLE hFilesInfo
= (HANDLE
)wParam
;
1692 DragQueryPoint(hFilesInfo
, (LPPOINT
) &dropPoint
);
1694 // Get the total number of files dropped
1695 WORD gwFilesDropped
= (WORD
)DragQueryFile ((HDROP
)hFilesInfo
,
1700 wxString
*files
= new wxString
[gwFilesDropped
];
1702 for (wIndex
=0; wIndex
< (int)gwFilesDropped
; wIndex
++)
1704 DragQueryFile (hFilesInfo
, wIndex
, (LPSTR
) wxBuffer
, 1000);
1705 files
[wIndex
] = wxBuffer
;
1707 DragFinish (hFilesInfo
);
1709 wxDropFilesEvent
event(wxEVT_DROP_FILES
, gwFilesDropped
, files
);
1710 event
.m_eventObject
= this;
1711 event
.m_pos
.x
= dropPoint
.x
; event
.m_pos
.x
= dropPoint
.y
;
1713 if (!GetEventHandler()->ProcessEvent(event
))
1719 bool wxWindow::MSWOnDrawItem(int id
, WXDRAWITEMSTRUCT
*itemStruct
)
1722 if ( id
== 0 ) { // is it a menu item?
1723 DRAWITEMSTRUCT
*pDrawStruct
= (DRAWITEMSTRUCT
*)itemStruct
;
1724 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pDrawStruct
->itemData
);
1725 wxCHECK( pMenuItem
->IsKindOf(CLASSINFO(wxMenuItem
)), FALSE
);
1727 // prepare to call OnDrawItem()
1729 dc
.SetHDC((WXHDC
)pDrawStruct
->hDC
, FALSE
);
1730 wxRect
rect(pDrawStruct
->rcItem
.left
, pDrawStruct
->rcItem
.top
,
1731 pDrawStruct
->rcItem
.right
- pDrawStruct
->rcItem
.left
,
1732 pDrawStruct
->rcItem
.bottom
- pDrawStruct
->rcItem
.top
);
1733 return pMenuItem
->OnDrawItem(
1735 (wxOwnerDrawn::wxODAction
)pDrawStruct
->itemAction
,
1736 (wxOwnerDrawn::wxODStatus
)pDrawStruct
->itemState
1739 #endif // owner-drawn menus
1741 wxWindow
*item
= FindItem(id
);
1742 #if USE_DYNAMIC_CLASSES
1743 if (item
&& item
->IsKindOf(CLASSINFO(wxControl
)))
1745 return ((wxControl
*)item
)->MSWOnDraw(itemStruct
);
1752 bool wxWindow::MSWOnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*itemStruct
)
1755 if ( id
== 0 ) { // is it a menu item?
1756 MEASUREITEMSTRUCT
*pMeasureStruct
= (MEASUREITEMSTRUCT
*)itemStruct
;
1757 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pMeasureStruct
->itemData
);
1758 wxCHECK( pMenuItem
->IsKindOf(CLASSINFO(wxMenuItem
)), FALSE
);
1760 return pMenuItem
->OnMeasureItem(&pMeasureStruct
->itemWidth
,
1761 &pMeasureStruct
->itemHeight
);
1763 #endif // owner-drawn menus
1765 wxWindow
*item
= FindItem(id
);
1766 #if USE_DYNAMIC_CLASSES
1767 if (item
&& item
->IsKindOf(CLASSINFO(wxControl
)))
1769 return ((wxControl
*)item
)->MSWOnMeasure(itemStruct
);
1776 WXHBRUSH
wxWindow::MSWOnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
1777 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1780 wxDebugMsg("wxWindow::MSWOnCtlColour %d\n", m_hWnd
);
1782 if (nCtlColor
== CTLCOLOR_DLG
)
1784 return OnCtlColor(pDC
, pWnd
, nCtlColor
, message
, wParam
, lParam
);
1787 wxControl
*item
= (wxControl
*)FindItemByHWND(pWnd
, TRUE
);
1789 WXHBRUSH hBrush
= 0;
1792 hBrush
= item
->OnCtlColor(pDC
, pWnd
, nCtlColor
, message
, wParam
, lParam
);
1794 // I think that even for dialogs, we may need to call DefWindowProc (?)
1795 // Or maybe just rely on the usual default behaviour.
1797 hBrush
= (WXHBRUSH
) MSWDefWindowProc(message
, wParam
, lParam
);
1802 // Define for each class of dialog and control
1803 WXHBRUSH
wxWindow::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
1804 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1806 return (WXHBRUSH
) MSWDefWindowProc(message
, wParam
, lParam
);
1809 bool wxWindow::MSWOnColorChange(WXHWND hWnd
, WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1811 wxSysColourChangedEvent event
;
1812 event
.m_eventObject
= this;
1814 // Check if app handles this.
1815 if (GetEventHandler()->ProcessEvent(event
))
1818 // We didn't process it
1822 // Responds to colour changes: passes event on to children.
1823 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1825 wxNode
*node
= GetChildren()->First();
1828 // Only propagate to non-top-level windows
1829 wxWindow
*win
= (wxWindow
*)node
->Data();
1830 if ( win
->GetParent() )
1832 wxSysColourChangedEvent event2
;
1833 event
.m_eventObject
= win
;
1834 win
->GetEventHandler()->ProcessEvent(event2
);
1837 node
= node
->Next();
1841 long wxWindow::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1844 return ::CallWindowProc(CASTWNDPROC (FARPROC
) m_oldWndProc
, (HWND
) GetHWND(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1846 return ::DefWindowProc((HWND
) GetHWND(), nMsg
, wParam
, lParam
);
1849 long wxWindow::Default()
1851 // Ignore 'fake' events (perhaps generated as a result of a separate real event)
1856 wxLogTrace(wxTraceMessages
, "Forwarding %s to DefWindowProc.",
1857 GetMessageName(m_lastMsg
));
1860 return this->MSWDefWindowProc(m_lastMsg
, m_lastWParam
, m_lastLParam
);
1863 bool wxWindow::MSWProcessMessage(WXMSG
* pMsg
)
1865 if ( m_hWnd
!= 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL
) ) {
1866 // intercept dialog navigation keys
1867 MSG
*msg
= (MSG
*)pMsg
;
1868 bool bProcess
= TRUE
;
1869 if ( msg
->message
!= WM_KEYDOWN
)
1872 if ( (HIWORD(msg
->lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
1875 bool bCtrlDown
= (::GetKeyState(VK_CONTROL
) & 0x100) != 0;
1877 // WM_GETDLGCODE: if the control wants it for itself, don't process it
1878 // (except for Ctrl-Tab combination which is always processed)
1880 if ( bProcess
&& !bCtrlDown
) {
1881 lDlgCode
= ::SendMessage(msg
->hwnd
, WM_GETDLGCODE
, 0, 0);
1886 switch ( msg
->wParam
) {
1888 if ( lDlgCode
& DLGC_WANTTAB
)
1891 bForward
= !(::GetKeyState(VK_SHIFT
) & 0x100);
1896 if ( lDlgCode
& DLGC_WANTARROWS
|| bCtrlDown
)
1904 if ( lDlgCode
& DLGC_WANTARROWS
|| bCtrlDown
)
1916 wxNavigationKeyEvent event
;
1917 event
.SetDirection(bForward
);
1918 event
.SetWindowChange(bCtrlDown
);
1919 event
.SetEventObject(this);
1921 if ( GetEventHandler()->ProcessEvent(event
) )
1925 return ::IsDialogMessage((HWND
)GetHWND(), msg
) != 0;
1931 long wxWindow::MSWOnMDIActivate(long WXUNUSED(flag
), WXHWND
WXUNUSED(activate
), WXHWND
WXUNUSED(deactivate
))
1934 wxDebugMsg("wxWindow::MSWOnMDIActivate %d\n", m_hWnd
);
1939 void wxWindow::MSWDetachWindowMenu(void)
1943 int N
= GetMenuItemCount((HMENU
) m_hMenu
);
1945 for (i
= 0; i
< N
; i
++)
1948 int chars
= GetMenuString((HMENU
) m_hMenu
, i
, buf
, 100, MF_BYPOSITION
);
1949 if ((chars
> 0) && (strcmp(buf
, "&Window") == 0))
1951 RemoveMenu((HMENU
) m_hMenu
, i
, MF_BYPOSITION
);
1958 bool wxWindow::MSWOnPaint(void)
1960 wxPaintEvent
event(m_windowId
);
1961 event
.SetEventObject(this);
1962 if (!GetEventHandler()->ProcessEvent(event
))
1967 void wxWindow::MSWOnSize(int w
, int h
, WXUINT
WXUNUSED(flag
))
1973 wxDebugMsg("wxWindow::MSWOnSize %d\n", m_hWnd
);
1980 wxSizeEvent
event(wxSize(w
, h
), m_windowId
);
1981 event
.SetEventObject(this);
1982 if (!GetEventHandler()->ProcessEvent(event
))
1988 void wxWindow::MSWOnWindowPosChanging(void *WXUNUSED(lpPos
))
1993 // Deal with child commands from buttons etc.
1994 bool wxWindow::MSWOnCommand(WXWORD id
, WXWORD cmd
, WXHWND
WXUNUSED(control
))
1997 wxDebugMsg("wxWindow::MSWOnCommand\n");
1999 if (wxCurrentPopupMenu
)
2001 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
2002 wxCurrentPopupMenu
= NULL
;
2003 bool succ
= popupMenu
->MSWCommand(cmd
, id
);
2008 sprintf(buf
, "Looking for item %d...\n", id
);
2012 wxWindow
*item
= FindItem(id
);
2015 bool value
= item
->MSWCommand(cmd
, id
);
2018 wxDebugMsg("MSWCommand succeeded\n");
2020 wxDebugMsg("MSWCommand failed\n");
2027 wxDebugMsg("Could not find item!\n");
2029 wxDebugMsg("Item ids for this panel:\n");
2031 wxNode
*current
= GetChildren()->First();
2034 wxObject
*obj
= (wxObject
*)current
->Data() ;
2035 if (obj
->IsKindOf(CLASSINFO(wxControl
)))
2037 wxControl
*item
= (wxControl
*)current
->Data();
2038 sprintf(buf
, " %d\n", (int)item
->m_windowId
);
2041 current
= current
->Next();
2049 long wxWindow::MSWOnSysCommand(WXWPARAM wParam
, WXLPARAM lParam
)
2055 wxMaximizeEvent
event(m_windowId
);
2056 event
.SetEventObject(this);
2057 if (!GetEventHandler()->ProcessEvent(event
))
2065 wxIconizeEvent
event(m_windowId
);
2066 event
.SetEventObject(this);
2067 if (!GetEventHandler()->ProcessEvent(event
))
2079 void wxWindow::MSWOnLButtonDown(int x
, int y
, WXUINT flags
)
2081 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
2083 event
.m_x
= x
; event
.m_y
= y
;
2084 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2085 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2086 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2087 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2088 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2089 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2090 event
.m_eventObject
= this;
2092 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVENT_TYPE_LEFT_DOWN
;
2094 if (!GetEventHandler()->ProcessEvent(event
))
2098 void wxWindow::MSWOnLButtonUp(int x
, int y
, WXUINT flags
)
2100 wxMouseEvent
event(wxEVT_LEFT_UP
);
2102 event
.m_x
= x
; event
.m_y
= y
;
2103 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2104 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2105 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2106 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2107 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2108 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2109 event
.m_eventObject
= this;
2111 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_LEFT_UP
;
2113 if (!GetEventHandler()->ProcessEvent(event
))
2117 void wxWindow::MSWOnLButtonDClick(int x
, int y
, WXUINT flags
)
2119 wxMouseEvent
event(wxEVT_LEFT_DCLICK
);
2121 event
.m_x
= x
; event
.m_y
= y
;
2122 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2123 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2124 event
.m_leftDown
= ((flags
& MK_LBUTTON
!= 0));
2125 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2126 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2127 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2128 event
.m_eventObject
= this;
2130 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_LEFT_DCLICK
;
2132 if (!GetEventHandler()->ProcessEvent(event
))
2136 void wxWindow::MSWOnMButtonDown(int x
, int y
, WXUINT flags
)
2138 wxMouseEvent
event(wxEVT_MIDDLE_DOWN
);
2140 event
.m_x
= x
; event
.m_y
= y
;
2141 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2142 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2143 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2144 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2145 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2146 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2147 event
.m_eventObject
= this;
2149 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_MIDDLE_DOWN
;
2151 if (!GetEventHandler()->ProcessEvent(event
))
2155 void wxWindow::MSWOnMButtonUp(int x
, int y
, WXUINT flags
)
2157 //wxDebugMsg("MButtonUp\n") ;
2158 wxMouseEvent
event(wxEVT_MIDDLE_UP
);
2160 event
.m_x
= x
; event
.m_y
= y
;
2161 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2162 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2163 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2164 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2165 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2166 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2167 event
.m_eventObject
= this;
2169 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_MIDDLE_UP
;
2171 if (!GetEventHandler()->ProcessEvent(event
))
2175 void wxWindow::MSWOnMButtonDClick(int x
, int y
, WXUINT flags
)
2177 wxMouseEvent
event(wxEVT_MIDDLE_DCLICK
);
2179 event
.m_x
= x
; event
.m_y
= y
;
2180 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2181 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2182 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2183 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2184 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2185 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2186 event
.m_eventObject
= this;
2188 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_MIDDLE_DCLICK
;
2190 if (!GetEventHandler()->ProcessEvent(event
))
2194 void wxWindow::MSWOnRButtonDown(int x
, int y
, WXUINT flags
)
2196 wxMouseEvent
event(wxEVT_RIGHT_DOWN
);
2198 event
.m_x
= x
; event
.m_y
= y
;
2199 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2200 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2201 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2202 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2203 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2204 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2205 event
.m_eventObject
= this;
2207 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_RIGHT_DOWN
;
2209 if (!GetEventHandler()->ProcessEvent(event
))
2213 void wxWindow::MSWOnRButtonUp(int x
, int y
, WXUINT flags
)
2215 wxMouseEvent
event(wxEVT_RIGHT_UP
);
2217 event
.m_x
= x
; event
.m_y
= y
;
2218 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2219 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2220 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2221 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2222 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2223 event
.m_eventObject
= this;
2224 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2226 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_RIGHT_UP
;
2228 if (!GetEventHandler()->ProcessEvent(event
))
2232 void wxWindow::MSWOnRButtonDClick(int x
, int y
, WXUINT flags
)
2234 wxMouseEvent
event(wxEVT_RIGHT_DCLICK
);
2236 event
.m_x
= x
; event
.m_y
= y
;
2237 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2238 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2239 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2240 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2241 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2242 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2243 event
.m_eventObject
= this;
2245 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_RIGHT_DCLICK
;
2247 if (!GetEventHandler()->ProcessEvent(event
))
2251 void wxWindow::MSWOnMouseMove(int x
, int y
, WXUINT flags
)
2253 // 'normal' move event...
2254 // Set cursor, but only if we're not in 'busy' mode
2256 // Trouble with this is that it sets the cursor for controls too :-(
2257 if (m_windowCursor
.Ok() && !wxIsBusy())
2258 ::SetCursor((HCURSOR
) m_windowCursor
.GetHCURSOR());
2260 if (!m_mouseInWindow
)
2262 // Generate an ENTER event
2263 m_mouseInWindow
= TRUE
;
2264 MSWOnMouseEnter(x
, y
, flags
);
2267 wxMouseEvent
event(wxEVT_MOTION
);
2269 event
.m_x
= x
; event
.m_y
= y
;
2270 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2271 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2272 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2273 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2274 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2275 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2276 event
.m_eventObject
= this;
2278 // Window gets a click down message followed by a mouse move
2279 // message even if position isn't changed! We want to discard
2280 // the trailing move event if x and y are the same.
2281 if ((m_lastEvent
== wxEVT_RIGHT_DOWN
|| m_lastEvent
== wxEVT_LEFT_DOWN
||
2282 m_lastEvent
== wxEVT_MIDDLE_DOWN
) &&
2283 (m_lastXPos
== event
.m_x
&& m_lastYPos
== event
.m_y
))
2285 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2286 m_lastEvent
= wxEVT_MOTION
;
2290 m_lastEvent
= wxEVT_MOTION
;
2291 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2293 if (!GetEventHandler()->ProcessEvent(event
))
2297 void wxWindow::MSWOnMouseEnter(int x
, int y
, WXUINT flags
)
2299 wxMouseEvent
event(wxEVT_ENTER_WINDOW
);
2301 event
.m_x
= x
; event
.m_y
= y
;
2302 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2303 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2304 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2305 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2306 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2307 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2308 event
.m_eventObject
= this;
2310 m_lastEvent
= wxEVT_ENTER_WINDOW
;
2311 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2312 // No message - ensure we don't try to call the default behaviour accidentally.
2314 GetEventHandler()->ProcessEvent(event
);
2317 void wxWindow::MSWOnMouseLeave(int x
, int y
, WXUINT flags
)
2319 wxMouseEvent
event(wxEVT_LEAVE_WINDOW
);
2321 event
.m_x
= x
; event
.m_y
= y
;
2322 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2323 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2324 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2325 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2326 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2327 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2328 event
.m_eventObject
= this;
2330 m_lastEvent
= wxEVT_LEAVE_WINDOW
;
2331 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2332 // No message - ensure we don't try to call the default behaviour accidentally.
2334 GetEventHandler()->ProcessEvent(event
);
2337 void wxWindow::MSWOnChar(WXWORD wParam
, WXLPARAM lParam
, bool isASCII
)
2340 bool tempControlDown
= FALSE
;
2343 // If 1 -> 26, translate to CTRL plus a letter.
2345 if ((id
> 0) && (id
< 27))
2366 tempControlDown
= TRUE
;
2372 else if ((id
= wxCharCodeMSWToWX(wParam
)) == 0) {
2373 // it's ASCII and will be processed here only when called from
2374 // WM_CHAR (i.e. when isASCII = TRUE)
2380 wxKeyEvent
event(wxEVT_CHAR
);
2381 event
.m_shiftDown
= (::GetKeyState(VK_SHIFT
)&0x100?TRUE
:FALSE
);
2382 event
.m_controlDown
= (::GetKeyState(VK_CONTROL
)&0x100?TRUE
:FALSE
);
2383 if ((HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
2384 event
.m_altDown
= TRUE
;
2386 event
.m_eventObject
= this;
2387 event
.m_keyCode
= id
;
2388 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2393 GetWindowRect((HWND
) GetHWND(),&rect
) ;
2397 event
.m_x
= pt
.x
; event
.m_y
= pt
.y
;
2399 if (!GetEventHandler()->ProcessEvent(event
))
2404 void wxWindow::MSWOnJoyDown(int joystick
, int x
, int y
, WXUINT flags
)
2408 if (flags
& JOY_BUTTON1CHG
)
2409 change
= wxJOY_BUTTON1
;
2410 if (flags
& JOY_BUTTON2CHG
)
2411 change
= wxJOY_BUTTON2
;
2412 if (flags
& JOY_BUTTON3CHG
)
2413 change
= wxJOY_BUTTON3
;
2414 if (flags
& JOY_BUTTON4CHG
)
2415 change
= wxJOY_BUTTON4
;
2417 if (flags
& JOY_BUTTON1
)
2418 buttons
|= wxJOY_BUTTON1
;
2419 if (flags
& JOY_BUTTON2
)
2420 buttons
|= wxJOY_BUTTON2
;
2421 if (flags
& JOY_BUTTON3
)
2422 buttons
|= wxJOY_BUTTON3
;
2423 if (flags
& JOY_BUTTON4
)
2424 buttons
|= wxJOY_BUTTON4
;
2426 wxJoystickEvent
event(wxEVT_JOY_BUTTON_DOWN
, buttons
, joystick
, change
);
2427 event
.SetPosition(wxPoint(x
, y
));
2428 event
.SetEventObject(this);
2430 GetEventHandler()->ProcessEvent(event
);
2433 void wxWindow::MSWOnJoyUp(int joystick
, int x
, int y
, WXUINT flags
)
2437 if (flags
& JOY_BUTTON1CHG
)
2438 change
= wxJOY_BUTTON1
;
2439 if (flags
& JOY_BUTTON2CHG
)
2440 change
= wxJOY_BUTTON2
;
2441 if (flags
& JOY_BUTTON3CHG
)
2442 change
= wxJOY_BUTTON3
;
2443 if (flags
& JOY_BUTTON4CHG
)
2444 change
= wxJOY_BUTTON4
;
2446 if (flags
& JOY_BUTTON1
)
2447 buttons
|= wxJOY_BUTTON1
;
2448 if (flags
& JOY_BUTTON2
)
2449 buttons
|= wxJOY_BUTTON2
;
2450 if (flags
& JOY_BUTTON3
)
2451 buttons
|= wxJOY_BUTTON3
;
2452 if (flags
& JOY_BUTTON4
)
2453 buttons
|= wxJOY_BUTTON4
;
2455 wxJoystickEvent
event(wxEVT_JOY_BUTTON_UP
, buttons
, joystick
, change
);
2456 event
.SetPosition(wxPoint(x
, y
));
2457 event
.SetEventObject(this);
2459 GetEventHandler()->ProcessEvent(event
);
2462 void wxWindow::MSWOnJoyMove(int joystick
, int x
, int y
, WXUINT flags
)
2465 if (flags
& JOY_BUTTON1
)
2466 buttons
|= wxJOY_BUTTON1
;
2467 if (flags
& JOY_BUTTON2
)
2468 buttons
|= wxJOY_BUTTON2
;
2469 if (flags
& JOY_BUTTON3
)
2470 buttons
|= wxJOY_BUTTON3
;
2471 if (flags
& JOY_BUTTON4
)
2472 buttons
|= wxJOY_BUTTON4
;
2474 wxJoystickEvent
event(wxEVT_JOY_MOVE
, buttons
, joystick
, 0);
2475 event
.SetPosition(wxPoint(x
, y
));
2476 event
.SetEventObject(this);
2478 GetEventHandler()->ProcessEvent(event
);
2481 void wxWindow::MSWOnJoyZMove(int joystick
, int z
, WXUINT flags
)
2484 if (flags
& JOY_BUTTON1
)
2485 buttons
|= wxJOY_BUTTON1
;
2486 if (flags
& JOY_BUTTON2
)
2487 buttons
|= wxJOY_BUTTON2
;
2488 if (flags
& JOY_BUTTON3
)
2489 buttons
|= wxJOY_BUTTON3
;
2490 if (flags
& JOY_BUTTON4
)
2491 buttons
|= wxJOY_BUTTON4
;
2493 wxJoystickEvent
event(wxEVT_JOY_ZMOVE
, buttons
, joystick
, 0);
2494 event
.SetZPosition(z
);
2495 event
.SetEventObject(this);
2497 GetEventHandler()->ProcessEvent(event
);
2500 void wxWindow::MSWOnVScroll(WXWORD wParam
, WXWORD pos
, WXHWND control
)
2504 wxWindow
*child
= wxFindWinFromHandle(control
);
2506 child
->MSWOnVScroll(wParam
, pos
, control
);
2510 wxScrollEvent event
;
2511 event
.SetPosition(pos
);
2512 event
.SetOrientation(wxVERTICAL
);
2513 event
.m_eventObject
= this;
2518 event
.m_eventType
= wxEVT_SCROLL_TOP
;
2522 event
.m_eventType
= wxEVT_SCROLL_BOTTOM
;
2526 event
.m_eventType
= wxEVT_SCROLL_LINEUP
;
2530 event
.m_eventType
= wxEVT_SCROLL_LINEDOWN
;
2534 event
.m_eventType
= wxEVT_SCROLL_PAGEUP
;
2538 event
.m_eventType
= wxEVT_SCROLL_PAGEDOWN
;
2542 case SB_THUMBPOSITION
:
2543 event
.m_eventType
= wxEVT_SCROLL_THUMBTRACK
;
2551 if (!GetEventHandler()->ProcessEvent(event
))
2555 void wxWindow::MSWOnHScroll( WXWORD wParam
, WXWORD pos
, WXHWND control
)
2559 wxWindow
*child
= wxFindWinFromHandle(control
);
2561 child
->MSWOnHScroll(wParam
, pos
, control
);
2565 wxScrollEvent event
;
2566 event
.SetPosition(pos
);
2567 event
.SetOrientation(wxHORIZONTAL
);
2568 event
.m_eventObject
= this;
2573 event
.m_eventType
= wxEVT_SCROLL_TOP
;
2577 event
.m_eventType
= wxEVT_SCROLL_BOTTOM
;
2581 event
.m_eventType
= wxEVT_SCROLL_LINEUP
;
2585 event
.m_eventType
= wxEVT_SCROLL_LINEDOWN
;
2589 event
.m_eventType
= wxEVT_SCROLL_PAGEUP
;
2593 event
.m_eventType
= wxEVT_SCROLL_PAGEDOWN
;
2597 case SB_THUMBPOSITION
:
2598 event
.m_eventType
= wxEVT_SCROLL_THUMBTRACK
;
2605 if (!GetEventHandler()->ProcessEvent(event
))
2609 void wxWindow::MSWOnShow(bool show
, int status
)
2611 wxShowEvent
event(GetId(), show
);
2612 event
.m_eventObject
= this;
2613 GetEventHandler()->ProcessEvent(event
);
2616 bool wxWindow::MSWOnInitDialog(WXHWND
WXUNUSED(hWndFocus
))
2618 wxInitDialogEvent
event(GetId());
2619 event
.m_eventObject
= this;
2620 GetEventHandler()->ProcessEvent(event
);
2624 void wxWindow::InitDialog(void)
2626 wxInitDialogEvent
event(GetId());
2627 event
.SetEventObject( this );
2628 GetEventHandler()->ProcessEvent(event
);
2631 // Default init dialog behaviour is to transfer data to window
2632 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
2634 TransferDataToWindow();
2637 void wxGetCharSize(WXHWND wnd
, int *x
, int *y
,wxFont
*the_font
)
2640 HDC dc
= ::GetDC((HWND
) wnd
);
2646 wxDebugMsg("wxGetCharSize: Selecting HFONT %X\n", fnt
);
2648 // the_font->UseResource();
2649 // the_font->RealizeResource();
2650 if ((fnt
=(HFONT
) the_font
->GetResourceHandle()))
2651 was
= SelectObject(dc
,fnt
) ;
2653 GetTextMetrics(dc
, &tm
);
2654 if (the_font
&& fnt
&& was
)
2657 wxDebugMsg("wxGetCharSize: Selecting old HFONT %X\n", was
);
2659 SelectObject(dc
,was
) ;
2661 ReleaseDC((HWND
)wnd
, dc
);
2662 *x
= tm
.tmAveCharWidth
;
2663 *y
= tm
.tmHeight
+ tm
.tmExternalLeading
;
2666 // the_font->ReleaseResource();
2669 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
2670 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
2671 int wxCharCodeMSWToWX(int keySym
)
2676 case VK_CANCEL
: id
= WXK_CANCEL
; break;
2677 case VK_BACK
: id
= WXK_BACK
; break;
2678 case VK_TAB
: id
= WXK_TAB
; break;
2679 case VK_CLEAR
: id
= WXK_CLEAR
; break;
2680 case VK_RETURN
: id
= WXK_RETURN
; break;
2681 case VK_SHIFT
: id
= WXK_SHIFT
; break;
2682 case VK_CONTROL
: id
= WXK_CONTROL
; break;
2683 case VK_MENU
: id
= WXK_MENU
; break;
2684 case VK_PAUSE
: id
= WXK_PAUSE
; break;
2685 case VK_SPACE
: id
= WXK_SPACE
; break;
2686 case VK_ESCAPE
: id
= WXK_ESCAPE
; break;
2687 case VK_PRIOR
: id
= WXK_PRIOR
; break;
2688 case VK_NEXT
: id
= WXK_NEXT
; break;
2689 case VK_END
: id
= WXK_END
; break;
2690 case VK_HOME
: id
= WXK_HOME
; break;
2691 case VK_LEFT
: id
= WXK_LEFT
; break;
2692 case VK_UP
: id
= WXK_UP
; break;
2693 case VK_RIGHT
: id
= WXK_RIGHT
; break;
2694 case VK_DOWN
: id
= WXK_DOWN
; break;
2695 case VK_SELECT
: id
= WXK_SELECT
; break;
2696 case VK_PRINT
: id
= WXK_PRINT
; break;
2697 case VK_EXECUTE
: id
= WXK_EXECUTE
; break;
2698 case VK_INSERT
: id
= WXK_INSERT
; break;
2699 case VK_DELETE
: id
= WXK_DELETE
; break;
2700 case VK_HELP
: id
= WXK_HELP
; break;
2701 case VK_NUMPAD0
: id
= WXK_NUMPAD0
; break;
2702 case VK_NUMPAD1
: id
= WXK_NUMPAD1
; break;
2703 case VK_NUMPAD2
: id
= WXK_NUMPAD2
; break;
2704 case VK_NUMPAD3
: id
= WXK_NUMPAD3
; break;
2705 case VK_NUMPAD4
: id
= WXK_NUMPAD4
; break;
2706 case VK_NUMPAD5
: id
= WXK_NUMPAD5
; break;
2707 case VK_NUMPAD6
: id
= WXK_NUMPAD6
; break;
2708 case VK_NUMPAD7
: id
= WXK_NUMPAD7
; break;
2709 case VK_NUMPAD8
: id
= WXK_NUMPAD8
; break;
2710 case VK_NUMPAD9
: id
= WXK_NUMPAD9
; break;
2711 case VK_MULTIPLY
: id
= WXK_MULTIPLY
; break;
2712 case VK_ADD
: id
= WXK_ADD
; break;
2713 case VK_SUBTRACT
: id
= WXK_SUBTRACT
; break;
2714 case VK_DECIMAL
: id
= WXK_DECIMAL
; break;
2715 case VK_DIVIDE
: id
= WXK_DIVIDE
; break;
2716 case VK_F1
: id
= WXK_F1
; break;
2717 case VK_F2
: id
= WXK_F2
; break;
2718 case VK_F3
: id
= WXK_F3
; break;
2719 case VK_F4
: id
= WXK_F4
; break;
2720 case VK_F5
: id
= WXK_F5
; break;
2721 case VK_F6
: id
= WXK_F6
; break;
2722 case VK_F7
: id
= WXK_F7
; break;
2723 case VK_F8
: id
= WXK_F8
; break;
2724 case VK_F9
: id
= WXK_F9
; break;
2725 case VK_F10
: id
= WXK_F10
; break;
2726 case VK_F11
: id
= WXK_F11
; break;
2727 case VK_F12
: id
= WXK_F12
; break;
2728 case VK_F13
: id
= WXK_F13
; break;
2729 case VK_F14
: id
= WXK_F14
; break;
2730 case VK_F15
: id
= WXK_F15
; break;
2731 case VK_F16
: id
= WXK_F16
; break;
2732 case VK_F17
: id
= WXK_F17
; break;
2733 case VK_F18
: id
= WXK_F18
; break;
2734 case VK_F19
: id
= WXK_F19
; break;
2735 case VK_F20
: id
= WXK_F20
; break;
2736 case VK_F21
: id
= WXK_F21
; break;
2737 case VK_F22
: id
= WXK_F22
; break;
2738 case VK_F23
: id
= WXK_F23
; break;
2739 case VK_F24
: id
= WXK_F24
; break;
2740 case VK_NUMLOCK
: id
= WXK_NUMLOCK
; break;
2741 case VK_SCROLL
: id
= WXK_SCROLL
; break;
2750 int wxCharCodeWXToMSW(int id
, bool *isVirtual
)
2756 case WXK_CANCEL
: keySym
= VK_CANCEL
; break;
2757 case WXK_CLEAR
: keySym
= VK_CLEAR
; break;
2758 case WXK_SHIFT
: keySym
= VK_SHIFT
; break;
2759 case WXK_CONTROL
: keySym
= VK_CONTROL
; break;
2760 case WXK_MENU
: keySym
= VK_MENU
; break;
2761 case WXK_PAUSE
: keySym
= VK_PAUSE
; break;
2762 case WXK_PRIOR
: keySym
= VK_PRIOR
; break;
2763 case WXK_NEXT
: keySym
= VK_NEXT
; break;
2764 case WXK_END
: keySym
= VK_END
; break;
2765 case WXK_HOME
: keySym
= VK_HOME
; break;
2766 case WXK_LEFT
: keySym
= VK_LEFT
; break;
2767 case WXK_UP
: keySym
= VK_UP
; break;
2768 case WXK_RIGHT
: keySym
= VK_RIGHT
; break;
2769 case WXK_DOWN
: keySym
= VK_DOWN
; break;
2770 case WXK_SELECT
: keySym
= VK_SELECT
; break;
2771 case WXK_PRINT
: keySym
= VK_PRINT
; break;
2772 case WXK_EXECUTE
: keySym
= VK_EXECUTE
; break;
2773 case WXK_INSERT
: keySym
= VK_INSERT
; break;
2774 case WXK_DELETE
: keySym
= VK_DELETE
; break;
2775 case WXK_HELP
: keySym
= VK_HELP
; break;
2776 case WXK_NUMPAD0
: keySym
= VK_NUMPAD0
; break;
2777 case WXK_NUMPAD1
: keySym
= VK_NUMPAD1
; break;
2778 case WXK_NUMPAD2
: keySym
= VK_NUMPAD2
; break;
2779 case WXK_NUMPAD3
: keySym
= VK_NUMPAD3
; break;
2780 case WXK_NUMPAD4
: keySym
= VK_NUMPAD4
; break;
2781 case WXK_NUMPAD5
: keySym
= VK_NUMPAD5
; break;
2782 case WXK_NUMPAD6
: keySym
= VK_NUMPAD6
; break;
2783 case WXK_NUMPAD7
: keySym
= VK_NUMPAD7
; break;
2784 case WXK_NUMPAD8
: keySym
= VK_NUMPAD8
; break;
2785 case WXK_NUMPAD9
: keySym
= VK_NUMPAD9
; break;
2786 case WXK_MULTIPLY
: keySym
= VK_MULTIPLY
; break;
2787 case WXK_ADD
: keySym
= VK_ADD
; break;
2788 case WXK_SUBTRACT
: keySym
= VK_SUBTRACT
; break;
2789 case WXK_DECIMAL
: keySym
= VK_DECIMAL
; break;
2790 case WXK_DIVIDE
: keySym
= VK_DIVIDE
; break;
2791 case WXK_F1
: keySym
= VK_F1
; break;
2792 case WXK_F2
: keySym
= VK_F2
; break;
2793 case WXK_F3
: keySym
= VK_F3
; break;
2794 case WXK_F4
: keySym
= VK_F4
; break;
2795 case WXK_F5
: keySym
= VK_F5
; break;
2796 case WXK_F6
: keySym
= VK_F6
; break;
2797 case WXK_F7
: keySym
= VK_F7
; break;
2798 case WXK_F8
: keySym
= VK_F8
; break;
2799 case WXK_F9
: keySym
= VK_F9
; break;
2800 case WXK_F10
: keySym
= VK_F10
; break;
2801 case WXK_F11
: keySym
= VK_F11
; break;
2802 case WXK_F12
: keySym
= VK_F12
; break;
2803 case WXK_F13
: keySym
= VK_F13
; break;
2804 case WXK_F14
: keySym
= VK_F14
; break;
2805 case WXK_F15
: keySym
= VK_F15
; break;
2806 case WXK_F16
: keySym
= VK_F16
; break;
2807 case WXK_F17
: keySym
= VK_F17
; break;
2808 case WXK_F18
: keySym
= VK_F18
; break;
2809 case WXK_F19
: keySym
= VK_F19
; break;
2810 case WXK_F20
: keySym
= VK_F20
; break;
2811 case WXK_F21
: keySym
= VK_F21
; break;
2812 case WXK_F22
: keySym
= VK_F22
; break;
2813 case WXK_F23
: keySym
= VK_F23
; break;
2814 case WXK_F24
: keySym
= VK_F24
; break;
2815 case WXK_NUMLOCK
: keySym
= VK_NUMLOCK
; break;
2816 case WXK_SCROLL
: keySym
= VK_SCROLL
; break;
2827 // Caret manipulation
2828 void wxWindow::CreateCaret(int w
, int h
)
2832 m_caretEnabled
= TRUE
;
2835 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
2840 void wxWindow::ShowCaret(bool show
)
2845 ::ShowCaret((HWND
) GetHWND());
2847 ::HideCaret((HWND
) GetHWND());
2848 m_caretShown
= show
;
2852 void wxWindow::DestroyCaret(void)
2854 m_caretEnabled
= FALSE
;
2857 void wxWindow::SetCaretPos(int x
, int y
)
2859 ::SetCaretPos(x
, y
);
2862 void wxWindow::GetCaretPos(int *x
, int *y
) const
2865 ::GetCaretPos(&point
);
2871 * Update iterator. Use from within OnPaint.
2874 static RECT gs_UpdateRect
;
2876 wxUpdateIterator::wxUpdateIterator(wxWindow
* wnd
)
2878 current
= 0; //start somewhere...
2879 #if defined(__WIN32__) && !defined(__win32s__)
2880 rlist
= NULL
; //make sure I don't free randomly
2881 int len
= GetRegionData((HRGN
) wnd
->m_updateRgn
,0,NULL
); //Get buffer size
2884 rlist
= (WXRGNDATA
*) (RGNDATA
*)new char[len
];
2885 GetRegionData((HRGN
) wnd
->m_updateRgn
,len
, (RGNDATA
*)rlist
);
2886 rp
= (void *)(RECT
*) ((RGNDATA
*)rlist
)->Buffer
;
2887 rects
= ((RGNDATA
*)rlist
)->rdh
.nCount
;
2892 gs_UpdateRect
.left
= wnd
->m_updateRect
.x
;
2893 gs_UpdateRect
.top
= wnd
->m_updateRect
.y
;
2894 gs_UpdateRect
.right
= wnd
->m_updateRect
.x
+ wnd
->m_updateRect
.width
;
2895 gs_UpdateRect
.bottom
= wnd
->m_updateRect
.y
+ wnd
->m_updateRect
.height
;
2897 rp
= (void *)&gs_UpdateRect
; //Only one available in Win16,32s
2901 wxUpdateIterator::~wxUpdateIterator(void)
2905 if (rlist
) delete (RGNDATA
*) rlist
;
2910 wxUpdateIterator::operator int (void)
2912 if (current
< rects
)
2922 wxUpdateIterator
* wxUpdateIterator::operator ++(int)
2928 void wxUpdateIterator::GetRect(wxRect
*rect
)
2930 RECT
*mswRect
= ((RECT
*)rp
)+current
; //ought to error check this...
2931 rect
->x
= mswRect
->left
;
2932 rect
->y
= mswRect
->top
;
2933 rect
->width
= mswRect
->right
- mswRect
->left
;
2934 rect
->height
= mswRect
->bottom
- mswRect
->top
;
2937 int wxUpdateIterator::GetX()
2939 return ((RECT
*)rp
)[current
].left
;
2942 int wxUpdateIterator::GetY()
2944 return ((RECT
*)rp
)[current
].top
;
2947 int wxUpdateIterator::GetW()
2949 return ((RECT
*)rp
)[current
].right
-GetX();
2952 int wxUpdateIterator::GetH()
2954 return ((RECT
*)rp
)[current
].bottom
-GetY();
2957 wxWindow
*wxGetActiveWindow(void)
2959 HWND hWnd
= GetActiveWindow();
2962 return wxFindWinFromHandle((WXHWND
) hWnd
);
2967 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
2968 // in active frames and dialogs, regardless of where the focus is.
2969 static HHOOK wxTheKeyboardHook
= 0;
2970 static FARPROC wxTheKeyboardHookProc
= 0;
2971 int APIENTRY _EXPORT
2972 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
);
2974 void wxSetKeyboardHook(bool doIt
)
2978 wxTheKeyboardHookProc
= MakeProcInstance((FARPROC
) wxKeyboardHook
, wxGetInstance());
2979 wxTheKeyboardHook
= SetWindowsHookEx(WH_KEYBOARD
, (HOOKPROC
) wxTheKeyboardHookProc
, wxGetInstance(),
2981 GetCurrentThreadId());
2982 // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
2989 UnhookWindowsHookEx(wxTheKeyboardHook
);
2990 FreeProcInstance(wxTheKeyboardHookProc
);
2994 int APIENTRY _EXPORT
2995 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
)
2997 DWORD hiWord
= HIWORD(lParam
);
2998 if (nCode
!= HC_NOREMOVE
&& ((hiWord
& KF_UP
) == 0))
3001 if ((id
= wxCharCodeMSWToWX(wParam
)) != 0)
3003 wxKeyEvent
event(wxEVT_CHAR_HOOK
);
3004 if ((HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
3005 event
.m_altDown
= TRUE
;
3007 event
.m_eventObject
= NULL
;
3008 event
.m_keyCode
= id
;
3009 /* begin Albert's fix for control and shift key 26.5 */
3010 event
.m_shiftDown
= (::GetKeyState(VK_SHIFT
)&0x100?TRUE
:FALSE
);
3011 event
.m_controlDown
= (::GetKeyState(VK_CONTROL
)&0x100?TRUE
:FALSE
);
3012 /* end Albert's fix for control and shift key 26.5 */
3013 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
3015 wxWindow
*win
= wxGetActiveWindow();
3018 if (win
->GetEventHandler()->ProcessEvent(event
))
3023 if ( wxTheApp
&& wxTheApp
->ProcessEvent(event
) )
3028 return (int)CallNextHookEx(wxTheKeyboardHook
, nCode
, wParam
, lParam
);
3031 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int WXUNUSED(incW
), int WXUNUSED(incH
))
3039 void wxWindow::Centre(int direction
)
3041 int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
;
3043 wxWindow
*father
= (wxWindow
*)GetParent();
3047 father
->GetClientSize(&panel_width
, &panel_height
);
3048 GetSize(&width
, &height
);
3049 GetPosition(&x
, &y
);
3054 if (direction
& wxHORIZONTAL
)
3055 new_x
= (int)((panel_width
- width
)/2);
3057 if (direction
& wxVERTICAL
)
3058 new_y
= (int)((panel_height
- height
)/2);
3060 SetSize(new_x
, new_y
, -1, -1);
3065 void wxWindow::OnPaint(void)
3067 PaintSelectionHandles();
3071 void wxWindow::WarpPointer (int x_pos
, int y_pos
)
3073 // Move the pointer to (x_pos,y_pos) coordinates. They are expressed in
3074 // pixel coordinates, relatives to the canvas -- So, we first need to
3075 // substract origin of the window, then convert to screen position
3077 int x
= x_pos
; int y
= y_pos
;
3078 /* Leave this to the app to decide (and/or wxScrolledWindow)
3079 x -= m_xScrollPosition * m_xScrollPixelsPerLine;
3080 y -= m_yScrollPosition * m_yScrollPixelsPerLine;
3083 GetWindowRect ((HWND
) GetHWND(), &rect
);
3088 SetCursorPos (x
, y
);
3091 void wxWindow::MSWDeviceToLogical (float *x
, float *y
) const
3094 // Do we have a SetUserScale in wxWindow too, so we can
3095 // get mouse events scaled?
3099 *x = m_windowDC->DeviceToLogicalX ((int) *x);
3100 *y = m_windowDC->DeviceToLogicalY ((int) *y);
3105 bool wxWindow::MSWOnEraseBkgnd (WXHDC pDC
)
3113 wxEraseEvent
event(m_windowId
, &dc
);
3114 event
.m_eventObject
= this;
3115 if (!GetEventHandler()->ProcessEvent(event
))
3118 dc
.SelectOldObjects(pDC
);
3124 dc
.SelectOldObjects(pDC
);
3127 dc
.SetHDC((WXHDC
) NULL
);
3131 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
3134 ::GetClientRect((HWND
) GetHWND(), &rect
);
3136 HBRUSH hBrush
= ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
3137 int mode
= ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), MM_TEXT
);
3139 // ::GetClipBox((HDC) event.GetDC()->GetHDC(), &rect);
3140 ::FillRect ((HDC
) event
.GetDC()->GetHDC(), &rect
, hBrush
);
3141 ::DeleteObject(hBrush
);
3142 ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), mode
);
3144 // Less efficient version (and doesn't account for scrolling)
3146 GetClientSize(& w, & h);
3147 wxBrush *brush = wxTheBrushList->FindOrCreateBrush(& GetBackgroundColour(), wxSOLID);
3148 event.GetDC()->SetBrush(brush);
3149 event.GetDC()->SetPen(wxTRANSPARENT_PEN);
3151 event.GetDC()->DrawRectangle(0, 0, w+1, h+1);
3155 #if WXWIN_COMPATIBILITY
3156 void wxWindow::SetScrollRange(int orient
, int range
, bool refresh
)
3158 #if defined(__WIN95__)
3162 // Try to adjust the range to cope with page size > 1
3163 // - a Windows API quirk
3164 int pageSize
= GetScrollPage(orient
);
3165 if ( pageSize
> 1 && range
> 0)
3167 range1
+= (pageSize
- 1);
3173 if (orient
== wxHORIZONTAL
) {
3179 info
.cbSize
= sizeof(SCROLLINFO
);
3180 info
.nPage
= pageSize
; // Have to set this, or scrollbar goes awry
3184 info
.fMask
= SIF_RANGE
| SIF_PAGE
;
3186 HWND hWnd
= (HWND
) GetHWND();
3188 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3191 if (orient
== wxHORIZONTAL
)
3196 HWND hWnd
= (HWND
) GetHWND();
3198 ::SetScrollRange(hWnd
, wOrient
, 0, range
, refresh
);
3202 void wxWindow::SetScrollPage(int orient
, int page
, bool refresh
)
3204 #if defined(__WIN95__)
3208 if (orient
== wxHORIZONTAL
) {
3210 m_xThumbSize
= page
;
3213 m_yThumbSize
= page
;
3216 info
.cbSize
= sizeof(SCROLLINFO
);
3219 info
.fMask
= SIF_PAGE
;
3221 HWND hWnd
= (HWND
) GetHWND();
3223 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3225 if (orient
== wxHORIZONTAL
)
3226 m_xThumbSize
= page
;
3228 m_yThumbSize
= page
;
3232 int wxWindow::OldGetScrollRange(int orient
) const
3235 if (orient
== wxHORIZONTAL
)
3240 #if __WATCOMC__ && defined(__WINDOWS_386__)
3241 short minPos
, maxPos
;
3245 HWND hWnd
= (HWND
) GetHWND();
3248 ::GetScrollRange(hWnd
, wOrient
, &minPos
, &maxPos
);
3249 #if defined(__WIN95__)
3250 // Try to adjust the range to cope with page size > 1
3251 // - a Windows API quirk
3252 int pageSize
= GetScrollPage(orient
);
3255 maxPos
-= (pageSize
- 1);
3264 int wxWindow::GetScrollPage(int orient
) const
3266 if (orient
== wxHORIZONTAL
)
3267 return m_xThumbSize
;
3269 return m_yThumbSize
;
3273 int wxWindow::GetScrollPos(int orient
) const
3276 if (orient
== wxHORIZONTAL
)
3280 HWND hWnd
= (HWND
) GetHWND();
3283 return ::GetScrollPos(hWnd
, wOrient
);
3289 // This now returns the whole range, not just the number
3290 // of positions that we can scroll.
3291 int wxWindow::GetScrollRange(int orient
) const
3294 if (orient
== wxHORIZONTAL
)
3299 #if __WATCOMC__ && defined(__WINDOWS_386__)
3300 short minPos
, maxPos
;
3304 HWND hWnd
= (HWND
) GetHWND();
3307 ::GetScrollRange(hWnd
, wOrient
, &minPos
, &maxPos
);
3308 #if defined(__WIN95__)
3309 // Try to adjust the range to cope with page size > 1
3310 // - a Windows API quirk
3311 int pageSize
= GetScrollPage(orient
);
3314 maxPos
-= (pageSize
- 1);
3316 // October 10th: new range concept.
3326 int wxWindow::GetScrollThumb(int orient
) const
3328 if (orient
== wxHORIZONTAL
)
3329 return m_xThumbSize
;
3331 return m_yThumbSize
;
3334 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
3336 #if defined(__WIN95__)
3340 if (orient
== wxHORIZONTAL
) {
3346 info
.cbSize
= sizeof(SCROLLINFO
);
3350 info
.fMask
= SIF_POS
;
3352 HWND hWnd
= (HWND
) GetHWND();
3354 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3357 if (orient
== wxHORIZONTAL
)
3362 HWND hWnd
= (HWND
) GetHWND();
3364 ::SetScrollPos(hWnd
, wOrient
, pos
, refresh
);
3368 // New function that will replace some of the above.
3369 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
3370 int range
, bool refresh
)
3373 SetScrollPage(orient, thumbVisible, FALSE);
3375 int oldRange = range - thumbVisible ;
3376 SetScrollRange(orient, oldRange, FALSE);
3378 SetScrollPos(orient, pos, refresh);
3380 #if defined(__WIN95__)
3381 int oldRange
= range
- thumbVisible
;
3383 int range1
= oldRange
;
3385 // Try to adjust the range to cope with page size > 1
3386 // - a Windows API quirk
3387 int pageSize
= thumbVisible
;
3388 if ( pageSize
> 1 && range
> 0)
3390 range1
+= (pageSize
- 1);
3396 if (orient
== wxHORIZONTAL
) {
3402 info
.cbSize
= sizeof(SCROLLINFO
);
3403 info
.nPage
= pageSize
; // Have to set this, or scrollbar goes awry
3407 info
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
3409 HWND hWnd
= (HWND
) GetHWND();
3411 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3414 if (orient
== wxHORIZONTAL
)
3419 HWND hWnd
= (HWND
) GetHWND();
3422 ::SetScrollRange(hWnd
, wOrient
, 0, range
, FALSE
);
3423 ::SetScrollPos(hWnd
, wOrient
, pos
, refresh
);
3426 if (orient
== wxHORIZONTAL
) {
3427 m_xThumbSize
= thumbVisible
;
3429 m_yThumbSize
= thumbVisible
;
3433 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRectangle
*rect
)
3438 rect2
.left
= rect
->x
;
3439 rect2
.top
= rect
->y
;
3440 rect2
.right
= rect
->x
+ rect
->width
;
3441 rect2
.bottom
= rect
->y
+ rect
->height
;
3445 ::ScrollWindow((HWND
) GetHWND(), dx
, dy
, &rect2
, NULL
);
3447 ::ScrollWindow((HWND
) GetHWND(), dx
, dy
, NULL
, NULL
);
3450 void wxWindow::OnSize(wxSizeEvent
& event
)
3454 if (GetAutoLayout())
3460 void wxWindow::CalcScrolledPosition(int x, int y, int *xx, int *yy) const
3466 void wxWindow::CalcUnscrolledPosition(int x, int y, float *xx, float *yy) const
3473 void wxWindow::SetFont(const wxFont
& font
)
3475 // Decrement the usage count of the old label font
3476 // (we may be able to free it up)
3477 // if (GetFont()->Ok())
3478 // GetFont()->ReleaseResource();
3480 m_windowFont
= font
;
3482 if (!m_windowFont
.Ok())
3485 // m_windowFont.UseResource();
3487 HWND hWnd
= (HWND
) GetHWND();
3490 // m_windowFont.RealizeResource();
3492 if (m_windowFont
.GetResourceHandle())
3493 SendMessage(hWnd
, WM_SETFONT
,
3494 (WPARAM
)m_windowFont
.GetResourceHandle(),TRUE
);
3498 void wxWindow::SubclassWin(WXHWND hWnd
)
3500 wxAssociateWinWithHandle((HWND
)hWnd
, this);
3502 m_oldWndProc
= (WXFARPROC
) GetWindowLong((HWND
) hWnd
, GWL_WNDPROC
);
3503 SetWindowLong((HWND
) hWnd
, GWL_WNDPROC
, (LONG
) wxWndProc
);
3506 void wxWindow::UnsubclassWin(void)
3508 wxRemoveHandleAssociation(this);
3510 // Restore old Window proc
3511 if ((HWND
) GetHWND())
3513 FARPROC farProc
= (FARPROC
) GetWindowLong((HWND
) GetHWND(), GWL_WNDPROC
);
3514 if ((m_oldWndProc
!= 0) && (farProc
!= (FARPROC
) m_oldWndProc
))
3516 SetWindowLong((HWND
) GetHWND(), GWL_WNDPROC
, (LONG
) m_oldWndProc
);
3522 // Make a Windows extended style from the given wxWindows window style
3523 WXDWORD
wxWindow::MakeExtendedStyle(long style
, bool eliminateBorders
)
3525 WXDWORD exStyle
= 0;
3526 if ( style
& wxTRANSPARENT_WINDOW
)
3527 exStyle
|= WS_EX_TRANSPARENT
;
3529 if ( !eliminateBorders
)
3531 if ( style
& wxSUNKEN_BORDER
)
3532 exStyle
|= WS_EX_CLIENTEDGE
;
3533 if ( style
& wxDOUBLE_BORDER
)
3534 exStyle
|= WS_EX_DLGMODALFRAME
;
3535 #if defined(__WIN95__)
3536 if ( style
& wxRAISED_BORDER
)
3537 exStyle
|= WS_EX_WINDOWEDGE
;
3538 if ( style
& wxSTATIC_BORDER
)
3539 exStyle
|= WS_EX_STATICEDGE
;
3545 // Determines whether native 3D effects or CTL3D should be used,
3546 // applying a default border style if required, and returning an extended
3547 // style to pass to CreateWindowEx.
3548 WXDWORD
wxWindow::Determine3DEffects(WXDWORD defaultBorderStyle
, bool *want3D
)
3550 // If matches certain criteria, then assume no 3D effects
3551 // unless specifically requested (dealt with in MakeExtendedStyle)
3552 if ( !GetParent() || !IsKindOf(CLASSINFO(wxControl
)) || (m_windowStyle
& wxNO_BORDER
) )
3555 return MakeExtendedStyle(m_windowStyle
, FALSE
);
3558 // Determine whether we should be using 3D effects or not.
3559 bool nativeBorder
= FALSE
; // by default, we don't want a Win95 effect
3561 // 1) App can specify global 3D effects
3562 *want3D
= wxTheApp
->GetAuto3D();
3564 // 2) If the parent is being drawn with user colours, or simple border specified,
3565 // switch effects off. TODO: replace wxUSER_COLOURS with wxNO_3D
3566 if (GetParent() && (GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
) || (m_windowStyle
& wxSIMPLE_BORDER
))
3569 // 3) Control can override this global setting by defining
3570 // a border style, e.g. wxSUNKEN_BORDER
3571 if (m_windowStyle
& wxSUNKEN_BORDER
)
3574 // 4) If it's a special border, CTL3D can't cope so we want a native border
3575 if ( (m_windowStyle
& wxDOUBLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
3576 (m_windowStyle
& wxSTATIC_BORDER
) )
3579 nativeBorder
= TRUE
;
3582 // 5) If this isn't a Win95 app, and we are using CTL3D, remove border
3583 // effects from extended style
3586 nativeBorder
= FALSE
;
3589 DWORD exStyle
= MakeExtendedStyle(m_windowStyle
, !nativeBorder
);
3591 // If we want 3D, but haven't specified a border here,
3592 // apply the default border style specified.
3593 // TODO what about non-Win95 WIN32? Does it have borders?
3594 #if defined(__WIN95__) && !CTL3D
3595 if (defaultBorderStyle
&& (*want3D
) && ! ((m_windowStyle
& wxDOUBLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
3596 (m_windowStyle
& wxSTATIC_BORDER
) || (m_windowStyle
& wxSIMPLE_BORDER
) ))
3597 exStyle
|= defaultBorderStyle
; // WS_EX_CLIENTEDGE ;
3603 void wxWindow::OnChar(wxKeyEvent
& event
)
3605 if ( event
.KeyCode() == WXK_TAB
) {
3606 // propagate the TABs to the parent - it's up to it to decide what
3608 if ( GetParent() ) {
3609 if ( GetParent()->ProcessEvent(event
) )
3615 int id
= wxCharCodeWXToMSW((int)event
.KeyCode(), &isVirtual
);
3620 if ( !event
.ControlDown() )
3621 (void) MSWDefWindowProc(m_lastMsg
, (WPARAM
) id
, m_lastLParam
);
3624 void wxWindow::OnPaint(wxPaintEvent
& event
)
3629 bool wxWindow::IsEnabled(void) const
3631 return (::IsWindowEnabled((HWND
) GetHWND()) != 0);
3634 // Dialog support: override these and call
3635 // base class members to add functionality
3636 // that can't be done using validators.
3637 // NOTE: these functions assume that controls
3638 // are direct children of this window, not grandchildren
3639 // or other levels of descendant.
3641 // Transfer values to controls. If returns FALSE,
3642 // it's an application error (pops up a dialog)
3643 bool wxWindow::TransferDataToWindow(void)
3645 wxNode
*node
= GetChildren()->First();
3648 wxWindow
*child
= (wxWindow
*)node
->Data();
3649 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */
3650 !child
->GetValidator()->TransferToWindow() )
3652 wxMessageBox("Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
3656 node
= node
->Next();
3661 // Transfer values from controls. If returns FALSE,
3662 // validation failed: don't quit
3663 bool wxWindow::TransferDataFromWindow(void)
3665 wxNode
*node
= GetChildren()->First();
3668 wxWindow
*child
= (wxWindow
*)node
->Data();
3669 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->TransferFromWindow() )
3674 node
= node
->Next();
3679 bool wxWindow::Validate(void)
3681 wxNode
*node
= GetChildren()->First();
3684 wxWindow
*child
= (wxWindow
*)node
->Data();
3685 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
3690 node
= node
->Next();
3695 // Get the window with the focus
3696 wxWindow
*wxWindow::FindFocus(void)
3698 HWND hWnd
= ::GetFocus();
3701 return wxFindWinFromHandle((WXHWND
) hWnd
);
3706 void wxWindow::AddChild(wxWindow
*child
)
3708 GetChildren()->Append(child
);
3709 child
->m_windowParent
= this;
3712 void wxWindow::RemoveChild(wxWindow
*child
)
3715 GetChildren()->DeleteObject(child
);
3716 child
->m_windowParent
= NULL
;
3719 void wxWindow::DestroyChildren(void)
3721 if (GetChildren()) {
3723 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
) {
3725 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
3727 if ( GetChildren()->Member(child
) )
3734 void wxWindow::MakeModal(bool modal
)
3736 // Disable all other windows
3737 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
3739 wxNode
*node
= wxTopLevelWindows
.First();
3742 wxWindow
*win
= (wxWindow
*)node
->Data();
3744 win
->Enable(!modal
);
3746 node
= node
->Next();
3751 // If nothing defined for this, try the parent.
3752 // E.g. we may be a button loaded from a resource, with no callback function
3754 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
3756 if (GetEventHandler()->ProcessEvent(event
) )
3759 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
3762 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
3766 UnsetConstraints(m_constraints
);
3767 delete m_constraints
;
3772 // Make sure other windows know they're part of a 'meaningful relationship'
3773 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
3774 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3775 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
3776 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3777 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
3778 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3779 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
3780 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3781 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
3782 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3783 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
3784 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3785 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
3786 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3787 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
3788 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3792 // This removes any dangling pointers to this window
3793 // in other windows' constraintsInvolvedIn lists.
3794 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
3798 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
3799 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3800 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
3801 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3802 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
3803 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3804 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
3805 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3806 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
3807 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3808 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
3809 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3810 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
3811 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3812 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
3813 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3817 // Back-pointer to other windows we're involved with, so if we delete
3818 // this window, we must delete any constraints we're involved with.
3819 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
3821 if (!m_constraintsInvolvedIn
)
3822 m_constraintsInvolvedIn
= new wxList
;
3823 if (!m_constraintsInvolvedIn
->Member(otherWin
))
3824 m_constraintsInvolvedIn
->Append(otherWin
);
3827 // REMOVE back-pointer to other windows we're involved with.
3828 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
3830 if (m_constraintsInvolvedIn
)
3831 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
3834 // Reset any constraints that mention this window
3835 void wxWindow::DeleteRelatedConstraints(void)
3837 if (m_constraintsInvolvedIn
)
3839 wxNode
*node
= m_constraintsInvolvedIn
->First();
3842 wxWindow
*win
= (wxWindow
*)node
->Data();
3843 wxNode
*next
= node
->Next();
3844 wxLayoutConstraints
*constr
= win
->GetConstraints();
3846 // Reset any constraints involving this window
3849 constr
->left
.ResetIfWin((wxWindow
*)this);
3850 constr
->top
.ResetIfWin((wxWindow
*)this);
3851 constr
->right
.ResetIfWin((wxWindow
*)this);
3852 constr
->bottom
.ResetIfWin((wxWindow
*)this);
3853 constr
->width
.ResetIfWin((wxWindow
*)this);
3854 constr
->height
.ResetIfWin((wxWindow
*)this);
3855 constr
->centreX
.ResetIfWin((wxWindow
*)this);
3856 constr
->centreY
.ResetIfWin((wxWindow
*)this);
3861 delete m_constraintsInvolvedIn
;
3862 m_constraintsInvolvedIn
= NULL
;
3866 void wxWindow::SetSizer(wxSizer
*sizer
)
3868 m_windowSizer
= sizer
;
3870 sizer
->SetSizerParent((wxWindow
*)this);
3877 bool wxWindow::Layout(void)
3879 if (GetConstraints())
3882 GetClientSize(&w
, &h
);
3883 GetConstraints()->width
.SetValue(w
);
3884 GetConstraints()->height
.SetValue(h
);
3887 // If top level (one sizer), evaluate the sizer's constraints.
3891 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
3892 GetSizer()->LayoutPhase1(&noChanges
);
3893 GetSizer()->LayoutPhase2(&noChanges
);
3894 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
3899 // Otherwise, evaluate child constraints
3900 ResetConstraints(); // Mark all constraints as unevaluated
3901 DoPhase(1); // Just one phase need if no sizers involved
3903 SetConstraintSizes(); // Recursively set the real window sizes
3909 // Do a phase of evaluating constraints:
3910 // the default behaviour. wxSizers may do a similar
3911 // thing, but also impose their own 'constraints'
3912 // and order the evaluation differently.
3913 bool wxWindow::LayoutPhase1(int *noChanges
)
3915 wxLayoutConstraints
*constr
= GetConstraints();
3918 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
3924 bool wxWindow::LayoutPhase2(int *noChanges
)
3934 // Do a phase of evaluating child constraints
3935 bool wxWindow::DoPhase(int phase
)
3937 int noIterations
= 0;
3938 int maxIterations
= 500;
3942 while ((noChanges
> 0) && (noIterations
< maxIterations
))
3946 wxNode
*node
= GetChildren()->First();
3949 wxWindow
*child
= (wxWindow
*)node
->Data();
3950 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
3952 wxLayoutConstraints
*constr
= child
->GetConstraints();
3955 if (succeeded
.Member(child
))
3960 int tempNoChanges
= 0;
3961 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
3962 noChanges
+= tempNoChanges
;
3965 succeeded
.Append(child
);
3970 node
= node
->Next();
3977 void wxWindow::ResetConstraints(void)
3979 wxLayoutConstraints
*constr
= GetConstraints();
3982 constr
->left
.SetDone(FALSE
);
3983 constr
->top
.SetDone(FALSE
);
3984 constr
->right
.SetDone(FALSE
);
3985 constr
->bottom
.SetDone(FALSE
);
3986 constr
->width
.SetDone(FALSE
);
3987 constr
->height
.SetDone(FALSE
);
3988 constr
->centreX
.SetDone(FALSE
);
3989 constr
->centreY
.SetDone(FALSE
);
3991 wxNode
*node
= GetChildren()->First();
3994 wxWindow
*win
= (wxWindow
*)node
->Data();
3995 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
3996 win
->ResetConstraints();
3997 node
= node
->Next();
4001 // Need to distinguish between setting the 'fake' size for
4002 // windows and sizers, and setting the real values.
4003 void wxWindow::SetConstraintSizes(bool recurse
)
4005 wxLayoutConstraints
*constr
= GetConstraints();
4006 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
4007 constr
->width
.GetDone() && constr
->height
.GetDone())
4009 int x
= constr
->left
.GetValue();
4010 int y
= constr
->top
.GetValue();
4011 int w
= constr
->width
.GetValue();
4012 int h
= constr
->height
.GetValue();
4014 // If we don't want to resize this window, just move it...
4015 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
4016 (constr
->height
.GetRelationship() != wxAsIs
))
4018 // Calls Layout() recursively. AAAGH. How can we stop that.
4019 // Simply take Layout() out of non-top level OnSizes.
4020 SizerSetSize(x
, y
, w
, h
);
4029 char *windowClass
= this->GetClassInfo()->GetClassName();
4032 if (GetName() == "")
4033 winName
= "unnamed";
4035 winName
= GetName();
4036 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
4037 if (!constr
->left
.GetDone())
4038 wxDebugMsg(" unsatisfied 'left' constraint.\n");
4039 if (!constr
->right
.GetDone())
4040 wxDebugMsg(" unsatisfied 'right' constraint.\n");
4041 if (!constr
->width
.GetDone())
4042 wxDebugMsg(" unsatisfied 'width' constraint.\n");
4043 if (!constr
->height
.GetDone())
4044 wxDebugMsg(" unsatisfied 'height' constraint.\n");
4045 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
4050 wxNode
*node
= GetChildren()->First();
4053 wxWindow
*win
= (wxWindow
*)node
->Data();
4054 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
4055 win
->SetConstraintSizes();
4056 node
= node
->Next();
4061 // This assumes that all sizers are 'on' the same
4062 // window, i.e. the parent of this window.
4063 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
4065 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
4066 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
4070 m_sizerParent
->GetPosition(&xp
, &yp
);
4071 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
4076 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
4080 TransformSizerToActual(&xx
, &yy
);
4081 SetSize(xx
, yy
, w
, h
);
4084 void wxWindow::SizerMove(int x
, int y
)
4088 TransformSizerToActual(&xx
, &yy
);
4092 // Only set the size/position of the constraint (if any)
4093 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
4095 wxLayoutConstraints
*constr
= GetConstraints();
4100 constr
->left
.SetValue(x
);
4101 constr
->left
.SetDone(TRUE
);
4105 constr
->top
.SetValue(y
);
4106 constr
->top
.SetDone(TRUE
);
4110 constr
->width
.SetValue(w
);
4111 constr
->width
.SetDone(TRUE
);
4115 constr
->height
.SetValue(h
);
4116 constr
->height
.SetDone(TRUE
);
4121 void wxWindow::MoveConstraint(int x
, int y
)
4123 wxLayoutConstraints
*constr
= GetConstraints();
4128 constr
->left
.SetValue(x
);
4129 constr
->left
.SetDone(TRUE
);
4133 constr
->top
.SetValue(y
);
4134 constr
->top
.SetDone(TRUE
);
4139 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
4141 wxLayoutConstraints
*constr
= GetConstraints();
4144 *w
= constr
->width
.GetValue();
4145 *h
= constr
->height
.GetValue();
4151 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
4153 wxLayoutConstraints
*constr
= GetConstraints();
4156 *w
= constr
->width
.GetValue();
4157 *h
= constr
->height
.GetValue();
4160 GetClientSize(w
, h
);
4163 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
4165 wxLayoutConstraints
*constr
= GetConstraints();
4168 *x
= constr
->left
.GetValue();
4169 *y
= constr
->top
.GetValue();
4175 bool wxWindow::Close(bool force
)
4177 // Let's generalise it to work the same for any window.
4179 if (!IsKindOf(CLASSINFO(wxDialog)) && !IsKindOf(CLASSINFO(wxFrame)))
4186 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
4187 event
.SetEventObject(this);
4188 event
.SetForce(force
);
4190 return GetEventHandler()->ProcessEvent(event
);
4193 if ( !force && event.GetVeto() )
4198 if (!wxPendingDelete.Member(this))
4199 wxPendingDelete.Append(this);
4205 wxObject
* wxWindow::GetChild(int number
) const
4207 // Return a pointer to the Nth object in the Panel
4210 wxNode
*node
= GetChildren()->First();
4213 node
= node
->Next() ;
4216 wxObject
*obj
= (wxObject
*)node
->Data();
4223 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
4225 /* This is obsolete now; if we wish to intercept listbox double-clicks,
4226 * we explicitly intercept the wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
4229 if (initiatingItem->IsKindOf(CLASSINFO(wxListBox)))
4231 wxListBox *lbox = (wxListBox *)initiatingItem;
4232 wxCommandEvent event(wxEVT_COMMAND_LEFT_DCLICK);
4233 event.m_commandInt = -1;
4234 if ((lbox->GetWindowStyleFlag() & wxLB_MULTIPLE) == 0)
4236 event.m_commandString = copystring(lbox->GetStringSelection());
4237 event.m_commandInt = lbox->GetSelection();
4238 event.m_clientData = lbox->wxListBox::GetClientData(event.m_commandInt);
4240 event.m_eventObject = lbox;
4242 lbox->ProcessCommand(event);
4244 if (event.m_commandString)
4245 delete[] event.m_commandString;
4249 wxButton *but = GetDefaultItem();
4252 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
4253 event.SetEventObject(but);
4254 but->Command(event);
4259 void wxWindow::Clear(void)
4261 wxClientDC
dc(this);
4262 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
4263 dc
.SetBackground(brush
);
4267 // Fits the panel around the items
4268 void wxWindow::Fit(void)
4272 wxNode
*node
= GetChildren()->First();
4275 wxWindow
*win
= (wxWindow
*)node
->Data();
4277 win
->GetPosition(&wx
, &wy
);
4278 win
->GetSize(&ww
, &wh
);
4279 if ( wx
+ ww
> maxX
)
4281 if ( wy
+ wh
> maxY
)
4284 node
= node
->Next();
4286 SetClientSize(maxX
+ 5, maxY
+ 5);
4289 void wxWindow::SetValidator(const wxValidator
& validator
)
4291 if ( m_windowValidator
)
4292 delete m_windowValidator
;
4293 m_windowValidator
= validator
.Clone();
4295 if ( m_windowValidator
)
4296 m_windowValidator
->SetWindow(this) ;
4299 // Find a window by id or name
4300 wxWindow
*wxWindow::FindWindow(long id
)
4305 wxNode
*node
= GetChildren()->First();
4308 wxWindow
*child
= (wxWindow
*)node
->Data();
4309 wxWindow
*found
= child
->FindWindow(id
);
4312 node
= node
->Next();
4317 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
4319 if ( GetName() == name
)
4322 wxNode
*node
= GetChildren()->First();
4325 wxWindow
*child
= (wxWindow
*)node
->Data();
4326 wxWindow
*found
= child
->FindWindow(name
);
4329 node
= node
->Next();
4335 // Default input behaviour for a scrolling canvas should be to scroll
4336 // according to the cursor keys pressed
4337 void wxWindow::OnChar(wxKeyEvent& event)
4349 GetScrollUnitsPerPage(&x_page, &y_page);
4351 GetVirtualSize(&v_width,&v_height);
4353 ViewStart(&start_x, &start_y);
4356 y_pages = (int)(v_height/vert_units) - y_page;
4364 switch (event.keyCode)
4371 if (start_y - y_page > 0)
4372 Scroll(start_x, start_y - y_page);
4382 if ((y_page > 0) && (start_y <= y_pages-y-1))
4384 if (y_pages + y < start_y + y_page)
4385 Scroll(start_x, y_pages + y);
4387 Scroll(start_x, start_y + y_page);
4394 if ((y_page > 0) && (start_y >= 1))
4395 Scroll(start_x, start_y - 1);
4401 if ((y_page > 0) && (start_y <= y_pages-y-1))
4404 Scroll(start_x, start_y + 1);
4410 if ((x_page > 0) && (start_x >= 1))
4411 Scroll(start_x - 1, start_y);
4417 Scroll(start_x + 1, start_y);
4428 Scroll(start_x, y_pages+y);
4436 // Setup background and foreground colours correctly
4437 void wxWindow::SetupColours(void)
4440 SetBackgroundColour(GetParent()->GetBackgroundColour());
4443 // Do Update UI processing for child controls
4445 // TODO: should this be implemented for the child window rather
4446 // than the parent? Then you can override it e.g. for wxCheckBox
4447 // to do the Right Thing rather than having to assume a fixed number
4448 // of control classes.
4450 void wxWindow::UpdateWindowUI(void)
4452 wxWindowID id
= GetId();
4455 wxUpdateUIEvent
event(id
);
4456 event
.m_eventObject
= this;
4458 if (this->GetEventHandler()->ProcessEvent(event
))
4460 if (event
.GetSetEnabled())
4461 this->Enable(event
.GetEnabled());
4463 if (event
.GetSetText() && this->IsKindOf(CLASSINFO(wxControl
)))
4464 ((wxControl
*)this)->SetLabel(event
.GetText());
4466 if (this->IsKindOf(CLASSINFO(wxCheckBox
)))
4468 if (event
.GetSetChecked())
4469 ((wxCheckBox
*) this)->SetValue(event
.GetChecked());
4471 else if (this->IsKindOf(CLASSINFO(wxRadioButton
)))
4473 if (event
.GetSetChecked())
4474 ((wxRadioButton
*) this)->SetValue(event
.GetChecked());
4481 void wxWindow::OnIdle(wxIdleEvent
& event
)
4483 // Check if we need to send a LEAVE event
4484 if (m_mouseInWindow
)
4487 ::GetCursorPos(&pt
);
4488 if (::WindowFromPoint(pt
) != (HWND
) GetHWND())
4490 // Generate a LEAVE event
4491 m_mouseInWindow
= FALSE
;
4492 MSWOnMouseLeave(pt
.x
, pt
.y
, 0);
4498 // Raise the window to the top of the Z order
4499 void wxWindow::Raise(void)
4501 ::BringWindowToTop((HWND
) GetHWND());
4504 // Lower the window to the bottom of the Z order
4505 void wxWindow::Lower(void)
4507 ::SetWindowPos((HWND
) GetHWND(), HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
4510 long wxWindow::MSWGetDlgCode()
4512 // default: just forward to def window proc (the msg has no parameters)
4513 return MSWDefWindowProc(WM_GETDLGCODE
, 0, 0);
4516 bool wxWindow::AcceptsFocus() const
4518 return IsShown() && IsEnabled();
4522 static const char *GetMessageName(int message
)
4524 switch ( message
) {
4525 case 0x0000: return "WM_NULL";
4526 case 0x0001: return "WM_CREATE";
4527 case 0x0002: return "WM_DESTROY";
4528 case 0x0003: return "WM_MOVE";
4529 case 0x0005: return "WM_SIZE";
4530 case 0x0006: return "WM_ACTIVATE";
4531 case 0x0007: return "WM_SETFOCUS";
4532 case 0x0008: return "WM_KILLFOCUS";
4533 case 0x000A: return "WM_ENABLE";
4534 case 0x000B: return "WM_SETREDRAW";
4535 case 0x000C: return "WM_SETTEXT";
4536 case 0x000D: return "WM_GETTEXT";
4537 case 0x000E: return "WM_GETTEXTLENGTH";
4538 case 0x000F: return "WM_PAINT";
4539 case 0x0010: return "WM_CLOSE";
4540 case 0x0011: return "WM_QUERYENDSESSION";
4541 case 0x0012: return "WM_QUIT";
4542 case 0x0013: return "WM_QUERYOPEN";
4543 case 0x0014: return "WM_ERASEBKGND";
4544 case 0x0015: return "WM_SYSCOLORCHANGE";
4545 case 0x0016: return "WM_ENDSESSION";
4546 case 0x0017: return "WM_SYSTEMERROR";
4547 case 0x0018: return "WM_SHOWWINDOW";
4548 case 0x0019: return "WM_CTLCOLOR";
4549 case 0x001A: return "WM_WININICHANGE";
4550 case 0x001B: return "WM_DEVMODECHANGE";
4551 case 0x001C: return "WM_ACTIVATEAPP";
4552 case 0x001D: return "WM_FONTCHANGE";
4553 case 0x001E: return "WM_TIMECHANGE";
4554 case 0x001F: return "WM_CANCELMODE";
4555 case 0x0020: return "WM_SETCURSOR";
4556 case 0x0021: return "WM_MOUSEACTIVATE";
4557 case 0x0022: return "WM_CHILDACTIVATE";
4558 case 0x0023: return "WM_QUEUESYNC";
4559 case 0x0024: return "WM_GETMINMAXINFO";
4560 case 0x0026: return "WM_PAINTICON";
4561 case 0x0027: return "WM_ICONERASEBKGND";
4562 case 0x0028: return "WM_NEXTDLGCTL";
4563 case 0x002A: return "WM_SPOOLERSTATUS";
4564 case 0x002B: return "WM_DRAWITEM";
4565 case 0x002C: return "WM_MEASUREITEM";
4566 case 0x002D: return "WM_DELETEITEM";
4567 case 0x002E: return "WM_VKEYTOITEM";
4568 case 0x002F: return "WM_CHARTOITEM";
4569 case 0x0030: return "WM_SETFONT";
4570 case 0x0031: return "WM_GETFONT";
4571 case 0x0037: return "WM_QUERYDRAGICON";
4572 case 0x0039: return "WM_COMPAREITEM";
4573 case 0x0041: return "WM_COMPACTING";
4574 case 0x0044: return "WM_COMMNOTIFY";
4575 case 0x0046: return "WM_WINDOWPOSCHANGING";
4576 case 0x0047: return "WM_WINDOWPOSCHANGED";
4577 case 0x0048: return "WM_POWER";
4578 case 0x0081: return "WM_NCCREATE";
4579 case 0x0082: return "WM_NCDESTROY";
4580 case 0x0083: return "WM_NCCALCSIZE";
4581 case 0x0084: return "WM_NCHITTEST";
4582 case 0x0085: return "WM_NCPAINT";
4583 case 0x0086: return "WM_NCACTIVATE";
4584 case 0x0087: return "WM_GETDLGCODE";
4585 case 0x00A0: return "WM_NCMOUSEMOVE";
4586 case 0x00A1: return "WM_NCLBUTTONDOWN";
4587 case 0x00A2: return "WM_NCLBUTTONUP";
4588 case 0x00A3: return "WM_NCLBUTTONDBLCLK";
4589 case 0x00A4: return "WM_NCRBUTTONDOWN";
4590 case 0x00A5: return "WM_NCRBUTTONUP";
4591 case 0x00A6: return "WM_NCRBUTTONDBLCLK";
4592 case 0x00A7: return "WM_NCMBUTTONDOWN";
4593 case 0x00A8: return "WM_NCMBUTTONUP";
4594 case 0x00A9: return "WM_NCMBUTTONDBLCLK";
4595 case 0x0100: return "WM_KEYDOWN";
4596 case 0x0101: return "WM_KEYUP";
4597 case 0x0102: return "WM_CHAR";
4598 case 0x0103: return "WM_DEADCHAR";
4599 case 0x0104: return "WM_SYSKEYDOWN";
4600 case 0x0105: return "WM_SYSKEYUP";
4601 case 0x0106: return "WM_SYSCHAR";
4602 case 0x0107: return "WM_SYSDEADCHAR";
4603 case 0x0108: return "WM_KEYLAST";
4604 case 0x0110: return "WM_INITDIALOG";
4605 case 0x0111: return "WM_COMMAND";
4606 case 0x0112: return "WM_SYSCOMMAND";
4607 case 0x0113: return "WM_TIMER";
4608 case 0x0114: return "WM_HSCROLL";
4609 case 0x0115: return "WM_VSCROLL";
4610 case 0x0116: return "WM_INITMENU";
4611 case 0x0117: return "WM_INITMENUPOPUP";
4612 case 0x011F: return "WM_MENUSELECT";
4613 case 0x0120: return "WM_MENUCHAR";
4614 case 0x0121: return "WM_ENTERIDLE";
4615 case 0x0200: return "WM_MOUSEMOVE";
4616 case 0x0201: return "WM_LBUTTONDOWN";
4617 case 0x0202: return "WM_LBUTTONUP";
4618 case 0x0203: return "WM_LBUTTONDBLCLK";
4619 case 0x0204: return "WM_RBUTTONDOWN";
4620 case 0x0205: return "WM_RBUTTONUP";
4621 case 0x0206: return "WM_RBUTTONDBLCLK";
4622 case 0x0207: return "WM_MBUTTONDOWN";
4623 case 0x0208: return "WM_MBUTTONUP";
4624 case 0x0209: return "WM_MBUTTONDBLCLK";
4625 case 0x0210: return "WM_PARENTNOTIFY";
4626 case 0x0220: return "WM_MDICREATE";
4627 case 0x0221: return "WM_MDIDESTROY";
4628 case 0x0222: return "WM_MDIACTIVATE";
4629 case 0x0223: return "WM_MDIRESTORE";
4630 case 0x0224: return "WM_MDINEXT";
4631 case 0x0225: return "WM_MDIMAXIMIZE";
4632 case 0x0226: return "WM_MDITILE";
4633 case 0x0227: return "WM_MDICASCADE";
4634 case 0x0228: return "WM_MDIICONARRANGE";
4635 case 0x0229: return "WM_MDIGETACTIVE";
4636 case 0x0230: return "WM_MDISETMENU";
4637 case 0x0233: return "WM_DROPFILES";
4638 case 0x0300: return "WM_CUT";
4639 case 0x0301: return "WM_COPY";
4640 case 0x0302: return "WM_PASTE";
4641 case 0x0303: return "WM_CLEAR";
4642 case 0x0304: return "WM_UNDO";
4643 case 0x0305: return "WM_RENDERFORMAT";
4644 case 0x0306: return "WM_RENDERALLFORMATS";
4645 case 0x0307: return "WM_DESTROYCLIPBOARD";
4646 case 0x0308: return "WM_DRAWCLIPBOARD";
4647 case 0x0309: return "WM_PAINTCLIPBOARD";
4648 case 0x030A: return "WM_VSCROLLCLIPBOARD";
4649 case 0x030B: return "WM_SIZECLIPBOARD";
4650 case 0x030C: return "WM_ASKCBFORMATNAME";
4651 case 0x030D: return "WM_CHANGECBCHAIN";
4652 case 0x030E: return "WM_HSCROLLCLIPBOARD";
4653 case 0x030F: return "WM_QUERYNEWPALETTE";
4654 case 0x0310: return "WM_PALETTEISCHANGING";
4655 case 0x0311: return "WM_PALETTECHANGED";
4657 static char s_szBuf
[128];
4658 sprintf(s_szBuf
, "<unknown message = %d>", message
);