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_ERASE_BACKGROUND(wxWindow::OnEraseBackground
)
102 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
103 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
104 EVT_IDLE(wxWindow::OnIdle
)
109 // Find an item given the MS Windows id
110 wxWindow
*wxWindow::FindItem(int id
) const
114 wxNode
*current
= GetChildren()->First();
117 wxWindow
*childWin
= (wxWindow
*)current
->Data();
119 wxWindow
*wnd
= childWin
->FindItem(id
) ;
123 if (childWin
->IsKindOf(CLASSINFO(wxControl
)))
125 wxControl
*item
= (wxControl
*)childWin
;
126 if (item
->m_windowId
== id
)
130 // In case it's a 'virtual' control (e.g. radiobox)
131 if (item
->GetSubcontrols().Member((wxObject
*)id
))
135 current
= current
->Next();
140 // Find an item given the MS Windows handle
141 wxWindow
*wxWindow::FindItemByHWND(WXHWND hWnd
, bool controlOnly
) const
145 wxNode
*current
= GetChildren()->First();
148 wxObject
*obj
= (wxObject
*)current
->Data() ;
149 // Do a recursive search.
150 wxWindow
*parent
= (wxWindow
*)obj
;
151 wxWindow
*wnd
= parent
->FindItemByHWND(hWnd
) ;
155 if ((!controlOnly
) || obj
->IsKindOf(CLASSINFO(wxControl
)))
157 wxWindow
*item
= (wxWindow
*)current
->Data();
158 if ((HWND
)(item
->GetHWND()) == (HWND
) hWnd
)
162 if ( item
->ContainsHWND(hWnd
) )
166 current
= current
->Next();
171 // Default command handler
172 bool wxWindow::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
177 bool wxWindow::MSWNotify(WXWPARAM
WXUNUSED(wParam
), WXLPARAM
WXUNUSED(lParam
))
182 void wxWindow::PreDelete(WXHDC
WXUNUSED(dc
))
186 WXHWND
wxWindow::GetHWND(void) const
188 return (WXHWND
) m_hWnd
;
191 void wxWindow::SetHWND(WXHWND hWnd
)
197 wxWindow::wxWindow(void)
203 m_windowParent
= NULL
;
204 m_windowEventHandler
= this;
206 m_windowCursor
= *wxSTANDARD_CURSOR
;
207 m_children
= new wxList
;
208 m_doubleClickAllowed
= 0 ;
209 m_winCaptured
= FALSE
;
210 m_constraints
= NULL
;
211 m_constraintsInvolvedIn
= NULL
;
212 m_windowSizer
= NULL
;
213 m_sizerParent
= NULL
;
214 m_autoLayout
= FALSE
;
215 m_windowValidator
= NULL
;
220 m_caretWidth
= 0; m_caretHeight
= 0;
221 m_caretEnabled
= FALSE
;
222 m_caretShown
= FALSE
;
230 m_isBeingDeleted
= FALSE
;
237 m_defaultItem
= NULL
;
239 wxSystemSettings settings
;
241 m_backgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_WINDOW
) ; ;
242 m_foregroundColour
= *wxBLACK
;
243 m_defaultForegroundColour
= *wxBLACK
;
244 m_defaultBackgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
247 wxColour(GetRValue(GetSysColor(COLOR_WINDOW)),
248 GetGValue(GetSysColor(COLOR_BTNFACE)), GetBValue(GetSysColor(COLOR_BTNFACE)));
255 m_acceleratorTable
= 0;
260 m_backgroundTransparent
= FALSE
;
262 m_lastXPos
= (float)-1.0;
263 m_lastYPos
= (float)-1.0;
267 #if USE_DRAG_AND_DROP
268 m_pDropTarget
= NULL
;
273 wxWindow::~wxWindow(void)
275 m_isBeingDeleted
= TRUE
;
277 // JACS - if behaviour is odd, restore this
278 // to the start of ~wxWindow. Vadim has changed
279 // it to nearer the end. Unsure of side-effects
280 // e.g. when deleting associated global data.
281 // Restore old Window proc, if required
284 // Have to delete constraints/sizer FIRST otherwise
285 // sizers may try to look at deleted windows as they
286 // delete themselves.
288 DeleteRelatedConstraints();
291 // This removes any dangling pointers to this window
292 // in other windows' constraintsInvolvedIn lists.
293 UnsetConstraints(m_constraints
);
294 delete m_constraints
;
295 m_constraints
= NULL
;
299 delete m_windowSizer
;
300 m_windowSizer
= NULL
;
302 // If this is a child of a sizer, remove self from parent
304 m_sizerParent
->RemoveChild((wxWindow
*)this);
308 MSWDetachWindowMenu();
310 // TODO for backward compatibility
315 HWND hWnd
= (HWND
) GetHWND();
316 HDC dc
= ::GetDC(hWnd
);
317 m_windowDC
->SelectOldObjects (dc
);
324 m_windowParent
->RemoveChild(this);
329 ::DestroyWindow((HWND
)m_hWnd
);
331 wxRemoveHandleAssociation(this);
336 GlobalFree((HGLOBAL
) m_globalHandle
);
344 // Just in case the window has been Closed, but
345 // we're then deleting immediately: don't leave
346 // dangling pointers.
347 wxPendingDelete
.DeleteObject(this);
349 // Just in case we've loaded a top-level window via
350 // wxWindow::LoadNativeDialog but we weren't a dialog
352 wxTopLevelWindows
.DeleteObject(this);
354 // if (GetFont() && GetFont()->Ok())
355 // GetFont()->ReleaseResource();
357 if ( m_windowValidator
)
358 delete m_windowValidator
;
360 // Restore old Window proc, if required
361 // and remove hWnd <-> wxWindow association
365 // Destroy the window (delayed, if a managed window)
366 bool wxWindow::Destroy(void)
372 extern char wxCanvasClassName
[];
375 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
379 const wxString
& name
)
382 m_isBeingDeleted
= FALSE
;
386 m_windowParent
= NULL
;
387 m_windowEventHandler
= this;
388 // m_windowFont = NULL;
389 // We don't wish internal (potentially transient) fonts to be found
391 // wxTheFontList->RemoveFont(& m_windowFont);
393 m_windowCursor
= *wxSTANDARD_CURSOR
;
394 m_doubleClickAllowed
= 0 ;
395 m_winCaptured
= FALSE
;
396 m_constraints
= NULL
;
397 m_constraintsInvolvedIn
= NULL
;
398 m_windowSizer
= NULL
;
399 m_sizerParent
= NULL
;
400 m_autoLayout
= FALSE
;
401 m_windowValidator
= NULL
;
402 #if USE_DRAG_AND_DROP
403 m_pDropTarget
= NULL
;
409 m_caretWidth
= 0; m_caretHeight
= 0;
410 m_caretEnabled
= FALSE
;
411 m_caretShown
= FALSE
;
424 m_defaultItem
= NULL
;
425 m_windowParent
= NULL
;
426 // m_windowDC = NULL;
427 m_mouseInWindow
= FALSE
;
431 if (parent
) parent
->AddChild(this);
437 m_acceleratorTable
= 0;
442 m_backgroundTransparent
= FALSE
;
444 m_lastXPos
= (float)-1.0;
445 m_lastYPos
= (float)-1.0;
452 m_windowId
= (int)NewControlId();
461 wxSystemSettings settings
;
463 m_backgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_WINDOW
) ; ;
464 m_foregroundColour
= *wxBLACK
;
465 m_defaultForegroundColour
= *wxBLACK
;
466 m_defaultBackgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
468 m_defaultBackgroundColour = wxColour(GetRValue(GetSysColor(COLOR_BTNFACE)),
469 GetGValue(GetSysColor(COLOR_BTNFACE)), GetBValue(GetSysColor(COLOR_BTNFACE)));
472 m_windowStyle
= style
;
475 if (style
& wxBORDER
)
476 msflags
|= WS_BORDER
;
477 if (style
& wxTHICK_FRAME
)
478 msflags
|= WS_THICKFRAME
;
480 msflags
|= WS_CHILD
| WS_VISIBLE
;
481 if (style
& wxCLIP_CHILDREN
)
482 msflags
|= WS_CLIPCHILDREN
;
485 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
) ;
487 // Even with extended styles, need to combine with WS_BORDER
488 // for them to look right.
489 if (want3D
|| (m_windowStyle
& wxSIMPLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
490 (m_windowStyle
& wxSUNKEN_BORDER
) || (m_windowStyle
& wxDOUBLE_BORDER
))
491 msflags
|= WS_BORDER
;
493 m_mouseInWindow
= FALSE
;
496 m_windowId
= (int)NewControlId();
500 MSWCreate(m_windowId
, (wxWindow
*)parent
, wxCanvasClassName
, this, NULL
, x
, y
, width
, height
, msflags
,
506 void wxWindow::SetFocus(void)
508 HWND hWnd
= (HWND
) GetHWND();
513 void wxWindow::Enable(bool enable
)
515 m_winEnabled
= enable
;
516 HWND hWnd
= (HWND
) GetHWND();
518 ::EnableWindow(hWnd
, (BOOL
)enable
);
521 void wxWindow::CaptureMouse(void)
523 HWND hWnd
= (HWND
) GetHWND();
524 if (hWnd
&& !m_winCaptured
)
527 m_winCaptured
= TRUE
;
531 void wxWindow::ReleaseMouse(void)
536 m_winCaptured
= FALSE
;
540 // Push/pop event handler (i.e. allow a chain of event handlers
542 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
544 handler
->SetNextHandler(GetEventHandler());
545 SetEventHandler(handler
);
548 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
550 if ( GetEventHandler() )
552 wxEvtHandler
*handlerA
= GetEventHandler();
553 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
554 handlerA
->SetNextHandler(NULL
);
555 SetEventHandler(handlerB
);
568 #if USE_DRAG_AND_DROP
570 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
572 if ( m_pDropTarget
!= 0 ) {
573 m_pDropTarget
->Revoke(m_hWnd
);
574 delete m_pDropTarget
;
577 m_pDropTarget
= pDropTarget
;
578 if ( m_pDropTarget
!= 0 )
579 m_pDropTarget
->Register(m_hWnd
);
584 //old style file-manager drag&drop support
585 // I think we should retain the old-style
586 // DragAcceptFiles in parallel with SetDropTarget.
588 void wxWindow::DragAcceptFiles(bool accept
)
590 HWND hWnd
= (HWND
) GetHWND();
592 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
596 void wxWindow::GetSize(int *x
, int *y
) const
598 HWND hWnd
= (HWND
) GetHWND();
600 GetWindowRect(hWnd
, &rect
);
601 *x
= rect
.right
- rect
.left
;
602 *y
= rect
.bottom
- rect
.top
;
605 void wxWindow::GetPosition(int *x
, int *y
) const
607 HWND hWnd
= (HWND
) GetHWND();
610 hParentWnd
= (HWND
) GetParent()->GetHWND();
613 GetWindowRect(hWnd
, &rect
);
615 // Since we now have the absolute screen coords,
616 // if there's a parent we must subtract its top left corner
622 ::ScreenToClient(hParentWnd
, &point
);
625 // We may be faking the client origin.
626 // So a window that's really at (0, 30) may appear
627 // (to wxWin apps) to be at (0, 0).
630 wxPoint
pt(GetParent()->GetClientAreaOrigin());
638 void wxWindow::ScreenToClient(int *x
, int *y
) const
640 HWND hWnd
= (HWND
) GetHWND();
644 ::ScreenToClient(hWnd
, &pt
);
646 // We may be faking the client origin.
647 // So a window that's really at (0, 30) may appear
648 // (to wxWin apps) to be at (0, 0).
651 wxPoint
pt1(GetParent()->GetClientAreaOrigin());
659 void wxWindow::ClientToScreen(int *x
, int *y
) const
661 HWND hWnd
= (HWND
) GetHWND();
666 // We may be faking the client origin.
667 // So a window that's really at (0, 30) may appear
668 // (to wxWin apps) to be at (0, 0).
671 wxPoint
pt1(GetParent()->GetClientAreaOrigin());
676 ::ClientToScreen(hWnd
, &pt
);
682 void wxWindow::SetCursor(const wxCursor
& cursor
)
684 m_windowCursor
= cursor
;
685 if (m_windowCursor
.Ok())
687 HWND hWnd
= (HWND
) GetHWND();
689 // Change the cursor NOW if we're within the correct window
691 ::GetCursorPos(&point
);
694 ::GetWindowRect(hWnd
, &rect
);
696 if (::PtInRect(&rect
, point
) && !wxIsBusy())
697 ::SetCursor((HCURSOR
) m_windowCursor
.GetHCURSOR());
700 // This will cause big reentrancy problems if wxFlushEvents is implemented.
702 // return old_cursor;
706 // Get size *available for subwindows* i.e. excluding menu bar etc.
707 void wxWindow::GetClientSize(int *x
, int *y
) const
709 HWND hWnd
= (HWND
) GetHWND();
711 GetClientRect(hWnd
, &rect
);
716 void wxWindow::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
718 int currentX
, currentY
;
719 GetPosition(¤tX
, ¤tY
);
720 int actualWidth
= width
;
721 int actualHeight
= height
;
724 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
726 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
729 AdjustForParentClientOrigin(actualX
, actualY
, sizeFlags
);
731 int currentW
,currentH
;
732 GetSize(¤tW
, ¤tH
);
734 actualWidth
= currentW
;
736 actualHeight
= currentH
;
738 HWND hWnd
= (HWND
) GetHWND();
740 MoveWindow(hWnd
, actualX
, actualY
, actualWidth
, actualHeight
, (BOOL
)TRUE
);
743 void wxWindow::SetClientSize(int width
, int height
)
745 wxWindow
*parent
= GetParent();
746 HWND hWnd
= (HWND
) GetHWND();
747 HWND hParentWnd
= (HWND
) (HWND
) parent
->GetHWND();
750 GetClientRect(hWnd
, &rect
);
753 GetWindowRect(hWnd
, &rect2
);
755 // Find the difference between the entire window (title bar and all)
756 // and the client area; add this to the new client size to move the
758 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
759 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
761 // If there's a parent, must subtract the parent's top left corner
762 // since MoveWindow moves relative to the parent
765 point
.x
= rect2
.left
;
769 ::ScreenToClient(hParentWnd
, &point
);
772 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
774 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
775 event
.SetEventObject(this);
776 GetEventHandler()->ProcessEvent(event
);
779 // For implementation purposes - sometimes decorations make the client area
781 wxPoint
wxWindow::GetClientAreaOrigin() const
783 return wxPoint(0, 0);
786 // Makes an adjustment to the window position (for example, a frame that has
787 // a toolbar that it manages itself).
788 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
790 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
792 wxPoint
pt(GetParent()->GetClientAreaOrigin());
793 x
+= pt
.x
; y
+= pt
.y
;
797 bool wxWindow::Show(bool show
)
799 HWND hWnd
= (HWND
) GetHWND();
805 ShowWindow(hWnd
, (BOOL
)cshow
);
808 BringWindowToTop(hWnd
);
809 // Next line causes a crash on NT, apparently.
810 // UpdateWindow(hWnd); // Should this be here or will it cause inefficiency?
815 bool wxWindow::IsShown(void) const
817 return (::IsWindowVisible((HWND
) GetHWND()) != 0);
820 int wxWindow::GetCharHeight(void) const
822 TEXTMETRIC lpTextMetric
;
823 HWND hWnd
= (HWND
) GetHWND();
824 HDC dc
= ::GetDC(hWnd
);
826 GetTextMetrics(dc
, &lpTextMetric
);
827 ::ReleaseDC(hWnd
, dc
);
829 return lpTextMetric
.tmHeight
;
832 int wxWindow::GetCharWidth(void) const
834 TEXTMETRIC lpTextMetric
;
835 HWND hWnd
= (HWND
) GetHWND();
836 HDC dc
= ::GetDC(hWnd
);
838 GetTextMetrics(dc
, &lpTextMetric
);
839 ::ReleaseDC(hWnd
, dc
);
841 return lpTextMetric
.tmAveCharWidth
;
844 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
845 int *descent
, int *externalLeading
, const wxFont
*theFont
, bool) const
847 wxFont
*fontToUse
= (wxFont
*)theFont
;
849 fontToUse
= (wxFont
*) & m_windowFont
;
851 HWND hWnd
= (HWND
) GetHWND();
852 HDC dc
= ::GetDC(hWnd
);
856 if (fontToUse
&& fontToUse
->Ok())
858 if ((fnt
=(HFONT
) fontToUse
->GetResourceHandle()))
859 was
= (HFONT
) SelectObject(dc
,fnt
) ;
864 GetTextExtentPoint(dc
, (const char *)string
, (int)string
.Length(), &sizeRect
);
865 GetTextMetrics(dc
, &tm
);
867 if (fontToUse
&& fnt
&& was
)
868 SelectObject(dc
,was
) ;
874 if (descent
) *descent
= tm
.tmDescent
;
875 if (externalLeading
) *externalLeading
= tm
.tmExternalLeading
;
878 // fontToUse->ReleaseResource();
881 void wxWindow::Refresh(bool eraseBack
, const wxRectangle
*rect
)
883 HWND hWnd
= (HWND
) GetHWND();
889 mswRect
.left
= rect
->x
;
890 mswRect
.top
= rect
->y
;
891 mswRect
.right
= rect
->x
+ rect
->width
;
892 mswRect
.bottom
= rect
->y
+ rect
->height
;
894 ::InvalidateRect(hWnd
, &mswRect
, eraseBack
);
897 ::InvalidateRect(hWnd
, NULL
, eraseBack
);
901 // Hook for new window just as it's being created,
902 // when the window isn't yet associated with the handle
903 wxWindow
*wxWndHook
= NULL
;
906 LRESULT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
908 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
910 if (!wnd
&& wxWndHook
)
912 wxAssociateWinWithHandle(hWnd
, wxWndHook
);
915 wnd
->m_hWnd
= (WXHWND
) hWnd
;
918 wxDebugMsg("hWnd = %d, m_hWnd = %d, msg = %d\n", hWnd
, m_hWnd
, message
);
920 // Stop right here if we don't have a valid handle
921 // in our wxWnd object.
922 if (wnd
&& !wnd
->m_hWnd
) {
923 // wxDebugMsg("Warning: could not find a valid handle, wx_win.cc/wxWndProc.\n");
924 wnd
->m_hWnd
= (WXHWND
) hWnd
;
925 long res
= wnd
->MSWDefWindowProc(message
, wParam
, lParam
);
931 wnd
->m_lastMsg
= message
;
932 wnd
->m_lastWParam
= wParam
;
933 wnd
->m_lastLParam
= lParam
;
936 return wnd
->MSWWindowProc(message
, wParam
, lParam
);
938 return DefWindowProc( hWnd
, message
, wParam
, lParam
);
941 // Should probably have a test for 'genuine' NT
942 #if defined(__WIN32__)
943 #define DIMENSION_TYPE short
945 #define DIMENSION_TYPE int
948 // Main Windows 3 window proc
949 long wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
952 wxLogTrace(wxTraceMessages
, "Processing %s", GetMessageName(message
));
955 HWND hWnd
= (HWND
)m_hWnd
;
962 WORD state
= LOWORD(wParam
);
963 WORD minimized
= HIWORD(wParam
);
964 HWND hwnd
= (HWND
)lParam
;
966 WORD state
= (WORD
)wParam
;
967 WORD minimized
= LOWORD(lParam
);
968 HWND hwnd
= (HWND
)HIWORD(lParam
);
970 MSWOnActivate(state
, (minimized
!= 0), (WXHWND
) hwnd
);
976 HWND hwnd
= (HWND
)wParam
;
977 // return OnSetFocus(hwnd);
979 if (MSWOnSetFocus((WXHWND
) hwnd
))
981 else return MSWDefWindowProc(message
, wParam
, lParam
);
986 HWND hwnd
= (HWND
)lParam
;
987 // return OnKillFocus(hwnd);
988 if (MSWOnKillFocus((WXHWND
) hwnd
))
991 return MSWDefWindowProc(message
, wParam
, lParam
);
996 MSWOnCreate((WXLPCREATESTRUCT
) (LPCREATESTRUCT
)lParam
);
1002 MSWOnShow((wParam
!= 0), (int) lParam
);
1009 else return MSWDefWindowProc(message
, wParam
, lParam
);
1012 case WM_QUERYDRAGICON
:
1015 if ((hIcon
= (HICON
) MSWOnQueryDragIcon()))
1017 else return MSWDefWindowProc(message
, wParam
, lParam
);
1023 int width
= LOWORD(lParam
);
1024 int height
= HIWORD(lParam
);
1025 MSWOnSize(width
, height
, wParam
);
1029 case WM_WINDOWPOSCHANGING
:
1031 WINDOWPOS
*pos
= (WINDOWPOS
*)lParam
;
1032 MSWOnWindowPosChanging((void *)pos
);
1036 case WM_RBUTTONDOWN
:
1038 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1039 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1040 MSWOnRButtonDown(x
, y
, wParam
);
1045 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1046 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1047 MSWOnRButtonUp(x
, y
, wParam
);
1050 case WM_RBUTTONDBLCLK
:
1052 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1053 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1054 MSWOnRButtonDClick(x
, y
, wParam
);
1057 case WM_MBUTTONDOWN
:
1059 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1060 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1061 MSWOnMButtonDown(x
, y
, wParam
);
1066 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1067 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1068 MSWOnMButtonUp(x
, y
, wParam
);
1071 case WM_MBUTTONDBLCLK
:
1073 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1074 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1075 MSWOnMButtonDClick(x
, y
, wParam
);
1078 case WM_LBUTTONDOWN
:
1080 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1081 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1082 MSWOnLButtonDown(x
, y
, wParam
);
1087 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1088 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1089 MSWOnLButtonUp(x
, y
, wParam
);
1092 case WM_LBUTTONDBLCLK
:
1094 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1095 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1096 MSWOnLButtonDClick(x
, y
, wParam
);
1101 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1102 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1103 MSWOnMouseMove(x
, y
, wParam
);
1106 case MM_JOY1BUTTONDOWN
:
1108 int x
= LOWORD(lParam
);
1109 int y
= HIWORD(lParam
);
1110 MSWOnJoyDown(wxJOYSTICK1
, x
, y
, wParam
);
1113 case MM_JOY2BUTTONDOWN
:
1115 int x
= LOWORD(lParam
);
1116 int y
= HIWORD(lParam
);
1117 MSWOnJoyDown(wxJOYSTICK2
, x
, y
, wParam
);
1120 case MM_JOY1BUTTONUP
:
1122 int x
= LOWORD(lParam
);
1123 int y
= HIWORD(lParam
);
1124 MSWOnJoyUp(wxJOYSTICK1
, x
, y
, wParam
);
1127 case MM_JOY2BUTTONUP
:
1129 int x
= LOWORD(lParam
);
1130 int y
= HIWORD(lParam
);
1131 MSWOnJoyUp(wxJOYSTICK2
, x
, y
, wParam
);
1136 int x
= LOWORD(lParam
);
1137 int y
= HIWORD(lParam
);
1138 MSWOnJoyMove(wxJOYSTICK1
, x
, y
, wParam
);
1143 int x
= LOWORD(lParam
);
1144 int y
= HIWORD(lParam
);
1145 MSWOnJoyMove(wxJOYSTICK2
, x
, y
, wParam
);
1150 int z
= LOWORD(lParam
);
1151 MSWOnJoyZMove(wxJOYSTICK1
, z
, wParam
);
1156 int z
= LOWORD(lParam
);
1157 MSWOnJoyZMove(wxJOYSTICK2
, z
, wParam
);
1164 else return MSWDefWindowProc(message
, wParam
, lParam
);
1169 return MSWOnSysCommand(wParam
, lParam
);
1175 WORD id
= LOWORD(wParam
);
1176 HWND hwnd
= (HWND
)lParam
;
1177 WORD cmd
= HIWORD(wParam
);
1179 WORD id
= (WORD
)wParam
;
1180 HWND hwnd
= (HWND
)LOWORD(lParam
) ;
1181 WORD cmd
= HIWORD(lParam
);
1183 if (!MSWOnCommand(id
, cmd
, (WXHWND
) hwnd
))
1184 return MSWDefWindowProc(message
, wParam
, lParam
);
1187 #if defined(__WIN95__)
1190 if (!MSWOnNotify(wParam
, lParam
))
1191 return MSWDefWindowProc(message
, wParam
, lParam
);
1198 WORD flags
= HIWORD(wParam
);
1199 HMENU sysmenu
= (HMENU
)lParam
;
1201 WORD flags
= LOWORD(lParam
);
1202 HMENU sysmenu
= (HMENU
)HIWORD(lParam
);
1204 MSWOnMenuHighlight((WORD
)wParam
, flags
, (WXHMENU
) sysmenu
);
1207 case WM_INITMENUPOPUP
:
1209 MSWOnInitMenuPopup((WXHMENU
) (HMENU
)wParam
, (int)LOWORD(lParam
), (HIWORD(lParam
) != 0));
1214 return MSWOnDrawItem((int)wParam
, (WXDRAWITEMSTRUCT
*)lParam
);
1217 case WM_MEASUREITEM
:
1219 return MSWOnMeasureItem((int)wParam
, (WXMEASUREITEMSTRUCT
*)lParam
);
1224 // we consider these message "not interesting"
1225 if ( wParam
== VK_SHIFT
|| wParam
== VK_CONTROL
)
1228 // Avoid duplicate messages to OnChar
1229 if ( (wParam
!= VK_ESCAPE
) && (wParam
!= VK_SPACE
) &&
1230 (wParam
!= VK_RETURN
) && (wParam
!= VK_BACK
) &&
1231 (wParam
!= VK_TAB
) )
1233 MSWOnChar((WORD
)wParam
, lParam
);
1234 if ( ::GetKeyState(VK_CONTROL
) & 0x100 )
1237 else if ( ::GetKeyState(VK_CONTROL
) & 0x100 )
1238 MSWOnChar((WORD
)wParam
, lParam
);
1246 case WM_CHAR
: // Always an ASCII character
1248 MSWOnChar((WORD
)wParam
, lParam
, TRUE
);
1255 WORD code
= LOWORD(wParam
);
1256 WORD pos
= HIWORD(wParam
);
1257 HWND control
= (HWND
)lParam
;
1259 WORD code
= (WORD
)wParam
;
1260 WORD pos
= LOWORD(lParam
);
1261 HWND control
= (HWND
)HIWORD(lParam
);
1263 MSWOnHScroll(code
, pos
, (WXHWND
) control
);
1269 WORD code
= LOWORD(wParam
);
1270 WORD pos
= HIWORD(wParam
);
1271 HWND control
= (HWND
)lParam
;
1273 WORD code
= (WORD
)wParam
;
1274 WORD pos
= LOWORD(lParam
);
1275 HWND control
= (HWND
)HIWORD(lParam
);
1277 MSWOnVScroll(code
, pos
, (WXHWND
) control
);
1281 case WM_CTLCOLORBTN
:
1283 int nCtlColor
= CTLCOLOR_BTN
;
1284 HWND control
= (HWND
)lParam
;
1285 HDC pDC
= (HDC
)wParam
;
1286 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1287 message
, wParam
, lParam
);
1290 case WM_CTLCOLORDLG
:
1292 int nCtlColor
= CTLCOLOR_DLG
;
1293 HWND control
= (HWND
)lParam
;
1294 HDC pDC
= (HDC
)wParam
;
1295 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1296 message
, wParam
, lParam
);\
1299 case WM_CTLCOLORLISTBOX
:
1301 int nCtlColor
= CTLCOLOR_LISTBOX
;
1302 HWND control
= (HWND
)lParam
;
1303 HDC pDC
= (HDC
)wParam
;
1304 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1305 message
, wParam
, lParam
);
1308 case WM_CTLCOLORMSGBOX
:
1310 int nCtlColor
= CTLCOLOR_MSGBOX
;
1311 HWND control
= (HWND
)lParam
;
1312 HDC pDC
= (HDC
)wParam
;
1313 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1314 message
, wParam
, lParam
);
1317 case WM_CTLCOLORSCROLLBAR
:
1319 int nCtlColor
= CTLCOLOR_SCROLLBAR
;
1320 HWND control
= (HWND
)lParam
;
1321 HDC pDC
= (HDC
)wParam
;
1322 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1323 message
, wParam
, lParam
);
1326 case WM_CTLCOLORSTATIC
:
1328 int nCtlColor
= CTLCOLOR_STATIC
;
1329 HWND control
= (HWND
)lParam
;
1330 HDC pDC
= (HDC
)wParam
;
1331 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1332 message
, wParam
, lParam
);
1335 case WM_CTLCOLOREDIT
:
1337 int nCtlColor
= CTLCOLOR_EDIT
;
1338 HWND control
= (HWND
)lParam
;
1339 HDC pDC
= (HDC
)wParam
;
1340 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1341 message
, wParam
, lParam
);
1347 HWND control
= (HWND
)LOWORD(lParam
);
1348 int nCtlColor
= (int)HIWORD(lParam
);
1349 HDC pDC
= (HDC
)wParam
;
1350 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1351 message
, wParam
, lParam
);
1355 case WM_SYSCOLORCHANGE
:
1357 // Return value of 0 means, we processed it.
1358 if (MSWOnColorChange((WXHWND
) hWnd
, message
, wParam
, lParam
) == 0)
1361 return MSWDefWindowProc(message
, wParam
, lParam
);
1366 // Prevents flicker when dragging
1367 if (IsIconic(hWnd
)) return 1;
1371 if (!MSWOnEraseBkgnd((WXHDC
) (HDC
)wParam
))
1372 return 0; // Default(); MSWDefWindowProc(message, wParam, lParam );
1376 case WM_MDIACTIVATE
:
1379 HWND hWndActivate
= GET_WM_MDIACTIVATE_HWNDACTIVATE(wParam
,lParam
);
1380 HWND hWndDeactivate
= GET_WM_MDIACTIVATE_HWNDDEACT(wParam
,lParam
);
1381 BOOL activate
= GET_WM_MDIACTIVATE_FACTIVATE(hWnd
,wParam
,lParam
);
1382 return MSWOnMDIActivate((long) activate
, (WXHWND
) hWndActivate
, (WXHWND
) hWndDeactivate
);
1384 return MSWOnMDIActivate((BOOL
)wParam
, (HWND
)LOWORD(lParam
),
1385 (HWND
)HIWORD(lParam
));
1390 MSWOnDropFiles(wParam
);
1395 return 0; // MSWOnInitDialog((WXHWND)(HWND)wParam);
1398 case WM_QUERYENDSESSION
:
1400 // Same as WM_CLOSE, but inverted results. Thx Microsoft :-)
1401 return MSWOnClose();
1413 case WM_GETMINMAXINFO
:
1415 MINMAXINFO
*info
= (MINMAXINFO
*)lParam
;
1416 if (m_minSizeX
!= -1)
1417 info
->ptMinTrackSize
.x
= (int)m_minSizeX
;
1418 if (m_minSizeY
!= -1)
1419 info
->ptMinTrackSize
.y
= (int)m_minSizeY
;
1420 if (m_maxSizeX
!= -1)
1421 info
->ptMaxTrackSize
.x
= (int)m_maxSizeX
;
1422 if (m_maxSizeY
!= -1)
1423 info
->ptMaxTrackSize
.y
= (int)m_maxSizeY
;
1424 return MSWDefWindowProc(message
, wParam
, lParam
);
1429 return MSWGetDlgCode();
1435 __ddeUnblock(hWnd, wParam);
1439 case ASYNC_SELECT_MESSAGE:
1440 return ddeWindowProc(hWnd,message,wParam,lParam);
1445 return MSWDefWindowProc(message
, wParam
, lParam
);
1447 return 0; // Success: we processed this command.
1450 // Dialog window proc
1451 LONG APIENTRY _EXPORT
1452 wxDlgProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1457 wxList
*wxWinHandleList
= NULL
;
1458 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
)
1460 wxNode
*node
= wxWinHandleList
->Find((long)hWnd
);
1463 return (wxWindow
*)node
->Data();
1466 void wxAssociateWinWithHandle(HWND hWnd
, wxWindow
*win
)
1468 // adding NULL hWnd is (first) surely a result of an error and
1469 // (secondly) breaks menu command processing
1470 wxCHECK_RET( hWnd
!= NULL
, "attempt to add a NULL hWnd to window list" );
1472 if ( !wxWinHandleList
->Find((long)hWnd
) )
1473 wxWinHandleList
->Append((long)hWnd
, win
);
1476 void wxRemoveHandleAssociation(wxWindow
*win
)
1478 wxWinHandleList
->DeleteObject(win
);
1481 // Default destroyer - override if you destroy it in some other way
1482 // (e.g. with MDI child windows)
1483 void wxWindow::MSWDestroyWindow(void)
1488 wxDebugMsg("wxWindow::MSWDestroyWindow %d\n", handle
);
1490 MSWDetachWindowMenu();
1491 // SetWindowLong(handle, 0, (long)0);
1492 HWND oldHandle
= handle
;
1495 ::DestroyWindow(oldHandle
);
1497 // Menu is destroyed explicitly by wxMDIChild::DestroyWindow,
1498 // or when Windows HWND is deleted if MDI parent or
1503 ::DestroyMenu(m_hMenu);
1510 void wxWindow::MSWCreate(int id
, wxWindow
*parent
, const char *wclass
, wxWindow
*wx_win
, const char *title
,
1511 int x
, int y
, int width
, int height
,
1512 WXDWORD style
, const char *dialog_template
, WXDWORD extendedStyle
)
1514 bool is_dialog
= (dialog_template
!= NULL
);
1515 int x1
= CW_USEDEFAULT
;
1517 int width1
= CW_USEDEFAULT
;
1520 // Find parent's size, if it exists, to set up a possible default
1521 // panel size the size of the parent window
1525 // Was GetWindowRect: JACS 5/5/95
1526 ::GetClientRect((HWND
) parent
->GetHWND(), &parent_rect
);
1528 width1
= parent_rect
.right
- parent_rect
.left
;
1529 height1
= parent_rect
.bottom
- parent_rect
.top
;
1534 if (width
> -1) width1
= width
;
1535 if (height
> -1) height1
= height
;
1537 HWND hParent
= NULL
;
1539 hParent
= (HWND
) parent
->GetHWND();
1545 // MakeProcInstance doesn't seem to be needed in C7. Is it needed for
1546 // other compilers???
1547 // VZ: it's always needed for Win16 and never for Win32
1549 m_hWnd
= (WXHWND
) ::CreateDialog(wxGetInstance(), dialog_template
, hParent
,
1550 (DLGPROC
)wxDlgProc
);
1552 DLGPROC dlgproc
= (DLGPROC
)MakeProcInstance((DLGPROC
)wxWndProc
, wxGetInstance());
1554 m_hWnd
= (WXHWND
) ::CreateDialog(wxGetInstance(), dialog_template
, hParent
,
1559 MessageBox(NULL
, "Can't find dummy dialog template!\nCheck resource include path for finding wx.rc.",
1560 "wxWindows Error", MB_ICONEXCLAMATION
| MB_OK
);
1561 else MoveWindow((HWND
) m_hWnd
, x1
, y1
, width1
, height1
, FALSE
);
1566 if (style
& WS_CHILD
)
1571 m_hWnd
= (WXHWND
) CreateWindowEx(extendedStyle
, wclass
,
1576 // hParent, NULL, wxGetInstance(),
1577 hParent
, (HMENU
)controlId
, wxGetInstance(),
1583 sprintf(buf
, "Can't create window of class %s! Weird.\nPossible Windows 3.x compatibility problem?",
1586 "Fatal wxWindows Error");
1590 wxWinHandleList
->Append((long)m_hWnd
, this);
1593 wxDebugMsg("wxWindow::MSWCreate %d\n", m_hWnd
);
1597 void wxWindow::MSWOnCreate(WXLPCREATESTRUCT
WXUNUSED(cs
))
1601 bool wxWindow::MSWOnClose(void)
1604 wxDebugMsg("wxWindow::MSWOnClose %d\n", handle
);
1609 bool wxWindow::MSWOnDestroy(void)
1612 wxDebugMsg("wxWindow::MSWOnDestroy %d\n", handle
);
1614 // delete our drop target if we've got one
1615 #if USE_DRAG_AND_DROP
1616 if ( m_pDropTarget
!= NULL
) {
1617 m_pDropTarget
->Revoke(m_hWnd
);
1619 delete m_pDropTarget
;
1620 m_pDropTarget
= NULL
;
1627 // Deal with child commands from buttons etc.
1629 bool wxWindow::MSWOnNotify(WXWPARAM wParam
, WXLPARAM lParam
)
1631 #if defined(__WIN95__)
1632 // Find a child window to send the notification to, e.g. a toolbar.
1633 // There's a problem here. NMHDR::hwndFrom doesn't give us the
1634 // handle of the toolbar; it's probably the handle of the tooltip
1635 // window (anyway, it's parent is also the toolbar's parent).
1636 // So, since we don't know which hWnd or wxWindow originated the
1637 // WM_NOTIFY, we'll need to go through all the children of this window
1638 // trying out MSWNotify.
1639 // This won't work now, though, because any number of controls
1640 // could respond to the same generic messages :-(
1642 /* This doesn't work for toolbars, but try for other controls first.
1644 NMHDR
*hdr
= (NMHDR
*)lParam
;
1645 HWND hWnd
= (HWND
)hdr
->hwndFrom
;
1646 wxWindow
*win
= wxFindWinFromHandle((WXHWND
) hWnd
);
1649 return win
->MSWNotify(wParam
, lParam
);
1652 // Rely on MSWNotify to check whether the message
1653 // belongs to the window or not
1654 wxNode
*node
= GetChildren()->First();
1657 wxWindow
*child
= (wxWindow
*)node
->Data();
1658 if ( child
->MSWNotify(wParam
, lParam
) )
1660 node
= node
->Next();
1670 void wxWindow::MSWOnMenuHighlight(WXWORD
WXUNUSED(item
), WXWORD
WXUNUSED(flags
), WXHMENU
WXUNUSED(sysmenu
))
1673 wxDebugMsg("wxWindow::MSWOnMenuHighlight %d\n", handle
);
1677 void wxWindow::MSWOnInitMenuPopup(WXHMENU menu
, int pos
, bool isSystem
)
1681 bool wxWindow::MSWOnActivate(int state
, bool WXUNUSED(minimized
), WXHWND
WXUNUSED(activate
))
1684 wxDebugMsg("wxWindow::MSWOnActivate %d\n", handle
);
1687 wxActivateEvent
event(wxEVT_ACTIVATE
, ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)),
1689 event
.SetEventObject(this);
1690 GetEventHandler()->ProcessEvent(event
);
1694 bool wxWindow::MSWOnSetFocus(WXHWND
WXUNUSED(hwnd
))
1697 wxDebugMsg("wxWindow::MSWOnSetFocus %d\n", m_hWnd
);
1700 if (m_caretEnabled
&& (m_caretWidth
> 0) && (m_caretHeight
> 0))
1702 ::CreateCaret((HWND
) GetHWND(), NULL
, m_caretWidth
, m_caretHeight
);
1704 ::ShowCaret((HWND
) GetHWND());
1707 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
1708 event
.SetEventObject(this);
1709 if (!GetEventHandler()->ProcessEvent(event
))
1714 bool wxWindow::MSWOnKillFocus(WXHWND
WXUNUSED(hwnd
))
1717 wxDebugMsg("wxWindow::MSWOnKillFocus %d\n", m_hWnd
);
1725 wxFocusEvent
event(wxEVT_KILL_FOCUS
, m_windowId
);
1726 event
.SetEventObject(this);
1727 if (!GetEventHandler()->ProcessEvent(event
))
1732 void wxWindow::MSWOnDropFiles(WXWPARAM wParam
)
1735 wxDebugMsg("wxWindow::MSWOnDropFiles %d\n", m_hWnd
);
1738 HDROP hFilesInfo
= (HDROP
) wParam
;
1740 DragQueryPoint(hFilesInfo
, (LPPOINT
) &dropPoint
);
1742 // Get the total number of files dropped
1743 WORD gwFilesDropped
= (WORD
)DragQueryFile ((HDROP
)hFilesInfo
,
1748 wxString
*files
= new wxString
[gwFilesDropped
];
1750 for (wIndex
=0; wIndex
< (int)gwFilesDropped
; wIndex
++)
1752 DragQueryFile (hFilesInfo
, wIndex
, (LPSTR
) wxBuffer
, 1000);
1753 files
[wIndex
] = wxBuffer
;
1755 DragFinish (hFilesInfo
);
1757 wxDropFilesEvent
event(wxEVT_DROP_FILES
, gwFilesDropped
, files
);
1758 event
.m_eventObject
= this;
1759 event
.m_pos
.x
= dropPoint
.x
; event
.m_pos
.x
= dropPoint
.y
;
1761 if (!GetEventHandler()->ProcessEvent(event
))
1767 bool wxWindow::MSWOnDrawItem(int id
, WXDRAWITEMSTRUCT
*itemStruct
)
1770 if ( id
== 0 ) { // is it a menu item?
1771 DRAWITEMSTRUCT
*pDrawStruct
= (DRAWITEMSTRUCT
*)itemStruct
;
1772 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pDrawStruct
->itemData
);
1773 wxCHECK( pMenuItem
->IsKindOf(CLASSINFO(wxMenuItem
)), FALSE
);
1775 // prepare to call OnDrawItem()
1777 dc
.SetHDC((WXHDC
)pDrawStruct
->hDC
, FALSE
);
1778 wxRect
rect(pDrawStruct
->rcItem
.left
, pDrawStruct
->rcItem
.top
,
1779 pDrawStruct
->rcItem
.right
- pDrawStruct
->rcItem
.left
,
1780 pDrawStruct
->rcItem
.bottom
- pDrawStruct
->rcItem
.top
);
1781 return pMenuItem
->OnDrawItem(
1783 (wxOwnerDrawn::wxODAction
)pDrawStruct
->itemAction
,
1784 (wxOwnerDrawn::wxODStatus
)pDrawStruct
->itemState
1787 #endif // owner-drawn menus
1789 wxWindow
*item
= FindItem(id
);
1790 #if USE_DYNAMIC_CLASSES
1791 if (item
&& item
->IsKindOf(CLASSINFO(wxControl
)))
1793 return ((wxControl
*)item
)->MSWOnDraw(itemStruct
);
1800 bool wxWindow::MSWOnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*itemStruct
)
1803 if ( id
== 0 ) { // is it a menu item?
1804 MEASUREITEMSTRUCT
*pMeasureStruct
= (MEASUREITEMSTRUCT
*)itemStruct
;
1805 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pMeasureStruct
->itemData
);
1806 wxCHECK( pMenuItem
->IsKindOf(CLASSINFO(wxMenuItem
)), FALSE
);
1808 return pMenuItem
->OnMeasureItem(&pMeasureStruct
->itemWidth
,
1809 &pMeasureStruct
->itemHeight
);
1811 #endif // owner-drawn menus
1813 wxWindow
*item
= FindItem(id
);
1814 #if USE_DYNAMIC_CLASSES
1815 if (item
&& item
->IsKindOf(CLASSINFO(wxControl
)))
1817 return ((wxControl
*)item
)->MSWOnMeasure(itemStruct
);
1824 WXHBRUSH
wxWindow::MSWOnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
1825 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1828 wxDebugMsg("wxWindow::MSWOnCtlColour %d\n", m_hWnd
);
1830 if (nCtlColor
== CTLCOLOR_DLG
)
1832 return OnCtlColor(pDC
, pWnd
, nCtlColor
, message
, wParam
, lParam
);
1835 wxControl
*item
= (wxControl
*)FindItemByHWND(pWnd
, TRUE
);
1837 WXHBRUSH hBrush
= 0;
1840 hBrush
= item
->OnCtlColor(pDC
, pWnd
, nCtlColor
, message
, wParam
, lParam
);
1842 // I think that even for dialogs, we may need to call DefWindowProc (?)
1843 // Or maybe just rely on the usual default behaviour.
1845 hBrush
= (WXHBRUSH
) MSWDefWindowProc(message
, wParam
, lParam
);
1850 // Define for each class of dialog and control
1851 WXHBRUSH
wxWindow::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
1852 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1854 return (WXHBRUSH
) MSWDefWindowProc(message
, wParam
, lParam
);
1857 bool wxWindow::MSWOnColorChange(WXHWND hWnd
, WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1859 wxSysColourChangedEvent event
;
1860 event
.m_eventObject
= this;
1862 // Check if app handles this.
1863 if (GetEventHandler()->ProcessEvent(event
))
1866 // We didn't process it
1870 // Responds to colour changes: passes event on to children.
1871 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1873 wxNode
*node
= GetChildren()->First();
1876 // Only propagate to non-top-level windows
1877 wxWindow
*win
= (wxWindow
*)node
->Data();
1878 if ( win
->GetParent() )
1880 wxSysColourChangedEvent event2
;
1881 event
.m_eventObject
= win
;
1882 win
->GetEventHandler()->ProcessEvent(event2
);
1885 node
= node
->Next();
1889 long wxWindow::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1892 return ::CallWindowProc(CASTWNDPROC (FARPROC
) m_oldWndProc
, (HWND
) GetHWND(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1894 return ::DefWindowProc((HWND
) GetHWND(), nMsg
, wParam
, lParam
);
1897 long wxWindow::Default()
1899 // Ignore 'fake' events (perhaps generated as a result of a separate real event)
1904 wxLogTrace(wxTraceMessages
, "Forwarding %s to DefWindowProc.",
1905 GetMessageName(m_lastMsg
));
1908 return this->MSWDefWindowProc(m_lastMsg
, m_lastWParam
, m_lastLParam
);
1911 bool wxWindow::MSWProcessMessage(WXMSG
* pMsg
)
1913 if ( m_hWnd
!= 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL
) ) {
1914 // intercept dialog navigation keys
1915 MSG
*msg
= (MSG
*)pMsg
;
1916 bool bProcess
= TRUE
;
1917 if ( msg
->message
!= WM_KEYDOWN
)
1920 if ( (HIWORD(msg
->lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
1923 bool bCtrlDown
= (::GetKeyState(VK_CONTROL
) & 0x100) != 0;
1925 // WM_GETDLGCODE: if the control wants it for itself, don't process it
1926 // (except for Ctrl-Tab combination which is always processed)
1928 if ( bProcess
&& !bCtrlDown
) {
1929 lDlgCode
= ::SendMessage(msg
->hwnd
, WM_GETDLGCODE
, 0, 0);
1934 switch ( msg
->wParam
) {
1936 if ( lDlgCode
& DLGC_WANTTAB
)
1939 bForward
= !(::GetKeyState(VK_SHIFT
) & 0x100);
1944 if ( lDlgCode
& DLGC_WANTARROWS
|| bCtrlDown
)
1952 if ( lDlgCode
& DLGC_WANTARROWS
|| bCtrlDown
)
1964 wxNavigationKeyEvent event
;
1965 event
.SetDirection(bForward
);
1966 event
.SetWindowChange(bCtrlDown
);
1967 event
.SetEventObject(this);
1969 if ( GetEventHandler()->ProcessEvent(event
) )
1973 return ::IsDialogMessage((HWND
)GetHWND(), msg
) != 0;
1979 long wxWindow::MSWOnMDIActivate(long WXUNUSED(flag
), WXHWND
WXUNUSED(activate
), WXHWND
WXUNUSED(deactivate
))
1982 wxDebugMsg("wxWindow::MSWOnMDIActivate %d\n", m_hWnd
);
1987 void wxWindow::MSWDetachWindowMenu(void)
1991 int N
= GetMenuItemCount((HMENU
) m_hMenu
);
1993 for (i
= 0; i
< N
; i
++)
1996 int chars
= GetMenuString((HMENU
) m_hMenu
, i
, buf
, 100, MF_BYPOSITION
);
1997 if ((chars
> 0) && (strcmp(buf
, "&Window") == 0))
1999 RemoveMenu((HMENU
) m_hMenu
, i
, MF_BYPOSITION
);
2006 bool wxWindow::MSWOnPaint(void)
2009 HRGN hRegion
= ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle
2010 ::GetUpdateRgn((HWND
) GetHWND(), hRegion
, FALSE
);
2012 m_updateRegion
= wxRegion((WXHRGN
) hRegion
);
2015 ::GetUpdateRect((HWND
) GetHWND(), & updateRect
, FALSE
);
2017 m_updateRegion
= wxRegion(updateRect
.left
, updateRect
.top
,
2018 updateRect
.right
- updateRect
.left
, updateRect
.bottom
- updateRect
.top
);
2021 wxPaintEvent
event(m_windowId
);
2022 event
.SetEventObject(this);
2023 if (!GetEventHandler()->ProcessEvent(event
))
2028 void wxWindow::MSWOnSize(int w
, int h
, WXUINT
WXUNUSED(flag
))
2034 wxDebugMsg("wxWindow::MSWOnSize %d\n", m_hWnd
);
2041 wxSizeEvent
event(wxSize(w
, h
), m_windowId
);
2042 event
.SetEventObject(this);
2043 if (!GetEventHandler()->ProcessEvent(event
))
2049 void wxWindow::MSWOnWindowPosChanging(void *WXUNUSED(lpPos
))
2054 // Deal with child commands from buttons etc.
2055 bool wxWindow::MSWOnCommand(WXWORD id
, WXWORD cmd
, WXHWND
WXUNUSED(control
))
2058 wxDebugMsg("wxWindow::MSWOnCommand\n");
2060 if (wxCurrentPopupMenu
)
2062 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
2063 wxCurrentPopupMenu
= NULL
;
2064 bool succ
= popupMenu
->MSWCommand(cmd
, id
);
2069 sprintf(buf
, "Looking for item %d...\n", id
);
2073 wxWindow
*item
= FindItem(id
);
2076 bool value
= item
->MSWCommand(cmd
, id
);
2079 wxDebugMsg("MSWCommand succeeded\n");
2081 wxDebugMsg("MSWCommand failed\n");
2088 wxDebugMsg("Could not find item!\n");
2090 wxDebugMsg("Item ids for this panel:\n");
2092 wxNode
*current
= GetChildren()->First();
2095 wxObject
*obj
= (wxObject
*)current
->Data() ;
2096 if (obj
->IsKindOf(CLASSINFO(wxControl
)))
2098 wxControl
*item
= (wxControl
*)current
->Data();
2099 sprintf(buf
, " %d\n", (int)item
->m_windowId
);
2102 current
= current
->Next();
2110 long wxWindow::MSWOnSysCommand(WXWPARAM wParam
, WXLPARAM lParam
)
2116 wxMaximizeEvent
event(m_windowId
);
2117 event
.SetEventObject(this);
2118 if (!GetEventHandler()->ProcessEvent(event
))
2126 wxIconizeEvent
event(m_windowId
);
2127 event
.SetEventObject(this);
2128 if (!GetEventHandler()->ProcessEvent(event
))
2140 void wxWindow::MSWOnLButtonDown(int x
, int y
, WXUINT flags
)
2142 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
2144 event
.m_x
= x
; event
.m_y
= y
;
2145 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2146 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2147 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2148 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2149 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2150 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2151 event
.m_eventObject
= this;
2153 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVENT_TYPE_LEFT_DOWN
;
2155 if (!GetEventHandler()->ProcessEvent(event
))
2159 void wxWindow::MSWOnLButtonUp(int x
, int y
, WXUINT flags
)
2161 wxMouseEvent
event(wxEVT_LEFT_UP
);
2163 event
.m_x
= x
; event
.m_y
= y
;
2164 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2165 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2166 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2167 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2168 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2169 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2170 event
.m_eventObject
= this;
2172 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_LEFT_UP
;
2174 if (!GetEventHandler()->ProcessEvent(event
))
2178 void wxWindow::MSWOnLButtonDClick(int x
, int y
, WXUINT flags
)
2180 wxMouseEvent
event(wxEVT_LEFT_DCLICK
);
2182 event
.m_x
= x
; event
.m_y
= y
;
2183 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2184 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2185 event
.m_leftDown
= ((flags
& MK_LBUTTON
!= 0));
2186 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2187 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2188 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2189 event
.m_eventObject
= this;
2191 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_LEFT_DCLICK
;
2193 if (!GetEventHandler()->ProcessEvent(event
))
2197 void wxWindow::MSWOnMButtonDown(int x
, int y
, WXUINT flags
)
2199 wxMouseEvent
event(wxEVT_MIDDLE_DOWN
);
2201 event
.m_x
= x
; event
.m_y
= y
;
2202 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2203 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2204 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2205 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2206 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2207 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2208 event
.m_eventObject
= this;
2210 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_MIDDLE_DOWN
;
2212 if (!GetEventHandler()->ProcessEvent(event
))
2216 void wxWindow::MSWOnMButtonUp(int x
, int y
, WXUINT flags
)
2218 //wxDebugMsg("MButtonUp\n") ;
2219 wxMouseEvent
event(wxEVT_MIDDLE_UP
);
2221 event
.m_x
= x
; event
.m_y
= y
;
2222 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2223 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2224 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2225 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2226 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2227 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2228 event
.m_eventObject
= this;
2230 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_MIDDLE_UP
;
2232 if (!GetEventHandler()->ProcessEvent(event
))
2236 void wxWindow::MSWOnMButtonDClick(int x
, int y
, WXUINT flags
)
2238 wxMouseEvent
event(wxEVT_MIDDLE_DCLICK
);
2240 event
.m_x
= x
; event
.m_y
= y
;
2241 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2242 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2243 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2244 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2245 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2246 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2247 event
.m_eventObject
= this;
2249 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_MIDDLE_DCLICK
;
2251 if (!GetEventHandler()->ProcessEvent(event
))
2255 void wxWindow::MSWOnRButtonDown(int x
, int y
, WXUINT flags
)
2257 wxMouseEvent
event(wxEVT_RIGHT_DOWN
);
2259 event
.m_x
= x
; event
.m_y
= y
;
2260 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2261 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2262 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2263 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2264 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2265 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2266 event
.m_eventObject
= this;
2268 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_RIGHT_DOWN
;
2270 if (!GetEventHandler()->ProcessEvent(event
))
2274 void wxWindow::MSWOnRButtonUp(int x
, int y
, WXUINT flags
)
2276 wxMouseEvent
event(wxEVT_RIGHT_UP
);
2278 event
.m_x
= x
; event
.m_y
= y
;
2279 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2280 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2281 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2282 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2283 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2284 event
.m_eventObject
= this;
2285 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2287 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_RIGHT_UP
;
2289 if (!GetEventHandler()->ProcessEvent(event
))
2293 void wxWindow::MSWOnRButtonDClick(int x
, int y
, WXUINT flags
)
2295 wxMouseEvent
event(wxEVT_RIGHT_DCLICK
);
2297 event
.m_x
= x
; event
.m_y
= y
;
2298 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2299 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2300 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2301 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2302 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2303 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2304 event
.m_eventObject
= this;
2306 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_RIGHT_DCLICK
;
2308 if (!GetEventHandler()->ProcessEvent(event
))
2312 void wxWindow::MSWOnMouseMove(int x
, int y
, WXUINT flags
)
2314 // 'normal' move event...
2315 // Set cursor, but only if we're not in 'busy' mode
2317 // Trouble with this is that it sets the cursor for controls too :-(
2318 if (m_windowCursor
.Ok() && !wxIsBusy())
2319 ::SetCursor((HCURSOR
) m_windowCursor
.GetHCURSOR());
2321 if (!m_mouseInWindow
)
2323 // Generate an ENTER event
2324 m_mouseInWindow
= TRUE
;
2325 MSWOnMouseEnter(x
, y
, flags
);
2328 wxMouseEvent
event(wxEVT_MOTION
);
2330 event
.m_x
= x
; event
.m_y
= y
;
2331 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2332 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2333 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2334 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2335 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2336 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2337 event
.m_eventObject
= this;
2339 // Window gets a click down message followed by a mouse move
2340 // message even if position isn't changed! We want to discard
2341 // the trailing move event if x and y are the same.
2342 if ((m_lastEvent
== wxEVT_RIGHT_DOWN
|| m_lastEvent
== wxEVT_LEFT_DOWN
||
2343 m_lastEvent
== wxEVT_MIDDLE_DOWN
) &&
2344 (m_lastXPos
== event
.m_x
&& m_lastYPos
== event
.m_y
))
2346 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2347 m_lastEvent
= wxEVT_MOTION
;
2351 m_lastEvent
= wxEVT_MOTION
;
2352 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2354 if (!GetEventHandler()->ProcessEvent(event
))
2358 void wxWindow::MSWOnMouseEnter(int x
, int y
, WXUINT flags
)
2360 wxMouseEvent
event(wxEVT_ENTER_WINDOW
);
2362 event
.m_x
= x
; event
.m_y
= y
;
2363 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2364 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2365 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2366 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2367 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2368 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2369 event
.m_eventObject
= this;
2371 m_lastEvent
= wxEVT_ENTER_WINDOW
;
2372 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2373 // No message - ensure we don't try to call the default behaviour accidentally.
2375 GetEventHandler()->ProcessEvent(event
);
2378 void wxWindow::MSWOnMouseLeave(int x
, int y
, WXUINT flags
)
2380 wxMouseEvent
event(wxEVT_LEAVE_WINDOW
);
2382 event
.m_x
= x
; event
.m_y
= y
;
2383 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2384 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2385 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2386 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2387 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2388 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2389 event
.m_eventObject
= this;
2391 m_lastEvent
= wxEVT_LEAVE_WINDOW
;
2392 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2393 // No message - ensure we don't try to call the default behaviour accidentally.
2395 GetEventHandler()->ProcessEvent(event
);
2398 void wxWindow::MSWOnChar(WXWORD wParam
, WXLPARAM lParam
, bool isASCII
)
2401 bool tempControlDown
= FALSE
;
2404 // If 1 -> 26, translate to CTRL plus a letter.
2406 if ((id
> 0) && (id
< 27))
2427 tempControlDown
= TRUE
;
2433 else if ((id
= wxCharCodeMSWToWX(wParam
)) == 0) {
2434 // it's ASCII and will be processed here only when called from
2435 // WM_CHAR (i.e. when isASCII = TRUE)
2441 wxKeyEvent
event(wxEVT_CHAR
);
2442 event
.m_shiftDown
= (::GetKeyState(VK_SHIFT
)&0x100?TRUE
:FALSE
);
2443 event
.m_controlDown
= (::GetKeyState(VK_CONTROL
)&0x100?TRUE
:FALSE
);
2444 if ((HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
2445 event
.m_altDown
= TRUE
;
2447 event
.m_eventObject
= this;
2448 event
.m_keyCode
= id
;
2449 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2454 GetWindowRect((HWND
) GetHWND(),&rect
) ;
2458 event
.m_x
= pt
.x
; event
.m_y
= pt
.y
;
2460 if (!GetEventHandler()->ProcessEvent(event
))
2465 void wxWindow::MSWOnJoyDown(int joystick
, int x
, int y
, WXUINT flags
)
2469 if (flags
& JOY_BUTTON1CHG
)
2470 change
= wxJOY_BUTTON1
;
2471 if (flags
& JOY_BUTTON2CHG
)
2472 change
= wxJOY_BUTTON2
;
2473 if (flags
& JOY_BUTTON3CHG
)
2474 change
= wxJOY_BUTTON3
;
2475 if (flags
& JOY_BUTTON4CHG
)
2476 change
= wxJOY_BUTTON4
;
2478 if (flags
& JOY_BUTTON1
)
2479 buttons
|= wxJOY_BUTTON1
;
2480 if (flags
& JOY_BUTTON2
)
2481 buttons
|= wxJOY_BUTTON2
;
2482 if (flags
& JOY_BUTTON3
)
2483 buttons
|= wxJOY_BUTTON3
;
2484 if (flags
& JOY_BUTTON4
)
2485 buttons
|= wxJOY_BUTTON4
;
2487 wxJoystickEvent
event(wxEVT_JOY_BUTTON_DOWN
, buttons
, joystick
, change
);
2488 event
.SetPosition(wxPoint(x
, y
));
2489 event
.SetEventObject(this);
2491 GetEventHandler()->ProcessEvent(event
);
2494 void wxWindow::MSWOnJoyUp(int joystick
, int x
, int y
, WXUINT flags
)
2498 if (flags
& JOY_BUTTON1CHG
)
2499 change
= wxJOY_BUTTON1
;
2500 if (flags
& JOY_BUTTON2CHG
)
2501 change
= wxJOY_BUTTON2
;
2502 if (flags
& JOY_BUTTON3CHG
)
2503 change
= wxJOY_BUTTON3
;
2504 if (flags
& JOY_BUTTON4CHG
)
2505 change
= wxJOY_BUTTON4
;
2507 if (flags
& JOY_BUTTON1
)
2508 buttons
|= wxJOY_BUTTON1
;
2509 if (flags
& JOY_BUTTON2
)
2510 buttons
|= wxJOY_BUTTON2
;
2511 if (flags
& JOY_BUTTON3
)
2512 buttons
|= wxJOY_BUTTON3
;
2513 if (flags
& JOY_BUTTON4
)
2514 buttons
|= wxJOY_BUTTON4
;
2516 wxJoystickEvent
event(wxEVT_JOY_BUTTON_UP
, buttons
, joystick
, change
);
2517 event
.SetPosition(wxPoint(x
, y
));
2518 event
.SetEventObject(this);
2520 GetEventHandler()->ProcessEvent(event
);
2523 void wxWindow::MSWOnJoyMove(int joystick
, int x
, int y
, WXUINT flags
)
2526 if (flags
& JOY_BUTTON1
)
2527 buttons
|= wxJOY_BUTTON1
;
2528 if (flags
& JOY_BUTTON2
)
2529 buttons
|= wxJOY_BUTTON2
;
2530 if (flags
& JOY_BUTTON3
)
2531 buttons
|= wxJOY_BUTTON3
;
2532 if (flags
& JOY_BUTTON4
)
2533 buttons
|= wxJOY_BUTTON4
;
2535 wxJoystickEvent
event(wxEVT_JOY_MOVE
, buttons
, joystick
, 0);
2536 event
.SetPosition(wxPoint(x
, y
));
2537 event
.SetEventObject(this);
2539 GetEventHandler()->ProcessEvent(event
);
2542 void wxWindow::MSWOnJoyZMove(int joystick
, int z
, WXUINT flags
)
2545 if (flags
& JOY_BUTTON1
)
2546 buttons
|= wxJOY_BUTTON1
;
2547 if (flags
& JOY_BUTTON2
)
2548 buttons
|= wxJOY_BUTTON2
;
2549 if (flags
& JOY_BUTTON3
)
2550 buttons
|= wxJOY_BUTTON3
;
2551 if (flags
& JOY_BUTTON4
)
2552 buttons
|= wxJOY_BUTTON4
;
2554 wxJoystickEvent
event(wxEVT_JOY_ZMOVE
, buttons
, joystick
, 0);
2555 event
.SetZPosition(z
);
2556 event
.SetEventObject(this);
2558 GetEventHandler()->ProcessEvent(event
);
2561 void wxWindow::MSWOnVScroll(WXWORD wParam
, WXWORD pos
, WXHWND control
)
2565 wxWindow
*child
= wxFindWinFromHandle(control
);
2567 child
->MSWOnVScroll(wParam
, pos
, control
);
2571 wxScrollEvent event
;
2572 event
.SetPosition(pos
);
2573 event
.SetOrientation(wxVERTICAL
);
2574 event
.m_eventObject
= this;
2579 event
.m_eventType
= wxEVT_SCROLL_TOP
;
2583 event
.m_eventType
= wxEVT_SCROLL_BOTTOM
;
2587 event
.m_eventType
= wxEVT_SCROLL_LINEUP
;
2591 event
.m_eventType
= wxEVT_SCROLL_LINEDOWN
;
2595 event
.m_eventType
= wxEVT_SCROLL_PAGEUP
;
2599 event
.m_eventType
= wxEVT_SCROLL_PAGEDOWN
;
2603 case SB_THUMBPOSITION
:
2604 event
.m_eventType
= wxEVT_SCROLL_THUMBTRACK
;
2612 if (!GetEventHandler()->ProcessEvent(event
))
2616 void wxWindow::MSWOnHScroll( WXWORD wParam
, WXWORD pos
, WXHWND control
)
2620 wxWindow
*child
= wxFindWinFromHandle(control
);
2622 child
->MSWOnHScroll(wParam
, pos
, control
);
2626 wxScrollEvent event
;
2627 event
.SetPosition(pos
);
2628 event
.SetOrientation(wxHORIZONTAL
);
2629 event
.m_eventObject
= this;
2634 event
.m_eventType
= wxEVT_SCROLL_TOP
;
2638 event
.m_eventType
= wxEVT_SCROLL_BOTTOM
;
2642 event
.m_eventType
= wxEVT_SCROLL_LINEUP
;
2646 event
.m_eventType
= wxEVT_SCROLL_LINEDOWN
;
2650 event
.m_eventType
= wxEVT_SCROLL_PAGEUP
;
2654 event
.m_eventType
= wxEVT_SCROLL_PAGEDOWN
;
2658 case SB_THUMBPOSITION
:
2659 event
.m_eventType
= wxEVT_SCROLL_THUMBTRACK
;
2666 if (!GetEventHandler()->ProcessEvent(event
))
2670 void wxWindow::MSWOnShow(bool show
, int status
)
2672 wxShowEvent
event(GetId(), show
);
2673 event
.m_eventObject
= this;
2674 GetEventHandler()->ProcessEvent(event
);
2677 bool wxWindow::MSWOnInitDialog(WXHWND
WXUNUSED(hWndFocus
))
2679 wxInitDialogEvent
event(GetId());
2680 event
.m_eventObject
= this;
2681 GetEventHandler()->ProcessEvent(event
);
2685 void wxWindow::InitDialog(void)
2687 wxInitDialogEvent
event(GetId());
2688 event
.SetEventObject( this );
2689 GetEventHandler()->ProcessEvent(event
);
2692 // Default init dialog behaviour is to transfer data to window
2693 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
2695 TransferDataToWindow();
2698 void wxGetCharSize(WXHWND wnd
, int *x
, int *y
,wxFont
*the_font
)
2701 HDC dc
= ::GetDC((HWND
) wnd
);
2707 wxDebugMsg("wxGetCharSize: Selecting HFONT %X\n", fnt
);
2709 // the_font->UseResource();
2710 // the_font->RealizeResource();
2711 if ((fnt
=(HFONT
) the_font
->GetResourceHandle()))
2712 was
= (HFONT
) SelectObject(dc
,fnt
) ;
2714 GetTextMetrics(dc
, &tm
);
2715 if (the_font
&& fnt
&& was
)
2718 wxDebugMsg("wxGetCharSize: Selecting old HFONT %X\n", was
);
2720 SelectObject(dc
,was
) ;
2722 ReleaseDC((HWND
)wnd
, dc
);
2723 *x
= tm
.tmAveCharWidth
;
2724 *y
= tm
.tmHeight
+ tm
.tmExternalLeading
;
2727 // the_font->ReleaseResource();
2730 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
2731 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
2732 int wxCharCodeMSWToWX(int keySym
)
2737 case VK_CANCEL
: id
= WXK_CANCEL
; break;
2738 case VK_BACK
: id
= WXK_BACK
; break;
2739 case VK_TAB
: id
= WXK_TAB
; break;
2740 case VK_CLEAR
: id
= WXK_CLEAR
; break;
2741 case VK_RETURN
: id
= WXK_RETURN
; break;
2742 case VK_SHIFT
: id
= WXK_SHIFT
; break;
2743 case VK_CONTROL
: id
= WXK_CONTROL
; break;
2744 case VK_MENU
: id
= WXK_MENU
; break;
2745 case VK_PAUSE
: id
= WXK_PAUSE
; break;
2746 case VK_SPACE
: id
= WXK_SPACE
; break;
2747 case VK_ESCAPE
: id
= WXK_ESCAPE
; break;
2748 case VK_PRIOR
: id
= WXK_PRIOR
; break;
2749 case VK_NEXT
: id
= WXK_NEXT
; break;
2750 case VK_END
: id
= WXK_END
; break;
2751 case VK_HOME
: id
= WXK_HOME
; break;
2752 case VK_LEFT
: id
= WXK_LEFT
; break;
2753 case VK_UP
: id
= WXK_UP
; break;
2754 case VK_RIGHT
: id
= WXK_RIGHT
; break;
2755 case VK_DOWN
: id
= WXK_DOWN
; break;
2756 case VK_SELECT
: id
= WXK_SELECT
; break;
2757 case VK_PRINT
: id
= WXK_PRINT
; break;
2758 case VK_EXECUTE
: id
= WXK_EXECUTE
; break;
2759 case VK_INSERT
: id
= WXK_INSERT
; break;
2760 case VK_DELETE
: id
= WXK_DELETE
; break;
2761 case VK_HELP
: id
= WXK_HELP
; break;
2762 case VK_NUMPAD0
: id
= WXK_NUMPAD0
; break;
2763 case VK_NUMPAD1
: id
= WXK_NUMPAD1
; break;
2764 case VK_NUMPAD2
: id
= WXK_NUMPAD2
; break;
2765 case VK_NUMPAD3
: id
= WXK_NUMPAD3
; break;
2766 case VK_NUMPAD4
: id
= WXK_NUMPAD4
; break;
2767 case VK_NUMPAD5
: id
= WXK_NUMPAD5
; break;
2768 case VK_NUMPAD6
: id
= WXK_NUMPAD6
; break;
2769 case VK_NUMPAD7
: id
= WXK_NUMPAD7
; break;
2770 case VK_NUMPAD8
: id
= WXK_NUMPAD8
; break;
2771 case VK_NUMPAD9
: id
= WXK_NUMPAD9
; break;
2772 case VK_MULTIPLY
: id
= WXK_MULTIPLY
; break;
2773 case VK_ADD
: id
= WXK_ADD
; break;
2774 case VK_SUBTRACT
: id
= WXK_SUBTRACT
; break;
2775 case VK_DECIMAL
: id
= WXK_DECIMAL
; break;
2776 case VK_DIVIDE
: id
= WXK_DIVIDE
; break;
2777 case VK_F1
: id
= WXK_F1
; break;
2778 case VK_F2
: id
= WXK_F2
; break;
2779 case VK_F3
: id
= WXK_F3
; break;
2780 case VK_F4
: id
= WXK_F4
; break;
2781 case VK_F5
: id
= WXK_F5
; break;
2782 case VK_F6
: id
= WXK_F6
; break;
2783 case VK_F7
: id
= WXK_F7
; break;
2784 case VK_F8
: id
= WXK_F8
; break;
2785 case VK_F9
: id
= WXK_F9
; break;
2786 case VK_F10
: id
= WXK_F10
; break;
2787 case VK_F11
: id
= WXK_F11
; break;
2788 case VK_F12
: id
= WXK_F12
; break;
2789 case VK_F13
: id
= WXK_F13
; break;
2790 case VK_F14
: id
= WXK_F14
; break;
2791 case VK_F15
: id
= WXK_F15
; break;
2792 case VK_F16
: id
= WXK_F16
; break;
2793 case VK_F17
: id
= WXK_F17
; break;
2794 case VK_F18
: id
= WXK_F18
; break;
2795 case VK_F19
: id
= WXK_F19
; break;
2796 case VK_F20
: id
= WXK_F20
; break;
2797 case VK_F21
: id
= WXK_F21
; break;
2798 case VK_F22
: id
= WXK_F22
; break;
2799 case VK_F23
: id
= WXK_F23
; break;
2800 case VK_F24
: id
= WXK_F24
; break;
2801 case VK_NUMLOCK
: id
= WXK_NUMLOCK
; break;
2802 case VK_SCROLL
: id
= WXK_SCROLL
; break;
2811 int wxCharCodeWXToMSW(int id
, bool *isVirtual
)
2817 case WXK_CANCEL
: keySym
= VK_CANCEL
; break;
2818 case WXK_CLEAR
: keySym
= VK_CLEAR
; break;
2819 case WXK_SHIFT
: keySym
= VK_SHIFT
; break;
2820 case WXK_CONTROL
: keySym
= VK_CONTROL
; break;
2821 case WXK_MENU
: keySym
= VK_MENU
; break;
2822 case WXK_PAUSE
: keySym
= VK_PAUSE
; break;
2823 case WXK_PRIOR
: keySym
= VK_PRIOR
; break;
2824 case WXK_NEXT
: keySym
= VK_NEXT
; break;
2825 case WXK_END
: keySym
= VK_END
; break;
2826 case WXK_HOME
: keySym
= VK_HOME
; break;
2827 case WXK_LEFT
: keySym
= VK_LEFT
; break;
2828 case WXK_UP
: keySym
= VK_UP
; break;
2829 case WXK_RIGHT
: keySym
= VK_RIGHT
; break;
2830 case WXK_DOWN
: keySym
= VK_DOWN
; break;
2831 case WXK_SELECT
: keySym
= VK_SELECT
; break;
2832 case WXK_PRINT
: keySym
= VK_PRINT
; break;
2833 case WXK_EXECUTE
: keySym
= VK_EXECUTE
; break;
2834 case WXK_INSERT
: keySym
= VK_INSERT
; break;
2835 case WXK_DELETE
: keySym
= VK_DELETE
; break;
2836 case WXK_HELP
: keySym
= VK_HELP
; break;
2837 case WXK_NUMPAD0
: keySym
= VK_NUMPAD0
; break;
2838 case WXK_NUMPAD1
: keySym
= VK_NUMPAD1
; break;
2839 case WXK_NUMPAD2
: keySym
= VK_NUMPAD2
; break;
2840 case WXK_NUMPAD3
: keySym
= VK_NUMPAD3
; break;
2841 case WXK_NUMPAD4
: keySym
= VK_NUMPAD4
; break;
2842 case WXK_NUMPAD5
: keySym
= VK_NUMPAD5
; break;
2843 case WXK_NUMPAD6
: keySym
= VK_NUMPAD6
; break;
2844 case WXK_NUMPAD7
: keySym
= VK_NUMPAD7
; break;
2845 case WXK_NUMPAD8
: keySym
= VK_NUMPAD8
; break;
2846 case WXK_NUMPAD9
: keySym
= VK_NUMPAD9
; break;
2847 case WXK_MULTIPLY
: keySym
= VK_MULTIPLY
; break;
2848 case WXK_ADD
: keySym
= VK_ADD
; break;
2849 case WXK_SUBTRACT
: keySym
= VK_SUBTRACT
; break;
2850 case WXK_DECIMAL
: keySym
= VK_DECIMAL
; break;
2851 case WXK_DIVIDE
: keySym
= VK_DIVIDE
; break;
2852 case WXK_F1
: keySym
= VK_F1
; break;
2853 case WXK_F2
: keySym
= VK_F2
; break;
2854 case WXK_F3
: keySym
= VK_F3
; break;
2855 case WXK_F4
: keySym
= VK_F4
; break;
2856 case WXK_F5
: keySym
= VK_F5
; break;
2857 case WXK_F6
: keySym
= VK_F6
; break;
2858 case WXK_F7
: keySym
= VK_F7
; break;
2859 case WXK_F8
: keySym
= VK_F8
; break;
2860 case WXK_F9
: keySym
= VK_F9
; break;
2861 case WXK_F10
: keySym
= VK_F10
; break;
2862 case WXK_F11
: keySym
= VK_F11
; break;
2863 case WXK_F12
: keySym
= VK_F12
; break;
2864 case WXK_F13
: keySym
= VK_F13
; break;
2865 case WXK_F14
: keySym
= VK_F14
; break;
2866 case WXK_F15
: keySym
= VK_F15
; break;
2867 case WXK_F16
: keySym
= VK_F16
; break;
2868 case WXK_F17
: keySym
= VK_F17
; break;
2869 case WXK_F18
: keySym
= VK_F18
; break;
2870 case WXK_F19
: keySym
= VK_F19
; break;
2871 case WXK_F20
: keySym
= VK_F20
; break;
2872 case WXK_F21
: keySym
= VK_F21
; break;
2873 case WXK_F22
: keySym
= VK_F22
; break;
2874 case WXK_F23
: keySym
= VK_F23
; break;
2875 case WXK_F24
: keySym
= VK_F24
; break;
2876 case WXK_NUMLOCK
: keySym
= VK_NUMLOCK
; break;
2877 case WXK_SCROLL
: keySym
= VK_SCROLL
; break;
2888 // Caret manipulation
2889 void wxWindow::CreateCaret(int w
, int h
)
2893 m_caretEnabled
= TRUE
;
2896 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
2901 void wxWindow::ShowCaret(bool show
)
2906 ::ShowCaret((HWND
) GetHWND());
2908 ::HideCaret((HWND
) GetHWND());
2909 m_caretShown
= show
;
2913 void wxWindow::DestroyCaret(void)
2915 m_caretEnabled
= FALSE
;
2918 void wxWindow::SetCaretPos(int x
, int y
)
2920 ::SetCaretPos(x
, y
);
2923 void wxWindow::GetCaretPos(int *x
, int *y
) const
2926 ::GetCaretPos(&point
);
2931 // OBSOLETE: use GetUpdateRegion instead.
2935 * Update iterator. Use from within OnPaint.
2938 static RECT gs_UpdateRect
;
2940 wxUpdateIterator::wxUpdateIterator(wxWindow
* wnd
)
2942 current
= 0; //start somewhere...
2943 #if defined(__WIN32__) && !defined(__win32s__)
2944 rlist
= NULL
; //make sure I don't free randomly
2945 int len
= GetRegionData((HRGN
) wnd
->m_updateRgn
,0,NULL
); //Get buffer size
2948 rlist
= (WXRGNDATA
*) (RGNDATA
*)new char[len
];
2949 GetRegionData((HRGN
) wnd
->m_updateRgn
,len
, (RGNDATA
*)rlist
);
2950 rp
= (void *)(RECT
*) ((RGNDATA
*)rlist
)->Buffer
;
2951 rects
= ((RGNDATA
*)rlist
)->rdh
.nCount
;
2956 gs_UpdateRect
.left
= wnd
->m_updateRect
.x
;
2957 gs_UpdateRect
.top
= wnd
->m_updateRect
.y
;
2958 gs_UpdateRect
.right
= wnd
->m_updateRect
.x
+ wnd
->m_updateRect
.width
;
2959 gs_UpdateRect
.bottom
= wnd
->m_updateRect
.y
+ wnd
->m_updateRect
.height
;
2961 rp
= (void *)&gs_UpdateRect
; //Only one available in Win16,32s
2965 wxUpdateIterator::~wxUpdateIterator(void)
2969 if (rlist
) delete (RGNDATA
*) rlist
;
2974 wxUpdateIterator::operator int (void)
2976 if (current
< rects
)
2986 wxUpdateIterator
* wxUpdateIterator::operator ++(int)
2992 void wxUpdateIterator::GetRect(wxRect
*rect
)
2994 RECT
*mswRect
= ((RECT
*)rp
)+current
; //ought to error check this...
2995 rect
->x
= mswRect
->left
;
2996 rect
->y
= mswRect
->top
;
2997 rect
->width
= mswRect
->right
- mswRect
->left
;
2998 rect
->height
= mswRect
->bottom
- mswRect
->top
;
3001 int wxUpdateIterator::GetX()
3003 return ((RECT
*)rp
)[current
].left
;
3006 int wxUpdateIterator::GetY()
3008 return ((RECT
*)rp
)[current
].top
;
3011 int wxUpdateIterator::GetW()
3013 return ((RECT
*)rp
)[current
].right
-GetX();
3016 int wxUpdateIterator::GetH()
3018 return ((RECT
*)rp
)[current
].bottom
-GetY();
3022 wxWindow
*wxGetActiveWindow(void)
3024 HWND hWnd
= GetActiveWindow();
3027 return wxFindWinFromHandle((WXHWND
) hWnd
);
3032 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
3033 // in active frames and dialogs, regardless of where the focus is.
3034 static HHOOK wxTheKeyboardHook
= 0;
3035 static FARPROC wxTheKeyboardHookProc
= 0;
3036 int APIENTRY _EXPORT
3037 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
);
3039 void wxSetKeyboardHook(bool doIt
)
3043 wxTheKeyboardHookProc
= MakeProcInstance((FARPROC
) wxKeyboardHook
, wxGetInstance());
3044 wxTheKeyboardHook
= SetWindowsHookEx(WH_KEYBOARD
, (HOOKPROC
) wxTheKeyboardHookProc
, wxGetInstance(),
3046 GetCurrentThreadId());
3047 // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
3054 UnhookWindowsHookEx(wxTheKeyboardHook
);
3055 FreeProcInstance(wxTheKeyboardHookProc
);
3059 int APIENTRY _EXPORT
3060 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
)
3062 DWORD hiWord
= HIWORD(lParam
);
3063 if (nCode
!= HC_NOREMOVE
&& ((hiWord
& KF_UP
) == 0))
3066 if ((id
= wxCharCodeMSWToWX(wParam
)) != 0)
3068 wxKeyEvent
event(wxEVT_CHAR_HOOK
);
3069 if ((HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
3070 event
.m_altDown
= TRUE
;
3072 event
.m_eventObject
= NULL
;
3073 event
.m_keyCode
= id
;
3074 /* begin Albert's fix for control and shift key 26.5 */
3075 event
.m_shiftDown
= (::GetKeyState(VK_SHIFT
)&0x100?TRUE
:FALSE
);
3076 event
.m_controlDown
= (::GetKeyState(VK_CONTROL
)&0x100?TRUE
:FALSE
);
3077 /* end Albert's fix for control and shift key 26.5 */
3078 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
3080 wxWindow
*win
= wxGetActiveWindow();
3083 if (win
->GetEventHandler()->ProcessEvent(event
))
3088 if ( wxTheApp
&& wxTheApp
->ProcessEvent(event
) )
3093 return (int)CallNextHookEx(wxTheKeyboardHook
, nCode
, wParam
, lParam
);
3096 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int WXUNUSED(incW
), int WXUNUSED(incH
))
3104 void wxWindow::Centre(int direction
)
3106 int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
;
3108 wxWindow
*father
= (wxWindow
*)GetParent();
3112 father
->GetClientSize(&panel_width
, &panel_height
);
3113 GetSize(&width
, &height
);
3114 GetPosition(&x
, &y
);
3119 if (direction
& wxHORIZONTAL
)
3120 new_x
= (int)((panel_width
- width
)/2);
3122 if (direction
& wxVERTICAL
)
3123 new_y
= (int)((panel_height
- height
)/2);
3125 SetSize(new_x
, new_y
, -1, -1);
3130 void wxWindow::OnPaint(void)
3132 PaintSelectionHandles();
3136 void wxWindow::WarpPointer (int x_pos
, int y_pos
)
3138 // Move the pointer to (x_pos,y_pos) coordinates. They are expressed in
3139 // pixel coordinates, relatives to the canvas -- So, we first need to
3140 // substract origin of the window, then convert to screen position
3142 int x
= x_pos
; int y
= y_pos
;
3143 /* Leave this to the app to decide (and/or wxScrolledWindow)
3144 x -= m_xScrollPosition * m_xScrollPixelsPerLine;
3145 y -= m_yScrollPosition * m_yScrollPixelsPerLine;
3148 GetWindowRect ((HWND
) GetHWND(), &rect
);
3153 SetCursorPos (x
, y
);
3156 void wxWindow::MSWDeviceToLogical (float *x
, float *y
) const
3159 // Do we have a SetUserScale in wxWindow too, so we can
3160 // get mouse events scaled?
3164 *x = m_windowDC->DeviceToLogicalX ((int) *x);
3165 *y = m_windowDC->DeviceToLogicalY ((int) *y);
3170 bool wxWindow::MSWOnEraseBkgnd (WXHDC pDC
)
3178 wxEraseEvent
event(m_windowId
, &dc
);
3179 event
.m_eventObject
= this;
3180 if (!GetEventHandler()->ProcessEvent(event
))
3183 dc
.SelectOldObjects(pDC
);
3189 dc
.SelectOldObjects(pDC
);
3192 dc
.SetHDC((WXHDC
) NULL
);
3196 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
3199 ::GetClientRect((HWND
) GetHWND(), &rect
);
3201 HBRUSH hBrush
= ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
3202 int mode
= ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), MM_TEXT
);
3204 // ::GetClipBox((HDC) event.GetDC()->GetHDC(), &rect);
3205 ::FillRect ((HDC
) event
.GetDC()->GetHDC(), &rect
, hBrush
);
3206 ::DeleteObject(hBrush
);
3207 ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), mode
);
3209 // Less efficient version (and doesn't account for scrolling)
3211 GetClientSize(& w, & h);
3212 wxBrush *brush = wxTheBrushList->FindOrCreateBrush(& GetBackgroundColour(), wxSOLID);
3213 event.GetDC()->SetBrush(brush);
3214 event.GetDC()->SetPen(wxTRANSPARENT_PEN);
3216 event.GetDC()->DrawRectangle(0, 0, w+1, h+1);
3220 #if WXWIN_COMPATIBILITY
3221 void wxWindow::SetScrollRange(int orient
, int range
, bool refresh
)
3223 #if defined(__WIN95__)
3227 // Try to adjust the range to cope with page size > 1
3228 // - a Windows API quirk
3229 int pageSize
= GetScrollPage(orient
);
3230 if ( pageSize
> 1 && range
> 0)
3232 range1
+= (pageSize
- 1);
3238 if (orient
== wxHORIZONTAL
) {
3244 info
.cbSize
= sizeof(SCROLLINFO
);
3245 info
.nPage
= pageSize
; // Have to set this, or scrollbar goes awry
3249 info
.fMask
= SIF_RANGE
| SIF_PAGE
;
3251 HWND hWnd
= (HWND
) GetHWND();
3253 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3256 if (orient
== wxHORIZONTAL
)
3261 HWND hWnd
= (HWND
) GetHWND();
3263 ::SetScrollRange(hWnd
, wOrient
, 0, range
, refresh
);
3267 void wxWindow::SetScrollPage(int orient
, int page
, bool refresh
)
3269 #if defined(__WIN95__)
3273 if (orient
== wxHORIZONTAL
) {
3275 m_xThumbSize
= page
;
3278 m_yThumbSize
= page
;
3281 info
.cbSize
= sizeof(SCROLLINFO
);
3284 info
.fMask
= SIF_PAGE
;
3286 HWND hWnd
= (HWND
) GetHWND();
3288 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3290 if (orient
== wxHORIZONTAL
)
3291 m_xThumbSize
= page
;
3293 m_yThumbSize
= page
;
3297 int wxWindow::OldGetScrollRange(int orient
) const
3300 if (orient
== wxHORIZONTAL
)
3305 #if __WATCOMC__ && defined(__WINDOWS_386__)
3306 short minPos
, maxPos
;
3310 HWND hWnd
= (HWND
) GetHWND();
3313 ::GetScrollRange(hWnd
, wOrient
, &minPos
, &maxPos
);
3314 #if defined(__WIN95__)
3315 // Try to adjust the range to cope with page size > 1
3316 // - a Windows API quirk
3317 int pageSize
= GetScrollPage(orient
);
3320 maxPos
-= (pageSize
- 1);
3329 int wxWindow::GetScrollPage(int orient
) const
3331 if (orient
== wxHORIZONTAL
)
3332 return m_xThumbSize
;
3334 return m_yThumbSize
;
3338 int wxWindow::GetScrollPos(int orient
) const
3341 if (orient
== wxHORIZONTAL
)
3345 HWND hWnd
= (HWND
) GetHWND();
3348 return ::GetScrollPos(hWnd
, wOrient
);
3354 // This now returns the whole range, not just the number
3355 // of positions that we can scroll.
3356 int wxWindow::GetScrollRange(int orient
) const
3359 if (orient
== wxHORIZONTAL
)
3364 #if __WATCOMC__ && defined(__WINDOWS_386__)
3365 short minPos
, maxPos
;
3369 HWND hWnd
= (HWND
) GetHWND();
3372 ::GetScrollRange(hWnd
, wOrient
, &minPos
, &maxPos
);
3373 #if defined(__WIN95__)
3374 // Try to adjust the range to cope with page size > 1
3375 // - a Windows API quirk
3376 int pageSize
= GetScrollPage(orient
);
3379 maxPos
-= (pageSize
- 1);
3381 // October 10th: new range concept.
3391 int wxWindow::GetScrollThumb(int orient
) const
3393 if (orient
== wxHORIZONTAL
)
3394 return m_xThumbSize
;
3396 return m_yThumbSize
;
3399 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
3401 #if defined(__WIN95__)
3405 if (orient
== wxHORIZONTAL
) {
3411 info
.cbSize
= sizeof(SCROLLINFO
);
3415 info
.fMask
= SIF_POS
;
3417 HWND hWnd
= (HWND
) GetHWND();
3419 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3422 if (orient
== wxHORIZONTAL
)
3427 HWND hWnd
= (HWND
) GetHWND();
3429 ::SetScrollPos(hWnd
, wOrient
, pos
, refresh
);
3433 // New function that will replace some of the above.
3434 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
3435 int range
, bool refresh
)
3438 SetScrollPage(orient, thumbVisible, FALSE);
3440 int oldRange = range - thumbVisible ;
3441 SetScrollRange(orient, oldRange, FALSE);
3443 SetScrollPos(orient, pos, refresh);
3445 #if defined(__WIN95__)
3446 int oldRange
= range
- thumbVisible
;
3448 int range1
= oldRange
;
3450 // Try to adjust the range to cope with page size > 1
3451 // - a Windows API quirk
3452 int pageSize
= thumbVisible
;
3453 if ( pageSize
> 1 && range
> 0)
3455 range1
+= (pageSize
- 1);
3461 if (orient
== wxHORIZONTAL
) {
3467 info
.cbSize
= sizeof(SCROLLINFO
);
3468 info
.nPage
= pageSize
; // Have to set this, or scrollbar goes awry
3472 info
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
3474 HWND hWnd
= (HWND
) GetHWND();
3476 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3479 if (orient
== wxHORIZONTAL
)
3484 HWND hWnd
= (HWND
) GetHWND();
3487 ::SetScrollRange(hWnd
, wOrient
, 0, range
, FALSE
);
3488 ::SetScrollPos(hWnd
, wOrient
, pos
, refresh
);
3491 if (orient
== wxHORIZONTAL
) {
3492 m_xThumbSize
= thumbVisible
;
3494 m_yThumbSize
= thumbVisible
;
3498 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRectangle
*rect
)
3503 rect2
.left
= rect
->x
;
3504 rect2
.top
= rect
->y
;
3505 rect2
.right
= rect
->x
+ rect
->width
;
3506 rect2
.bottom
= rect
->y
+ rect
->height
;
3510 ::ScrollWindow((HWND
) GetHWND(), dx
, dy
, &rect2
, NULL
);
3512 ::ScrollWindow((HWND
) GetHWND(), dx
, dy
, NULL
, NULL
);
3516 void wxWindow::CalcScrolledPosition(int x, int y, int *xx, int *yy) const
3522 void wxWindow::CalcUnscrolledPosition(int x, int y, float *xx, float *yy) const
3529 void wxWindow::SetFont(const wxFont
& font
)
3531 // Decrement the usage count of the old label font
3532 // (we may be able to free it up)
3533 // if (GetFont()->Ok())
3534 // GetFont()->ReleaseResource();
3536 m_windowFont
= font
;
3538 if (!m_windowFont
.Ok())
3541 // m_windowFont.UseResource();
3543 HWND hWnd
= (HWND
) GetHWND();
3546 // m_windowFont.RealizeResource();
3548 if (m_windowFont
.GetResourceHandle())
3549 SendMessage(hWnd
, WM_SETFONT
,
3550 (WPARAM
)m_windowFont
.GetResourceHandle(),TRUE
);
3554 void wxWindow::SubclassWin(WXHWND hWnd
)
3556 wxAssociateWinWithHandle((HWND
)hWnd
, this);
3558 m_oldWndProc
= (WXFARPROC
) GetWindowLong((HWND
) hWnd
, GWL_WNDPROC
);
3559 SetWindowLong((HWND
) hWnd
, GWL_WNDPROC
, (LONG
) wxWndProc
);
3562 void wxWindow::UnsubclassWin(void)
3564 wxRemoveHandleAssociation(this);
3566 // Restore old Window proc
3567 if ((HWND
) GetHWND())
3569 FARPROC farProc
= (FARPROC
) GetWindowLong((HWND
) GetHWND(), GWL_WNDPROC
);
3570 if ((m_oldWndProc
!= 0) && (farProc
!= (FARPROC
) m_oldWndProc
))
3572 SetWindowLong((HWND
) GetHWND(), GWL_WNDPROC
, (LONG
) m_oldWndProc
);
3578 // Make a Windows extended style from the given wxWindows window style
3579 WXDWORD
wxWindow::MakeExtendedStyle(long style
, bool eliminateBorders
)
3581 WXDWORD exStyle
= 0;
3582 if ( style
& wxTRANSPARENT_WINDOW
)
3583 exStyle
|= WS_EX_TRANSPARENT
;
3585 if ( !eliminateBorders
)
3587 if ( style
& wxSUNKEN_BORDER
)
3588 exStyle
|= WS_EX_CLIENTEDGE
;
3589 if ( style
& wxDOUBLE_BORDER
)
3590 exStyle
|= WS_EX_DLGMODALFRAME
;
3591 #if defined(__WIN95__)
3592 if ( style
& wxRAISED_BORDER
)
3593 exStyle
|= WS_EX_WINDOWEDGE
;
3594 if ( style
& wxSTATIC_BORDER
)
3595 exStyle
|= WS_EX_STATICEDGE
;
3601 // Determines whether native 3D effects or CTL3D should be used,
3602 // applying a default border style if required, and returning an extended
3603 // style to pass to CreateWindowEx.
3604 WXDWORD
wxWindow::Determine3DEffects(WXDWORD defaultBorderStyle
, bool *want3D
)
3606 // If matches certain criteria, then assume no 3D effects
3607 // unless specifically requested (dealt with in MakeExtendedStyle)
3608 if ( !GetParent() || !IsKindOf(CLASSINFO(wxControl
)) || (m_windowStyle
& wxNO_BORDER
) )
3611 return MakeExtendedStyle(m_windowStyle
, FALSE
);
3614 // Determine whether we should be using 3D effects or not.
3615 bool nativeBorder
= FALSE
; // by default, we don't want a Win95 effect
3617 // 1) App can specify global 3D effects
3618 *want3D
= wxTheApp
->GetAuto3D();
3620 // 2) If the parent is being drawn with user colours, or simple border specified,
3621 // switch effects off. TODO: replace wxUSER_COLOURS with wxNO_3D
3622 if (GetParent() && (GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
) || (m_windowStyle
& wxSIMPLE_BORDER
))
3625 // 3) Control can override this global setting by defining
3626 // a border style, e.g. wxSUNKEN_BORDER
3627 if (m_windowStyle
& wxSUNKEN_BORDER
)
3630 // 4) If it's a special border, CTL3D can't cope so we want a native border
3631 if ( (m_windowStyle
& wxDOUBLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
3632 (m_windowStyle
& wxSTATIC_BORDER
) )
3635 nativeBorder
= TRUE
;
3638 // 5) If this isn't a Win95 app, and we are using CTL3D, remove border
3639 // effects from extended style
3642 nativeBorder
= FALSE
;
3645 DWORD exStyle
= MakeExtendedStyle(m_windowStyle
, !nativeBorder
);
3647 // If we want 3D, but haven't specified a border here,
3648 // apply the default border style specified.
3649 // TODO what about non-Win95 WIN32? Does it have borders?
3650 #if defined(__WIN95__) && !CTL3D
3651 if (defaultBorderStyle
&& (*want3D
) && ! ((m_windowStyle
& wxDOUBLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
3652 (m_windowStyle
& wxSTATIC_BORDER
) || (m_windowStyle
& wxSIMPLE_BORDER
) ))
3653 exStyle
|= defaultBorderStyle
; // WS_EX_CLIENTEDGE ;
3659 void wxWindow::OnChar(wxKeyEvent
& event
)
3661 if ( event
.KeyCode() == WXK_TAB
) {
3662 // propagate the TABs to the parent - it's up to it to decide what
3664 if ( GetParent() ) {
3665 if ( GetParent()->ProcessEvent(event
) )
3671 int id
= wxCharCodeWXToMSW((int)event
.KeyCode(), &isVirtual
);
3676 if ( !event
.ControlDown() )
3677 (void) MSWDefWindowProc(m_lastMsg
, (WPARAM
) id
, m_lastLParam
);
3680 void wxWindow::OnPaint(wxPaintEvent
& event
)
3685 bool wxWindow::IsEnabled(void) const
3687 return (::IsWindowEnabled((HWND
) GetHWND()) != 0);
3690 // Dialog support: override these and call
3691 // base class members to add functionality
3692 // that can't be done using validators.
3693 // NOTE: these functions assume that controls
3694 // are direct children of this window, not grandchildren
3695 // or other levels of descendant.
3697 // Transfer values to controls. If returns FALSE,
3698 // it's an application error (pops up a dialog)
3699 bool wxWindow::TransferDataToWindow(void)
3701 wxNode
*node
= GetChildren()->First();
3704 wxWindow
*child
= (wxWindow
*)node
->Data();
3705 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */
3706 !child
->GetValidator()->TransferToWindow() )
3708 wxMessageBox("Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
3712 node
= node
->Next();
3717 // Transfer values from controls. If returns FALSE,
3718 // validation failed: don't quit
3719 bool wxWindow::TransferDataFromWindow(void)
3721 wxNode
*node
= GetChildren()->First();
3724 wxWindow
*child
= (wxWindow
*)node
->Data();
3725 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->TransferFromWindow() )
3730 node
= node
->Next();
3735 bool wxWindow::Validate(void)
3737 wxNode
*node
= GetChildren()->First();
3740 wxWindow
*child
= (wxWindow
*)node
->Data();
3741 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
3746 node
= node
->Next();
3751 // Get the window with the focus
3752 wxWindow
*wxWindow::FindFocus(void)
3754 HWND hWnd
= ::GetFocus();
3757 return wxFindWinFromHandle((WXHWND
) hWnd
);
3762 void wxWindow::AddChild(wxWindow
*child
)
3764 GetChildren()->Append(child
);
3765 child
->m_windowParent
= this;
3768 void wxWindow::RemoveChild(wxWindow
*child
)
3771 GetChildren()->DeleteObject(child
);
3772 child
->m_windowParent
= NULL
;
3775 void wxWindow::DestroyChildren(void)
3777 if (GetChildren()) {
3779 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
) {
3781 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
3783 if ( GetChildren()->Member(child
) )
3790 void wxWindow::MakeModal(bool modal
)
3792 // Disable all other windows
3793 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
3795 wxNode
*node
= wxTopLevelWindows
.First();
3798 wxWindow
*win
= (wxWindow
*)node
->Data();
3800 win
->Enable(!modal
);
3802 node
= node
->Next();
3807 // If nothing defined for this, try the parent.
3808 // E.g. we may be a button loaded from a resource, with no callback function
3810 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
3812 if (GetEventHandler()->ProcessEvent(event
) )
3815 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
3818 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
3822 UnsetConstraints(m_constraints
);
3823 delete m_constraints
;
3828 // Make sure other windows know they're part of a 'meaningful relationship'
3829 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
3830 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3831 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
3832 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3833 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
3834 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3835 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
3836 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3837 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
3838 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3839 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
3840 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3841 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
3842 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3843 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
3844 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3848 // This removes any dangling pointers to this window
3849 // in other windows' constraintsInvolvedIn lists.
3850 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
3854 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
3855 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3856 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
3857 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3858 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
3859 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3860 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
3861 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3862 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
3863 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3864 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
3865 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3866 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
3867 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3868 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
3869 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3873 // Back-pointer to other windows we're involved with, so if we delete
3874 // this window, we must delete any constraints we're involved with.
3875 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
3877 if (!m_constraintsInvolvedIn
)
3878 m_constraintsInvolvedIn
= new wxList
;
3879 if (!m_constraintsInvolvedIn
->Member(otherWin
))
3880 m_constraintsInvolvedIn
->Append(otherWin
);
3883 // REMOVE back-pointer to other windows we're involved with.
3884 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
3886 if (m_constraintsInvolvedIn
)
3887 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
3890 // Reset any constraints that mention this window
3891 void wxWindow::DeleteRelatedConstraints(void)
3893 if (m_constraintsInvolvedIn
)
3895 wxNode
*node
= m_constraintsInvolvedIn
->First();
3898 wxWindow
*win
= (wxWindow
*)node
->Data();
3899 wxNode
*next
= node
->Next();
3900 wxLayoutConstraints
*constr
= win
->GetConstraints();
3902 // Reset any constraints involving this window
3905 constr
->left
.ResetIfWin((wxWindow
*)this);
3906 constr
->top
.ResetIfWin((wxWindow
*)this);
3907 constr
->right
.ResetIfWin((wxWindow
*)this);
3908 constr
->bottom
.ResetIfWin((wxWindow
*)this);
3909 constr
->width
.ResetIfWin((wxWindow
*)this);
3910 constr
->height
.ResetIfWin((wxWindow
*)this);
3911 constr
->centreX
.ResetIfWin((wxWindow
*)this);
3912 constr
->centreY
.ResetIfWin((wxWindow
*)this);
3917 delete m_constraintsInvolvedIn
;
3918 m_constraintsInvolvedIn
= NULL
;
3922 void wxWindow::SetSizer(wxSizer
*sizer
)
3924 m_windowSizer
= sizer
;
3926 sizer
->SetSizerParent((wxWindow
*)this);
3933 bool wxWindow::Layout(void)
3935 if (GetConstraints())
3938 GetClientSize(&w
, &h
);
3939 GetConstraints()->width
.SetValue(w
);
3940 GetConstraints()->height
.SetValue(h
);
3943 // If top level (one sizer), evaluate the sizer's constraints.
3947 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
3948 GetSizer()->LayoutPhase1(&noChanges
);
3949 GetSizer()->LayoutPhase2(&noChanges
);
3950 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
3955 // Otherwise, evaluate child constraints
3956 ResetConstraints(); // Mark all constraints as unevaluated
3957 DoPhase(1); // Just one phase need if no sizers involved
3959 SetConstraintSizes(); // Recursively set the real window sizes
3965 // Do a phase of evaluating constraints:
3966 // the default behaviour. wxSizers may do a similar
3967 // thing, but also impose their own 'constraints'
3968 // and order the evaluation differently.
3969 bool wxWindow::LayoutPhase1(int *noChanges
)
3971 wxLayoutConstraints
*constr
= GetConstraints();
3974 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
3980 bool wxWindow::LayoutPhase2(int *noChanges
)
3990 // Do a phase of evaluating child constraints
3991 bool wxWindow::DoPhase(int phase
)
3993 int noIterations
= 0;
3994 int maxIterations
= 500;
3998 while ((noChanges
> 0) && (noIterations
< maxIterations
))
4002 wxNode
*node
= GetChildren()->First();
4005 wxWindow
*child
= (wxWindow
*)node
->Data();
4006 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
4008 wxLayoutConstraints
*constr
= child
->GetConstraints();
4011 if (succeeded
.Member(child
))
4016 int tempNoChanges
= 0;
4017 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
4018 noChanges
+= tempNoChanges
;
4021 succeeded
.Append(child
);
4026 node
= node
->Next();
4033 void wxWindow::ResetConstraints(void)
4035 wxLayoutConstraints
*constr
= GetConstraints();
4038 constr
->left
.SetDone(FALSE
);
4039 constr
->top
.SetDone(FALSE
);
4040 constr
->right
.SetDone(FALSE
);
4041 constr
->bottom
.SetDone(FALSE
);
4042 constr
->width
.SetDone(FALSE
);
4043 constr
->height
.SetDone(FALSE
);
4044 constr
->centreX
.SetDone(FALSE
);
4045 constr
->centreY
.SetDone(FALSE
);
4047 wxNode
*node
= GetChildren()->First();
4050 wxWindow
*win
= (wxWindow
*)node
->Data();
4051 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
4052 win
->ResetConstraints();
4053 node
= node
->Next();
4057 // Need to distinguish between setting the 'fake' size for
4058 // windows and sizers, and setting the real values.
4059 void wxWindow::SetConstraintSizes(bool recurse
)
4061 wxLayoutConstraints
*constr
= GetConstraints();
4062 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
4063 constr
->width
.GetDone() && constr
->height
.GetDone())
4065 int x
= constr
->left
.GetValue();
4066 int y
= constr
->top
.GetValue();
4067 int w
= constr
->width
.GetValue();
4068 int h
= constr
->height
.GetValue();
4070 // If we don't want to resize this window, just move it...
4071 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
4072 (constr
->height
.GetRelationship() != wxAsIs
))
4074 // Calls Layout() recursively. AAAGH. How can we stop that.
4075 // Simply take Layout() out of non-top level OnSizes.
4076 SizerSetSize(x
, y
, w
, h
);
4085 char *windowClass
= this->GetClassInfo()->GetClassName();
4088 if (GetName() == "")
4089 winName
= "unnamed";
4091 winName
= GetName();
4092 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
4093 if (!constr
->left
.GetDone())
4094 wxDebugMsg(" unsatisfied 'left' constraint.\n");
4095 if (!constr
->right
.GetDone())
4096 wxDebugMsg(" unsatisfied 'right' constraint.\n");
4097 if (!constr
->width
.GetDone())
4098 wxDebugMsg(" unsatisfied 'width' constraint.\n");
4099 if (!constr
->height
.GetDone())
4100 wxDebugMsg(" unsatisfied 'height' constraint.\n");
4101 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
4106 wxNode
*node
= GetChildren()->First();
4109 wxWindow
*win
= (wxWindow
*)node
->Data();
4110 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
4111 win
->SetConstraintSizes();
4112 node
= node
->Next();
4117 // This assumes that all sizers are 'on' the same
4118 // window, i.e. the parent of this window.
4119 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
4121 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
4122 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
4126 m_sizerParent
->GetPosition(&xp
, &yp
);
4127 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
4132 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
4136 TransformSizerToActual(&xx
, &yy
);
4137 SetSize(xx
, yy
, w
, h
);
4140 void wxWindow::SizerMove(int x
, int y
)
4144 TransformSizerToActual(&xx
, &yy
);
4148 // Only set the size/position of the constraint (if any)
4149 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
4151 wxLayoutConstraints
*constr
= GetConstraints();
4156 constr
->left
.SetValue(x
);
4157 constr
->left
.SetDone(TRUE
);
4161 constr
->top
.SetValue(y
);
4162 constr
->top
.SetDone(TRUE
);
4166 constr
->width
.SetValue(w
);
4167 constr
->width
.SetDone(TRUE
);
4171 constr
->height
.SetValue(h
);
4172 constr
->height
.SetDone(TRUE
);
4177 void wxWindow::MoveConstraint(int x
, int y
)
4179 wxLayoutConstraints
*constr
= GetConstraints();
4184 constr
->left
.SetValue(x
);
4185 constr
->left
.SetDone(TRUE
);
4189 constr
->top
.SetValue(y
);
4190 constr
->top
.SetDone(TRUE
);
4195 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
4197 wxLayoutConstraints
*constr
= GetConstraints();
4200 *w
= constr
->width
.GetValue();
4201 *h
= constr
->height
.GetValue();
4207 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
4209 wxLayoutConstraints
*constr
= GetConstraints();
4212 *w
= constr
->width
.GetValue();
4213 *h
= constr
->height
.GetValue();
4216 GetClientSize(w
, h
);
4219 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
4221 wxLayoutConstraints
*constr
= GetConstraints();
4224 *x
= constr
->left
.GetValue();
4225 *y
= constr
->top
.GetValue();
4231 bool wxWindow::Close(bool force
)
4233 // Let's generalise it to work the same for any window.
4235 if (!IsKindOf(CLASSINFO(wxDialog)) && !IsKindOf(CLASSINFO(wxFrame)))
4242 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
4243 event
.SetEventObject(this);
4244 event
.SetForce(force
);
4246 return GetEventHandler()->ProcessEvent(event
);
4249 if ( !force && event.GetVeto() )
4254 if (!wxPendingDelete.Member(this))
4255 wxPendingDelete.Append(this);
4261 wxObject
* wxWindow::GetChild(int number
) const
4263 // Return a pointer to the Nth object in the Panel
4266 wxNode
*node
= GetChildren()->First();
4269 node
= node
->Next() ;
4272 wxObject
*obj
= (wxObject
*)node
->Data();
4279 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
4281 /* This is obsolete now; if we wish to intercept listbox double-clicks,
4282 * we explicitly intercept the wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
4285 if (initiatingItem->IsKindOf(CLASSINFO(wxListBox)))
4287 wxListBox *lbox = (wxListBox *)initiatingItem;
4288 wxCommandEvent event(wxEVT_COMMAND_LEFT_DCLICK);
4289 event.m_commandInt = -1;
4290 if ((lbox->GetWindowStyleFlag() & wxLB_MULTIPLE) == 0)
4292 event.m_commandString = copystring(lbox->GetStringSelection());
4293 event.m_commandInt = lbox->GetSelection();
4294 event.m_clientData = lbox->wxListBox::GetClientData(event.m_commandInt);
4296 event.m_eventObject = lbox;
4298 lbox->ProcessCommand(event);
4300 if (event.m_commandString)
4301 delete[] event.m_commandString;
4305 wxButton *but = GetDefaultItem();
4308 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
4309 event.SetEventObject(but);
4310 but->Command(event);
4315 void wxWindow::Clear(void)
4317 wxClientDC
dc(this);
4318 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
4319 dc
.SetBackground(brush
);
4323 // Fits the panel around the items
4324 void wxWindow::Fit(void)
4328 wxNode
*node
= GetChildren()->First();
4331 wxWindow
*win
= (wxWindow
*)node
->Data();
4333 win
->GetPosition(&wx
, &wy
);
4334 win
->GetSize(&ww
, &wh
);
4335 if ( wx
+ ww
> maxX
)
4337 if ( wy
+ wh
> maxY
)
4340 node
= node
->Next();
4342 SetClientSize(maxX
+ 5, maxY
+ 5);
4345 void wxWindow::SetValidator(const wxValidator
& validator
)
4347 if ( m_windowValidator
)
4348 delete m_windowValidator
;
4349 m_windowValidator
= validator
.Clone();
4351 if ( m_windowValidator
)
4352 m_windowValidator
->SetWindow(this) ;
4355 // Find a window by id or name
4356 wxWindow
*wxWindow::FindWindow(long id
)
4361 wxNode
*node
= GetChildren()->First();
4364 wxWindow
*child
= (wxWindow
*)node
->Data();
4365 wxWindow
*found
= child
->FindWindow(id
);
4368 node
= node
->Next();
4373 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
4375 if ( GetName() == name
)
4378 wxNode
*node
= GetChildren()->First();
4381 wxWindow
*child
= (wxWindow
*)node
->Data();
4382 wxWindow
*found
= child
->FindWindow(name
);
4385 node
= node
->Next();
4391 // Default input behaviour for a scrolling canvas should be to scroll
4392 // according to the cursor keys pressed
4393 void wxWindow::OnChar(wxKeyEvent& event)
4405 GetScrollUnitsPerPage(&x_page, &y_page);
4407 GetVirtualSize(&v_width,&v_height);
4409 ViewStart(&start_x, &start_y);
4412 y_pages = (int)(v_height/vert_units) - y_page;
4420 switch (event.keyCode)
4427 if (start_y - y_page > 0)
4428 Scroll(start_x, start_y - y_page);
4438 if ((y_page > 0) && (start_y <= y_pages-y-1))
4440 if (y_pages + y < start_y + y_page)
4441 Scroll(start_x, y_pages + y);
4443 Scroll(start_x, start_y + y_page);
4450 if ((y_page > 0) && (start_y >= 1))
4451 Scroll(start_x, start_y - 1);
4457 if ((y_page > 0) && (start_y <= y_pages-y-1))
4460 Scroll(start_x, start_y + 1);
4466 if ((x_page > 0) && (start_x >= 1))
4467 Scroll(start_x - 1, start_y);
4473 Scroll(start_x + 1, start_y);
4484 Scroll(start_x, y_pages+y);
4492 // Setup background and foreground colours correctly
4493 void wxWindow::SetupColours(void)
4496 SetBackgroundColour(GetParent()->GetBackgroundColour());
4499 void wxWindow::OnIdle(wxIdleEvent
& event
)
4501 // Check if we need to send a LEAVE event
4502 if (m_mouseInWindow
)
4505 ::GetCursorPos(&pt
);
4506 if (::WindowFromPoint(pt
) != (HWND
) GetHWND())
4508 // Generate a LEAVE event
4509 m_mouseInWindow
= FALSE
;
4510 MSWOnMouseLeave(pt
.x
, pt
.y
, 0);
4516 // Raise the window to the top of the Z order
4517 void wxWindow::Raise(void)
4519 ::BringWindowToTop((HWND
) GetHWND());
4522 // Lower the window to the bottom of the Z order
4523 void wxWindow::Lower(void)
4525 ::SetWindowPos((HWND
) GetHWND(), HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
4528 long wxWindow::MSWGetDlgCode()
4530 // default: just forward to def window proc (the msg has no parameters)
4531 return MSWDefWindowProc(WM_GETDLGCODE
, 0, 0);
4534 bool wxWindow::AcceptsFocus() const
4536 return IsShown() && IsEnabled();
4539 // Update region access
4540 wxRegion
wxWindow::GetUpdateRegion() const
4542 return m_updateRegion
;
4545 bool wxWindow::IsExposed(int x
, int y
, int w
, int h
) const
4547 return (m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
);
4550 bool wxWindow::IsExposed(const wxPoint
& pt
) const
4552 return (m_updateRegion
.Contains(pt
) != wxOutRegion
);
4555 bool wxWindow::IsExposed(const wxRect
& rect
) const
4557 return (m_updateRegion
.Contains(rect
) != wxOutRegion
);
4563 static const char *GetMessageName(int message
)
4565 switch ( message
) {
4566 case 0x0000: return "WM_NULL";
4567 case 0x0001: return "WM_CREATE";
4568 case 0x0002: return "WM_DESTROY";
4569 case 0x0003: return "WM_MOVE";
4570 case 0x0005: return "WM_SIZE";
4571 case 0x0006: return "WM_ACTIVATE";
4572 case 0x0007: return "WM_SETFOCUS";
4573 case 0x0008: return "WM_KILLFOCUS";
4574 case 0x000A: return "WM_ENABLE";
4575 case 0x000B: return "WM_SETREDRAW";
4576 case 0x000C: return "WM_SETTEXT";
4577 case 0x000D: return "WM_GETTEXT";
4578 case 0x000E: return "WM_GETTEXTLENGTH";
4579 case 0x000F: return "WM_PAINT";
4580 case 0x0010: return "WM_CLOSE";
4581 case 0x0011: return "WM_QUERYENDSESSION";
4582 case 0x0012: return "WM_QUIT";
4583 case 0x0013: return "WM_QUERYOPEN";
4584 case 0x0014: return "WM_ERASEBKGND";
4585 case 0x0015: return "WM_SYSCOLORCHANGE";
4586 case 0x0016: return "WM_ENDSESSION";
4587 case 0x0017: return "WM_SYSTEMERROR";
4588 case 0x0018: return "WM_SHOWWINDOW";
4589 case 0x0019: return "WM_CTLCOLOR";
4590 case 0x001A: return "WM_WININICHANGE";
4591 case 0x001B: return "WM_DEVMODECHANGE";
4592 case 0x001C: return "WM_ACTIVATEAPP";
4593 case 0x001D: return "WM_FONTCHANGE";
4594 case 0x001E: return "WM_TIMECHANGE";
4595 case 0x001F: return "WM_CANCELMODE";
4596 case 0x0020: return "WM_SETCURSOR";
4597 case 0x0021: return "WM_MOUSEACTIVATE";
4598 case 0x0022: return "WM_CHILDACTIVATE";
4599 case 0x0023: return "WM_QUEUESYNC";
4600 case 0x0024: return "WM_GETMINMAXINFO";
4601 case 0x0026: return "WM_PAINTICON";
4602 case 0x0027: return "WM_ICONERASEBKGND";
4603 case 0x0028: return "WM_NEXTDLGCTL";
4604 case 0x002A: return "WM_SPOOLERSTATUS";
4605 case 0x002B: return "WM_DRAWITEM";
4606 case 0x002C: return "WM_MEASUREITEM";
4607 case 0x002D: return "WM_DELETEITEM";
4608 case 0x002E: return "WM_VKEYTOITEM";
4609 case 0x002F: return "WM_CHARTOITEM";
4610 case 0x0030: return "WM_SETFONT";
4611 case 0x0031: return "WM_GETFONT";
4612 case 0x0037: return "WM_QUERYDRAGICON";
4613 case 0x0039: return "WM_COMPAREITEM";
4614 case 0x0041: return "WM_COMPACTING";
4615 case 0x0044: return "WM_COMMNOTIFY";
4616 case 0x0046: return "WM_WINDOWPOSCHANGING";
4617 case 0x0047: return "WM_WINDOWPOSCHANGED";
4618 case 0x0048: return "WM_POWER";
4619 case 0x0081: return "WM_NCCREATE";
4620 case 0x0082: return "WM_NCDESTROY";
4621 case 0x0083: return "WM_NCCALCSIZE";
4622 case 0x0084: return "WM_NCHITTEST";
4623 case 0x0085: return "WM_NCPAINT";
4624 case 0x0086: return "WM_NCACTIVATE";
4625 case 0x0087: return "WM_GETDLGCODE";
4626 case 0x00A0: return "WM_NCMOUSEMOVE";
4627 case 0x00A1: return "WM_NCLBUTTONDOWN";
4628 case 0x00A2: return "WM_NCLBUTTONUP";
4629 case 0x00A3: return "WM_NCLBUTTONDBLCLK";
4630 case 0x00A4: return "WM_NCRBUTTONDOWN";
4631 case 0x00A5: return "WM_NCRBUTTONUP";
4632 case 0x00A6: return "WM_NCRBUTTONDBLCLK";
4633 case 0x00A7: return "WM_NCMBUTTONDOWN";
4634 case 0x00A8: return "WM_NCMBUTTONUP";
4635 case 0x00A9: return "WM_NCMBUTTONDBLCLK";
4636 case 0x0100: return "WM_KEYDOWN";
4637 case 0x0101: return "WM_KEYUP";
4638 case 0x0102: return "WM_CHAR";
4639 case 0x0103: return "WM_DEADCHAR";
4640 case 0x0104: return "WM_SYSKEYDOWN";
4641 case 0x0105: return "WM_SYSKEYUP";
4642 case 0x0106: return "WM_SYSCHAR";
4643 case 0x0107: return "WM_SYSDEADCHAR";
4644 case 0x0108: return "WM_KEYLAST";
4645 case 0x0110: return "WM_INITDIALOG";
4646 case 0x0111: return "WM_COMMAND";
4647 case 0x0112: return "WM_SYSCOMMAND";
4648 case 0x0113: return "WM_TIMER";
4649 case 0x0114: return "WM_HSCROLL";
4650 case 0x0115: return "WM_VSCROLL";
4651 case 0x0116: return "WM_INITMENU";
4652 case 0x0117: return "WM_INITMENUPOPUP";
4653 case 0x011F: return "WM_MENUSELECT";
4654 case 0x0120: return "WM_MENUCHAR";
4655 case 0x0121: return "WM_ENTERIDLE";
4656 case 0x0200: return "WM_MOUSEMOVE";
4657 case 0x0201: return "WM_LBUTTONDOWN";
4658 case 0x0202: return "WM_LBUTTONUP";
4659 case 0x0203: return "WM_LBUTTONDBLCLK";
4660 case 0x0204: return "WM_RBUTTONDOWN";
4661 case 0x0205: return "WM_RBUTTONUP";
4662 case 0x0206: return "WM_RBUTTONDBLCLK";
4663 case 0x0207: return "WM_MBUTTONDOWN";
4664 case 0x0208: return "WM_MBUTTONUP";
4665 case 0x0209: return "WM_MBUTTONDBLCLK";
4666 case 0x0210: return "WM_PARENTNOTIFY";
4667 case 0x0220: return "WM_MDICREATE";
4668 case 0x0221: return "WM_MDIDESTROY";
4669 case 0x0222: return "WM_MDIACTIVATE";
4670 case 0x0223: return "WM_MDIRESTORE";
4671 case 0x0224: return "WM_MDINEXT";
4672 case 0x0225: return "WM_MDIMAXIMIZE";
4673 case 0x0226: return "WM_MDITILE";
4674 case 0x0227: return "WM_MDICASCADE";
4675 case 0x0228: return "WM_MDIICONARRANGE";
4676 case 0x0229: return "WM_MDIGETACTIVE";
4677 case 0x0230: return "WM_MDISETMENU";
4678 case 0x0233: return "WM_DROPFILES";
4679 case 0x0300: return "WM_CUT";
4680 case 0x0301: return "WM_COPY";
4681 case 0x0302: return "WM_PASTE";
4682 case 0x0303: return "WM_CLEAR";
4683 case 0x0304: return "WM_UNDO";
4684 case 0x0305: return "WM_RENDERFORMAT";
4685 case 0x0306: return "WM_RENDERALLFORMATS";
4686 case 0x0307: return "WM_DESTROYCLIPBOARD";
4687 case 0x0308: return "WM_DRAWCLIPBOARD";
4688 case 0x0309: return "WM_PAINTCLIPBOARD";
4689 case 0x030A: return "WM_VSCROLLCLIPBOARD";
4690 case 0x030B: return "WM_SIZECLIPBOARD";
4691 case 0x030C: return "WM_ASKCBFORMATNAME";
4692 case 0x030D: return "WM_CHANGECBCHAIN";
4693 case 0x030E: return "WM_HSCROLLCLIPBOARD";
4694 case 0x030F: return "WM_QUERYNEWPALETTE";
4695 case 0x0310: return "WM_PALETTEISCHANGING";
4696 case 0x0311: return "WM_PALETTECHANGED";
4698 static char s_szBuf
[128];
4699 sprintf(s_szBuf
, "<unknown message = %d>", message
);