From 5706de1cf469f1ca53be7c402365d47e12a616cf Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Sun, 1 Jun 2003 14:37:28 +0000 Subject: [PATCH] Partially applied patch [ 531199 ] new EVT_MOVING and EVT_SIZING Changed to reuse wxMoveEvent, wxSizeEvent Only applied the Mac part as a TODO comment git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20816 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/event.h | 18 +++++++++- include/wx/msw/window.h | 2 ++ src/common/event.cpp | 2 ++ src/mac/carbon/toplevel.cpp | 69 +++++++++++++++++++++++++++++++++++++ src/mac/toplevel.cpp | 69 +++++++++++++++++++++++++++++++++++++ src/msw/window.cpp | 58 +++++++++++++++++++++++++++++++ 6 files changed, 217 insertions(+), 1 deletion(-) diff --git a/include/wx/event.h b/include/wx/event.h index 87a6628590..06a60da6cc 100644 --- a/include/wx/event.h +++ b/include/wx/event.h @@ -247,6 +247,8 @@ BEGIN_DECLARE_EVENT_TYPES() DECLARE_EVENT_TYPE(wxEVT_INIT_DIALOG, 438) DECLARE_EVENT_TYPE(wxEVT_IDLE, 439) DECLARE_EVENT_TYPE(wxEVT_UPDATE_UI, 440) + DECLARE_EVENT_TYPE(wxEVT_SIZING, 441) + DECLARE_EVENT_TYPE(wxEVT_MOVING, 4442) // Generic command events // Note: a click is a higher-level event than button down/up @@ -932,15 +934,21 @@ public: { } wxSizeEvent(const wxSizeEvent & event) : wxEvent(event), - m_size(event.m_size) + m_size(event.m_size), m_rect(event.m_rect) { } + wxSizeEvent(const wxRect& rect, int id = 0) + : m_rect(rect), m_size(rect.GetSize()) + { m_eventType = wxEVT_SIZING; m_id = id; } wxSize GetSize() const { return m_size; } + wxRect GetRect() const { return m_rect; } + void SetRect(wxRect rect) { m_rect = rect; } virtual wxEvent *Clone() const { return new wxSizeEvent(*this); } public: wxSize m_size; + wxRect m_rect; // Used for wxEVT_SIZING private: DECLARE_DYNAMIC_CLASS(wxSizeEvent) @@ -966,12 +974,18 @@ public: : wxEvent(event), m_pos(event.m_pos) { } + wxMoveEvent(const wxRect& rect, int id = 0) + : m_pos(rect.GetPosition()), m_rect(rect) + { m_eventType = wxEVT_MOVING; m_id = id; } wxPoint GetPosition() const { return m_pos; } + wxRect GetRect() const { return m_rect; } + void SetRect(wxRect rect) { m_rect = rect; } virtual wxEvent *Clone() const { return new wxMoveEvent(*this); } wxPoint m_pos; + wxRect m_rect; private: DECLARE_DYNAMIC_CLASS(wxMoveEvent) @@ -2198,7 +2212,9 @@ typedef void (wxEvtHandler::*wxMouseCaptureChangedEventFunction)(wxMouseCaptureC // Miscellaneous #define EVT_SIZE(func) DECLARE_EVENT_TABLE_ENTRY( wxEVT_SIZE, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) (wxSizeEventFunction) & func, (wxObject *) NULL ), +#define EVT_SIZING(func) DECLARE_EVENT_TABLE_ENTRY( wxEVT_SIZING, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxSizeEventFunction) & func, (wxObject *) NULL ), #define EVT_MOVE(func) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MOVE, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) (wxMoveEventFunction) & func, (wxObject *) NULL ), +#define EVT_MOVING(func) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MOVING, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxMoveEventFunction) & func, (wxObject *) NULL ), #define EVT_CLOSE(func) DECLARE_EVENT_TABLE_ENTRY( wxEVT_CLOSE_WINDOW, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) (wxCloseEventFunction) & func, (wxObject *) NULL ), #define EVT_END_SESSION(func) DECLARE_EVENT_TABLE_ENTRY( wxEVT_END_SESSION, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) (wxCloseEventFunction) & func, (wxObject *) NULL ), #define EVT_QUERY_END_SESSION(func) DECLARE_EVENT_TABLE_ENTRY( wxEVT_QUERY_END_SESSION, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) (wxCloseEventFunction) & func, (wxObject *) NULL ), diff --git a/include/wx/msw/window.h b/include/wx/msw/window.h index a34ac1e2dd..615e9f03f9 100644 --- a/include/wx/msw/window.h +++ b/include/wx/msw/window.h @@ -323,6 +323,7 @@ public: bool HandleMinimize(); bool HandleMaximize(); bool HandleSize(int x, int y, WXUINT flag); + bool HandleSizing(wxRect& rect); bool HandleGetMinMaxInfo(void *mmInfo); bool HandleShow(bool show, int status); @@ -478,6 +479,7 @@ private: // the (non-virtual) handlers for the events bool HandleMove(int x, int y); + bool HandleMoving(wxRect& rect); bool HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags); #ifdef __WIN95__ diff --git a/src/common/event.cpp b/src/common/event.cpp index b2dc2e82f4..e0fac8a8a5 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -204,7 +204,9 @@ DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBRELEASE) // System events DEFINE_EVENT_TYPE(wxEVT_SIZE) +DEFINE_EVENT_TYPE(wxEVT_SIZING) DEFINE_EVENT_TYPE(wxEVT_MOVE) +DEFINE_EVENT_TYPE(wxEVT_MOVING) DEFINE_EVENT_TYPE(wxEVT_CLOSE_WINDOW) DEFINE_EVENT_TYPE(wxEVT_END_SESSION) DEFINE_EVENT_TYPE(wxEVT_QUERY_END_SESSION) diff --git a/src/mac/carbon/toplevel.cpp b/src/mac/carbon/toplevel.cpp index 92cbb42606..34db5c2604 100644 --- a/src/mac/carbon/toplevel.cpp +++ b/src/mac/carbon/toplevel.cpp @@ -349,6 +349,64 @@ pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler ) +// Patch 531199 defined a window event handler, as follows. +// TODO: merge the moving/sizing event handling with the event +// handler above. +#if 0 +static pascal OSStatus +WindowHandler( EventHandlerCallRef inHandler, EventRef inEvent, void* userData ) +{ + Rect bounds; + SInt16 height, width; + UInt32 attributes; + OSStatus result = eventNotHandledErr; + + GetEventParameter( inEvent, kEventParamAttributes, typeUInt32, NULL, sizeof( UInt32 ), NULL, &attributes ); + + if ((attributes & (kWindowBoundsChangeSizeChanged | kWindowBoundsChangeOriginChanged)) != 0) + { + // Extract the current bounds. This is the paramter you get to modify to + // alter the window position or size during a window resizing. + GetEventParameter( inEvent, kEventParamCurrentBounds, typeQDRectangle, NULL, sizeof( bounds ), NULL, &bounds ); + + wxRect rect; + rect.SetLeft(bounds.left); + rect.SetTop(bounds.top); + rect.SetRight(bounds.right); + rect.SetBottom(bounds.bottom); + + bool rc; + wxWindowMac *pWindow = (wxWindowMac*)userData; + if ((attributes & kWindowBoundsChangeSizeChanged) != 0) { + wxSizeEvent event(rect, pWindow->GetId()); + event.SetEventObject(pWindow); + rc = pWindow->GetEventHandler()->ProcessEvent(event); + rect = event.GetRect(); + } + else { + wxMoveEvent event(rect, pWindow->GetId()); + event.SetEventObject(pWindow); + rc = pWindow->GetEventHandler()->ProcessEvent(event); + rect = event.GetRect(); + } + + if (rc) { + bounds.left = rect.GetLeft(); + bounds.top = rect.GetTop(); + bounds.right = rect.GetRight(); + bounds.bottom = rect.GetBottom(); + } + + // Set the current bounds parameter to our adjusted bounds. Return + // noErr to indicate we handled this event. + SetEventParameter( inEvent, kEventParamCurrentBounds, typeQDRectangle, sizeof( bounds ), &bounds ); + result = noErr; + } + return result; +} +#endif + // WindowHandler + #endif // --------------------------------------------------------------------------- @@ -629,6 +687,17 @@ void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title, InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow)) ) ; InstallWindowEventHandler(MAC_WXHWND(m_macWindow), GetwxMacWindowEventHandlerUPP(), GetEventTypeCount(eventList), eventList, this, &((EventHandlerRef)m_macEventHandler)); + + // Patch 531199 also defined a window event handler, as follows: +#if 0 + // install a window event handler to send wxEVT_MOVING and wxEVT_SIZING events + EventTypeSpec events[] = { { kEventClassWindow, kEventWindowBoundsChanging } }; + EventHandlerUPP handlerProc = NewEventHandlerUPP( WindowHandler ); + EventHandlerRef eventHandlerRef; + InstallWindowEventHandler( m_macWindowData->m_macWindow, handlerProc, GetEventTypeCount(events), + events, (void*)this, &eventHandlerRef); +#endif + #endif m_macFocus = NULL ; diff --git a/src/mac/toplevel.cpp b/src/mac/toplevel.cpp index 92cbb42606..34db5c2604 100644 --- a/src/mac/toplevel.cpp +++ b/src/mac/toplevel.cpp @@ -349,6 +349,64 @@ pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler ) +// Patch 531199 defined a window event handler, as follows. +// TODO: merge the moving/sizing event handling with the event +// handler above. +#if 0 +static pascal OSStatus +WindowHandler( EventHandlerCallRef inHandler, EventRef inEvent, void* userData ) +{ + Rect bounds; + SInt16 height, width; + UInt32 attributes; + OSStatus result = eventNotHandledErr; + + GetEventParameter( inEvent, kEventParamAttributes, typeUInt32, NULL, sizeof( UInt32 ), NULL, &attributes ); + + if ((attributes & (kWindowBoundsChangeSizeChanged | kWindowBoundsChangeOriginChanged)) != 0) + { + // Extract the current bounds. This is the paramter you get to modify to + // alter the window position or size during a window resizing. + GetEventParameter( inEvent, kEventParamCurrentBounds, typeQDRectangle, NULL, sizeof( bounds ), NULL, &bounds ); + + wxRect rect; + rect.SetLeft(bounds.left); + rect.SetTop(bounds.top); + rect.SetRight(bounds.right); + rect.SetBottom(bounds.bottom); + + bool rc; + wxWindowMac *pWindow = (wxWindowMac*)userData; + if ((attributes & kWindowBoundsChangeSizeChanged) != 0) { + wxSizeEvent event(rect, pWindow->GetId()); + event.SetEventObject(pWindow); + rc = pWindow->GetEventHandler()->ProcessEvent(event); + rect = event.GetRect(); + } + else { + wxMoveEvent event(rect, pWindow->GetId()); + event.SetEventObject(pWindow); + rc = pWindow->GetEventHandler()->ProcessEvent(event); + rect = event.GetRect(); + } + + if (rc) { + bounds.left = rect.GetLeft(); + bounds.top = rect.GetTop(); + bounds.right = rect.GetRight(); + bounds.bottom = rect.GetBottom(); + } + + // Set the current bounds parameter to our adjusted bounds. Return + // noErr to indicate we handled this event. + SetEventParameter( inEvent, kEventParamCurrentBounds, typeQDRectangle, sizeof( bounds ), &bounds ); + result = noErr; + } + return result; +} +#endif + // WindowHandler + #endif // --------------------------------------------------------------------------- @@ -629,6 +687,17 @@ void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title, InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow)) ) ; InstallWindowEventHandler(MAC_WXHWND(m_macWindow), GetwxMacWindowEventHandlerUPP(), GetEventTypeCount(eventList), eventList, this, &((EventHandlerRef)m_macEventHandler)); + + // Patch 531199 also defined a window event handler, as follows: +#if 0 + // install a window event handler to send wxEVT_MOVING and wxEVT_SIZING events + EventTypeSpec events[] = { { kEventClassWindow, kEventWindowBoundsChanging } }; + EventHandlerUPP handlerProc = NewEventHandlerUPP( WindowHandler ); + EventHandlerRef eventHandlerRef; + InstallWindowEventHandler( m_macWindowData->m_macWindow, handlerProc, GetEventTypeCount(events), + events, (void*)this, &eventHandlerRef); +#endif + #endif m_macFocus = NULL ; diff --git a/src/msw/window.cpp b/src/msw/window.cpp index f5db90dc55..555ac97b0b 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -2188,6 +2188,24 @@ long wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam processed = HandleMove(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); break; + case WM_MOVING: + { + LPRECT pRect = (LPRECT)lParam; + wxRect rc; + rc.SetLeft(pRect->left); + rc.SetTop(pRect->top); + rc.SetRight(pRect->right); + rc.SetBottom(pRect->bottom); + processed = HandleMoving(rc); + if (processed) { + pRect->left = rc.GetLeft(); + pRect->top = rc.GetTop(); + pRect->right = rc.GetRight(); + pRect->bottom = rc.GetBottom(); + } + } + break; + case WM_SIZE: switch ( wParam ) { @@ -2216,6 +2234,24 @@ long wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam } break; + case WM_SIZING: + { + LPRECT pRect = (LPRECT)lParam; + wxRect rc; + rc.SetLeft(pRect->left); + rc.SetTop(pRect->top); + rc.SetRight(pRect->right); + rc.SetBottom(pRect->bottom); + processed = HandleSizing(rc); + if (processed) { + pRect->left = rc.GetLeft(); + pRect->top = rc.GetTop(); + pRect->right = rc.GetRight(); + pRect->bottom = rc.GetBottom(); + } + } + break; + #ifndef __WXMICROWIN__ case WM_ACTIVATEAPP: wxTheApp->SetActive(wParam != 0, FindFocus()); @@ -3818,6 +3854,17 @@ bool wxWindowMSW::HandleMove(int x, int y) return GetEventHandler()->ProcessEvent(event); } +bool wxWindowMSW::HandleMoving(wxRect& rect) +{ + wxMoveEvent event(rect, m_windowId); + event.SetEventObject(this); + + bool rc = GetEventHandler()->ProcessEvent(event); + if (rc) + rect = event.GetRect(); + return rc; +} + bool wxWindowMSW::HandleSize(int WXUNUSED(w), int WXUNUSED(h), WXUINT WXUNUSED(flag)) { @@ -3830,6 +3877,17 @@ bool wxWindowMSW::HandleSize(int WXUNUSED(w), int WXUNUSED(h), return GetEventHandler()->ProcessEvent(event); } +bool wxWindowMSW::HandleSizing(wxRect& rect) +{ + wxSizeEvent event(rect, m_windowId); + event.SetEventObject(this); + + bool rc = GetEventHandler()->ProcessEvent(event); + if (rc) + rect = event.GetRect(); + return rc; +} + bool wxWindowMSW::HandleGetMinMaxInfo(void *mmInfo) { MINMAXINFO *info = (MINMAXINFO *)mmInfo; -- 2.45.2