]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/spinctrl.cpp
wxChoice/wxComboBox background colour change (to get back to where we were);
[wxWidgets.git] / src / gtk / spinctrl.cpp
index 7b40f4ccbea4bb90353206055d76b99cadb5977a..5e13787f4bf7ec94c7064982f18f2d4e217fe4b7 100644 (file)
 
 #include "wx/spinctrl.h"
 
-#ifdef wxUSE_SPINBTN
+#if wxUSE_SPINCTRL
 
 #include "wx/utils.h"
-#include "wx/spinbutt.h"
+
 #include <math.h>
 
-#include "gdk/gdk.h"
-#include "gtk/gtk.h"
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
 
 //-----------------------------------------------------------------------------
 // idle system
@@ -36,8 +36,6 @@ extern bool g_isIdle;
 
 extern bool   g_blockEventsOnDrag;
 
-static const float sensitivity = 0.02;
-
 //-----------------------------------------------------------------------------
 // "value_changed"
 //-----------------------------------------------------------------------------
@@ -49,34 +47,10 @@ static void gtk_spinctrl_callback( GtkWidget *WXUNUSED(widget), wxSpinCtrl *win
     if (!win->m_hasVMT) return;
     if (g_blockEventsOnDrag) return;
 
-    float diff = win->m_adjust->value - win->m_oldPos;
-    if (fabs(diff) < sensitivity) return;
-    win->m_oldPos = win->m_adjust->value;
-
-    wxEventType command = wxEVT_NULL;
-
-    float line_step = win->m_adjust->step_increment;
-
-    if (fabs(diff-line_step) < sensitivity) command = wxEVT_SCROLL_LINEDOWN;
-    else if (fabs(diff+line_step) < sensitivity) command = wxEVT_SCROLL_LINEUP;
-    else command = wxEVT_SCROLL_THUMBTRACK;
-
-    int value = (int)ceil(win->m_adjust->value);
-
-    wxSpinEvent event( command, win->GetId());
-    event.SetPosition( value );
+    wxCommandEvent event( wxEVT_COMMAND_SPINCTRL_UPDATED, win->GetId());
     event.SetEventObject( win );
+    event.SetInt( win->GetValue() );
     win->GetEventHandler()->ProcessEvent( event );
-    
-    /* always send a thumbtrack event */
-    if (command != wxEVT_SCROLL_THUMBTRACK)
-    {
-        command = wxEVT_SCROLL_THUMBTRACK;
-        wxSpinEvent event2( command, win->GetId());
-        event2.SetPosition( value );
-        event2.SetEventObject( win );
-        win->GetEventHandler()->ProcessEvent( event2 );
-    }
 }
 
 //-----------------------------------------------------------------------------
@@ -85,6 +59,10 @@ static void gtk_spinctrl_callback( GtkWidget *WXUNUSED(widget), wxSpinCtrl *win
 
 IMPLEMENT_DYNAMIC_CLASS(wxSpinCtrl,wxControl)
 
+BEGIN_EVENT_TABLE(wxSpinCtrl, wxControl)
+    EVT_CHAR(wxSpinCtrl::OnChar)
+END_EVENT_TABLE()
+
 bool wxSpinCtrl::Create(wxWindow *parent, wxWindowID id,
                         const wxString& value,
                         const wxPoint& pos,  const wxSize& size,
@@ -93,6 +71,7 @@ bool wxSpinCtrl::Create(wxWindow *parent, wxWindowID id,
                         const wxString& name)
 {
     m_needParent = TRUE;
+    m_acceptsFocus = TRUE;
 
     wxSize new_size = size;
     if (new_size.y == -1)
@@ -111,7 +90,8 @@ bool wxSpinCtrl::Create(wxWindow *parent, wxWindowID id,
 
     m_widget = gtk_spin_button_new( m_adjust, 1, 0 );
 
-    gtk_spin_button_set_wrap( GTK_SPIN_BUTTON(m_widget), (m_windowStyle & wxSP_WRAP) );
+    gtk_spin_button_set_wrap( GTK_SPIN_BUTTON(m_widget),
+                              (int)(m_windowStyle & wxSP_WRAP) );
 
     gtk_signal_connect( GTK_OBJECT (m_adjust),
                         "value_changed",
@@ -165,7 +145,7 @@ void wxSpinCtrl::SetValue( const wxString& value )
     else
     {
         // invalid number - set text as is (wxMSW compatible)
-        gtk_entry_set_text( GTK_ENTRY(m_widget), value.c_str() );
+        gtk_entry_set_text( GTK_ENTRY(m_widget), value.mbc_str() );
     }
 }
 
@@ -199,12 +179,33 @@ void wxSpinCtrl::SetRange(int minVal, int maxVal)
     m_adjust->upper = fmax;
 
     gtk_signal_emit_by_name( GTK_OBJECT(m_adjust), "changed" );
-    
+
     // these two calls are required due to some bug in GTK
     Refresh();
     SetFocus();
 }
 
+void wxSpinCtrl::OnChar( wxKeyEvent &event )
+{
+    wxCHECK_RET( m_widget != NULL, wxT("invalid spin ctrl") );
+
+    if (event.KeyCode() == WXK_RETURN)
+    {
+        wxWindow *top_frame = m_parent;
+        while (top_frame->GetParent() && !(top_frame->GetParent()->m_isFrame))
+            top_frame = top_frame->GetParent();
+       GtkWindow *window = GTK_WINDOW(top_frame->m_widget);
+
+       if (window->default_widget)
+        {
+            gtk_widget_activate (window->default_widget);
+           return;
+       }
+    }
+
+    event.Skip();
+}
+
 bool wxSpinCtrl::IsOwnGtkWindow( GdkWindow *window )
 {
     return GTK_SPIN_BUTTON(m_widget)->panel == window;
@@ -217,3 +218,4 @@ void wxSpinCtrl::ApplyWidgetStyle()
 }
 
 #endif
+   // wxUSE_SPINCTRL