X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2b07d7130880c63b7f7908606a10f885e2719efc..53b88b545eecb4a975f0bdddd5f6a08f50e42209:/src/gtk/window.cpp?ds=sidebyside diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 2c6b88d560..584b8f808c 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -121,6 +121,39 @@ */ +//----------------------------------------------------------------------------- +// debug +//----------------------------------------------------------------------------- + +#ifdef __WXDEBUG__ + +static gint gtk_debug_focus_in_callback( GtkWidget *WXUNUSED(widget), + GdkEvent *WXUNUSED(event), + const wxChar *name ) +{ + wxPrintf( _T("FOCUS NOW AT: ") ); + wxPrintf( name ); + wxPrintf( _T("\n") ); + + return FALSE; +} + +void debug_focus_in( GtkWidget* widget, const wxChar* name, const wxChar *window ) +{ + wxString tmp = name; + tmp += _T(" FROM "); + tmp += window; + + wxChar *s = new wxChar[tmp.Length()+1]; + + wxStrcpy( s, tmp ); + + gtk_signal_connect( GTK_OBJECT(widget), "focus_in_event", + GTK_SIGNAL_FUNC(gtk_debug_focus_in_callback), (gpointer)s ); +} + +#endif + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -128,6 +161,7 @@ extern wxList wxPendingDelete; extern bool g_blockEventsOnDrag; extern bool g_blockEventsOnScroll; +extern bool g_isIdle; static bool g_capturing = FALSE; static wxWindow *g_focusWindow = (wxWindow*) NULL; @@ -135,6 +169,13 @@ static wxWindow *g_focusWindow = (wxWindow*) NULL; the last click here */ static guint32 gs_timeLastClick = 0; +//----------------------------------------------------------------------------- +// idle system +//----------------------------------------------------------------------------- + +extern void wxapp_install_idle_handler(); +extern bool g_isIdle; + #if (GTK_MINOR_VERSION > 0) //----------------------------------------------------------------------------- @@ -231,6 +272,8 @@ static void gtk_window_own_draw_callback( GtkWidget *widget, GdkRectangle *WXUNU static void gtk_window_expose_callback( GtkWidget *WXUNUSED(widget), GdkEventExpose *gdk_event, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return; win->m_updateRegion.Union( gdk_event->area.x, @@ -260,6 +303,8 @@ static void gtk_window_expose_callback( GtkWidget *WXUNUSED(widget), GdkEventExp static void gtk_window_draw_callback( GtkWidget *WXUNUSED(widget), GdkRectangle *rect, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return; win->m_updateRegion.Union( rect->x, rect->y, rect->width, rect->height ); @@ -277,16 +322,18 @@ static void gtk_window_draw_callback( GtkWidget *WXUNUSED(widget), GdkRectangle static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return FALSE; /* - printf( "OnKeyPress from " ); + wxPrintf( _T("OnKeyPress from ") ); if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) - printf( win->GetClassInfo()->GetClassName() ); - printf( ".\n" ); + wxPrintf( win->GetClassInfo()->GetClassName() ); + wxPrintf( _T(".\n") ); */ - + long key_code = 0; switch (gdk_event->keyval) { @@ -456,6 +503,8 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_e static gint gtk_window_key_release_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return FALSE; @@ -572,6 +621,15 @@ static gint gtk_window_key_release_callback( GtkWidget *widget, GdkEventKey *gdk static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + +/* + wxPrintf( _T("1) OnButtonPress from ") ); + if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) + wxPrintf( win->GetClassInfo()->GetClassName() ); + wxPrintf( _T(".\n") ); +*/ + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return TRUE; if (g_blockEventsOnScroll) return TRUE; @@ -585,20 +643,31 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton gtk_widget_grab_focus (win->m_wxwindow); /* - printf( "GrabFocus from " ); + wxPrintf( _T("GrabFocus from ") ); if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) - printf( win->GetClassInfo()->GetClassName() ); - printf( ".\n" ); + wxPrintf( win->GetClassInfo()->GetClassName() ); + wxPrintf( _T(".\n") ); */ } +/* + else + { + wxPrintf( _T("No GrabFocus from ") ); + if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) + wxPrintf( win->GetClassInfo()->GetClassName() ); + if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow)) + wxPrintf( _T(" because it already has") ); + wxPrintf( _T(".\n") ); + } +*/ } /* - printf( "OnButtonPress from " ); + wxPrintf( _T("2) OnButtonPress from ") ); if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) - printf( win->GetClassInfo()->GetClassName() ); - printf( ".\n" ); + wxPrintf( win->GetClassInfo()->GetClassName() ); + wxPrintf( _T(".\n") ); */ wxEventType event_type = wxEVT_LEFT_DOWN; @@ -716,6 +785,8 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return FALSE; if (g_blockEventsOnScroll) return FALSE; @@ -820,6 +891,8 @@ static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButto static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion *gdk_event, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return FALSE; if (g_blockEventsOnScroll) return FALSE; @@ -927,6 +1000,8 @@ static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion static gint gtk_window_focus_in_callback( GtkWidget *widget, GdkEvent *WXUNUSED(event), wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return FALSE; @@ -948,12 +1023,12 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget, GdkEvent *WXUNUSED( /* - printf( "OnSetFocus from " ); + wxPrintf( _T("OnSetFocus from ") ); if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) - printf( win->GetClassInfo()->GetClassName() ); - printf( " " ); - printf( WXSTRINGCAST win->GetLabel() ); - printf( ".\n" ); + wxPrintf( win->GetClassInfo()->GetClassName() ); + wxPrintf( _T(" ") ); + wxPrintf( win->GetLabel() ); + wxPrintf( _T(".\n") ); */ wxFocusEvent event( wxEVT_SET_FOCUS, win->GetId() ); @@ -974,6 +1049,8 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget, GdkEvent *WXUNUSED( static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED(event), wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return FALSE; @@ -984,10 +1061,12 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED } /* - printf( "OnKillFocus from " ); + wxPrintf( _T("OnKillFocus from ") ); if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) - printf( win->GetClassInfo()->GetClassName() ); - printf( ".\n" ); + wxPrintf( win->GetClassInfo()->GetClassName() ); + wxPrintf( _T(" ") ); + wxPrintf( win->GetLabel() ); + wxPrintf( _T(".\n") ); */ wxFocusEvent event( wxEVT_KILL_FOCUS, win->GetId() ); @@ -1008,13 +1087,15 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return FALSE; if (widget->window != gdk_event->window) return FALSE; - if ((widget->window) && (win->m_cursor)) - gdk_window_set_cursor( widget->window, win->m_cursor->GetCursor() ); + if ((widget->window) && (win->m_cursor.Ok())) + gdk_window_set_cursor( widget->window, win->m_cursor.GetCursor() ); /* printf( "OnEnter from " ); @@ -1058,12 +1139,14 @@ static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_ static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return FALSE; if (widget->window != gdk_event->window) return FALSE; - if ((widget->window) && (win->m_cursor)) + if (widget->window) gdk_window_set_cursor( widget->window, wxSTANDARD_CURSOR->GetCursor() ); /* @@ -1108,6 +1191,8 @@ static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_ static void gtk_window_vscroll_callback( GtkWidget *WXUNUSED(widget), wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (g_blockEventsOnDrag) return; /* @@ -1156,6 +1241,8 @@ static void gtk_window_vscroll_callback( GtkWidget *WXUNUSED(widget), wxWindow * static void gtk_window_hscroll_callback( GtkWidget *WXUNUSED(widget), wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (g_blockEventsOnDrag) return; /* @@ -1204,6 +1291,8 @@ static void gtk_window_hscroll_callback( GtkWidget *WXUNUSED(widget), wxWindow * static void gtk_window_vscroll_change_callback( GtkWidget *WXUNUSED(widget), wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (g_blockEventsOnDrag) return; /* @@ -1229,6 +1318,8 @@ static void gtk_window_vscroll_change_callback( GtkWidget *WXUNUSED(widget), wxW static void gtk_window_hscroll_change_callback( GtkWidget *WXUNUSED(widget), wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (g_blockEventsOnDrag) return; /* @@ -1256,6 +1347,8 @@ static gint gtk_scrollbar_button_press_callback( GtkRange *WXUNUSED(widget), GdkEventButton *WXUNUSED(gdk_event), wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + // don't test here as we can release the mouse while being over // a different window then the slider // @@ -1275,6 +1368,7 @@ static gint gtk_scrollbar_button_release_callback( GtkRange *widget, GdkEventButton *WXUNUSED(gdk_event), wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); // don't test here as we can release the mouse while being over // a different window then the slider @@ -1304,6 +1398,8 @@ static gint gtk_scrollbar_button_release_callback( GtkRange *widget, static gint gtk_window_realized_callback( GtkWidget *widget, wxWindow *win ) { + if (g_isIdle) wxapp_install_idle_handler(); + if (win->m_font != *wxSWISS_FONT) { wxFont font( win->m_font ); @@ -1325,6 +1421,10 @@ gtk_window_realized_callback( GtkWidget *widget, wxWindow *win ) win->SetForegroundColour( fg ); } + wxCursor cursor( win->m_cursor ); + win->m_cursor = wxNullCursor; + win->SetCursor( cursor ); + return FALSE; } @@ -1405,7 +1505,7 @@ void wxWindow::Init() m_windowId = -1; - m_cursor = (wxCursor *) NULL; + m_cursor = *wxSTANDARD_CURSOR; m_font = *wxSWISS_FONT; m_windowStyle = 0; m_windowName = "noname"; @@ -1475,8 +1575,17 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id, m_widget = gtk_scrolled_window_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL ); GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS ); +#ifdef __WXDEBUG__ + debug_focus_in( m_widget, _T("wxWindow::m_widget"), name ); +#endif + GtkScrolledWindow *s_window = GTK_SCROLLED_WINDOW(m_widget); +#ifdef __WXDEBUG__ + debug_focus_in( s_window->hscrollbar, _T("wxWindow::hsrcollbar"), name ); + debug_focus_in( s_window->vscrollbar, _T("wxWindow::vsrcollbar"), name ); +#endif + GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass ); scroll_class->scrollbar_spacing = 0; @@ -1490,8 +1599,12 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id, m_wxwindow = gtk_myfixed_new(); +#ifdef __WXDEBUG__ + debug_focus_in( m_wxwindow, _T("wxWindow::m_wxwindow"), name ); +#endif + gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow ); - + #if (GTK_MINOR_VERSION > 0) GtkMyFixed *myfixed = GTK_MYFIXED(m_wxwindow); @@ -1524,10 +1637,10 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id, } #endif + /* we always allow a window to get the focus as long as it + doesn't have any children. */ if (m_windowStyle & wxTAB_TRAVERSAL) { - /* we now allow a window to get the focus as long as it - doesn't have any children. */ GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); m_acceptsFocus = FALSE; } @@ -1536,7 +1649,13 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id, GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); m_acceptsFocus = TRUE; } + + /* grab the actual focus */ +// gtk_widget_grab_focus( m_wxwindow ); + + gtk_widget_show( m_wxwindow ); + #if (GTK_MINOR_VERSION == 0) // shut the viewport up gtk_viewport_set_hadjustment( viewport, (GtkAdjustment*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) ); @@ -1589,8 +1708,6 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id, gtk_signal_connect(GTK_OBJECT(m_vAdjust), "changed", (GtkSignalFunc) gtk_window_vscroll_change_callback, (gpointer) this ); - gtk_widget_show( m_wxwindow ); - if (m_parent) m_parent->AddChild( this ); (m_parent->m_insertCallback)( m_parent, this ); @@ -1636,8 +1753,6 @@ wxWindow::~wxWindow() if (m_widget) gtk_widget_destroy( m_widget ); - if (m_cursor) delete m_cursor; - DeleteRelatedConstraints(); if (m_constraints) { @@ -1718,7 +1833,7 @@ void wxWindow::PreCreation( wxWindow *parent, wxWindowID id, m_sizeSet = FALSE; - m_cursor = new wxCursor( wxCURSOR_ARROW ); + m_cursor = *wxSTANDARD_CURSOR; m_font = *wxSWISS_FONT; m_backgroundColour = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE ); m_foregroundColour = *wxBLACK; @@ -1782,12 +1897,13 @@ void wxWindow::PostCreation() #endif } - ConnectWidget( GetConnectWidget() ); + GtkWidget *connect_widget = GetConnectWidget(); -/* we cannot set colours, fonts and cursors before the widget has - been realized, so we do this directly after realization */ - - gtk_signal_connect( GTK_OBJECT(m_widget), "realize", + ConnectWidget( connect_widget ); + + /* we cannot set colours, fonts and cursors before the widget has + been realized, so we do this directly after realization */ + gtk_signal_connect( GTK_OBJECT(connect_widget), "realize", GTK_SIGNAL_FUNC(gtk_window_realized_callback), (gpointer) this ); m_hasVMT = TRUE; @@ -1935,7 +2051,17 @@ void wxWindow::DoSetSize( int x, int y, int width, int height, int sizeFlags ) gtk_myfixed_move( GTK_MYFIXED(m_parent->m_wxwindow), m_widget, m_x, m_y ); if ((old_width != m_width) || (old_height != m_height)) - gtk_widget_set_usize( m_widget, m_width, m_height ); + { +/* + GtkAllocation alloc; + alloc.x = m_x; + alloc.y = m_y; + alloc.width = m_width; + alloc.height = m_height; + gtk_widget_size_allocate( m_widget, &alloc ); +*/ + gtk_widget_set_usize( m_widget, m_width, m_height ); + } } } @@ -2216,6 +2342,9 @@ void wxWindow::SetSizeHints( int minW, int minH, int maxW, int maxH, int WXUNUSE void wxWindow::OnSize( wxSizeEvent &WXUNUSED(event) ) { + /* this is commented because it also is commented + in wxMSW. before I get even more questions about + this. */ // if (GetAutoLayout()) Layout(); } @@ -2492,20 +2621,20 @@ void wxWindow::SetCursor( const wxCursor &cursor ) if (cursor.Ok()) { - if (cursor == *m_cursor) return; - *m_cursor = cursor; + if (cursor == m_cursor) return; + m_cursor = cursor; } else { - *m_cursor = *wxSTANDARD_CURSOR; + m_cursor = *wxSTANDARD_CURSOR; } if (!m_widget->window) return; - gdk_window_set_cursor( m_widget->window, m_cursor->GetCursor() ); + gdk_window_set_cursor( m_widget->window, m_cursor.GetCursor() ); if ((m_wxwindow) && (m_wxwindow->window)) - gdk_window_set_cursor( m_wxwindow->window, m_cursor->GetCursor() ); + gdk_window_set_cursor( m_wxwindow->window, m_cursor.GetCursor() ); } void wxWindow::WarpPointer( int WXUNUSED(x), int WXUNUSED(y) ) @@ -2642,8 +2771,9 @@ void wxWindow::SetBackgroundColour( const wxColour &colour ) m_backgroundColour = colour; if (!m_backgroundColour.Ok()) return; - if (!m_widget->window) return; - + GtkWidget *connect_widget = GetConnectWidget(); + if (!connect_widget->window) return; + if (m_wxwindow && m_wxwindow->window) { /* wxMSW doesn't clear the window here. I don't do that @@ -3095,7 +3225,7 @@ void wxWindow::SetScrollbar( int orient, int pos, int thumbVisible, m_vAdjust->page_size = fthumb; } - if (m_wxwindow->window) + if (m_wxwindow) { if (orient == wxHORIZONTAL) gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" );