]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/window.cpp
wxGTK now works a little again.
[wxWidgets.git] / src / gtk / window.cpp
index dcf7519e32e505a5e8a3caaa91f0abb2aa620d5a..fa72030a8ccaa592a43126f8eddc1affa103d754 100644 (file)
@@ -145,16 +145,15 @@ static gint gtk_debug_focus_in_callback( GtkWidget *WXUNUSED(widget),
                                          GdkEvent *WXUNUSED(event),
                                          const wxChar *name )
 {
-    // to enable logging of the focus events replace 0 with 1
-#if 0
+/*
     static bool s_done = FALSE;
     if ( !s_done )
     {
         wxLog::AddTraceMask("focus");
         s_done = TRUE;
     }
-#endif
     wxLogTrace(_T("FOCUS NOW AT: %s"), name);
+*/
 
     return FALSE;
 }
@@ -339,15 +338,27 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_e
     if (g_blockEventsOnDrag) return FALSE;
 
 /*
-    printf( "OnKeyPress from " );
-    if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
-        printf( win->GetClassInfo()->GetClassName() );
-    printf( ".\n" );
+    printf( "KeyDown-ScanCode is: %d.\n", gdk_event->keyval );
+    if (gdk_event->state & GDK_SHIFT_MASK)
+      printf( "ShiftDown.\n" );
+    else
+      printf( "ShiftUp.\n" );
+    if (gdk_event->state & GDK_CONTROL_MASK)
+      printf( "ControlDown.\n" );
+    else
+      printf( "ControlUp.\n" );
+    printf( "\n" );
 */
 
     long key_code = 0;
     switch (gdk_event->keyval)
     {
+        case GDK_Shift_L:
+       case GDK_Shift_R:       key_code = WXK_SHIFT;       break;
+        case GDK_Control_L:
+       case GDK_Control_R:     key_code = WXK_CONTROL;     break;
+       case GDK_Menu:          key_code = WXK_MENU;        break;
+       case GDK_Help:          key_code = WXK_HELP;        break;
         case GDK_BackSpace:     key_code = WXK_BACK;        break;
         case GDK_ISO_Left_Tab:
         case GDK_KP_Tab:
@@ -424,16 +435,21 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_e
         }
     }
 
-    if (!key_code) return FALSE;
+    int x = 0;
+    int y = 0;
+    GdkModifierType state;
+    if (gdk_event->window) gdk_window_get_pointer(gdk_event->window, &x, &y, &state);
 
     wxKeyEvent event( wxEVT_KEY_DOWN );
+    event.SetTimestamp( gdk_event->time );
     event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK);
     event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK);
     event.m_altDown = (gdk_event->state & GDK_MOD1_MASK);
     event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK);
     event.m_keyCode = key_code;
-    event.m_x = 0;
-    event.m_y = 0;
+    event.m_scanCode = gdk_event->keyval;
+    event.m_x = x;
+    event.m_y = y;
     event.SetEventObject( win );
 
     bool ret = win->GetEventHandler()->ProcessEvent( event );
@@ -521,15 +537,27 @@ static gint gtk_window_key_release_callback( GtkWidget *widget, GdkEventKey *gdk
     if (g_blockEventsOnDrag) return FALSE;
 
 /*
-    printf( "OnKeyRelease from " );
-    if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
-        printf( win->GetClassInfo()->GetClassName() );
-    printf( ".\n" );
+    printf( "KeyUp-ScanCode is: %d.\n", gdk_event->keyval );
+    if (gdk_event->state & GDK_SHIFT_MASK)
+      printf( "ShiftDown.\n" );
+    else
+      printf( "ShiftUp.\n" );
+    if (gdk_event->state & GDK_CONTROL_MASK)
+      printf( "ControlDown.\n" );
+    else
+      printf( "ControlUp.\n" );
+    printf( "\n" );
 */
 
     long key_code = 0;
     switch (gdk_event->keyval)
     {
+        case GDK_Shift_L:
+       case GDK_Shift_R:       key_code = WXK_SHIFT;       break;
+        case GDK_Control_L:
+       case GDK_Control_R:     key_code = WXK_CONTROL;     break;
+       case GDK_Menu:          key_code = WXK_MENU;        break;
+       case GDK_Help:          key_code = WXK_HELP;        break;
         case GDK_BackSpace:     key_code = WXK_BACK;        break;
         case GDK_ISO_Left_Tab:
         case GDK_KP_Tab:
@@ -606,16 +634,21 @@ static gint gtk_window_key_release_callback( GtkWidget *widget, GdkEventKey *gdk
         }
     }
 
-    if (!key_code) return FALSE;
+    int x = 0;
+    int y = 0;
+    GdkModifierType state;
+    if (gdk_event->window) gdk_window_get_pointer(gdk_event->window, &x, &y, &state);
 
     wxKeyEvent event( wxEVT_KEY_UP );
+    event.SetTimestamp( gdk_event->time );
     event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK);
     event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK);
     event.m_altDown = (gdk_event->state & GDK_MOD1_MASK);
     event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK);
     event.m_keyCode = key_code;
