]> git.saurik.com Git - wxWidgets.git/commitdiff
Some work on GTK focus handling and events.
authorRobert Roebling <robert@roebling.de>
Sat, 23 Feb 2002 18:59:46 +0000 (18:59 +0000)
committerRobert Roebling <robert@roebling.de>
Sat, 23 Feb 2002 18:59:46 +0000 (18:59 +0000)
  Removed some code #ifdeffed for GTK from
    wxListCtrl.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14363 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/popupcmn.cpp
src/generic/listctrl.cpp
src/gtk/textctrl.cpp
src/gtk/window.cpp
src/gtk1/textctrl.cpp
src/gtk1/window.cpp
src/univ/menu.cpp
src/x11/window.cpp

index c17d528fbfbd90923a7475f52ebca00b52f810b0..7da199a713f50435b6fb8f8ed782070433954f7d 100644 (file)
@@ -354,6 +354,7 @@ void wxPopupWindowHandler::OnLeftDown(wxMouseEvent& event)
     wxWindow *sbar = NULL;
 
     wxWindow *win = (wxWindow *)event.GetEventObject();
+    
     switch ( win->HitTest(pos.x, pos.y) )
     {
         case wxHT_WINDOW_OUTSIDE:
@@ -425,6 +426,7 @@ void wxPopupFocusHandler::OnKillFocus(wxFocusEvent& event)
             return;
         win = win->GetParent();
     }
+    
     m_popup->DismissAndNotify();
 }
 
index 07141e897ec33543ec778a9cd48cfa65a2e981c2..5ddd7f99c32004770dbf84128226317d35f888ce 100644 (file)
@@ -2662,14 +2662,6 @@ void wxListMainWindow::RefreshSelected()
         to = GetItemCount() - 1;
     }
 
-    // VZ: this code would work fine if wxGTK wxWindow::Refresh() were
-    //     reasonable, i.e. if it only generated one expose event for
-    //     several calls to it - as it is, each Refresh() results in a
-    //     repaint which provokes flicker too horrible to be seen
-    //
-    //     when/if wxGTK is fixed, this code should be restored as normally it
-    //     should generate _less_ flicker than the version below
-#ifndef __WXGTK__
     if ( HasCurrent() && m_current >= from && m_current <= to )
     {
         RefreshLine(m_current);
@@ -2683,26 +2675,6 @@ void wxListMainWindow::RefreshSelected()
             RefreshLine(line);
         }
     }
-#else // __WXGTK__
-    size_t selMin = (size_t)-1,
-           selMax = 0;
-
-    for ( size_t line = from; line <= to; line++ )
-    {
-        if ( IsHighlighted(line) || (line == m_current) )
-        {
-            if ( line < selMin )
-                selMin = line;
-            if ( line > selMax )
-                selMax = line;
-        }
-    }
-
-    if ( selMin != (size_t)-1 )
-    {
-        RefreshLines(selMin, selMax);
-    }
-#endif // !__WXGTK__/__WXGTK__
 }
 
 void wxListMainWindow::Freeze()
@@ -3426,10 +3398,6 @@ void wxListMainWindow::OnChar( wxKeyEvent &event )
 // focus handling
 // ----------------------------------------------------------------------------
 
-#ifdef __WXGTK__
-extern wxWindow *g_focusWindow;
-#endif
-
 void wxListMainWindow::SetFocus()
 {
     // VS: wxListMainWindow derives from wxPanel (via wxScrolledWindow) and wxPanel
@@ -3466,10 +3434,6 @@ void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
     if ( !GetParent() )
         return;
 
-#ifdef __WXGTK__
-    g_focusWindow = GetParent();
-#endif
-
     wxFocusEvent event( wxEVT_SET_FOCUS, GetParent()->GetId() );
     event.SetEventObject( GetParent() );
     GetParent()->GetEventHandler()->ProcessEvent( event );
@@ -4437,10 +4401,8 @@ void wxListMainWindow::OnScroll(wxScrollWinEvent& event)
         wxListCtrl* lc = GetListCtrl();
         wxCHECK_RET( lc, _T("no listctrl window?") );
 
-        lc->m_headerWin->Refresh() ;
-#ifdef __WXMAC__
-        lc->m_headerWin->MacUpdateImmediately() ;
-#endif
+        lc->m_headerWin->Refresh();
+        lc->m_headerWin->Update();
     }
 }
 
