Cursors, too, have been a constant source of pleasure. The main difficulty
is that a GdkWindow inherits a cursor if the programmer sets a new cursor
- for the parent. To prevent this from doing too much harm, I use idle time
- to set the cursor over and over again, starting from the toplevel windows
- and ending with the youngest generation (speaking of parent and child windows).
+ for the parent. To prevent this from doing too much harm, SetCursor calls
+ GTKUpdateCursor, which will recursively re-set the cursors of all child windows.
Also don't forget that cursors (like much else) are connected to GdkWindows,
not GtkWidgets and that the "window" field of a GtkWidget might very well
point to the GdkWindow of the parent widget (-> "window-less widget") and
that the two obviously have very different meanings.
-
*/
//-----------------------------------------------------------------------------
if (gdk_event->window != gtk_widget_get_parent_window(win->m_wxwindow))
return false;
+ if (!win->IsShown())
+ return false;
+
const GtkAllocation& alloc = win->m_wxwindow->allocation;
const int x = alloc.x;
const int y = alloc.y;
wxWindowCreateEvent event( win );
event.SetEventObject( win );
win->GTKProcessEvent( event );
+
+ win->GTKUpdateCursor(true, false);
}
//-----------------------------------------------------------------------------
m_needsStyleChange = false;
}
- wxCursor cursor = m_cursor;
- if (g_globalCursor.Ok()) cursor = g_globalCursor;
-
- if (cursor.Ok())
- {
- /* I now set the cursor anew in every OnInternalIdle call
- as setting the cursor in a parent window also effects the
- windows above so that checking for the current cursor is
- not possible. */
-
- if (m_wxwindow && (m_wxwindow != m_widget))
- {
- GdkWindow* window = GTKGetDrawingWindow();
- if (window)
- gdk_window_set_cursor( window, cursor.GetCursor() );
-
- if (!g_globalCursor.Ok())
- cursor = *wxSTANDARD_CURSOR;
-
- window = m_widget->window;
- if ((window) && !(GTK_WIDGET_NO_WINDOW(m_widget)))
- gdk_window_set_cursor( window, cursor.GetCursor() );
-
- }
- else if ( m_widget )
- {
- GdkWindow *window = m_widget->window;
- if ( window && !GTK_WIDGET_NO_WINDOW(m_widget) )
- gdk_window_set_cursor( window, cursor.GetCursor() );
- }
- }
-
if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
}
return true;
}
-void wxWindowGTK::GTKUpdateCursor()
+void wxWindowGTK::GTKUpdateCursor(bool update_self /*=true*/, bool recurse /*=true*/)
{
- wxCursor cursor(g_globalCursor.Ok() ? g_globalCursor : GetCursor());
- if ( cursor.Ok() )
+ if (update_self)
{
- wxArrayGdkWindows windowsThis;
- GdkWindow * const winThis = GTKGetWindow(windowsThis);
- if ( winThis )
- {
- gdk_window_set_cursor(winThis, cursor.GetCursor());
- }
- else
+ wxCursor cursor(g_globalCursor.Ok() ? g_globalCursor : GetCursor());
+ if ( cursor.Ok() )
{
- const size_t count = windowsThis.size();
- for ( size_t n = 0; n < count; n++ )
+ wxArrayGdkWindows windowsThis;
+ GdkWindow* window = GTKGetWindow(windowsThis);
+ if (window)
+ gdk_window_set_cursor( window, cursor.GetCursor() );
+ else
{
- GdkWindow *win = windowsThis[n];
- if ( !win )
+ const size_t count = windowsThis.size();
+ for ( size_t n = 0; n < count; n++ )
{
- wxFAIL_MSG(wxT("NULL window returned by GTKGetWindow()?"));
- continue;
+ GdkWindow *win = windowsThis[n];
+ // It can be zero if the window has not been realized yet.
+ if ( win )
+ {
+ gdk_window_set_cursor(win, cursor.GetCursor());
+ }
}
-
- gdk_window_set_cursor(win, cursor.GetCursor());
}
}
}
+
+ if (recurse)
+ {
+ for (wxWindowList::iterator it = GetChildren().begin(); it != GetChildren().end(); ++it)
+ {
+ (*it)->GTKUpdateCursor( true );
+ }
+ }
}
void wxWindowGTK::WarpPointer( int x, int y )
{
GdkWindow* window = NULL;
if (m_wxwindow)
- window = WX_PIZZA(m_wxwindow)->m_draw_window;
+ window = m_wxwindow->window;
return window;
}