]> git.saurik.com Git - wxWidgets.git/commitdiff
Added wxCommandEvent::IsSeection for listbox,
authorRobert Roebling <robert@roebling.de>
Sat, 16 Dec 2000 10:02:47 +0000 (10:02 +0000)
committerRobert Roebling <robert@roebling.de>
Sat, 16 Dec 2000 10:02:47 +0000 (10:02 +0000)
  Applied patch for wxListBox::Set when sorting
  Added new value rounding code (corrected for
    negative values) to scrollbar and slider
  Added ...TEXT_CHANGED event to wxSpinCtrl

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

src/common/image.cpp
src/gtk/dcclient.cpp
src/gtk/listbox.cpp
src/gtk/scrolbar.cpp
src/gtk/slider.cpp
src/gtk/spinctrl.cpp
src/gtk1/dcclient.cpp
src/gtk1/listbox.cpp
src/gtk1/scrolbar.cpp
src/gtk1/slider.cpp
src/gtk1/spinctrl.cpp

index 903defa811ebbf5dd557d4fa389b387fd7a1b6e5..893eed643f6ac72b48a94daac5c4e68a84f69158 100644 (file)
@@ -1948,7 +1948,7 @@ wxImage::wxImage( const wxBitmap &bitmap )
     }
 
     wxCHECK_RET( gdk_image, wxT("couldn't create image") );
-
+    
     Create( bitmap.GetWidth(), bitmap.GetHeight() );
     char unsigned *data = GetData();
 
index 588fbb5501ddae3a84d37644a09eea86600fdc0e..740f2b06da991027228ce8b1e9e14a5eee459ffe 100644 (file)
@@ -415,6 +415,7 @@ bool wxWindowDC::DoGetPixel( wxCoord x1, wxCoord y1, wxColour *col ) const
     memdc.SelectObject(bitmap);
     memdc.Blit(0, 0, 1, 1, (wxDC*) this, x1, y1);
     memdc.SelectObject(wxNullBitmap);
+    
     wxImage image(bitmap);
     col->Set(image.GetRed(0, 0), image.GetGreen(0, 0), image.GetBlue(0, 0));
     return TRUE;
index 14dd4558ae7192a79026197b879cdd35a3d19e5c..de705e5ce37ca6ddd5ae1d27fdc846d09ace4023 100644 (file)
@@ -251,14 +251,19 @@ gtk_listbox_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxLis
 // "select" and "deselect"
 //-----------------------------------------------------------------------------
 
-static void gtk_listitem_select_callback( GtkWidget *WXUNUSED(widget), wxListBox *listbox );
+static void gtk_listitem_select_cb( GtkWidget *widget, wxListBox *listbox, bool is_selection );
+
+static void gtk_listitem_select_callback( GtkWidget *widget, wxListBox *listbox )
+{
+    gtk_listitem_select_cb( widget, listbox, TRUE );
+}
 
 static void gtk_listitem_deselect_callback( GtkWidget *widget, wxListBox *listbox )
 {
-    gtk_listitem_select_callback( widget, listbox );
+    gtk_listitem_select_cb( widget, listbox, FALSE );
 }
 