index 8dff685433d179120daa1479f3e8dbddb5362fe4..1c63ae186ea6967e14abacb3eec346d42b72a5b1 100644 (file)
@@ -791,9 +791,19 @@ void wxTextCtrl::SetSelection( long from, long to )
     gtk_editable_select_region( GTK_EDITABLE(m_text), (gint)from, (gint)to );
 }
 
-void wxTextCtrl::ShowPosition( long WXUNUSED(pos) )
+void wxTextCtrl::ShowPosition( long pos )
 {
-//    SetInsertionPoint( pos );
+    if (m_windowStyle & wxTE_MULTILINE)
+    {
+        GtkAdjustment *vp = GTK_TEXT(m_text)->vadj;
+        float totalLines =  (float) GetNumberOfLines();
+        long posX;
+        long posY;
+        PositionToXY(pos, &posX, &posY);
+        float posLine = (float) posY;
+        float p = (posLine/totalLines)*(vp->upper - vp->lower) + vp->lower;
+        gtk_adjustment_set_value(GTK_TEXT(m_text)->vadj, p);
+    }
 }
 
 long wxTextCtrl::GetInsertionPoint() const
index e2c690114e78b90b1c2aaae7e805a74f6c2de8ea..4294a2a24963990d6033a5b558b7a25fb1e8f444 100644 (file)
@@ -1212,20 +1212,15 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton
 
     if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE;
 
-    if (win->m_wxwindow)
+    if (win->m_wxwindow && (g_focusWindow != win) && win->AcceptsFocus())
     {
-        if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow) && !GTK_WIDGET_HAS_FOCUS (win->m_wxwindow) )
-        {
-            gtk_widget_grab_focus (win->m_wxwindow);
-
+        gtk_widget_grab_focus( win->m_wxwindow );
 /*
-            wxPrintf( wxT("GrabFocus from ") );
-            if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
-                wxPrintf( win->GetClassInfo()->GetClassName() );
-            wxPrintf( wxT(".\n") );
+        wxPrintf( wxT("GrabFocus from ") );
+        if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
+            wxPrintf( win->GetClassInfo()->GetClassName() );
+        wxPrintf( wxT(".\n") );
 */
-
-        }
     }
 
     wxEventType event_type = wxEVT_NULL;
@@ -1648,10 +1643,7 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget,
     g_focusWindow = win;
 
 #if 0
-    wxPrintf( "OnSetFocus from " );
-    if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
-        wxPrintf( win->GetClassInfo()->GetClassName() );
-    wxPrintf( ".\n" );
+    wxLogDebug( wxT("OnSetFocus from %s\n"), win->GetName().c_str() );
 #endif
 
     // notify the parent keeping track of focus for the kbd navigation
@@ -1710,9 +1702,7 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget,
 // "focus_out_event"
 //-----------------------------------------------------------------------------
 
