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 static 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
->GetNumberOfCols();
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
->GetColType( (unsigned int) index
);
252 if (wxtype
== wxT("string"))
253 gtype
= G_TYPE_STRING
;
259 wxgtk_list_store_get_iter (GtkTreeModel
*tree_model
,
263 GtkWxListStore
*list_store
= (GtkWxListStore
*) tree_model
;
264 g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model
), FALSE
);
265 g_return_val_if_fail (gtk_tree_path_get_depth (path
) > 0, FALSE
);
267 unsigned int i
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
269 if (i
>= list_store
->model
->GetNumberOfRows())
272 iter
->stamp
= list_store
->stamp
;
273 // user_data is just the index
274 iter
->user_data
= (gpointer
) i
;
280 wxgtk_list_store_get_path (GtkTreeModel
*tree_model
,
283 g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model
), NULL
);
284 g_return_val_if_fail (iter
->stamp
== GTK_WX_LIST_STORE (tree_model
)->stamp
, NULL
);
286 GtkTreePath
*retval
= gtk_tree_path_new ();
287 // user_data is just the index
288 int i
= (wxUIntPtr
) iter
->user_data
;
289 gtk_tree_path_append_index (retval
, i
);
294 wxgtk_list_store_get_value (GtkTreeModel
*tree_model
,
299 GtkWxListStore
*list_store
= (GtkWxListStore
*) tree_model
;
300 g_return_if_fail (GTK_IS_WX_LIST_STORE (tree_model
) );
302 wxDataViewListModel
*model
= list_store
->model
;
303 wxString mtype
= model
->GetColType( (unsigned int) column
);
304 if (mtype
== wxT("string"))
307 g_value_init( value
, G_TYPE_STRING
);
308 model
->GetValue( variant
, (unsigned int) column
, (unsigned int) iter
->user_data
);
309 g_value_set_string( value
, wxGTK_CONV(variant
.GetString()) );
316 GtkTreeDataList
*list
;
317 gint tmp_column
= column
;
319 g_return_if_fail (column
< GTK_LIST_STORE (tree_model
)->n_columns
);
320 g_return_if_fail (GTK_LIST_STORE (tree_model
)->stamp
== iter
->stamp
);
322 list
= G_SLIST (iter
->user_data
)->data
;
324 while (tmp_column
-- > 0 && list
)
328 g_value_init (value
, GTK_LIST_STORE (tree_model
)->column_headers
[column
]);
330 _gtk_tree_data_list_node_to_value (list
,
331 GTK_LIST_STORE (tree_model
)->column_headers
[column
],
338 wxgtk_list_store_iter_next (GtkTreeModel
*tree_model
,
341 g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model
), FALSE
);
342 GtkWxListStore
*list_store
= (GtkWxListStore
*) tree_model
;
344 g_return_val_if_fail (list_store
->stamp
== iter
->stamp
, FALSE
);
346 int n
= (wxUIntPtr
) iter
->user_data
;
351 if (n
>= (int) list_store
->model
->GetNumberOfRows()-1)
354 iter
->user_data
= (gpointer
) ++n
;
360 wxgtk_list_store_iter_children (GtkTreeModel
*tree_model
,
364 g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model
), FALSE
);
365 GtkWxListStore
*list_store
= (GtkWxListStore
*) tree_model
;
367 // this is a list, nodes have no children
371 iter
->stamp
= list_store
->stamp
;
372 iter
->user_data
= (gpointer
) -1;
378 wxgtk_list_store_iter_has_child (GtkTreeModel
*tree_model
,
385 wxgtk_list_store_iter_n_children (GtkTreeModel
*tree_model
,
388 g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model
), -1);
389 GtkWxListStore
*list_store
= (GtkWxListStore
*) tree_model
;
392 return (gint
) list_store
->model
->GetNumberOfRows();
394 g_return_val_if_fail (list_store
->stamp
== iter
->stamp
, -1);
400 wxgtk_list_store_iter_nth_child (GtkTreeModel
*tree_model
,
405 g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model
), FALSE
);
406 GtkWxListStore
*list_store
= (GtkWxListStore
*) tree_model
;
414 if (n
>= (gint
) list_store
->model
->GetNumberOfRows())
417 iter
->stamp
= list_store
->stamp
;
418 iter
->user_data
= (gpointer
) n
;
424 wxgtk_list_store_iter_parent (GtkTreeModel
*tree_model
,
431 //-----------------------------------------------------------------------------
432 // define new GTK+ class wxGtkRendererRenderer
433 //-----------------------------------------------------------------------------
437 #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ())
438 #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer))
439 #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
440 #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER))
441 #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER))
442 #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
444 GType
gtk_wx_cell_renderer_get_type (void);
446 typedef struct _GtkWxCellRenderer GtkWxCellRenderer
;
447 typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass
;
449 struct _GtkWxCellRenderer
451 GtkCellRenderer parent
;
454 wxDataViewCustomRenderer
*cell
;
458 struct _GtkWxCellRendererClass
460 GtkCellRendererClass cell_parent_class
;
464 static GtkCellRenderer
*gtk_wx_cell_renderer_new (void);
465 static void gtk_wx_cell_renderer_init (
466 GtkWxCellRenderer
*cell
);
467 static void gtk_wx_cell_renderer_class_init(
468 GtkWxCellRendererClass
*klass
);
469 static void gtk_wx_cell_renderer_finalize (
471 static void gtk_wx_cell_renderer_get_size (
472 GtkCellRenderer
*cell
,
474 GdkRectangle
*rectangle
,
479 static void gtk_wx_cell_renderer_render (
480 GtkCellRenderer
*cell
,
483 GdkRectangle
*background_area
,
484 GdkRectangle
*cell_area
,
485 GdkRectangle
*expose_area
,
486 GtkCellRendererState flags
);
487 static gboolean
gtk_wx_cell_renderer_activate(
488 GtkCellRenderer
*cell
,
492 GdkRectangle
*background_area
,
493 GdkRectangle
*cell_area
,
494 GtkCellRendererState flags
);
496 static GObjectClass
*cell_parent_class
= NULL
;
501 gtk_wx_cell_renderer_get_type (void)
503 static GType cell_wx_type
= 0;
507 static const GTypeInfo cell_wx_info
=
509 sizeof (GtkWxCellRendererClass
),
510 NULL
, /* base_init */
511 NULL
, /* base_finalize */
512 (GClassInitFunc
) gtk_wx_cell_renderer_class_init
,
513 NULL
, /* class_finalize */
514 NULL
, /* class_data */
515 sizeof (GtkWxCellRenderer
),
517 (GInstanceInitFunc
) gtk_wx_cell_renderer_init
,
520 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER
,
521 "GtkWxCellRenderer", &cell_wx_info
, (GTypeFlags
)0 );
528 gtk_wx_cell_renderer_init (GtkWxCellRenderer
*cell
)
531 cell
->last_click
= 0;
535 gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass
*klass
)
537 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
538 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
540 cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
542 object_class
->finalize
= gtk_wx_cell_renderer_finalize
;
544 cell_class
->get_size
= gtk_wx_cell_renderer_get_size
;
545 cell_class
->render
= gtk_wx_cell_renderer_render
;
546 cell_class
->activate
= gtk_wx_cell_renderer_activate
;
550 gtk_wx_cell_renderer_finalize (GObject
*object
)
553 (* G_OBJECT_CLASS (cell_parent_class
)->finalize
) (object
);
557 gtk_wx_cell_renderer_new (void)
559 return (GtkCellRenderer
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER
, NULL
);
563 gtk_wx_cell_renderer_get_size (GtkCellRenderer
*renderer
,
565 GdkRectangle
*cell_area
,
571 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
572 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
574 wxSize size
= cell
->GetSize();
576 gint calc_width
= (gint
) renderer
->xpad
* 2 + size
.x
;
577 gint calc_height
= (gint
) renderer
->ypad
* 2 + size
.y
;
584 if (cell_area
&& size
.x
> 0 && size
.y
> 0)
588 *x_offset
= (gint
)((renderer
->xalign
*
589 (cell_area
->width
- calc_width
- 2 * renderer
->xpad
)));
590 *x_offset
= MAX (*x_offset
, 0) + renderer
->xpad
;
594 *y_offset
= (gint
)((renderer
->yalign
*
595 (cell_area
->height
- calc_height
- 2 * renderer
->ypad
)));
596 *y_offset
= MAX (*y_offset
, 0) + renderer
->ypad
;
604 *height
= calc_height
;
608 gtk_wx_cell_renderer_render (GtkCellRenderer
*renderer
,
611 GdkRectangle
*background_area
,
612 GdkRectangle
*cell_area
,
613 GdkRectangle
*expose_area
,
614 GtkCellRendererState flags
)
617 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
618 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
621 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
627 rect
.x
+= cell_area
->x
;
628 rect
.y
+= cell_area
->y
;
629 rect
.width
-= renderer
->xpad
* 2;
630 rect
.height
-= renderer
->ypad
* 2;
633 if (gdk_rectangle_intersect (expose_area
, &rect
, &dummy
))
635 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
636 wxWindowDC
* dc
= (wxWindowDC
*) cell
->GetDC();
637 if (dc
->m_window
== NULL
)
639 dc
->m_window
= window
;
644 if (flags
& GTK_CELL_RENDERER_SELECTED
)
645 state
|= wxDATAVIEW_CELL_SELECTED
;
646 if (flags
& GTK_CELL_RENDERER_PRELIT
)
647 state
|= wxDATAVIEW_CELL_PRELIT
;
648 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
649 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
650 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
651 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
652 if (flags
& GTK_CELL_RENDERER_FOCUSED
)
653 state
|= wxDATAVIEW_CELL_FOCUSED
;
654 cell
->Render( renderrect
, dc
, state
);
659 gtk_wx_cell_renderer_activate(
660 GtkCellRenderer
*renderer
,
664 GdkRectangle
*background_area
,
665 GdkRectangle
*cell_area
,
666 GtkCellRendererState flags
)
668 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
669 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
672 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
678 rect
.x
+= cell_area
->x
;
679 rect
.y
+= cell_area
->y
;
680 rect
.width
-= renderer
->xpad
* 2;
681 rect
.height
-= renderer
->ypad
* 2;
683 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
685 wxDataViewListModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
687 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
688 unsigned int model_row
= (unsigned int)gtk_tree_path_get_indices (treepath
)[0];
689 gtk_tree_path_free( treepath
);
691 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
693 if (event
->type
== GDK_BUTTON_PRESS
)
695 GdkEventButton
*button_event
= (GdkEventButton
*) event
;
696 wxPoint
pt( ((int) button_event
->x
) - renderrect
.x
,
697 ((int) button_event
->y
) - renderrect
.y
);
700 if (button_event
->button
== 1)
702 if (cell
->LeftClick( pt
, renderrect
, model
, model_col
, model_row
))
704 // TODO: query system double-click time
705 if (button_event
->time
- wxrenderer
->last_click
< 400)
706 if (cell
->Activate( renderrect
, model
, model_col
, model_row
))
709 if (button_event
->button
== 3)
711 if (cell
->RightClick( pt
, renderrect
, model
, model_col
, model_row
))
715 wxrenderer
->last_click
= button_event
->time
;
723 // ---------------------------------------------------------
724 // wxGtkDataViewListModelNotifier
725 // ---------------------------------------------------------
727 class wxGtkDataViewListModelNotifier
: public wxDataViewListModelNotifier
730 wxGtkDataViewListModelNotifier( GtkWxListStore
* gtk_store
, wxDataViewListModel
*wx_model
);
732 virtual bool RowAppended();
733 virtual bool RowPrepended();
734 virtual bool RowInserted( unsigned int before
);
735 virtual bool RowDeleted( unsigned int row
);
736 virtual bool RowChanged( unsigned int row
);
737 virtual bool ValueChanged( unsigned int col
, unsigned int row
);
738 virtual bool RowsReordered( unsigned int *new_order
);
739 virtual bool Cleared();
741 GtkWxListStore
*m_gtk_store
;
742 wxDataViewListModel
*m_wx_model
;
745 // ---------------------------------------------------------
746 // wxGtkDataViewListModelNotifier
747 // ---------------------------------------------------------
749 wxGtkDataViewListModelNotifier::wxGtkDataViewListModelNotifier(
750 GtkWxListStore
* gtk_store
, wxDataViewListModel
*wx_model
)
752 m_gtk_store
= gtk_store
;
753 m_wx_model
= wx_model
;
756 bool wxGtkDataViewListModelNotifier::RowAppended()
758 unsigned int pos
= m_wx_model
->GetNumberOfRows()-1;
761 iter
.stamp
= m_gtk_store
->stamp
;
762 iter
.user_data
= (gpointer
) pos
;
764 GtkTreePath
*path
= gtk_tree_path_new ();
765 gtk_tree_path_append_index (path
, (gint
) pos
);
766 gtk_tree_model_row_inserted (GTK_TREE_MODEL (m_gtk_store
), path
, &iter
);
767 gtk_tree_path_free (path
);
772 bool wxGtkDataViewListModelNotifier::RowPrepended()
775 iter
.stamp
= m_gtk_store
->stamp
;
776 iter
.user_data
= (gpointer
) 0;
778 GtkTreePath
*path
= gtk_tree_path_new ();
779 gtk_tree_path_append_index (path
, (gint
) 0);
780 gtk_tree_model_row_inserted (GTK_TREE_MODEL (m_gtk_store
), path
, &iter
);
781 gtk_tree_path_free (path
);
786 bool wxGtkDataViewListModelNotifier::RowInserted( unsigned int before
)
789 iter
.stamp
= m_gtk_store
->stamp
;
790 iter
.user_data
= (gpointer
) before
;
792 GtkTreePath
*path
= gtk_tree_path_new ();
793 gtk_tree_path_append_index (path
, (gint
) before
);
794 gtk_tree_model_row_inserted (GTK_TREE_MODEL (m_gtk_store
), path
, &iter
);
795 gtk_tree_path_free (path
);
800 bool wxGtkDataViewListModelNotifier::RowDeleted( unsigned int row
)
802 GtkTreePath
*path
= gtk_tree_path_new ();
803 gtk_tree_path_append_index (path
, (gint
) row
);
804 gtk_tree_model_row_deleted (GTK_TREE_MODEL (m_gtk_store
), path
);
805 gtk_tree_path_free (path
);
810 bool wxGtkDataViewListModelNotifier::RowChanged( unsigned int row
)
813 iter
.stamp
= m_gtk_store
->stamp
;
814 iter
.user_data
= (gpointer
) row
;
815 GtkTreePath
*path
= gtk_tree_model_get_path (GTK_TREE_MODEL (m_gtk_store
), &iter
);
816 gtk_tree_model_row_changed (GTK_TREE_MODEL (m_gtk_store
), path
, &iter
);
817 gtk_tree_path_free (path
);
822 bool wxGtkDataViewListModelNotifier::ValueChanged( unsigned int model_col
, unsigned int model_row
)
824 // This adds GTK+'s missing MVC logic for ValueChanged
825 wxNode
*node
= GetOwner()->m_viewingColumns
.GetFirst();
828 wxDataViewViewingColumn
* viewing_column
= (wxDataViewViewingColumn
*) node
->GetData();
829 if (viewing_column
->m_modelColumn
== model_col
)
831 GtkTreeView
*widget
= GTK_TREE_VIEW(viewing_column
->m_viewColumn
->GetOwner()->m_treeview
);
832 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(viewing_column
->m_viewColumn
->GetGtkHandle());
835 GtkTreePath
*path
= gtk_tree_path_new();
836 gtk_tree_path_append_index( path
, model_row
);
837 GdkRectangle cell_area
;
838 gtk_tree_view_get_cell_area( widget
, path
, column
, &cell_area
);
839 gtk_tree_path_free( path
);
841 int ydiff
= column
->button
->allocation
.height
;
843 gtk_widget_queue_draw_area( GTK_WIDGET(widget
),
844 cell_area
.x
, ydiff
+ cell_area
.y
, cell_area
.width
, cell_area
.height
);
847 node
= node
->GetNext();
853 bool wxGtkDataViewListModelNotifier::RowsReordered( unsigned int *new_order
)
855 // Assume sizeof(unsigned int)= == sizeof(gint)
857 GtkTreePath
*path
= gtk_tree_path_new ();
858 gtk_tree_model_rows_reordered (GTK_TREE_MODEL (m_gtk_store
), path
, NULL
, (gint
*)new_order
);
859 gtk_tree_path_free (path
);
861 // This adds GTK+'s missing MVC logic for RowsReordered
862 wxNode
*node
= GetOwner()->m_viewingColumns
.GetFirst();
865 wxDataViewViewingColumn
* viewing_column
= (wxDataViewViewingColumn
*) node
->GetData();
866 GtkTreeView
*widget
= GTK_TREE_VIEW(viewing_column
->m_viewColumn
->GetOwner()->m_treeview
);
867 // Doesn't work yet...
868 gtk_widget_queue_draw( GTK_WIDGET(widget
) );
870 node
= node
->GetNext();
876 bool wxGtkDataViewListModelNotifier::Cleared()
881 // ---------------------------------------------------------
882 // wxDataViewRenderer
883 // ---------------------------------------------------------
885 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
887 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
) :
888 wxDataViewRendererBase( varianttype
, mode
)
893 // ---------------------------------------------------------
894 // wxDataViewTextRenderer
895 // ---------------------------------------------------------
898 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
899 gchar
*arg1
, gchar
*arg2
, gpointer user_data
);
902 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
903 gchar
*arg1
, gchar
*arg2
, gpointer user_data
)
905 wxDataViewTextRenderer
*cell
= (wxDataViewTextRenderer
*) user_data
;
907 wxString tmp
= wxGTK_CONV_BACK( arg2
);
908 wxVariant value
= tmp
;
909 if (!cell
->Validate( value
))
912 wxDataViewListModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
914 GtkTreePath
*path
= gtk_tree_path_new_from_string( arg1
);
915 unsigned int model_row
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
916 gtk_tree_path_free( path
);
918 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
920 model
->SetValue( value
, model_col
, model_row
);
921 model
->ValueChanged( model_col
, model_row
);
924 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
926 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
) :
927 wxDataViewRenderer( varianttype
, mode
)
929 m_renderer
= (void*) gtk_cell_renderer_text_new();
931 if (m_mode
& wxDATAVIEW_CELL_EDITABLE
)
933 GValue gvalue
= { 0, };
934 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
935 g_value_set_boolean( &gvalue
, true );
936 g_object_set_property( G_OBJECT(m_renderer
), "editable", &gvalue
);
937 g_value_unset( &gvalue
);
939 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
943 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
945 wxString tmp
= value
;
947 GValue gvalue
= { 0, };
948 g_value_init( &gvalue
, G_TYPE_STRING
);
949 g_value_set_string( &gvalue
, wxGTK_CONV( tmp
) );
950 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
951 g_value_unset( &gvalue
);
956 bool wxDataViewTextRenderer::GetValue( wxVariant
&value
)
958 GValue gvalue
= { 0, };
959 g_value_init( &gvalue
, G_TYPE_STRING
);
960 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
961 wxString tmp
= wxGTK_CONV_BACK( g_value_get_string( &gvalue
) );
962 g_value_unset( &gvalue
);
969 // ---------------------------------------------------------
970 // wxDataViewBitmapRenderer
971 // ---------------------------------------------------------
973 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
975 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
) :
976 wxDataViewRenderer( varianttype
, mode
)
978 m_renderer
= (void*) gtk_cell_renderer_pixbuf_new();
981 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
983 if (value
.GetType() == wxT("wxBitmap"))
988 // This may create a Pixbuf representation in the
989 // wxBitmap object (and it will stay there)
990 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
992 GValue gvalue
= { 0, };
993 g_value_init( &gvalue
, G_TYPE_OBJECT
);
994 g_value_set_object( &gvalue
, pixbuf
);
995 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
996 g_value_unset( &gvalue
);
1001 if (value
.GetType() == wxT("wxIcon"))
1006 // This may create a Pixbuf representation in the
1007 // wxBitmap object (and it will stay there)
1008 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1010 GValue gvalue
= { 0, };
1011 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1012 g_value_set_object( &gvalue
, pixbuf
);
1013 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1014 g_value_unset( &gvalue
);
1022 bool wxDataViewBitmapRenderer::GetValue( wxVariant
&value
)
1027 // ---------------------------------------------------------
1028 // wxDataViewToggleRenderer
1029 // ---------------------------------------------------------
1032 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1033 gchar
*path
, gpointer user_data
);
1036 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1037 gchar
*path
, gpointer user_data
)
1039 wxDataViewToggleRenderer
*cell
= (wxDataViewToggleRenderer
*) user_data
;
1042 GValue gvalue
= { 0, };
1043 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1044 g_object_get_property( G_OBJECT(renderer
), "active", &gvalue
);
1045 bool tmp
= g_value_get_boolean( &gvalue
);
1046 g_value_unset( &gvalue
);
1050 wxVariant value
= tmp
;
1051 if (!cell
->Validate( value
))
1054 wxDataViewListModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1056 GtkTreePath
*gtk_path
= gtk_tree_path_new_from_string( path
);
1057 unsigned int model_row
= (unsigned int)gtk_tree_path_get_indices (gtk_path
)[0];
1058 gtk_tree_path_free( gtk_path
);
1060 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1062 model
->SetValue( value
, model_col
, model_row
);
1063 model
->ValueChanged( model_col
, model_row
);
1066 IMPLEMENT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
1068 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
1069 wxDataViewCellMode mode
) :
1070 wxDataViewRenderer( varianttype
, mode
)
1072 m_renderer
= (void*) gtk_cell_renderer_toggle_new();
1074 if (m_mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
1076 g_signal_connect_after( m_renderer
, "toggled", G_CALLBACK(wxGtkToggleRendererToggledCallback
), this );
1081 GValue gvalue
= { 0, };
1082 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1083 g_value_set_boolean( &gvalue
, false );
1084 g_object_set_property( G_OBJECT(m_renderer
), "activatable", &gvalue
);
1085 g_value_unset( &gvalue
);
1087 GValue gvalue2
= { 0, };
1088 g_value_init( &gvalue2
, gtk_cell_renderer_mode_get_type() );
1089 g_value_set_enum( &gvalue2
, GTK_CELL_RENDERER_MODE_INERT
);
1090 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue2
);
1091 g_value_unset( &gvalue2
);
1096 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
1100 GValue gvalue
= { 0, };
1101 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1102 g_value_set_boolean( &gvalue
, tmp
);
1103 g_object_set_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1104 g_value_unset( &gvalue
);
1109 bool wxDataViewToggleRenderer::GetValue( wxVariant
&value
)
1111 GValue gvalue
= { 0, };
1112 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1113 g_object_get_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1114 bool tmp
= g_value_get_boolean( &gvalue
);
1115 g_value_unset( &gvalue
);
1122 // ---------------------------------------------------------
1123 // wxDataViewCustomRenderer
1124 // ---------------------------------------------------------
1126 class wxDataViewCtrlDC
: public wxWindowDC
1129 wxDataViewCtrlDC( wxDataViewCtrl
*window
)
1131 GtkWidget
*widget
= window
->m_treeview
;
1135 m_context
= window
->GtkGetPangoDefaultContext();
1136 m_layout
= pango_layout_new( m_context
);
1137 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
1139 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
1141 // Set m_window later
1143 // m_owner = window;
1147 // ---------------------------------------------------------
1148 // wxDataViewCustomRenderer
1149 // ---------------------------------------------------------
1151 IMPLEMENT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
1153 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
1154 wxDataViewCellMode mode
, bool no_init
) :
1155 wxDataViewRenderer( varianttype
, mode
)
1165 bool wxDataViewCustomRenderer::Init()
1167 GtkWxCellRenderer
*renderer
= (GtkWxCellRenderer
*) gtk_wx_cell_renderer_new();
1168 renderer
->cell
= this;
1170 m_renderer
= (void*) renderer
;
1172 if (m_mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
1174 GValue gvalue
= { 0, };
1175 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1176 g_value_set_enum( &gvalue
, GTK_CELL_RENDERER_MODE_ACTIVATABLE
);
1177 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue
);
1178 g_value_unset( &gvalue
);
1184 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
1190 wxDC
*wxDataViewCustomRenderer::GetDC()
1194 if (GetOwner() == NULL
)
1196 if (GetOwner()->GetOwner() == NULL
)
1198 m_dc
= new wxDataViewCtrlDC( GetOwner()->GetOwner() );
1204 // ---------------------------------------------------------
1205 // wxDataViewProgressRenderer
1206 // ---------------------------------------------------------
1208 IMPLEMENT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
1210 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
1211 const wxString
&varianttype
, wxDataViewCellMode mode
) :
1212 wxDataViewCustomRenderer( varianttype
, mode
, true )
1218 if (!gtk_check_version(2,6,0))
1220 m_renderer
= (void*) gtk_cell_renderer_progress_new();
1222 GValue gvalue
= { 0, };
1223 g_value_init( &gvalue
, G_TYPE_STRING
);
1224 g_value_set_boolean( &gvalue
, wxGTK_CONV(m_label
) );
1225 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1226 g_value_unset( &gvalue
);
1231 // Use custom cell code
1232 wxDataViewCustomRenderer::Init();
1236 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
1240 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
1243 if (!gtk_check_version(2,6,0))
1245 gint tmp
= (int) value
;
1246 GValue gvalue
= { 0, };
1247 g_value_init( &gvalue
, G_TYPE_INT
);
1248 g_value_set_boolean( &gvalue
, tmp
);
1249 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
1250 g_value_unset( &gvalue
);
1255 m_value
= (long) value
;
1257 if (m_value
< 0) m_value
= 0;
1258 if (m_value
> 100) m_value
= 100;
1264 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1266 double pct
= (double)m_value
/ 100.0;
1268 bar
.width
= (int)(cell
.width
* pct
);
1269 dc
->SetPen( *wxTRANSPARENT_PEN
);
1270 dc
->SetBrush( *wxBLUE_BRUSH
);
1271 dc
->DrawRectangle( bar
);
1273 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1274 dc
->SetPen( *wxBLACK_PEN
);
1275 dc
->DrawRectangle( cell
);
1280 wxSize
wxDataViewProgressRenderer::GetSize()
1282 return wxSize(40,12);
1285 // ---------------------------------------------------------
1286 // wxDataViewDateRenderer
1287 // ---------------------------------------------------------
1289 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
1292 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
1293 wxDataViewListModel
*model
, unsigned int col
, unsigned int row
) :
1294 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
1299 m_cal
= new wxCalendarCtrl( this, -1, *value
);
1300 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
1301 sizer
->Add( m_cal
, 1, wxGROW
);
1306 virtual void OnDismiss()
1310 void OnCalendar( wxCalendarEvent
&event
);
1312 wxCalendarCtrl
*m_cal
;
1313 wxDataViewListModel
*m_model
;
1318 DECLARE_EVENT_TABLE()
1321 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
1322 EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar
)
1325 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
1327 wxDateTime date
= event
.GetDate();
1328 wxVariant value
= date
;
1329 m_model
->SetValue( value
, m_col
, m_row
);
1330 m_model
->ValueChanged( m_col
, m_row
);
1334 IMPLEMENT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
1336 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
1337 wxDataViewCellMode mode
) :
1338 wxDataViewCustomRenderer( varianttype
, mode
)
1342 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
1344 m_date
= value
.GetDateTime();
1349 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1351 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
1352 wxString tmp
= m_date
.FormatDate();
1353 dc
->DrawText( tmp
, cell
.x
, cell
.y
);
1358 wxSize
wxDataViewDateRenderer::GetSize()
1360 wxDataViewCtrl
* view
= GetOwner()->GetOwner();
1361 wxString tmp
= m_date
.FormatDate();
1363 view
->GetTextExtent( tmp
, &x
, &y
, &d
);
1364 return wxSize(x
,y
+d
);
1367 bool wxDataViewDateRenderer::Activate( wxRect cell
, wxDataViewListModel
*model
, unsigned int col
, unsigned int row
)
1370 model
->GetValue( variant
, col
, row
);
1371 wxDateTime value
= variant
.GetDateTime();
1373 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
1374 GetOwner()->GetOwner()->GetParent(), &value
, model
, col
, row
);
1375 wxPoint pos
= wxGetMousePosition();
1378 popup
->Popup( popup
->m_cal
);
1383 // ---------------------------------------------------------
1385 // ---------------------------------------------------------
1388 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
1389 GtkCellRenderer
*cell
,
1390 GtkTreeModel
*model
,
1396 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
1397 GtkCellRenderer
*renderer
,
1398 GtkTreeModel
*model
,
1402 g_return_if_fail (GTK_IS_WX_LIST_STORE (model
));
1403 GtkWxListStore
*list_store
= (GtkWxListStore
*) model
;
1405 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
1407 unsigned int model_row
= (unsigned int) iter
->user_data
;
1410 list_store
->model
->GetValue( value
, cell
->GetOwner()->GetModelColumn(), model_row
);
1412 if (value
.GetType() != cell
->GetVariantType())
1413 wxLogError( wxT("Wrong type, required: %s but: %s"),
1414 value
.GetType().c_str(),
1415 cell
->GetVariantType().c_str() );
1417 cell
->SetValue( value
);
1420 IMPLEMENT_CLASS(wxDataViewColumn
, wxDataViewColumnBase
)
1422 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
, unsigned int model_column
,
1423 int width
, int flags
) :
1424 wxDataViewColumnBase( title
, cell
, model_column
, width
, flags
)
1426 GtkCellRenderer
*renderer
= (GtkCellRenderer
*) cell
->GetGtkHandle();
1428 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
1430 gtk_tree_view_column_set_title( column
, wxGTK_CONV(title
) );
1432 if (flags
& wxDATAVIEW_COL_RESIZABLE
)
1433 gtk_tree_view_column_set_resizable( column
, true );
1434 if (flags
& wxDATAVIEW_COL_HIDDEN
)
1435 gtk_tree_view_column_set_visible( column
, false );
1436 if (flags
& wxDATAVIEW_COL_SORTABLE
)
1437 gtk_tree_view_column_set_sort_indicator( column
, true );
1441 gtk_tree_view_column_set_fixed_width( column
, width
);
1442 gtk_tree_view_column_set_sizing( column
, GTK_TREE_VIEW_COLUMN_FIXED
);
1445 gtk_tree_view_column_pack_end( column
, renderer
, FALSE
);
1447 gtk_tree_view_column_set_cell_data_func( column
, renderer
,
1448 wxGtkTreeCellDataFunc
, (gpointer
) cell
, NULL
);
1450 m_column
= (void*) column
;
1453 wxDataViewColumn::~wxDataViewColumn()
1457 void wxDataViewColumn::SetTitle( const wxString
&title
)
1459 wxDataViewColumnBase::SetTitle( title
);
1461 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)m_column
;
1462 gtk_tree_view_column_set_title( column
, wxGTK_CONV(title
) );
1465 int wxDataViewColumn::GetWidth()
1467 return gtk_tree_view_column_get_width( (GtkTreeViewColumn
*)m_column
);
1470 void wxDataViewColumn::SetFixedWidth( int width
)
1472 gtk_tree_view_column_set_fixed_width( (GtkTreeViewColumn
*)m_column
, width
);
1475 int wxDataViewColumn::GetFixedWidth()
1477 return gtk_tree_view_column_get_fixed_width( (GtkTreeViewColumn
*)m_column
);
1480 //-----------------------------------------------------------------------------
1481 // wxDataViewCtrl signal callbacks
1482 //-----------------------------------------------------------------------------
1485 wxdataview_selection_changed_callback( GtkTreeSelection
* selection
, wxDataViewCtrl
*dv
)
1487 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ROW_SELECTED
, dv
->GetId() );
1488 event
.SetRow( dv
->GetSelection() );
1489 event
.SetModel( dv
->GetModel() );
1490 dv
->GetEventHandler()->ProcessEvent( event
);
1494 wxdataview_row_activated_callback( GtkTreeView
* treeview
, GtkTreePath
*path
,
1495 GtkTreeViewColumn
*column
, wxDataViewCtrl
*dv
)
1497 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ROW_ACTIVATED
, dv
->GetId() );
1498 unsigned int row
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
1499 event
.SetRow( row
);
1500 event
.SetModel( dv
->GetModel() );
1501 dv
->GetEventHandler()->ProcessEvent( event
);
1504 //-----------------------------------------------------------------------------
1506 //-----------------------------------------------------------------------------
1508 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
1510 wxDataViewCtrl::~wxDataViewCtrl()
1513 GetModel()->RemoveNotifier( m_notifier
);
1516 void wxDataViewCtrl::Init()
1521 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
1522 const wxPoint
& pos
, const wxSize
& size
,
1523 long style
, const wxValidator
& validator
)
1527 m_needParent
= true;
1528 m_acceptsFocus
= true;
1530 if (!PreCreation( parent
, pos
, size
) ||
1531 !CreateBase( parent
, id
, pos
, size
, style
, validator
))
1533 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
1537 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
1539 GtkScrolledWindowSetBorder(m_widget
, style
);
1541 m_treeview
= gtk_tree_view_new();
1542 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
1544 if (style
& wxDV_MULTIPLE
)
1546 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
1547 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
1550 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
1551 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
);
1552 gtk_widget_show (m_treeview
);
1554 m_parent
->DoAddChild( this );
1556 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
1557 g_signal_connect_after (selection
, "changed",
1558 G_CALLBACK (wxdataview_selection_changed_callback
), this);
1559 g_signal_connect_after (m_treeview
, "row_activated",
1560 G_CALLBACK (wxdataview_row_activated_callback
), this);
1567 bool wxDataViewCtrl::AssociateModel( wxDataViewListModel
*model
)
1569 if (!wxDataViewCtrlBase::AssociateModel( model
))
1572 GtkWxListStore
*gtk_store
= wxgtk_list_store_new();
1573 gtk_store
->model
= model
;
1575 m_notifier
= new wxGtkDataViewListModelNotifier( gtk_store
, model
);
1577 model
->AddNotifier( m_notifier
);
1579 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), GTK_TREE_MODEL(gtk_store
) );
1580 g_object_unref( gtk_store
);
1585 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
1587 if (!wxDataViewCtrlBase::AppendColumn(col
))
1590 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)col
->GetGtkHandle();
1592 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
), column
);
1597 void wxDataViewCtrl::SetSelection( int row
)
1599 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
1603 gtk_tree_selection_unselect_all( selection
);
1607 GtkTreePath
*path
= gtk_tree_path_new ();
1608 gtk_tree_path_append_index( path
, row
);
1610 gtk_tree_selection_select_path( selection
, path
);
1612 gtk_tree_path_free( path
);
1616 void wxDataViewCtrl::Unselect( unsigned int row
)
1618 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
1620 GtkTreePath
*path
= gtk_tree_path_new ();
1621 gtk_tree_path_append_index( path
, row
);
1623 gtk_tree_selection_unselect_path( selection
, path
);
1625 gtk_tree_path_free( path
);
1628 void wxDataViewCtrl::SetSelectionRange( unsigned int from
, unsigned int to
)
1632 void wxDataViewCtrl::SetSelections( const wxArrayInt
& aSelections
)
1636 bool wxDataViewCtrl::IsSelected( unsigned int row
) const
1638 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
1640 GtkTreePath
*path
= gtk_tree_path_new ();
1641 gtk_tree_path_append_index( path
, row
);
1643 gboolean ret
= gtk_tree_selection_path_is_selected( selection
, path
);
1645 gtk_tree_path_free( path
);
1650 int wxDataViewCtrl::GetSelection() const
1652 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
1653 if (HasFlag(wxDV_MULTIPLE
))
1655 GtkTreeModel
*model
;
1656 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
1661 // list = g_list_nth( list, 0 ); should be a noop
1662 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
1664 unsigned int row
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
1667 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
1668 g_list_free( list
);
1676 GtkTreeModel
*model
;
1678 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
1681 unsigned int row
= (wxUIntPtr
) iter
.user_data
;
1689 int wxDataViewCtrl::GetSelections(wxArrayInt
& aSelections
) const
1691 aSelections
.Clear();
1693 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
1694 if (HasFlag(wxDV_MULTIPLE
))
1696 GtkTreeModel
*model
;
1697 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
1703 // list = g_list_nth( list, 0 ); should be a noop
1704 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
1706 unsigned int row
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
1708 aSelections
.Add( (int) row
);
1710 list
= g_list_next( list
);
1714 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
1715 g_list_free( list
);
1721 GtkTreeModel
*model
;
1723 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
1726 unsigned int row
= (wxUIntPtr
) iter
.user_data
;
1727 aSelections
.Add( (int) row
);
1737 // !wxUSE_GENERICDATAVIEWCTRL
1740 // wxUSE_DATAVIEWCTRL