-static void gtk_listitem_select_callback( GtkWidget *WXUNUSED(widget), wxListBox *listbox )
+static void gtk_listitem_select_cb( GtkWidget *WXUNUSED(widget), wxListBox *listbox, bool is_selection )
 {
     if (g_isIdle) wxapp_install_idle_handler();
 
@@ -267,6 +272,7 @@ static void gtk_listitem_select_callback( GtkWidget *WXUNUSED(widget), wxListBox
 
     wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, listbox->GetId() );
     event.SetEventObject( listbox );
+    event.SetExtraLong( (long) is_selection );
 
     wxArrayInt aSelections;
     int n, count = listbox->GetSelections(aSelections);
@@ -430,24 +436,47 @@ void wxListBox::DoInsertItems(const wxArrayString& items, int pos)
     wxCHECK_RET( pos <= length, wxT("invalid index in wxListBox::InsertItems") );
 
     size_t nItems = items.GetCount();
+    int index;
 
-    if (pos == length)
+    if (m_strings)
     {
-        for ( size_t n = 0; n < nItems; n++ )
+        for (size_t n = 0; n < nItems; n++)
         {
-            GtkAddItem( items[n] );
-
-            m_clientList.Append((wxObject *)NULL);
+            index = m_strings->Add( items[n] );
+            
+            if (index != GetCount())
+            {
+                GtkAddItem( items[n], index );
+                wxNode *node = m_clientList.Nth( index );
+                m_clientList.Insert( node, (wxObject*) NULL );
+            }
+            else
+            {
+                GtkAddItem( items[n] );
+                m_clientList.Append( (wxObject*) NULL );
+            }
         }
     }
     else
     {
-        wxNode *node = m_clientList.Nth( pos );
-        for ( size_t n = 0; n < nItems; n++ )
+        if (pos == length)
+        {
+            for ( size_t n = 0; n < nItems; n++ )
+            {
+                GtkAddItem( items[n] );
+
+                m_clientList.Append((wxObject *)NULL);
+            }
+        }
+        else
         {
-            GtkAddItem( items[n], pos+n );
+            wxNode *node = m_clientList.Nth( pos );
+            for ( size_t n = 0; n < nItems; n++ )
+            {
+                GtkAddItem( items[n], pos+n );
 
-            m_clientList.Insert( node, (wxObject *)NULL );
+                m_clientList.Insert( node, (wxObject *)NULL );
+            }
         }
     }
 
index 5b03e147032879abe255e3964ae01946c7b88b6e..a235fa0e73ca8ee960dc4d0858a761ccb2b3c7da 100644 (file)
@@ -63,7 +63,8 @@ static void gtk_scrollbar_callback( GtkAdjustment *adjust, wxScrollBar *win )
     else if (range->scroll_type == GTK_SCROLL_PAGE_BACKWARD) command = wxEVT_SCROLL_PAGEUP;
     else if (range->scroll_type == GTK_SCROLL_PAGE_FORWARD)  command = wxEVT_SCROLL_PAGEDOWN;
     
-    int value = (int)ceil(adjust->value);
+    double dvalue = adjust->value;
+    int value = (int)(dvalue >= 0 ? dvalue - 0.5 : dvalue + 0.5);
       
     int orient = win->HasFlag(wxSB_VERTICAL) ? wxVERTICAL : wxHORIZONTAL;
   
@@ -129,7 +130,7 @@ static gint gtk_scrollbar_button_release_callback( GtkRange *WXUNUSED(widget),
 
 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar,wxControl)
 
-wxScrollBar::~wxScrollBar(void)
+wxScrollBar::~wxScrollBar()
 {
 }
 
@@ -144,7 +145,7 @@ bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
         !CreateBase( parent, id, pos, size, style, validator, name ))
     {
         wxFAIL_MSG( wxT("wxScrollBar creation failed") );
-       return FALSE;
+        return FALSE;
     }
 
     m_oldPos = 0.0;
@@ -182,9 +183,10 @@ bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
     return TRUE;
 }
 
-int wxScrollBar::GetThumbPosition(void) const
+int wxScrollBar::GetThumbPosition() const
 {
-    return (int)(m_adjust->value+0.5);
+    double val = m_adjust->value;
+    return (int)(val >= 0 ? val - 0.5 : val + 0.5);
 }
 
 int wxScrollBar::GetThumbSize() const
@@ -252,7 +254,7 @@ void wxScrollBar::SetScrollbar( int position, int thumbSize, int range, int page
 }
 
 /* Backward compatibility */
-int wxScrollBar::GetValue(void) const
+int wxScrollBar::GetValue() const
 {
     return GetThumbPosition();
 }
