--- /dev/null
+///////////////////////////////////////////////////////////////////////////////
+// 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__
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-
#ifndef __GTKCHOICEH__
#define __GTKCHOICEH__
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxListBoxNameStr )
{
+ m_hasCheckBoxes = FALSE;
Create(parent, id, pos, size, n, choices, style, validator, name);
}
~wxListBox();
void ApplyWidgetStyle();
GtkList *m_list;
- wxList m_clientDataList;
- wxList m_clientObjectList;
+ wxList m_clientDataList;
+ wxList m_clientObjectList;
+ bool m_hasCheckBoxes;
};
#endif // __GTKLISTBOXH__
--- /dev/null
+///////////////////////////////////////////////////////////////////////////////
+// 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__
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-
#ifndef __GTKCHOICEH__
#define __GTKCHOICEH__
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxListBoxNameStr )
{
+ m_hasCheckBoxes = FALSE;
Create(parent, id, pos, size, n, choices, style, validator, name);
}
~wxListBox();
void ApplyWidgetStyle();
GtkList *m_list;
- wxList m_clientDataList;
- wxList m_clientObjectList;
+ wxList m_clientDataList;
+ wxList m_clientObjectList;
+ bool m_hasCheckBoxes;
};
#endif // __GTKLISTBOXH__
#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.
const int ID_SPIN = 182;
+const int ID_CHECKLIST = 190;
+
BEGIN_EVENT_TABLE(MyPanel, wxPanel)
EVT_SIZE ( MyPanel::OnSize)
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) )
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
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
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)
{
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);
}
}
gtk/brush.cpp \
gtk/button.cpp \
gtk/checkbox.cpp \
+ gtk/checklst.cpp \
gtk/choice.cpp \
gtk/clipbrd.cpp \
gtk/colour.cpp \
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// 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");
+}
+
#include "wx/dynarray.h"
#include "wx/listbox.h"
#include "wx/utils.h"
-#include <wx/intl.h>
+#include "wx/intl.h"
+#include "wx/checklst.h"
//-------------------------------------------------------------------------
// conditional compilation
//-----------------------------------------------------------------------------
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"
wxListBox::wxListBox()
{
m_list = (GtkList *) NULL;
+ m_hasCheckBoxes = FALSE;
}
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 );
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 );
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 );
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 );
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 );
{
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;
}
{
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 "";
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 "";
}
{
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
{
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;
}
}
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// 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");
+}
+
#include "wx/dynarray.h"
#include "wx/listbox.h"
#include "wx/utils.h"
-#include <wx/intl.h>
+#include "wx/intl.h"
+#include "wx/checklst.h"
//-------------------------------------------------------------------------
// conditional compilation
//-----------------------------------------------------------------------------
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"
wxListBox::wxListBox()
{
m_list = (GtkList *) NULL;
+ m_hasCheckBoxes = FALSE;
}
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 );
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 );
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 );
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 );
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 );
{
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;
}
{
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 "";
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 "";
}
{
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
{
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;
}
}