]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk1/window.cpp
New module definition file for the ever chaning treectrl class interface.
[wxWidgets.git] / src / gtk1 / window.cpp
index ce6e688621d91f43799109ab4b804db0c36a4498..8f73c4e2db7ad7f02f261df34e9a02daa05a5a54 100644 (file)
     #include "wx/caret.h"
 #endif // wxUSE_CARET
 
+#if wxUSE_TEXTCTRL
+#include "wx/textctrl.h"
+#endif
+
 #include "wx/menu.h"
 #include "wx/statusbr.h"
 #include "wx/intl.h"
@@ -333,25 +337,25 @@ extern bool g_isIdle;
 // returns the child of win which currently has focus or NULL if not found
 //
 // Note: can't be static, needed by textctrl.cpp.
-wxWindow *FindFocusedChild(wxWindowGTK *win)
+wxWindow *wxFindFocusedChild(wxWindowGTK *win)
 {
-    wxWindowGTK *winFocus = wxWindowGTK::FindFocus();
+    wxWindow *winFocus = wxWindowGTK::FindFocus();
     if ( !winFocus )
-        return (wxWindowGTK *)NULL;
+        return (wxWindow *)NULL;
 
     if ( winFocus == win )
-        return win;
+        return (wxWindow *)win;
 
     for ( wxWindowList::Node *node = win->GetChildren().GetFirst();
           node;
           node = node->GetNext() )
     {
-        wxWindowGTK *child = FindFocusedChild(node->GetData());
+        wxWindow *child = wxFindFocusedChild(node->GetData());
         if ( child )
             return child;
     }
 
-    return (wxWindowGTK *)NULL;
+    return (wxWindow *)NULL;
 }
 
 static void draw_frame( GtkWidget *widget, wxWindowGTK *win )