index 58aa39db8193429e5844070da999d97ba0226394..6ad996cbfc91828558d9881f03e824d3973f1014 100644 (file)
@@ -61,7 +61,8 @@ static void gtk_slider_callback( GtkAdjustment *adjust, wxSlider *win )
     else if (range->scroll_type == GTK_SCROLL_PAGE_BACKWARD) command = wxEVT_SCROLL_PAGEUP;
     else if (range->scroll_type == GTK_SCROLL_PAGE_FORWARD)  command = wxEVT_SCROLL_PAGEDOWN;
 
-    int value = (int)ceil(adjust->value);
+    double dvalue = adjust->value;
+    int value = (int)(dvalue >= 0 ? dvalue - 0.5 : dvalue + 0.5);
 
     int orient = wxHORIZONTAL;
     if ( (win->GetWindowStyleFlag() & wxSB_VERTICAL) == wxSB_VERTICAL)
index db68c07d703098e78441398aa36108ad5387714e..d31372ed9b72121b470cd458a4c2de71d0bbf102 100644 (file)
@@ -55,6 +55,24 @@ static void gtk_spinctrl_callback( GtkWidget *WXUNUSED(widget), wxSpinCtrl *win
     win->GetEventHandler()->ProcessEvent( event );
 }
 
+//-----------------------------------------------------------------------------
+//  "changed"
+//-----------------------------------------------------------------------------
+
+static void
+gtk_spinctrl_text_changed_callback( GtkWidget *WXUNUSED(widget), wxSpinCtrl *win )
+{
+    if (!win->m_hasVMT) return;
+
+    if (g_isIdle)
+        wxapp_install_idle_handler();
+
+    wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->GetId() );
+    event.SetEventObject( win );
+    event.SetInt( win->GetValue() );
+    win->GetEventHandler()->ProcessEvent( event );
+}
+
 //-----------------------------------------------------------------------------
 // wxSpinCtrl
 //-----------------------------------------------------------------------------
@@ -125,6 +143,9 @@ void wxSpinCtrl::GtkDisableEvents()
                         GTK_SIGNAL_FUNC(gtk_spinctrl_callback),
                         (gpointer) this );
 
+    gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
+                        GTK_SIGNAL_FUNC(gtk_spinctrl_text_changed_callback),
+                        (gpointer) this );
 }
 
 void wxSpinCtrl::GtkEnableEvents()
@@ -133,6 +154,11 @@ void wxSpinCtrl::GtkEnableEvents()
                         "value_changed",
                         GTK_SIGNAL_FUNC(gtk_spinctrl_callback),
                         (gpointer) this );
+    
+    gtk_signal_connect( GTK_OBJECT(m_widget),
+                        "changed",
+                        GTK_SIGNAL_FUNC(gtk_spinctrl_text_changed_callback),
+                        (gpointer)this);
 }
 
 int wxSpinCtrl::GetMin() const
index 588fbb5501ddae3a84d37644a09eea86600fdc0e..740f2b06da991027228ce8b1e9e14a5eee459ffe 100644 (file)
@@ -415,6 +415,7 @@ bool wxWindowDC::DoGetPixel( wxCoord x1, wxCoord y1, wxColour *col ) const
     memdc.SelectObject(bitmap);
     memdc.Blit(0, 0, 1, 1, (wxDC*) this, x1, y1);
     memdc.SelectObject(wxNullBitmap);
+    
     wxImage image(bitmap);
     col->Set(image.GetRed(0, 0), image.GetGreen(0, 0), image.GetBlue(0, 0));
     return TRUE;
index 14dd4558ae7192a79026197b879cdd35a3d19e5c..de705e5ce37ca6ddd5ae1d27fdc846d09ace4023 100644 (file)
@@ -251,14 +251,19 @@ gtk_listbox_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxLis
 // "select" and "deselect"
 //-----------------------------------------------------------------------------
 
