g_value_init( value, G_TYPE_STRING );
model->GetValue( variant,
(unsigned int) column,
- (unsigned int) iter->user_data );
+ wxPtrToUInt(iter->user_data) );
// FIXME: we should support different encodings here
g_value_set_string( value, wxGTK_CONV_SYS(variant.GetString()) );
GdkRectangle *background_area,
GdkRectangle *cell_area,
GtkCellRendererState flags );
+static GtkCellEditable *gtk_wx_cell_renderer_start_editing(
+ GtkCellRenderer *cell,
+ GdkEvent *event,
+ GtkWidget *widget,
+ const gchar *path,
+ GdkRectangle *background_area,
+ GdkRectangle *cell_area,
+ GtkCellRendererState flags );
+
static GObjectClass *cell_parent_class = NULL;
cell_class->get_size = gtk_wx_cell_renderer_get_size;
cell_class->render = gtk_wx_cell_renderer_render;
cell_class->activate = gtk_wx_cell_renderer_activate;
+ cell_class->start_editing = gtk_wx_cell_renderer_start_editing;
}
static void
return (GtkCellRenderer*) g_object_new (GTK_TYPE_WX_CELL_RENDERER, NULL);
}
+
+
+static GtkCellEditable *gtk_wx_cell_renderer_start_editing(
+ GtkCellRenderer *renderer,
+ GdkEvent *event,
+ GtkWidget *widget,
+ const gchar *path,
+ GdkRectangle *background_area,
+ GdkRectangle *cell_area,
+ GtkCellRendererState flags )
+{
+ GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer;
+ wxDataViewCustomRenderer *cell = wxrenderer->cell;
+ if (!cell->HasEditorCtrl())
+ return NULL;
+
+ GdkRectangle rect;
+ gtk_wx_cell_renderer_get_size (renderer, widget, cell_area,
+ &rect.x,
+ &rect.y,
+ &rect.width,
+ &rect.height);
+
+ rect.x += cell_area->x;
+ rect.y += cell_area->y;
+// rect.width -= renderer->xpad * 2;
+// rect.height -= renderer->ypad * 2;
+
+// wxRect renderrect( rect.x, rect.y, rect.width, rect.height );
+ wxRect renderrect( cell_area->x, cell_area->y, cell_area->width, cell_area->height );
+
+ // wxDataViewListModel *model = cell->GetOwner()->GetOwner()->GetModel();
+
+ GtkTreePath *treepath = gtk_tree_path_new_from_string( path );
+ unsigned int model_row = (unsigned int)gtk_tree_path_get_indices (treepath)[0];
+ gtk_tree_path_free( treepath );
+
+ cell->StartEditing( model_row, renderrect );
+
+ return NULL;
+}
+
static void
gtk_wx_cell_renderer_get_size (GtkCellRenderer *renderer,
GtkWidget *widget,
unsigned int model_col = cell->GetOwner()->GetModelColumn();
- if (event->type == GDK_BUTTON_PRESS)
+ if (!event)
+ {
+ bool ret = false;
+
+ // activated by <ENTER>
+ if (cell->Activate( renderrect, model, model_col, model_row ))
+ ret = true;
+
+ return ret;
+ }
+ else if (event->type == GDK_BUTTON_PRESS)
{
GdkEventButton *button_event = (GdkEventButton*) event;
wxPoint pt( ((int) button_event->x) - renderrect.x,
class wxGtkDataViewListModelNotifier: public wxDataViewListModelNotifier
{
public:
- wxGtkDataViewListModelNotifier( GtkWxListStore* gtk_store, wxDataViewListModel *wx_model );
+ wxGtkDataViewListModelNotifier( GtkWxListStore* gtk_store,
+ wxDataViewListModel *wx_model,
+ wxDataViewCtrl* ctrl );
+ ~wxGtkDataViewListModelNotifier();
virtual bool RowAppended();
virtual bool RowPrepended();
virtual bool RowsReordered( unsigned int *new_order );
virtual bool Cleared();
- virtual bool Freed()
- {
- m_wx_model = NULL;
- m_gtk_store = NULL;
- return wxDataViewListModelNotifier::Freed();
- }
-
GtkWxListStore *m_gtk_store;
wxDataViewListModel *m_wx_model;
+ wxDataViewCtrl *m_owner;
};
// ---------------------------------------------------------
// ---------------------------------------------------------
wxGtkDataViewListModelNotifier::wxGtkDataViewListModelNotifier(
- GtkWxListStore* gtk_store, wxDataViewListModel *wx_model )
+ GtkWxListStore* gtk_store, wxDataViewListModel *wx_model,
+ wxDataViewCtrl *ctrl )
{
m_gtk_store = gtk_store;
m_wx_model = wx_model;
+ m_owner = ctrl;
+}
+
+wxGtkDataViewListModelNotifier::~wxGtkDataViewListModelNotifier()
+{
+ m_wx_model = NULL;
+ m_gtk_store = NULL;
}
bool wxGtkDataViewListModelNotifier::RowAppended()
bool wxGtkDataViewListModelNotifier::ValueChanged( unsigned int model_col, unsigned int model_row )
{
// This adds GTK+'s missing MVC logic for ValueChanged
- wxObjectList::compatibility_iterator
- node = GetOwner()->m_viewingColumns.GetFirst();
- while (node)
+ unsigned int index;
+ for (index = 0; index < m_owner->GetColumnCount(); index++)
{
- wxDataViewViewingColumn* viewing_column = (wxDataViewViewingColumn*) node->GetData();
- if (viewing_column->m_modelColumn == model_col)
+ wxDataViewColumn *column = m_owner->GetColumn( index );
+ if (column->GetModelColumn() == model_col)
{
- GtkTreeView *widget = GTK_TREE_VIEW(viewing_column->m_viewColumn->GetOwner()->m_treeview);
- GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(viewing_column->m_viewColumn->GetGtkHandle());
+ GtkTreeView *widget = GTK_TREE_VIEW(m_owner->m_treeview);
+ GtkTreeViewColumn *gcolumn = GTK_TREE_VIEW_COLUMN(column->GetGtkHandle());
// Get cell area
GtkTreePath *path = gtk_tree_path_new();
gtk_tree_path_append_index( path, model_row );
GdkRectangle cell_area;
- gtk_tree_view_get_cell_area( widget, path, column, &cell_area );
+ gtk_tree_view_get_cell_area( widget, path, gcolumn, &cell_area );
gtk_tree_path_free( path );
- int ydiff = column->button->allocation.height;
+ GtkAdjustment* hadjust = gtk_tree_view_get_hadjustment( widget );
+ double d = gtk_adjustment_get_value( hadjust );
+ int xdiff = (int) d;
+
+ int ydiff = gcolumn->button->allocation.height;
// Redraw
gtk_widget_queue_draw_area( GTK_WIDGET(widget),
- cell_area.x, ydiff + cell_area.y, cell_area.width, cell_area.height );
+ cell_area.x - xdiff, ydiff + cell_area.y, cell_area.width, cell_area.height );
}
-
- node = node->GetNext();
}
return true;
gtk_tree_path_free (path);
// This adds GTK+'s missing MVC logic for RowsReordered
- wxObjectList::compatibility_iterator
- node = GetOwner()->m_viewingColumns.GetFirst();
- while (node)
- {
- wxDataViewViewingColumn* viewing_column = (wxDataViewViewingColumn*) node->GetData();
- GtkTreeView *widget = GTK_TREE_VIEW(viewing_column->m_viewColumn->GetOwner()->m_treeview);
- // Doesn't work yet...
- gtk_widget_queue_draw( GTK_WIDGET(widget) );
-
- node = node->GetNext();
- }
+ GtkTreeView *widget = GTK_TREE_VIEW(m_owner->m_treeview);
+ // Doesn't work yet...
+ gtk_widget_queue_draw( GTK_WIDGET(widget) );
return true;
}
int align ) :
wxDataViewRenderer( varianttype, mode, align )
{
- m_renderer = (GtkWidget*) gtk_cell_renderer_text_new();
+ m_renderer = (GtkCellRenderer*) gtk_cell_renderer_text_new();
if (mode & wxDATAVIEW_CELL_EDITABLE)
{
{
wxDataViewRenderer::SetAlignment(align);
- // horizontal alignment:
+ if (gtk_check_version(2,10,0))
+ return;
+ // horizontal alignment:
PangoAlignment pangoAlign = PANGO_ALIGN_LEFT;
if (align & wxALIGN_RIGHT)
pangoAlign = PANGO_ALIGN_RIGHT;
int align ) :
wxDataViewRenderer( varianttype, mode, align )
{
- m_renderer = (GtkWidget*) gtk_cell_renderer_pixbuf_new();
+ m_renderer = (GtkCellRenderer*) gtk_cell_renderer_pixbuf_new();
SetMode(mode);
SetAlignment(align);
wxDataViewCellMode mode, int align ) :
wxDataViewRenderer( varianttype, mode, align )
{
- m_renderer = (GtkWidget*) gtk_cell_renderer_toggle_new();
+ m_renderer = (GtkCellRenderer*) gtk_cell_renderer_toggle_new();
if (mode & wxDATAVIEW_CELL_ACTIVATABLE)
{
GtkWxCellRenderer *renderer = (GtkWxCellRenderer *) gtk_wx_cell_renderer_new();
renderer->cell = this;
- m_renderer = (GtkWidget*) renderer;
+ m_renderer = (GtkCellRenderer*) renderer;
SetMode(mode);
SetAlignment(align);
#ifdef __WXGTK26__
if (!gtk_check_version(2,6,0))
{
- m_renderer = (GtkWidget*) gtk_cell_renderer_progress_new();
+ m_renderer = (GtkCellRenderer*) gtk_cell_renderer_progress_new();
GValue gvalue = { 0, };
g_value_init( &gvalue, G_TYPE_STRING );
wxDataViewRenderer *cell = (wxDataViewRenderer*) data;
- unsigned int model_row = (unsigned int) iter->user_data;
+ unsigned int model_row = wxPtrToUInt(iter->user_data);
wxVariant value;
list_store->model->GetValue( value, cell->GetOwner()->GetModelColumn(), model_row );
cell->GetVariantType().c_str() );
cell->SetValue( value );
+
+ wxListItemAttr attr;
+ list_store->model->GetAttr( attr, cell->GetOwner()->GetModelColumn(), model_row );
+
+ if (attr.HasBackgroundColour())
+ {
+ wxColour colour = attr.GetBackgroundColour();
+ const GdkColor * const gcol = colour.GetColor();
+
+ GValue gvalue = { 0, };
+ g_value_init( &gvalue, GDK_TYPE_COLOR );
+ g_value_set_boxed( &gvalue, gcol );
+ g_object_set_property( G_OBJECT(renderer), "cell-background_gdk", &gvalue );
+ g_value_unset( &gvalue );
+ }
+ else
+ {
+ GValue gvalue = { 0, };
+ g_value_init( &gvalue, G_TYPE_BOOLEAN );
+ g_value_set_boolean( &gvalue, FALSE );
+ g_object_set_property( G_OBJECT(renderer), "cell-background-set", &gvalue );
+ g_value_unset( &gvalue );
+ }
}
IMPLEMENT_CLASS(wxDataViewColumn, wxDataViewColumnBase)
// wxDataViewCtrl
//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+// InsertChild for wxDataViewCtrl
+//-----------------------------------------------------------------------------
+
+static void wxInsertChildInDataViewCtrl( wxWindowGTK* parent, wxWindowGTK* child )
+{
+ wxDataViewCtrl * dvc = (wxDataViewCtrl*) parent;
+ GtkWidget *treeview = dvc->GtkGetTreeView();
+
+ // Insert widget in GtkTreeView
+ if (GTK_WIDGET_REALIZED(treeview))
+ gtk_widget_set_parent_window( child->m_widget,
+ gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview) ) );
+ gtk_widget_set_parent( child->m_widget, treeview );
+}
+
+static
+void gtk_dataviewctrl_size_callback( GtkWidget *WXUNUSED(widget),
+ GtkAllocation *alloc,
+ wxDataViewCtrl *win )
+{
+
+ wxWindowList::Node *node = win->GetChildren().GetFirst();
+ while (node)
+ {
+ wxWindow *child = node->GetData();
+
+ GtkRequisition req;
+ gtk_widget_size_request( child->m_widget, &req );
+
+ GtkAllocation alloc;
+ alloc.x = child->m_x;
+ alloc.y = child->m_y;
+ alloc.width = child->m_width;
+ alloc.height = child->m_height;
+ gtk_widget_size_allocate( child->m_widget, &alloc );
+
+ node = node->GetNext();
+ }
+}
+
+
+
IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl, wxDataViewCtrlBase)
wxDataViewCtrl::~wxDataViewCtrl()
{
Init();
- m_needParent = true;
- m_acceptsFocus = true;
-
if (!PreCreation( parent, pos, size ) ||
!CreateBase( parent, id, pos, size, style, validator ))
{
return false;
}
+ m_insertCallback = wxInsertChildInDataViewCtrl;
+
m_widget = gtk_scrolled_window_new (NULL, NULL);
GtkScrolledWindowSetBorder(m_widget, style);
m_treeview = gtk_tree_view_new();
gtk_container_add (GTK_CONTAINER (m_widget), m_treeview);
+ g_signal_connect (m_treeview, "size_allocate",
+ G_CALLBACK (gtk_dataviewctrl_size_callback), this);
+
#ifdef __WXGTK26__
if (!gtk_check_version(2,6,0))
gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview), TRUE );
}
else
#endif
+ {
gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview), (style & wxDV_HORIZ_RULES) != 0 );
+ }
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget),
GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
PostCreation(size);
- GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
- g_signal_connect_after (selection, "changed",
- G_CALLBACK (wxdataview_selection_changed_callback), this);
+ GtkEnableSelectionEvents();
+
g_signal_connect_after (m_treeview, "row_activated",
G_CALLBACK (wxdataview_row_activated_callback), this);
GtkWxListStore *gtk_store = wxgtk_list_store_new();
gtk_store->model = model;
- m_notifier = new wxGtkDataViewListModelNotifier( gtk_store, model );
+ m_notifier = new wxGtkDataViewListModelNotifier( gtk_store, model, this );
model->AddNotifier( m_notifier );
return true;
}
+void wxDataViewCtrl::GtkDisableSelectionEvents()
+{
+ GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
+ g_signal_connect_after (selection, "changed",
+ G_CALLBACK (wxdataview_selection_changed_callback), this);
+}
+
+void wxDataViewCtrl::GtkEnableSelectionEvents()
+{
+ GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
+ g_signal_handlers_disconnect_by_func( selection,
+ (gpointer) (wxdataview_selection_changed_callback), this);
+}
+
void wxDataViewCtrl::SetSelection( int row )
{
+ GtkDisableSelectionEvents();
+
GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
if (row < 0)
gtk_tree_path_free( path );
}
+
+ GtkEnableSelectionEvents();
}
void wxDataViewCtrl::Unselect( unsigned int row )
{
+ GtkDisableSelectionEvents();
+
GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
GtkTreePath *path = gtk_tree_path_new ();
gtk_tree_selection_unselect_path( selection, path );
gtk_tree_path_free( path );
+
+ GtkEnableSelectionEvents();
}
void wxDataViewCtrl::SetSelectionRange( unsigned int from, unsigned int to )
{
+ GtkDisableSelectionEvents();
+
+ if (from > to)
+ {
+ unsigned int tmp = from;
+ from = to;
+ to = tmp;
+ }
+
+ GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
+
+ GtkTreePath *path_from = gtk_tree_path_new ();
+ gtk_tree_path_append_index( path_from, from );
+ GtkTreePath *path_to = gtk_tree_path_new ();
+ gtk_tree_path_append_index( path_to, to );
+
+ gtk_tree_selection_select_range( selection, path_from, path_to );
+
+ gtk_tree_path_free( path_to );
+ gtk_tree_path_free( path_from );
+
+ GtkEnableSelectionEvents();
}
void wxDataViewCtrl::SetSelections( const wxArrayInt& aSelections)
{
+ GtkDisableSelectionEvents();
+
+ GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
+
+ unsigned int i;
+ for (i = 0; i < aSelections.GetCount(); i++)
+ {
+ GtkTreePath *path = gtk_tree_path_new ();
+ gtk_tree_path_append_index( path, aSelections[i] );
+
+ gtk_tree_selection_select_path( selection, path );
+
+ gtk_tree_path_free( path );
+ }
+
+ GtkEnableSelectionEvents();
}
bool wxDataViewCtrl::IsSelected( unsigned int row ) const