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
) );
303 wxDataViewListModel
*model
= list_store
->model
;
304 wxString mtype
= model
->GetColType( (unsigned int) column
);
305 if (mtype
== wxT("string"))
308 g_value_init( value
, G_TYPE_STRING
);
309 model
->GetValue( variant
, (unsigned int) column
, (unsigned int) iter
->user_data
);
310 g_value_set_string( value
, wxGTK_CONV(variant
.GetString()) );
318 GtkTreeDataList
*list
;
319 gint tmp_column
= column
;
321 g_return_if_fail (column
< GTK_LIST_STORE (tree_model
)->n_columns
);
322 g_return_if_fail (GTK_LIST_STORE (tree_model
)->stamp
== iter
->stamp
);
324 list
= G_SLIST (iter
->user_data
)->data
;
326 while (tmp_column
-- > 0 && list
)
330 g_value_init (value
, GTK_LIST_STORE (tree_model
)->column_headers
[column
]);
332 _gtk_tree_data_list_node_to_value (list
,
333 GTK_LIST_STORE (tree_model
)->column_headers
[column
],
340 wxgtk_list_store_iter_next (GtkTreeModel
*tree_model
,
343 g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model
), FALSE
);
344 GtkWxListStore
*list_store
= (GtkWxListStore
*) tree_model
;
346 g_return_val_if_fail (list_store
->stamp
== iter
->stamp
, FALSE
);
348 int n
= (wxUIntPtr
) iter
->user_data
;
353 if (n
>= (int) list_store
->model
->GetNumberOfRows()-1)
356 iter
->user_data
= (gpointer
) ++n
;
362 wxgtk_list_store_iter_children (GtkTreeModel
*tree_model
,
366 g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model
), FALSE
);
367 GtkWxListStore
*list_store
= (GtkWxListStore
*) tree_model
;
369 // this is a list, nodes have no children
373 iter
->stamp
= list_store
->stamp
;
374 iter
->user_data
= (gpointer
) -1;
380 wxgtk_list_store_iter_has_child (GtkTreeModel
*tree_model
,
387 wxgtk_list_store_iter_n_children (GtkTreeModel
*tree_model
,
390 g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model
), -1);
391 GtkWxListStore
*list_store
= (GtkWxListStore
*) tree_model
;
394 return (gint
) list_store
->model
->GetNumberOfRows();
396 g_return_val_if_fail (list_store
->stamp
== iter
->stamp
, -1);
402 wxgtk_list_store_iter_nth_child (GtkTreeModel
*tree_model
,
407 g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model
), FALSE
);
408 GtkWxListStore
*list_store
= (GtkWxListStore
*) tree_model
;
416 if (n
>= (gint
) list_store
->model
->GetNumberOfRows())
419 iter
->stamp
= list_store
->stamp
;
420 iter
->user_data
= (gpointer
) n
;
426 wxgtk_list_store_iter_parent (GtkTreeModel
*tree_model
,
433 //-----------------------------------------------------------------------------
434 // define new GTK+ class wxGtkRendererRenderer
435 //-----------------------------------------------------------------------------
439 #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ())
440 #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer))
441 #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
442 #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER))
443 #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER))
444 #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
446 GType
gtk_wx_cell_renderer_get_type (void);
448 typedef struct _GtkWxCellRenderer GtkWxCellRenderer
;
449 typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass
;
451 struct _GtkWxCellRenderer
453 GtkCellRenderer parent
;
456 wxDataViewCustomRenderer
*cell
;
460 struct _GtkWxCellRendererClass
462 GtkCellRendererClass cell_parent_class
;
466 static GtkCellRenderer
*gtk_wx_cell_renderer_new (void);
467 static void gtk_wx_cell_renderer_init (
468 GtkWxCellRenderer
*cell
);
469 static void gtk_wx_cell_renderer_class_init(
470 GtkWxCellRendererClass
*klass
);
471 static void gtk_wx_cell_renderer_finalize (
473 static void gtk_wx_cell_renderer_get_size (
474 GtkCellRenderer
*cell
,
476 GdkRectangle
*rectangle
,
481 static void gtk_wx_cell_renderer_render (
482 GtkCellRenderer
*cell
,
485 GdkRectangle
*background_area
,
486 GdkRectangle
*cell_area
,
487 GdkRectangle
*expose_area
,
488 GtkCellRendererState flags
);
489 static gboolean
gtk_wx_cell_renderer_activate(
490 GtkCellRenderer
*cell
,
494 GdkRectangle
*background_area
,
495 GdkRectangle
*cell_area
,
496 GtkCellRendererState flags
);
498 static GObjectClass
*cell_parent_class
= NULL
;
503 gtk_wx_cell_renderer_get_type (void)
505 static GType cell_wx_type
= 0;
509 static const GTypeInfo cell_wx_info
=
511 sizeof (GtkWxCellRendererClass
),
512 NULL
, /* base_init */
513 NULL
, /* base_finalize */
514 (GClassInitFunc
) gtk_wx_cell_renderer_class_init
,
515 NULL
, /* class_finalize */
516 NULL
, /* class_data */
517 sizeof (GtkWxCellRenderer
),
519 (GInstanceInitFunc
) gtk_wx_cell_renderer_init
,
522 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER
,
523 "GtkWxCellRenderer", &cell_wx_info
, (GTypeFlags
)0 );
530 gtk_wx_cell_renderer_init (GtkWxCellRenderer
*cell
)
533 cell
->last_click
= 0;
537 gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass
*klass
)
539 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
540 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
542 cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
544 object_class
->finalize
= gtk_wx_cell_renderer_finalize
;
546 cell_class
->get_size
= gtk_wx_cell_renderer_get_size
;
547 cell_class
->render
= gtk_wx_cell_renderer_render
;
548 cell_class
->activate
= gtk_wx_cell_renderer_activate
;
552 gtk_wx_cell_renderer_finalize (GObject
*object
)
555 (* G_OBJECT_CLASS (cell_parent_class
)->finalize
) (object
);
559 gtk_wx_cell_renderer_new (void)
561 return (GtkCellRenderer
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER
, NULL
);
565 gtk_wx_cell_renderer_get_size (GtkCellRenderer
*renderer
,
567 GdkRectangle
*cell_area
,
573 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
574 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
576 wxSize size
= cell
->GetSize();
578 gint calc_width
= (gint
) renderer
->xpad
* 2 + size
.x
;
579 gint calc_height
= (gint
) renderer
->ypad
* 2 + size
.y
;
586 if (cell_area
&& size
.x
> 0 && size
.y
> 0)
590 *x_offset
= (gint
)((renderer
->xalign
*
591 (cell_area
->width
- calc_width
- 2 * renderer
->xpad
)));
592 *x_offset
= MAX (*x_offset
, 0) + renderer
->xpad
;
596 *y_offset
= (gint
)((renderer
->yalign
*
597 (cell_area
->height
- calc_height
- 2 * renderer
->ypad
)));
598 *y_offset
= MAX (*y_offset
, 0) + renderer
->ypad
;
606 *height
= calc_height
;
610 gtk_wx_cell_renderer_render (GtkCellRenderer
*renderer
,
613 GdkRectangle
*background_area
,
614 GdkRectangle
*cell_area
,
615 GdkRectangle
*expose_area
,
616 GtkCellRendererState flags
)
619 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
620 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
623 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
629 rect
.x
+= cell_area
->x
;
630 rect
.y
+= cell_area
->y
;
631 rect
.width
-= renderer
->xpad
* 2;
632 rect
.height
-= renderer
->ypad
* 2;
635 if (gdk_rectangle_intersect (expose_area
, &rect
, &dummy
))
637 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
638 wxWindowDC
* dc
= (wxWindowDC
*) cell
->GetDC();
639 if (dc
->m_window
== NULL
)
641 dc
->m_window
= window
;
646 if (flags
& GTK_CELL_RENDERER_SELECTED
)
647 state
|= wxDATAVIEW_CELL_SELECTED
;
648 if (flags
& GTK_CELL_RENDERER_PRELIT
)
649 state
|= wxDATAVIEW_CELL_PRELIT
;
650 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
651 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
652 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
653 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
654 if (flags
& GTK_CELL_RENDERER_FOCUSED
)
655 state
|= wxDATAVIEW_CELL_FOCUSED
;
656 cell
->Render( renderrect
, dc
, state
);
661 gtk_wx_cell_renderer_activate(
662 GtkCellRenderer
*renderer
,
666 GdkRectangle
*background_area
,
667 GdkRectangle
*cell_area
,
668 GtkCellRendererState flags
)
670 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
671 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
674 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
680 rect
.x
+= cell_area
->x
;
681 rect
.y
+= cell_area
->y
;
682 rect
.width
-= renderer
->xpad
* 2;
683 rect
.height
-= renderer
->ypad
* 2;
685 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
687 wxDataViewListModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
689 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
690 unsigned int model_row
= (unsigned int)gtk_tree_path_get_indices (treepath
)[0];
691 gtk_tree_path_free( treepath
);
693 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
695 if (event
->type
== GDK_BUTTON_PRESS
)
697 GdkEventButton
*button_event
= (GdkEventButton
*) event
;
698 wxPoint
pt( ((int) button_event
->x
) - renderrect
.x
,
699 ((int) button_event
->y
) - renderrect
.y
);
702 if (button_event
->button
== 1)
704 if (cell
->LeftClick( pt
, renderrect
, model
, model_col
, model_row
))
706 // TODO: query system double-click time
707 if (button_event
->time
- wxrenderer
->last_click
< 400)
708 if (cell
->Activate( renderrect
, model
, model_col
, model_row
))
711 if (button_event
->button
== 3)
713 if (cell
->RightClick( pt
, renderrect
, model
, model_col
, model_row
))
717 wxrenderer
->last_click
= button_event
->time
;
725 // ---------------------------------------------------------
726 // wxGtkDataViewListModelNotifier
727 // ---------------------------------------------------------
729 class wxGtkDataViewListModelNotifier
: public wxDataViewListModelNotifier
732 wxGtkDataViewListModelNotifier( GtkWxListStore
* gtk_store
, wxDataViewListModel
*wx_model
);
734 virtual bool RowAppended();
735 virtual bool RowPrepended();
736 virtual bool RowInserted( unsigned int before
);
737 virtual bool RowDeleted( unsigned int row
);
738 virtual bool RowChanged( unsigned int row
);
739 virtual bool ValueChanged( unsigned int col
, unsigned int row
);
740 virtual bool RowsReordered( unsigned int *new_order
);
741 virtual bool Cleared();
743 GtkWxListStore
*m_gtk_store
;
744 wxDataViewListModel
*m_wx_model
;
747 // ---------------------------------------------------------
748 // wxGtkDataViewListModelNotifier
749 // ---------------------------------------------------------
751 wxGtkDataViewListModelNotifier::wxGtkDataViewListModelNotifier(
752 GtkWxListStore
* gtk_store
, wxDataViewListModel
*wx_model
)
754 m_gtk_store
= gtk_store
;
755 m_wx_model
= wx_model
;
758 bool wxGtkDataViewListModelNotifier::RowAppended()
760 unsigned int pos
= m_wx_model
->GetNumberOfRows()-1;
763 iter
.stamp
= m_gtk_store
->stamp
;
764 iter
.user_data
= (gpointer
) pos
;
766 GtkTreePath
*path
= gtk_tree_path_new ();
767 gtk_tree_path_append_index (path
, (gint
) pos
);
768 gtk_tree_model_row_inserted (GTK_TREE_MODEL (m_gtk_store
), path
, &iter
);
769 gtk_tree_path_free (path
);
774 bool wxGtkDataViewListModelNotifier::RowPrepended()
777 iter
.stamp
= m_gtk_store
->stamp
;
778 iter
.user_data
= (gpointer
) 0;
780 GtkTreePath
*path
= gtk_tree_path_new ();
781 gtk_tree_path_append_index (path
, (gint
) 0);
782 gtk_tree_model_row_inserted (GTK_TREE_MODEL (m_gtk_store
), path
, &iter
);
783 gtk_tree_path_free (path
);
788 bool wxGtkDataViewListModelNotifier::RowInserted( unsigned int before
)
791 iter
.stamp
= m_gtk_store
->stamp
;
792 iter
.user_data
= (gpointer
) before
;
794 GtkTreePath
*path
= gtk_tree_path_new ();
795 gtk_tree_path_append_index (path
, (gint
) before
);
796 gtk_tree_model_row_inserted (GTK_TREE_MODEL (m_gtk_store
), path
, &iter
);
797 gtk_tree_path_free (path
);
802 bool wxGtkDataViewListModelNotifier::RowDeleted( unsigned int row
)
804 GtkTreePath
*path
= gtk_tree_path_new ();
805 gtk_tree_path_append_index (path
, (gint
) row
);
806 gtk_tree_model_row_deleted (GTK_TREE_MODEL (m_gtk_store
), path
);
807 gtk_tree_path_free (path
);
812 bool wxGtkDataViewListModelNotifier::RowChanged( unsigned int row
)
815 iter
.stamp
= m_gtk_store
->stamp
;
816 iter
.user_data
= (gpointer
) row
;
817 GtkTreePath
*path
= gtk_tree_model_get_path (GTK_TREE_MODEL (m_gtk_store
), &iter
);
818 gtk_tree_model_row_changed (GTK_TREE_MODEL (m_gtk_store
), path
, &iter
);
819 gtk_tree_path_free (path
);
824 bool wxGtkDataViewListModelNotifier::ValueChanged( unsigned int model_col
, unsigned int model_row
)
826 // This adds GTK+'s missing MVC logic for ValueChanged
827 wxNode
*node
= GetOwner()->m_viewingColumns
.GetFirst();
830 wxDataViewViewingColumn
* viewing_column
= (wxDataViewViewingColumn
*) node
->GetData();
831 if (viewing_column
->m_modelColumn
== model_col
)
833 GtkTreeView
*widget
= GTK_TREE_VIEW(viewing_column
->m_viewColumn
->GetOwner()->m_treeview
);
834 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(viewing_column
->m_viewColumn
->GetGtkHandle());
837 GtkTreePath
*path
= gtk_tree_path_new();
838 gtk_tree_path_append_index( path
, model_row
);
839 GdkRectangle cell_area
;
840 gtk_tree_view_get_cell_area( widget
, path
, column
, &cell_area
);
841 gtk_tree_path_free( path
);
843 int ydiff
= column
->button
->allocation
.height
;
845 gtk_widget_queue_draw_area( GTK_WIDGET(widget
),
846 cell_area
.x
, ydiff
+ cell_area
.y
, cell_area
.width
, cell_area
.height
);
849 node
= node
->GetNext();
855 bool wxGtkDataViewListModelNotifier::RowsReordered( unsigned int *new_order
)
857 // Assume sizeof(unsigned int)= == sizeof(gint)
859 GtkTreePath
*path
= gtk_tree_path_new ();
860 gtk_tree_model_rows_reordered (GTK_TREE_MODEL (m_gtk_store
), path
, NULL
, (gint
*)new_order
);
861 gtk_tree_path_free (path
);
863 // This adds GTK+'s missing MVC logic for RowsReordered
864 wxNode
*node
= GetOwner()->m_viewingColumns
.GetFirst();
867 wxDataViewViewingColumn
* viewing_column
= (wxDataViewViewingColumn
*) node
->GetData();
868 GtkTreeView
*widget
= GTK_TREE_VIEW(viewing_column
->m_viewColumn
->GetOwner()->m_treeview
);
869 // Doesn't work yet...
870 gtk_widget_queue_draw( GTK_WIDGET(widget
) );
872 node
= node
->GetNext();
878 bool wxGtkDataViewListModelNotifier::Cleared()
883 // ---------------------------------------------------------
884 // wxDataViewRenderer
885 // ---------------------------------------------------------
887 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
889 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
) :
890 wxDataViewRendererBase( varianttype
, mode
)
895 // ---------------------------------------------------------
896 // wxDataViewTextRenderer
897 // ---------------------------------------------------------
900 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
901 gchar
*arg1
, gchar
*arg2
, gpointer user_data
);
904 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
905 gchar
*arg1
, gchar
*arg2
, gpointer user_data
)
907 wxDataViewTextRenderer
*cell
= (wxDataViewTextRenderer
*) user_data
;
909 wxString tmp
= wxGTK_CONV_BACK( arg2
);
910 wxVariant value
= tmp
;
911 if (!cell
->Validate( value
))
914 wxDataViewListModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
916 GtkTreePath
*path
= gtk_tree_path_new_from_string( arg1
);
917 unsigned int model_row
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
918 gtk_tree_path_free( path
);
920 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
922 model
->SetValue( value
, model_col
, model_row
);
923 model
->ValueChanged( model_col
, model_row
);
926 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
928 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
) :
929 wxDataViewRenderer( varianttype
, mode
)
931 m_renderer
= (void*) gtk_cell_renderer_text_new();
933 if (m_mode
& wxDATAVIEW_CELL_EDITABLE
)
935 GValue gvalue
= { 0, };
936 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
937 g_value_set_boolean( &gvalue
, true );
938 g_object_set_property( G_OBJECT(m_renderer
), "editable", &gvalue
);
939 g_value_unset( &gvalue
);
941 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
945 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
947 wxString tmp
= value
;
949 GValue gvalue
= { 0, };
950 g_value_init( &gvalue
, G_TYPE_STRING
);
952 g_value_set_string( &gvalue
, wxGTK_CONV( tmp
) );
954 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( tmp
, GetOwner()->GetOwner()->GetFont() ) );
956 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
957 g_value_unset( &gvalue
);
962 bool wxDataViewTextRenderer::GetValue( wxVariant
&value
)
964 GValue gvalue
= { 0, };
965 g_value_init( &gvalue
, G_TYPE_STRING
);
966 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
967 wxString tmp
= wxGTK_CONV_BACK( g_value_get_string( &gvalue
) );
968 g_value_unset( &gvalue
);
975 // ---------------------------------------------------------
976 // wxDataViewBitmapRenderer
977 // ---------------------------------------------------------
979 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
981 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
) :
982 wxDataViewRenderer( varianttype
, mode
)
984 m_renderer
= (void*) gtk_cell_renderer_pixbuf_new();
987 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
989 if (value
.GetType() == wxT("wxBitmap"))
994 // This may create a Pixbuf representation in the
995 // wxBitmap object (and it will stay there)
996 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
998 GValue gvalue
= { 0, };
999 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1000 g_value_set_object( &gvalue
, pixbuf
);
1001 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1002 g_value_unset( &gvalue
);
1007 if (value
.GetType() == wxT("wxIcon"))
1012 // This may create a Pixbuf representation in the
1013 // wxBitmap object (and it will stay there)
1014 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1016 GValue gvalue
= { 0, };
1017 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1018 g_value_set_object( &gvalue
, pixbuf
);
1019 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1020 g_value_unset( &gvalue
);
1028 bool wxDataViewBitmapRenderer::GetValue( wxVariant
&value
)
1033 // ---------------------------------------------------------
1034 // wxDataViewToggleRenderer
1035 // ---------------------------------------------------------
1038 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1039 gchar
*path
, gpointer user_data
);
1042 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1043 gchar
*path
, gpointer user_data
)
1045 wxDataViewToggleRenderer
*cell
= (wxDataViewToggleRenderer
*) user_data
;
1048 GValue gvalue
= { 0, };
1049 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1050 g_object_get_property( G_OBJECT(renderer
), "active", &gvalue
);
1051 bool tmp
= g_value_get_boolean( &gvalue
);
1052 g_value_unset( &gvalue
);
1056 wxVariant value
= tmp
;
1057 if (!cell
->Validate( value
))
1060 wxDataViewListModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1062 GtkTreePath
*gtk_path
= gtk_tree_path_new_from_string( path
);
1063 unsigned int model_row
= (unsigned int)gtk_tree_path_get_indices (gtk_path
)[0];
1064 gtk_tree_path_free( gtk_path
);
1066 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1068 model
->SetValue( value
, model_col
, model_row
);
1069 model
->ValueChanged( model_col
, model_row
);
1072 IMPLEMENT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
1074 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
1075 wxDataViewCellMode mode
) :
1076 wxDataViewRenderer( varianttype
, mode
)
1078 m_renderer
= (void*) gtk_cell_renderer_toggle_new();
1080 if (m_mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
1082 g_signal_connect_after( m_renderer
, "toggled", G_CALLBACK(wxGtkToggleRendererToggledCallback
), this );
1087 GValue gvalue
= { 0, };
1088 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1089 g_value_set_boolean( &gvalue
, false );
1090 g_object_set_property( G_OBJECT(m_renderer
), "activatable", &gvalue
);
1091 g_value_unset( &gvalue
);
1093 GValue gvalue2
= { 0, };
1094 g_value_init( &gvalue2
, gtk_cell_renderer_mode_get_type() );
1095 g_value_set_enum( &gvalue2
, GTK_CELL_RENDERER_MODE_INERT
);
1096 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue2
);
1097 g_value_unset( &gvalue2
);
1102 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
1106 GValue gvalue
= { 0, };
1107 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1108 g_value_set_boolean( &gvalue
, tmp
);
1109 g_object_set_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1110 g_value_unset( &gvalue
);
1115 bool wxDataViewToggleRenderer::GetValue( wxVariant
&value
)
1117 GValue gvalue
= { 0, };
1118 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1119 g_object_get_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1120 bool tmp
= g_value_get_boolean( &gvalue
);
1121 g_value_unset( &gvalue
);
1128 // ---------------------------------------------------------
1129 // wxDataViewCustomRenderer
1130 // ---------------------------------------------------------
1132 class wxDataViewCtrlDC
: public wxWindowDC
1135 wxDataViewCtrlDC( wxDataViewCtrl
*window
)
1137 GtkWidget
*widget
= window
->m_treeview
;
1141 m_context
= window
->GtkGetPangoDefaultContext();
1142 m_layout
= pango_layout_new( m_context
);
1143 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
1145 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
1147 // Set m_window later
1149 // m_owner = window;
1153 // ---------------------------------------------------------
1154 // wxDataViewCustomRenderer
1155 // ---------------------------------------------------------
1157 IMPLEMENT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
1159 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
1160 wxDataViewCellMode mode
, bool no_init
) :
1161 wxDataViewRenderer( varianttype
, mode
)
1171 bool wxDataViewCustomRenderer::Init()
1173 GtkWxCellRenderer
*renderer
= (GtkWxCellRenderer
*) gtk_wx_cell_renderer_new();
1174 renderer
->cell
= this;
1176 m_renderer
= (void*) renderer
;
1178 if (m_mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
1180 GValue gvalue
= { 0, };
1181 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1182 g_value_set_enum( &gvalue
, GTK_CELL_RENDERER_MODE_ACTIVATABLE
);
1183 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue
);
1184 g_value_unset( &gvalue
);
1190 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
1196 wxDC
*wxDataViewCustomRenderer::GetDC()
1200 if (GetOwner() == NULL
)
1202 if (GetOwner()->GetOwner() == NULL
)
1204 m_dc
= new wxDataViewCtrlDC( GetOwner()->GetOwner() );
1210 // ---------------------------------------------------------
1211 // wxDataViewProgressRenderer
1212 // ---------------------------------------------------------
1214 IMPLEMENT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
1216 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
1217 const wxString
&varianttype
, wxDataViewCellMode mode
) :
1218 wxDataViewCustomRenderer( varianttype
, mode
, true )
1224 if (!gtk_check_version(2,6,0))
1226 m_renderer
= (void*) gtk_cell_renderer_progress_new();
1228 GValue gvalue
= { 0, };
1229 g_value_init( &gvalue
, G_TYPE_STRING
);
1231 g_value_set_string( &gvalue
, wxGTK_CONV(m_label
) );
1233 g_value_set_string( &gvalue
, wxGTK_CONV_SYS(m_label
) );
1235 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1236 g_value_unset( &gvalue
);
1241 // Use custom cell code
1242 wxDataViewCustomRenderer::Init();
1246 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
1250 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
1253 if (!gtk_check_version(2,6,0))
1255 gint tmp
= (long) value
;
1256 GValue gvalue
= { 0, };
1257 g_value_init( &gvalue
, G_TYPE_INT
);
1258 g_value_set_int( &gvalue
, tmp
);
1259 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
1260 g_value_unset( &gvalue
);
1265 m_value
= (long) value
;
1267 if (m_value
< 0) m_value
= 0;
1268 if (m_value
> 100) m_value
= 100;
1274 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1276 double pct
= (double)m_value
/ 100.0;
1278 bar
.width
= (int)(cell
.width
* pct
);
1279 dc
->SetPen( *wxTRANSPARENT_PEN
);
1280 dc
->SetBrush( *wxBLUE_BRUSH
);
1281 dc
->DrawRectangle( bar
);
1283 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1284 dc
->SetPen( *wxBLACK_PEN
);
1285 dc
->DrawRectangle( cell
);
1290 wxSize
wxDataViewProgressRenderer::GetSize()
1292 return wxSize(40,12);
1295 // ---------------------------------------------------------
1296 // wxDataViewDateRenderer
1297 // ---------------------------------------------------------
1299 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
1302 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
1303 wxDataViewListModel
*model
, unsigned int col
, unsigned int row
) :
1304 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
1309 m_cal
= new wxCalendarCtrl( this, -1, *value
);
1310 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
1311 sizer
->Add( m_cal
, 1, wxGROW
);
1316 virtual void OnDismiss()
1320 void OnCalendar( wxCalendarEvent
&event
);
1322 wxCalendarCtrl
*m_cal
;
1323 wxDataViewListModel
*m_model
;
1328 DECLARE_EVENT_TABLE()
1331 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
1332 EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar
)
1335 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
1337 wxDateTime date
= event
.GetDate();
1338 wxVariant value
= date
;
1339 m_model
->SetValue( value
, m_col
, m_row
);
1340 m_model
->ValueChanged( m_col
, m_row
);
1344 IMPLEMENT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
1346 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
1347 wxDataViewCellMode mode
) :
1348 wxDataViewCustomRenderer( varianttype
, mode
)
1352 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
1354 m_date
= value
.GetDateTime();
1359 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1361 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
1362 wxString tmp
= m_date
.FormatDate();
1363 dc
->DrawText( tmp
, cell
.x
, cell
.y
);
1368 wxSize
wxDataViewDateRenderer::GetSize()
1370 wxDataViewCtrl
* view
= GetOwner()->GetOwner();
1371 wxString tmp
= m_date
.FormatDate();
1373 view
->GetTextExtent( tmp
, &x
, &y
, &d
);
1374 return wxSize(x
,y
+d
);
1377 bool wxDataViewDateRenderer::Activate( wxRect cell
, wxDataViewListModel
*model
, unsigned int col
, unsigned int row
)
1380 model
->GetValue( variant
, col
, row
);
1381 wxDateTime value
= variant
.GetDateTime();
1383 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
1384 GetOwner()->GetOwner()->GetParent(), &value
, model
, col
, row
);
1385 wxPoint pos
= wxGetMousePosition();
1388 popup
->Popup( popup
->m_cal
);
1393 // ---------------------------------------------------------
1395 // ---------------------------------------------------------
1399 gtk_dataview_header_button_press_callback( GtkWidget
*widget
,
1400 GdkEventButton
*gdk_event
,
1401 wxDataViewColumn
*column
)
1403 if (gdk_event
->type
!= GDK_BUTTON_PRESS
)
1406 if (gdk_event
->button
== 1)
1408 wxDataViewCtrl
*dv
= column
->GetOwner();
1409 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, dv
->GetId() );
1410 event
.SetDataViewColumn( column
);
1411 event
.SetModel( dv
->GetModel() );
1412 dv
->GetEventHandler()->ProcessEvent( event
);
1419 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
1420 GtkCellRenderer
*cell
,
1421 GtkTreeModel
*model
,
1427 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
1428 GtkCellRenderer
*renderer
,
1429 GtkTreeModel
*model
,
1433 g_return_if_fail (GTK_IS_WX_LIST_STORE (model
));
1434 GtkWxListStore
*list_store
= (GtkWxListStore
*) model
;
1436 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
1438 unsigned int model_row
= (unsigned int) iter
->user_data
;
1441 list_store
->model
->GetValue( value
, cell
->GetOwner()->GetModelColumn(), model_row
);
1443 if (value
.GetType() != cell
->GetVariantType())
1444 wxLogError( wxT("Wrong type, required: %s but: %s"),
1445 value
.GetType().c_str(),
1446 cell
->GetVariantType().c_str() );
1448 cell
->SetValue( value
);
1451 IMPLEMENT_CLASS(wxDataViewColumn
, wxDataViewColumnBase
)
1453 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
, unsigned int model_column
,
1454 int width
, int flags
) :
1455 wxDataViewColumnBase( title
, cell
, model_column
, width
, flags
)
1457 m_isConnected
= false;
1459 GtkCellRenderer
*renderer
= (GtkCellRenderer
*) cell
->GetGtkHandle();
1461 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
1462 m_column
= (void*) column
;
1464 gtk_tree_view_column_set_clickable( column
, true );
1468 if (flags
& wxDATAVIEW_COL_RESIZABLE
)
1469 gtk_tree_view_column_set_resizable( column
, true );
1470 if (flags
& wxDATAVIEW_COL_HIDDEN
)
1471 gtk_tree_view_column_set_visible( column
, false );
1472 if (flags
& wxDATAVIEW_COL_SORTABLE
)
1473 gtk_tree_view_column_set_sort_indicator( column
, true );
1476 gtk_tree_view_column_set_fixed_width( column
, width
);
1478 gtk_tree_view_column_set_fixed_width( column
, 70 ); // FIXME
1480 gtk_tree_view_column_set_sizing( column
, GTK_TREE_VIEW_COLUMN_FIXED
);
1482 gtk_tree_view_column_pack_end( column
, renderer
, FALSE
);
1484 gtk_tree_view_column_set_cell_data_func( column
, renderer
,
1485 wxGtkTreeCellDataFunc
, (gpointer
) cell
, NULL
);
1489 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
, unsigned int model_column
,
1490 int width
, int flags
) :
1491 wxDataViewColumnBase( bitmap
, cell
, model_column
, width
, flags
)
1493 m_isConnected
= false;
1495 GtkCellRenderer
*renderer
= (GtkCellRenderer
*) cell
->GetGtkHandle();
1497 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
1498 m_column
= (void*) column
;
1500 SetBitmap( bitmap
);
1502 if (flags
& wxDATAVIEW_COL_RESIZABLE
)
1503 gtk_tree_view_column_set_resizable( column
, true );
1504 if (flags
& wxDATAVIEW_COL_HIDDEN
)
1505 gtk_tree_view_column_set_visible( column
, false );
1506 if (flags
& wxDATAVIEW_COL_SORTABLE
)
1507 gtk_tree_view_column_set_sort_indicator( column
, true );
1510 gtk_tree_view_column_set_fixed_width( column
, width
);
1512 gtk_tree_view_column_set_fixed_width( column
, 70 ); // FIXME
1514 gtk_tree_view_column_set_sizing( column
, GTK_TREE_VIEW_COLUMN_FIXED
);
1516 gtk_tree_view_column_pack_end( column
, renderer
, FALSE
);
1518 gtk_tree_view_column_set_cell_data_func( column
, renderer
,
1519 wxGtkTreeCellDataFunc
, (gpointer
) cell
, NULL
);
1522 wxDataViewColumn::~wxDataViewColumn()
1526 void wxDataViewColumn::OnInternalIdle()
1531 if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview
))
1533 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)m_column
;
1536 g_signal_connect(column
->button
, "button_press_event",
1537 G_CALLBACK (gtk_dataview_header_button_press_callback
), this);
1539 m_isConnected
= true;
1544 void wxDataViewColumn::SetOwner( wxDataViewCtrl
*owner
)
1546 wxDataViewColumnBase::SetOwner( owner
);
1548 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)m_column
;
1552 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
1556 void wxDataViewColumn::SetTitle( const wxString
&title
)
1558 wxDataViewColumnBase::SetTitle( title
);
1560 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)m_column
;
1564 // disconnect before column->button gets recreated
1565 g_signal_handlers_disconnect_by_func( column
->button
,
1566 (void*) gtk_dataview_header_button_press_callback
, this);
1568 m_isConnected
= false;
1572 gtk_tree_view_column_set_title( column
, wxGTK_CONV(title
) );
1575 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(title
, GetOwner()->GetFont() ) );
1577 gtk_tree_view_column_set_title( column
, "" );
1580 gtk_tree_view_column_set_widget( column
, NULL
);
1583 void wxDataViewColumn::SetBitmap( const wxBitmap
&bitmap
)
1585 wxDataViewColumnBase::SetBitmap( bitmap
);
1587 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)m_column
;
1590 GtkImage
*gtk_image
= GTK_IMAGE( gtk_image_new() );
1592 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
1593 if (bitmap
.GetMask())
1594 mask
= bitmap
.GetMask()->GetBitmap();
1596 if (bitmap
.HasPixbuf())
1598 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image
),
1599 bitmap
.GetPixbuf());
1603 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image
),
1604 bitmap
.GetPixmap(), mask
);
1606 gtk_widget_show( GTK_WIDGET(gtk_image
) );
1608 gtk_tree_view_column_set_widget( column
, GTK_WIDGET(gtk_image
) );
1612 gtk_tree_view_column_set_widget( column
, NULL
);
1616 void wxDataViewColumn::SetAlignment( wxAlignment align
)
1618 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)m_column
;
1620 gfloat xalign
= 0.0;
1621 if (align
== wxALIGN_RIGHT
)
1623 if (align
== wxALIGN_CENTER
)
1626 gtk_tree_view_column_set_alignment( column
, xalign
);
1629 void wxDataViewColumn::SetSortable( bool sortable
)
1631 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)m_column
;
1632 gtk_tree_view_column_set_sort_indicator( column
, sortable
);
1635 bool wxDataViewColumn::GetSortable()
1637 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)m_column
;
1638 return gtk_tree_view_column_get_sort_indicator( column
);
1641 void wxDataViewColumn::SetSortOrder( bool ascending
)
1643 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)m_column
;
1646 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_ASCENDING
);
1648 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_DESCENDING
);
1651 bool wxDataViewColumn::IsSortOrderAscending()
1653 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)m_column
;
1655 return (gtk_tree_view_column_get_sort_order( column
) != GTK_SORT_DESCENDING
);
1658 int wxDataViewColumn::GetWidth()
1660 return gtk_tree_view_column_get_width( (GtkTreeViewColumn
*)m_column
);
1663 void wxDataViewColumn::SetFixedWidth( int width
)
1665 gtk_tree_view_column_set_fixed_width( (GtkTreeViewColumn
*)m_column
, width
);
1668 int wxDataViewColumn::GetFixedWidth()
1670 return gtk_tree_view_column_get_fixed_width( (GtkTreeViewColumn
*)m_column
);
1673 //-----------------------------------------------------------------------------
1674 // wxDataViewCtrl signal callbacks
1675 //-----------------------------------------------------------------------------
1678 wxdataview_selection_changed_callback( GtkTreeSelection
* selection
, wxDataViewCtrl
*dv
)
1680 if (!GTK_WIDGET_REALIZED(dv
->m_widget
))
1683 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ROW_SELECTED
, dv
->GetId() );
1684 event
.SetRow( dv
->GetSelection() );
1685 event
.SetModel( dv
->GetModel() );
1686 dv
->GetEventHandler()->ProcessEvent( event
);
1690 wxdataview_row_activated_callback( GtkTreeView
* treeview
, GtkTreePath
*path
,
1691 GtkTreeViewColumn
*column
, wxDataViewCtrl
*dv
)
1693 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ROW_ACTIVATED
, dv
->GetId() );
1694 unsigned int row
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
1695 event
.SetRow( row
);
1696 event
.SetModel( dv
->GetModel() );
1697 dv
->GetEventHandler()->ProcessEvent( event
);
1700 //-----------------------------------------------------------------------------
1702 //-----------------------------------------------------------------------------
1704 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
1706 wxDataViewCtrl::~wxDataViewCtrl()
1709 GetModel()->RemoveNotifier( m_notifier
);
1712 void wxDataViewCtrl::Init()
1717 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
1718 const wxPoint
& pos
, const wxSize
& size
,
1719 long style
, const wxValidator
& validator
)
1723 m_needParent
= true;
1724 m_acceptsFocus
= true;
1726 if (!PreCreation( parent
, pos
, size
) ||
1727 !CreateBase( parent
, id
, pos
, size
, style
, validator
))
1729 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
1733 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
1735 GtkScrolledWindowSetBorder(m_widget
, style
);
1737 m_treeview
= gtk_tree_view_new();
1738 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
1741 if (!gtk_check_version(2,6,0))
1742 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), TRUE
);
1745 if (style
& wxDV_MULTIPLE
)
1747 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
1748 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
1751 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
1752 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
);
1753 gtk_widget_show (m_treeview
);
1755 m_parent
->DoAddChild( this );
1759 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
1760 g_signal_connect_after (selection
, "changed",
1761 G_CALLBACK (wxdataview_selection_changed_callback
), this);
1762 g_signal_connect_after (m_treeview
, "row_activated",
1763 G_CALLBACK (wxdataview_row_activated_callback
), this);
1768 void wxDataViewCtrl::OnInternalIdle()
1770 wxWindow::OnInternalIdle();
1772 unsigned int cols
= GetNumberOfColumns();
1774 for (i
= 0; i
< cols
; i
++)
1776 wxDataViewColumn
*col
= GetColumn( i
);
1777 col
->OnInternalIdle();
1781 bool wxDataViewCtrl::AssociateModel( wxDataViewListModel
*model
)
1783 if (!wxDataViewCtrlBase::AssociateModel( model
))
1786 GtkWxListStore
*gtk_store
= wxgtk_list_store_new();
1787 gtk_store
->model
= model
;
1789 m_notifier
= new wxGtkDataViewListModelNotifier( gtk_store
, model
);
1791 model
->AddNotifier( m_notifier
);
1793 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), GTK_TREE_MODEL(gtk_store
) );
1794 g_object_unref( gtk_store
);
1799 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
1801 if (!wxDataViewCtrlBase::AppendColumn(col
))
1804 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)col
->GetGtkHandle();
1806 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
), column
);
1811 void wxDataViewCtrl::SetSelection( int row
)
1813 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
1817 gtk_tree_selection_unselect_all( selection
);
1821 GtkTreePath
*path
= gtk_tree_path_new ();
1822 gtk_tree_path_append_index( path
, row
);
1824 gtk_tree_selection_select_path( selection
, path
);
1826 gtk_tree_path_free( path
);
1830 void wxDataViewCtrl::Unselect( unsigned int row
)
1832 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
1834 GtkTreePath
*path
= gtk_tree_path_new ();
1835 gtk_tree_path_append_index( path
, row
);
1837 gtk_tree_selection_unselect_path( selection
, path
);
1839 gtk_tree_path_free( path
);
1842 void wxDataViewCtrl::SetSelectionRange( unsigned int from
, unsigned int to
)
1846 void wxDataViewCtrl::SetSelections( const wxArrayInt
& aSelections
)
1850 bool wxDataViewCtrl::IsSelected( unsigned int row
) const
1852 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
1854 GtkTreePath
*path
= gtk_tree_path_new ();
1855 gtk_tree_path_append_index( path
, row
);
1857 gboolean ret
= gtk_tree_selection_path_is_selected( selection
, path
);
1859 gtk_tree_path_free( path
);
1864 int wxDataViewCtrl::GetSelection() const
1866 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
1867 if (HasFlag(wxDV_MULTIPLE
))
1869 GtkTreeModel
*model
;
1870 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
1875 // list = g_list_nth( list, 0 ); should be a noop
1876 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
1878 unsigned int row
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
1881 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
1882 g_list_free( list
);
1890 GtkTreeModel
*model
;
1892 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
1895 unsigned int row
= (wxUIntPtr
) iter
.user_data
;
1903 int wxDataViewCtrl::GetSelections(wxArrayInt
& aSelections
) const
1905 aSelections
.Clear();
1907 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
1908 if (HasFlag(wxDV_MULTIPLE
))
1910 GtkTreeModel
*model
;
1911 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
1917 // list = g_list_nth( list, 0 ); should be a noop
1918 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
1920 unsigned int row
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
1922 aSelections
.Add( (int) row
);
1924 list
= g_list_next( list
);
1928 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
1929 g_list_free( list
);
1935 GtkTreeModel
*model
;
1937 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
1940 unsigned int row
= (wxUIntPtr
) iter
.user_data
;
1941 aSelections
.Add( (int) row
);
1951 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1953 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
1958 // !wxUSE_GENERICDATAVIEWCTRL
1961 // wxUSE_DATAVIEWCTRL