-static void gtk_listitem_select_callback( GtkWidget *WXUNUSED(widget), wxListBox *listbox );
+static void gtk_listitem_select_cb( GtkWidget *widget, wxListBox *listbox, bool is_selection );
+
+static void gtk_listitem_select_callback( GtkWidget *widget, wxListBox *listbox )
+{
+    gtk_listitem_select_cb( widget, listbox, TRUE );
+}
 
 static void gtk_listitem_deselect_callback( GtkWidget *widget, wxListBox *listbox )
 {
-    gtk_listitem_select_callback( widget, listbox );
+    gtk_listitem_select_cb( widget, listbox, FALSE );
 }
 
-static void gtk_listitem_select_callback( GtkWidget *WXUNUSED(widget), wxListBox *listbox )
+static void gtk_listitem_select_cb( GtkWidget *WXUNUSED(widget), wxListBox *listbox, bool is_selection )
 {
     if (g_isIdle) wxapp_install_idle_handler();
 
@@ -267,6 +272,7 @@ static void gtk_listitem_select_callback( GtkWidget *WXUNUSED(widget), wxListBox
 
     wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, listbox->GetId() );
     event.SetEventObject( listbox );
+    event.SetExtraLong( (long) is_selection );
 
     wxArrayInt aSelections;
     int n, count = listbox->GetSelections(aSelections);
@@ -430,24 +436,47 @@ void wxListBox::DoInsertItems(const wxArrayString& items, int pos)
     wxCHECK_RET( pos <= length, wxT("invalid index in wxListBox::InsertItems") );
 
     size_t nItems = items.GetCount();
+    int index;
 
-    if (pos == length)
+    if (m_strings)
     {
-        for ( size_t n = 0; n < nItems; n++ )
+        for (size_t n = 0; n < nItems; n++)
         {
-            GtkAddItem( items[n] );
-
-            m_clientList.Append((wxObject *)NULL);
+            index = m_strings->Add( items[n] );
+            
+            if (index != GetCount())
+            {
+                GtkAddItem( items[n], index );
+                wxNode *node = m_clientList.Nth( index );
+                m_clientList.Insert( node, (wxObject*) NULL );
+            }
+            else
+            {
+                GtkAddItem( items[n] );
+                m_clientList.Append( (wxObject*) NULL );
+            }
         }
     }
     else
     {
-        wxNode *node = m_clientList.Nth( pos );
-        for ( size_t n = 0; n < nItems; n++ )
+        if (pos == length)
+        {
+            for ( size_t n = 0; n < nItems; n++ )
+            {
+                GtkAddItem( items[n] );
+
+                m_clientList.Append((wxObject *)NULL);
+            }
+        }
+        else
         {
-            GtkAddItem( items[n], pos+n );
+            wxNode *node = m_clientList.Nth( pos );
+            for ( size_t n = 0; n < nItems; n++ )
+            {
+                GtkAddItem( items[n], pos+n );
 
-            m_clientList.Insert( node, (wxObject *)NULL );
+                m_clientList.Insert( node, (wxObject *)NULL );
+            }
         }
     }
 
index 5b03e147032879abe255e3964ae01946c7b88b6e..a235fa0e73ca8ee960dc4d0858a761ccb2b3c7da 100644 (file)
@@ -63,7 +63,8 @@ static void gtk_scrollbar_callback( GtkAdjustment *adjust, wxScrollBar *win )
     else if (range->scroll_type == GTK_SCROLL_PAGE_BACKWARD) command = wxEVT_SCROLL_PAGEUP;
     else if (range->scroll_type == GTK_SCROLL_PAGE_FORWARD)  command = wxEVT_SCROLL_PAGEDOWN;
     
-    int value = (int)ceil(adjust->value);
+    double dvalue = adjust->value;
+    int value = (int)(dvalue >= 0 ? dvalue - 0.5 : dvalue + 0.5);
       
     int orient = win->HasFlag(wxSB_VERTICAL) ? wxVERTICAL : wxHORIZONTAL;
   
@@ -129,7 +130,7 @@ static gint gtk_scrollbar_button_release_callback( GtkRange *WXUNUSED(widget),
 
 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar,wxControl)
 
-wxScrollBar::~wxScrollBar(void)
+wxScrollBar::~wxScrollBar()
 {
 }
 
@@ -144,7 +145,7 @@ bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
         !CreateBase( parent, id, pos, size, style, validator, name ))
     {
         wxFAIL_MSG( wxT("wxScrollBar creation failed") );
-       return FALSE;
+        return FALSE;
     }
 
     m_oldPos = 0.0;
