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 OldOnInitMenuPopup(pos);
1677 bool wxWindow::MSWOnActivate(int state
, bool WXUNUSED(minimized
), WXHWND
WXUNUSED(activate
))
1680 wxDebugMsg("wxWindow::MSWOnActivate %d\n", handle
);
1683 wxActivateEvent
event(wxEVT_ACTIVATE
, ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)),
1685 event
.SetEventObject(this);
1686 GetEventHandler()->ProcessEvent(event
);
1690 bool wxWindow::MSWOnSetFocus(WXHWND
WXUNUSED(hwnd
))
1693 wxDebugMsg("wxWindow::MSWOnSetFocus %d\n", m_hWnd
);
1696 if (m_caretEnabled
&& (m_caretWidth
> 0) && (m_caretHeight
> 0))
1698 ::CreateCaret((HWND
) GetHWND(), NULL
, m_caretWidth
, m_caretHeight
);
1700 ::ShowCaret((HWND
) GetHWND());
1703 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
1704 event
.SetEventObject(this);
1705 if (!GetEventHandler()->ProcessEvent(event
))
1710 bool wxWindow::MSWOnKillFocus(WXHWND
WXUNUSED(hwnd
))
1713 wxDebugMsg("wxWindow::MSWOnKillFocus %d\n", m_hWnd
);
1721 wxFocusEvent
event(wxEVT_KILL_FOCUS
, m_windowId
);
1722 event
.SetEventObject(this);
1723 if (!GetEventHandler()->ProcessEvent(event
))
1728 void wxWindow::MSWOnDropFiles(WXWPARAM wParam
)
1731 wxDebugMsg("wxWindow::MSWOnDropFiles %d\n", m_hWnd
);
1734 HANDLE hFilesInfo
= (HANDLE
)wParam
;
1736 DragQueryPoint(hFilesInfo
, (LPPOINT
) &dropPoint
);
1738 // Get the total number of files dropped
1739 WORD gwFilesDropped
= (WORD
)DragQueryFile ((HDROP
)hFilesInfo
,
1744 wxString
*files
= new wxString
[gwFilesDropped
];
1746 for (wIndex
=0; wIndex
< (int)gwFilesDropped
; wIndex
++)
1748 DragQueryFile (hFilesInfo
, wIndex
, (LPSTR
) wxBuffer
, 1000);
1749 files
[wIndex
] = wxBuffer
;
1751 DragFinish (hFilesInfo
);
1753 wxDropFilesEvent
event(wxEVT_DROP_FILES
, gwFilesDropped
, files
);
1754 event
.m_eventObject
= this;
1755 event
.m_pos
.x
= dropPoint
.x
; event
.m_pos
.x
= dropPoint
.y
;
1757 if (!GetEventHandler()->ProcessEvent(event
))
1763 bool wxWindow::MSWOnDrawItem(int id
, WXDRAWITEMSTRUCT
*itemStruct
)
1766 if ( id
== 0 ) { // is it a menu item?
1767 DRAWITEMSTRUCT
*pDrawStruct
= (DRAWITEMSTRUCT
*)itemStruct
;
1768 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pDrawStruct
->itemData
);
1769 wxCHECK( pMenuItem
->IsKindOf(CLASSINFO(wxMenuItem
)), FALSE
);
1771 // prepare to call OnDrawItem()
1773 dc
.SetHDC((WXHDC
)pDrawStruct
->hDC
, FALSE
);
1774 wxRect
rect(pDrawStruct
->rcItem
.left
, pDrawStruct
->rcItem
.top
,
1775 pDrawStruct
->rcItem
.right
- pDrawStruct
->rcItem
.left
,
1776 pDrawStruct
->rcItem
.bottom
- pDrawStruct
->rcItem
.top
);
1777 return pMenuItem
->OnDrawItem(
1779 (wxOwnerDrawn::wxODAction
)pDrawStruct
->itemAction
,
1780 (wxOwnerDrawn::wxODStatus
)pDrawStruct
->itemState
1783 #endif // owner-drawn menus
1785 wxWindow
*item
= FindItem(id
);
1786 #if USE_DYNAMIC_CLASSES
1787 if (item
&& item
->IsKindOf(CLASSINFO(wxControl
)))
1789 return ((wxControl
*)item
)->MSWOnDraw(itemStruct
);
1796 bool wxWindow::MSWOnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*itemStruct
)
1799 if ( id
== 0 ) { // is it a menu item?
1800 MEASUREITEMSTRUCT
*pMeasureStruct
= (MEASUREITEMSTRUCT
*)itemStruct
;
1801 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pMeasureStruct
->itemData
);
1802 wxCHECK( pMenuItem
->IsKindOf(CLASSINFO(wxMenuItem
)), FALSE
);
1804 return pMenuItem
->OnMeasureItem(&pMeasureStruct
->itemWidth
,
1805 &pMeasureStruct
->itemHeight
);
1807 #endif // owner-drawn menus
1809 wxWindow
*item
= FindItem(id
);
1810 #if USE_DYNAMIC_CLASSES
1811 if (item
&& item
->IsKindOf(CLASSINFO(wxControl
)))
1813 return ((wxControl
*)item
)->MSWOnMeasure(itemStruct
);
1820 WXHBRUSH
wxWindow::MSWOnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
1821 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1824 wxDebugMsg("wxWindow::MSWOnCtlColour %d\n", m_hWnd
);
1826 if (nCtlColor
== CTLCOLOR_DLG
)
1828 return OnCtlColor(pDC
, pWnd
, nCtlColor
, message
, wParam
, lParam
);
1831 wxControl
*item
= (wxControl
*)FindItemByHWND(pWnd
, TRUE
);
1833 WXHBRUSH hBrush
= 0;
1836 hBrush
= item
->OnCtlColor(pDC
, pWnd
, nCtlColor
, message
, wParam
, lParam
);
1838 // I think that even for dialogs, we may need to call DefWindowProc (?)
1839 // Or maybe just rely on the usual default behaviour.
1841 hBrush
= (WXHBRUSH
) MSWDefWindowProc(message
, wParam
, lParam
);
1846 // Define for each class of dialog and control
1847 WXHBRUSH
wxWindow::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
1848 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1850 return (WXHBRUSH
) MSWDefWindowProc(message
, wParam
, lParam
);
1853 bool wxWindow::MSWOnColorChange(WXHWND hWnd
, WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1855 wxSysColourChangedEvent event
;
1856 event
.m_eventObject
= this;
1858 // Check if app handles this.
1859 if (GetEventHandler()->ProcessEvent(event
))
1862 // We didn't process it
1866 // Responds to colour changes: passes event on to children.
1867 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1869 wxNode
*node
= GetChildren()->First();
1872 // Only propagate to non-top-level windows
1873 wxWindow
*win
= (wxWindow
*)node
->Data();
1874 if ( win
->GetParent() )
1876 wxSysColourChangedEvent event2
;
1877 event
.m_eventObject
= win
;
1878 win
->GetEventHandler()->ProcessEvent(event2
);
1881 node
= node
->Next();
1885 long wxWindow::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1888 return ::CallWindowProc(CASTWNDPROC (FARPROC
) m_oldWndProc
, (HWND
) GetHWND(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1890 return ::DefWindowProc((HWND
) GetHWND(), nMsg
, wParam
, lParam
);
1893 long wxWindow::Default()
1895 // Ignore 'fake' events (perhaps generated as a result of a separate real event)
1899 return this->MSWDefWindowProc(m_lastMsg
, m_lastWParam
, m_lastLParam
);
1902 bool wxWindow::MSWProcessMessage(WXMSG
* pMsg
)
1908 // Suggestion by Andrew Davison to allow
1909 // a panel to accept character input in user edit mode
1911 // OK, what we probably want to do here for wxWin 2.0
1912 // is have a window style to indicate whether the window
1913 // should process dialog-style input, since we can't
1914 // otherwise tell whether it's supposed to do tab traversal
1916 if (GetWindowStyleFlag() & wxTAB_TRAVERSAL
)
1917 return (::IsDialogMessage((HWND
) m_hWnd
, (MSG
*)pMsg
) != 0);
1923 long wxWindow::MSWOnMDIActivate(long WXUNUSED(flag
), WXHWND
WXUNUSED(activate
), WXHWND
WXUNUSED(deactivate
))
1926 wxDebugMsg("wxWindow::MSWOnMDIActivate %d\n", m_hWnd
);
1931 void wxWindow::MSWDetachWindowMenu(void)
1935 int N
= GetMenuItemCount((HMENU
) m_hMenu
);
1937 for (i
= 0; i
< N
; i
++)
1940 int chars
= GetMenuString((HMENU
) m_hMenu
, i
, buf
, 100, MF_BYPOSITION
);
1941 if ((chars
> 0) && (strcmp(buf
, "&Window") == 0))
1943 RemoveMenu((HMENU
) m_hMenu
, i
, MF_BYPOSITION
);
1950 bool wxWindow::MSWOnPaint(void)
1952 wxPaintEvent
event(m_windowId
);
1953 event
.SetEventObject(this);
1954 if (!GetEventHandler()->ProcessEvent(event
))
1959 void wxWindow::MSWOnSize(int w
, int h
, WXUINT
WXUNUSED(flag
))
1965 wxDebugMsg("wxWindow::MSWOnSize %d\n", m_hWnd
);
1972 wxSizeEvent
event(wxSize(w
, h
), m_windowId
);
1973 event
.SetEventObject(this);
1974 if (!GetEventHandler()->ProcessEvent(event
))
1980 void wxWindow::MSWOnWindowPosChanging(void *WXUNUSED(lpPos
))
1985 // Deal with child commands from buttons etc.
1986 bool wxWindow::MSWOnCommand(WXWORD id
, WXWORD cmd
, WXHWND
WXUNUSED(control
))
1989 wxDebugMsg("wxWindow::MSWOnCommand\n");
1991 if (wxCurrentPopupMenu
)
1993 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
1994 wxCurrentPopupMenu
= NULL
;
1995 bool succ
= popupMenu
->MSWCommand(cmd
, id
);
2000 sprintf(buf
, "Looking for item %d...\n", id
);
2004 wxWindow
*item
= FindItem(id
);
2007 bool value
= item
->MSWCommand(cmd
, id
);
2010 wxDebugMsg("MSWCommand succeeded\n");
2012 wxDebugMsg("MSWCommand failed\n");
2019 wxDebugMsg("Could not find item!\n");
2021 wxDebugMsg("Item ids for this panel:\n");
2023 wxNode
*current
= GetChildren()->First();
2026 wxObject
*obj
= (wxObject
*)current
->Data() ;
2027 if (obj
->IsKindOf(CLASSINFO(wxControl
)))
2029 wxControl
*item
= (wxControl
*)current
->Data();
2030 sprintf(buf
, " %d\n", (int)item
->m_windowId
);
2033 current
= current
->Next();
2041 long wxWindow::MSWOnSysCommand(WXWPARAM wParam
, WXLPARAM lParam
)
2047 wxMaximizeEvent
event(m_windowId
);
2048 event
.SetEventObject(this);
2049 if (!GetEventHandler()->ProcessEvent(event
))
2057 wxIconizeEvent
event(m_windowId
);
2058 event
.SetEventObject(this);
2059 if (!GetEventHandler()->ProcessEvent(event
))
2071 void wxWindow::MSWOnLButtonDown(int x
, int y
, WXUINT flags
)
2073 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
2075 event
.m_x
= x
; event
.m_y
= y
;
2076 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2077 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2078 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2079 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2080 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2081 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2082 event
.m_eventObject
= this;
2084 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVENT_TYPE_LEFT_DOWN
;
2086 if (!GetEventHandler()->ProcessEvent(event
))
2090 void wxWindow::MSWOnLButtonUp(int x
, int y
, WXUINT flags
)
2092 wxMouseEvent
event(wxEVT_LEFT_UP
);
2094 event
.m_x
= x
; event
.m_y
= y
;
2095 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2096 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2097 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2098 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2099 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2100 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2101 event
.m_eventObject
= this;
2103 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_LEFT_UP
;
2105 if (!GetEventHandler()->ProcessEvent(event
))
2109 void wxWindow::MSWOnLButtonDClick(int x
, int y
, WXUINT flags
)
2111 wxMouseEvent
event(wxEVT_LEFT_DCLICK
);
2113 event
.m_x
= x
; event
.m_y
= y
;
2114 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2115 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2116 event
.m_leftDown
= ((flags
& MK_LBUTTON
!= 0));
2117 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2118 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2119 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2120 event
.m_eventObject
= this;
2122 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_LEFT_DCLICK
;
2124 if (!GetEventHandler()->ProcessEvent(event
))
2128 void wxWindow::MSWOnMButtonDown(int x
, int y
, WXUINT flags
)
2130 wxMouseEvent
event(wxEVT_MIDDLE_DOWN
);
2132 event
.m_x
= x
; event
.m_y
= y
;
2133 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2134 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2135 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2136 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2137 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2138 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2139 event
.m_eventObject
= this;
2141 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_MIDDLE_DOWN
;
2143 if (!GetEventHandler()->ProcessEvent(event
))
2147 void wxWindow::MSWOnMButtonUp(int x
, int y
, WXUINT flags
)
2149 //wxDebugMsg("MButtonUp\n") ;
2150 wxMouseEvent
event(wxEVT_MIDDLE_UP
);
2152 event
.m_x
= x
; event
.m_y
= y
;
2153 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2154 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2155 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2156 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2157 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2158 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2159 event
.m_eventObject
= this;
2161 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_MIDDLE_UP
;
2163 if (!GetEventHandler()->ProcessEvent(event
))
2167 void wxWindow::MSWOnMButtonDClick(int x
, int y
, WXUINT flags
)
2169 wxMouseEvent
event(wxEVT_MIDDLE_DCLICK
);
2171 event
.m_x
= x
; event
.m_y
= y
;
2172 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2173 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2174 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2175 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2176 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2177 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2178 event
.m_eventObject
= this;
2180 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_MIDDLE_DCLICK
;
2182 if (!GetEventHandler()->ProcessEvent(event
))
2186 void wxWindow::MSWOnRButtonDown(int x
, int y
, WXUINT flags
)
2188 wxMouseEvent
event(wxEVT_RIGHT_DOWN
);
2190 event
.m_x
= x
; event
.m_y
= y
;
2191 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2192 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2193 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2194 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2195 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2196 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2197 event
.m_eventObject
= this;
2199 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_RIGHT_DOWN
;
2201 if (!GetEventHandler()->ProcessEvent(event
))
2205 void wxWindow::MSWOnRButtonUp(int x
, int y
, WXUINT flags
)
2207 wxMouseEvent
event(wxEVT_RIGHT_UP
);
2209 event
.m_x
= x
; event
.m_y
= y
;
2210 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2211 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2212 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2213 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2214 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2215 event
.m_eventObject
= this;
2216 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2218 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_RIGHT_UP
;
2220 if (!GetEventHandler()->ProcessEvent(event
))
2224 void wxWindow::MSWOnRButtonDClick(int x
, int y
, WXUINT flags
)
2226 wxMouseEvent
event(wxEVT_RIGHT_DCLICK
);
2228 event
.m_x
= x
; event
.m_y
= y
;
2229 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2230 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2231 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2232 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2233 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2234 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2235 event
.m_eventObject
= this;
2237 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
; m_lastEvent
= wxEVT_RIGHT_DCLICK
;
2239 if (!GetEventHandler()->ProcessEvent(event
))
2243 void wxWindow::MSWOnMouseMove(int x
, int y
, WXUINT flags
)
2245 // 'normal' move event...
2246 // Set cursor, but only if we're not in 'busy' mode
2248 // Trouble with this is that it sets the cursor for controls too :-(
2249 if (m_windowCursor
.Ok() && !wxIsBusy())
2250 ::SetCursor((HCURSOR
) m_windowCursor
.GetHCURSOR());
2252 if (!m_mouseInWindow
)
2254 // Generate an ENTER event
2255 m_mouseInWindow
= TRUE
;
2256 MSWOnMouseEnter(x
, y
, flags
);
2259 wxMouseEvent
event(wxEVT_MOTION
);
2261 event
.m_x
= x
; event
.m_y
= y
;
2262 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2263 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2264 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2265 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2266 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2267 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2268 event
.m_eventObject
= this;
2270 // Window gets a click down message followed by a mouse move
2271 // message even if position isn't changed! We want to discard
2272 // the trailing move event if x and y are the same.
2273 if ((m_lastEvent
== wxEVT_RIGHT_DOWN
|| m_lastEvent
== wxEVT_LEFT_DOWN
||
2274 m_lastEvent
== wxEVT_MIDDLE_DOWN
) &&
2275 (m_lastXPos
== event
.m_x
&& m_lastYPos
== event
.m_y
))
2277 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2278 m_lastEvent
= wxEVT_MOTION
;
2282 m_lastEvent
= wxEVT_MOTION
;
2283 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2285 if (!GetEventHandler()->ProcessEvent(event
))
2289 void wxWindow::MSWOnMouseEnter(int x
, int y
, WXUINT flags
)
2291 wxMouseEvent
event(wxEVT_ENTER_WINDOW
);
2293 event
.m_x
= x
; event
.m_y
= y
;
2294 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2295 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2296 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2297 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2298 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2299 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2300 event
.m_eventObject
= this;
2302 m_lastEvent
= wxEVT_ENTER_WINDOW
;
2303 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2304 // No message - ensure we don't try to call the default behaviour accidentally.
2306 GetEventHandler()->ProcessEvent(event
);
2309 void wxWindow::MSWOnMouseLeave(int x
, int y
, WXUINT flags
)
2311 wxMouseEvent
event(wxEVT_LEAVE_WINDOW
);
2313 event
.m_x
= x
; event
.m_y
= y
;
2314 event
.m_shiftDown
= ((flags
& MK_SHIFT
) != 0);
2315 event
.m_controlDown
= ((flags
& MK_CONTROL
) != 0);
2316 event
.m_leftDown
= ((flags
& MK_LBUTTON
) != 0);
2317 event
.m_middleDown
= ((flags
& MK_MBUTTON
) != 0);
2318 event
.m_rightDown
= ((flags
& MK_RBUTTON
) != 0);
2319 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2320 event
.m_eventObject
= this;
2322 m_lastEvent
= wxEVT_LEAVE_WINDOW
;
2323 m_lastXPos
= event
.m_x
; m_lastYPos
= event
.m_y
;
2324 // No message - ensure we don't try to call the default behaviour accidentally.
2326 GetEventHandler()->ProcessEvent(event
);
2329 void wxWindow::MSWOnChar(WXWORD wParam
, WXLPARAM lParam
, bool isASCII
)
2332 bool tempControlDown
= FALSE
;
2335 // If 1 -> 26, translate to CTRL plus a letter.
2337 if ((id
> 0) && (id
< 27))
2358 tempControlDown
= TRUE
;
2364 else if ((id
= wxCharCodeMSWToWX(wParam
)) == 0) {
2365 // it's ASCII and will be processed here only when called from
2366 // WM_CHAR (i.e. when isASCII = TRUE)
2372 wxKeyEvent
event(wxEVT_CHAR
);
2373 event
.m_shiftDown
= (::GetKeyState(VK_SHIFT
)&0x100?TRUE
:FALSE
);
2374 event
.m_controlDown
= (::GetKeyState(VK_CONTROL
)&0x100?TRUE
:FALSE
);
2375 if ((HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
2376 event
.m_altDown
= TRUE
;
2378 event
.m_eventObject
= this;
2379 event
.m_keyCode
= id
;
2380 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
2385 GetWindowRect((HWND
) GetHWND(),&rect
) ;
2389 event
.m_x
= pt
.x
; event
.m_y
= pt
.y
;
2391 if (!GetEventHandler()->ProcessEvent(event
))
2396 void wxWindow::MSWOnJoyDown(int joystick
, int x
, int y
, WXUINT flags
)
2400 if (flags
& JOY_BUTTON1CHG
)
2401 change
= wxJOY_BUTTON1
;
2402 if (flags
& JOY_BUTTON2CHG
)
2403 change
= wxJOY_BUTTON2
;
2404 if (flags
& JOY_BUTTON3CHG
)
2405 change
= wxJOY_BUTTON3
;
2406 if (flags
& JOY_BUTTON4CHG
)
2407 change
= wxJOY_BUTTON4
;
2409 if (flags
& JOY_BUTTON1
)
2410 buttons
|= wxJOY_BUTTON1
;
2411 if (flags
& JOY_BUTTON2
)
2412 buttons
|= wxJOY_BUTTON2
;
2413 if (flags
& JOY_BUTTON3
)
2414 buttons
|= wxJOY_BUTTON3
;
2415 if (flags
& JOY_BUTTON4
)
2416 buttons
|= wxJOY_BUTTON4
;
2418 wxJoystickEvent
event(wxEVT_JOY_BUTTON_DOWN
, buttons
, joystick
, change
);
2419 event
.SetPosition(wxPoint(x
, y
));
2420 event
.SetEventObject(this);
2422 GetEventHandler()->ProcessEvent(event
);
2425 void wxWindow::MSWOnJoyUp(int joystick
, int x
, int y
, WXUINT flags
)
2429 if (flags
& JOY_BUTTON1CHG
)
2430 change
= wxJOY_BUTTON1
;
2431 if (flags
& JOY_BUTTON2CHG
)
2432 change
= wxJOY_BUTTON2
;
2433 if (flags
& JOY_BUTTON3CHG
)
2434 change
= wxJOY_BUTTON3
;
2435 if (flags
& JOY_BUTTON4CHG
)
2436 change
= wxJOY_BUTTON4
;
2438 if (flags
& JOY_BUTTON1
)
2439 buttons
|= wxJOY_BUTTON1
;
2440 if (flags
& JOY_BUTTON2
)
2441 buttons
|= wxJOY_BUTTON2
;
2442 if (flags
& JOY_BUTTON3
)
2443 buttons
|= wxJOY_BUTTON3
;
2444 if (flags
& JOY_BUTTON4
)
2445 buttons
|= wxJOY_BUTTON4
;
2447 wxJoystickEvent
event(wxEVT_JOY_BUTTON_UP
, buttons
, joystick
, change
);
2448 event
.SetPosition(wxPoint(x
, y
));
2449 event
.SetEventObject(this);
2451 GetEventHandler()->ProcessEvent(event
);
2454 void wxWindow::MSWOnJoyMove(int joystick
, int x
, int y
, WXUINT flags
)
2457 if (flags
& JOY_BUTTON1
)
2458 buttons
|= wxJOY_BUTTON1
;
2459 if (flags
& JOY_BUTTON2
)
2460 buttons
|= wxJOY_BUTTON2
;
2461 if (flags
& JOY_BUTTON3
)
2462 buttons
|= wxJOY_BUTTON3
;
2463 if (flags
& JOY_BUTTON4
)
2464 buttons
|= wxJOY_BUTTON4
;
2466 wxJoystickEvent
event(wxEVT_JOY_MOVE
, buttons
, joystick
, 0);
2467 event
.SetPosition(wxPoint(x
, y
));
2468 event
.SetEventObject(this);
2470 GetEventHandler()->ProcessEvent(event
);
2473 void wxWindow::MSWOnJoyZMove(int joystick
, int z
, WXUINT flags
)
2476 if (flags
& JOY_BUTTON1
)
2477 buttons
|= wxJOY_BUTTON1
;
2478 if (flags
& JOY_BUTTON2
)
2479 buttons
|= wxJOY_BUTTON2
;
2480 if (flags
& JOY_BUTTON3
)
2481 buttons
|= wxJOY_BUTTON3
;
2482 if (flags
& JOY_BUTTON4
)
2483 buttons
|= wxJOY_BUTTON4
;
2485 wxJoystickEvent
event(wxEVT_JOY_ZMOVE
, buttons
, joystick
, 0);
2486 event
.SetZPosition(z
);
2487 event
.SetEventObject(this);
2489 GetEventHandler()->ProcessEvent(event
);
2492 void wxWindow::MSWOnVScroll(WXWORD wParam
, WXWORD pos
, WXHWND control
)
2496 wxWindow
*child
= wxFindWinFromHandle(control
);
2498 child
->MSWOnVScroll(wParam
, pos
, control
);
2502 wxScrollEvent event
;
2503 event
.SetPosition(pos
);
2504 event
.SetOrientation(wxVERTICAL
);
2505 event
.m_eventObject
= this;
2510 event
.m_eventType
= wxEVT_SCROLL_TOP
;
2514 event
.m_eventType
= wxEVT_SCROLL_BOTTOM
;
2518 event
.m_eventType
= wxEVT_SCROLL_LINEUP
;
2522 event
.m_eventType
= wxEVT_SCROLL_LINEDOWN
;
2526 event
.m_eventType
= wxEVT_SCROLL_PAGEUP
;
2530 event
.m_eventType
= wxEVT_SCROLL_PAGEDOWN
;
2534 case SB_THUMBPOSITION
:
2535 event
.m_eventType
= wxEVT_SCROLL_THUMBTRACK
;
2543 if (!GetEventHandler()->ProcessEvent(event
))
2547 void wxWindow::MSWOnHScroll( WXWORD wParam
, WXWORD pos
, WXHWND control
)
2551 wxWindow
*child
= wxFindWinFromHandle(control
);
2553 child
->MSWOnHScroll(wParam
, pos
, control
);
2557 wxScrollEvent event
;
2558 event
.SetPosition(pos
);
2559 event
.SetOrientation(wxHORIZONTAL
);
2560 event
.m_eventObject
= this;
2565 event
.m_eventType
= wxEVT_SCROLL_TOP
;
2569 event
.m_eventType
= wxEVT_SCROLL_BOTTOM
;
2573 event
.m_eventType
= wxEVT_SCROLL_LINEUP
;
2577 event
.m_eventType
= wxEVT_SCROLL_LINEDOWN
;
2581 event
.m_eventType
= wxEVT_SCROLL_PAGEUP
;
2585 event
.m_eventType
= wxEVT_SCROLL_PAGEDOWN
;
2589 case SB_THUMBPOSITION
:
2590 event
.m_eventType
= wxEVT_SCROLL_THUMBTRACK
;
2597 if (!GetEventHandler()->ProcessEvent(event
))
2601 void wxWindow::MSWOnShow(bool show
, int status
)
2603 wxShowEvent
event(GetId(), show
);
2604 event
.m_eventObject
= this;
2605 GetEventHandler()->ProcessEvent(event
);
2608 bool wxWindow::MSWOnInitDialog(WXHWND
WXUNUSED(hWndFocus
))
2610 wxInitDialogEvent
event(GetId());
2611 event
.m_eventObject
= this;
2612 GetEventHandler()->ProcessEvent(event
);
2616 void wxWindow::InitDialog(void)
2618 wxInitDialogEvent
event(GetId());
2619 event
.SetEventObject( this );
2620 GetEventHandler()->ProcessEvent(event
);
2623 // Default init dialog behaviour is to transfer data to window
2624 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
2626 TransferDataToWindow();
2629 void wxGetCharSize(WXHWND wnd
, int *x
, int *y
,wxFont
*the_font
)
2632 HDC dc
= ::GetDC((HWND
) wnd
);
2638 wxDebugMsg("wxGetCharSize: Selecting HFONT %X\n", fnt
);
2640 // the_font->UseResource();
2641 // the_font->RealizeResource();
2642 if ((fnt
=(HFONT
) the_font
->GetResourceHandle()))
2643 was
= SelectObject(dc
,fnt
) ;
2645 GetTextMetrics(dc
, &tm
);
2646 if (the_font
&& fnt
&& was
)
2649 wxDebugMsg("wxGetCharSize: Selecting old HFONT %X\n", was
);
2651 SelectObject(dc
,was
) ;
2653 ReleaseDC((HWND
)wnd
, dc
);
2654 *x
= tm
.tmAveCharWidth
;
2655 *y
= tm
.tmHeight
+ tm
.tmExternalLeading
;
2658 // the_font->ReleaseResource();
2661 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
2662 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
2663 int wxCharCodeMSWToWX(int keySym
)
2668 case VK_CANCEL
: id
= WXK_CANCEL
; break;
2669 case VK_BACK
: id
= WXK_BACK
; break;
2670 case VK_TAB
: id
= WXK_TAB
; break;
2671 case VK_CLEAR
: id
= WXK_CLEAR
; break;
2672 case VK_RETURN
: id
= WXK_RETURN
; break;
2673 case VK_SHIFT
: id
= WXK_SHIFT
; break;
2674 case VK_CONTROL
: id
= WXK_CONTROL
; break;
2675 case VK_MENU
: id
= WXK_MENU
; break;
2676 case VK_PAUSE
: id
= WXK_PAUSE
; break;
2677 case VK_SPACE
: id
= WXK_SPACE
; break;
2678 case VK_ESCAPE
: id
= WXK_ESCAPE
; break;
2679 case VK_PRIOR
: id
= WXK_PRIOR
; break;
2680 case VK_NEXT
: id
= WXK_NEXT
; break;
2681 case VK_END
: id
= WXK_END
; break;
2682 case VK_HOME
: id
= WXK_HOME
; break;
2683 case VK_LEFT
: id
= WXK_LEFT
; break;
2684 case VK_UP
: id
= WXK_UP
; break;
2685 case VK_RIGHT
: id
= WXK_RIGHT
; break;
2686 case VK_DOWN
: id
= WXK_DOWN
; break;
2687 case VK_SELECT
: id
= WXK_SELECT
; break;
2688 case VK_PRINT
: id
= WXK_PRINT
; break;
2689 case VK_EXECUTE
: id
= WXK_EXECUTE
; break;
2690 case VK_INSERT
: id
= WXK_INSERT
; break;
2691 case VK_DELETE
: id
= WXK_DELETE
; break;
2692 case VK_HELP
: id
= WXK_HELP
; break;
2693 case VK_NUMPAD0
: id
= WXK_NUMPAD0
; break;
2694 case VK_NUMPAD1
: id
= WXK_NUMPAD1
; break;
2695 case VK_NUMPAD2
: id
= WXK_NUMPAD2
; break;
2696 case VK_NUMPAD3
: id
= WXK_NUMPAD3
; break;
2697 case VK_NUMPAD4
: id
= WXK_NUMPAD4
; break;
2698 case VK_NUMPAD5
: id
= WXK_NUMPAD5
; break;
2699 case VK_NUMPAD6
: id
= WXK_NUMPAD6
; break;
2700 case VK_NUMPAD7
: id
= WXK_NUMPAD7
; break;
2701 case VK_NUMPAD8
: id
= WXK_NUMPAD8
; break;
2702 case VK_NUMPAD9
: id
= WXK_NUMPAD9
; break;
2703 case VK_MULTIPLY
: id
= WXK_MULTIPLY
; break;
2704 case VK_ADD
: id
= WXK_ADD
; break;
2705 case VK_SUBTRACT
: id
= WXK_SUBTRACT
; break;
2706 case VK_DECIMAL
: id
= WXK_DECIMAL
; break;
2707 case VK_DIVIDE
: id
= WXK_DIVIDE
; break;
2708 case VK_F1
: id
= WXK_F1
; break;
2709 case VK_F2
: id
= WXK_F2
; break;
2710 case VK_F3
: id
= WXK_F3
; break;
2711 case VK_F4
: id
= WXK_F4
; break;
2712 case VK_F5
: id
= WXK_F5
; break;
2713 case VK_F6
: id
= WXK_F6
; break;
2714 case VK_F7
: id
= WXK_F7
; break;
2715 case VK_F8
: id
= WXK_F8
; break;
2716 case VK_F9
: id
= WXK_F9
; break;
2717 case VK_F10
: id
= WXK_F10
; break;
2718 case VK_F11
: id
= WXK_F11
; break;
2719 case VK_F12
: id
= WXK_F12
; break;
2720 case VK_F13
: id
= WXK_F13
; break;
2721 case VK_F14
: id
= WXK_F14
; break;
2722 case VK_F15
: id
= WXK_F15
; break;
2723 case VK_F16
: id
= WXK_F16
; break;
2724 case VK_F17
: id
= WXK_F17
; break;
2725 case VK_F18
: id
= WXK_F18
; break;
2726 case VK_F19
: id
= WXK_F19
; break;
2727 case VK_F20
: id
= WXK_F20
; break;
2728 case VK_F21
: id
= WXK_F21
; break;
2729 case VK_F22
: id
= WXK_F22
; break;
2730 case VK_F23
: id
= WXK_F23
; break;
2731 case VK_F24
: id
= WXK_F24
; break;
2732 case VK_NUMLOCK
: id
= WXK_NUMLOCK
; break;
2733 case VK_SCROLL
: id
= WXK_SCROLL
; break;
2742 int wxCharCodeWXToMSW(int id
, bool *isVirtual
)
2748 case WXK_CANCEL
: keySym
= VK_CANCEL
; break;
2749 case WXK_CLEAR
: keySym
= VK_CLEAR
; break;
2750 case WXK_SHIFT
: keySym
= VK_SHIFT
; break;
2751 case WXK_CONTROL
: keySym
= VK_CONTROL
; break;
2752 case WXK_MENU
: keySym
= VK_MENU
; break;
2753 case WXK_PAUSE
: keySym
= VK_PAUSE
; break;
2754 case WXK_PRIOR
: keySym
= VK_PRIOR
; break;
2755 case WXK_NEXT
: keySym
= VK_NEXT
; break;
2756 case WXK_END
: keySym
= VK_END
; break;
2757 case WXK_HOME
: keySym
= VK_HOME
; break;
2758 case WXK_LEFT
: keySym
= VK_LEFT
; break;
2759 case WXK_UP
: keySym
= VK_UP
; break;
2760 case WXK_RIGHT
: keySym
= VK_RIGHT
; break;
2761 case WXK_DOWN
: keySym
= VK_DOWN
; break;
2762 case WXK_SELECT
: keySym
= VK_SELECT
; break;
2763 case WXK_PRINT
: keySym
= VK_PRINT
; break;
2764 case WXK_EXECUTE
: keySym
= VK_EXECUTE
; break;
2765 case WXK_INSERT
: keySym
= VK_INSERT
; break;
2766 case WXK_DELETE
: keySym
= VK_DELETE
; break;
2767 case WXK_HELP
: keySym
= VK_HELP
; break;
2768 case WXK_NUMPAD0
: keySym
= VK_NUMPAD0
; break;
2769 case WXK_NUMPAD1
: keySym
= VK_NUMPAD1
; break;
2770 case WXK_NUMPAD2
: keySym
= VK_NUMPAD2
; break;
2771 case WXK_NUMPAD3
: keySym
= VK_NUMPAD3
; break;
2772 case WXK_NUMPAD4
: keySym
= VK_NUMPAD4
; break;
2773 case WXK_NUMPAD5
: keySym
= VK_NUMPAD5
; break;
2774 case WXK_NUMPAD6
: keySym
= VK_NUMPAD6
; break;
2775 case WXK_NUMPAD7
: keySym
= VK_NUMPAD7
; break;
2776 case WXK_NUMPAD8
: keySym
= VK_NUMPAD8
; break;
2777 case WXK_NUMPAD9
: keySym
= VK_NUMPAD9
; break;
2778 case WXK_MULTIPLY
: keySym
= VK_MULTIPLY
; break;
2779 case WXK_ADD
: keySym
= VK_ADD
; break;
2780 case WXK_SUBTRACT
: keySym
= VK_SUBTRACT
; break;
2781 case WXK_DECIMAL
: keySym
= VK_DECIMAL
; break;
2782 case WXK_DIVIDE
: keySym
= VK_DIVIDE
; break;
2783 case WXK_F1
: keySym
= VK_F1
; break;
2784 case WXK_F2
: keySym
= VK_F2
; break;
2785 case WXK_F3
: keySym
= VK_F3
; break;
2786 case WXK_F4
: keySym
= VK_F4
; break;
2787 case WXK_F5
: keySym
= VK_F5
; break;
2788 case WXK_F6
: keySym
= VK_F6
; break;
2789 case WXK_F7
: keySym
= VK_F7
; break;
2790 case WXK_F8
: keySym
= VK_F8
; break;
2791 case WXK_F9
: keySym
= VK_F9
; break;
2792 case WXK_F10
: keySym
= VK_F10
; break;
2793 case WXK_F11
: keySym
= VK_F11
; break;
2794 case WXK_F12
: keySym
= VK_F12
; break;
2795 case WXK_F13
: keySym
= VK_F13
; break;
2796 case WXK_F14
: keySym
= VK_F14
; break;
2797 case WXK_F15
: keySym
= VK_F15
; break;
2798 case WXK_F16
: keySym
= VK_F16
; break;
2799 case WXK_F17
: keySym
= VK_F17
; break;
2800 case WXK_F18
: keySym
= VK_F18
; break;
2801 case WXK_F19
: keySym
= VK_F19
; break;
2802 case WXK_F20
: keySym
= VK_F20
; break;
2803 case WXK_F21
: keySym
= VK_F21
; break;
2804 case WXK_F22
: keySym
= VK_F22
; break;
2805 case WXK_F23
: keySym
= VK_F23
; break;
2806 case WXK_F24
: keySym
= VK_F24
; break;
2807 case WXK_NUMLOCK
: keySym
= VK_NUMLOCK
; break;
2808 case WXK_SCROLL
: keySym
= VK_SCROLL
; break;
2819 // Caret manipulation
2820 void wxWindow::CreateCaret(int w
, int h
)
2824 m_caretEnabled
= TRUE
;
2827 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
2832 void wxWindow::ShowCaret(bool show
)
2837 ::ShowCaret((HWND
) GetHWND());
2839 ::HideCaret((HWND
) GetHWND());
2840 m_caretShown
= show
;
2844 void wxWindow::DestroyCaret(void)
2846 m_caretEnabled
= FALSE
;
2849 void wxWindow::SetCaretPos(int x
, int y
)
2851 ::SetCaretPos(x
, y
);
2854 void wxWindow::GetCaretPos(int *x
, int *y
) const
2857 ::GetCaretPos(&point
);
2863 * Update iterator. Use from within OnPaint.
2866 static RECT gs_UpdateRect
;
2868 wxUpdateIterator::wxUpdateIterator(wxWindow
* wnd
)
2870 current
= 0; //start somewhere...
2871 #if defined(__WIN32__) && !defined(__win32s__)
2872 rlist
= NULL
; //make sure I don't free randomly
2873 int len
= GetRegionData((HRGN
) wnd
->m_updateRgn
,0,NULL
); //Get buffer size
2876 rlist
= (WXRGNDATA
*) (RGNDATA
*)new char[len
];
2877 GetRegionData((HRGN
) wnd
->m_updateRgn
,len
, (RGNDATA
*)rlist
);
2878 rp
= (void *)(RECT
*) ((RGNDATA
*)rlist
)->Buffer
;
2879 rects
= ((RGNDATA
*)rlist
)->rdh
.nCount
;
2884 gs_UpdateRect
.left
= wnd
->m_updateRect
.x
;
2885 gs_UpdateRect
.top
= wnd
->m_updateRect
.y
;
2886 gs_UpdateRect
.right
= wnd
->m_updateRect
.x
+ wnd
->m_updateRect
.width
;
2887 gs_UpdateRect
.bottom
= wnd
->m_updateRect
.y
+ wnd
->m_updateRect
.height
;
2889 rp
= (void *)&gs_UpdateRect
; //Only one available in Win16,32s
2893 wxUpdateIterator::~wxUpdateIterator(void)
2897 if (rlist
) delete (RGNDATA
*) rlist
;
2902 wxUpdateIterator::operator int (void)
2904 if (current
< rects
)
2914 wxUpdateIterator
* wxUpdateIterator::operator ++(int)
2920 void wxUpdateIterator::GetRect(wxRect
*rect
)
2922 RECT
*mswRect
= ((RECT
*)rp
)+current
; //ought to error check this...
2923 rect
->x
= mswRect
->left
;
2924 rect
->y
= mswRect
->top
;
2925 rect
->width
= mswRect
->right
- mswRect
->left
;
2926 rect
->height
= mswRect
->bottom
- mswRect
->top
;
2929 int wxUpdateIterator::GetX()
2931 return ((RECT
*)rp
)[current
].left
;
2934 int wxUpdateIterator::GetY()
2936 return ((RECT
*)rp
)[current
].top
;
2939 int wxUpdateIterator::GetW()
2941 return ((RECT
*)rp
)[current
].right
-GetX();
2944 int wxUpdateIterator::GetH()
2946 return ((RECT
*)rp
)[current
].bottom
-GetY();
2949 wxWindow
*wxGetActiveWindow(void)
2951 HWND hWnd
= GetActiveWindow();
2954 return wxFindWinFromHandle((WXHWND
) hWnd
);
2959 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
2960 // in active frames and dialogs, regardless of where the focus is.
2961 static HHOOK wxTheKeyboardHook
= 0;
2962 static FARPROC wxTheKeyboardHookProc
= 0;
2963 int APIENTRY _EXPORT
2964 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
);
2966 void wxSetKeyboardHook(bool doIt
)
2970 wxTheKeyboardHookProc
= MakeProcInstance((FARPROC
) wxKeyboardHook
, wxGetInstance());
2971 wxTheKeyboardHook
= SetWindowsHookEx(WH_KEYBOARD
, (HOOKPROC
) wxTheKeyboardHookProc
, wxGetInstance(),
2973 GetCurrentThreadId());
2974 // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
2981 UnhookWindowsHookEx(wxTheKeyboardHook
);
2982 FreeProcInstance(wxTheKeyboardHookProc
);
2986 int APIENTRY _EXPORT
2987 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
)
2989 DWORD hiWord
= HIWORD(lParam
);
2990 if (nCode
!= HC_NOREMOVE
&& ((hiWord
& KF_UP
) == 0))
2993 if ((id
= wxCharCodeMSWToWX(wParam
)) != 0)
2995 wxKeyEvent
event(wxEVT_CHAR_HOOK
);
2996 if ((HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
2997 event
.m_altDown
= TRUE
;
2999 event
.m_eventObject
= NULL
;
3000 event
.m_keyCode
= id
;
3001 /* begin Albert's fix for control and shift key 26.5 */
3002 event
.m_shiftDown
= (::GetKeyState(VK_SHIFT
)&0x100?TRUE
:FALSE
);
3003 event
.m_controlDown
= (::GetKeyState(VK_CONTROL
)&0x100?TRUE
:FALSE
);
3004 /* end Albert's fix for control and shift key 26.5 */
3005 event
.SetTimestamp(wxApp::sm_lastMessageTime
); /* MATTHEW: timeStamp */
3007 wxWindow
*win
= wxGetActiveWindow();
3010 if (win
->GetEventHandler()->ProcessEvent(event
))
3015 if ( wxTheApp
&& wxTheApp
->ProcessEvent(event
) )
3020 return (int)CallNextHookEx(wxTheKeyboardHook
, nCode
, wParam
, lParam
);
3023 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int WXUNUSED(incW
), int WXUNUSED(incH
))
3031 void wxWindow::Centre(int direction
)
3033 int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
;
3035 wxWindow
*father
= (wxWindow
*)GetParent();
3039 father
->GetClientSize(&panel_width
, &panel_height
);
3040 GetSize(&width
, &height
);
3041 GetPosition(&x
, &y
);
3046 if (direction
& wxHORIZONTAL
)
3047 new_x
= (int)((panel_width
- width
)/2);
3049 if (direction
& wxVERTICAL
)
3050 new_y
= (int)((panel_height
- height
)/2);
3052 SetSize(new_x
, new_y
, -1, -1);
3057 void wxWindow::OnPaint(void)
3059 PaintSelectionHandles();
3063 void wxWindow::WarpPointer (int x_pos
, int y_pos
)
3065 // Move the pointer to (x_pos,y_pos) coordinates. They are expressed in
3066 // pixel coordinates, relatives to the canvas -- So, we first need to
3067 // substract origin of the window, then convert to screen position
3069 int x
= x_pos
; int y
= y_pos
;
3070 /* Leave this to the app to decide (and/or wxScrolledWindow)
3071 x -= m_xScrollPosition * m_xScrollPixelsPerLine;
3072 y -= m_yScrollPosition * m_yScrollPixelsPerLine;
3075 GetWindowRect ((HWND
) GetHWND(), &rect
);
3080 SetCursorPos (x
, y
);
3083 void wxWindow::MSWDeviceToLogical (float *x
, float *y
) const
3086 // Do we have a SetUserScale in wxWindow too, so we can
3087 // get mouse events scaled?
3091 *x = m_windowDC->DeviceToLogicalX ((int) *x);
3092 *y = m_windowDC->DeviceToLogicalY ((int) *y);
3097 bool wxWindow::MSWOnEraseBkgnd (WXHDC pDC
)
3105 wxEraseEvent
event(m_windowId
, &dc
);
3106 event
.m_eventObject
= this;
3107 if (!GetEventHandler()->ProcessEvent(event
))
3110 dc
.SelectOldObjects(pDC
);
3116 dc
.SelectOldObjects(pDC
);
3119 dc
.SetHDC((WXHDC
) NULL
);
3123 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
3126 ::GetClientRect((HWND
) GetHWND(), &rect
);
3128 HBRUSH hBrush
= ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
3129 int mode
= ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), MM_TEXT
);
3131 // ::GetClipBox((HDC) event.GetDC()->GetHDC(), &rect);
3132 ::FillRect ((HDC
) event
.GetDC()->GetHDC(), &rect
, hBrush
);
3133 ::DeleteObject(hBrush
);
3134 ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), mode
);
3136 // Less efficient version (and doesn't account for scrolling)
3138 GetClientSize(& w, & h);
3139 wxBrush *brush = wxTheBrushList->FindOrCreateBrush(& GetBackgroundColour(), wxSOLID);
3140 event.GetDC()->SetBrush(brush);
3141 event.GetDC()->SetPen(wxTRANSPARENT_PEN);
3143 event.GetDC()->DrawRectangle(0, 0, w+1, h+1);
3147 #if WXWIN_COMPATIBILITY
3148 void wxWindow::SetScrollRange(int orient
, int range
, bool refresh
)
3150 #if defined(__WIN95__)
3154 // Try to adjust the range to cope with page size > 1
3155 // - a Windows API quirk
3156 int pageSize
= GetScrollPage(orient
);
3157 if ( pageSize
> 1 && range
> 0)
3159 range1
+= (pageSize
- 1);
3165 if (orient
== wxHORIZONTAL
) {
3171 info
.cbSize
= sizeof(SCROLLINFO
);
3172 info
.nPage
= pageSize
; // Have to set this, or scrollbar goes awry
3176 info
.fMask
= SIF_RANGE
| SIF_PAGE
;
3178 HWND hWnd
= (HWND
) GetHWND();
3180 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3183 if (orient
== wxHORIZONTAL
)
3188 HWND hWnd
= (HWND
) GetHWND();
3190 ::SetScrollRange(hWnd
, wOrient
, 0, range
, refresh
);
3194 void wxWindow::SetScrollPage(int orient
, int page
, bool refresh
)
3196 #if defined(__WIN95__)
3200 if (orient
== wxHORIZONTAL
) {
3202 m_xThumbSize
= page
;
3205 m_yThumbSize
= page
;
3208 info
.cbSize
= sizeof(SCROLLINFO
);
3211 info
.fMask
= SIF_PAGE
;
3213 HWND hWnd
= (HWND
) GetHWND();
3215 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3217 if (orient
== wxHORIZONTAL
)
3218 m_xThumbSize
= page
;
3220 m_yThumbSize
= page
;
3224 int wxWindow::OldGetScrollRange(int orient
) const
3227 if (orient
== wxHORIZONTAL
)
3232 #if __WATCOMC__ && defined(__WINDOWS_386__)
3233 short minPos
, maxPos
;
3237 HWND hWnd
= (HWND
) GetHWND();
3240 ::GetScrollRange(hWnd
, wOrient
, &minPos
, &maxPos
);
3241 #if defined(__WIN95__)
3242 // Try to adjust the range to cope with page size > 1
3243 // - a Windows API quirk
3244 int pageSize
= GetScrollPage(orient
);
3247 maxPos
-= (pageSize
- 1);
3256 int wxWindow::GetScrollPage(int orient
) const
3258 if (orient
== wxHORIZONTAL
)
3259 return m_xThumbSize
;
3261 return m_yThumbSize
;
3265 int wxWindow::GetScrollPos(int orient
) const
3268 if (orient
== wxHORIZONTAL
)
3272 HWND hWnd
= (HWND
) GetHWND();
3275 return ::GetScrollPos(hWnd
, wOrient
);
3281 // This now returns the whole range, not just the number
3282 // of positions that we can scroll.
3283 int wxWindow::GetScrollRange(int orient
) const
3286 if (orient
== wxHORIZONTAL
)
3291 #if __WATCOMC__ && defined(__WINDOWS_386__)
3292 short minPos
, maxPos
;
3296 HWND hWnd
= (HWND
) GetHWND();
3299 ::GetScrollRange(hWnd
, wOrient
, &minPos
, &maxPos
);
3300 #if defined(__WIN95__)
3301 // Try to adjust the range to cope with page size > 1
3302 // - a Windows API quirk
3303 int pageSize
= GetScrollPage(orient
);
3306 maxPos
-= (pageSize
- 1);
3308 // October 10th: new range concept.
3318 int wxWindow::GetScrollThumb(int orient
) const
3320 if (orient
== wxHORIZONTAL
)
3321 return m_xThumbSize
;
3323 return m_yThumbSize
;
3326 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
3328 #if defined(__WIN95__)
3332 if (orient
== wxHORIZONTAL
) {
3338 info
.cbSize
= sizeof(SCROLLINFO
);
3342 info
.fMask
= SIF_POS
;
3344 HWND hWnd
= (HWND
) GetHWND();
3346 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3349 if (orient
== wxHORIZONTAL
)
3354 HWND hWnd
= (HWND
) GetHWND();
3356 ::SetScrollPos(hWnd
, wOrient
, pos
, refresh
);
3360 // New function that will replace some of the above.
3361 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
3362 int range
, bool refresh
)
3365 SetScrollPage(orient, thumbVisible, FALSE);
3367 int oldRange = range - thumbVisible ;
3368 SetScrollRange(orient, oldRange, FALSE);
3370 SetScrollPos(orient, pos, refresh);
3372 #if defined(__WIN95__)
3373 int oldRange
= range
- thumbVisible
;
3375 int range1
= oldRange
;
3377 // Try to adjust the range to cope with page size > 1
3378 // - a Windows API quirk
3379 int pageSize
= thumbVisible
;
3380 if ( pageSize
> 1 && range
> 0)
3382 range1
+= (pageSize
- 1);
3388 if (orient
== wxHORIZONTAL
) {
3394 info
.cbSize
= sizeof(SCROLLINFO
);
3395 info
.nPage
= pageSize
; // Have to set this, or scrollbar goes awry
3399 info
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
3401 HWND hWnd
= (HWND
) GetHWND();
3403 ::SetScrollInfo(hWnd
, dir
, &info
, refresh
);
3406 if (orient
== wxHORIZONTAL
)
3411 HWND hWnd
= (HWND
) GetHWND();
3414 ::SetScrollRange(hWnd
, wOrient
, 0, range
, FALSE
);
3415 ::SetScrollPos(hWnd
, wOrient
, pos
, refresh
);
3418 if (orient
== wxHORIZONTAL
) {
3419 m_xThumbSize
= thumbVisible
;
3421 m_yThumbSize
= thumbVisible
;
3425 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRectangle
*rect
)
3430 rect2
.left
= rect
->x
;
3431 rect2
.top
= rect
->y
;
3432 rect2
.right
= rect
->x
+ rect
->width
;
3433 rect2
.bottom
= rect
->y
+ rect
->height
;
3437 ::ScrollWindow((HWND
) GetHWND(), dx
, dy
, &rect2
, NULL
);
3439 ::ScrollWindow((HWND
) GetHWND(), dx
, dy
, NULL
, NULL
);
3442 void wxWindow::OnSize(wxSizeEvent
& event
)
3446 if (GetAutoLayout())
3452 void wxWindow::CalcScrolledPosition(int x, int y, int *xx, int *yy) const
3458 void wxWindow::CalcUnscrolledPosition(int x, int y, float *xx, float *yy) const
3465 void wxWindow::SetFont(const wxFont
& font
)
3467 // Decrement the usage count of the old label font
3468 // (we may be able to free it up)
3469 // if (GetFont()->Ok())
3470 // GetFont()->ReleaseResource();
3472 m_windowFont
= font
;
3474 if (!m_windowFont
.Ok())
3477 // m_windowFont.UseResource();
3479 HWND hWnd
= (HWND
) GetHWND();
3482 // m_windowFont.RealizeResource();
3484 if (m_windowFont
.GetResourceHandle())
3485 SendMessage(hWnd
, WM_SETFONT
,
3486 (WPARAM
)m_windowFont
.GetResourceHandle(),TRUE
);
3490 void wxWindow::SubclassWin(WXHWND hWnd
)
3492 wxAssociateWinWithHandle((HWND
)hWnd
, this);
3494 m_oldWndProc
= (WXFARPROC
) GetWindowLong((HWND
) hWnd
, GWL_WNDPROC
);
3495 SetWindowLong((HWND
) hWnd
, GWL_WNDPROC
, (LONG
) wxWndProc
);
3498 void wxWindow::UnsubclassWin(void)
3500 wxRemoveHandleAssociation(this);
3502 // Restore old Window proc
3503 if ((HWND
) GetHWND())
3505 FARPROC farProc
= (FARPROC
) GetWindowLong((HWND
) GetHWND(), GWL_WNDPROC
);
3506 if ((m_oldWndProc
!= 0) && (farProc
!= (FARPROC
) m_oldWndProc
))
3508 SetWindowLong((HWND
) GetHWND(), GWL_WNDPROC
, (LONG
) m_oldWndProc
);
3514 // Make a Windows extended style from the given wxWindows window style
3515 WXDWORD
wxWindow::MakeExtendedStyle(long style
, bool eliminateBorders
)
3517 WXDWORD exStyle
= 0;
3518 if ( style
& wxTRANSPARENT_WINDOW
)
3519 exStyle
|= WS_EX_TRANSPARENT
;
3521 if ( !eliminateBorders
)
3523 if ( style
& wxSUNKEN_BORDER
)
3524 exStyle
|= WS_EX_CLIENTEDGE
;
3525 if ( style
& wxDOUBLE_BORDER
)
3526 exStyle
|= WS_EX_DLGMODALFRAME
;
3527 #if defined(__WIN95__)
3528 if ( style
& wxRAISED_BORDER
)
3529 exStyle
|= WS_EX_WINDOWEDGE
;
3530 if ( style
& wxSTATIC_BORDER
)
3531 exStyle
|= WS_EX_STATICEDGE
;
3537 // Determines whether native 3D effects or CTL3D should be used,
3538 // applying a default border style if required, and returning an extended
3539 // style to pass to CreateWindowEx.
3540 WXDWORD
wxWindow::Determine3DEffects(WXDWORD defaultBorderStyle
, bool *want3D
)
3542 // If matches certain criteria, then assume no 3D effects
3543 // unless specifically requested (dealt with in MakeExtendedStyle)
3544 if ( !GetParent() || !IsKindOf(CLASSINFO(wxControl
)) || (m_windowStyle
& wxNO_BORDER
) )
3547 return MakeExtendedStyle(m_windowStyle
, FALSE
);
3550 // Determine whether we should be using 3D effects or not.
3551 bool nativeBorder
= FALSE
; // by default, we don't want a Win95 effect
3553 // 1) App can specify global 3D effects
3554 *want3D
= wxTheApp
->GetAuto3D();
3556 // 2) If the parent is being drawn with user colours, or simple border specified,
3557 // switch effects off. TODO: replace wxUSER_COLOURS with wxNO_3D
3558 if (GetParent() && (GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
) || (m_windowStyle
& wxSIMPLE_BORDER
))
3561 // 3) Control can override this global setting by defining
3562 // a border style, e.g. wxSUNKEN_BORDER
3563 if (m_windowStyle
& wxSUNKEN_BORDER
)
3566 // 4) If it's a special border, CTL3D can't cope so we want a native border
3567 if ( (m_windowStyle
& wxDOUBLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
3568 (m_windowStyle
& wxSTATIC_BORDER
) )
3571 nativeBorder
= TRUE
;
3574 // 5) If this isn't a Win95 app, and we are using CTL3D, remove border
3575 // effects from extended style
3578 nativeBorder
= FALSE
;
3581 DWORD exStyle
= MakeExtendedStyle(m_windowStyle
, !nativeBorder
);
3583 // If we want 3D, but haven't specified a border here,
3584 // apply the default border style specified.
3585 // TODO what about non-Win95 WIN32? Does it have borders?
3586 #if defined(__WIN95__) && !CTL3D
3587 if (defaultBorderStyle
&& (*want3D
) && ! ((m_windowStyle
& wxDOUBLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
3588 (m_windowStyle
& wxSTATIC_BORDER
) || (m_windowStyle
& wxSIMPLE_BORDER
) ))
3589 exStyle
|= defaultBorderStyle
; // WS_EX_CLIENTEDGE ;
3596 #if WXWIN_COMPATIBILITY
3597 void wxWindow::OldOnPaint(void)
3599 wxPaintEvent event(m_windowId);
3600 event.m_eventObject = this;
3601 if (!GetEventHandler()->ProcessEvent(event))
3605 void wxWindow::OldOnSize(int w, int h)
3607 wxSizeEvent event(wxSize(w, h), m_windowId);
3608 event.m_eventObject = this;
3609 if (!GetEventHandler()->ProcessEvent(event))
3613 void wxWindow::OldOnMouseEvent(wxMouseEvent& event)
3615 if (!GetEventHandler()->ProcessEvent(event))
3619 void wxWindow::OldOnChar(wxKeyEvent& event)
3621 if (!GetEventHandler()->ProcessEvent(event))
3625 void wxWindow::OldOnSetFocus(void)
3627 wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId);
3628 event.m_eventObject = this;
3629 if (!GetEventHandler()->ProcessEvent(event))
3633 void wxWindow::OldOnKillFocus(void)
3635 wxFocusEvent event(wxEVT_KILL_FOCUS, m_windowId);
3636 event.m_eventObject = this;
3637 if (!GetEventHandler()->ProcessEvent(event))
3643 void wxWindow::OnChar(wxKeyEvent
& event
)
3646 int id
= wxCharCodeWXToMSW((int)event
.KeyCode(), &isVirtual
);
3651 if ( !event
.ControlDown() )
3652 (void) MSWDefWindowProc(m_lastMsg
, (WPARAM
) id
, m_lastLParam
);
3655 void wxWindow::OnPaint(wxPaintEvent
& event
)
3660 bool wxWindow::IsEnabled(void) const
3662 return (::IsWindowEnabled((HWND
) GetHWND()) != 0);
3665 // Dialog support: override these and call
3666 // base class members to add functionality
3667 // that can't be done using validators.
3668 // NOTE: these functions assume that controls
3669 // are direct children of this window, not grandchildren
3670 // or other levels of descendant.
3672 // Transfer values to controls. If returns FALSE,
3673 // it's an application error (pops up a dialog)
3674 bool wxWindow::TransferDataToWindow(void)
3676 wxNode
*node
= GetChildren()->First();
3679 wxWindow
*child
= (wxWindow
*)node
->Data();
3680 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */
3681 !child
->GetValidator()->TransferToWindow() )
3683 wxMessageBox("Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
3687 node
= node
->Next();
3692 // Transfer values from controls. If returns FALSE,
3693 // validation failed: don't quit
3694 bool wxWindow::TransferDataFromWindow(void)
3696 wxNode
*node
= GetChildren()->First();
3699 wxWindow
*child
= (wxWindow
*)node
->Data();
3700 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->TransferFromWindow() )
3705 node
= node
->Next();
3710 bool wxWindow::Validate(void)
3712 wxNode
*node
= GetChildren()->First();
3715 wxWindow
*child
= (wxWindow
*)node
->Data();
3716 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
3721 node
= node
->Next();
3726 // Get the window with the focus
3727 wxWindow
*wxWindow::FindFocus(void)
3729 HWND hWnd
= ::GetFocus();
3732 return wxFindWinFromHandle((WXHWND
) hWnd
);
3737 void wxWindow::AddChild(wxWindow
*child
)
3739 GetChildren()->Append(child
);
3740 child
->m_windowParent
= this;
3743 void wxWindow::RemoveChild(wxWindow
*child
)
3746 GetChildren()->DeleteObject(child
);
3747 child
->m_windowParent
= NULL
;
3750 void wxWindow::DestroyChildren(void)
3752 if (GetChildren()) {
3754 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
) {
3756 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
3758 if ( GetChildren()->Member(child
) )
3765 void wxWindow::MakeModal(bool modal
)
3767 // Disable all other windows
3768 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
3770 wxNode
*node
= wxTopLevelWindows
.First();
3773 wxWindow
*win
= (wxWindow
*)node
->Data();
3775 win
->Enable(!modal
);
3777 node
= node
->Next();
3782 // If nothing defined for this, try the parent.
3783 // E.g. we may be a button loaded from a resource, with no callback function
3785 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
3787 if (GetEventHandler()->ProcessEvent(event
) )
3790 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
3793 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
3797 UnsetConstraints(m_constraints
);
3798 delete m_constraints
;
3803 // Make sure other windows know they're part of a 'meaningful relationship'
3804 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
3805 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3806 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
3807 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3808 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
3809 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3810 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
3811 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3812 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
3813 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3814 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
3815 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3816 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
3817 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3818 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
3819 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
3823 // This removes any dangling pointers to this window
3824 // in other windows' constraintsInvolvedIn lists.
3825 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
3829 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
3830 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3831 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
3832 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3833 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
3834 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3835 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
3836 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3837 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
3838 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3839 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
3840 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3841 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
3842 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3843 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
3844 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
3848 // Back-pointer to other windows we're involved with, so if we delete
3849 // this window, we must delete any constraints we're involved with.
3850 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
3852 if (!m_constraintsInvolvedIn
)
3853 m_constraintsInvolvedIn
= new wxList
;
3854 if (!m_constraintsInvolvedIn
->Member(otherWin
))
3855 m_constraintsInvolvedIn
->Append(otherWin
);
3858 // REMOVE back-pointer to other windows we're involved with.
3859 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
3861 if (m_constraintsInvolvedIn
)
3862 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
3865 // Reset any constraints that mention this window
3866 void wxWindow::DeleteRelatedConstraints(void)
3868 if (m_constraintsInvolvedIn
)
3870 wxNode
*node
= m_constraintsInvolvedIn
->First();
3873 wxWindow
*win
= (wxWindow
*)node
->Data();
3874 wxNode
*next
= node
->Next();
3875 wxLayoutConstraints
*constr
= win
->GetConstraints();
3877 // Reset any constraints involving this window
3880 constr
->left
.ResetIfWin((wxWindow
*)this);
3881 constr
->top
.ResetIfWin((wxWindow
*)this);
3882 constr
->right
.ResetIfWin((wxWindow
*)this);
3883 constr
->bottom
.ResetIfWin((wxWindow
*)this);
3884 constr
->width
.ResetIfWin((wxWindow
*)this);
3885 constr
->height
.ResetIfWin((wxWindow
*)this);
3886 constr
->centreX
.ResetIfWin((wxWindow
*)this);
3887 constr
->centreY
.ResetIfWin((wxWindow
*)this);
3892 delete m_constraintsInvolvedIn
;
3893 m_constraintsInvolvedIn
= NULL
;
3897 void wxWindow::SetSizer(wxSizer
*sizer
)
3899 m_windowSizer
= sizer
;
3901 sizer
->SetSizerParent((wxWindow
*)this);
3908 bool wxWindow::Layout(void)
3910 if (GetConstraints())
3913 GetClientSize(&w
, &h
);
3914 GetConstraints()->width
.SetValue(w
);
3915 GetConstraints()->height
.SetValue(h
);
3918 // If top level (one sizer), evaluate the sizer's constraints.
3922 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
3923 GetSizer()->LayoutPhase1(&noChanges
);
3924 GetSizer()->LayoutPhase2(&noChanges
);
3925 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
3930 // Otherwise, evaluate child constraints
3931 ResetConstraints(); // Mark all constraints as unevaluated
3932 DoPhase(1); // Just one phase need if no sizers involved
3934 SetConstraintSizes(); // Recursively set the real window sizes
3940 // Do a phase of evaluating constraints:
3941 // the default behaviour. wxSizers may do a similar
3942 // thing, but also impose their own 'constraints'
3943 // and order the evaluation differently.
3944 bool wxWindow::LayoutPhase1(int *noChanges
)
3946 wxLayoutConstraints
*constr
= GetConstraints();
3949 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
3955 bool wxWindow::LayoutPhase2(int *noChanges
)
3965 // Do a phase of evaluating child constraints
3966 bool wxWindow::DoPhase(int phase
)
3968 int noIterations
= 0;
3969 int maxIterations
= 500;
3973 while ((noChanges
> 0) && (noIterations
< maxIterations
))
3977 wxNode
*node
= GetChildren()->First();
3980 wxWindow
*child
= (wxWindow
*)node
->Data();
3981 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
3983 wxLayoutConstraints
*constr
= child
->GetConstraints();
3986 if (succeeded
.Member(child
))
3991 int tempNoChanges
= 0;
3992 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
3993 noChanges
+= tempNoChanges
;
3996 succeeded
.Append(child
);
4001 node
= node
->Next();
4008 void wxWindow::ResetConstraints(void)
4010 wxLayoutConstraints
*constr
= GetConstraints();
4013 constr
->left
.SetDone(FALSE
);
4014 constr
->top
.SetDone(FALSE
);
4015 constr
->right
.SetDone(FALSE
);
4016 constr
->bottom
.SetDone(FALSE
);
4017 constr
->width
.SetDone(FALSE
);
4018 constr
->height
.SetDone(FALSE
);
4019 constr
->centreX
.SetDone(FALSE
);
4020 constr
->centreY
.SetDone(FALSE
);
4022 wxNode
*node
= GetChildren()->First();
4025 wxWindow
*win
= (wxWindow
*)node
->Data();
4026 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
4027 win
->ResetConstraints();
4028 node
= node
->Next();
4032 // Need to distinguish between setting the 'fake' size for
4033 // windows and sizers, and setting the real values.
4034 void wxWindow::SetConstraintSizes(bool recurse
)
4036 wxLayoutConstraints
*constr
= GetConstraints();
4037 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
4038 constr
->width
.GetDone() && constr
->height
.GetDone())
4040 int x
= constr
->left
.GetValue();
4041 int y
= constr
->top
.GetValue();
4042 int w
= constr
->width
.GetValue();
4043 int h
= constr
->height
.GetValue();
4045 // If we don't want to resize this window, just move it...
4046 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
4047 (constr
->height
.GetRelationship() != wxAsIs
))
4049 // Calls Layout() recursively. AAAGH. How can we stop that.
4050 // Simply take Layout() out of non-top level OnSizes.
4051 SizerSetSize(x
, y
, w
, h
);
4060 char *windowClass
= this->GetClassInfo()->GetClassName();
4063 if (GetName() == "")
4064 winName
= "unnamed";
4066 winName
= GetName();
4067 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
4068 if (!constr
->left
.GetDone())
4069 wxDebugMsg(" unsatisfied 'left' constraint.\n");
4070 if (!constr
->right
.GetDone())
4071 wxDebugMsg(" unsatisfied 'right' constraint.\n");
4072 if (!constr
->width
.GetDone())
4073 wxDebugMsg(" unsatisfied 'width' constraint.\n");
4074 if (!constr
->height
.GetDone())
4075 wxDebugMsg(" unsatisfied 'height' constraint.\n");
4076 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
4081 wxNode
*node
= GetChildren()->First();
4084 wxWindow
*win
= (wxWindow
*)node
->Data();
4085 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
4086 win
->SetConstraintSizes();
4087 node
= node
->Next();
4092 // This assumes that all sizers are 'on' the same
4093 // window, i.e. the parent of this window.
4094 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
4096 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
4097 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
4101 m_sizerParent
->GetPosition(&xp
, &yp
);
4102 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
4107 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
4111 TransformSizerToActual(&xx
, &yy
);
4112 SetSize(xx
, yy
, w
, h
);
4115 void wxWindow::SizerMove(int x
, int y
)
4119 TransformSizerToActual(&xx
, &yy
);
4123 // Only set the size/position of the constraint (if any)
4124 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
4126 wxLayoutConstraints
*constr
= GetConstraints();
4131 constr
->left
.SetValue(x
);
4132 constr
->left
.SetDone(TRUE
);
4136 constr
->top
.SetValue(y
);
4137 constr
->top
.SetDone(TRUE
);
4141 constr
->width
.SetValue(w
);
4142 constr
->width
.SetDone(TRUE
);
4146 constr
->height
.SetValue(h
);
4147 constr
->height
.SetDone(TRUE
);
4152 void wxWindow::MoveConstraint(int x
, int y
)
4154 wxLayoutConstraints
*constr
= GetConstraints();
4159 constr
->left
.SetValue(x
);
4160 constr
->left
.SetDone(TRUE
);
4164 constr
->top
.SetValue(y
);
4165 constr
->top
.SetDone(TRUE
);
4170 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
4172 wxLayoutConstraints
*constr
= GetConstraints();
4175 *w
= constr
->width
.GetValue();
4176 *h
= constr
->height
.GetValue();
4182 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
4184 wxLayoutConstraints
*constr
= GetConstraints();
4187 *w
= constr
->width
.GetValue();
4188 *h
= constr
->height
.GetValue();
4191 GetClientSize(w
, h
);
4194 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
4196 wxLayoutConstraints
*constr
= GetConstraints();
4199 *x
= constr
->left
.GetValue();
4200 *y
= constr
->top
.GetValue();
4206 bool wxWindow::Close(bool force
)
4208 // Let's generalise it to work the same for any window.
4210 if (!IsKindOf(CLASSINFO(wxDialog)) && !IsKindOf(CLASSINFO(wxFrame)))
4217 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
4218 event
.SetEventObject(this);
4219 event
.SetForce(force
);
4221 return GetEventHandler()->ProcessEvent(event
);
4224 if ( !force && event.GetVeto() )
4229 if (!wxPendingDelete.Member(this))
4230 wxPendingDelete.Append(this);
4236 wxObject
* wxWindow::GetChild(int number
) const
4238 // Return a pointer to the Nth object in the Panel
4241 wxNode
*node
= GetChildren()->First();
4244 node
= node
->Next() ;
4247 wxObject
*obj
= (wxObject
*)node
->Data();
4254 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
4256 /* This is obsolete now; if we wish to intercept listbox double-clicks,
4257 * we explicitly intercept the wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
4260 if (initiatingItem->IsKindOf(CLASSINFO(wxListBox)))
4262 wxListBox *lbox = (wxListBox *)initiatingItem;
4263 wxCommandEvent event(wxEVT_COMMAND_LEFT_DCLICK);
4264 event.m_commandInt = -1;
4265 if ((lbox->GetWindowStyleFlag() & wxLB_MULTIPLE) == 0)
4267 event.m_commandString = copystring(lbox->GetStringSelection());
4268 event.m_commandInt = lbox->GetSelection();
4269 event.m_clientData = lbox->wxListBox::GetClientData(event.m_commandInt);
4271 event.m_eventObject = lbox;
4273 lbox->ProcessCommand(event);
4275 if (event.m_commandString)
4276 delete[] event.m_commandString;
4280 wxButton *but = GetDefaultItem();
4283 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
4284 event.SetEventObject(but);
4285 but->Command(event);
4290 void wxWindow::Clear(void)
4292 wxClientDC
dc(this);
4293 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
4294 dc
.SetBackground(brush
);
4298 // Fits the panel around the items
4299 void wxWindow::Fit(void)
4303 wxNode
*node
= GetChildren()->First();
4306 wxWindow
*win
= (wxWindow
*)node
->Data();
4308 win
->GetPosition(&wx
, &wy
);
4309 win
->GetSize(&ww
, &wh
);
4310 if ( wx
+ ww
> maxX
)
4312 if ( wy
+ wh
> maxY
)
4315 node
= node
->Next();
4317 SetClientSize(maxX
+ 5, maxY
+ 5);
4320 void wxWindow::SetValidator(const wxValidator
& validator
)
4322 if ( m_windowValidator
)
4323 delete m_windowValidator
;
4324 m_windowValidator
= validator
.Clone();
4326 if ( m_windowValidator
)
4327 m_windowValidator
->SetWindow(this) ;
4330 // Find a window by id or name
4331 wxWindow
*wxWindow::FindWindow(long id
)
4336 wxNode
*node
= GetChildren()->First();
4339 wxWindow
*child
= (wxWindow
*)node
->Data();
4340 wxWindow
*found
= child
->FindWindow(id
);
4343 node
= node
->Next();
4348 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
4350 if ( GetName() == name
)
4353 wxNode
*node
= GetChildren()->First();
4356 wxWindow
*child
= (wxWindow
*)node
->Data();
4357 wxWindow
*found
= child
->FindWindow(name
);
4360 node
= node
->Next();
4366 // Default input behaviour for a scrolling canvas should be to scroll
4367 // according to the cursor keys pressed
4368 void wxWindow::OnChar(wxKeyEvent& event)
4380 GetScrollUnitsPerPage(&x_page, &y_page);
4382 GetVirtualSize(&v_width,&v_height);
4384 ViewStart(&start_x, &start_y);
4387 y_pages = (int)(v_height/vert_units) - y_page;
4395 switch (event.keyCode)
4402 if (start_y - y_page > 0)
4403 Scroll(start_x, start_y - y_page);
4413 if ((y_page > 0) && (start_y <= y_pages-y-1))
4415 if (y_pages + y < start_y + y_page)
4416 Scroll(start_x, y_pages + y);
4418 Scroll(start_x, start_y + y_page);
4425 if ((y_page > 0) && (start_y >= 1))
4426 Scroll(start_x, start_y - 1);
4432 if ((y_page > 0) && (start_y <= y_pages-y-1))
4435 Scroll(start_x, start_y + 1);
4441 if ((x_page > 0) && (start_x >= 1))
4442 Scroll(start_x - 1, start_y);
4448 Scroll(start_x + 1, start_y);
4459 Scroll(start_x, y_pages+y);
4467 // Setup background and foreground colours correctly
4468 void wxWindow::SetupColours(void)
4471 SetBackgroundColour(GetParent()->GetBackgroundColour());
4474 // Do Update UI processing for child controls
4476 // TODO: should this be implemented for the child window rather
4477 // than the parent? Then you can override it e.g. for wxCheckBox
4478 // to do the Right Thing rather than having to assume a fixed number
4479 // of control classes.
4481 void wxWindow::UpdateWindowUI(void)
4483 wxWindowID id
= GetId();
4486 wxUpdateUIEvent
event(id
);
4487 event
.m_eventObject
= this;
4489 if (this->GetEventHandler()->ProcessEvent(event
))
4491 if (event
.GetSetEnabled())
4492 this->Enable(event
.GetEnabled());
4494 if (event
.GetSetText() && this->IsKindOf(CLASSINFO(wxControl
)))
4495 ((wxControl
*)this)->SetLabel(event
.GetText());
4497 if (this->IsKindOf(CLASSINFO(wxCheckBox
)))
4499 if (event
.GetSetChecked())
4500 ((wxCheckBox
*) this)->SetValue(event
.GetChecked());
4502 else if (this->IsKindOf(CLASSINFO(wxRadioButton
)))
4504 if (event
.GetSetChecked())
4505 ((wxRadioButton
*) this)->SetValue(event
.GetChecked());
4512 void wxWindow::OnIdle(wxIdleEvent
& event
)
4514 // Check if we need to send a LEAVE event
4515 if (m_mouseInWindow
)
4518 ::GetCursorPos(&pt
);
4519 if (::WindowFromPoint(pt
) != (HWND
) GetHWND())
4521 // Generate a LEAVE event
4522 m_mouseInWindow
= FALSE
;
4523 MSWOnMouseLeave(pt
.x
, pt
.y
, 0);
4529 // Raise the window to the top of the Z order
4530 void wxWindow::Raise(void)
4532 ::BringWindowToTop((HWND
) GetHWND());
4535 // Lower the window to the bottom of the Z order
4536 void wxWindow::Lower(void)
4538 ::SetWindowPos((HWND
) GetHWND(), HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);