-    event.m_x = 0;
-    event.m_y = 0;
+    event.m_scanCode = gdk_event->keyval;
+    event.m_x = x;
+    event.m_y = y;
     event.SetEventObject( win );
 
     if (win->GetEventHandler()->ProcessEvent( event ))
@@ -642,7 +675,6 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton
         wxPrintf( win->GetClassInfo()->GetClassName() );
     wxPrintf( _T(".\n") );
 */
-
     if (!win->m_hasVMT) return FALSE;
     if (g_blockEventsOnDrag) return TRUE;
     if (g_blockEventsOnScroll) return TRUE;
@@ -703,6 +735,7 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton
     }
 
     wxMouseEvent event( event_type );
+    event.SetTimestamp( gdk_event->time );
     event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK);
     event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK);
     event.m_altDown = (gdk_event->state & GDK_MOD1_MASK);
@@ -813,6 +846,7 @@ static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButto
     }
 
     wxMouseEvent event( event_type );
+    event.SetTimestamp( gdk_event->time );
     event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK);
     event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK);
     event.m_altDown = (gdk_event->state & GDK_MOD1_MASK);
@@ -922,6 +956,7 @@ static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion
 */
 
     wxMouseEvent event( wxEVT_MOTION );
+    event.SetTimestamp( gdk_event->time );
     event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK);
     event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK);
     event.m_altDown = (gdk_event->state & GDK_MOD1_MASK);
@@ -1103,6 +1138,7 @@ static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_
         gdk_window_set_cursor( widget->window, win->GetCursor().GetCursor() );
 
     wxMouseEvent event( wxEVT_ENTER_WINDOW );
+    event.SetTimestamp( gdk_event->time );
     event.SetEventObject( win );
 
     int x = 0;
@@ -1149,6 +1185,7 @@ static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_
         gdk_window_set_cursor( widget->window, wxSTANDARD_CURSOR->GetCursor() );
 
     wxMouseEvent event( wxEVT_LEAVE_WINDOW );
+    event.SetTimestamp( gdk_event->time );
     event.SetEventObject( win );
 
     int x = 0;
@@ -1369,35 +1406,21 @@ wxWindow *wxWindowBase::FindFocus()
    been realized, so we do this directly after realization */
 
 static gint
-gtk_window_realized_callback( GtkWidget *widget, wxWindow *win )
+gtk_window_realized_callback( GtkWidget * WXUNUSED(widget), wxWindow *win )
 {
     if (g_isIdle) 
         wxapp_install_idle_handler();
 
-    if (win->m_font != *wxSWISS_FONT)
-    {
-        wxFont font( win->m_font );
-        win->m_font = wxNullFont;
-       win->SetFont( font );
-    }
+    if (win->m_delayedFont)
+        win->SetFont( win->GetFont() );
 
-    if (win->m_backgroundColour != wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE ))
-    {
-        wxColour bg( win->m_backgroundColour );
-       win->m_backgroundColour = wxNullColour;
-       win->SetBackgroundColour( bg );
-    }
+    if (win->m_delayedBackgroundColour)
+        win->SetBackgroundColour( win->GetBackgroundColour() );
 
-    if (win->m_foregroundColour != *wxBLACK)
-    {
-        wxColour fg( win->m_foregroundColour );
-       win->m_foregroundColour = wxNullColour;
-       win->SetForegroundColour( fg );
-    }
+    if (win->m_delayedForegroundColour)
+        win->SetForegroundColour( win->GetForegroundColour() );
 
