From 238d735dc2db6fc2c64ed48ceba2d00a85c4b273 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Wed, 26 May 1999 20:40:04 +0000 Subject: [PATCH] Got a new idea to do cursors, including global ones and busy etc. Fixed an assert in UserScaler from PS code. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2577 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/dc.h | 2 +- include/wx/gtk/dcclient.h | 2 ++ include/wx/gtk1/dc.h | 2 +- include/wx/gtk1/dcclient.h | 2 ++ src/gtk/cursor.cpp | 39 ++++++++++++++++++++------------------ src/gtk/data.cpp | 2 +- src/gtk/dc.cpp | 14 -------------- src/gtk/dcclient.cpp | 20 +++++++++++++++++++ src/gtk/window.cpp | 22 ++++++++++----------- src/gtk1/cursor.cpp | 39 ++++++++++++++++++++------------------ src/gtk1/data.cpp | 2 +- src/gtk1/dc.cpp | 14 -------------- src/gtk1/dcclient.cpp | 20 +++++++++++++++++++ src/gtk1/window.cpp | 22 ++++++++++----------- 14 files changed, 112 insertions(+), 90 deletions(-) diff --git a/include/wx/gtk/dc.h b/include/wx/gtk/dc.h index 8b71e9ceb0..acc56d3bcd 100644 --- a/include/wx/gtk/dc.h +++ b/include/wx/gtk/dc.h @@ -70,7 +70,7 @@ public: // implementation // -------------- - void ComputeScaleAndOrigin(); + virtual void ComputeScaleAndOrigin(); long XDEV2LOG(long x) const { diff --git a/include/wx/gtk/dcclient.h b/include/wx/gtk/dcclient.h index e9b2a518da..b3b0439b4a 100644 --- a/include/wx/gtk/dcclient.h +++ b/include/wx/gtk/dcclient.h @@ -118,6 +118,8 @@ public: void SetUpDC(); void Destroy(); + void ComputeScaleAndOrigin(); + GdkWindow *GetWindow() { return m_window; } }; diff --git a/include/wx/gtk1/dc.h b/include/wx/gtk1/dc.h index 8b71e9ceb0..acc56d3bcd 100644 --- a/include/wx/gtk1/dc.h +++ b/include/wx/gtk1/dc.h @@ -70,7 +70,7 @@ public: // implementation // -------------- - void ComputeScaleAndOrigin(); + virtual void ComputeScaleAndOrigin(); long XDEV2LOG(long x) const { diff --git a/include/wx/gtk1/dcclient.h b/include/wx/gtk1/dcclient.h index e9b2a518da..b3b0439b4a 100644 --- a/include/wx/gtk1/dcclient.h +++ b/include/wx/gtk1/dcclient.h @@ -118,6 +118,8 @@ public: void SetUpDC(); void Destroy(); + void ComputeScaleAndOrigin(); + GdkWindow *GetWindow() { return m_window; } }; diff --git a/src/gtk/cursor.cpp b/src/gtk/cursor.cpp index 3c22177973..2277c0aee4 100644 --- a/src/gtk/cursor.cpp +++ b/src/gtk/cursor.cpp @@ -16,6 +16,13 @@ #include "gdk/gdk.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // wxCursor //----------------------------------------------------------------------------- @@ -137,38 +144,31 @@ GdkCursor *wxCursor::GetCursor() const // busy cursor routines //----------------------------------------------------------------------------- -extern wxCursor *g_globalCursor; +extern wxCursor g_globalCursor; -static wxCursor *gs_savedCursor = NULL; +static wxCursor gs_savedCursor; static int gs_busyCount = 0; void wxEndBusyCursor() { - if ( --gs_busyCount > 0 ) + if (--gs_busyCount > 0) return; - wxCHECK_RET( gs_savedCursor && gs_savedCursor->Ok(), - _T("calling wxEndBusyCursor() without wxBeginBusyCursor()?") ); - - wxSetCursor(*gs_savedCursor); - delete gs_savedCursor; - gs_savedCursor = NULL; + wxSetCursor( gs_savedCursor ); + gs_savedCursor = wxNullCursor; } void wxBeginBusyCursor( wxCursor *WXUNUSED(cursor) ) { - if ( gs_busyCount++ > 0 ) + if (gs_busyCount++ > 0) return; - wxASSERT_MSG( !gs_savedCursor, + wxASSERT_MSG( !gs_savedCursor.Ok(), _T("forgot to call wxEndBusyCursor, will leak memory") ); - gs_savedCursor = new wxCursor; - if ( g_globalCursor && g_globalCursor->Ok() ) - *gs_savedCursor = *g_globalCursor; - else - *gs_savedCursor = wxCursor(wxCURSOR_ARROW); - wxSetCursor(wxCursor(wxCURSOR_WATCH)); + gs_savedCursor = g_globalCursor; + + wxSetCursor( wxCursor(wxCURSOR_WATCH) ); } bool wxIsBusy() @@ -178,5 +178,8 @@ bool wxIsBusy() void wxSetCursor( const wxCursor& cursor ) { - if (g_globalCursor) (*g_globalCursor) = cursor; + if (g_isIdle) + wxapp_install_idle_handler(); + + g_globalCursor = cursor; } diff --git a/src/gtk/data.cpp b/src/gtk/data.cpp index b2fdae961c..ff11a0b0d6 100644 --- a/src/gtk/data.cpp +++ b/src/gtk/data.cpp @@ -46,7 +46,7 @@ wxCriticalSection *wxPendingEventsLocker = NULL; /* Current cursor, in order to hang on to * cursor handle when setting the cursor globally */ -wxCursor *g_globalCursor = (wxCursor *) NULL; +wxCursor g_globalCursor; /* Don't allow event propagation during drag */ bool g_blockEventsOnDrag = FALSE; diff --git a/src/gtk/dc.cpp b/src/gtk/dc.cpp index ad4b1373f6..57c1f336a7 100644 --- a/src/gtk/dc.cpp +++ b/src/gtk/dc.cpp @@ -97,22 +97,8 @@ wxSize wxDC::GetPPI() const void wxDC::ComputeScaleAndOrigin() { - /* CMB: copy scale to see if it changes */ - double origScaleX = m_scaleX; - double origScaleY = m_scaleY; - m_scaleX = m_logicalScaleX * m_userScaleX; m_scaleY = m_logicalScaleY * m_userScaleY; - - /* CMB: if scale has changed call SetPen to recalulate the line width */ - if (m_scaleX != origScaleX || m_scaleY != origScaleY) - { - /* this is a bit artificial, but we need to force wxDC to think - the pen has changed */ - wxPen pen = m_pen; - m_pen = wxNullPen; - SetPen( pen ); - } } void wxDC::SetMapMode( int mode ) diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp index 560c4162ef..d71a04d8fb 100644 --- a/src/gtk/dcclient.cpp +++ b/src/gtk/dcclient.cpp @@ -1200,6 +1200,26 @@ void wxWindowDC::Destroy() m_bgGC = (GdkGC*) NULL; } +void wxWindowDC::ComputeScaleAndOrigin() +{ + /* CMB: copy scale to see if it changes */ + double origScaleX = m_scaleX; + double origScaleY = m_scaleY; + + wxDC::ComputeScaleAndOrigin(); + + /* CMB: if scale has changed call SetPen to recalulate the line width */ + if ((m_scaleX != origScaleX || m_scaleY != origScaleY) && + (m_pen.Ok())) + { + /* this is a bit artificial, but we need to force wxDC to think + the pen has changed */ + wxPen pen = m_pen; + m_pen = wxNullPen; + SetPen( pen ); + } +} + // Resolution in pixels per logical inch wxSize wxWindowDC::GetPPI() const { diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index ade9c04dc7..5a676c5c1b 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -132,6 +132,7 @@ extern wxList wxPendingDelete; extern bool g_blockEventsOnDrag; extern bool g_blockEventsOnScroll; +extern wxCursor g_globalCursor; static bool g_capturing = FALSE; static wxWindow *g_focusWindow = (wxWindow*) NULL; @@ -1250,9 +1251,6 @@ static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_ if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE; - if (widget->window && win->GetCursor().Ok() ) - gdk_window_set_cursor( widget->window, win->GetCursor().GetCursor() ); - wxMouseEvent event( wxEVT_ENTER_WINDOW ); #if (GTK_MINOR_VERSION > 0) event.SetTimestamp( gdk_event->time ); @@ -1299,9 +1297,6 @@ static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_ if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE; - if (widget->window && win->GetCursor().Ok() ) - gdk_window_set_cursor( widget->window, wxSTANDARD_CURSOR->GetCursor() ); - wxMouseEvent event( wxEVT_LEAVE_WINDOW ); #if (GTK_MINOR_VERSION > 0) event.SetTimestamp( gdk_event->time ); @@ -2032,6 +2027,15 @@ void wxWindow::DoSetSize( int x, int y, int width, int height, int sizeFlags ) void wxWindow::OnInternalIdle() { + GdkWindow *window = GetConnectWidget()->window; + if (window) + { + if (g_globalCursor.Ok()) + gdk_window_set_cursor( window, g_globalCursor.GetCursor() ); + else + gdk_window_set_cursor( window, m_cursor.GetCursor() ); + } + UpdateWindowUI(); } @@ -2391,11 +2395,7 @@ bool wxWindow::SetCursor( const wxCursor &cursor ) return TRUE; } - if ((m_widget) && (m_widget->window)) - gdk_window_set_cursor( m_widget->window, GetCursor().GetCursor() ); - - if ((m_wxwindow) && (m_wxwindow->window)) - gdk_window_set_cursor( m_wxwindow->window, GetCursor().GetCursor() ); +// gdk_window_set_cursor( connect_widget->window, GetCursor().GetCursor() ); // cursor was set return TRUE; diff --git a/src/gtk1/cursor.cpp b/src/gtk1/cursor.cpp index 3c22177973..2277c0aee4 100644 --- a/src/gtk1/cursor.cpp +++ b/src/gtk1/cursor.cpp @@ -16,6 +16,13 @@ #include "gdk/gdk.h" +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + //----------------------------------------------------------------------------- // wxCursor //----------------------------------------------------------------------------- @@ -137,38 +144,31 @@ GdkCursor *wxCursor::GetCursor() const // busy cursor routines //----------------------------------------------------------------------------- -extern wxCursor *g_globalCursor; +extern wxCursor g_globalCursor; -static wxCursor *gs_savedCursor = NULL; +static wxCursor gs_savedCursor; static int gs_busyCount = 0; void wxEndBusyCursor() { - if ( --gs_busyCount > 0 ) + if (--gs_busyCount > 0) return; - wxCHECK_RET( gs_savedCursor && gs_savedCursor->Ok(), - _T("calling wxEndBusyCursor() without wxBeginBusyCursor()?") ); - - wxSetCursor(*gs_savedCursor); - delete gs_savedCursor; - gs_savedCursor = NULL; + wxSetCursor( gs_savedCursor ); + gs_savedCursor = wxNullCursor; } void wxBeginBusyCursor( wxCursor *WXUNUSED(cursor) ) { - if ( gs_busyCount++ > 0 ) + if (gs_busyCount++ > 0) return; - wxASSERT_MSG( !gs_savedCursor, + wxASSERT_MSG( !gs_savedCursor.Ok(), _T("forgot to call wxEndBusyCursor, will leak memory") ); - gs_savedCursor = new wxCursor; - if ( g_globalCursor && g_globalCursor->Ok() ) - *gs_savedCursor = *g_globalCursor; - else - *gs_savedCursor = wxCursor(wxCURSOR_ARROW); - wxSetCursor(wxCursor(wxCURSOR_WATCH)); + gs_savedCursor = g_globalCursor; + + wxSetCursor( wxCursor(wxCURSOR_WATCH) ); } bool wxIsBusy() @@ -178,5 +178,8 @@ bool wxIsBusy() void wxSetCursor( const wxCursor& cursor ) { - if (g_globalCursor) (*g_globalCursor) = cursor; + if (g_isIdle) + wxapp_install_idle_handler(); + + g_globalCursor = cursor; } diff --git a/src/gtk1/data.cpp b/src/gtk1/data.cpp index b2fdae961c..ff11a0b0d6 100644 --- a/src/gtk1/data.cpp +++ b/src/gtk1/data.cpp @@ -46,7 +46,7 @@ wxCriticalSection *wxPendingEventsLocker = NULL; /* Current cursor, in order to hang on to * cursor handle when setting the cursor globally */ -wxCursor *g_globalCursor = (wxCursor *) NULL; +wxCursor g_globalCursor; /* Don't allow event propagation during drag */ bool g_blockEventsOnDrag = FALSE; diff --git a/src/gtk1/dc.cpp b/src/gtk1/dc.cpp index ad4b1373f6..57c1f336a7 100644 --- a/src/gtk1/dc.cpp +++ b/src/gtk1/dc.cpp @@ -97,22 +97,8 @@ wxSize wxDC::GetPPI() const void wxDC::ComputeScaleAndOrigin() { - /* CMB: copy scale to see if it changes */ - double origScaleX = m_scaleX; - double origScaleY = m_scaleY; - m_scaleX = m_logicalScaleX * m_userScaleX; m_scaleY = m_logicalScaleY * m_userScaleY; - - /* CMB: if scale has changed call SetPen to recalulate the line width */ - if (m_scaleX != origScaleX || m_scaleY != origScaleY) - { - /* this is a bit artificial, but we need to force wxDC to think - the pen has changed */ - wxPen pen = m_pen; - m_pen = wxNullPen; - SetPen( pen ); - } } void wxDC::SetMapMode( int mode ) diff --git a/src/gtk1/dcclient.cpp b/src/gtk1/dcclient.cpp index 560c4162ef..d71a04d8fb 100644 --- a/src/gtk1/dcclient.cpp +++ b/src/gtk1/dcclient.cpp @@ -1200,6 +1200,26 @@ void wxWindowDC::Destroy() m_bgGC = (GdkGC*) NULL; } +void wxWindowDC::ComputeScaleAndOrigin() +{ + /* CMB: copy scale to see if it changes */ + double origScaleX = m_scaleX; + double origScaleY = m_scaleY; + + wxDC::ComputeScaleAndOrigin(); + + /* CMB: if scale has changed call SetPen to recalulate the line width */ + if ((m_scaleX != origScaleX || m_scaleY != origScaleY) && + (m_pen.Ok())) + { + /* this is a bit artificial, but we need to force wxDC to think + the pen has changed */ + wxPen pen = m_pen; + m_pen = wxNullPen; + SetPen( pen ); + } +} + // Resolution in pixels per logical inch wxSize wxWindowDC::GetPPI() const { diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index ade9c04dc7..5a676c5c1b 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -132,6 +132,7 @@ extern wxList wxPendingDelete; extern bool g_blockEventsOnDrag; extern bool g_blockEventsOnScroll; +extern wxCursor g_globalCursor; static bool g_capturing = FALSE; static wxWindow *g_focusWindow = (wxWindow*) NULL; @@ -1250,9 +1251,6 @@ static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_ if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE; - if (widget->window && win->GetCursor().Ok() ) - gdk_window_set_cursor( widget->window, win->GetCursor().GetCursor() ); - wxMouseEvent event( wxEVT_ENTER_WINDOW ); #if (GTK_MINOR_VERSION > 0) event.SetTimestamp( gdk_event->time ); @@ -1299,9 +1297,6 @@ static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_ if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE; - if (widget->window && win->GetCursor().Ok() ) - gdk_window_set_cursor( widget->window, wxSTANDARD_CURSOR->GetCursor() ); - wxMouseEvent event( wxEVT_LEAVE_WINDOW ); #if (GTK_MINOR_VERSION > 0) event.SetTimestamp( gdk_event->time ); @@ -2032,6 +2027,15 @@ void wxWindow::DoSetSize( int x, int y, int width, int height, int sizeFlags ) void wxWindow::OnInternalIdle() { + GdkWindow *window = GetConnectWidget()->window; + if (window) + { + if (g_globalCursor.Ok()) + gdk_window_set_cursor( window, g_globalCursor.GetCursor() ); + else + gdk_window_set_cursor( window, m_cursor.GetCursor() ); + } + UpdateWindowUI(); } @@ -2391,11 +2395,7 @@ bool wxWindow::SetCursor( const wxCursor &cursor ) return TRUE; } - if ((m_widget) && (m_widget->window)) - gdk_window_set_cursor( m_widget->window, GetCursor().GetCursor() ); - - if ((m_wxwindow) && (m_wxwindow->window)) - gdk_window_set_cursor( m_wxwindow->window, GetCursor().GetCursor() ); +// gdk_window_set_cursor( connect_widget->window, GetCursor().GetCursor() ); // cursor was set return TRUE; -- 2.45.2