X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7a30ee8f2c5e90a26415132033a98b82ac9af5b4..fd128b0c3ab84380d782e45bfa98f181a848df27:/src/gtk1/listbox.cpp diff --git a/src/gtk1/listbox.cpp b/src/gtk1/listbox.cpp index dc0d32c66b..0b62dcb261 100644 --- a/src/gtk1/listbox.cpp +++ b/src/gtk1/listbox.cpp @@ -12,8 +12,11 @@ #pragma implementation "listbox.h" #endif -#include "wx/dynarray.h" #include "wx/listbox.h" + +#if wxUSE_LISTBOX + +#include "wx/dynarray.h" #include "wx/utils.h" #include "wx/intl.h" #include "wx/checklst.h" @@ -42,13 +45,15 @@ extern bool g_isIdle; //------------------------------------------------------------------------- #if (GTK_MINOR_VERSION > 0) -#define NEW_GTK_SCROLL_CODE + #define NEW_GTK_SCROLL_CODE #endif //----------------------------------------------------------------------------- // private functions //----------------------------------------------------------------------------- +#if wxUSE_CHECKLISTBOX + #define CHECKBOX_STRING "[-] " // checklistboxes have "[±] " prepended to their lables, this macro removes it @@ -57,6 +62,12 @@ extern bool g_isIdle; // the argument to it is a "const char *" pointer #define GET_REAL_LABEL(label) ((m_hasCheckBoxes)?(label)+4 : (label)) +#else // !wxUSE_CHECKLISTBOX + +#define GET_REAL_LABEL(label) (label) + +#endif // wxUSE_CHECKLISTBOX + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -127,6 +138,7 @@ gtk_listbox_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, int sel = listbox->GetIndex( widget ); +#if wxUSE_CHECKLISTBOX if ((listbox->m_hasCheckBoxes) && (gdk_event->x < 15) && (gdk_event->type != GDK_2BUTTON_PRESS)) { wxCheckListBox *clb = (wxCheckListBox *)listbox; @@ -138,6 +150,7 @@ gtk_listbox_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, event.SetInt( sel ); listbox->GetEventHandler()->ProcessEvent( event ); } +#endif // wxUSE_CHECKLISTBOX /* emit wxEVT_COMMAND_LISTBOX_DOUBLECLICKED later */ g_hasDoubleClicked = (gdk_event->type == GDK_2BUTTON_PRESS); @@ -149,6 +162,7 @@ gtk_listbox_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, // "key_press_event" //----------------------------------------------------------------------------- +#if wxUSE_CHECKLISTBOX static gint gtk_listbox_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxListBox *listbox ) { @@ -173,6 +187,7 @@ gtk_listbox_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxLis return FALSE; } +#endif // wxUSE_CHECKLISTBOX //----------------------------------------------------------------------------- // "select" and "deselect" @@ -216,7 +231,9 @@ IMPLEMENT_DYNAMIC_CLASS(wxListBox,wxControl) wxListBox::wxListBox() { m_list = (GtkList *) NULL; +#if wxUSE_CHECKLISTBOX m_hasCheckBoxes = FALSE; +#endif // wxUSE_CHECKLISTBOX } bool wxListBox::Create( wxWindow *parent, wxWindowID id, @@ -229,7 +246,9 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, PreCreation( parent, id, pos, size, style, name ); +#if wxUSE_VALIDATORS SetValidator( validator ); +#endif m_widget = gtk_scrolled_window_new( (GtkAdjustment*) NULL, (GtkAdjustment*) NULL ); if (style & wxLB_ALWAYS_SB) @@ -274,10 +293,12 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, GtkWidget *list_item; wxString str(choices[i]); +#if wxUSE_CHECKLISTBOX if (m_hasCheckBoxes) { str.Prepend(CHECKBOX_STRING); } +#endif // wxUSE_CHECKLISTBOX list_item = gtk_list_item_new_with_label( str.mbc_str() ); @@ -300,6 +321,7 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, (GtkSignalFunc)gtk_listbox_button_release_callback, (gpointer) this ); +#if wxUSE_CHECKLISTBOX if (m_hasCheckBoxes) { gtk_signal_connect( GTK_OBJECT(list_item), @@ -307,6 +329,7 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, (GtkSignalFunc)gtk_listbox_key_press_callback, (gpointer)this ); } +#endif // wxUSE_CHECKLISTBOX ConnectWidget( list_item ); @@ -369,7 +392,7 @@ void wxListBox::InsertItems(int nItems, const wxString items[], int pos) GtkBin *bin = GTK_BIN( child->data ); GtkLabel *label = GTK_LABEL( bin->child ); - wxString str(GET_REAL_LABEL(label->label)); + wxString str(GET_REAL_LABEL(label->label),*wxConvCurrent); deletedLabels.Add(str); // save data @@ -399,11 +422,13 @@ void wxListBox::InsertItems(int nItems, const wxString items[], int pos) deletedData.Add(clientData); +#if wxUSE_CHECKLISTBOX // save check state if ( m_hasCheckBoxes ) { deletedChecks.Add(((wxCheckListBox *)this)->IsChecked(pos + n)); } +#endif // wxUSE_CHECKLISTBOX } int nDeletedCount = n; @@ -422,10 +447,12 @@ void wxListBox::InsertItems(int nItems, const wxString items[], int pos) { Append(deletedLabels[n], deletedData[n]); +#if wxUSE_CHECKLISTBOX if ( m_hasCheckBoxes ) { ((wxCheckListBox *)this)->Check(pos + n, (bool)deletedChecks[n]); } +#endif // wxUSE_CHECKLISTBOX } } @@ -436,10 +463,12 @@ void wxListBox::AppendCommon( const wxString &item ) GtkWidget *list_item; wxString label(item); +#if wxUSE_CHECKLISTBOX if (m_hasCheckBoxes) { label.Prepend(CHECKBOX_STRING); } +#endif // wxUSE_CHECKLISTBOX list_item = gtk_list_item_new_with_label( label.mbc_str() ); @@ -457,6 +486,12 @@ void wxListBox::AppendCommon( const wxString &item ) (GtkSignalFunc)gtk_listbox_button_press_callback, (gpointer) this ); + gtk_signal_connect_after( GTK_OBJECT(list_item), + "button_release_event", + (GtkSignalFunc)gtk_listbox_button_release_callback, + (gpointer) this ); + +#if wxUSE_CHECKLISTBOX if (m_hasCheckBoxes) { gtk_signal_connect( GTK_OBJECT(list_item), @@ -464,6 +499,7 @@ void wxListBox::AppendCommon( const wxString &item ) (GtkSignalFunc)gtk_listbox_key_press_callback, (gpointer)this ); } +#endif // wxUSE_CHECKLISTBOX gtk_widget_show( list_item ); @@ -604,7 +640,11 @@ void wxListBox::Deselect( int n ) { wxCHECK_RET( m_list != NULL, _T("invalid listbox") ); + DisableEvents(); + gtk_list_unselect_item( m_list, n ); + + EnableEvents(); } int wxListBox::FindString( const wxString &item ) const @@ -618,7 +658,7 @@ int wxListBox::FindString( const wxString &item ) const GtkBin *bin = GTK_BIN( child->data ); GtkLabel *label = GTK_LABEL( bin->child ); - wxString str = GET_REAL_LABEL(label->label); + wxString str = wxString(GET_REAL_LABEL(label->label),*wxConvCurrent); if (str == item) return count; @@ -687,7 +727,7 @@ wxString wxListBox::GetString( int n ) const GtkBin *bin = GTK_BIN( child->data ); GtkLabel *label = GTK_LABEL( bin->child ); - wxString str = GET_REAL_LABEL(label->label); + wxString str = wxString(GET_REAL_LABEL(label->label),*wxConvCurrent); return str; } @@ -707,7 +747,7 @@ wxString wxListBox::GetStringSelection() const GtkBin *bin = GTK_BIN( selection->data ); GtkLabel *label = GTK_LABEL( bin->child ); - wxString str = GET_REAL_LABEL(label->label); + wxString str = wxString(GET_REAL_LABEL(label->label),*wxConvCurrent); return str; } @@ -763,10 +803,14 @@ void wxListBox::SetSelection( int n, bool select ) { wxCHECK_RET( m_list != NULL, _T("invalid listbox") ); + DisableEvents(); + if (select) gtk_list_select_item( m_list, n ); else gtk_list_unselect_item( m_list, n ); + + EnableEvents(); } void wxListBox::SetString( int n, const wxString &string ) @@ -780,8 +824,10 @@ void wxListBox::SetString( int n, const wxString &string ) GtkLabel *label = GTK_LABEL( bin->child ); wxString str; +#if wxUSE_CHECKLISTBOX if (m_hasCheckBoxes) str += CHECKBOX_STRING; +#endif // wxUSE_CHECKLISTBOX str += string; gtk_label_set( label, str.mbc_str() ); @@ -821,7 +867,7 @@ void wxListBox::ApplyToolTip( GtkTooltips *tips, const wxChar *tip ) GList *child = m_list->children; while (child) { - gtk_tooltips_set_tip( tips, GTK_WIDGET( child->data ), wxConv_local.cWX2MB(tip), (gchar*) NULL ); + gtk_tooltips_set_tip( tips, GTK_WIDGET( child->data ), wxConvCurrent->cWX2MB(tip), (gchar*) NULL ); child = child->next; } } @@ -860,6 +906,38 @@ void wxListBox::SetDropTarget( wxDropTarget *dropTarget ) } #endif +void wxListBox::DisableEvents() +{ + GList *child = m_list->children; + while (child) + { + gtk_signal_disconnect_by_func( GTK_OBJECT(child->data), + GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this ); + + if (HasFlag(wxLB_MULTIPLE)) + gtk_signal_disconnect_by_func( GTK_OBJECT(child->data), + GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this ); + + child = child->next; + } +} + +void wxListBox::EnableEvents() +{ + GList *child = m_list->children; + while (child) + { + gtk_signal_connect( GTK_OBJECT(child->data), "select", + GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this ); + + if (HasFlag(wxLB_MULTIPLE)) + gtk_signal_connect( GTK_OBJECT(child->data), "deselect", + GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this ); + + child = child->next; + } +} + GtkWidget *wxListBox::GetConnectWidget() { return GTK_WIDGET(m_list); @@ -907,3 +985,5 @@ void wxListBox::ApplyWidgetStyle() child = child->next; } } + +#endif \ No newline at end of file