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"
49 #include "wx/msw/private.h"
63 #include <wx/msw/gnuwin32/extra.h>
82 #define WINDOW_MARGIN 3 // This defines sensitivity of Leave events
84 wxMenu
*wxCurrentPopupMenu
= NULL
;
85 extern wxList wxPendingDelete
;
87 void wxRemoveHandleAssociation(wxWindow
*win
);
88 void wxAssociateWinWithHandle(HWND hWnd
, wxWindow
*win
);
89 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
);
91 #if !USE_SHARED_LIBRARY
92 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxEvtHandler
)
94 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
95 EVT_CHAR(wxWindow::OnChar
)
96 EVT_SIZE(wxWindow::OnSize
)
97 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground
)
98 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
99 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
100 EVT_IDLE(wxWindow::OnIdle
)
105 // Find an item given the MS Windows id
106 wxWindow
*wxWindow::FindItem(int id
) const
110 wxNode
*current
= GetChildren()->First();
113 wxWindow
*childWin
= (wxWindow
*)current
->Data();
115 wxWindow
*wnd
= childWin
->FindItem(id
) ;
119 if (childWin
->IsKindOf(CLASSINFO(wxControl
)))
121 wxControl
*item
= (wxControl
*)childWin
;
122 if (item
->m_windowId
== id
)
126 // In case it's a 'virtual' control (e.g. radiobox)
127 if (item
->GetSubcontrols().Member((wxObject
*)id
))
131 current
= current
->Next();
136 // Find an item given the MS Windows handle
137 wxWindow
*wxWindow::FindItemByHWND(WXHWND hWnd
, bool controlOnly
) const
141 wxNode
*current
= GetChildren()->First();
144 wxObject
*obj
= (wxObject
*)current
->Data() ;
145 // Do a recursive search.
146 wxWindow
*parent
= (wxWindow
*)obj
;
147 wxWindow
*wnd
= parent
->FindItemByHWND(hWnd
) ;
151 if ((!controlOnly
) || obj
->IsKindOf(CLASSINFO(wxControl
)))
153 wxWindow
*item
= (wxWindow
*)current
->Data();
154 if ((HWND
)(item
->GetHWND()) == (HWND
) hWnd
)
158 if ( item
->ContainsHWND(hWnd
) )
162 current
= current
->Next();
167 // Default command handler
168 bool wxWindow::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
173 bool wxWindow::MSWNotify(WXWPARAM
WXUNUSED(wParam
), WXLPARAM
WXUNUSED(lParam
))
178 void wxWindow::PreDelete(WXHDC
WXUNUSED(dc
))
182 WXHWND
wxWindow::GetHWND(void) const
184 return (WXHWND
) m_hWnd
;
187 void wxWindow::SetHWND(WXHWND hWnd
)
193 wxWindow::wxWindow(void)
199 m_windowParent
= NULL
;
200 m_windowEventHandler
= this;
202 m_windowCursor
= *wxSTANDARD_CURSOR
;
203 m_children
= new wxList
;
204 m_doubleClickAllowed
= 0 ;
205 m_winCaptured
= FALSE
;
206 m_constraints
= NULL
;
207 m_constraintsInvolvedIn
= NULL
;
208 m_windowSizer
= NULL
;
209 m_sizerParent
= NULL
;
210 m_autoLayout
= FALSE
;
211 m_windowValidator
= NULL
;
216 m_caretWidth
= 0; m_caretHeight
= 0;
217 m_caretEnabled
= FALSE
;
218 m_caretShown
= FALSE
;
226 m_isBeingDeleted
= FALSE
;
233 m_defaultItem
= NULL
;
235 wxSystemSettings settings
;
237 m_backgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_WINDOW
) ; ;
238 m_foregroundColour
= *wxBLACK
;
239 m_defaultForegroundColour
= *wxBLACK
;
240 m_defaultBackgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
243 wxColour(GetRValue(GetSysColor(COLOR_WINDOW)),
244 GetGValue(GetSysColor(COLOR_BTNFACE)), GetBValue(GetSysColor(COLOR_BTNFACE)));
251 m_acceleratorTable
= 0;
256 m_backgroundTransparent
= FALSE
;
258 m_lastXPos
= (float)-1.0;
259 m_lastYPos
= (float)-1.0;
263 #if USE_DRAG_AND_DROP
264 m_pDropTarget
= NULL
;
269 wxWindow::~wxWindow(void)
271 m_isBeingDeleted
= TRUE
;
273 // JACS - if behaviour is odd, restore this
274 // to the start of ~wxWindow. Vadim has changed
275 // it to nearer the end. Unsure of side-effects
276 // e.g. when deleting associated global data.
277 // Restore old Window proc, if required
280 // Have to delete constraints/sizer FIRST otherwise
281 // sizers may try to look at deleted windows as they
282 // delete themselves.
284 DeleteRelatedConstraints();
287 // This removes any dangling pointers to this window
288 // in other windows' constraintsInvolvedIn lists.
289 UnsetConstraints(m_constraints
);
290 delete m_constraints
;
291 m_constraints
= NULL
;
295 delete m_windowSizer
;
296 m_windowSizer
= NULL
;
298 // If this is a child of a sizer, remove self from parent
300 m_sizerParent
->RemoveChild((wxWindow
*)this);
304 MSWDetachWindowMenu();
306 // TODO for backward compatibility
311 HWND hWnd
= (HWND
) GetHWND();
312 HDC dc
= ::GetDC(hWnd
);
313 m_windowDC
->SelectOldObjects (dc
);
320 m_windowParent
->RemoveChild(this);
325 ::DestroyWindow((HWND
)m_hWnd
);
327 wxRemoveHandleAssociation(this);
332 GlobalFree((HGLOBAL
) m_globalHandle
);
340 // Just in case the window has been Closed, but
341 // we're then deleting immediately: don't leave
342 // dangling pointers.
343 wxPendingDelete
.DeleteObject(this);
345 // Just in case we've loaded a top-level window via
346 // wxWindow::LoadNativeDialog but we weren't a dialog
348 wxTopLevelWindows
.DeleteObject(this);
350 // if (GetFont() && GetFont()->Ok())
351 // GetFont()->ReleaseResource();
353 if ( m_windowValidator
)
354 delete m_windowValidator
;
356 // Restore old Window proc, if required
357 // and remove hWnd <-> wxWindow association
361 // Destroy the window (delayed, if a managed window)
362 bool wxWindow::Destroy(void)
368 extern char wxCanvasClassName
[];
371 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
375 const wxString
& name
)
378 m_isBeingDeleted
= FALSE
;
382 m_windowParent
= NULL
;
383 m_windowEventHandler
= this;
384 // m_windowFont = NULL;
385 // We don't wish internal (potentially transient) fonts to be found
387 // wxTheFontList->RemoveFont(& m_windowFont);
389 m_windowCursor
= *wxSTANDARD_CURSOR
;
390 m_doubleClickAllowed
= 0 ;
391 m_winCaptured
= FALSE
;
392 m_constraints
= NULL
;
393 m_constraintsInvolvedIn
= NULL
;
394 m_windowSizer
= NULL
;
395 m_sizerParent
= NULL
;
396 m_autoLayout
= FALSE
;
397 m_windowValidator
= NULL
;
398 #if USE_DRAG_AND_DROP
399 m_pDropTarget
= NULL
;
405 m_caretWidth
= 0; m_caretHeight
= 0;
406 m_caretEnabled
= FALSE
;
407 m_caretShown
= FALSE
;
420 m_defaultItem
= NULL
;
421 m_windowParent
= NULL
;
422 // m_windowDC = NULL;
423 m_mouseInWindow
= FALSE
;
427 if (parent
) parent
->AddChild(this);
433 m_acceleratorTable
= 0;
438 m_backgroundTransparent
= FALSE
;
440 m_lastXPos
= (float)-1.0;
441 m_lastYPos
= (float)-1.0;
448 m_windowId
= (int)NewControlId();
457 wxSystemSettings settings
;
459 m_backgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_WINDOW
) ; ;
460 m_foregroundColour
= *wxBLACK
;
461 m_defaultForegroundColour
= *wxBLACK
;
462 m_defaultBackgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
464 m_defaultBackgroundColour = wxColour(GetRValue(GetSysColor(COLOR_BTNFACE)),
465 GetGValue(GetSysColor(COLOR_BTNFACE)), GetBValue(GetSysColor(COLOR_BTNFACE)));
468 m_windowStyle
= style
;
471 if (style
& wxBORDER
)
472 msflags
|= WS_BORDER
;
473 if (style
& wxTHICK_FRAME
)
474 msflags
|= WS_THICKFRAME
;
476 msflags
|= WS_CHILD
| WS_VISIBLE
;
477 if (style
& wxCLIP_CHILDREN
)
478 msflags
|= WS_CLIPCHILDREN
;
481 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
) ;
483 // Even with extended styles, need to combine with WS_BORDER
484 // for them to look right.
485 if (want3D
|| (m_windowStyle
& wxSIMPLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
486 (m_windowStyle
& wxSUNKEN_BORDER
) || (m_windowStyle
& wxDOUBLE_BORDER
))
487 msflags
|= WS_BORDER
;
489 m_mouseInWindow
= FALSE
;
492 m_windowId
= (int)NewControlId();
496 MSWCreate(m_windowId
, (wxWindow
*)parent
, wxCanvasClassName
, this, NULL
, x
, y
, width
, height
, msflags
,
502 void wxWindow::SetFocus(void)
504 HWND hWnd
= (HWND
) GetHWND();
509 void wxWindow::Enable(bool enable
)
511 m_winEnabled
= enable
;
512 HWND hWnd
= (HWND
) GetHWND();
514 ::EnableWindow(hWnd
, (BOOL
)enable
);
517 void wxWindow::CaptureMouse(void)
519 HWND hWnd
= (HWND
) GetHWND();
520 if (hWnd
&& !m_winCaptured
)
523 m_winCaptured
= TRUE
;
527 void wxWindow::ReleaseMouse(void)
532 m_winCaptured
= FALSE
;
536 // Push/pop event handler (i.e. allow a chain of event handlers
538 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
540 handler
->SetNextHandler(GetEventHandler());
541 SetEventHandler(handler
);
544 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
546 if ( GetEventHandler() )
548 wxEvtHandler
*handlerA
= GetEventHandler();
549 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
550 handlerA
->SetNextHandler(NULL
);
551 SetEventHandler(handlerB
);
564 #if USE_DRAG_AND_DROP
566 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
568 if ( m_pDropTarget
!= 0 ) {
569 m_pDropTarget
->Revoke(m_hWnd
);
570 delete m_pDropTarget
;
573 m_pDropTarget
= pDropTarget
;
574 if ( m_pDropTarget
!= 0 )
575 m_pDropTarget
->Register(m_hWnd
);
580 //old style file-manager drag&drop support
581 // I think we should retain the old-style
582 // DragAcceptFiles in parallel with SetDropTarget.
584 void wxWindow::DragAcceptFiles(bool accept
)
586 HWND hWnd
= (HWND
) GetHWND();
588 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
592 void wxWindow::GetSize(int *x
, int *y
) const
594 HWND hWnd
= (HWND
) GetHWND();
596 GetWindowRect(hWnd
, &rect
);
597 *x
= rect
.right
- rect
.left
;
598 *y
= rect
.bottom
- rect
.top
;
601 void wxWindow::GetPosition(int *x
, int *y
) const
603 HWND hWnd
= (HWND
) GetHWND();
606 hParentWnd
= (HWND
) GetParent()->GetHWND();
609 GetWindowRect(hWnd
, &rect
);
611 // Since we now have the absolute screen coords,
612 // if there's a parent we must subtract its top left corner
618 ::ScreenToClient(hParentWnd
, &point
);
624 void wxWindow::ScreenToClient(int *x
, int *y
) const
626 HWND hWnd
= (HWND
) GetHWND();
630 ::ScreenToClient(hWnd
, &pt
);
636 void wxWindow::ClientToScreen(int *x
, int *y
) const
638 HWND hWnd
= (HWND
) GetHWND();
642 ::ClientToScreen(hWnd
, &pt
);
648 void wxWindow::SetCursor(const wxCursor
& cursor
)
650 m_windowCursor
= cursor
;
651 if (m_windowCursor
.Ok())
653 HWND hWnd
= (HWND
) GetHWND();
655 // Change the cursor NOW if we're within the correct window
657 ::GetCursorPos(&point
);
660 ::GetWindowRect(hWnd
, &rect
);
662 if (::PtInRect(&rect
, point
) && !wxIsBusy())
663 ::SetCursor((HCURSOR
) m_windowCursor
.GetHCURSOR());
666 // This will cause big reentrancy problems if wxFlushEvents is implemented.
668 // return old_cursor;
672 // Get size *available for subwindows* i.e. excluding menu bar etc.
673 // For XView, this is the same as GetSize
674 void wxWindow::GetClientSize(int *x
, int *y
) const
676 HWND hWnd
= (HWND
) GetHWND();
678 GetClientRect(hWnd
, &rect
);
683 void wxWindow::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
685 int currentX
, currentY
;
686 GetPosition(¤tX
, ¤tY
);
687 int actualWidth
= width
;
688 int actualHeight
= height
;
691 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
693 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
696 int currentW
,currentH
;
697 GetSize(¤tW
, ¤tH
);
699 actualWidth
= currentW
;
701 actualHeight
= currentH
;
703 HWND hWnd
= (HWND
) GetHWND();
705 MoveWindow(hWnd
, actualX
, actualY
, actualWidth
, actualHeight
, (BOOL
)TRUE
);
708 void wxWindow::SetClientSize(int width
, int height
)
710 wxWindow
*parent
= GetParent();
711 HWND hWnd
= (HWND
) GetHWND();
712 HWND hParentWnd
= (HWND
) (HWND
) parent
->GetHWND();
715 GetClientRect(hWnd
, &rect
);
718 GetWindowRect(hWnd
, &rect2
);
720 // Find the difference between the entire window (title bar and all)
721 // and the client area; add this to the new client size to move the
723 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
724 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
726 // If there's a parent, must subtract the parent's top left corner
727 // since MoveWindow moves relative to the parent
730 point
.x
= rect2
.left
;
734 ::ScreenToClient(hParentWnd
, &point
);
737 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
739 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
740 event
.SetEventObject(this);
741 GetEventHandler()->ProcessEvent(event
);
744 bool wxWindow::Show(bool show
)
746 HWND hWnd
= (HWND
) GetHWND();
752 ShowWindow(hWnd
, (BOOL
)cshow
);
755 BringWindowToTop(hWnd
);
756 // Next line causes a crash on NT, apparently.
757 // UpdateWindow(hWnd); // Should this be here or will it cause inefficiency?
762 bool wxWindow::IsShown(void) const
764 return (::IsWindowVisible((HWND
) GetHWND()) != 0);
767 int wxWindow::GetCharHeight(void) const
769 TEXTMETRIC lpTextMetric
;
770 HWND hWnd
= (HWND
) GetHWND();
771 HDC dc
= ::GetDC(hWnd
);
773 GetTextMetrics(dc
, &lpTextMetric
);
774 ::ReleaseDC(hWnd
, dc
);
776 return lpTextMetric
.tmHeight
;
779 int wxWindow::GetCharWidth(void) const
781 TEXTMETRIC lpTextMetric
;
782 HWND hWnd
= (HWND
) GetHWND();
783 HDC dc
= ::GetDC(hWnd
);
785 GetTextMetrics(dc
, &lpTextMetric
);
786 ::ReleaseDC(hWnd
, dc
);
788 return lpTextMetric
.tmAveCharWidth
;
791 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
792 int *descent
, int *externalLeading
, const wxFont
*theFont
, bool) const
794 wxFont
*fontToUse
= (wxFont
*)theFont
;
796 fontToUse
= (wxFont
*) & m_windowFont
;
798 HWND hWnd
= (HWND
) GetHWND();
799 HDC dc
= ::GetDC(hWnd
);
803 if (fontToUse
&& fontToUse
->Ok())
805 if ((fnt
=(HFONT
) fontToUse
->GetResourceHandle()))
806 was
= SelectObject(dc
,fnt
) ;
811 GetTextExtentPoint(dc
, (const char *)string
, (int)string
.Length(), &sizeRect
);
812 GetTextMetrics(dc
, &tm
);
814 if (fontToUse
&& fnt
&& was
)
815 SelectObject(dc
,was
) ;
821 if (descent
) *descent
= tm
.tmDescent
;
822 if (externalLeading
) *externalLeading
= tm
.tmExternalLeading
;
825 // fontToUse->ReleaseResource();
828 void wxWindow::Refresh(bool eraseBack
, const wxRectangle
*rect
)
830 HWND hWnd
= (HWND
) GetHWND();
836 mswRect
.left
= rect
->x
;
837 mswRect
.top
= rect
->y
;
838 mswRect
.right
= rect
->x
+ rect
->width
;
839 mswRect
.bottom
= rect
->y
+ rect
->height
;
841 ::InvalidateRect(hWnd
, &mswRect
, eraseBack
);
844 ::InvalidateRect(hWnd
, NULL
, eraseBack
);
848 // Hook for new window just as it's being created,
849 // when the window isn't yet associated with the handle
850 wxWindow
*wxWndHook
= NULL
;
853 LRESULT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
855 wxWindow
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
857 if (!wnd
&& wxWndHook
)
859 wxAssociateWinWithHandle(hWnd
, wxWndHook
);
862 wnd
->m_hWnd
= (WXHWND
) hWnd
;
865 wxDebugMsg("hWnd = %d, m_hWnd = %d, msg = %d\n", hWnd
, m_hWnd
, message
);
867 // Stop right here if we don't have a valid handle
868 // in our wxWnd object.
869 if (wnd
&& !wnd
->m_hWnd
) {
870 // wxDebugMsg("Warning: could not find a valid handle, wx_win.cc/wxWndProc.\n");
871 wnd
->m_hWnd
= (WXHWND
) hWnd
;
872 long res
= wnd
->MSWDefWindowProc(message
, wParam
, lParam
);
878 wnd
->m_lastMsg
= message
;
879 wnd
->m_lastWParam
= wParam
;
880 wnd
->m_lastLParam
= lParam
;
883 return wnd
->MSWWindowProc(message
, wParam
, lParam
);
885 return DefWindowProc( hWnd
, message
, wParam
, lParam
);
888 // Should probably have a test for 'genuine' NT
889 #if defined(__WIN32__)
890 #define DIMENSION_TYPE short
892 #define DIMENSION_TYPE int
895 // Main Windows 3 window proc
896 long wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
907 case WM_QUERYDRAGICON
:
911 case WM_RBUTTONDBLCLK
:
914 case WM_MBUTTONDBLCLK
:
917 case WM_LBUTTONDBLCLK
:
923 case WM_INITMENUPOPUP
:
928 case WM_CHAR
: // Always an ASCII character
933 case WM_CTLCOLORLISTBOX
:
934 case WM_CTLCOLORMSGBOX
:
935 case WM_CTLCOLORSCROLLBAR
:
936 case WM_CTLCOLORSTATIC
:
937 case WM_CTLCOLOREDIT
:
938 case WM_SYSCOLORCHANGE
:
942 case WM_QUERYENDSESSION
:
944 case WM_GETMINMAXINFO
:
945 return MSWDefWindowProc(message
, wParam
, lParam
);
950 HWND hWnd
= (HWND
)m_hWnd
;
957 WORD state
= LOWORD(wParam
);
958 WORD minimized
= HIWORD(wParam
);
959 HWND hwnd
= (HWND
)lParam
;
961 WORD state
= (WORD
)wParam
;
962 WORD minimized
= LOWORD(lParam
);
963 HWND hwnd
= (HWND
)HIWORD(lParam
);
965 MSWOnActivate(state
, (minimized
!= 0), (WXHWND
) hwnd
);
971 HWND hwnd
= (HWND
)wParam
;
972 // return OnSetFocus(hwnd);
974 if (MSWOnSetFocus((WXHWND
) hwnd
))
976 else return MSWDefWindowProc(message
, wParam
, lParam
);
981 HWND hwnd
= (HWND
)lParam
;
982 // return OnKillFocus(hwnd);
983 if (MSWOnKillFocus((WXHWND
) hwnd
))
986 return MSWDefWindowProc(message
, wParam
, lParam
);
991 MSWOnCreate((WXLPCREATESTRUCT
) (LPCREATESTRUCT
)lParam
);
997 MSWOnShow((wParam
!= 0), (int) lParam
);
1004 else return MSWDefWindowProc(message
, wParam
, lParam
);
1007 case WM_QUERYDRAGICON
:
1010 if ((hIcon
= (HICON
) MSWOnQueryDragIcon()))
1012 else return MSWDefWindowProc(message
, wParam
, lParam
);
1018 int width
= LOWORD(lParam
);
1019 int height
= HIWORD(lParam
);
1020 MSWOnSize(width
, height
, wParam
);
1024 case WM_WINDOWPOSCHANGING
:
1026 WINDOWPOS
*pos
= (WINDOWPOS
*)lParam
;
1027 MSWOnWindowPosChanging((void *)pos
);
1031 case WM_RBUTTONDOWN
:
1033 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1034 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1035 MSWOnRButtonDown(x
, y
, wParam
);
1040 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1041 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1042 MSWOnRButtonUp(x
, y
, wParam
);
1045 case WM_RBUTTONDBLCLK
:
1047 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1048 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1049 MSWOnRButtonDClick(x
, y
, wParam
);
1052 case WM_MBUTTONDOWN
:
1054 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1055 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1056 MSWOnMButtonDown(x
, y
, wParam
);
1061 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1062 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1063 MSWOnMButtonUp(x
, y
, wParam
);
1066 case WM_MBUTTONDBLCLK
:
1068 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1069 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1070 MSWOnMButtonDClick(x
, y
, wParam
);
1073 case WM_LBUTTONDOWN
:
1075 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1076 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1077 MSWOnLButtonDown(x
, y
, wParam
);
1082 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1083 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1084 MSWOnLButtonUp(x
, y
, wParam
);
1087 case WM_LBUTTONDBLCLK
:
1089 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1090 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1091 MSWOnLButtonDClick(x
, y
, wParam
);
1096 int x
= (DIMENSION_TYPE
) LOWORD(lParam
);
1097 int y
= (DIMENSION_TYPE
) HIWORD(lParam
);
1098 MSWOnMouseMove(x
, y
, wParam
);
1101 case MM_JOY1BUTTONDOWN
:
1103 int x
= LOWORD(lParam
);
1104 int y
= HIWORD(lParam
);
1105 MSWOnJoyDown(wxJOYSTICK1
, x
, y
, wParam
);
1108 case MM_JOY2BUTTONDOWN
:
1110 int x
= LOWORD(lParam
);
1111 int y
= HIWORD(lParam
);
1112 MSWOnJoyDown(wxJOYSTICK2
, x
, y
, wParam
);
1115 case MM_JOY1BUTTONUP
:
1117 int x
= LOWORD(lParam
);
1118 int y
= HIWORD(lParam
);
1119 MSWOnJoyUp(wxJOYSTICK1
, x
, y
, wParam
);
1122 case MM_JOY2BUTTONUP
:
1124 int x
= LOWORD(lParam
);
1125 int y
= HIWORD(lParam
);
1126 MSWOnJoyUp(wxJOYSTICK2
, x
, y
, wParam
);
1131 int x
= LOWORD(lParam
);
1132 int y
= HIWORD(lParam
);
1133 MSWOnJoyMove(wxJOYSTICK1
, x
, y
, wParam
);
1138 int x
= LOWORD(lParam
);
1139 int y
= HIWORD(lParam
);
1140 MSWOnJoyMove(wxJOYSTICK2
, x
, y
, wParam
);
1145 int z
= LOWORD(lParam
);
1146 MSWOnJoyZMove(wxJOYSTICK1
, z
, wParam
);
1151 int z
= LOWORD(lParam
);
1152 MSWOnJoyZMove(wxJOYSTICK2
, z
, wParam
);
1159 else return MSWDefWindowProc(message
, wParam
, lParam
);
1164 return MSWOnSysCommand(wParam
, lParam
);
1170 WORD id
= LOWORD(wParam
);
1171 HWND hwnd
= (HWND
)lParam
;
1172 WORD cmd
= HIWORD(wParam
);
1174 WORD id
= (WORD
)wParam
;
1175 HWND hwnd
= (HWND
)LOWORD(lParam
) ;
1176 WORD cmd
= HIWORD(lParam
);
1178 if (!MSWOnCommand(id
, cmd
, (WXHWND
) hwnd
))
1179 return MSWDefWindowProc(message
, wParam
, lParam
);
1182 #if defined(__WIN95__)
1185 if (!MSWOnNotify(wParam
, lParam
))
1186 return MSWDefWindowProc(message
, wParam
, lParam
);
1193 WORD flags
= HIWORD(wParam
);
1194 HMENU sysmenu
= (HMENU
)lParam
;
1196 WORD flags
= LOWORD(lParam
);
1197 HMENU sysmenu
= (HMENU
)HIWORD(lParam
);
1199 MSWOnMenuHighlight((WORD
)wParam
, flags
, (WXHMENU
) sysmenu
);
1202 case WM_INITMENUPOPUP
:
1204 MSWOnInitMenuPopup((WXHMENU
) (HMENU
)wParam
, (int)LOWORD(lParam
), (HIWORD(lParam
) != 0));
1209 return MSWOnDrawItem((int)wParam
, (WXDRAWITEMSTRUCT
*)lParam
);
1212 case WM_MEASUREITEM
:
1214 return MSWOnMeasureItem((int)wParam
, (WXMEASUREITEMSTRUCT
*)lParam
);
1220 if (wParam
== VK_SHIFT
)
1223 else if (wParam
== VK_CONTROL
)
1226 // Avoid duplicate messages to OnChar
1227 else if ((wParam
!= VK_ESCAPE
) && (wParam
!= VK_SPACE
) && (wParam
!= VK_RETURN
) && (wParam
!= VK_BACK
) && (wParam
!= VK_TAB
))
1229 MSWOnChar((WORD
)wParam
, lParam
);
1230 if (::GetKeyState(VK_CONTROL
)&0x100?TRUE
:FALSE
)
1240 // VZ: WM_KEYUP not processed
1241 case WM_CHAR
: // Always an ASCII character
1243 MSWOnChar((WORD
)wParam
, lParam
, TRUE
);
1250 WORD code
= LOWORD(wParam
);
1251 WORD pos
= HIWORD(wParam
);
1252 HWND control
= (HWND
)lParam
;
1254 WORD code
= (WORD
)wParam
;
1255 WORD pos
= LOWORD(lParam
);
1256 HWND control
= (HWND
)HIWORD(lParam
);
1258 MSWOnHScroll(code
, pos
, (WXHWND
) control
);
1264 WORD code
= LOWORD(wParam
);
1265 WORD pos
= HIWORD(wParam
);
1266 HWND control
= (HWND
)lParam
;
1268 WORD code
= (WORD
)wParam
;
1269 WORD pos
= LOWORD(lParam
);
1270 HWND control
= (HWND
)HIWORD(lParam
);
1272 MSWOnVScroll(code
, pos
, (WXHWND
) control
);
1276 case WM_CTLCOLORBTN
:
1278 int nCtlColor
= CTLCOLOR_BTN
;
1279 HWND control
= (HWND
)lParam
;
1280 HDC pDC
= (HDC
)wParam
;
1281 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1282 message
, wParam
, lParam
);
1285 case WM_CTLCOLORDLG
:
1287 int nCtlColor
= CTLCOLOR_DLG
;
1288 HWND control
= (HWND
)lParam
;
1289 HDC pDC
= (HDC
)wParam
;
1290 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1291 message
, wParam
, lParam
);\
1294 case WM_CTLCOLORLISTBOX
:
1296 int nCtlColor
= CTLCOLOR_LISTBOX
;
1297 HWND control
= (HWND
)lParam
;
1298 HDC pDC
= (HDC
)wParam
;
1299 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1300 message
, wParam
, lParam
);
1303 case WM_CTLCOLORMSGBOX
:
1305 int nCtlColor
= CTLCOLOR_MSGBOX
;
1306 HWND control
= (HWND
)lParam
;
1307 HDC pDC
= (HDC
)wParam
;
1308 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1309 message
, wParam
, lParam
);
1312 case WM_CTLCOLORSCROLLBAR
:
1314 int nCtlColor
= CTLCOLOR_SCROLLBAR
;
1315 HWND control
= (HWND
)lParam
;
1316 HDC pDC
= (HDC
)wParam
;
1317 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1318 message
, wParam
, lParam
);
1321 case WM_CTLCOLORSTATIC
:
1323 int nCtlColor
= CTLCOLOR_STATIC
;
1324 HWND control
= (HWND
)lParam
;
1325 HDC pDC
= (HDC
)wParam
;
1326 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1327 message
, wParam
, lParam
);
1330 case WM_CTLCOLOREDIT
:
1332 int nCtlColor
= CTLCOLOR_EDIT
;
1333 HWND control
= (HWND
)lParam
;
1334 HDC pDC
= (HDC
)wParam
;
1335 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1336 message
, wParam
, lParam
);
1342 HWND control
= (HWND
)LOWORD(lParam
);
1343 int nCtlColor
= (int)HIWORD(lParam
);
1344 HDC pDC
= (HDC
)wParam
;
1345 return (DWORD
)MSWOnCtlColor((WXHDC
) pDC
, (WXHWND
) control
, nCtlColor
,
1346 message
, wParam
, lParam
);
1350 case WM_SYSCOLORCHANGE
:
1352 // Return value of 0 means, we processed it.
1353 if (MSWOnColorChange((WXHWND
) hWnd
, message
, wParam
, lParam
) == 0)
1356 return MSWDefWindowProc(message
, wParam
, lParam
);
1361 // Prevents flicker when dragging
1362 if (IsIconic(hWnd
)) return 1;
1366 if (!MSWOnEraseBkgnd((WXHDC
) (HDC
)wParam
))
1367 return 0; // Default(); MSWDefWindowProc(message, wParam, lParam );
1371 case WM_MDIACTIVATE
:
1374 HWND hWndActivate
= GET_WM_MDIACTIVATE_HWNDACTIVATE(wParam
,lParam
);
1375 HWND hWndDeactivate
= GET_WM_MDIACTIVATE_HWNDDEACT(wParam
,lParam
);
1376 BOOL activate
= GET_WM_MDIACTIVATE_FACTIVATE(hWnd
,wParam
,lParam
);
1377 return MSWOnMDIActivate((long) activate
, (WXHWND
) hWndActivate
, (WXHWND
) hWndDeactivate
);
1379 return MSWOnMDIActivate((BOOL
)wParam
, (HWND
)LOWORD(lParam
),
1380 (HWND
)HIWORD(lParam
));
1385 MSWOnDropFiles(wParam
);
1390 return 0; // MSWOnInitDialog((WXHWND)(HWND)wParam);
1393 case WM_QUERYENDSESSION
:
1395 // Same as WM_CLOSE, but inverted results. Thx Microsoft :-)
1396 return MSWOnClose();
1408 case WM_GETMINMAXINFO
:
1410 MINMAXINFO
*info
= (MINMAXINFO
*)lParam
;
1411 if (m_minSizeX
!= -1)
1412 info
->ptMinTrackSize
.x
= (int)m_minSizeX
;
1413 if (m_minSizeY
!= -1)
1414 info
->ptMinTrackSize
.y
= (int)m_minSizeY
;
1415 if (m_maxSizeX
!= -1)
1416 info
->ptMaxTrackSize
.x
= (int)m_maxSizeX
;
1417 if (m_maxSizeY
!= -1)
1418 info
->ptMaxTrackSize
.y
= (int)m_maxSizeY
;
1419 return MSWDefWindowProc(message
, wParam
, lParam
);
1427 __ddeUnblock(hWnd, wParam);
1431 case ASYNC_SELECT_MESSAGE:
1432 return ddeWindowProc(hWnd,message,wParam,lParam);
1437 return MSWDefWindowProc(message
, wParam
, lParam
);
1439 return 0; // Success: we processed this command.
1442 // Dialog window proc
1443 LONG APIENTRY _EXPORT
1444 wxDlgProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1449 wxList
*wxWinHandleList
= NULL
;
1450 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
)
1452 wxNode
*node
= wxWinHandleList
->Find((long)hWnd
);
1455 return (wxWindow
*)node
->Data();
1458 void wxAssociateWinWithHandle(HWND hWnd
, wxWindow
*win
)
1460 // adding NULL hWnd is (first) surely a result of an error and
1461 // (secondly) breaks menu command processing
1462 wxCHECK_RET( hWnd
!= NULL
, "attempt to add a NULL hWnd to window list" );
1464 if ( !wxWinHandleList
->Find((long)hWnd
) )
1465 wxWinHandleList
->Append((long)hWnd
, win
);
1468 void wxRemoveHandleAssociation(wxWindow
*win
)
1470 wxWinHandleList
->DeleteObject(win
);
1473 // Default destroyer - override if you destroy it in some other way
1474 // (e.g. with MDI child windows)
1475 void wxWindow::MSWDestroyWindow(void)
1480 wxDebugMsg("wxWindow::MSWDestroyWindow %d\n", handle
);
1482 MSWDetachWindowMenu();
1483 // SetWindowLong(handle, 0, (long)0);
1484 HWND oldHandle
= handle
;
1487 ::DestroyWindow(oldHandle
);
1489 // Menu is destroyed explicitly by wxMDIChild::DestroyWindow,
1490 // or when Windows HWND is deleted if MDI parent or
1495 ::DestroyMenu(m_hMenu);
1502 void wxWindow::MSWCreate(int id
, wxWindow
*parent
, const char *wclass
, wxWindow
*wx_win
, const char *title
,
1503 int x
, int y
, int width
, int height
,
1504 WXDWORD style
, const char *dialog_template
, WXDWORD extendedStyle
)
1506 bool is_dialog
= (dialog_template
!= NULL
);
1507 int x1
= CW_USEDEFAULT
;
1509 int width1
= CW_USEDEFAULT
;
1512 // Find parent's size, if it exists, to set up a possible default
1513 // panel size the size of the parent window
1517 // Was GetWindowRect: JACS 5/5/95
1518 ::GetClientRect((HWND
) parent
->GetHWND(), &parent_rect
);
1520 width1
= parent_rect
.right
- parent_rect
.left
;
1521 height1
= parent_rect
.bottom
- parent_rect
.top
;
1526 if (width
> -1) width1
= width
;
1527 if (height
> -1) height1
= height
;
1529 HWND hParent
= NULL
;
1531 hParent
= (HWND
) parent
->GetHWND();
1537 // MakeProcInstance doesn't seem to be needed in C7. Is it needed for
1538 // other compilers???
1539 // VZ: it's always needed for Win16 and never for Win32
1541 m_hWnd
= (WXHWND
) ::CreateDialog(wxGetInstance(), dialog_template
, hParent
,
1542 (DLGPROC
)wxDlgProc
);
1544 DLGPROC dlgproc
= (DLGPROC
)MakeProcInstance((DLGPROC
)wxWndProc
, wxGetInstance());
1546 m_hWnd
= (WXHWND
) ::CreateDialog(wxGetInstance(), dialog_template
, hParent
,
1551 MessageBox(NULL
, "Can't find dummy dialog template!\nCheck resource include path for finding wx.rc.",
1552 "wxWindows Error", MB_ICONEXCLAMATION
| MB_OK
);
1553 else MoveWindow((HWND
) m_hWnd
, x1
, y1
, width1
, height1
, FALSE
);
1558 if (style
& WS_CHILD
)
1563 m_hWnd
= (WXHWND
) CreateWindowEx(extendedStyle
, wclass
,
1568 // hParent, NULL, wxGetInstance(),
1569 hParent
, (HMENU
)controlId
, wxGetInstance(),
1575 sprintf(buf
, "Can't create window of class %s! Weird.\nPossible Windows 3.x compatibility problem?",
1578 "Fatal wxWindows Error");
1582 wxWinHandleList
->Append((long)m_hWnd
, this);
1585 wxDebugMsg("wxWindow::MSWCreate %d\n", m_hWnd
);
1589 void wxWindow::MSWOnCreate(WXLPCREATESTRUCT
WXUNUSED(cs
))
1593 bool wxWindow::MSWOnClose(void)
1596 wxDebugMsg("wxWindow::MSWOnClose %d\n", handle
);
1601 bool wxWindow::MSWOnDestroy(void)
1604 wxDebugMsg("wxWindow::MSWOnDestroy %d\n", handle
);
1606 // delete our drop target if we've got one
1607 #if USE_DRAG_AND_DROP
1608 if ( m_pDropTarget
!= NULL
) {
1609 m_pDropTarget
->Revoke(m_hWnd
);
1611 delete m_pDropTarget
;
1612 m_pDropTarget
= NULL
;
1619 // Deal with child commands from buttons etc.
1621 bool wxWindow::MSWOnNotify(WXWPARAM wParam
, WXLPARAM lParam
)
1623 #if defined(__WIN95__)
1624 // Find a child window to send the notification to, e.g. a toolbar.
1625 // There's a problem here. NMHDR::hwndFrom doesn't give us the
1626 // handle of the toolbar; it's probably the handle of the tooltip
1627 // window (anyway, it's parent is also the toolbar's parent).
1628 // So, since we don't know which hWnd or wxWindow originated the
1629 // WM_NOTIFY, we'll need to go through all the children of this window
1630 // trying out MSWNotify.
1631 // This won't work now, though, because any number of controls
1632 // could respond to the same generic messages :-(
1634 /* This doesn't work for toolbars, but try for other controls first.
1636 NMHDR
*hdr
= (NMHDR
*)lParam
;
1637 HWND hWnd
= (HWND
)hdr
->hwndFrom
;
1638 wxWindow
*win
= wxFindWinFromHandle((WXHWND
) hWnd
);
1641 return win
->MSWNotify(wParam
, lParam
);
1644 // Rely on MSWNotify to check whether the message
1645 // belongs to the window or not
1646 wxNode
*node
= GetChildren()->First();
1649 wxWindow
*child
= (wxWindow
*)node
->Data();
1650 if ( child
->MSWNotify(wParam
, lParam
) )
1652 node
= node
->Next();
1662 void wxWindow::MSWOnMenuHighlight(WXWORD
WXUNUSED(item
), WXWORD
WXUNUSED(flags
), WXHMENU
WXUNUSED(sysmenu
))
1665 wxDebugMsg("wxWindow::MSWOnMenuHighlight %d\n", handle
);
1669 void wxWindow::MSWOnInitMenuPopup(WXHMENU menu
, int pos
, bool isSystem
)
1673 bool wxWindow::MSWOnActivate(int state
, bool WXUNUSED(minimized
), WXHWND
WXUNUSED(activate
))
1676 wxDebugMsg("wxWindow::MSWOnActivate %d\n", handle
);
1679 wxActivateEvent
event(wxEVT_ACTIVATE
, ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)),
1681 event
.SetEventObject(this);
1682 GetEventHandler()->ProcessEvent(event
);
1686 bool wxWindow::MSWOnSetFocus(WXHWND
WXUNUSED(hwnd
))
1689 wxDebugMsg("wxWindow::MSWOnSetFocus %d\n", m_hWnd
);
1692 if (m_caretEnabled
&& (m_caretWidth
> 0) && (m_caretHeight
> 0))
1694 ::CreateCaret((HWND
) GetHWND(), NULL
, m_caretWidth
, m_caretHeight
);
1696 ::ShowCaret((HWND
) GetHWND());
1699 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
1700 event
.SetEventObject(this);
1701 if (!GetEventHandler()->ProcessEvent(event
))
1706 bool wxWindow::MSWOnKillFocus(WXHWND
WXUNUSED(hwnd
))
1709 wxDebugMsg("wxWindow::MSWOnKillFocus %d\n", m_hWnd
);
1717 wxFocusEvent
event(wxEVT_KILL_FOCUS
, m_windowId
);
1718 event
.SetEventObject(this);
1719 if (!GetEventHandler()->ProcessEvent(event
))
1724 void wxWindow::MSWOnDropFiles(WXWPARAM wParam
)
1727 wxDebugMsg("wxWindow::MSWOnDropFiles %d\n", m_hWnd
);
1730 HANDLE hFilesInfo
= (HANDLE
)wParam
;
1732 DragQueryPoint(hFilesInfo
, (LPPOINT
) &dropPoint
);
1734 // Get the total number of files dropped
1735 WORD gwFilesDropped
= (WORD
)DragQueryFile ((HDROP
)hFilesInfo
,
1740 wxString
*files
= new wxString
[gwFilesDropped
];
1742 for (wIndex
=0; wIndex
< (int)gwFilesDropped
; wIndex
++)
1744 DragQueryFile (hFilesInfo
, wIndex
, (LPSTR
) wxBuffer
, 1000);
1745 files
[wIndex
] = wxBuffer
;
1747 DragFinish (hFilesInfo
);
1749 wxDropFilesEvent
event(wxEVT_DROP_FILES
, gwFilesDropped
, files
);
1750 event
.m_eventObject
= this;
1751 event
.m_pos
.x
= dropPoint
.x
; event
.m_pos
.x
= dropPoint
.y
;
1753 if (!GetEventHandler()->ProcessEvent(event
))
1759 bool wxWindow::MSWOnDrawItem(int id
, WXDRAWITEMSTRUCT
*itemStruct
)
1762 if ( id
== 0 ) { // is it a menu item?
1763 DRAWITEMSTRUCT
*pDrawStruct
= (DRAWITEMSTRUCT
*)itemStruct
;
1764 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pDrawStruct
->itemData
);
1765 wxCHECK( pMenuItem
->IsKindOf(CLASSINFO(wxMenuItem
)), FALSE
);
1767 // prepare to call OnDrawItem()
1769 dc
.SetHDC((WXHDC
)pDrawStruct
->hDC
, FALSE
);
1770 wxRect
rect(pDrawStruct
->rcItem
.left
, pDrawStruct
->rcItem
.top
,
1771 pDrawStruct
->rcItem
.right
- pDrawStruct
->rcItem
.left
,
1772 pDrawStruct
->rcItem
.bottom
- pDrawStruct
->rcItem
.top
);
1773 return pMenuItem
->OnDrawItem(
1775 (wxOwnerDrawn::wxODAction
)pDrawStruct
->itemAction
,
1776 (wxOwnerDrawn::wxODStatus
)pDrawStruct
->itemState
1779 #endif // owner-drawn menus
1781 wxWindow
*item
= FindItem(id
);
1782 #if USE_DYNAMIC_CLASSES
1783 if (item
&& item
->IsKindOf(CLASSINFO(wxControl
)))
1785 return ((wxControl
*)item
)->MSWOnDraw(itemStruct
);
1792 bool wxWindow::MSWOnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*itemStruct
)
1795 if ( id
== 0 ) { // is it a menu item?
1796 MEASUREITEMSTRUCT
*pMeasureStruct
= (MEASUREITEMSTRUCT
*)itemStruct
;
1797 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pMeasureStruct
->itemData
);
1798 wxCHECK( pMenuItem
->IsKindOf(CLASSINFO(wxMenuItem
)), FALSE
);
1800 return pMenuItem
->OnMeasureItem(&pMeasureStruct
->itemWidth
,
1801 &pMeasureStruct
->itemHeight
);
1803 #endif // owner-drawn menus
1805 wxWindow
*item
= FindItem(id
);
1806 #if USE_DYNAMIC_CLASSES
1807 if (item
&& item
->IsKindOf(CLASSINFO(wxControl
)))
1809 return ((wxControl
*)item
)->MSWOnMeasure(itemStruct
);
1816 WXHBRUSH
wxWindow::MSWOnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
1817 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1820 wxDebugMsg("wxWindow::MSWOnCtlColour %d\n", m_hWnd
);
1822 if (nCtlColor
== CTLCOLOR_DLG
)
1824 return OnCtlColor(pDC
, pWnd
, nCtlColor
, message
, wParam
, lParam
);
1827 wxControl
*item
= (wxControl
*)FindItemByHWND(pWnd
, TRUE
);
1829 WXHBRUSH hBrush
= 0;
1832 hBrush
= item
->OnCtlColor(pDC
, pWnd
, nCtlColor
, message
, wParam
, lParam
);
1834 // I think that even for dialogs, we may need to call DefWindowProc (?)
1835 // Or maybe just rely on the usual default behaviour.
1837 hBrush
= (WXHBRUSH
) MSWDefWindowProc(message
, wParam
, lParam
);
1842 // Define for each class of dialog and control
1843 WXHBRUSH
wxWindow::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
1844 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1846 return (WXHBRUSH
) MSWDefWindowProc(message
, wParam
, lParam
);
1849 bool wxWindow::MSWOnColorChange(WXHWND hWnd
, WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1851 wxSysColourChangedEvent event
;
1852 event
.m_eventObject
= this;
1854 // Check if app handles this.
1855 if (GetEventHandler()->ProcessEvent(event
))
1858 // We didn't process it
1862 // Responds to colour changes: passes event on to children.
1863 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1865 wxNode
*node
= GetChildren()->First();
1868 // Only propagate to non-top-level windows
1869 wxWindow
*win
= (wxWindow
*)node
->Data();
1870 if ( win
->GetParent() )
1872 wxSysColourChangedEvent event2
;
1873 event
.m_eventObject
= win
;
1874 win
->GetEventHandler()->ProcessEvent(event2
);
1877 node
= node
->Next();
1881 long wxWindow::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1884 return ::CallWindowProc(CASTWNDPROC (FARPROC
) m_oldWndProc
, (HWND
) GetHWND(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1886 return ::DefWindowProc((HWND
) GetHWND(), nMsg
, wParam
, lParam
);
1889 long wxWindow::Default()
1891 // Ignore 'fake' events (perhaps generated as a result of a separate real event)
1895 return this->MSWDefWindowProc(m_lastMsg
, m_lastWParam
, m_lastLParam
);
1898 bool wxWindow::MSWProcessMessage(WXMSG
* pMsg
)
1904 // Suggestion by Andrew Davison to allow
1905 // a panel to accept character input in user edit mode
1907 // OK, what we probably want to do here for wxWin 2.0
1908 // is have a window style to indicate whether the window
1909 // should process dialog-style input, since we can't
1910 // otherwise tell whether it's supposed to do tab traversal
1912 if (GetWindowStyleFlag() & wxTAB_TRAVERSAL
)
1913 return (::IsDialogMessage((HWND
) m_hWnd
, (MSG
*)pMsg
) != 0);
1919 long wxWindow::MSWOnMDIActivate(long WXUNUSED(flag
), WXHWND
WXUNUSED(activate
), WXHWND
WXUNUSED(deactivate
))
1922 wxDebugMsg("wxWindow::MSWOnMDIActivate %d\n", m_hWnd
);
1927 void wxWindow::MSWDetachWindowMenu(void)
1931 int N
= GetMenuItemCount((HMENU
) m_hMenu
);
1933 for (i
= 0; i
< N
; i
++)
1936 int chars
= GetMenuString((HMENU
) m_hMenu
, i
, buf
, 100, MF_BYPOSITION
);
1937 if ((chars
> 0) && (strcmp(buf
, "&Window") == 0))
1939 RemoveMenu((HMENU
) m_hMenu
, i
, MF_BYPOSITION
);
1946 bool wxWindow::MSWOnPaint(void)
1948 wxPaintEvent
event(m_windowId
);
1949 event
.SetEventObject(this);
1950 if (!GetEventHandler()->ProcessEvent(event
))
1955 void wxWindow::MSWOnSize(int w
, int h
, WXUINT
WXUNUSED(flag
))
1961 wxDebugMsg("wxWindow::MSWOnSize %d\n", m_hWnd
);
1968 wxSizeEvent
event(wxSize(w
, h
), m_windowId
);
1969 event
.SetEventObject(this);
1970 if (!GetEventHandler()->ProcessEvent(event
))
1976 void wxWindow::MSWOnWindowPosChanging(void *WXUNUSED(lpPos
))
1981 // Deal with child commands from buttons etc.
1982 bool wxWindow::MSWOnCommand(WXWORD id
, WXWORD cmd
, WXHWND
WXUNUSED(control
))
1985 wxDebugMsg("wxWindow::MSWOnCommand\n");
1987 if (wxCurrentPopupMenu
)
1989 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
1990 wxCurrentPopupMenu
= NULL
;
1991 bool succ
= popupMenu
->MSWCommand(cmd
, id
);
1996 sprintf(buf
, "Looking for item %d...\n", id
);
2000 wxWindow
*item
= FindItem(id
);
2003 bool value
= item
->MSWCommand(cmd
, id
);
2006 wxDebugMsg("MSWCommand succeeded\n");
2008 wxDebugMsg("MSWCommand failed\n");
2015 wxDebugMsg("Could not find item!\n");
2017 wxDebugMsg("Item ids for this panel:\n");
2019 wxNode
*current
= GetChildren()->First();
2022 wxObject
*obj
= (wxObject
*)current
->Data() ;
2023 if (obj
->IsKindOf(CLASSINFO(wxControl
)))
2025 wxControl
*item
= (wxControl
*)current
->Data();
2026 sprintf(buf
, " %d\n", (int)item
->m_windowId
);
2029 current
= current
->Next();
2037 long wxWindow::MSWOnSysCommand(WXWPARAM wParam
, WXLPARAM lParam
)
2043 wxMaximizeEvent
event(m_windowId
);
2044 event
.SetEventObject(this);
2045 if (!GetEventHandler()->ProcessEvent(event
))
2053 wxIconizeEvent
event(m_windowId
);
2054 event
.SetEventObject(this);
2055 if (!GetEventHandler()->ProcessEvent(event
))
2067 void wxWindow::MSWOnLButtonDown(int x
, int y
, WXUINT flags
)
2069 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
2071 event
.m_x
= x
; event
.m_y
= y
;
2072 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2073 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2074 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2075 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2076 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2077 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2078 event
.m_eventObject
= this;
2080 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVENT_TYPE_LEFT_DOWN
;
2082 if (!GetEventHandler()->ProcessEvent(event
))
2086 void wxWindow::MSWOnLButtonUp(int x
, int y
, WXUINT flags
)
2088 wxMouseEvent
event(wxEVT_LEFT_UP
);
2090 event
.m_x
= x
; event
.m_y
= y
;
2091 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2092 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2093 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2094 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2095 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2096 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2097 event
.m_eventObject
= this;
2099 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_LEFT_UP
;
2101 if (!GetEventHandler()->ProcessEvent(event
))
2105 void wxWindow::MSWOnLButtonDClick(int x
, int y
, WXUINT flags
)
2107 wxMouseEvent
event(wxEVT_LEFT_DCLICK
);
2109 event
.m_x
= x
; event
.m_y
= y
;
2110 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2111 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2112 event
.m_leftDown
= ((flags
& MK_LBUTTON
!= 0));
2113 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2114 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2115 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2116 event
.m_eventObject
= this;
2118 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_LEFT_DCLICK
;
2120 if (!GetEventHandler()->ProcessEvent(event
))
2124 void wxWindow::MSWOnMButtonDown(int x
, int y
, WXUINT flags
)
2126 wxMouseEvent
event(wxEVT_MIDDLE_DOWN
);
2128 event
.m_x
= x
; event
.m_y
= y
;
2129 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2130 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2131 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2132 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2133 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2134 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2135 event
.m_eventObject
= this;
2137 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_MIDDLE_DOWN
;
2139 if (!GetEventHandler()->ProcessEvent(event
))
2143 void wxWindow::MSWOnMButtonUp(int x
, int y
, WXUINT flags
)
2145 //wxDebugMsg("MButtonUp\n") ;
2146 wxMouseEvent
event(wxEVT_MIDDLE_UP
);
2148 event
.m_x
= x
; event
.m_y
= y
;
2149 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2150 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2151 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2152 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2153 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2154 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2155 event
.m_eventObject
= this;
2157 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_MIDDLE_UP
;
2159 if (!GetEventHandler()->ProcessEvent(event
))
2163 void wxWindow::MSWOnMButtonDClick(int x
, int y
, WXUINT flags
)
2165 wxMouseEvent
event(wxEVT_MIDDLE_DCLICK
);
2167 event
.m_x
= x
; event
.m_y
= y
;
2168 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2169 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2170 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2171 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2172 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2173 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2174 event
.m_eventObject
= this;
2176 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_MIDDLE_DCLICK
;
2178 if (!GetEventHandler()->ProcessEvent(event
))
2182 void wxWindow::MSWOnRButtonDown(int x
, int y
, WXUINT flags
)
2184 wxMouseEvent
event(wxEVT_RIGHT_DOWN
);
2186 event
.m_x
= x
; event
.m_y
= y
;
2187 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2188 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2189 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2190 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2191 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2192 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2193 event
.m_eventObject
= this;
2195 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_RIGHT_DOWN
;
2197 if (!GetEventHandler()->ProcessEvent(event
))
2201 void wxWindow::MSWOnRButtonUp(int x
, int y
, WXUINT flags
)
2203 wxMouseEvent
event(wxEVT_RIGHT_UP
);
2205 event
.m_x
= x
; event
.m_y
= y
;
2206 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2207 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2208 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2209 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2210 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2211 event
.m_eventObject
= this;
2212 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2214 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_RIGHT_UP
;
2216 if (!GetEventHandler()->ProcessEvent(event
))
2220 void wxWindow::MSWOnRButtonDClick(int x
, int y
, WXUINT flags
)
2222 wxMouseEvent
event(wxEVT_RIGHT_DCLICK
);
2224 event
.m_x
= x
; event
.m_y
= y
;
2225 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2226 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2227 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2228 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2229 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2230 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2231 event
.m_eventObject
= this;
2233 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_RIGHT_DCLICK
;
2235 if (!GetEventHandler()->ProcessEvent(event
))
2239 void wxWindow::MSWOnMouseMove(int x
, int y
, WXUINT flags
)
2241 // 'normal' move event...
2242 // Set cursor, but only if we're not in 'busy' mode
2244 // Trouble with this is that it sets the cursor for controls too :-(
2245 if (m_windowCursor
.Ok() && !wxIsBusy())
2246 ::SetCursor((HCURSOR
) m_windowCursor
.GetHCURSOR());
2248 if (!m_mouseInWindow
)
2250 // Generate an ENTER event
2251 m_mouseInWindow
= TRUE
;
2252 MSWOnMouseEnter(x
, y
, flags
);
2255 wxMouseEvent
event(wxEVT_MOTION
);
2257 event
.m_x
= x
; event
.m_y
= y
;
2258 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2259 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2260 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2261 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2262 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2263 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2264 event
.m_eventObject
= this;
2266 // Window gets a click down message followed by a mouse move
2267 // message even if position isn't changed! We want to discard
2268 // the trailing move event if x and y are the same.
2269 if ((m_lastEvent
== wxEVT_RIGHT_DOWN
|| m_lastEvent
== wxEVT_LEFT_DOWN
||
2270 m_lastEvent
== wxEVT_MIDDLE_DOWN
) &&
2271 (m_lastXPos
== event
.m_x
&& m_lastYPos
== event
.m_y
))
2273 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2274 m_lastEvent
= wxEVT_MOTION
;
2278 m_lastEvent
= wxEVT_MOTION
;
2279 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2281 if (!GetEventHandler()->ProcessEvent(event
))
2285 void wxWindow::MSWOnMouseEnter(int x
, int y
, WXUINT flags
)
2287 wxMouseEvent
event(wxEVT_ENTER_WINDOW
);
2289 event
.m_x
= x
; event
.m_y
= y
;
2290 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2291 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2292 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2293 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2294 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2295 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2296 event
.m_eventObject
= this;
2298 m_lastEvent
= wxEVT_ENTER_WINDOW
;
2299 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2300 // No message - ensure we don't try to call the default behaviour accidentally.
2302 GetEventHandler()->ProcessEvent(event
);
2305 void wxWindow::MSWOnMouseLeave(int x
, int y
, WXUINT flags
)
2307 wxMouseEvent
event(wxEVT_LEAVE_WINDOW
);
2309 event
.m_x
= x
; event
.m_y
= y
;
2310 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2311 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2312 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2313 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2314 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2315 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2316 event
.m_eventObject
= this;
2318 m_lastEvent
= wxEVT_LEAVE_WINDOW
;
2319 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2320 // No message - ensure we don't try to call the default behaviour accidentally.
2322 GetEventHandler()->ProcessEvent(event
);
2325 void wxWindow::MSWOnChar(WXWORD wParam
, WXLPARAM lParam
, bool isASCII
)
2328 bool tempControlDown
= FALSE
;
2331 // If 1 -> 26, translate to CTRL plus a letter.
2333 if ((id
> 0) && (id
< 27))
2354 tempControlDown
= TRUE
;
2360 else if ((id
= wxCharCodeMSWToWX(wParam
)) == 0) {
2361 // it's ASCII and will be processed here only when called from
2362 // WM_CHAR (i.e. when isASCII = TRUE)
2368 wxKeyEvent
event(wxEVT_CHAR
);
2369 event
.m_shiftDown
= (::GetKeyState(VK_SHIFT
)&0x100?TRUE
:FALSE
);
2370 event
.m_controlDown
= (::GetKeyState(VK_CONTROL
)&0x100?TRUE
:FALSE
);
2371 if ((HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
2372 event
.m_altDown
= TRUE
;
2374 event
.m_eventObject
= this;
2375 event
.m_keyCode
= id
;
2376 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2381 GetWindowRect((HWND
) GetHWND(),&rect
) ;
2385 event
.m_x
= pt
.x
; event
.m_y
= pt
.y
;
2387 if (!GetEventHandler()->ProcessEvent(event
))
2392 void wxWindow::MSWOnJoyDown(int joystick
, int x
, int y
, WXUINT flags
)
2396 if (flags
& JOY_BUTTON1CHG
)
2397 change
= wxJOY_BUTTON1
;
2398 if (flags
& JOY_BUTTON2CHG
)
2399 change
= wxJOY_BUTTON2
;
2400 if (flags
& JOY_BUTTON3CHG
)
2401 change
= wxJOY_BUTTON3
;
2402 if (flags
& JOY_BUTTON4CHG
)
2403 change
= wxJOY_BUTTON4
;
2405 if (flags
& JOY_BUTTON1
)
2406 buttons
|= wxJOY_BUTTON1
;
2407 if (flags
& JOY_BUTTON2
)
2408 buttons
|= wxJOY_BUTTON2
;
2409 if (flags
& JOY_BUTTON3
)
2410 buttons
|= wxJOY_BUTTON3
;
2411 if (flags
& JOY_BUTTON4
)
2412 buttons
|= wxJOY_BUTTON4
;
2414 wxJoystickEvent
event(wxEVT_JOY_BUTTON_DOWN
, buttons
, joystick
, change
);
2415 event
.SetPosition(wxPoint(x
, y
));
2416 event
.SetEventObject(this);
2418 GetEventHandler()->ProcessEvent(event
);
2421 void wxWindow::MSWOnJoyUp(int joystick
, int x
, int y
, WXUINT flags
)
2425 if (flags
& JOY_BUTTON1CHG
)
2426 change
= wxJOY_BUTTON1
;
2427 if (flags
& JOY_BUTTON2CHG
)
2428 change
= wxJOY_BUTTON2
;
2429 if (flags
& JOY_BUTTON3CHG
)
2430 change
= wxJOY_BUTTON3
;
2431 if (flags
& JOY_BUTTON4CHG
)
2432 change
= wxJOY_BUTTON4
;
2434 if (flags
& JOY_BUTTON1
)
2435 buttons
|= wxJOY_BUTTON1
;
2436 if (flags
& JOY_BUTTON2
)
2437 buttons
|= wxJOY_BUTTON2
;
2438 if (flags
& JOY_BUTTON3
)
2439 buttons
|= wxJOY_BUTTON3
;
2440 if (flags
& JOY_BUTTON4
)
2441 buttons
|= wxJOY_BUTTON4
;
2443 wxJoystickEvent
event(wxEVT_JOY_BUTTON_UP
, buttons
, joystick
, change
);
2444 event
.SetPosition(wxPoint(x
, y
));
2445 event
.SetEventObject(this);
2447 GetEventHandler()->ProcessEvent(event
);
2450 void wxWindow::MSWOnJoyMove(int joystick
, int x
, int y
, WXUINT flags
)
2453 if (flags
& JOY_BUTTON1
)
2454 buttons
|= wxJOY_BUTTON1
;
2455 if (flags
& JOY_BUTTON2
)
2456 buttons
|= wxJOY_BUTTON2
;
2457 if (flags
& JOY_BUTTON3
)
2458 buttons
|= wxJOY_BUTTON3
;
2459 if (flags
& JOY_BUTTON4
)
2460 buttons
|= wxJOY_BUTTON4
;
2462 wxJoystickEvent
event(wxEVT_JOY_MOVE
, buttons
, joystick
, 0);
2463 event
.SetPosition(wxPoint(x
, y
));
2464 event
.SetEventObject(this);
2466 GetEventHandler()->ProcessEvent(event
);
2469 void wxWindow::MSWOnJoyZMove(int joystick
, int z
, WXUINT flags
)
2472 if (flags
& JOY_BUTTON1
)
2473 buttons
|= wxJOY_BUTTON1
;
2474 if (flags
& JOY_BUTTON2
)
2475 buttons
|= wxJOY_BUTTON2
;
2476 if (flags
& JOY_BUTTON3
)
2477 buttons
|= wxJOY_BUTTON3
;
2478 if (flags
& JOY_BUTTON4
)
2479 buttons
|= wxJOY_BUTTON4
;
2481 wxJoystickEvent
event(wxEVT_JOY_ZMOVE
, buttons
, joystick
, 0);
2482 event
.SetZPosition(z
);
2483 event
.SetEventObject(this);
2485 GetEventHandler()->ProcessEvent(event
);
2488 void wxWindow::MSWOnVScroll(WXWORD wParam
, WXWORD pos
, WXHWND control
)
2492 wxWindow
*child
= wxFindWinFromHandle(control
);
2494 child
->MSWOnVScroll(wParam
, pos
, control
);
2498 wxScrollEvent event
;
2499 event
.SetPosition(pos
);
2500 event
.SetOrientation(wxVERTICAL
);
2501 event
.m_eventObject
= this;
2506 event
.m_eventType
= wxEVT_SCROLL_TOP
;
2510 event
.m_eventType
= wxEVT_SCROLL_BOTTOM
;
2514 event
.m_eventType
= wxEVT_SCROLL_LINEUP
;
2518 event
.m_eventType
= wxEVT_SCROLL_LINEDOWN
;
2522 event
.m_eventType
= wxEVT_SCROLL_PAGEUP
;
2526 event
.m_eventType
= wxEVT_SCROLL_PAGEDOWN
;
2530 case SB_THUMBPOSITION
:
2531 event
.m_eventType
= wxEVT_SCROLL_THUMBTRACK
;
2539 if (!GetEventHandler()->ProcessEvent(event
))
2543 void wxWindow::MSWOnHScroll( WXWORD wParam
, WXWORD pos
, WXHWND control
)
2547 wxWindow
*child
= wxFindWinFromHandle(control
);
2549 child
->MSWOnHScroll(wParam
, pos
, control
);
2553 wxScrollEvent event
;
2554 event
.SetPosition(pos
);
2555 event
.SetOrientation(wxHORIZONTAL
);
2556 event
.m_eventObject
= this;
2561 event
.m_eventType
= wxEVT_SCROLL_TOP
;
2565 event
.m_eventType
= wxEVT_SCROLL_BOTTOM
;
2569 event
.m_eventType
= wxEVT_SCROLL_LINEUP
;
2573 event
.m_eventType
= wxEVT_SCROLL_LINEDOWN
;
2577 event
.m_eventType
= wxEVT_SCROLL_PAGEUP
;
2581 event
.m_eventType
= wxEVT_SCROLL_PAGEDOWN
;
2585 case SB_THUMBPOSITION
:
2586 event
.m_eventType
= wxEVT_SCROLL_THUMBTRACK
;
2593 if (!GetEventHandler()->ProcessEvent(event
))
2597 void wxWindow::MSWOnShow(bool show
, int status
)
2599 wxShowEvent
event(GetId(), show
);
2600 event
.m_eventObject
= this;
2601 GetEventHandler()->ProcessEvent(event
);
2604 bool wxWindow::MSWOnInitDialog(WXHWND
WXUNUSED(hWndFocus
))
2606 wxInitDialogEvent
event(GetId());
2607 event
.m_eventObject
= this;
2608 GetEventHandler()->ProcessEvent(event
);
2612 void wxWindow::InitDialog(void)
2614 wxInitDialogEvent
event(GetId());
2615 event
.SetEventObject( this );
2616 GetEventHandler()->ProcessEvent(event
);
2619 // Default init dialog behaviour is to transfer data to window
2620 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
2622 TransferDataToWindow();
2625 void wxGetCharSize(WXHWND wnd
, int *x
, int *y
,wxFont
*the_font
)
2628 HDC dc
= ::GetDC((HWND
) wnd
);
2634 wxDebugMsg("wxGetCharSize: Selecting HFONT %X\n", fnt
);
2636 // the_font->UseResource();
2637 // the_font->RealizeResource();
2638 if ((fnt
=(HFONT
) the_font
->GetResourceHandle()))
2639 was
= SelectObject(dc
,fnt
) ;
2641 GetTextMetrics(dc
, &tm
);
2642 if (the_font
&& fnt
&& was
)
2645 wxDebugMsg("wxGetCharSize: Selecting old HFONT %X\n", was
);
2647 SelectObject(dc
,was
) ;
2649 ReleaseDC((HWND
)wnd
, dc
);
2650 *x
= tm
.tmAveCharWidth
;
2651 *y
= tm
.tmHeight
+ tm
.tmExternalLeading
;
2654 // the_font->ReleaseResource();
2657 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
2658 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
2659 int wxCharCodeMSWToWX(int keySym
)
2664 case VK_CANCEL
: id
= WXK_CANCEL
; break;
2665 case VK_BACK
: id
= WXK_BACK
; break;
2666 case VK_TAB
: id
= WXK_TAB
; break;
2667 case VK_CLEAR
: id
= WXK_CLEAR
; break;
2668 case VK_RETURN
: id
= WXK_RETURN
; break;
2669 case VK_SHIFT
: id
= WXK_SHIFT
; break;
2670 case VK_CONTROL
: id
= WXK_CONTROL
; break;
2671 case VK_MENU
: id
= WXK_MENU
; break;
2672 case VK_PAUSE
: id
= WXK_PAUSE
; break;
2673 case VK_SPACE
: id
= WXK_SPACE
; break;
2674 case VK_ESCAPE
: id
= WXK_ESCAPE
; break;
2675 case VK_PRIOR
: id
= WXK_PRIOR
; break;
2676 case VK_NEXT
: id
= WXK_NEXT
; break;
2677 case VK_END
: id
= WXK_END
; break;
2678 case VK_HOME
: id
= WXK_HOME
; break;
2679 case VK_LEFT
: id
= WXK_LEFT
; break;
2680 case VK_UP
: id
= WXK_UP
; break;
2681 case VK_RIGHT
: id
= WXK_RIGHT
; break;
2682 case VK_DOWN
: id
= WXK_DOWN
; break;
2683 case VK_SELECT
: id
= WXK_SELECT
; break;
2684 case VK_PRINT
: id
= WXK_PRINT
; break;
2685 case VK_EXECUTE
: id
= WXK_EXECUTE
; break;
2686 case VK_INSERT
: id
= WXK_INSERT
; break;
2687 case VK_DELETE
: id
= WXK_DELETE
; break;
2688 case VK_HELP
: id
= WXK_HELP
; break;
2689 case VK_NUMPAD0
: id
= WXK_NUMPAD0
; break;
2690 case VK_NUMPAD1
: id
= WXK_NUMPAD1
; break;
2691 case VK_NUMPAD2
: id
= WXK_NUMPAD2
; break;
2692 case VK_NUMPAD3
: id
= WXK_NUMPAD3
; break;
2693 case VK_NUMPAD4
: id
= WXK_NUMPAD4
; break;
2694 case VK_NUMPAD5
: id
= WXK_NUMPAD5
; break;
2695 case VK_NUMPAD6
: id
= WXK_NUMPAD6
; break;
2696 case VK_NUMPAD7
: id
= WXK_NUMPAD7
; break;
2697 case VK_NUMPAD8
: id
= WXK_NUMPAD8
; break;
2698 case VK_NUMPAD9
: id
= WXK_NUMPAD9
; break;
2699 case VK_MULTIPLY
: id
= WXK_MULTIPLY
; break;
2700 case VK_ADD
: id
= WXK_ADD
; break;
2701 case VK_SUBTRACT
: id
= WXK_SUBTRACT
; break;
2702 case VK_DECIMAL
: id
= WXK_DECIMAL
; break;
2703 case VK_DIVIDE
: id
= WXK_DIVIDE
; break;
2704 case VK_F1
: id
= WXK_F1
; break;
2705 case VK_F2
: id
= WXK_F2
; break;
2706 case VK_F3
: id
= WXK_F3
; break;
2707 case VK_F4
: id
= WXK_F4
; break;
2708 case VK_F5
: id
= WXK_F5
; break;
2709 case VK_F6
: id
= WXK_F6
; break;
2710 case VK_F7
: id
= WXK_F7
; break;
2711 case VK_F8
: id
= WXK_F8
; break;
2712 case VK_F9
: id
= WXK_F9
; break;
2713 case VK_F10
: id
= WXK_F10
; break;
2714 case VK_F11
: id
= WXK_F11
; break;
2715 case VK_F12
: id
= WXK_F12
; break;
2716 case VK_F13
: id
= WXK_F13
; break;
2717 case VK_F14
: id
= WXK_F14
; break;
2718 case VK_F15
: id
= WXK_F15
; break;
2719 case VK_F16
: id
= WXK_F16
; break;
2720 case VK_F17
: id
= WXK_F17
; break;
2721 case VK_F18
: id
= WXK_F18
; break;
2722 case VK_F19
: id
= WXK_F19
; break;
2723 case VK_F20
: id
= WXK_F20
; break;
2724 case VK_F21
: id
= WXK_F21
; break;
2725 case VK_F22
: id
= WXK_F22
; break;
2726 case VK_F23
: id
= WXK_F23
; break;
2727 case VK_F24
: id
= WXK_F24
; break;
2728 case VK_NUMLOCK
: id
= WXK_NUMLOCK
; break;
2729 case VK_SCROLL
: id
= WXK_SCROLL
; break;
2738 int wxCharCodeWXToMSW(int id
, bool *isVirtual
)
2744 case WXK_CANCEL
: keySym
= VK_CANCEL
; break;
2745 case WXK_CLEAR
: keySym
= VK_CLEAR
; break;
2746 case WXK_SHIFT
: keySym
= VK_SHIFT
; break;
2747 case WXK_CONTROL
: keySym
= VK_CONTROL
; break;
2748 case WXK_MENU
: keySym
= VK_MENU
; break;
2749 case WXK_PAUSE
: keySym
= VK_PAUSE
; break;
2750 case WXK_PRIOR
: keySym
= VK_PRIOR
; break;
2751 case WXK_NEXT
: keySym
= VK_NEXT
; break;
2752 case WXK_END
: keySym
= VK_END
; break;
2753 case WXK_HOME
: keySym
= VK_HOME
; break;
2754 case WXK_LEFT
: keySym
= VK_LEFT
; break;
2755 case WXK_UP
: keySym
= VK_UP
; break;
2756 case WXK_RIGHT
: keySym
= VK_RIGHT
; break;
2757 case WXK_DOWN
: keySym
= VK_DOWN
; break;
2758 case WXK_SELECT
: keySym
= VK_SELECT
; break;
2759 case WXK_PRINT
: keySym
= VK_PRINT
; break;
2760 case WXK_EXECUTE
: keySym
= VK_EXECUTE
; break;
2761 case WXK_INSERT
: keySym
= VK_INSERT
; break;
2762 case WXK_DELETE
: keySym
= VK_DELETE
; break;
2763 case WXK_HELP
: keySym
= VK_HELP
; break;
2764 case WXK_NUMPAD0
: keySym
= VK_NUMPAD0
; break;
2765 case WXK_NUMPAD1
: keySym
= VK_NUMPAD1
; break;
2766 case WXK_NUMPAD2
: keySym
= VK_NUMPAD2
; break;
2767 case WXK_NUMPAD3
: keySym
= VK_NUMPAD3
; break;
2768 case WXK_NUMPAD4
: keySym
= VK_NUMPAD4
; break;
2769 case WXK_NUMPAD5
: keySym
= VK_NUMPAD5
; break;
2770 case WXK_NUMPAD6
: keySym
= VK_NUMPAD6
; break;
2771 case WXK_NUMPAD7
: keySym
= VK_NUMPAD7
; break;
2772 case WXK_NUMPAD8
: keySym
= VK_NUMPAD8
; break;
2773 case WXK_NUMPAD9
: keySym
= VK_NUMPAD9
; break;
2774 case WXK_MULTIPLY
: keySym
= VK_MULTIPLY
; break;
2775 case WXK_ADD
: keySym
= VK_ADD
; break;
2776 case WXK_SUBTRACT
: keySym
= VK_SUBTRACT
; break;
2777 case WXK_DECIMAL
: keySym
= VK_DECIMAL
; break;
2778 case WXK_DIVIDE
: keySym
= VK_DIVIDE
; break;
2779 case WXK_F1
: keySym
= VK_F1
; break;
2780 case WXK_F2
: keySym
= VK_F2
; break;
2781 case WXK_F3
: keySym
= VK_F3
; break;
2782 case WXK_F4
: keySym
= VK_F4
; break;
2783 case WXK_F5
: keySym
= VK_F5
; break;
2784 case WXK_F6
: keySym
= VK_F6
; break;
2785 case WXK_F7
: keySym
= VK_F7
; break;
2786 case WXK_F8
: keySym
= VK_F8
; break;
2787 case WXK_F9
: keySym
= VK_F9
; break;
2788 case WXK_F10
: keySym
= VK_F10
; break;
2789 case WXK_F11
: keySym
= VK_F11
; break;
2790 case WXK_F12
: keySym
= VK_F12
; break;
2791 case WXK_F13
: keySym
= VK_F13
; break;
2792 case WXK_F14
: keySym
= VK_F14
; break;
2793 case WXK_F15
: keySym
= VK_F15
; break;
2794 case WXK_F16
: keySym
= VK_F16
; break;
2795 case WXK_F17
: keySym
= VK_F17
; break;
2796 case WXK_F18
: keySym
= VK_F18
; break;
2797 case WXK_F19
: keySym
= VK_F19
; break;
2798 case WXK_F20
: keySym
= VK_F20
; break;
2799 case WXK_F21
: keySym
= VK_F21
; break;
2800 case WXK_F22
: keySym
= VK_F22
; break;
2801 case WXK_F23
: keySym
= VK_F23
; break;
2802 case WXK_F24
: keySym
= VK_F24
; break;
2803 case WXK_NUMLOCK
: keySym
= VK_NUMLOCK
; break;
2804 case WXK_SCROLL
: keySym
= VK_SCROLL
; break;
2815 // Caret manipulation
2816 void wxWindow::CreateCaret(int w
, int h
)
2820 m_caretEnabled
= TRUE
;
2823 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
2828 void wxWindow::ShowCaret(bool show
)
2833 ::ShowCaret((HWND
) GetHWND());
2835 ::HideCaret((HWND
) GetHWND());
2836 m_caretShown
= show
;
2840 void wxWindow::DestroyCaret(void)
2842 m_caretEnabled
= FALSE
;
2845 void wxWindow::SetCaretPos(int x
, int y
)
2847 ::SetCaretPos(x
, y
);
2850 void wxWindow::GetCaretPos(int *x
, int *y
) const
2853 ::GetCaretPos(&point
);
2859 * Update iterator. Use from within OnPaint.
2862 static RECT gs_UpdateRect
;
2864 wxUpdateIterator::wxUpdateIterator(wxWindow
* wnd
)
2866 current
= 0; //start somewhere...
2867 #if defined(__WIN32__) && !defined(__win32s__)
2868 rlist
= NULL
; //make sure I don't free randomly
2869 int len
= GetRegionData((HRGN
) wnd
->m_updateRgn
,0,NULL
); //Get buffer size
2872 rlist
= (WXRGNDATA
*) (RGNDATA
*)new char[len
];
2873 GetRegionData((HRGN
) wnd
->m_updateRgn
,len
, (RGNDATA
*)rlist
);
2874 rp
= (void *)(RECT
*) ((RGNDATA
*)rlist
)->Buffer
;
2875 rects
= ((RGNDATA
*)rlist
)->rdh
.nCount
;
2880 gs_UpdateRect
.left
= wnd
->m_updateRect
.x
;
2881 gs_UpdateRect
.top
= wnd
->m_updateRect
.y
;
2882 gs_UpdateRect
.right
= wnd
->m_updateRect
.x
+ wnd
->m_updateRect
.width
;
2883 gs_UpdateRect
.bottom
= wnd
->m_updateRect
.y
+ wnd
->m_updateRect
.height
;
2885 rp
= (void *)&gs_UpdateRect
; //Only one available in Win16,32s
2889 wxUpdateIterator::~wxUpdateIterator(void)
2893 if (rlist
) delete (RGNDATA
*) rlist
;
2898 wxUpdateIterator::operator int (void)
2900 if (current
< rects
)
2910 wxUpdateIterator
* wxUpdateIterator::operator ++(int)
2916 void wxUpdateIterator::GetRect(wxRect
*rect
)
2918 RECT
*mswRect
= ((RECT
*)rp
)+current
; //ought to error check this...
2919 rect
->x
= mswRect
->left
;
2920 rect
->y
= mswRect
->top
;
2921 rect
->width
= mswRect
->right
- mswRect
->left
;
2922 rect
->height
= mswRect
->bottom
- mswRect
->top
;
2925 int wxUpdateIterator::GetX()
2927 return ((RECT
*)rp
)[current
].left
;
2930 int wxUpdateIterator::GetY()
2932 return ((RECT
*)rp
)[current
].top
;
2935 int wxUpdateIterator::GetW()
2937 return ((RECT
*)rp
)[current
].right
-GetX();
2940 int wxUpdateIterator::GetH()
2942 return ((RECT
*)rp
)[current
].bottom
-GetY();
2945 wxWindow
*wxGetActiveWindow(void)
2947 HWND hWnd
= GetActiveWindow();
2950 return wxFindWinFromHandle((WXHWND
) hWnd
);
2955 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
2956 // in active frames and dialogs, regardless of where the focus is.
2957 static HHOOK wxTheKeyboardHook
= 0;
2958 static FARPROC wxTheKeyboardHookProc
= 0;
2959 int APIENTRY _EXPORT
2960 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
);
2962 void wxSetKeyboardHook(bool doIt
)
2966 wxTheKeyboardHookProc
= MakeProcInstance((FARPROC
) wxKeyboardHook
, wxGetInstance());
2967 wxTheKeyboardHook
= SetWindowsHookEx(WH_KEYBOARD
, (HOOKPROC
) wxTheKeyboardHookProc
, wxGetInstance(),
2969 GetCurrentThreadId());
2970 // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
2977 UnhookWindowsHookEx(wxTheKeyboardHook
);
2978 FreeProcInstance(wxTheKeyboardHookProc
);
2982 int APIENTRY _EXPORT
2983 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
)
2985 DWORD hiWord
= HIWORD(lParam
);
2986 if (nCode
!= HC_NOREMOVE
&& ((hiWord
& KF_UP
) == 0))
2989 if ((id
= wxCharCodeMSWToWX(wParam
)) != 0)
2991 wxKeyEvent
event(wxEVT_CHAR_HOOK
);
2992 if ((HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
2993 event
.m_altDown
= TRUE
;
2995 event
.m_eventObject
= NULL
;
2996 event
.m_keyCode
= id
;
2997 /* begin Albert's fix for control and shift key 26.5 */
2998 event
.m_shiftDown
= (::GetKeyState(VK_SHIFT
)&0x100?TRUE
:FALSE
);
2999 event
.m_controlDown
= (::GetKeyState(VK_CONTROL
)&0x100?TRUE
:FALSE
);
3000 /* end Albert's fix for control and shift key 26.5 */
3001 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
3003 wxWindow
*win
= wxGetActiveWindow();
3006 if (win
->GetEventHandler()->ProcessEvent(event
))
3011 if ( wxTheApp
&& wxTheApp
->ProcessEvent(event
) )
3016 return (int)CallNextHookEx(wxTheKeyboardHook
, nCode
, wParam
, lParam
);
3019 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int WXUNUSED(incW
), int WXUNUSED(incH
))
3027 void wxWindow::Centre(int direction
)
3029 int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
;
3031 wxWindow
*father
= (wxWindow
*)GetParent();
3035 father
->GetClientSize(&panel_width
, &panel_height
);
3036 GetSize(&width
, &height
);
3037 GetPosition(&x
, &y
);
3042 if (direction
& wxHORIZONTAL
)
3043 new_x
= (int)((panel_width
- width
)/2);
3045 if (direction
& wxVERTICAL
)
3046 new_y
= (int)((panel_height
- height
)/2);
3048 SetSize(new_x
, new_y
, -1, -1);
3053 void wxWindow::OnPaint(void)
3055 PaintSelectionHandles();
3059 void wxWindow::WarpPointer (int x_pos
, int y_pos
)
3061 // Move the pointer to (x_pos,y_pos) coordinates. They are expressed in
3062 // pixel coordinates, relatives to the canvas -- So, we first need to
3063 // substract origin of the window, then convert to screen position
3065 int x
= x_pos
; int y
= y_pos
;
3066 /* Leave this to the app to decide (and/or wxScrolledWindow)
3067 x -= m_xScrollPosition * m_xScrollPixelsPerLine;
3068 y -= m_yScrollPosition * m_yScrollPixelsPerLine;
3071 GetWindowRect ((HWND
) GetHWND(), &rect
);
3076 SetCursorPos (x
, y
);
3079 void wxWindow::MSWDeviceToLogical (float *x
, float *y
) const
3082 // Do we have a SetUserScale in wxWindow too, so we can
3083 // get mouse events scaled?
3087 *x = m_windowDC->DeviceToLogicalX ((int) *x);
3088 *y = m_windowDC->DeviceToLogicalY ((int) *y);
3093 bool wxWindow::MSWOnEraseBkgnd (WXHDC pDC
)
3101 wxEraseEvent
event(m_windowId
, &dc
);
3102 event
.m_eventObject
= this;
3103 if (!GetEventHandler()->ProcessEvent(event
))
3106 dc
.SelectOldObjects(pDC
);
3112 dc
.SelectOldObjects(pDC
);
3115 dc
.SetHDC((WXHDC
) NULL
);
3119 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
3122 ::GetClientRect((HWND
) GetHWND(), &rect
);
3124 HBRUSH hBrush
= ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
3125 int mode
= ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), MM_TEXT
);
3127 // ::GetClipBox((HDC) event.GetDC()->GetHDC(), &rect);
3128 ::FillRect ((HDC
) event
.GetDC()->GetHDC(), &rect
, hBrush
);
3129 ::DeleteObject(hBrush
);
3130 ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), mode
);
3132 // Less efficient version (and doesn't account for scrolling)
3134 GetClientSize(& w, & h);
3135 wxBrush *brush = wxTheBrushList->FindOrCreateBrush(& GetBackgroundColour(), wxSOLID);
3136 event.GetDC()->SetBrush(brush);
3137 event.GetDC()->SetPen(wxTRANSPARENT_PEN);
3139 event.GetDC()->DrawRectangle(0, 0, w+1, h+1);
3143 #if WXWIN_COMPATIBILITY
3144 void wxWindow::SetScrollRange(int orient
, int range
, bool refresh
)
3146 #if defined(__WIN95__)
3150 // Try to adjust the range to cope with page size > 1
3151 // - a Windows API quirk
3152 int pageSize
= GetScrollPage(orient
);
3153 if ( pageSize
> 1 && range
> 0)
3155 range1
+= (pageSize
- 1);
3161 if (orient
== wxHORIZONTAL
) {
3167 info
.cbSize
= sizeof(SCROLLINFO
);
3168 info
.nPage
= pageSize
; // Have to set this, or scrollbar goes awry
3172 info
.fMask
= SIF_RANGE
| SIF_PAGE
;
3174 HWND hWnd
= (HWND
) GetHWND();
3176 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3179 if (orient
== wxHORIZONTAL
)
3184 HWND hWnd
= (HWND
) GetHWND();
3186 ::SetScrollRange(hWnd
, wOrient
, 0, range
, refresh
);
3190 void wxWindow::SetScrollPage(int orient
, int page
, bool refresh
)
3192 #if defined(__WIN95__)
3196 if (orient
== wxHORIZONTAL
) {
3198 m_xThumbSize
= page
;
3201 m_yThumbSize
= page
;
3204 info
.cbSize
= sizeof(SCROLLINFO
);
3207 info
.fMask
= SIF_PAGE
;
3209 HWND hWnd
= (HWND
) GetHWND();
3211 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3213 if (orient
== wxHORIZONTAL
)
3214 m_xThumbSize
= page
;
3216 m_yThumbSize
= page
;
3220 int wxWindow::OldGetScrollRange(int orient
) const
3223 if (orient
== wxHORIZONTAL
)
3228 #if __WATCOMC__ && defined(__WINDOWS_386__)
3229 short minPos
, maxPos
;
3233 HWND hWnd
= (HWND
) GetHWND();
3236 ::GetScrollRange(hWnd
, wOrient
, &minPos
, &maxPos
);
3237 #if defined(__WIN95__)
3238 // Try to adjust the range to cope with page size > 1
3239 // - a Windows API quirk
3240 int pageSize
= GetScrollPage(orient
);
3243 maxPos
-= (pageSize
- 1);
3252 int wxWindow::GetScrollPage(int orient
) const
3254 if (orient
== wxHORIZONTAL
)
3255 return m_xThumbSize
;
3257 return m_yThumbSize
;
3261 int wxWindow::GetScrollPos(int orient
) const
3264 if (orient
== wxHORIZONTAL
)
3268 HWND hWnd
= (HWND
) GetHWND();
3271 return ::GetScrollPos(hWnd
, wOrient
);
3277 // This now returns the whole range, not just the number
3278 // of positions that we can scroll.
3279 int wxWindow::GetScrollRange(int orient
) const
3282 if (orient
== wxHORIZONTAL
)
3287 #if __WATCOMC__ && defined(__WINDOWS_386__)
3288 short minPos
, maxPos
;
3292 HWND hWnd
= (HWND
) GetHWND();
3295 ::GetScrollRange(hWnd
, wOrient
, &minPos
, &maxPos
);
3296 #if defined(__WIN95__)
3297 // Try to adjust the range to cope with page size > 1
3298 // - a Windows API quirk
3299 int pageSize
= GetScrollPage(orient
);
3302 maxPos
-= (pageSize
- 1);
3304 // October 10th: new range concept.
3314 int wxWindow::GetScrollThumb(int orient
) const
3316 if (orient
== wxHORIZONTAL
)
3317 return m_xThumbSize
;
3319 return m_yThumbSize
;
3322 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
3324 #if defined(__WIN95__)
3328 if (orient
== wxHORIZONTAL
) {
3334 info
.cbSize
= sizeof(SCROLLINFO
);
3338 info
.fMask
= SIF_POS
;
3340 HWND hWnd
= (HWND
) GetHWND();
3342 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3345 if (orient
== wxHORIZONTAL
)
3350 HWND hWnd
= (HWND
) GetHWND();
3352 ::SetScrollPos(hWnd
, wOrient
, pos
, refresh
);
3356 // New function that will replace some of the above.
3357 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
3358 int range
, bool refresh
)
3361 SetScrollPage(orient, thumbVisible, FALSE);
3363 int oldRange = range - thumbVisible ;
3364 SetScrollRange(orient, oldRange, FALSE);
3366 SetScrollPos(orient, pos, refresh);
3368 #if defined(__WIN95__)
3369 int oldRange
= range
- thumbVisible
;
3371 int range1
= oldRange
;
3373 // Try to adjust the range to cope with page size > 1
3374 // - a Windows API quirk
3375 int pageSize
= thumbVisible
;
3376 if ( pageSize
> 1 && range
> 0)
3378 range1
+= (pageSize
- 1);
3384 if (orient
== wxHORIZONTAL
) {
3390 info
.cbSize
= sizeof(SCROLLINFO
);
3391 info
.nPage
= pageSize
; // Have to set this, or scrollbar goes awry
3395 info
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
3397 HWND hWnd
= (HWND
) GetHWND();
3399 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3402 if (orient
== wxHORIZONTAL
)
3407 HWND hWnd
= (HWND
) GetHWND();
3410 ::SetScrollRange(hWnd
, wOrient
, 0, range
, FALSE
);
3411 ::SetScrollPos(hWnd
, wOrient
, pos
, refresh
);
3414 if (orient
== wxHORIZONTAL
) {
3415 m_xThumbSize
= thumbVisible
;
3417 m_yThumbSize
= thumbVisible
;
3421 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRectangle
*rect
)
3426 rect2
.left
= rect
->x
;
3427 rect2
.top
= rect
->y
;
3428 rect2
.right
= rect
->x
+ rect
->width
;
3429 rect2
.bottom
= rect
->y
+ rect
->height
;
3433 ::ScrollWindow((HWND
) GetHWND(), dx
, dy
, &rect2
, NULL
);
3435 ::ScrollWindow((HWND
) GetHWND(), dx
, dy
, NULL
, NULL
);
3438 void wxWindow::OnSize(wxSizeEvent
& event
)
3442 if (GetAutoLayout())
3448 void wxWindow::CalcScrolledPosition(int x, int y, int *xx, int *yy) const
3454 void wxWindow::CalcUnscrolledPosition(int x, int y, float *xx, float *yy) const
3461 void wxWindow::SetFont(const wxFont
& font
)
3463 // Decrement the usage count of the old label font
3464 // (we may be able to free it up)
3465 // if (GetFont()->Ok())
3466 // GetFont()->ReleaseResource();
3468 m_windowFont
= font
;
3470 if (!m_windowFont
.Ok())
3473 // m_windowFont.UseResource();
3475 HWND hWnd
= (HWND
) GetHWND();
3478 // m_windowFont.RealizeResource();
3480 if (m_windowFont
.GetResourceHandle())
3481 SendMessage(hWnd
, WM_SETFONT
,
3482 (WPARAM
)m_windowFont
.GetResourceHandle(),TRUE
);
3486 void wxWindow::SubclassWin(WXHWND hWnd
)
3488 wxAssociateWinWithHandle((HWND
)hWnd
, this);
3490 m_oldWndProc
= (WXFARPROC
) GetWindowLong((HWND
) hWnd
, GWL_WNDPROC
);
3491 SetWindowLong((HWND
) hWnd
, GWL_WNDPROC
, (LONG
) wxWndProc
);
3494 void wxWindow::UnsubclassWin(void)
3496 wxRemoveHandleAssociation(this);
3498 // Restore old Window proc
3499 if ((HWND
) GetHWND())
3501 FARPROC farProc
= (FARPROC
) GetWindowLong((HWND
) GetHWND(), GWL_WNDPROC
);
3502 if ((m_oldWndProc
!= 0) && (farProc
!= (FARPROC
) m_oldWndProc
))
3504 SetWindowLong((HWND
) GetHWND(), GWL_WNDPROC
, (LONG
) m_oldWndProc
);
3510 // Make a Windows extended style from the given wxWindows window style
3511 WXDWORD
wxWindow::MakeExtendedStyle(long style
, bool eliminateBorders
)
3513 WXDWORD exStyle
= 0;
3514 if ( style
& wxTRANSPARENT_WINDOW
)
3515 exStyle
|= WS_EX_TRANSPARENT
;
3517 if ( !eliminateBorders
)
3519 if ( style
& wxSUNKEN_BORDER
)
3520 exStyle
|= WS_EX_CLIENTEDGE
;
3521 if ( style
& wxDOUBLE_BORDER
)
3522 exStyle
|= WS_EX_DLGMODALFRAME
;
3523 #if defined(__WIN95__)
3524 if ( style
& wxRAISED_BORDER
)
3525 exStyle
|= WS_EX_WINDOWEDGE
;
3526 if ( style
& wxSTATIC_BORDER
)
3527 exStyle
|= WS_EX_STATICEDGE
;
3533 // Determines whether native 3D effects or CTL3D should be used,
3534 // applying a default border style if required, and returning an extended
3535 // style to pass to CreateWindowEx.
3536 WXDWORD
wxWindow::Determine3DEffects(WXDWORD defaultBorderStyle
, bool *want3D
)
3538 // If matches certain criteria, then assume no 3D effects
3539 // unless specifically requested (dealt with in MakeExtendedStyle)
3540 if ( !GetParent() || !IsKindOf(CLASSINFO(wxControl
)) || (m_windowStyle
& wxNO_BORDER
) )
3543 return MakeExtendedStyle(m_windowStyle
, FALSE
);
3546 // Determine whether we should be using 3D effects or not.
3547 bool nativeBorder
= FALSE
; // by default, we don't want a Win95 effect
3549 // 1) App can specify global 3D effects
3550 *want3D
= wxTheApp
->GetAuto3D();
3552 // 2) If the parent is being drawn with user colours, or simple border specified,
3553 // switch effects off. TODO: replace wxUSER_COLOURS with wxNO_3D
3554 if (GetParent() && (GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
) || (m_windowStyle
& wxSIMPLE_BORDER
))
3557 // 3) Control can override this global setting by defining
3558 // a border style, e.g. wxSUNKEN_BORDER
3559 if (m_windowStyle
& wxSUNKEN_BORDER
)
3562 // 4) If it's a special border, CTL3D can't cope so we want a native border
3563 if ( (m_windowStyle
& wxDOUBLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
3564 (m_windowStyle
& wxSTATIC_BORDER
) )
3567 nativeBorder
= TRUE
;
3570 // 5) If this isn't a Win95 app, and we are using CTL3D, remove border
3571 // effects from extended style
3574 nativeBorder
= FALSE
;
3577 DWORD exStyle
= MakeExtendedStyle(m_windowStyle
, !nativeBorder
);
3579 // If we want 3D, but haven't specified a border here,
3580 // apply the default border style specified.
3581 // TODO what about non-Win95 WIN32? Does it have borders?
3582 #if defined(__WIN95__) && !CTL3D
3583 if (defaultBorderStyle
&& (*want3D
) && ! ((m_windowStyle
& wxDOUBLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
3584 (m_windowStyle
& wxSTATIC_BORDER
) || (m_windowStyle
& wxSIMPLE_BORDER
) ))
3585 exStyle
|= defaultBorderStyle
; // WS_EX_CLIENTEDGE ;
3591 void wxWindow::OnChar(wxKeyEvent
& event
)
3594 int id
= wxCharCodeWXToMSW((int)event
.KeyCode(), &isVirtual
);
3599 if ( !event
.ControlDown() )
3600 (void) MSWDefWindowProc(m_lastMsg
, (WPARAM
) id
, m_lastLParam
);
3603 void wxWindow::OnPaint(wxPaintEvent
& event
)
3608 bool wxWindow::IsEnabled(void) const
3610 return (::IsWindowEnabled((HWND
) GetHWND()) != 0);
3613 // Dialog support: override these and call
3614 // base class members to add functionality
3615 // that can't be done using validators.
3616 // NOTE: these functions assume that controls
3617 // are direct children of this window, not grandchildren
3618 // or other levels of descendant.
3620 // Transfer values to controls. If returns FALSE,
3621 // it's an application error (pops up a dialog)
3622 bool wxWindow::TransferDataToWindow(void)
3624 wxNode
*node
= GetChildren()->First();
3627 wxWindow
*child
= (wxWindow
*)node
->Data();
3628 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */
3629 !child
->GetValidator()->TransferToWindow() )
3631 wxMessageBox("Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
3635 node
= node
->Next();
3640 // Transfer values from controls. If returns FALSE,
3641 // validation failed: don't quit
3642 bool wxWindow::TransferDataFromWindow(void)
3644 wxNode
*node
= GetChildren()->First();
3647 wxWindow
*child
= (wxWindow
*)node
->Data();
3648 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->TransferFromWindow() )
3653 node
= node
->Next();
3658 bool wxWindow::Validate(void)
3660 wxNode
*node
= GetChildren()->First();
3663 wxWindow
*child
= (wxWindow
*)node
->Data();
3664 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
3669 node
= node
->Next();
3674 // Get the window with the focus
3675 wxWindow
*wxWindow::FindFocus(void)
3677 HWND hWnd
= ::GetFocus();
3680 return wxFindWinFromHandle((WXHWND
) hWnd
);
3685 void wxWindow::AddChild(wxWindow
*child
)
3687 GetChildren()->Append(child
);
3688 child
->m_windowParent
= this;
3691 void wxWindow::RemoveChild(wxWindow
*child
)
3694 GetChildren()->DeleteObject(child
);
3695 child
->m_windowParent
= NULL
;
3698 void wxWindow::DestroyChildren(void)
3700 if (GetChildren()) {
3702 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
) {
3704 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
3706 if ( GetChildren()->Member(child
) )
3713 void wxWindow::MakeModal(bool modal
)
3715 // Disable all other windows
3716 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
3718 wxNode
*node
= wxTopLevelWindows
.First();
3721 wxWindow
*win
= (wxWindow
*)node
->Data();
3723 win
->Enable(!modal
);
3725 node
= node
->Next();
3730 // If nothing defined for this, try the parent.
3731 // E.g. we may be a button loaded from a resource, with no callback function
3733 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
3735 if (GetEventHandler()->ProcessEvent(event
) )
3738 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
3741 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
3745 UnsetConstraints(m_constraints
);
3746 delete m_constraints
;
3751 // Make sure other windows know they're part of a 'meaningful relationship'
3752 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
3753 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3754 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
3755 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3756 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
3757 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3758 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
3759 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3760 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
3761 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3762 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
3763 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3764 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
3765 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3766 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
3767 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3771 // This removes any dangling pointers to this window
3772 // in other windows' constraintsInvolvedIn lists.
3773 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
3777 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
3778 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3779 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
3780 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3781 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
3782 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3783 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
3784 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3785 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
3786 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3787 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
3788 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3789 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
3790 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3791 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
3792 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3796 // Back-pointer to other windows we're involved with, so if we delete
3797 // this window, we must delete any constraints we're involved with.
3798 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
3800 if (!m_constraintsInvolvedIn
)
3801 m_constraintsInvolvedIn
= new wxList
;
3802 if (!m_constraintsInvolvedIn
->Member(otherWin
))
3803 m_constraintsInvolvedIn
->Append(otherWin
);
3806 // REMOVE back-pointer to other windows we're involved with.
3807 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
3809 if (m_constraintsInvolvedIn
)
3810 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
3813 // Reset any constraints that mention this window
3814 void wxWindow::DeleteRelatedConstraints(void)
3816 if (m_constraintsInvolvedIn
)
3818 wxNode
*node
= m_constraintsInvolvedIn
->First();
3821 wxWindow
*win
= (wxWindow
*)node
->Data();
3822 wxNode
*next
= node
->Next();
3823 wxLayoutConstraints
*constr
= win
->GetConstraints();
3825 // Reset any constraints involving this window
3828 constr
->left
.ResetIfWin((wxWindow
*)this);
3829 constr
->top
.ResetIfWin((wxWindow
*)this);
3830 constr
->right
.ResetIfWin((wxWindow
*)this);
3831 constr
->bottom
.ResetIfWin((wxWindow
*)this);
3832 constr
->width
.ResetIfWin((wxWindow
*)this);
3833 constr
->height
.ResetIfWin((wxWindow
*)this);
3834 constr
->centreX
.ResetIfWin((wxWindow
*)this);
3835 constr
->centreY
.ResetIfWin((wxWindow
*)this);
3840 delete m_constraintsInvolvedIn
;
3841 m_constraintsInvolvedIn
= NULL
;
3845 void wxWindow::SetSizer(wxSizer
*sizer
)
3847 m_windowSizer
= sizer
;
3849 sizer
->SetSizerParent((wxWindow
*)this);
3856 bool wxWindow::Layout(void)
3858 if (GetConstraints())
3861 GetClientSize(&w
, &h
);
3862 GetConstraints()->width
.SetValue(w
);
3863 GetConstraints()->height
.SetValue(h
);
3866 // If top level (one sizer), evaluate the sizer's constraints.
3870 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
3871 GetSizer()->LayoutPhase1(&noChanges
);
3872 GetSizer()->LayoutPhase2(&noChanges
);
3873 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
3878 // Otherwise, evaluate child constraints
3879 ResetConstraints(); // Mark all constraints as unevaluated
3880 DoPhase(1); // Just one phase need if no sizers involved
3882 SetConstraintSizes(); // Recursively set the real window sizes
3888 // Do a phase of evaluating constraints:
3889 // the default behaviour. wxSizers may do a similar
3890 // thing, but also impose their own 'constraints'
3891 // and order the evaluation differently.
3892 bool wxWindow::LayoutPhase1(int *noChanges
)
3894 wxLayoutConstraints
*constr
= GetConstraints();
3897 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
3903 bool wxWindow::LayoutPhase2(int *noChanges
)
3913 // Do a phase of evaluating child constraints
3914 bool wxWindow::DoPhase(int phase
)
3916 int noIterations
= 0;
3917 int maxIterations
= 500;
3921 while ((noChanges
> 0) && (noIterations
< maxIterations
))
3925 wxNode
*node
= GetChildren()->First();
3928 wxWindow
*child
= (wxWindow
*)node
->Data();
3929 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
3931 wxLayoutConstraints
*constr
= child
->GetConstraints();
3934 if (succeeded
.Member(child
))
3939 int tempNoChanges
= 0;
3940 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
3941 noChanges
+= tempNoChanges
;
3944 succeeded
.Append(child
);
3949 node
= node
->Next();
3956 void wxWindow::ResetConstraints(void)
3958 wxLayoutConstraints
*constr
= GetConstraints();
3961 constr
->left
.SetDone(FALSE
);
3962 constr
->top
.SetDone(FALSE
);
3963 constr
->right
.SetDone(FALSE
);
3964 constr
->bottom
.SetDone(FALSE
);
3965 constr
->width
.SetDone(FALSE
);
3966 constr
->height
.SetDone(FALSE
);
3967 constr
->centreX
.SetDone(FALSE
);
3968 constr
->centreY
.SetDone(FALSE
);
3970 wxNode
*node
= GetChildren()->First();
3973 wxWindow
*win
= (wxWindow
*)node
->Data();
3974 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
3975 win
->ResetConstraints();
3976 node
= node
->Next();
3980 // Need to distinguish between setting the 'fake' size for
3981 // windows and sizers, and setting the real values.
3982 void wxWindow::SetConstraintSizes(bool recurse
)
3984 wxLayoutConstraints
*constr
= GetConstraints();
3985 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
3986 constr
->width
.GetDone() && constr
->height
.GetDone())
3988 int x
= constr
->left
.GetValue();
3989 int y
= constr
->top
.GetValue();
3990 int w
= constr
->width
.GetValue();
3991 int h
= constr
->height
.GetValue();
3993 // If we don't want to resize this window, just move it...
3994 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
3995 (constr
->height
.GetRelationship() != wxAsIs
))
3997 // Calls Layout() recursively. AAAGH. How can we stop that.
3998 // Simply take Layout() out of non-top level OnSizes.
3999 SizerSetSize(x
, y
, w
, h
);
4008 char *windowClass
= this->GetClassInfo()->GetClassName();
4011 if (GetName() == "")
4012 winName
= "unnamed";
4014 winName
= GetName();
4015 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
4016 if (!constr
->left
.GetDone())
4017 wxDebugMsg(" unsatisfied 'left' constraint.\n");
4018 if (!constr
->right
.GetDone())
4019 wxDebugMsg(" unsatisfied 'right' constraint.\n");
4020 if (!constr
->width
.GetDone())
4021 wxDebugMsg(" unsatisfied 'width' constraint.\n");
4022 if (!constr
->height
.GetDone())
4023 wxDebugMsg(" unsatisfied 'height' constraint.\n");
4024 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
4029 wxNode
*node
= GetChildren()->First();
4032 wxWindow
*win
= (wxWindow
*)node
->Data();
4033 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
4034 win
->SetConstraintSizes();
4035 node
= node
->Next();
4040 // This assumes that all sizers are 'on' the same
4041 // window, i.e. the parent of this window.
4042 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
4044 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
4045 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
4049 m_sizerParent
->GetPosition(&xp
, &yp
);
4050 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
4055 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
4059 TransformSizerToActual(&xx
, &yy
);
4060 SetSize(xx
, yy
, w
, h
);
4063 void wxWindow::SizerMove(int x
, int y
)
4067 TransformSizerToActual(&xx
, &yy
);
4071 // Only set the size/position of the constraint (if any)
4072 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
4074 wxLayoutConstraints
*constr
= GetConstraints();
4079 constr
->left
.SetValue(x
);
4080 constr
->left
.SetDone(TRUE
);
4084 constr
->top
.SetValue(y
);
4085 constr
->top
.SetDone(TRUE
);
4089 constr
->width
.SetValue(w
);
4090 constr
->width
.SetDone(TRUE
);
4094 constr
->height
.SetValue(h
);
4095 constr
->height
.SetDone(TRUE
);
4100 void wxWindow::MoveConstraint(int x
, int y
)
4102 wxLayoutConstraints
*constr
= GetConstraints();
4107 constr
->left
.SetValue(x
);
4108 constr
->left
.SetDone(TRUE
);
4112 constr
->top
.SetValue(y
);
4113 constr
->top
.SetDone(TRUE
);
4118 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
4120 wxLayoutConstraints
*constr
= GetConstraints();
4123 *w
= constr
->width
.GetValue();
4124 *h
= constr
->height
.GetValue();
4130 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
4132 wxLayoutConstraints
*constr
= GetConstraints();
4135 *w
= constr
->width
.GetValue();
4136 *h
= constr
->height
.GetValue();
4139 GetClientSize(w
, h
);
4142 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
4144 wxLayoutConstraints
*constr
= GetConstraints();
4147 *x
= constr
->left
.GetValue();
4148 *y
= constr
->top
.GetValue();
4154 bool wxWindow::Close(bool force
)
4156 // Let's generalise it to work the same for any window.
4158 if (!IsKindOf(CLASSINFO(wxDialog)) && !IsKindOf(CLASSINFO(wxFrame)))
4165 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
4166 event
.SetEventObject(this);
4167 event
.SetForce(force
);
4169 return GetEventHandler()->ProcessEvent(event
);
4172 if ( !force && event.GetVeto() )
4177 if (!wxPendingDelete.Member(this))
4178 wxPendingDelete.Append(this);
4184 wxObject
* wxWindow::GetChild(int number
) const
4186 // Return a pointer to the Nth object in the Panel
4189 wxNode
*node
= GetChildren()->First();
4192 node
= node
->Next() ;
4195 wxObject
*obj
= (wxObject
*)node
->Data();
4202 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
4204 /* This is obsolete now; if we wish to intercept listbox double-clicks,
4205 * we explicitly intercept the wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
4208 if (initiatingItem->IsKindOf(CLASSINFO(wxListBox)))
4210 wxListBox *lbox = (wxListBox *)initiatingItem;
4211 wxCommandEvent event(wxEVT_COMMAND_LEFT_DCLICK);
4212 event.m_commandInt = -1;
4213 if ((lbox->GetWindowStyleFlag() & wxLB_MULTIPLE) == 0)
4215 event.m_commandString = copystring(lbox->GetStringSelection());
4216 event.m_commandInt = lbox->GetSelection();
4217 event.m_clientData = lbox->wxListBox::GetClientData(event.m_commandInt);
4219 event.m_eventObject = lbox;
4221 lbox->ProcessCommand(event);
4223 if (event.m_commandString)
4224 delete[] event.m_commandString;
4228 wxButton *but = GetDefaultItem();
4231 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
4232 event.SetEventObject(but);
4233 but->Command(event);
4238 void wxWindow::Clear(void)
4240 wxClientDC
dc(this);
4241 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
4242 dc
.SetBackground(brush
);
4246 // Fits the panel around the items
4247 void wxWindow::Fit(void)
4251 wxNode
*node
= GetChildren()->First();
4254 wxWindow
*win
= (wxWindow
*)node
->Data();
4256 win
->GetPosition(&wx
, &wy
);
4257 win
->GetSize(&ww
, &wh
);
4258 if ( wx
+ ww
> maxX
)
4260 if ( wy
+ wh
> maxY
)
4263 node
= node
->Next();
4265 SetClientSize(maxX
+ 5, maxY
+ 5);
4268 void wxWindow::SetValidator(const wxValidator
& validator
)
4270 if ( m_windowValidator
)
4271 delete m_windowValidator
;
4272 m_windowValidator
= validator
.Clone();
4274 if ( m_windowValidator
)
4275 m_windowValidator
->SetWindow(this) ;
4278 // Find a window by id or name
4279 wxWindow
*wxWindow::FindWindow(long id
)
4284 wxNode
*node
= GetChildren()->First();
4287 wxWindow
*child
= (wxWindow
*)node
->Data();
4288 wxWindow
*found
= child
->FindWindow(id
);
4291 node
= node
->Next();
4296 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
4298 if ( GetName() == name
)
4301 wxNode
*node
= GetChildren()->First();
4304 wxWindow
*child
= (wxWindow
*)node
->Data();
4305 wxWindow
*found
= child
->FindWindow(name
);
4308 node
= node
->Next();
4314 // Default input behaviour for a scrolling canvas should be to scroll
4315 // according to the cursor keys pressed
4316 void wxWindow::OnChar(wxKeyEvent& event)
4328 GetScrollUnitsPerPage(&x_page, &y_page);
4330 GetVirtualSize(&v_width,&v_height);
4332 ViewStart(&start_x, &start_y);
4335 y_pages = (int)(v_height/vert_units) - y_page;
4343 switch (event.keyCode)
4350 if (start_y - y_page > 0)
4351 Scroll(start_x, start_y - y_page);
4361 if ((y_page > 0) && (start_y <= y_pages-y-1))
4363 if (y_pages + y < start_y + y_page)
4364 Scroll(start_x, y_pages + y);
4366 Scroll(start_x, start_y + y_page);
4373 if ((y_page > 0) && (start_y >= 1))
4374 Scroll(start_x, start_y - 1);
4380 if ((y_page > 0) && (start_y <= y_pages-y-1))
4383 Scroll(start_x, start_y + 1);
4389 if ((x_page > 0) && (start_x >= 1))
4390 Scroll(start_x - 1, start_y);
4396 Scroll(start_x + 1, start_y);
4407 Scroll(start_x, y_pages+y);
4415 // Setup background and foreground colours correctly
4416 void wxWindow::SetupColours(void)
4419 SetBackgroundColour(GetParent()->GetBackgroundColour());
4422 // Do Update UI processing for child controls
4424 // TODO: should this be implemented for the child window rather
4425 // than the parent? Then you can override it e.g. for wxCheckBox
4426 // to do the Right Thing rather than having to assume a fixed number
4427 // of control classes.
4429 void wxWindow::UpdateWindowUI(void)
4431 wxWindowID id
= GetId();
4434 wxUpdateUIEvent
event(id
);
4435 event
.m_eventObject
= this;
4437 if (this->GetEventHandler()->ProcessEvent(event
))
4439 if (event
.GetSetEnabled())
4440 this->Enable(event
.GetEnabled());
4442 if (event
.GetSetText() && this->IsKindOf(CLASSINFO(wxControl
)))
4443 ((wxControl
*)this)->SetLabel(event
.GetText());
4445 if (this->IsKindOf(CLASSINFO(wxCheckBox
)))
4447 if (event
.GetSetChecked())
4448 ((wxCheckBox
*) this)->SetValue(event
.GetChecked());
4450 else if (this->IsKindOf(CLASSINFO(wxRadioButton
)))
4452 if (event
.GetSetChecked())
4453 ((wxRadioButton
*) this)->SetValue(event
.GetChecked());
4460 void wxWindow::OnIdle(wxIdleEvent
& event
)
4462 // Check if we need to send a LEAVE event
4463 if (m_mouseInWindow
)
4466 ::GetCursorPos(&pt
);
4467 if (::WindowFromPoint(pt
) != (HWND
) GetHWND())
4469 // Generate a LEAVE event
4470 m_mouseInWindow
= FALSE
;
4471 MSWOnMouseLeave(pt
.x
, pt
.y
, 0);
4477 // Raise the window to the top of the Z order
4478 void wxWindow::Raise(void)
4480 ::BringWindowToTop((HWND
) GetHWND());
4483 // Lower the window to the bottom of the Z order
4484 void wxWindow::Lower(void)
4486 ::SetWindowPos((HWND
) GetHWND(), HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);