-    wxCursor cursor( win->m_cursor );
-    win->m_cursor = wxNullCursor;
-    win->SetCursor( cursor );
+    win->SetCursor( win->GetCursor() );
 
     return FALSE;
 }
@@ -1464,12 +1487,10 @@ void wxWindow::Init()
     m_width = 0;
     m_height = 0;
 
-    m_font = *wxSWISS_FONT;
-    m_windowName = "noname";
-
     m_sizeSet = FALSE;
     m_hasVMT = FALSE;
     m_needParent = TRUE;
+    m_isBeingDeleted = FALSE;
 
     m_hasScrolling = FALSE;
     m_isScrolling = FALSE;
@@ -1650,6 +1671,7 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id,
 
 wxWindow::~wxWindow()
 {
+    m_isBeingDeleted = TRUE;
     m_hasVMT = FALSE;
 
     if (m_widget)
@@ -2098,8 +2120,11 @@ bool wxWindow::Show( bool show )
 {
     wxCHECK_MSG( (m_widget != NULL), FALSE, _T("invalid window") );
 
-    if ( !wxWindowBase::Show(show) )
+    if (!wxWindowBase::Show(show))
+    {
+        // nothing to do
         return FALSE;
+    }
 
     if (show)
         gtk_widget_show( m_widget );
@@ -2113,8 +2138,11 @@ bool wxWindow::Enable( bool enable )
 {
     wxCHECK_MSG( (m_widget != NULL), FALSE, _T("invalid window") );
 
-    if ( !wxWindowBase::Enable(enable) )
+    if (!wxWindowBase::Enable(enable))
+    {
+        // nothing to do
         return FALSE;
+    }
 
     gtk_widget_set_sensitive( m_widget, enable );
     if ( m_wxwindow )
@@ -2234,9 +2262,24 @@ bool wxWindow::SetCursor( const wxCursor &cursor )
 {
     wxCHECK_MSG( (m_widget != NULL), FALSE, _T("invalid window") );
 
-    if ( wxWindowBase::SetCursor(cursor) )
+    if (!wxWindowBase::SetCursor(cursor))
     {
-        if (!m_widget->window) return TRUE;
+        // don't leave if the GTK widget has just
+        // been realized
+        if (!m_delayedCursor) return FALSE;
+    }
+    
+    GtkWidget *connect_widget = GetConnectWidget();
+    if (!connect_widget->window)
+    {
+        // indicate that a new style has been set
+       // but it couldn't get applied as the
+       // widget hasn't been realized yet.
+       m_delayedCursor = TRUE;
+       
+       // pretend we have done something
+        return TRUE;
+    }
 
         if ((m_widget) && (m_widget->window))
              gdk_window_set_cursor( m_widget->window, GetCursor().GetCursor() );
@@ -2244,14 +2287,8 @@ bool wxWindow::SetCursor( const wxCursor &cursor )
         if ((m_wxwindow) && (m_wxwindow->window))
              gdk_window_set_cursor( m_wxwindow->window, GetCursor().GetCursor() );
 
-        // cursor was set
-        return TRUE;
-    }
-    else
-    {
-        // cursor hasn't been changed
-        return FALSE;
-    }
+    // cursor was set
+    return TRUE;
 }
 
 void wxWindow::WarpPointer( int WXUNUSED(x), int WXUNUSED(y) )
@@ -2332,11 +2369,24 @@ bool wxWindow::SetBackgroundColour( const wxColour &colour )
 {
     wxCHECK_MSG( m_widget != NULL, FALSE, _T("invalid window") );
 
-    if (!colour.Ok()) return FALSE;
-    if (m_backgroundColour == colour) return FALSE;
-
+    if (!wxWindowBase::SetBackgroundColour(colour))
+    {
+        // don't leave if the GTK widget has just
+        // been realized
+        if (!m_delayedBackgroundColour) return FALSE;
+    }
+    
     GtkWidget *connect_widget = GetConnectWidget();
-    if (!connect_widget->window) return TRUE;
+    if (!connect_widget->window)
+    {
+        // indicate that a new style has been set
+       // but it couldn't get applied as the
+       // widget hasn't been realized yet.
+       m_delayedBackgroundColour = TRUE;
+       
+       // pretend we have done something
+        return TRUE;
+    }
 
     if (m_wxwindow && m_wxwindow->window)
     {
@@ -2349,7 +2399,7 @@ bool wxWindow::SetBackgroundColour( const wxColour &colour )
 
     wxColour sysbg = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE );
 
-    if ( sysbg == m_backgroundColour )
+    if (sysbg == m_backgroundColour)
     {
         m_backgroundColour = wxNullColour;
         ApplyWidgetStyle();
@@ -2367,14 +2417,27 @@ bool wxWindow::SetForegroundColour( const wxColour &colour )
 {
     wxCHECK_MSG( m_widget != NULL, FALSE, _T("invalid window") );
 
-    if (!colour.Ok()) return FALSE;
-    if (m_backgroundColour == colour) return FALSE;
-
+    if (!wxWindowBase::SetForegroundColour(colour))
+    {
+        // don't leave if the GTK widget has just
+        // been realized
+        if (!m_delayedForegroundColour) return FALSE;
+    }
+    
     GtkWidget *connect_widget = GetConnectWidget();
-    if (!connect_widget->window) return TRUE;
+    if (!connect_widget->window)
+    {
+        // indicate that a new style has been set
+       // but it couldn't get applied as the
+       // widget hasn't been realized yet.
+       m_delayedForegroundColour = TRUE;
+       
+       // pretend we have done something
+        return TRUE;
+    }
 
     wxColour sysbg = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE );
-    if ( sysbg == m_foregroundColour )
+    if (sysbg == m_foregroundColour)
     {
         m_backgroundColour = wxNullColour;
         ApplyWidgetStyle();
@@ -2448,7 +2511,9 @@ static void SetInvokingWindow( wxMenu *menu, wxWindow *win )
 static gint gs_pop_x = 0;
 static gint gs_pop_y = 0;
 
-static void pop_pos_callback( GtkMenu *menu, gint *x, gint *y, wxWindow *win )
+static void pop_pos_callback( GtkMenu * WXUNUSED(menu),
+                              gint *x, gint *y,
+                              wxWindow *win )
 {
     win->ClientToScreen( &gs_pop_x, &gs_pop_y );
     *x = gs_pop_x;
@@ -2516,11 +2581,24 @@ bool wxWindow::SetFont( const wxFont &font )
 {
     wxCHECK_MSG( m_widget != NULL, FALSE, _T(  "invalid window") );
 
-    if (!font.Ok()) return FALSE;
-    if (m_font == font) return FALSE;
-
+    if (!wxWindowBase::SetFont(font))
+    {
+        // don't leave if the GTK widget has just
+        // been realized
+        if (!m_delayedFont) return FALSE;
+    }
+    
     GtkWidget *connect_widget = GetConnectWidget();
-    if (!connect_widget->window) return TRUE;
+    if (!connect_widget->window)
+    {
+        // indicate that a new style has been set
+       // but it couldn't get applied as the
+       // widget hasn't been realized yet.
+       m_delayedFont = TRUE;
+       
+       // pretend we have done something
+        return TRUE;
+    }
 
     wxColour sysbg = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE );
     if ( sysbg == m_backgroundColour )
@@ -2635,15 +2713,10 @@ void wxWindow::SetScrollbar( int orient, int pos, int thumbVisible,
         m_vAdjust->page_size = fthumb;
     }
 
-    if (m_wxwindow->window)
-    {
-        if (orient == wxHORIZONTAL)
-            gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" );
-        else
-            gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "changed" );
-
-        gtk_widget_set_usize( m_widget, m_width, m_height );
-    }
+    if (orient == wxHORIZONTAL)
+        gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" );
+    else
+        gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "changed" );
 }
 
 void wxWindow::SetScrollPos( int orient, int pos, bool WXUNUSED(refresh) )
@@ -2673,7 +2746,7 @@ void wxWindow::SetScrollPos( int orient, int pos, bool WXUNUSED(refresh) )
         m_vAdjust->value = fpos;
     }
 
-    if (!m_isScrolling)
+    if (!m_isScrolling)  /* prevent recursion */
     {
         if (m_wxwindow->window)
         {