1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/dataview.cpp
3 // Purpose: wxDataViewCtrl GTK+2 implementation
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
13 #if wxUSE_DATAVIEWCTRL
15 #include "wx/dataview.h"
17 #ifndef wxUSE_GENERICDATAVIEWCTRL
21 #include "wx/dcclient.h"
25 #include "wx/stockitem.h"
26 #include "wx/calctrl.h"
27 #include "wx/popupwin.h"
31 #include "wx/gtk/private.h"
32 #include "wx/gtk/win_gtk.h"
34 #include <gobject/gvaluecollector.h>
35 #include <gtk/gtktreemodel.h>
36 #include <gtk/gtktreednd.h>
38 #include <gdk/gdkkeysyms.h>
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
46 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
50 extern bool g_blockEventsOnDrag
;
52 //-----------------------------------------------------------------------------
53 // define new GTK+ class wxGtkListStore
54 //-----------------------------------------------------------------------------
58 #define GTK_TYPE_WX_LIST_STORE (gtk_wx_list_store_get_type ())
59 #define GTK_WX_LIST_STORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_LIST_STORE, GtkWxListStore))
60 #define GTK_WX_LIST_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_LIST_STORE, GtkWxListStoreClass))
61 #define GTK_IS_WX_LIST_STORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_LIST_STORE))
62 #define GTK_IS_WX_LIST_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_LIST_STORE))
63 #define GTK_WX_LIST_STORE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_LIST_STORE, GtkWxListStoreClass))
65 GType
gtk_wx_list_store_get_type (void);
67 typedef struct _GtkWxListStore GtkWxListStore
;
68 typedef struct _GtkWxListStoreClass GtkWxListStoreClass
;
70 struct _GtkWxListStore
76 wxDataViewListModel
*model
;
79 struct _GtkWxListStoreClass
81 GObjectClass list_parent_class
;
84 static GtkWxListStore
*wxgtk_list_store_new (void);
85 static void wxgtk_list_store_init (GtkWxListStore
*list_store
);
86 static void wxgtk_list_store_class_init (GtkWxListStoreClass
*klass
);
87 static void wxgtk_list_store_tree_model_init (GtkTreeModelIface
*iface
);
88 static void wxgtk_list_store_finalize (GObject
*object
);
89 static GtkTreeModelFlags
wxgtk_list_store_get_flags (GtkTreeModel
*tree_model
);
90 static gint
wxgtk_list_store_get_n_columns (GtkTreeModel
*tree_model
);
91 static GType
wxgtk_list_store_get_column_type (GtkTreeModel
*tree_model
,
93 static gboolean
wxgtk_list_store_get_iter (GtkTreeModel
*tree_model
,
96 static GtkTreePath
*wxgtk_list_store_get_path (GtkTreeModel
*tree_model
,
98 static void wxgtk_list_store_get_value (GtkTreeModel
*tree_model
,
102 static gboolean
wxgtk_list_store_iter_next (GtkTreeModel
*tree_model
,
104 static gboolean
wxgtk_list_store_iter_children (GtkTreeModel
*tree_model
,
106 GtkTreeIter
*parent
);
107 static gboolean
wxgtk_list_store_iter_has_child (GtkTreeModel
*tree_model
,
109 static gint
wxgtk_list_store_iter_n_children (GtkTreeModel
*tree_model
,
111 static gboolean
wxgtk_list_store_iter_nth_child (GtkTreeModel
*tree_model
,
115 static gboolean
wxgtk_list_store_iter_parent (GtkTreeModel
*tree_model
,
119 static GObjectClass
*list_parent_class
= NULL
;
122 gtk_wx_list_store_get_type (void)
124 static GType list_store_type
= 0;
126 if (!list_store_type
)
128 const GTypeInfo list_store_info
=
130 sizeof (GtkWxListStoreClass
),
131 NULL
, /* base_init */
132 NULL
, /* base_finalize */
133 (GClassInitFunc
) wxgtk_list_store_class_init
,
134 NULL
, /* class_finalize */
135 NULL
, /* class_data */
136 sizeof (GtkWxListStore
),
138 (GInstanceInitFunc
) wxgtk_list_store_init
,
141 static const GInterfaceInfo tree_model_info
=
143 (GInterfaceInitFunc
) wxgtk_list_store_tree_model_init
,
148 list_store_type
= g_type_register_static (G_TYPE_OBJECT
, "GtkWxListStore",
149 &list_store_info
, (GTypeFlags
)0 );
151 g_type_add_interface_static (list_store_type
,
156 return list_store_type
;
159 static GtkWxListStore
*
160 wxgtk_list_store_new(void)
162 GtkWxListStore
*retval
= (GtkWxListStore
*) g_object_new (GTK_TYPE_WX_LIST_STORE
, NULL
);
167 wxgtk_list_store_class_init (GtkWxListStoreClass
*klass
)
169 list_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
170 GObjectClass
*object_class
= (GObjectClass
*) klass
;
171 object_class
->finalize
= wxgtk_list_store_finalize
;
175 wxgtk_list_store_tree_model_init (GtkTreeModelIface
*iface
)
177 iface
->get_flags
= wxgtk_list_store_get_flags
;
178 iface
->get_n_columns
= wxgtk_list_store_get_n_columns
;
179 iface
->get_column_type
= wxgtk_list_store_get_column_type
;
180 iface
->get_iter
= wxgtk_list_store_get_iter
;
181 iface
->get_path
= wxgtk_list_store_get_path
;
182 iface
->get_value
= wxgtk_list_store_get_value
;
183 iface
->iter_next
= wxgtk_list_store_iter_next
;
184 iface
->iter_children
= wxgtk_list_store_iter_children
;
185 iface
->iter_has_child
= wxgtk_list_store_iter_has_child
;
186 iface
->iter_n_children
= wxgtk_list_store_iter_n_children
;
187 iface
->iter_nth_child
= wxgtk_list_store_iter_nth_child
;
188 iface
->iter_parent
= wxgtk_list_store_iter_parent
;
192 wxgtk_list_store_init (GtkWxListStore
*list_store
)
194 list_store
->model
= NULL
;
195 list_store
->stamp
= g_random_int();
199 wxgtk_list_store_finalize (GObject
*object
)
201 /* GtkWxListStore *list_store = GTK_WX_LIST_STORE (object); */
203 /* we need to sort out, which class deletes what */
204 /* delete list_store->model; */
207 (* list_parent_class
->finalize
) (object
);
212 //-----------------------------------------------------------------------------
213 // implement callbacks from wxGtkListStore class by letting
214 // them call the methods of wxWidgets' wxDataViewListModel
215 //-----------------------------------------------------------------------------
217 static GtkTreeModelFlags
218 wxgtk_list_store_get_flags (GtkTreeModel
*tree_model
)
220 g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model
), (GtkTreeModelFlags
)0 );
222 // GTK+ list store uses a linked list for storing the
223 // items and a pointer to a child is used as the member
224 // field of a GtkTreeIter. This means that the iter is
225 // valid in the GtkListStore as long as the child exists.
226 // We use the index of the row and since the index of a
227 // specific row will change if a row above is deleted,
228 // the iter does not persist
229 return /* GTK_TREE_MODEL_ITERS_PERSIST | */ GTK_TREE_MODEL_LIST_ONLY
;
233 wxgtk_list_store_get_n_columns (GtkTreeModel
*tree_model
)
235 GtkWxListStore
*list_store
= (GtkWxListStore
*) tree_model
;
236 g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model
), 0);
238 return list_store
->model
->GetColumnCount();
242 wxgtk_list_store_get_column_type (GtkTreeModel
*tree_model
,
245 GtkWxListStore
*list_store
= (GtkWxListStore
*) tree_model
;
246 g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model
), G_TYPE_INVALID
);
248 GType gtype
= G_TYPE_INVALID
;
250 wxString wxtype
= list_store
->model
->GetColumnType( (unsigned int) index
);
252 if (wxtype
== wxT("string"))
253 gtype
= G_TYPE_STRING
;
256 wxFAIL_MSG( _T("non-string columns not supported yet") );
263 wxgtk_list_store_get_iter (GtkTreeModel
*tree_model
,
267 GtkWxListStore
*list_store
= (GtkWxListStore
*) tree_model
;
268 g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model
), FALSE
);
269 g_return_val_if_fail (gtk_tree_path_get_depth (path
) > 0, FALSE
);
271 unsigned int i
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
273 if (i
>= list_store
->model
->GetRowCount())
276 iter
->stamp
= list_store
->stamp
;
277 // user_data is just the index
278 iter
->user_data
= (gpointer
) i
;
284 wxgtk_list_store_get_path (GtkTreeModel
*tree_model
,
287 g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model
), NULL
);
288 g_return_val_if_fail (iter
->stamp
== GTK_WX_LIST_STORE (tree_model
)->stamp
, NULL
);
290 GtkTreePath
*retval
= gtk_tree_path_new ();
291 // user_data is just the index
292 int i
= (wxUIntPtr
) iter
->user_data
;
293 gtk_tree_path_append_index (retval
, i
);
298 wxgtk_list_store_get_value (GtkTreeModel
*tree_model
,
303 GtkWxListStore
*list_store
= (GtkWxListStore
*) tree_model
;
304 g_return_if_fail (GTK_IS_WX_LIST_STORE (tree_model
) );
306 wxDataViewListModel
*model
= list_store
->model
;
307 wxString mtype
= model
->GetColumnType( (unsigned int) column
);
308 if (mtype
== wxT("string"))
311 g_value_init( value
, G_TYPE_STRING
);
312 model
->GetValue( variant
,
313 (unsigned int) column
,
314 wxPtrToUInt(iter
->user_data
) );
316 // FIXME: we should support different encodings here
317 g_value_set_string( value
, wxGTK_CONV_SYS(variant
.GetString()) );
321 wxFAIL_MSG( _T("non-string columns not supported yet") );
326 wxgtk_list_store_iter_next (GtkTreeModel
*tree_model
,
329 g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model
), FALSE
);
330 GtkWxListStore
*list_store
= (GtkWxListStore
*) tree_model
;
332 g_return_val_if_fail (list_store
->stamp
== iter
->stamp
, FALSE
);
334 int n
= (wxUIntPtr
) iter
->user_data
;
339 if (n
>= (int) list_store
->model
->GetRowCount()-1)
342 iter
->user_data
= (gpointer
) ++n
;
348 wxgtk_list_store_iter_children (GtkTreeModel
*tree_model
,
352 g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model
), FALSE
);
353 GtkWxListStore
*list_store
= (GtkWxListStore
*) tree_model
;
355 // this is a list, nodes have no children
359 iter
->stamp
= list_store
->stamp
;
360 iter
->user_data
= (gpointer
) -1;
366 wxgtk_list_store_iter_has_child (GtkTreeModel
*tree_model
,
373 wxgtk_list_store_iter_n_children (GtkTreeModel
*tree_model
,
376 g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model
), -1);
377 GtkWxListStore
*list_store
= (GtkWxListStore
*) tree_model
;
380 return (gint
) list_store
->model
->GetRowCount();
382 g_return_val_if_fail (list_store
->stamp
== iter
->stamp
, -1);
388 wxgtk_list_store_iter_nth_child (GtkTreeModel
*tree_model
,
393 g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model
), FALSE
);
394 GtkWxListStore
*list_store
= (GtkWxListStore
*) tree_model
;
402 if (n
>= (gint
) list_store
->model
->GetRowCount())
405 iter
->stamp
= list_store
->stamp
;
406 iter
->user_data
= (gpointer
) n
;
412 wxgtk_list_store_iter_parent (GtkTreeModel
*tree_model
,
419 //-----------------------------------------------------------------------------
420 // define new GTK+ class wxGtkRendererRenderer
421 //-----------------------------------------------------------------------------
425 #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ())
426 #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer))
427 #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
428 #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER))
429 #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER))
430 #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
432 GType
gtk_wx_cell_renderer_get_type (void);
434 typedef struct _GtkWxCellRenderer GtkWxCellRenderer
;
435 typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass
;
437 struct _GtkWxCellRenderer
439 GtkCellRenderer parent
;
442 wxDataViewCustomRenderer
*cell
;
446 struct _GtkWxCellRendererClass
448 GtkCellRendererClass cell_parent_class
;
452 static GtkCellRenderer
*gtk_wx_cell_renderer_new (void);
453 static void gtk_wx_cell_renderer_init (
454 GtkWxCellRenderer
*cell
);
455 static void gtk_wx_cell_renderer_class_init(
456 GtkWxCellRendererClass
*klass
);
457 static void gtk_wx_cell_renderer_finalize (
459 static void gtk_wx_cell_renderer_get_size (
460 GtkCellRenderer
*cell
,
462 GdkRectangle
*rectangle
,
467 static void gtk_wx_cell_renderer_render (
468 GtkCellRenderer
*cell
,
471 GdkRectangle
*background_area
,
472 GdkRectangle
*cell_area
,
473 GdkRectangle
*expose_area
,
474 GtkCellRendererState flags
);
475 static gboolean
gtk_wx_cell_renderer_activate(
476 GtkCellRenderer
*cell
,
480 GdkRectangle
*background_area
,
481 GdkRectangle
*cell_area
,
482 GtkCellRendererState flags
);
483 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
484 GtkCellRenderer
*cell
,
488 GdkRectangle
*background_area
,
489 GdkRectangle
*cell_area
,
490 GtkCellRendererState flags
);
493 static GObjectClass
*cell_parent_class
= NULL
;
498 gtk_wx_cell_renderer_get_type (void)
500 static GType cell_wx_type
= 0;
504 const GTypeInfo cell_wx_info
=
506 sizeof (GtkWxCellRendererClass
),
507 NULL
, /* base_init */
508 NULL
, /* base_finalize */
509 (GClassInitFunc
) gtk_wx_cell_renderer_class_init
,
510 NULL
, /* class_finalize */
511 NULL
, /* class_data */
512 sizeof (GtkWxCellRenderer
),
514 (GInstanceInitFunc
) gtk_wx_cell_renderer_init
,
517 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER
,
518 "GtkWxCellRenderer", &cell_wx_info
, (GTypeFlags
)0 );
525 gtk_wx_cell_renderer_init (GtkWxCellRenderer
*cell
)
528 cell
->last_click
= 0;
532 gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass
*klass
)
534 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
535 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
537 cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
539 object_class
->finalize
= gtk_wx_cell_renderer_finalize
;
541 cell_class
->get_size
= gtk_wx_cell_renderer_get_size
;
542 cell_class
->render
= gtk_wx_cell_renderer_render
;
543 cell_class
->activate
= gtk_wx_cell_renderer_activate
;
544 cell_class
->start_editing
= gtk_wx_cell_renderer_start_editing
;
548 gtk_wx_cell_renderer_finalize (GObject
*object
)
551 (* G_OBJECT_CLASS (cell_parent_class
)->finalize
) (object
);
555 gtk_wx_cell_renderer_new (void)
557 return (GtkCellRenderer
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER
, NULL
);
562 static GtkCellEditable
*gtk_wx_cell_renderer_start_editing(
563 GtkCellRenderer
*renderer
,
567 GdkRectangle
*background_area
,
568 GdkRectangle
*cell_area
,
569 GtkCellRendererState flags
)
571 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
572 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
573 if (!cell
->HasEditorCtrl())
577 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
583 rect
.x
+= cell_area
->x
;
584 rect
.y
+= cell_area
->y
;
585 // rect.width -= renderer->xpad * 2;
586 // rect.height -= renderer->ypad * 2;
588 // wxRect renderrect( rect.x, rect.y, rect.width, rect.height );
589 wxRect
renderrect( cell_area
->x
, cell_area
->y
, cell_area
->width
, cell_area
->height
);
591 // wxDataViewListModel *model = cell->GetOwner()->GetOwner()->GetModel();
593 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
594 unsigned int model_row
= (unsigned int)gtk_tree_path_get_indices (treepath
)[0];
595 gtk_tree_path_free( treepath
);
597 cell
->StartEditing( model_row
, renderrect
);
603 gtk_wx_cell_renderer_get_size (GtkCellRenderer
*renderer
,
605 GdkRectangle
*cell_area
,
611 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
612 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
614 wxSize size
= cell
->GetSize();
616 gint calc_width
= (gint
) renderer
->xpad
* 2 + size
.x
;
617 gint calc_height
= (gint
) renderer
->ypad
* 2 + size
.y
;
624 if (cell_area
&& size
.x
> 0 && size
.y
> 0)
628 *x_offset
= (gint
)((renderer
->xalign
*
629 (cell_area
->width
- calc_width
- 2 * renderer
->xpad
)));
630 *x_offset
= MAX (*x_offset
, 0) + renderer
->xpad
;
634 *y_offset
= (gint
)((renderer
->yalign
*
635 (cell_area
->height
- calc_height
- 2 * renderer
->ypad
)));
636 *y_offset
= MAX (*y_offset
, 0) + renderer
->ypad
;
644 *height
= calc_height
;
648 gtk_wx_cell_renderer_render (GtkCellRenderer
*renderer
,
651 GdkRectangle
*background_area
,
652 GdkRectangle
*cell_area
,
653 GdkRectangle
*expose_area
,
654 GtkCellRendererState flags
)
657 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
658 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
661 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
667 rect
.x
+= cell_area
->x
;
668 rect
.y
+= cell_area
->y
;
669 rect
.width
-= renderer
->xpad
* 2;
670 rect
.height
-= renderer
->ypad
* 2;
673 if (gdk_rectangle_intersect (expose_area
, &rect
, &dummy
))
675 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
676 wxWindowDC
* dc
= (wxWindowDC
*) cell
->GetDC();
677 if (dc
->m_window
== NULL
)
679 dc
->m_window
= window
;
684 if (flags
& GTK_CELL_RENDERER_SELECTED
)
685 state
|= wxDATAVIEW_CELL_SELECTED
;
686 if (flags
& GTK_CELL_RENDERER_PRELIT
)
687 state
|= wxDATAVIEW_CELL_PRELIT
;
688 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
689 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
690 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
691 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
692 if (flags
& GTK_CELL_RENDERER_FOCUSED
)
693 state
|= wxDATAVIEW_CELL_FOCUSED
;
694 cell
->Render( renderrect
, dc
, state
);
699 gtk_wx_cell_renderer_activate(
700 GtkCellRenderer
*renderer
,
704 GdkRectangle
*background_area
,
705 GdkRectangle
*cell_area
,
706 GtkCellRendererState flags
)
708 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
709 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
712 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
718 rect
.x
+= cell_area
->x
;
719 rect
.y
+= cell_area
->y
;
720 rect
.width
-= renderer
->xpad
* 2;
721 rect
.height
-= renderer
->ypad
* 2;
723 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
725 wxDataViewListModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
727 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
728 unsigned int model_row
= (unsigned int)gtk_tree_path_get_indices (treepath
)[0];
729 gtk_tree_path_free( treepath
);
731 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
737 // activated by <ENTER>
738 if (cell
->Activate( renderrect
, model
, model_col
, model_row
))
743 else if (event
->type
== GDK_BUTTON_PRESS
)
745 GdkEventButton
*button_event
= (GdkEventButton
*) event
;
746 wxPoint
pt( ((int) button_event
->x
) - renderrect
.x
,
747 ((int) button_event
->y
) - renderrect
.y
);
750 if (button_event
->button
== 1)
752 if (cell
->LeftClick( pt
, renderrect
, model
, model_col
, model_row
))
754 // TODO: query system double-click time
755 if (button_event
->time
- wxrenderer
->last_click
< 400)
756 if (cell
->Activate( renderrect
, model
, model_col
, model_row
))
759 if (button_event
->button
== 3)
761 if (cell
->RightClick( pt
, renderrect
, model
, model_col
, model_row
))
765 wxrenderer
->last_click
= button_event
->time
;
773 // ---------------------------------------------------------
774 // wxGtkDataViewListModelNotifier
775 // ---------------------------------------------------------
777 class wxGtkDataViewListModelNotifier
: public wxDataViewListModelNotifier
780 wxGtkDataViewListModelNotifier( GtkWxListStore
* gtk_store
,
781 wxDataViewListModel
*wx_model
,
782 wxDataViewCtrl
* ctrl
);
783 ~wxGtkDataViewListModelNotifier();
785 virtual bool RowAppended();
786 virtual bool RowPrepended();
787 virtual bool RowInserted( unsigned int before
);
788 virtual bool RowDeleted( unsigned int row
);
789 virtual bool RowChanged( unsigned int row
);
790 virtual bool ValueChanged( unsigned int col
, unsigned int row
);
791 virtual bool RowsReordered( unsigned int *new_order
);
792 virtual bool Cleared();
794 GtkWxListStore
*m_gtk_store
;
795 wxDataViewListModel
*m_wx_model
;
796 wxDataViewCtrl
*m_owner
;
799 // ---------------------------------------------------------
800 // wxGtkDataViewListModelNotifier
801 // ---------------------------------------------------------
803 wxGtkDataViewListModelNotifier::wxGtkDataViewListModelNotifier(
804 GtkWxListStore
* gtk_store
, wxDataViewListModel
*wx_model
,
805 wxDataViewCtrl
*ctrl
)
807 m_gtk_store
= gtk_store
;
808 m_wx_model
= wx_model
;
812 wxGtkDataViewListModelNotifier::~wxGtkDataViewListModelNotifier()
818 bool wxGtkDataViewListModelNotifier::RowAppended()
820 unsigned int pos
= m_wx_model
->GetRowCount()-1;
823 iter
.stamp
= m_gtk_store
->stamp
;
824 iter
.user_data
= (gpointer
) pos
;
826 GtkTreePath
*path
= gtk_tree_path_new ();
827 gtk_tree_path_append_index (path
, (gint
) pos
);
828 gtk_tree_model_row_inserted (GTK_TREE_MODEL (m_gtk_store
), path
, &iter
);
829 gtk_tree_path_free (path
);
834 bool wxGtkDataViewListModelNotifier::RowPrepended()
837 iter
.stamp
= m_gtk_store
->stamp
;
838 iter
.user_data
= (gpointer
) 0;
840 GtkTreePath
*path
= gtk_tree_path_new ();
841 gtk_tree_path_append_index (path
, (gint
) 0);
842 gtk_tree_model_row_inserted (GTK_TREE_MODEL (m_gtk_store
), path
, &iter
);
843 gtk_tree_path_free (path
);
848 bool wxGtkDataViewListModelNotifier::RowInserted( unsigned int before
)
851 iter
.stamp
= m_gtk_store
->stamp
;
852 iter
.user_data
= (gpointer
) before
;
854 GtkTreePath
*path
= gtk_tree_path_new ();
855 gtk_tree_path_append_index (path
, (gint
) before
);
856 gtk_tree_model_row_inserted (GTK_TREE_MODEL (m_gtk_store
), path
, &iter
);
857 gtk_tree_path_free (path
);
862 bool wxGtkDataViewListModelNotifier::RowDeleted( unsigned int row
)
864 GtkTreePath
*path
= gtk_tree_path_new ();
865 gtk_tree_path_append_index (path
, (gint
) row
);
866 gtk_tree_model_row_deleted (GTK_TREE_MODEL (m_gtk_store
), path
);
867 gtk_tree_path_free (path
);
872 bool wxGtkDataViewListModelNotifier::RowChanged( unsigned int row
)
875 iter
.stamp
= m_gtk_store
->stamp
;
876 iter
.user_data
= (gpointer
) row
;
877 GtkTreePath
*path
= gtk_tree_model_get_path (GTK_TREE_MODEL (m_gtk_store
), &iter
);
878 gtk_tree_model_row_changed (GTK_TREE_MODEL (m_gtk_store
), path
, &iter
);
879 gtk_tree_path_free (path
);
884 bool wxGtkDataViewListModelNotifier::ValueChanged( unsigned int model_col
, unsigned int model_row
)
886 // This adds GTK+'s missing MVC logic for ValueChanged
888 for (index
= 0; index
< m_owner
->GetColumnCount(); index
++)
890 wxDataViewColumn
*column
= m_owner
->GetColumn( index
);
891 if (column
->GetModelColumn() == model_col
)
893 GtkTreeView
*widget
= GTK_TREE_VIEW(m_owner
->m_treeview
);
894 GtkTreeViewColumn
*gcolumn
= GTK_TREE_VIEW_COLUMN(column
->GetGtkHandle());
897 GtkTreePath
*path
= gtk_tree_path_new();
898 gtk_tree_path_append_index( path
, model_row
);
899 GdkRectangle cell_area
;
900 gtk_tree_view_get_cell_area( widget
, path
, gcolumn
, &cell_area
);
901 gtk_tree_path_free( path
);
903 GtkAdjustment
* hadjust
= gtk_tree_view_get_hadjustment( widget
);
904 double d
= gtk_adjustment_get_value( hadjust
);
907 int ydiff
= gcolumn
->button
->allocation
.height
;
909 gtk_widget_queue_draw_area( GTK_WIDGET(widget
),
910 cell_area
.x
- xdiff
, ydiff
+ cell_area
.y
, cell_area
.width
, cell_area
.height
);
917 bool wxGtkDataViewListModelNotifier::RowsReordered( unsigned int *new_order
)
919 // Assume sizeof(unsigned int)= == sizeof(gint)
921 GtkTreePath
*path
= gtk_tree_path_new ();
922 gtk_tree_model_rows_reordered (GTK_TREE_MODEL (m_gtk_store
), path
, NULL
, (gint
*)new_order
);
923 gtk_tree_path_free (path
);
925 // This adds GTK+'s missing MVC logic for RowsReordered
926 GtkTreeView
*widget
= GTK_TREE_VIEW(m_owner
->m_treeview
);
927 // Doesn't work yet...
928 gtk_widget_queue_draw( GTK_WIDGET(widget
) );
933 bool wxGtkDataViewListModelNotifier::Cleared()
938 // ---------------------------------------------------------
939 // wxDataViewRenderer
940 // ---------------------------------------------------------
942 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
944 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
946 wxDataViewRendererBase( varianttype
, mode
, align
)
950 // NOTE: SetMode() and SetAlignment() needs to be called in the renderer's ctor,
951 // after the m_renderer pointer has been initialized
954 void wxDataViewRenderer::SetMode( wxDataViewCellMode mode
)
956 GtkCellRendererMode gtkMode
;
959 case wxDATAVIEW_CELL_INERT
:
960 gtkMode
= GTK_CELL_RENDERER_MODE_INERT
;
962 case wxDATAVIEW_CELL_ACTIVATABLE
:
963 gtkMode
= GTK_CELL_RENDERER_MODE_ACTIVATABLE
;
965 case wxDATAVIEW_CELL_EDITABLE
:
966 gtkMode
= GTK_CELL_RENDERER_MODE_EDITABLE
;
970 GValue gvalue
= { 0, };
971 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
972 g_value_set_enum( &gvalue
, gtkMode
);
973 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue
);
974 g_value_unset( &gvalue
);
977 wxDataViewCellMode
wxDataViewRenderer::GetMode() const
979 wxDataViewCellMode ret
;
982 g_object_get( G_OBJECT(m_renderer
), "mode", &gvalue
, NULL
);
984 switch (g_value_get_enum(&gvalue
))
986 case GTK_CELL_RENDERER_MODE_INERT
:
987 ret
= wxDATAVIEW_CELL_INERT
;
989 case GTK_CELL_RENDERER_MODE_ACTIVATABLE
:
990 ret
= wxDATAVIEW_CELL_ACTIVATABLE
;
992 case GTK_CELL_RENDERER_MODE_EDITABLE
:
993 ret
= wxDATAVIEW_CELL_EDITABLE
;
997 g_value_unset( &gvalue
);
1002 void wxDataViewRenderer::SetAlignment( int align
)
1004 // horizontal alignment:
1006 gfloat xalign
= 0.0;
1007 if (align
& wxALIGN_RIGHT
)
1009 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1012 GValue gvalue
= { 0, };
1013 g_value_init( &gvalue
, G_TYPE_FLOAT
);
1014 g_value_set_float( &gvalue
, xalign
);
1015 g_object_set_property( G_OBJECT(m_renderer
), "xalign", &gvalue
);
1016 g_value_unset( &gvalue
);
1018 // vertical alignment:
1020 gfloat yalign
= 0.0;
1021 if (align
& wxALIGN_BOTTOM
)
1023 else if (align
& wxALIGN_CENTER_VERTICAL
)
1026 GValue gvalue2
= { 0, };
1027 g_value_init( &gvalue2
, G_TYPE_FLOAT
);
1028 g_value_set_float( &gvalue2
, yalign
);
1029 g_object_set_property( G_OBJECT(m_renderer
), "yalign", &gvalue2
);
1030 g_value_unset( &gvalue2
);
1033 int wxDataViewRenderer::GetAlignment() const
1038 // horizontal alignment:
1040 g_object_get( G_OBJECT(m_renderer
), "xalign", &gvalue
, NULL
);
1041 float xalign
= g_value_get_float( &gvalue
);
1043 ret
|= wxALIGN_LEFT
;
1044 else if (xalign
== 0.5)
1045 ret
|= wxALIGN_CENTER_HORIZONTAL
;
1047 ret
|= wxALIGN_RIGHT
;
1048 g_value_unset( &gvalue
);
1051 // vertical alignment:
1053 g_object_get( G_OBJECT(m_renderer
), "yalign", &gvalue
, NULL
);
1054 float yalign
= g_value_get_float( &gvalue
);
1057 else if (yalign
== 0.5)
1058 ret
|= wxALIGN_CENTER_VERTICAL
;
1060 ret
|= wxALIGN_BOTTOM
;
1061 g_value_unset( &gvalue
);
1068 // ---------------------------------------------------------
1069 // wxDataViewTextRenderer
1070 // ---------------------------------------------------------
1073 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
1074 gchar
*arg1
, gchar
*arg2
, gpointer user_data
);
1077 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
1078 gchar
*arg1
, gchar
*arg2
, gpointer user_data
)
1080 wxDataViewTextRenderer
*cell
= (wxDataViewTextRenderer
*) user_data
;
1082 wxString tmp
= wxGTK_CONV_BACK_FONT(arg2
, cell
->GetOwner()->GetOwner()->GetFont());
1083 wxVariant value
= tmp
;
1084 if (!cell
->Validate( value
))
1087 wxDataViewListModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1089 GtkTreePath
*path
= gtk_tree_path_new_from_string( arg1
);
1090 unsigned int model_row
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
1091 gtk_tree_path_free( path
);
1093 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1095 model
->SetValue( value
, model_col
, model_row
);
1096 model
->ValueChanged( model_col
, model_row
);
1099 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
1101 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1103 wxDataViewRenderer( varianttype
, mode
, align
)
1105 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_text_new();
1107 if (mode
& wxDATAVIEW_CELL_EDITABLE
)
1109 GValue gvalue
= { 0, };
1110 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1111 g_value_set_boolean( &gvalue
, true );
1112 g_object_set_property( G_OBJECT(m_renderer
), "editable", &gvalue
);
1113 g_value_unset( &gvalue
);
1115 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
1119 SetAlignment(align
);
1122 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
1124 wxString tmp
= value
;
1126 GValue gvalue
= { 0, };
1127 g_value_init( &gvalue
, G_TYPE_STRING
);
1128 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( tmp
, GetOwner()->GetOwner()->GetFont() ) );
1129 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1130 g_value_unset( &gvalue
);
1135 bool wxDataViewTextRenderer::GetValue( wxVariant
&value
) const
1137 GValue gvalue
= { 0, };
1138 g_value_init( &gvalue
, G_TYPE_STRING
);
1139 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1140 wxString tmp
= wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue
),
1141 wx_const_cast(wxDataViewTextRenderer
*, this)->GetOwner()->GetOwner()->GetFont() );
1142 g_value_unset( &gvalue
);
1149 void wxDataViewTextRenderer::SetAlignment( int align
)
1151 wxDataViewRenderer::SetAlignment(align
);
1153 if (gtk_check_version(2,10,0))
1156 // horizontal alignment:
1157 PangoAlignment pangoAlign
= PANGO_ALIGN_LEFT
;
1158 if (align
& wxALIGN_RIGHT
)
1159 pangoAlign
= PANGO_ALIGN_RIGHT
;
1160 else if (align
& wxALIGN_CENTER_HORIZONTAL
)
1161 pangoAlign
= PANGO_ALIGN_CENTER
;
1163 GValue gvalue
= { 0, };
1164 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1165 g_value_set_enum( &gvalue
, pangoAlign
);
1166 g_object_set_property( G_OBJECT(m_renderer
), "alignment", &gvalue
);
1167 g_value_unset( &gvalue
);
1170 // ---------------------------------------------------------
1171 // wxDataViewBitmapRenderer
1172 // ---------------------------------------------------------
1174 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
1176 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
,
1178 wxDataViewRenderer( varianttype
, mode
, align
)
1180 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_pixbuf_new();
1183 SetAlignment(align
);
1186 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
1188 if (value
.GetType() == wxT("wxBitmap"))
1193 // This may create a Pixbuf representation in the
1194 // wxBitmap object (and it will stay there)
1195 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1197 GValue gvalue
= { 0, };
1198 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1199 g_value_set_object( &gvalue
, pixbuf
);
1200 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1201 g_value_unset( &gvalue
);
1206 if (value
.GetType() == wxT("wxIcon"))
1211 // This may create a Pixbuf representation in the
1212 // wxBitmap object (and it will stay there)
1213 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1215 GValue gvalue
= { 0, };
1216 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1217 g_value_set_object( &gvalue
, pixbuf
);
1218 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1219 g_value_unset( &gvalue
);
1227 bool wxDataViewBitmapRenderer::GetValue( wxVariant
&value
) const
1232 // ---------------------------------------------------------
1233 // wxDataViewToggleRenderer
1234 // ---------------------------------------------------------
1237 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1238 gchar
*path
, gpointer user_data
);
1241 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1242 gchar
*path
, gpointer user_data
)
1244 wxDataViewToggleRenderer
*cell
= (wxDataViewToggleRenderer
*) user_data
;
1247 GValue gvalue
= { 0, };
1248 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1249 g_object_get_property( G_OBJECT(renderer
), "active", &gvalue
);
1250 bool tmp
= g_value_get_boolean( &gvalue
);
1251 g_value_unset( &gvalue
);
1255 wxVariant value
= tmp
;
1256 if (!cell
->Validate( value
))
1259 wxDataViewListModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1261 GtkTreePath
*gtk_path
= gtk_tree_path_new_from_string( path
);
1262 unsigned int model_row
= (unsigned int)gtk_tree_path_get_indices (gtk_path
)[0];
1263 gtk_tree_path_free( gtk_path
);
1265 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1267 model
->SetValue( value
, model_col
, model_row
);
1268 model
->ValueChanged( model_col
, model_row
);
1271 IMPLEMENT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
1273 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
1274 wxDataViewCellMode mode
, int align
) :
1275 wxDataViewRenderer( varianttype
, mode
, align
)
1277 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_toggle_new();
1279 if (mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
1281 g_signal_connect_after( m_renderer
, "toggled",
1282 G_CALLBACK(wxGtkToggleRendererToggledCallback
), this );
1286 GValue gvalue
= { 0, };
1287 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1288 g_value_set_boolean( &gvalue
, false );
1289 g_object_set_property( G_OBJECT(m_renderer
), "activatable", &gvalue
);
1290 g_value_unset( &gvalue
);
1294 SetAlignment(align
);
1297 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
1301 GValue gvalue
= { 0, };
1302 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1303 g_value_set_boolean( &gvalue
, tmp
);
1304 g_object_set_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1305 g_value_unset( &gvalue
);
1310 bool wxDataViewToggleRenderer::GetValue( wxVariant
&value
) const
1312 GValue gvalue
= { 0, };
1313 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1314 g_object_get_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1315 bool tmp
= g_value_get_boolean( &gvalue
);
1316 g_value_unset( &gvalue
);
1323 // ---------------------------------------------------------
1324 // wxDataViewCustomRenderer
1325 // ---------------------------------------------------------
1327 class wxDataViewCtrlDC
: public wxWindowDC
1330 wxDataViewCtrlDC( wxDataViewCtrl
*window
)
1332 GtkWidget
*widget
= window
->m_treeview
;
1336 m_context
= window
->GtkGetPangoDefaultContext();
1337 m_layout
= pango_layout_new( m_context
);
1338 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
1340 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
1342 // Set m_window later
1344 // m_owner = window;
1348 // ---------------------------------------------------------
1349 // wxDataViewCustomRenderer
1350 // ---------------------------------------------------------
1352 IMPLEMENT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
1354 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
1355 wxDataViewCellMode mode
, int align
,
1357 wxDataViewRenderer( varianttype
, mode
, align
)
1367 bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode
, int align
)
1369 GtkWxCellRenderer
*renderer
= (GtkWxCellRenderer
*) gtk_wx_cell_renderer_new();
1370 renderer
->cell
= this;
1372 m_renderer
= (GtkCellRenderer
*) renderer
;
1375 SetAlignment(align
);
1380 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
1386 wxDC
*wxDataViewCustomRenderer::GetDC()
1390 if (GetOwner() == NULL
)
1392 if (GetOwner()->GetOwner() == NULL
)
1394 m_dc
= new wxDataViewCtrlDC( GetOwner()->GetOwner() );
1400 // ---------------------------------------------------------
1401 // wxDataViewProgressRenderer
1402 // ---------------------------------------------------------
1404 IMPLEMENT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
1406 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
1407 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1408 wxDataViewCustomRenderer( varianttype
, mode
, align
, true )
1414 if (!gtk_check_version(2,6,0))
1416 m_renderer
= (GtkCellRenderer
*) gtk_cell_renderer_progress_new();
1418 GValue gvalue
= { 0, };
1419 g_value_init( &gvalue
, G_TYPE_STRING
);
1421 // FIXME: font encoding support
1422 g_value_set_string( &gvalue
, wxGTK_CONV_SYS(m_label
) );
1423 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1424 g_value_unset( &gvalue
);
1427 SetAlignment(align
);
1432 // Use custom cell code
1433 wxDataViewCustomRenderer::Init(mode
, align
);
1437 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
1441 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
1444 if (!gtk_check_version(2,6,0))
1446 gint tmp
= (long) value
;
1447 GValue gvalue
= { 0, };
1448 g_value_init( &gvalue
, G_TYPE_INT
);
1449 g_value_set_int( &gvalue
, tmp
);
1450 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
1451 g_value_unset( &gvalue
);
1456 m_value
= (long) value
;
1458 if (m_value
< 0) m_value
= 0;
1459 if (m_value
> 100) m_value
= 100;
1465 bool wxDataViewProgressRenderer::GetValue( wxVariant
&value
) const
1470 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1472 double pct
= (double)m_value
/ 100.0;
1474 bar
.width
= (int)(cell
.width
* pct
);
1475 dc
->SetPen( *wxTRANSPARENT_PEN
);
1476 dc
->SetBrush( *wxBLUE_BRUSH
);
1477 dc
->DrawRectangle( bar
);
1479 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1480 dc
->SetPen( *wxBLACK_PEN
);
1481 dc
->DrawRectangle( cell
);
1486 wxSize
wxDataViewProgressRenderer::GetSize() const
1488 return wxSize(40,12);
1491 // ---------------------------------------------------------
1492 // wxDataViewDateRenderer
1493 // ---------------------------------------------------------
1495 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
1498 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
1499 wxDataViewListModel
*model
, unsigned int col
, unsigned int row
) :
1500 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
1505 m_cal
= new wxCalendarCtrl( this, -1, *value
);
1506 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
1507 sizer
->Add( m_cal
, 1, wxGROW
);
1512 virtual void OnDismiss()
1516 void OnCalendar( wxCalendarEvent
&event
);
1518 wxCalendarCtrl
*m_cal
;
1519 wxDataViewListModel
*m_model
;
1524 DECLARE_EVENT_TABLE()
1527 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
1528 EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar
)
1531 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
1533 wxDateTime date
= event
.GetDate();
1534 wxVariant value
= date
;
1535 m_model
->SetValue( value
, m_col
, m_row
);
1536 m_model
->ValueChanged( m_col
, m_row
);
1540 IMPLEMENT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
1542 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
1543 wxDataViewCellMode mode
, int align
) :
1544 wxDataViewCustomRenderer( varianttype
, mode
, align
)
1547 SetAlignment(align
);
1550 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
1552 m_date
= value
.GetDateTime();
1557 bool wxDataViewDateRenderer::GetValue( wxVariant
&value
) const
1562 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1564 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
1565 wxString tmp
= m_date
.FormatDate();
1566 dc
->DrawText( tmp
, cell
.x
, cell
.y
);
1571 wxSize
wxDataViewDateRenderer::GetSize() const
1573 wxString tmp
= m_date
.FormatDate();
1575 GetView()->GetTextExtent( tmp
, &x
, &y
, &d
);
1576 return wxSize(x
,y
+d
);
1579 bool wxDataViewDateRenderer::Activate( wxRect cell
, wxDataViewListModel
*model
,
1580 unsigned int col
, unsigned int row
)
1583 model
->GetValue( variant
, col
, row
);
1584 wxDateTime value
= variant
.GetDateTime();
1586 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
1587 GetOwner()->GetOwner()->GetParent(), &value
, model
, col
, row
);
1588 wxPoint pos
= wxGetMousePosition();
1591 popup
->Popup( popup
->m_cal
);
1596 // ---------------------------------------------------------
1598 // ---------------------------------------------------------
1602 gtk_dataview_header_button_press_callback( GtkWidget
*widget
,
1603 GdkEventButton
*gdk_event
,
1604 wxDataViewColumn
*column
)
1606 if (gdk_event
->type
!= GDK_BUTTON_PRESS
)
1609 if (gdk_event
->button
== 1)
1611 wxDataViewCtrl
*dv
= column
->GetOwner();
1612 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, dv
->GetId() );
1613 event
.SetDataViewColumn( column
);
1614 event
.SetModel( dv
->GetModel() );
1615 dv
->GetEventHandler()->ProcessEvent( event
);
1622 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
1623 GtkCellRenderer
*cell
,
1624 GtkTreeModel
*model
,
1630 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
1631 GtkCellRenderer
*renderer
,
1632 GtkTreeModel
*model
,
1636 g_return_if_fail (GTK_IS_WX_LIST_STORE (model
));
1637 GtkWxListStore
*list_store
= (GtkWxListStore
*) model
;
1639 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
1641 unsigned int model_row
= wxPtrToUInt(iter
->user_data
);
1644 list_store
->model
->GetValue( value
, cell
->GetOwner()->GetModelColumn(), model_row
);
1646 if (value
.GetType() != cell
->GetVariantType())
1647 wxLogError( wxT("Wrong type, required: %s but: %s"),
1648 value
.GetType().c_str(),
1649 cell
->GetVariantType().c_str() );
1651 cell
->SetValue( value
);
1653 wxListItemAttr attr
;
1654 list_store
->model
->GetAttr( attr
, cell
->GetOwner()->GetModelColumn(), model_row
);
1656 if (attr
.HasBackgroundColour())
1658 wxColour colour
= attr
.GetBackgroundColour();
1659 const GdkColor
* const gcol
= colour
.GetColor();
1661 GValue gvalue
= { 0, };
1662 g_value_init( &gvalue
, GDK_TYPE_COLOR
);
1663 g_value_set_boxed( &gvalue
, gcol
);
1664 g_object_set_property( G_OBJECT(renderer
), "cell-background_gdk", &gvalue
);
1665 g_value_unset( &gvalue
);
1669 GValue gvalue
= { 0, };
1670 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1671 g_value_set_boolean( &gvalue
, FALSE
);
1672 g_object_set_property( G_OBJECT(renderer
), "cell-background-set", &gvalue
);
1673 g_value_unset( &gvalue
);
1677 IMPLEMENT_CLASS(wxDataViewColumn
, wxDataViewColumnBase
)
1679 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
1680 unsigned int model_column
, int width
,
1681 wxAlignment align
, int flags
) :
1682 wxDataViewColumnBase( title
, cell
, model_column
, width
, align
, flags
)
1684 Init( align
, flags
, width
);
1686 gtk_tree_view_column_set_clickable( GTK_TREE_VIEW_COLUMN(m_column
), TRUE
);
1690 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
1691 unsigned int model_column
, int width
,
1692 wxAlignment align
, int flags
) :
1693 wxDataViewColumnBase( bitmap
, cell
, model_column
, width
, align
, flags
)
1695 Init( align
, flags
, width
);
1697 SetBitmap( bitmap
);
1700 void wxDataViewColumn::Init(wxAlignment align
, int flags
, int width
)
1702 m_isConnected
= false;
1704 GtkCellRenderer
*renderer
= (GtkCellRenderer
*) GetRenderer()->GetGtkHandle();
1705 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
1706 m_column
= (GtkWidget
*) column
;
1709 SetAlignment( align
);
1711 // NOTE: we prefer not to call SetMinWidth(wxDVC_DEFAULT_MINWIDTH);
1712 // as GTK+ is smart and unless explicitely told, will set the minimal
1713 // width to the title's lenght, which is a better default
1715 // the GTK_TREE_VIEW_COLUMN_FIXED is required by the "fixed height" mode
1716 // that we use for the wxDataViewCtrl
1717 gtk_tree_view_column_set_fixed_width( column
, width
< 0 ? wxDVC_DEFAULT_WIDTH
: width
);
1718 gtk_tree_view_column_set_sizing( column
, GTK_TREE_VIEW_COLUMN_FIXED
);
1720 gtk_tree_view_column_pack_end( column
, renderer
, TRUE
);
1722 gtk_tree_view_column_set_cell_data_func( column
, renderer
,
1723 wxGtkTreeCellDataFunc
, (gpointer
) GetRenderer(), NULL
);
1726 wxDataViewColumn::~wxDataViewColumn()
1730 void wxDataViewColumn::OnInternalIdle()
1735 if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview
))
1737 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
1740 g_signal_connect(column
->button
, "button_press_event",
1741 G_CALLBACK (gtk_dataview_header_button_press_callback
), this);
1743 m_isConnected
= true;
1748 void wxDataViewColumn::SetOwner( wxDataViewCtrl
*owner
)
1750 wxDataViewColumnBase::SetOwner( owner
);
1752 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
1754 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
1757 void wxDataViewColumn::SetTitle( const wxString
&title
)
1759 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
1763 // disconnect before column->button gets recreated
1764 g_signal_handlers_disconnect_by_func( column
->button
,
1765 (GtkWidget
*) gtk_dataview_header_button_press_callback
, this);
1767 m_isConnected
= false;
1770 // FIXME: can it really happen that we don't have the owner here??
1771 wxDataViewCtrl
*ctrl
= GetOwner();
1772 gtk_tree_view_column_set_title( column
, ctrl
? wxGTK_CONV_FONT(title
, ctrl
->GetFont())
1773 : wxGTK_CONV_SYS(title
) );
1775 gtk_tree_view_column_set_widget( column
, NULL
);
1778 wxString
wxDataViewColumn::GetTitle() const
1780 const gchar
*str
= gtk_tree_view_column_get_title( GTK_TREE_VIEW_COLUMN(m_column
) );
1781 return wxConvFileName
->cMB2WX(str
);
1784 void wxDataViewColumn::SetBitmap( const wxBitmap
&bitmap
)
1786 wxDataViewColumnBase::SetBitmap( bitmap
);
1788 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
1791 GtkImage
*gtk_image
= GTK_IMAGE( gtk_image_new() );
1793 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
1794 if (bitmap
.GetMask())
1795 mask
= bitmap
.GetMask()->GetBitmap();
1797 if (bitmap
.HasPixbuf())
1799 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image
),
1800 bitmap
.GetPixbuf());
1804 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image
),
1805 bitmap
.GetPixmap(), mask
);
1807 gtk_widget_show( GTK_WIDGET(gtk_image
) );
1809 gtk_tree_view_column_set_widget( column
, GTK_WIDGET(gtk_image
) );
1813 gtk_tree_view_column_set_widget( column
, NULL
);
1817 void wxDataViewColumn::SetHidden( bool hidden
)
1819 gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column
), !hidden
);
1822 void wxDataViewColumn::SetResizeable( bool resizeable
)
1824 gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column
), resizeable
);
1827 void wxDataViewColumn::SetAlignment( wxAlignment align
)
1829 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
1831 gfloat xalign
= 0.0;
1832 if (align
== wxALIGN_RIGHT
)
1834 if (align
== wxALIGN_CENTER_HORIZONTAL
||
1835 align
== wxALIGN_CENTER
)
1838 gtk_tree_view_column_set_alignment( column
, xalign
);
1841 wxAlignment
wxDataViewColumn::GetAlignment() const
1843 gfloat xalign
= gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column
) );
1846 return wxALIGN_RIGHT
;
1848 return wxALIGN_CENTER_HORIZONTAL
;
1850 return wxALIGN_LEFT
;
1853 void wxDataViewColumn::SetSortable( bool sortable
)
1855 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
1856 gtk_tree_view_column_set_sort_indicator( column
, sortable
);
1859 bool wxDataViewColumn::IsSortable() const
1861 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
1862 return gtk_tree_view_column_get_sort_indicator( column
);
1865 bool wxDataViewColumn::IsResizeable() const
1867 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
1868 return gtk_tree_view_column_get_resizable( column
);
1871 bool wxDataViewColumn::IsHidden() const
1873 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
1874 return !gtk_tree_view_column_get_visible( column
);
1877 void wxDataViewColumn::SetSortOrder( bool ascending
)
1879 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
1882 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_ASCENDING
);
1884 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_DESCENDING
);
1887 bool wxDataViewColumn::IsSortOrderAscending() const
1889 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(m_column
);
1891 return (gtk_tree_view_column_get_sort_order( column
) != GTK_SORT_DESCENDING
);
1894 void wxDataViewColumn::SetMinWidth( int width
)
1896 gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
1899 int wxDataViewColumn::GetMinWidth() const
1901 return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column
) );
1904 int wxDataViewColumn::GetWidth() const
1906 return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column
) );
1909 void wxDataViewColumn::SetWidth( int width
)
1911 gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column
), width
);
1915 //-----------------------------------------------------------------------------
1916 // wxDataViewCtrl signal callbacks
1917 //-----------------------------------------------------------------------------
1920 wxdataview_selection_changed_callback( GtkTreeSelection
* selection
, wxDataViewCtrl
*dv
)
1922 if (!GTK_WIDGET_REALIZED(dv
->m_widget
))
1925 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ROW_SELECTED
, dv
->GetId() );
1926 event
.SetRow( dv
->GetSelection() );
1927 event
.SetModel( dv
->GetModel() );
1928 dv
->GetEventHandler()->ProcessEvent( event
);
1932 wxdataview_row_activated_callback( GtkTreeView
* treeview
, GtkTreePath
*path
,
1933 GtkTreeViewColumn
*column
, wxDataViewCtrl
*dv
)
1935 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ROW_ACTIVATED
, dv
->GetId() );
1936 unsigned int row
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
1937 event
.SetRow( row
);
1938 event
.SetModel( dv
->GetModel() );
1939 dv
->GetEventHandler()->ProcessEvent( event
);
1942 //-----------------------------------------------------------------------------
1944 //-----------------------------------------------------------------------------
1946 //-----------------------------------------------------------------------------
1947 // InsertChild for wxDataViewCtrl
1948 //-----------------------------------------------------------------------------
1950 static void wxInsertChildInDataViewCtrl( wxWindowGTK
* parent
, wxWindowGTK
* child
)
1952 wxDataViewCtrl
* dvc
= (wxDataViewCtrl
*) parent
;
1953 GtkWidget
*treeview
= dvc
->GtkGetTreeView();
1955 // Insert widget in GtkTreeView
1956 if (GTK_WIDGET_REALIZED(treeview
))
1957 gtk_widget_set_parent_window( child
->m_widget
,
1958 gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview
) ) );
1959 gtk_widget_set_parent( child
->m_widget
, treeview
);
1963 void gtk_dataviewctrl_size_callback( GtkWidget
*WXUNUSED(widget
),
1964 GtkAllocation
*alloc
,
1965 wxDataViewCtrl
*win
)
1968 wxWindowList::Node
*node
= win
->GetChildren().GetFirst();
1971 wxWindow
*child
= node
->GetData();
1974 gtk_widget_size_request( child
->m_widget
, &req
);
1976 GtkAllocation alloc
;
1977 alloc
.x
= child
->m_x
;
1978 alloc
.y
= child
->m_y
;
1979 alloc
.width
= child
->m_width
;
1980 alloc
.height
= child
->m_height
;
1981 gtk_widget_size_allocate( child
->m_widget
, &alloc
);
1983 node
= node
->GetNext();
1989 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
1991 wxDataViewCtrl::~wxDataViewCtrl()
1994 GetModel()->RemoveNotifier( m_notifier
);
1996 // remove the model from the GtkTreeView before it gets destroyed by the
1997 // wxDataViewCtrlBase's dtor
1998 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), NULL
);
2001 void wxDataViewCtrl::Init()
2006 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
2007 const wxPoint
& pos
, const wxSize
& size
,
2008 long style
, const wxValidator
& validator
)
2012 if (!PreCreation( parent
, pos
, size
) ||
2013 !CreateBase( parent
, id
, pos
, size
, style
, validator
))
2015 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
2019 m_insertCallback
= wxInsertChildInDataViewCtrl
;
2021 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
2023 GtkScrolledWindowSetBorder(m_widget
, style
);
2025 m_treeview
= gtk_tree_view_new();
2026 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
2028 g_signal_connect (m_treeview
, "size_allocate",
2029 G_CALLBACK (gtk_dataviewctrl_size_callback
), this);
2032 if (!gtk_check_version(2,6,0))
2033 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), TRUE
);
2036 if (style
& wxDV_MULTIPLE
)
2038 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
2039 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
2042 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_NO_HEADER
) == 0 );
2045 if (!gtk_check_version(2,10,0))
2047 GtkTreeViewGridLines grid
= GTK_TREE_VIEW_GRID_LINES_NONE
;
2049 if ((style
& wxDV_HORIZ_RULES
) != 0 &&
2050 (style
& wxDV_VERT_RULES
) != 0)
2051 grid
= GTK_TREE_VIEW_GRID_LINES_BOTH
;
2052 else if (style
& wxDV_VERT_RULES
)
2053 grid
= GTK_TREE_VIEW_GRID_LINES_VERTICAL
;
2054 else if (style
& wxDV_HORIZ_RULES
)
2055 grid
= GTK_TREE_VIEW_GRID_LINES_HORIZONTAL
;
2057 gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview
), grid
);
2062 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview
), (style
& wxDV_HORIZ_RULES
) != 0 );
2065 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
2066 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
);
2067 gtk_widget_show (m_treeview
);
2069 m_parent
->DoAddChild( this );
2073 GtkEnableSelectionEvents();
2075 g_signal_connect_after (m_treeview
, "row_activated",
2076 G_CALLBACK (wxdataview_row_activated_callback
), this);
2081 void wxDataViewCtrl::OnInternalIdle()
2083 wxWindow::OnInternalIdle();
2085 unsigned int cols
= GetColumnCount();
2087 for (i
= 0; i
< cols
; i
++)
2089 wxDataViewColumn
*col
= GetColumn( i
);
2090 col
->OnInternalIdle();
2094 bool wxDataViewCtrl::AssociateModel( wxDataViewListModel
*model
)
2096 if (!wxDataViewCtrlBase::AssociateModel( model
))
2099 GtkWxListStore
*gtk_store
= wxgtk_list_store_new();
2100 gtk_store
->model
= model
;
2102 m_notifier
= new wxGtkDataViewListModelNotifier( gtk_store
, model
, this );
2104 model
->AddNotifier( m_notifier
);
2106 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), GTK_TREE_MODEL(gtk_store
) );
2107 g_object_unref( gtk_store
);
2112 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
2114 if (!wxDataViewCtrlBase::AppendColumn(col
))
2117 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)col
->GetGtkHandle();
2119 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
), column
);
2124 void wxDataViewCtrl::GtkDisableSelectionEvents()
2126 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
2127 g_signal_connect_after (selection
, "changed",
2128 G_CALLBACK (wxdataview_selection_changed_callback
), this);
2131 void wxDataViewCtrl::GtkEnableSelectionEvents()
2133 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
2134 g_signal_handlers_disconnect_by_func( selection
,
2135 (gpointer
) (wxdataview_selection_changed_callback
), this);
2138 void wxDataViewCtrl::SetSelection( int row
)
2140 GtkDisableSelectionEvents();
2142 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
2146 gtk_tree_selection_unselect_all( selection
);
2150 GtkTreePath
*path
= gtk_tree_path_new ();
2151 gtk_tree_path_append_index( path
, row
);
2153 gtk_tree_selection_select_path( selection
, path
);
2155 gtk_tree_path_free( path
);
2158 GtkEnableSelectionEvents();
2161 void wxDataViewCtrl::Unselect( unsigned int row
)
2163 GtkDisableSelectionEvents();
2165 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
2167 GtkTreePath
*path
= gtk_tree_path_new ();
2168 gtk_tree_path_append_index( path
, row
);
2170 gtk_tree_selection_unselect_path( selection
, path
);
2172 gtk_tree_path_free( path
);
2174 GtkEnableSelectionEvents();
2177 void wxDataViewCtrl::SetSelectionRange( unsigned int from
, unsigned int to
)
2179 GtkDisableSelectionEvents();
2183 unsigned int tmp
= from
;
2188 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
2190 GtkTreePath
*path_from
= gtk_tree_path_new ();
2191 gtk_tree_path_append_index( path_from
, from
);
2192 GtkTreePath
*path_to
= gtk_tree_path_new ();
2193 gtk_tree_path_append_index( path_to
, to
);
2195 gtk_tree_selection_select_range( selection
, path_from
, path_to
);
2197 gtk_tree_path_free( path_to
);
2198 gtk_tree_path_free( path_from
);
2200 GtkEnableSelectionEvents();
2203 void wxDataViewCtrl::SetSelections( const wxArrayInt
& aSelections
)
2205 GtkDisableSelectionEvents();
2207 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
2210 for (i
= 0; i
< aSelections
.GetCount(); i
++)
2212 GtkTreePath
*path
= gtk_tree_path_new ();
2213 gtk_tree_path_append_index( path
, aSelections
[i
] );
2215 gtk_tree_selection_select_path( selection
, path
);
2217 gtk_tree_path_free( path
);
2220 GtkEnableSelectionEvents();
2223 bool wxDataViewCtrl::IsSelected( unsigned int row
) const
2225 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
2227 GtkTreePath
*path
= gtk_tree_path_new ();
2228 gtk_tree_path_append_index( path
, row
);
2230 gboolean ret
= gtk_tree_selection_path_is_selected( selection
, path
);
2232 gtk_tree_path_free( path
);
2237 int wxDataViewCtrl::GetSelection() const
2239 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
2240 if (HasFlag(wxDV_MULTIPLE
))
2242 GtkTreeModel
*model
;
2243 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
2248 // list = g_list_nth( list, 0 ); should be a noop
2249 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
2251 unsigned int row
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
2254 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
2255 g_list_free( list
);
2263 GtkTreeModel
*model
;
2265 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
2268 unsigned int row
= (wxUIntPtr
) iter
.user_data
;
2276 int wxDataViewCtrl::GetSelections(wxArrayInt
& aSelections
) const
2278 aSelections
.Clear();
2280 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
2281 if (HasFlag(wxDV_MULTIPLE
))
2283 GtkTreeModel
*model
;
2284 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
2290 // list = g_list_nth( list, 0 ); should be a noop
2291 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
2293 unsigned int row
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
2295 aSelections
.Add( (int) row
);
2297 list
= g_list_next( list
);
2301 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
2302 g_list_free( list
);
2308 GtkTreeModel
*model
;
2310 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
2313 unsigned int row
= (wxUIntPtr
) iter
.user_data
;
2314 aSelections
.Add( (int) row
);
2324 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
2326 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
2331 // !wxUSE_GENERICDATAVIEWCTRL
2334 // wxUSE_DATAVIEWCTRL