-static GtkWidget *gs_widgetLastFocus = NULL;
-
-static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED(event), wxWindowGTK *win )
+static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEventFocus *gdk_event, wxWindowGTK *win )
 {
     DEBUG_MAIN_THREAD
 
@@ -1722,17 +1712,9 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED
     if (!win->m_hasVMT) return FALSE;
     if (g_blockEventsOnDrag) return FALSE;
 
-    // VZ: this is really weird but GTK+ seems to call us from inside
-    //     gtk_widget_grab_focus(), i.e. it first sends "focus_out" signal to
-    //     this widget and then "focus_in". This is totally unexpected and
-    //     completely breaks wxUniv code so ignore this dummy event (we can't
-    //     be losing focus if we're about to acquire it!)
-    if ( widget == gs_widgetLastFocus )
-    {
-        gs_widgetLastFocus = NULL;
-
-        return FALSE;
-    }
+#if 0
+    wxLogDebug( wxT("OnKillFocus from %s"), win->GetName().c_str() );
+#endif
 
     if ( !g_activeFrameLostFocus && g_activeFrame )
     {
@@ -1758,13 +1740,6 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED
 
     g_focusWindow = (wxWindowGTK *)NULL;
 
-#if 0
-    wxPrintf( "OnKillFocus from " );
-    if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
-        wxPrintf( win->GetClassInfo()->GetClassName() );
-    wxPrintf( ".\n" );
-#endif
-
 #ifdef HAVE_XIM
     if (win->m_ic)
         gdk_im_end();
@@ -3181,8 +3156,6 @@ void wxWindowGTK::SetFocus()
     {
         if (!GTK_WIDGET_HAS_FOCUS (m_wxwindow))
         {
-            // see comment in gtk_window_focus_out_callback()
-            gs_widgetLastFocus = m_wxwindow;
             gtk_widget_grab_focus (m_wxwindow);
         }
     }
@@ -3201,14 +3174,6 @@ void wxWindowGTK::SetFocus()
            // ?
         }
     }
-
-#if 0
-    wxPrintf( "SetFocus finished in " );
-    if (GetClassInfo() && GetClassInfo()->GetClassName())
-        wxPrintf( GetClassInfo()->GetClassName() );
-    wxPrintf( ".\n" );
-#endif
-
 }
 
 bool wxWindowGTK::AcceptsFocus() const
index 8dff685433d179120daa1479f3e8dbddb5362fe4..1c63ae186ea6967e14abacb3eec346d42b72a5b1 100644 (file)
@@ -791,9 +791,19 @@ void wxTextCtrl::SetSelection( long from, long to )
     gtk_editable_select_region( GTK_EDITABLE(m_text), (gint)from, (gint)to );
 }
 
-void wxTextCtrl::ShowPosition( long WXUNUSED(pos) )
+void wxTextCtrl::ShowPosition( long pos )
 {
-//    SetInsertionPoint( pos );
+    if (m_windowStyle & wxTE_MULTILINE)
+    {
+        GtkAdjustment *vp = GTK_TEXT(m_text)->vadj;
+        float totalLines =  (float) GetNumberOfLines();
+        long posX;
+        long posY;
+        PositionToXY(pos, &posX, &posY);
+        float posLine = (float) posY;
+        float p = (posLine/totalLines)*(vp->upper - vp->lower) + vp->lower;
+        gtk_adjustment_set_value(GTK_TEXT(m_text)->vadj, p);
+    }
 }
 
 long wxTextCtrl::GetInsertionPoint() const
index e2c690114e78b90b1c2aaae7e805a74f6c2de8ea..4294a2a24963990d6033a5b558b7a25fb1e8f444 100644 (file)
@@ -1212,20 +1212,15 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton
 
     if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE;
 
-    if (win->m_wxwindow)
+    if (win->m_wxwindow && (g_focusWindow != win) && win->AcceptsFocus())
     {
-        if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow) && !GTK_WIDGET_HAS_FOCUS (win->m_wxwindow) )
-        {
-            gtk_widget_grab_focus (win->m_wxwindow);
-
+        gtk_widget_grab_focus( win->m_wxwindow );
 /*
-            wxPrintf( wxT("GrabFocus from ") );
-            if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
-                wxPrintf( win->GetClassInfo()->GetClassName() );
-            wxPrintf( wxT(".\n") );
+        wxPrintf( wxT("GrabFocus from ") );
+        if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
+            wxPrintf( win->GetClassInfo()->GetClassName() );
+        wxPrintf( wxT(".\n") );
 */
-
-        }
     }
 
     wxEventType event_type = wxEVT_NULL;
@@ -1648,10 +1643,7 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget,
     g_focusWindow = win;
 
 #if 0