@@ -1665,7 +1669,7 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget,
     switch ( g_sendActivateEvent )
     {
         case -1:
-            // we've got focus from outside, synthtize wxActivateEvent
+            // we've got focus from outside, synthetize wxActivateEvent
             g_sendActivateEvent = 1;
             break;
 
@@ -1679,20 +1683,17 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget,
     g_focusWindowLast =
     g_focusWindow = win;
 
-/*
-    printf( "OnSetFocus from " );
+#if 0
+    wxPrintf( "OnSetFocus from " );
     if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
-        printf( win->GetClassInfo()->GetClassName() );
-    printf( "   " );
-    printf( WXSTRINGCAST win->GetLabel() );
-    printf( ".\n" );
-*/
+        wxPrintf( win->GetClassInfo()->GetClassName() );
+    wxPrintf( ".\n" );
+#endif
 
-    wxPanel *panel = wxDynamicCast(win->GetParent(), wxPanel);
-    if (panel)
-    {
-        panel->SetLastFocus(win);
-    }
+    // notify the parent keeping track of focus for the kbd navigation
+    // purposes that we got it
+    wxChildFocusEvent eventFocus(win);
+    (void)win->GetEventHandler()->ProcessEvent(eventFocus);
 
 #ifdef HAVE_XIM
     if (win->m_ic)
@@ -1749,18 +1750,18 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED
     // g_sendActivateEvent to -1
     g_sendActivateEvent = 0;
 
-    wxWindowGTK *winFocus = FindFocusedChild(win);
+    wxWindowGTK *winFocus = wxFindFocusedChild(win);
     if ( winFocus )
         win = winFocus;
 
     g_focusWindow = (wxWindowGTK *)NULL;
 
-/*
-    printf( "OnKillFocus from " );
+#if 0
+    wxPrintf( "OnKillFocus from " );
     if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
-        printf( win->GetClassInfo()->GetClassName() );
-    printf( ".\n" );
-*/
+        wxPrintf( win->GetClassInfo()->GetClassName() );
+    wxPrintf( ".\n" );
+#endif
 
 #ifdef HAVE_XIM
     if (win->m_ic)
@@ -1814,9 +1815,7 @@ static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_
     if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE;
 
     wxMouseEvent event( wxEVT_ENTER_WINDOW );
-#if (GTK_MINOR_VERSION > 0)
     event.SetTimestamp( gdk_event->time );
-#endif
     event.SetEventObject( win );
 
     int x = 0;
@@ -1856,9 +1855,7 @@ static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_
     if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE;
 
     wxMouseEvent event( wxEVT_LEAVE_WINDOW );
-#if (GTK_MINOR_VERSION > 0)
     event.SetTimestamp( gdk_event->time );
-#endif
     event.SetEventObject( win );
 
     int x = 0;
@@ -2260,11 +2257,13 @@ wxWindow *wxGetActiveWindow()
 // wxWindowGTK
 //-----------------------------------------------------------------------------
 
+// in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
+// method
 #ifdef __WXUNIVERSAL__
-    IMPLEMENT_DYNAMIC_CLASS(wxWindowGTK, wxWindowBase)
-#else
+    IMPLEMENT_ABSTRACT_CLASS(wxWindowGTK, wxWindowBase)
+#else // __WXGTK__
     IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
-#endif
+#endif // __WXUNIVERSAL__/__WXGTK__
 
 void wxWindowGTK::Init()
 {
@@ -2274,6 +2273,7 @@ void wxWindowGTK::Init()
     // GTK specific
     m_widget = (GtkWidget *) NULL;
     m_wxwindow = (GtkWidget *) NULL;
+    m_focusWidget = (GtkWidget *) NULL;
 
     // position/size
     m_x = 0;
@@ -2288,7 +2288,7 @@ void wxWindowGTK::Init()
 
     m_noExpose = FALSE;
     m_nativeSizeEvent = FALSE;
-
+    
     m_hasScrolling = FALSE;
     m_isScrolling = FALSE;
 
@@ -2462,6 +2462,8 @@ bool wxWindowGTK::Create( wxWindow *parent,
 
     if (m_parent)
         m_parent->DoAddChild( this );
+        
+    m_focusWidget = m_wxwindow;
 
     PostCreation();
 
@@ -2551,12 +2553,12 @@ bool wxWindowGTK::PreCreation( wxWindowGTK *parent, const wxPoint &pos,  const w
 void wxWindowGTK::PostCreation()
 {
     wxASSERT_MSG( (m_widget != NULL), wxT("invalid window") );
-
+    
     if (m_wxwindow)
     {
         if (!m_noExpose)
         {
-            /* these get reported to wxWindows -> wxPaintEvent */
+            // these get reported to wxWindows -> wxPaintEvent
 
             gtk_pizza_set_external( GTK_PIZZA(m_wxwindow), TRUE );
 
@@ -2573,35 +2575,32 @@ void wxWindowGTK::PostCreation()
             }
         }
 
-#if (GTK_MINOR_VERSION > 0)
-        /* these are called when the "sunken" or "raised" borders are drawn */
+        // these are called when the "sunken" or "raised" borders are drawn */
         gtk_signal_connect( GTK_OBJECT(m_widget), "expose_event",
           GTK_SIGNAL_FUNC(gtk_window_own_expose_callback), (gpointer)this );
 
         gtk_signal_connect( GTK_OBJECT(m_widget), "draw",
           GTK_SIGNAL_FUNC(gtk_window_own_draw_callback), (gpointer)this );
-#endif
     }
 
-    if (m_wxwindow && m_needParent)
-    {
-        gtk_signal_connect( GTK_OBJECT(m_wxwindow), "focus_in_event",
-            GTK_SIGNAL_FUNC(gtk_window_focus_in_callback), (gpointer)this );
+    // focus handling
 
-        gtk_signal_connect( GTK_OBJECT(m_wxwindow), "focus_out_event",
-            GTK_SIGNAL_FUNC(gtk_window_focus_out_callback), (gpointer)this );
-    }
-    else
-    {
-        // For dialogs and frames, we are interested mainly in
-        // m_widget's focus.
+    if (m_focusWidget == NULL)
+        m_focusWidget = m_widget;
+
+#if 0
+    if (GetClassInfo() && GetClassInfo()->GetClassName())
+        wxPrintf( GetClassInfo()->GetClassName() );
+    wxPrintf( ".\n" );
+#endif
 
-        gtk_signal_connect( GTK_OBJECT(m_widget), "focus_in_event",
-            GTK_SIGNAL_FUNC(gtk_window_focus_in_callback), (gpointer)this );
+    gtk_signal_connect( GTK_OBJECT(m_focusWidget), "focus_in_event",
+        GTK_SIGNAL_FUNC(gtk_window_focus_in_callback), (gpointer)this );
 
-        gtk_signal_connect( GTK_OBJECT(m_widget), "focus_out_event",
-            GTK_SIGNAL_FUNC(gtk_window_focus_out_callback), (gpointer)this );
-    }
+    gtk_signal_connect( GTK_OBJECT(m_focusWidget), "focus_out_event",
+         GTK_SIGNAL_FUNC(gtk_window_focus_out_callback), (gpointer)this );
+
+    // connect to the various key and mouse handlers
 
     GtkWidget *connect_widget = GetConnectWidget();
 
@@ -3067,7 +3066,7 @@ bool wxWindowGTK::Show( bool show )
     return TRUE;
 }
 
-static void wxWindowNotifyEnable(wxWindow* win, bool enable)
+static void wxWindowNotifyEnable(wxWindowGTK* win, bool enable)
 {
     win->OnParentEnable(enable);
 
@@ -3084,7 +3083,7 @@ static void wxWindowNotifyEnable(wxWindow* win, bool enable)
     }
 }
 
-bool wxWindow::Enable( bool enable )
+bool wxWindowGTK::Enable( bool enable )
 {
     wxCHECK_MSG( (m_widget != NULL), FALSE, wxT("invalid window") );
 
@@ -3394,7 +3393,7 @@ void wxWindowGTK::DoSetToolTip( wxToolTip *tip )
     wxWindowBase::DoSetToolTip(tip);
 
     if (m_tooltip)
-        m_tooltip->Apply( this );
+        m_tooltip->Apply( (wxWindow *)this );
 }
 
 void wxWindowGTK::ApplyToolTip( GtkTooltips *tips, const wxChar *tip )
@@ -3605,7 +3604,7 @@ void wxWindowGTK::ApplyWidgetStyle()
 // Pop-up menu stuff
 //-----------------------------------------------------------------------------
 
-#if wxUSE_MENUS
+#if wxUSE_MENUS_NATIVE
 
 static void gtk_pop_hide_callback( GtkWidget *WXUNUSED(widget), bool* is_waiting  )
 {
@@ -3677,7 +3676,7 @@ bool wxWindowGTK::DoPopupMenu( wxMenu *menu, int x, int y )
     return TRUE;
 }
 
-#endif // wxUSE_MENUS
+#endif // wxUSE_MENUS_NATIVE
 
 #if wxUSE_DRAG_AND_DROP
 
@@ -3741,15 +3740,13 @@ void wxWindowGTK::CaptureMouse()
 {
     wxCHECK_RET( m_widget != NULL, wxT("invalid window") );
 
-    wxCHECK_RET( g_captureWindow == NULL, wxT("CaptureMouse called twice") );
-
     GdkWindow *window = (GdkWindow*) NULL;
     if (m_wxwindow)
         window = GTK_PIZZA(m_wxwindow)->bin_window;
     else
         window = GetConnectWidget()->window;
 
-    if (!window) return;
+    wxCHECK_RET( window, _T("CaptureMouse() failed") );
 
     wxCursor* cursor = & m_cursor;
     if (!cursor->Ok())
@@ -3772,7 +3769,7 @@ void wxWindowGTK::ReleaseMouse()
 {
     wxCHECK_RET( m_widget != NULL, wxT("invalid window") );
 
-    wxCHECK_RET( g_captureWindow, wxT("ReleaseMouse called twice") );
+    wxCHECK_RET( g_captureWindow, wxT("can't release mouse - not captured") );
 
     GdkWindow *window = (GdkWindow*) NULL;
     if (m_wxwindow)