@@ -182,9 +183,10 @@ bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
     return TRUE;
 }
 
-int wxScrollBar::GetThumbPosition(void) const
+int wxScrollBar::GetThumbPosition() const
 {
-    return (int)(m_adjust->value+0.5);
+    double val = m_adjust->value;
+    return (int)(val >= 0 ? val - 0.5 : val + 0.5);
 }
 
 int wxScrollBar::GetThumbSize() const
@@ -252,7 +254,7 @@ void wxScrollBar::SetScrollbar( int position, int thumbSize, int range, int page
 }
 
 /* Backward compatibility */
-int wxScrollBar::GetValue(void) const
+int wxScrollBar::GetValue() const
 {
     return GetThumbPosition();
 }
index 58aa39db8193429e5844070da999d97ba0226394..6ad996cbfc91828558d9881f03e824d3973f1014 100644 (file)
@@ -61,7 +61,8 @@ static void gtk_slider_callback( GtkAdjustment *adjust, wxSlider *win )
     else if (range->scroll_type == GTK_SCROLL_PAGE_BACKWARD) command = wxEVT_SCROLL_PAGEUP;
     else if (range->scroll_type == GTK_SCROLL_PAGE_FORWARD)  command = wxEVT_SCROLL_PAGEDOWN;
 
-    int value = (int)ceil(adjust->value);
+    double dvalue = adjust->value;
+    int value = (int)(dvalue >= 0 ? dvalue - 0.5 : dvalue + 0.5);
 
     int orient = wxHORIZONTAL;
     if ( (win->GetWindowStyleFlag() & wxSB_VERTICAL) == wxSB_VERTICAL)
index db68c07d703098e78441398aa36108ad5387714e..d31372ed9b72121b470cd458a4c2de71d0bbf102 100644 (file)
@@ -55,6 +55,24 @@ static void gtk_spinctrl_callback( GtkWidget *WXUNUSED(widget), wxSpinCtrl *win
     win->GetEventHandler()->ProcessEvent( event );
 }
 
+//-----------------------------------------------------------------------------
+//  "changed"
+//-----------------------------------------------------------------------------
+
+static void
+gtk_spinctrl_text_changed_callback( GtkWidget *WXUNUSED(widget), wxSpinCtrl *win )
+{
+    if (!win->m_hasVMT) return;
+
+    if (g_isIdle)
+        wxapp_install_idle_handler();
+
+    wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->GetId() );
+    event.SetEventObject( win );
+    event.SetInt( win->GetValue() );
+    win->GetEventHandler()->ProcessEvent( event );
+}
+
 //-----------------------------------------------------------------------------
 // wxSpinCtrl
 //-----------------------------------------------------------------------------
@@ -125,6 +143,9 @@ void wxSpinCtrl::GtkDisableEvents()
                         GTK_SIGNAL_FUNC(gtk_spinctrl_callback),
                         (gpointer) this );
 
+    gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
+                        GTK_SIGNAL_FUNC(gtk_spinctrl_text_changed_callback),
+                        (gpointer) this );
 }
 
 void wxSpinCtrl::GtkEnableEvents()
@@ -133,6 +154,11 @@ void wxSpinCtrl::GtkEnableEvents()
                         "value_changed",
                         GTK_SIGNAL_FUNC(gtk_spinctrl_callback),
                         (gpointer) this );
+    
+    gtk_signal_connect( GTK_OBJECT(m_widget),
+                        "changed",
+                        GTK_SIGNAL_FUNC(gtk_spinctrl_text_changed_callback),
+                        (gpointer)this);
 }
 
 int wxSpinCtrl::GetMin() const