-    wxPrintf( "OnSetFocus from " );
-    if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
-        wxPrintf( win->GetClassInfo()->GetClassName() );
-    wxPrintf( ".\n" );
+    wxLogDebug( wxT("OnSetFocus from %s\n"), win->GetName().c_str() );
 #endif
 
     // notify the parent keeping track of focus for the kbd navigation
@@ -1710,9 +1702,7 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget,
 // "focus_out_event"
 //-----------------------------------------------------------------------------
 
-static GtkWidget *gs_widgetLastFocus = NULL;
-
-static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED(event), wxWindowGTK *win )
+static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEventFocus *gdk_event, wxWindowGTK *win )
 {
     DEBUG_MAIN_THREAD
 
@@ -1722,17 +1712,9 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED
     if (!win->m_hasVMT) return FALSE;
     if (g_blockEventsOnDrag) return FALSE;
 
-    // VZ: this is really weird but GTK+ seems to call us from inside
-    //     gtk_widget_grab_focus(), i.e. it first sends "focus_out" signal to
-    //     this widget and then "focus_in". This is totally unexpected and
-    //     completely breaks wxUniv code so ignore this dummy event (we can't
-    //     be losing focus if we're about to acquire it!)
-    if ( widget == gs_widgetLastFocus )
-    {
-        gs_widgetLastFocus = NULL;
-
-        return FALSE;
-    }
+#if 0
+    wxLogDebug( wxT("OnKillFocus from %s"), win->GetName().c_str() );
+#endif
 
     if ( !g_activeFrameLostFocus && g_activeFrame )
     {
@@ -1758,13 +1740,6 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED
 
     g_focusWindow = (wxWindowGTK *)NULL;
 
-#if 0
-    wxPrintf( "OnKillFocus from " );
-    if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
-        wxPrintf( win->GetClassInfo()->GetClassName() );
-    wxPrintf( ".\n" );
-#endif
-
 #ifdef HAVE_XIM
     if (win->m_ic)
         gdk_im_end();
@@ -3181,8 +3156,6 @@ void wxWindowGTK::SetFocus()
     {
         if (!GTK_WIDGET_HAS_FOCUS (m_wxwindow))
         {
-            // see comment in gtk_window_focus_out_callback()
-            gs_widgetLastFocus = m_wxwindow;
             gtk_widget_grab_focus (m_wxwindow);
         }
     }
@@ -3201,14 +3174,6 @@ void wxWindowGTK::SetFocus()
            // ?
         }
     }
-
-#if 0
-    wxPrintf( "SetFocus finished in " );
-    if (GetClassInfo() && GetClassInfo()->GetClassName())
-        wxPrintf( GetClassInfo()->GetClassName() );
-    wxPrintf( ".\n" );
-#endif
-
 }
 
 bool wxWindowGTK::AcceptsFocus() const
index bb9b246db11643823488a370dbe01b22091eaf5d..a880d500379f99f0c818e756bd052bb79e9971dd 100644 (file)
@@ -662,7 +662,7 @@ bool wxPopupMenuWindow::ProcessLeftDown(wxMouseEvent& event)
             wxPopupMenuWindow *win = menu->m_popupMenu;
 
             wxCHECK_MSG( win, FALSE, _T("parent menu not shown?") );
-
+            
             pos = ClientToScreen(pos);
             if ( win->GetMenuItemFromPoint(win->ScreenToClient(pos)) )
             {
index 54b47095d02b967c36558982a2db6d90f5f3a23e..13a199db536eafaf5f7cb3623cec62c355cecb8d 100644 (file)
@@ -383,7 +383,7 @@ void wxWindowX11::DoCaptureMouse()
             return;
         }
 
-        /// wxLogDebug("Grabbed pointer");
+        wxLogDebug("Grabbed pointer in %s", GetName().c_str() );
 
 #if 0
         res = XGrabButton(wxGlobalDisplay(), AnyButton, AnyModifier,
@@ -443,7 +443,7 @@ void wxWindowX11::DoReleaseMouse()
 #endif
     }
     
-    // wxLogDebug("Ungrabbed pointer");
+    wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() );
 
     m_winCaptured = FALSE;
 }