From caaa4cfd6779b689d6723e06df23cc23d1799fd3 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Tue, 15 Dec 1998 14:14:51 +0000 Subject: [PATCH] Added wxCheckLitBox (oh well) Minor optical fixes to gridg git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1200 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/checklst.h | 55 +++++++++++++++++ include/wx/gtk/choice.h | 1 - include/wx/gtk/listbox.h | 6 +- include/wx/gtk1/checklst.h | 55 +++++++++++++++++ include/wx/gtk1/choice.h | 1 - include/wx/gtk1/listbox.h | 6 +- samples/controls/controls.cpp | 12 +++- src/generic/gridg.cpp | 13 +++- src/gtk.inc | 1 + src/gtk/checklst.cpp | 85 ++++++++++++++++++++++++++ src/gtk/listbox.cpp | 112 +++++++++++++++++++++++++++++----- src/gtk1/checklst.cpp | 85 ++++++++++++++++++++++++++ src/gtk1/listbox.cpp | 112 +++++++++++++++++++++++++++++----- 13 files changed, 505 insertions(+), 39 deletions(-) create mode 100644 include/wx/gtk/checklst.h create mode 100644 include/wx/gtk1/checklst.h create mode 100644 src/gtk/checklst.cpp create mode 100644 src/gtk1/checklst.cpp diff --git a/include/wx/gtk/checklst.h b/include/wx/gtk/checklst.h new file mode 100644 index 0000000000..48cb62cf76 --- /dev/null +++ b/include/wx/gtk/checklst.h @@ -0,0 +1,55 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: checklst.h +// Purpose: wxCheckListBox class +// Author: Robert Roebling +// Modified by: +// RCS-ID: $Id$ +// Copyright: (c) 1998 Robert Roebling +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#ifndef __GTKCHECKLISTH__ +#define __GTKCHECKLISTH__ + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "wx/defs.h" +#include "wx/object.h" +#include "wx/list.h" +#include "wx/control.h" +#include "wx/listbox.h" + +//----------------------------------------------------------------------------- +// classes +//----------------------------------------------------------------------------- + +class wxCheckListBox; + +//----------------------------------------------------------------------------- +// wxCheckListBox +//----------------------------------------------------------------------------- + +class wxCheckListBox : public wxListBox +{ + DECLARE_DYNAMIC_CLASS(wxCheckListBox) +public: + + wxCheckListBox(); + wxCheckListBox(wxWindow *parent, wxWindowID id, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + int nStrings = 0, + const wxString choices[] = NULL, + long style = 0, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxListBoxNameStr); + + bool IsChecked( int index ) const; + void Check( int index, bool check = TRUE ); + +}; + +#endif + //__GTKCHECKLISTH__ diff --git a/include/wx/gtk/choice.h b/include/wx/gtk/choice.h index 2dc5110aeb..393c9e8861 100644 --- a/include/wx/gtk/choice.h +++ b/include/wx/gtk/choice.h @@ -7,7 +7,6 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// - #ifndef __GTKCHOICEH__ #define __GTKCHOICEH__ diff --git a/include/wx/gtk/listbox.h b/include/wx/gtk/listbox.h index 2a062629b6..badca50a2c 100644 --- a/include/wx/gtk/listbox.h +++ b/include/wx/gtk/listbox.h @@ -52,6 +52,7 @@ public: const wxValidator& validator = wxDefaultValidator, const wxString& name = wxListBoxNameStr ) { + m_hasCheckBoxes = FALSE; Create(parent, id, pos, size, n, choices, style, validator, name); } ~wxListBox(); @@ -101,8 +102,9 @@ public: void ApplyWidgetStyle(); GtkList *m_list; - wxList m_clientDataList; - wxList m_clientObjectList; + wxList m_clientDataList; + wxList m_clientObjectList; + bool m_hasCheckBoxes; }; #endif // __GTKLISTBOXH__ diff --git a/include/wx/gtk1/checklst.h b/include/wx/gtk1/checklst.h new file mode 100644 index 0000000000..48cb62cf76 --- /dev/null +++ b/include/wx/gtk1/checklst.h @@ -0,0 +1,55 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: checklst.h +// Purpose: wxCheckListBox class +// Author: Robert Roebling +// Modified by: +// RCS-ID: $Id$ +// Copyright: (c) 1998 Robert Roebling +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#ifndef __GTKCHECKLISTH__ +#define __GTKCHECKLISTH__ + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "wx/defs.h" +#include "wx/object.h" +#include "wx/list.h" +#include "wx/control.h" +#include "wx/listbox.h" + +//----------------------------------------------------------------------------- +// classes +//----------------------------------------------------------------------------- + +class wxCheckListBox; + +//----------------------------------------------------------------------------- +// wxCheckListBox +//----------------------------------------------------------------------------- + +class wxCheckListBox : public wxListBox +{ + DECLARE_DYNAMIC_CLASS(wxCheckListBox) +public: + + wxCheckListBox(); + wxCheckListBox(wxWindow *parent, wxWindowID id, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + int nStrings = 0, + const wxString choices[] = NULL, + long style = 0, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxListBoxNameStr); + + bool IsChecked( int index ) const; + void Check( int index, bool check = TRUE ); + +}; + +#endif + //__GTKCHECKLISTH__ diff --git a/include/wx/gtk1/choice.h b/include/wx/gtk1/choice.h index 2dc5110aeb..393c9e8861 100644 --- a/include/wx/gtk1/choice.h +++ b/include/wx/gtk1/choice.h @@ -7,7 +7,6 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// - #ifndef __GTKCHOICEH__ #define __GTKCHOICEH__ diff --git a/include/wx/gtk1/listbox.h b/include/wx/gtk1/listbox.h index 2a062629b6..badca50a2c 100644 --- a/include/wx/gtk1/listbox.h +++ b/include/wx/gtk1/listbox.h @@ -52,6 +52,7 @@ public: const wxValidator& validator = wxDefaultValidator, const wxString& name = wxListBoxNameStr ) { + m_hasCheckBoxes = FALSE; Create(parent, id, pos, size, n, choices, style, validator, name); } ~wxListBox(); @@ -101,8 +102,9 @@ public: void ApplyWidgetStyle(); GtkList *m_list; - wxList m_clientDataList; - wxList m_clientObjectList; + wxList m_clientDataList; + wxList m_clientObjectList; + bool m_hasCheckBoxes; }; #endif // __GTKLISTBOXH__ diff --git a/samples/controls/controls.cpp b/samples/controls/controls.cpp index 04259c3c3d..a824a9a84a 100644 --- a/samples/controls/controls.cpp +++ b/samples/controls/controls.cpp @@ -27,6 +27,7 @@ #include "wx/notebook.h" #include "wx/imaglist.h" #include "wx/clipbrd.h" +#include "wx/checklst.h" // XPM doesn't seem to work under Windows at present. Or, wxNotebook images // aren't working. @@ -205,6 +206,8 @@ const int ID_SLIDER = 181; const int ID_SPIN = 182; +const int ID_CHECKLIST = 190; + BEGIN_EVENT_TABLE(MyPanel, wxPanel) EVT_SIZE ( MyPanel::OnSize) @@ -402,8 +405,15 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) : m_spinbutton = new wxSpinButton( panel, ID_SPIN, wxPoint(103,159), wxSize(-1,-1) ); // m_spinbutton->SetBackgroundColour("wheat"); m_spinbutton->SetRange(0,100); - m_notebook->AddPage(panel, "wxGauge", FALSE, Image_Gauge); + + panel = new wxPanel(m_notebook); +// panel->SetBackgroundColour("cadet blue"); +// panel->SetForegroundColour("blue"); + m_listbox = new wxCheckListBox( panel, ID_CHECKLIST, wxPoint(10,10), wxSize(160,70), 5, choices ); +// m_listbox->SetBackgroundColour("wheat"); + button = new wxButton( panel, ID_LISTBOX_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) ); + m_notebook->AddPage(panel, "wxCheckListBox", FALSE, Image_List); } void MyPanel::OnPasteFromClipboard( wxCommandEvent &WXUNUSED(event) ) diff --git a/src/generic/gridg.cpp b/src/generic/gridg.cpp index 6184648dc6..84b4b4546f 100644 --- a/src/generic/gridg.cpp +++ b/src/generic/gridg.cpp @@ -88,6 +88,8 @@ wxGenericGrid::wxGenericGrid(void) m_editable = TRUE; #if defined(__WIN95__) m_scrollWidth = wxSystemSettings::GetSystemMetric(wxSYS_VSCROLL_X); +#elseif defined(__WXGTK__) + m_scrollWidth = wxSystemSettings::GetSystemMetric(wxSYS_VSCROLL_X); #else m_scrollWidth = 16; #endif @@ -144,6 +146,8 @@ bool wxGenericGrid::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, m_editable = TRUE; #if defined(__WIN95__) m_scrollWidth = wxSystemSettings::GetSystemMetric(wxSYS_VSCROLL_X); +#elseif defined(__WXGTK__) + m_scrollWidth = wxSystemSettings::GetSystemMetric(wxSYS_VSCROLL_X); #else m_scrollWidth = 16; #endif @@ -1025,8 +1029,13 @@ void wxGenericGrid::AdjustScrollbars(void) int nCols = GetCols(); m_hScrollBar->SetScrollbar(m_hScrollBar->GetThumbPosition(), wxMax(noHorizSteps, 1), (noHorizSteps == 0) ? 1 : nCols, wxMax(noHorizSteps, 1)); - m_hScrollBar->SetSize(m_leftOfSheet, ch - m_scrollWidth -2, +/* + m_hScrollBar->SetSize(m_leftOfSheet, ch - m_scrollWidth -2, // why -2 ? Robert. cw - vertScrollBarWidth - m_leftOfSheet, m_scrollWidth); +*/ + m_hScrollBar->SetSize(m_leftOfSheet, ch - m_scrollWidth, + cw - vertScrollBarWidth - m_leftOfSheet, m_scrollWidth); + } if (m_vScrollBar) @@ -1053,7 +1062,7 @@ void wxGenericGrid::OnSize(wxSizeEvent& WXUNUSED(event) ) { m_editingPanel->SetSize(0, 0, cw, m_editControlPosition.height + m_editControlPosition.y + 2); GetTextItem()->SetSize(m_editControlPosition.x, m_editControlPosition.y, - cw - m_editControlPosition.x, m_editControlPosition.height); + cw - 2*m_editControlPosition.x, m_editControlPosition.height); } } diff --git a/src/gtk.inc b/src/gtk.inc index edf6038a34..553f9239e8 100644 --- a/src/gtk.inc +++ b/src/gtk.inc @@ -73,6 +73,7 @@ LIB_CPP_SRC=\ gtk/brush.cpp \ gtk/button.cpp \ gtk/checkbox.cpp \ + gtk/checklst.cpp \ gtk/choice.cpp \ gtk/clipbrd.cpp \ gtk/colour.cpp \ diff --git a/src/gtk/checklst.cpp b/src/gtk/checklst.cpp new file mode 100644 index 0000000000..252e216983 --- /dev/null +++ b/src/gtk/checklst.cpp @@ -0,0 +1,85 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: checklst.cpp +// Purpose: +// Author: Robert Roebling +// Id: $Id$ +// Copyright: (c) 1998 Robert Roebling +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma implementation "checklst.h" +#endif + +#include "wx/checklst.h" + +//----------------------------------------------------------------------------- +// wxCheckListBox +//----------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox,wxListBox) + +wxCheckListBox::wxCheckListBox() : + wxListBox() +{ + m_hasCheckBoxes = TRUE; +} +wxCheckListBox::wxCheckListBox(wxWindow *parent, wxWindowID id, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + int nStrings = 0, + const wxString choices[] = NULL, + long style = 0, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxListBoxNameStr) +{ + m_hasCheckBoxes = TRUE; + wxListBox::Create( parent, id, pos, size, nStrings, choices, style, validator, name ); +} + +bool wxCheckListBox::IsChecked( int index ) const +{ + wxCHECK_MSG( m_list != NULL, FALSE, "invalid checklistbox" ); + + GList *child = g_list_nth( m_list->children, index ); + if (child) + { + GtkBin *bin = GTK_BIN( child->data ); + GtkLabel *label = GTK_LABEL( bin->child ); + + wxString str = label->label; + + return (str[1] == 'X'); + } + + wxFAIL_MSG("wrong checklistbox index"); + return FALSE; +} + +void wxCheckListBox::Check( int index, bool check ) +{ + wxCHECK_RET( m_list != NULL, "invalid checklistbox" ); + + GList *child = g_list_nth( m_list->children, index ); + if (child) + { + GtkBin *bin = GTK_BIN( child->data ); + GtkLabel *label = GTK_LABEL( bin->child ); + + wxString str = label->label; + + if (check == (str[1] == 'X')) return; + + if (check) + str.SetChar( 1, 'X' ); + else + str.SetChar( 1, '-' ); + + gtk_label_set( label, str ); + + return; + } + + wxFAIL_MSG("wrong checklistbox index"); +} + diff --git a/src/gtk/listbox.cpp b/src/gtk/listbox.cpp index 2793afeb92..6570cb1c40 100644 --- a/src/gtk/listbox.cpp +++ b/src/gtk/listbox.cpp @@ -15,7 +15,8 @@ #include "wx/dynarray.h" #include "wx/listbox.h" #include "wx/utils.h" -#include +#include "wx/intl.h" +#include "wx/checklst.h" //------------------------------------------------------------------------- // conditional compilation @@ -32,6 +33,30 @@ //----------------------------------------------------------------------------- extern bool g_blockEventsOnDrag; +extern bool g_blockEventsOnScroll; + +//----------------------------------------------------------------------------- +// "button_press_event" +//----------------------------------------------------------------------------- + +static gint +gtk_listbox_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxListBox *listbox ) +{ + if (g_blockEventsOnDrag) return FALSE; + if (g_blockEventsOnScroll) return FALSE; + + if (!listbox->HasVMT()) return FALSE; + + if (gdk_event->x > 15) return FALSE; + + int sel = listbox->GetIndex( widget ); + + wxCheckListBox *clb = (wxCheckListBox *)listbox; + + clb->Check( sel, !clb->IsChecked(sel) ); + + return FALSE; +} //----------------------------------------------------------------------------- // "select" and "deselect" @@ -74,6 +99,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxListBox,wxControl) wxListBox::wxListBox() { m_list = (GtkList *) NULL; + m_hasCheckBoxes = FALSE; } bool wxListBox::Create( wxWindow *parent, wxWindowID id, @@ -120,7 +146,17 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, m_clientObjectList.Append( (wxObject*) NULL ); GtkWidget *list_item; - list_item = gtk_list_item_new_with_label( choices[i] ); + + if (m_hasCheckBoxes) + { + wxString str = "[-] "; + str += choices[i]; + list_item = gtk_list_item_new_with_label( str ); + } + else + { + list_item = gtk_list_item_new_with_label( choices[i] ); + } gtk_container_add( GTK_CONTAINER(m_list), list_item ); @@ -131,6 +167,14 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, gtk_signal_connect( GTK_OBJECT(list_item), "deselect", GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this ); + if (m_hasCheckBoxes) + { + gtk_signal_connect( GTK_OBJECT(list_item), + "button_press_event", + (GtkSignalFunc)gtk_listbox_button_press_callback, + (gpointer) this ); + } + ConnectWidget( list_item ); gtk_widget_show( list_item ); @@ -154,14 +198,25 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, wxListBox::~wxListBox() { - Clear(); + Clear(); } void wxListBox::AppendCommon( const wxString &item ) { wxCHECK_RET( m_list != NULL, "invalid listbox" ); - GtkWidget *list_item = gtk_list_item_new_with_label( item ); + GtkWidget *list_item; + + if (m_hasCheckBoxes) + { + wxString str = "[-] "; + str += item; + list_item = gtk_list_item_new_with_label( str ); + } + else + { + list_item = gtk_list_item_new_with_label( item ); + } gtk_signal_connect( GTK_OBJECT(list_item), "select", GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this ); @@ -174,6 +229,14 @@ void wxListBox::AppendCommon( const wxString &item ) if (m_widgetStyle) ApplyWidgetStyle(); + if (m_hasCheckBoxes) + { + gtk_signal_connect( GTK_OBJECT(list_item), + "button_press_event", + (GtkSignalFunc)gtk_listbox_button_press_callback, + (gpointer) this ); + } + gtk_widget_show( list_item ); ConnectWidget( list_item ); @@ -274,11 +337,7 @@ void wxListBox::Delete( int n ) GList *child = g_list_nth( m_list->children, n ); - if (!child) - { - wxFAIL_MSG("wrong listbox index"); - return; - } + wxCHECK_RET( child, "wrong listbox index" ); GList *list = g_list_append( NULL, child->data ); gtk_list_remove_items( m_list, list ); @@ -316,7 +375,12 @@ int wxListBox::FindString( const wxString &item ) const { GtkBin *bin = GTK_BIN( child->data ); GtkLabel *label = GTK_LABEL( bin->child ); - if (item == label->label) return count; + + wxString str = label->label; + if (m_hasCheckBoxes) str.Remove( 0, 4 ); + + if (str == item) return count; + count++; child = child->next; } @@ -380,7 +444,11 @@ wxString wxListBox::GetString( int n ) const { GtkBin *bin = GTK_BIN( child->data ); GtkLabel *label = GTK_LABEL( bin->child ); - return label->label; + + wxString str = label->label; + if (m_hasCheckBoxes) str.Remove( 0, 4 ); + + return str; } wxFAIL_MSG("wrong listbox index"); return ""; @@ -394,9 +462,14 @@ wxString wxListBox::GetStringSelection() const if (selection) { GtkBin *bin = GTK_BIN( selection->data ); - wxString tmp = GTK_LABEL( bin->child )->label; - return tmp; + GtkLabel *label = GTK_LABEL( bin->child ); + + wxString str = label->label; + if (m_hasCheckBoxes) str.Remove( 0, 4 ); + + return str; } + wxFAIL_MSG("no listbox selection available"); return ""; } @@ -463,7 +536,12 @@ void wxListBox::SetString( int n, const wxString &string ) { GtkBin *bin = GTK_BIN( child->data ); GtkLabel *label = GTK_LABEL( bin->child ); - gtk_label_set( label, string ); + + wxString str; + if (m_hasCheckBoxes) str += "[-] "; + str += string; + + gtk_label_set( label, str ); } else { @@ -560,8 +638,12 @@ void wxListBox::ApplyWidgetStyle() GList *child = m_list->children; while (child) { - gtk_widget_set_style( GTK_BIN(child->data)->child, m_widgetStyle ); gtk_widget_set_style( GTK_WIDGET(child->data), m_widgetStyle ); + + GtkBin *bin = GTK_BIN( child->data ); + GtkWidget *label = GTK_WIDGET( bin->child ); + gtk_widget_set_style( label, m_widgetStyle ); + child = child->next; } } diff --git a/src/gtk1/checklst.cpp b/src/gtk1/checklst.cpp new file mode 100644 index 0000000000..252e216983 --- /dev/null +++ b/src/gtk1/checklst.cpp @@ -0,0 +1,85 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: checklst.cpp +// Purpose: +// Author: Robert Roebling +// Id: $Id$ +// Copyright: (c) 1998 Robert Roebling +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma implementation "checklst.h" +#endif + +#include "wx/checklst.h" + +//----------------------------------------------------------------------------- +// wxCheckListBox +//----------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox,wxListBox) + +wxCheckListBox::wxCheckListBox() : + wxListBox() +{ + m_hasCheckBoxes = TRUE; +} +wxCheckListBox::wxCheckListBox(wxWindow *parent, wxWindowID id, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + int nStrings = 0, + const wxString choices[] = NULL, + long style = 0, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxListBoxNameStr) +{ + m_hasCheckBoxes = TRUE; + wxListBox::Create( parent, id, pos, size, nStrings, choices, style, validator, name ); +} + +bool wxCheckListBox::IsChecked( int index ) const +{ + wxCHECK_MSG( m_list != NULL, FALSE, "invalid checklistbox" ); + + GList *child = g_list_nth( m_list->children, index ); + if (child) + { + GtkBin *bin = GTK_BIN( child->data ); + GtkLabel *label = GTK_LABEL( bin->child ); + + wxString str = label->label; + + return (str[1] == 'X'); + } + + wxFAIL_MSG("wrong checklistbox index"); + return FALSE; +} + +void wxCheckListBox::Check( int index, bool check ) +{ + wxCHECK_RET( m_list != NULL, "invalid checklistbox" ); + + GList *child = g_list_nth( m_list->children, index ); + if (child) + { + GtkBin *bin = GTK_BIN( child->data ); + GtkLabel *label = GTK_LABEL( bin->child ); + + wxString str = label->label; + + if (check == (str[1] == 'X')) return; + + if (check) + str.SetChar( 1, 'X' ); + else + str.SetChar( 1, '-' ); + + gtk_label_set( label, str ); + + return; + } + + wxFAIL_MSG("wrong checklistbox index"); +} + diff --git a/src/gtk1/listbox.cpp b/src/gtk1/listbox.cpp index 2793afeb92..6570cb1c40 100644 --- a/src/gtk1/listbox.cpp +++ b/src/gtk1/listbox.cpp @@ -15,7 +15,8 @@ #include "wx/dynarray.h" #include "wx/listbox.h" #include "wx/utils.h" -#include +#include "wx/intl.h" +#include "wx/checklst.h" //------------------------------------------------------------------------- // conditional compilation @@ -32,6 +33,30 @@ //----------------------------------------------------------------------------- extern bool g_blockEventsOnDrag; +extern bool g_blockEventsOnScroll; + +//----------------------------------------------------------------------------- +// "button_press_event" +//----------------------------------------------------------------------------- + +static gint +gtk_listbox_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxListBox *listbox ) +{ + if (g_blockEventsOnDrag) return FALSE; + if (g_blockEventsOnScroll) return FALSE; + + if (!listbox->HasVMT()) return FALSE; + + if (gdk_event->x > 15) return FALSE; + + int sel = listbox->GetIndex( widget ); + + wxCheckListBox *clb = (wxCheckListBox *)listbox; + + clb->Check( sel, !clb->IsChecked(sel) ); + + return FALSE; +} //----------------------------------------------------------------------------- // "select" and "deselect" @@ -74,6 +99,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxListBox,wxControl) wxListBox::wxListBox() { m_list = (GtkList *) NULL; + m_hasCheckBoxes = FALSE; } bool wxListBox::Create( wxWindow *parent, wxWindowID id, @@ -120,7 +146,17 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, m_clientObjectList.Append( (wxObject*) NULL ); GtkWidget *list_item; - list_item = gtk_list_item_new_with_label( choices[i] ); + + if (m_hasCheckBoxes) + { + wxString str = "[-] "; + str += choices[i]; + list_item = gtk_list_item_new_with_label( str ); + } + else + { + list_item = gtk_list_item_new_with_label( choices[i] ); + } gtk_container_add( GTK_CONTAINER(m_list), list_item ); @@ -131,6 +167,14 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, gtk_signal_connect( GTK_OBJECT(list_item), "deselect", GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this ); + if (m_hasCheckBoxes) + { + gtk_signal_connect( GTK_OBJECT(list_item), + "button_press_event", + (GtkSignalFunc)gtk_listbox_button_press_callback, + (gpointer) this ); + } + ConnectWidget( list_item ); gtk_widget_show( list_item ); @@ -154,14 +198,25 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, wxListBox::~wxListBox() { - Clear(); + Clear(); } void wxListBox::AppendCommon( const wxString &item ) { wxCHECK_RET( m_list != NULL, "invalid listbox" ); - GtkWidget *list_item = gtk_list_item_new_with_label( item ); + GtkWidget *list_item; + + if (m_hasCheckBoxes) + { + wxString str = "[-] "; + str += item; + list_item = gtk_list_item_new_with_label( str ); + } + else + { + list_item = gtk_list_item_new_with_label( item ); + } gtk_signal_connect( GTK_OBJECT(list_item), "select", GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this ); @@ -174,6 +229,14 @@ void wxListBox::AppendCommon( const wxString &item ) if (m_widgetStyle) ApplyWidgetStyle(); + if (m_hasCheckBoxes) + { + gtk_signal_connect( GTK_OBJECT(list_item), + "button_press_event", + (GtkSignalFunc)gtk_listbox_button_press_callback, + (gpointer) this ); + } + gtk_widget_show( list_item ); ConnectWidget( list_item ); @@ -274,11 +337,7 @@ void wxListBox::Delete( int n ) GList *child = g_list_nth( m_list->children, n ); - if (!child) - { - wxFAIL_MSG("wrong listbox index"); - return; - } + wxCHECK_RET( child, "wrong listbox index" ); GList *list = g_list_append( NULL, child->data ); gtk_list_remove_items( m_list, list ); @@ -316,7 +375,12 @@ int wxListBox::FindString( const wxString &item ) const { GtkBin *bin = GTK_BIN( child->data ); GtkLabel *label = GTK_LABEL( bin->child ); - if (item == label->label) return count; + + wxString str = label->label; + if (m_hasCheckBoxes) str.Remove( 0, 4 ); + + if (str == item) return count; + count++; child = child->next; } @@ -380,7 +444,11 @@ wxString wxListBox::GetString( int n ) const { GtkBin *bin = GTK_BIN( child->data ); GtkLabel *label = GTK_LABEL( bin->child ); - return label->label; + + wxString str = label->label; + if (m_hasCheckBoxes) str.Remove( 0, 4 ); + + return str; } wxFAIL_MSG("wrong listbox index"); return ""; @@ -394,9 +462,14 @@ wxString wxListBox::GetStringSelection() const if (selection) { GtkBin *bin = GTK_BIN( selection->data ); - wxString tmp = GTK_LABEL( bin->child )->label; - return tmp; + GtkLabel *label = GTK_LABEL( bin->child ); + + wxString str = label->label; + if (m_hasCheckBoxes) str.Remove( 0, 4 ); + + return str; } + wxFAIL_MSG("no listbox selection available"); return ""; } @@ -463,7 +536,12 @@ void wxListBox::SetString( int n, const wxString &string ) { GtkBin *bin = GTK_BIN( child->data ); GtkLabel *label = GTK_LABEL( bin->child ); - gtk_label_set( label, string ); + + wxString str; + if (m_hasCheckBoxes) str += "[-] "; + str += string; + + gtk_label_set( label, str ); } else { @@ -560,8 +638,12 @@ void wxListBox::ApplyWidgetStyle() GList *child = m_list->children; while (child) { - gtk_widget_set_style( GTK_BIN(child->data)->child, m_widgetStyle ); gtk_widget_set_style( GTK_WIDGET(child->data), m_widgetStyle ); + + GtkBin *bin = GTK_BIN( child->data ); + GtkWidget *label = GTK_WIDGET( bin->child ); + gtk_widget_set_style( label, m_widgetStyle ); + child = child->next; } } -- 2.47.2