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,
{
public:
wxGtkDataViewListModelNotifier( GtkWxListStore* gtk_store, wxDataViewListModel *wx_model );
+ ~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;
};
m_wx_model = wx_model;
}
+wxGtkDataViewListModelNotifier::~wxGtkDataViewListModelNotifier()
+{
+ m_wx_model = NULL;
+ m_gtk_store = NULL;
+}
+
bool wxGtkDataViewListModelNotifier::RowAppended()
{
unsigned int pos = m_wx_model->GetRowCount()-1;
bool wxGtkDataViewListModelNotifier::ValueChanged( unsigned int model_col, unsigned int model_row )
{
// This adds GTK+'s missing MVC logic for ValueChanged
- wxNode *node = GetOwner()->m_viewingColumns.GetFirst();
+ wxObjectList::compatibility_iterator
+ node = GetOwner()->m_viewingColumns.GetFirst();
while (node)
{
wxDataViewViewingColumn* viewing_column = (wxDataViewViewingColumn*) node->GetData();
gtk_tree_view_get_cell_area( widget, path, column, &cell_area );
gtk_tree_path_free( path );
+ GtkAdjustment* hadjust = gtk_tree_view_get_hadjustment( widget );
+ double d = gtk_adjustment_get_value( hadjust );
+ int xdiff = (int) d;
+
int ydiff = column->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();
gtk_tree_path_free (path);
// This adds GTK+'s missing MVC logic for RowsReordered
- wxNode *node = GetOwner()->m_viewingColumns.GetFirst();
+ wxObjectList::compatibility_iterator
+ node = GetOwner()->m_viewingColumns.GetFirst();
while (node)
{
wxDataViewViewingColumn* viewing_column = (wxDataViewViewingColumn*) node->GetData();
{
wxDataViewTextRenderer *cell = (wxDataViewTextRenderer*) user_data;
- wxString tmp = wxGTK_CONV_BACK( arg2 );
+ wxString tmp = wxGTK_CONV_BACK_FONT(arg2, cell->GetOwner()->GetOwner()->GetFont());
wxVariant value = tmp;
if (!cell->Validate( value ))
return;
GValue gvalue = { 0, };
g_value_init( &gvalue, G_TYPE_STRING );
g_object_get_property( G_OBJECT(m_renderer), "text", &gvalue );
- wxString tmp = wxGTK_CONV_BACK( g_value_get_string( &gvalue ) );
+ wxString tmp = wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue ),
+ wx_const_cast(wxDataViewTextRenderer*, this)->GetOwner()->GetOwner()->GetFont() );
g_value_unset( &gvalue );
value = tmp;
{
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;
g_value_unset( &gvalue );
}
-// ---------------------------------------------------------
+// ---------------------------------------------------------
// wxDataViewBitmapRenderer
-// ---------------------------------------------------------
+// ---------------------------------------------------------
IMPLEMENT_CLASS(wxDataViewBitmapRenderer, wxDataViewRenderer)
{
wxBitmap bitmap;
bitmap << value;
-
+
// This may create a Pixbuf representation in the
// wxBitmap object (and it will stay there)
GdkPixbuf *pixbuf = bitmap.GetPixbuf();
-
+
GValue gvalue = { 0, };
g_value_init( &gvalue, G_TYPE_OBJECT );
g_value_set_object( &gvalue, pixbuf );
g_object_set_property( G_OBJECT(m_renderer), "pixbuf", &gvalue );
g_value_unset( &gvalue );
-
+
return true;
}
-
+
if (value.GetType() == wxT("wxIcon"))
{
wxIcon bitmap;
bitmap << value;
-
+
// This may create a Pixbuf representation in the
// wxBitmap object (and it will stay there)
GdkPixbuf *pixbuf = bitmap.GetPixbuf();
-
+
GValue gvalue = { 0, };
g_value_init( &gvalue, G_TYPE_OBJECT );
g_value_set_object( &gvalue, pixbuf );
g_object_set_property( G_OBJECT(m_renderer), "pixbuf", &gvalue );
g_value_unset( &gvalue );
-
+
return true;
}
-
+
return false;
}
{
return false;
}
-
+
// ---------------------------------------------------------
// wxDataViewToggleRenderer
// ---------------------------------------------------------
{
if (gdk_event->type != GDK_BUTTON_PRESS)
return TRUE;
-
+
if (gdk_event->button == 1)
{
wxDataViewCtrl *dv = column->GetOwner();
event.SetModel( dv->GetModel() );
dv->GetEventHandler()->ProcessEvent( event );
}
-
+
return TRUE;
}
list_store->model->GetValue( value, cell->GetOwner()->GetModelColumn(), model_row );
if (value.GetType() != cell->GetVariantType())
- wxLogError( wxT("Wrong type, required: %s but: %s"),
- value.GetType().c_str(),
+ wxLogError( wxT("Wrong type, required: %s but: %s"),
+ value.GetType().c_str(),
cell->GetVariantType().c_str() );
cell->SetValue( value );
IMPLEMENT_CLASS(wxDataViewColumn, wxDataViewColumnBase)
-wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewRenderer *cell,
- unsigned int model_column, int width,
+wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewRenderer *cell,
+ unsigned int model_column, int width,
wxAlignment align, int flags ) :
wxDataViewColumnBase( title, cell, model_column, width, align, flags )
{
SetTitle( title );
}
-wxDataViewColumn::wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *cell,
- unsigned int model_column, int width,
+wxDataViewColumn::wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *cell,
+ unsigned int model_column, int width,
wxAlignment align, int flags ) :
wxDataViewColumnBase( bitmap, cell, model_column, width, align, flags )
{
{
if (m_isConnected)
return;
-
+
if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview))
{
GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
{
g_signal_connect(column->button, "button_press_event",
G_CALLBACK (gtk_dataview_header_button_press_callback), this);
-
+
m_isConnected = true;
}
}
void wxDataViewColumn::SetOwner( wxDataViewCtrl *owner )
{
wxDataViewColumnBase::SetOwner( owner );
-
+
GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
-
+
gtk_tree_view_column_set_title( column, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
}
void wxDataViewColumn::SetTitle( const wxString &title )
{
GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
-
+
if (m_isConnected)
{
// disconnect before column->button gets recreated
- g_signal_handlers_disconnect_by_func( column->button,
+ g_signal_handlers_disconnect_by_func( column->button,
(GtkWidget*) gtk_dataview_header_button_press_callback, this);
-
+
m_isConnected = false;
}
if (bitmap.Ok())
{
GtkImage *gtk_image = GTK_IMAGE( gtk_image_new() );
-
+
GdkBitmap *mask = (GdkBitmap *) NULL;
if (bitmap.GetMask())
mask = bitmap.GetMask()->GetBitmap();
bitmap.GetPixmap(), mask);
}
gtk_widget_show( GTK_WIDGET(gtk_image) );
-
+
gtk_tree_view_column_set_widget( column, GTK_WIDGET(gtk_image) );
}
else
void wxDataViewColumn::SetAlignment( wxAlignment align )
{
GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
-
+
gfloat xalign = 0.0;
if (align == wxALIGN_RIGHT)
xalign = 1.0;
if (align == wxALIGN_CENTER_HORIZONTAL ||
align == wxALIGN_CENTER)
xalign = 0.5;
-
+
gtk_tree_view_column_set_alignment( column, xalign );
}
return wxALIGN_RIGHT;
if (xalign == 0.5)
return wxALIGN_CENTER_HORIZONTAL;
-
+
return wxALIGN_LEFT;
}
void wxDataViewColumn::SetSortOrder( bool ascending )
{
GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
-
+
if (ascending)
gtk_tree_view_column_set_sort_order( column, GTK_SORT_ASCENDING );
else
bool wxDataViewColumn::IsSortOrderAscending() const
{
GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
-
+
return (gtk_tree_view_column_get_sort_order( column ) != GTK_SORT_DESCENDING);
}
{
if (!GTK_WIDGET_REALIZED(dv->m_widget))
return;
-
+
wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ROW_SELECTED, dv->GetId() );
event.SetRow( dv->GetSelection() );
event.SetModel( dv->GetModel() );
}
static void
-wxdataview_row_activated_callback( GtkTreeView* treeview, GtkTreePath *path,
+wxdataview_row_activated_callback( GtkTreeView* treeview, GtkTreePath *path,
GtkTreeViewColumn *column, wxDataViewCtrl *dv )
{
wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ROW_ACTIVATED, dv->GetId() );
// 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 );
if (!gtk_check_version(2,10,0))
{
GtkTreeViewGridLines grid = GTK_TREE_VIEW_GRID_LINES_NONE;
-
- if ((style & wxDV_HORIZ_RULES) != 0 &&
+
+ if ((style & wxDV_HORIZ_RULES) != 0 &&
(style & wxDV_VERT_RULES) != 0)
grid = GTK_TREE_VIEW_GRID_LINES_BOTH;
else if (style & wxDV_VERT_RULES)
}
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);
void wxDataViewCtrl::OnInternalIdle()
{
wxWindow::OnInternalIdle();
-
+
unsigned int cols = GetColumnCount();
unsigned int i;
for (i = 0; i < cols; i++)
void wxDataViewCtrl::SetSelection( int row )
{
GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
-
+
if (row < 0)
{
gtk_tree_selection_unselect_all( selection );
{
GtkTreePath *path = gtk_tree_path_new ();
gtk_tree_path_append_index( path, row );
-
+
gtk_tree_selection_select_path( selection, path );
-
+
gtk_tree_path_free( path );
}
}
void wxDataViewCtrl::Unselect( unsigned int row )
{
GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
-
+
GtkTreePath *path = gtk_tree_path_new ();
gtk_tree_path_append_index( path, row );
-
+
gtk_tree_selection_unselect_path( selection, path );
-
+
gtk_tree_path_free( path );
}
void wxDataViewCtrl::SetSelections( const wxArrayInt& aSelections)
{
}
-
+
bool wxDataViewCtrl::IsSelected( unsigned int row ) const
{
GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
-
+
GtkTreePath *path = gtk_tree_path_new ();
gtk_tree_path_append_index( path, row );
-
+
gboolean ret = gtk_tree_selection_path_is_selected( selection, path );
-
+
gtk_tree_path_free( path );
-
+
return ret;
}
{
GtkTreeModel *model;
GList *list = gtk_tree_selection_get_selected_rows( selection, &model );
-
+
// do something
if (list)
{
// list = g_list_nth( list, 0 ); should be a noop
GtkTreePath *path = (GtkTreePath*) list->data;
-
+
unsigned int row = (unsigned int)gtk_tree_path_get_indices (path)[0];
-
+
// delete list
g_list_foreach( list, (GFunc) gtk_tree_path_free, NULL );
g_list_free( list );
-
+
return (int) row;
}
}
else
{
-
+
GtkTreeModel *model;
GtkTreeIter iter;
gboolean has_selection = gtk_tree_selection_get_selected( selection, &model, &iter );
return (int) row;
}
}
-
+
return -1;
}
{
GtkTreeModel *model;
GList *list = gtk_tree_selection_get_selected_rows( selection, &model );
-
+
int count = 0;
while (list)
{
-
+
// list = g_list_nth( list, 0 ); should be a noop
GtkTreePath *path = (GtkTreePath*) list->data;
-
+
unsigned int row = (unsigned int)gtk_tree_path_get_indices (path)[0];
-
+
aSelections.Add( (int) row );
-
- list = g_list_next( list );
+
+ list = g_list_next( list );
}
-
+
// delete list
g_list_foreach( list, (GFunc) gtk_tree_path_free, NULL );
g_list_free( list );
-
+
return count;
}
else
return 1;
}
}
-
+
return 0;
}