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 wxPrintf( wxT("Hi\n") );
305 wxDataViewListModel
*model
= list_store
->model
;
306 wxString mtype
= model
->GetColType( (unsigned int) column
);
307 if (mtype
== wxT("string"))
310 g_value_init( value
, G_TYPE_STRING
);
311 model
->GetValue( variant
, (unsigned int) column
, (unsigned int) iter
->user_data
);
312 g_value_set_string( value
, wxGTK_CONV(variant
.GetString()) );
320 GtkTreeDataList
*list
;
321 gint tmp_column
= column
;
323 g_return_if_fail (column
< GTK_LIST_STORE (tree_model
)->n_columns
);
324 g_return_if_fail (GTK_LIST_STORE (tree_model
)->stamp
== iter
->stamp
);
326 list
= G_SLIST (iter
->user_data
)->data
;
328 while (tmp_column
-- > 0 && list
)
332 g_value_init (value
, GTK_LIST_STORE (tree_model
)->column_headers
[column
]);
334 _gtk_tree_data_list_node_to_value (list
,
335 GTK_LIST_STORE (tree_model
)->column_headers
[column
],
342 wxgtk_list_store_iter_next (GtkTreeModel
*tree_model
,
345 g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model
), FALSE
);
346 GtkWxListStore
*list_store
= (GtkWxListStore
*) tree_model
;
348 g_return_val_if_fail (list_store
->stamp
== iter
->stamp
, FALSE
);
350 int n
= (wxUIntPtr
) iter
->user_data
;
355 if (n
>= (int) list_store
->model
->GetNumberOfRows()-1)
358 iter
->user_data
= (gpointer
) ++n
;
364 wxgtk_list_store_iter_children (GtkTreeModel
*tree_model
,
368 g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model
), FALSE
);
369 GtkWxListStore
*list_store
= (GtkWxListStore
*) tree_model
;
371 // this is a list, nodes have no children
375 iter
->stamp
= list_store
->stamp
;
376 iter
->user_data
= (gpointer
) -1;
382 wxgtk_list_store_iter_has_child (GtkTreeModel
*tree_model
,
389 wxgtk_list_store_iter_n_children (GtkTreeModel
*tree_model
,
392 g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model
), -1);
393 GtkWxListStore
*list_store
= (GtkWxListStore
*) tree_model
;
396 return (gint
) list_store
->model
->GetNumberOfRows();
398 g_return_val_if_fail (list_store
->stamp
== iter
->stamp
, -1);
404 wxgtk_list_store_iter_nth_child (GtkTreeModel
*tree_model
,
409 g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model
), FALSE
);
410 GtkWxListStore
*list_store
= (GtkWxListStore
*) tree_model
;
418 if (n
>= (gint
) list_store
->model
->GetNumberOfRows())
421 iter
->stamp
= list_store
->stamp
;
422 iter
->user_data
= (gpointer
) n
;
428 wxgtk_list_store_iter_parent (GtkTreeModel
*tree_model
,
435 //-----------------------------------------------------------------------------
436 // define new GTK+ class wxGtkRendererRenderer
437 //-----------------------------------------------------------------------------
441 #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ())
442 #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer))
443 #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
444 #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER))
445 #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER))
446 #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
448 GType
gtk_wx_cell_renderer_get_type (void);
450 typedef struct _GtkWxCellRenderer GtkWxCellRenderer
;
451 typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass
;
453 struct _GtkWxCellRenderer
455 GtkCellRenderer parent
;
458 wxDataViewCustomRenderer
*cell
;
462 struct _GtkWxCellRendererClass
464 GtkCellRendererClass cell_parent_class
;
468 static GtkCellRenderer
*gtk_wx_cell_renderer_new (void);
469 static void gtk_wx_cell_renderer_init (
470 GtkWxCellRenderer
*cell
);
471 static void gtk_wx_cell_renderer_class_init(
472 GtkWxCellRendererClass
*klass
);
473 static void gtk_wx_cell_renderer_finalize (
475 static void gtk_wx_cell_renderer_get_size (
476 GtkCellRenderer
*cell
,
478 GdkRectangle
*rectangle
,
483 static void gtk_wx_cell_renderer_render (
484 GtkCellRenderer
*cell
,
487 GdkRectangle
*background_area
,
488 GdkRectangle
*cell_area
,
489 GdkRectangle
*expose_area
,
490 GtkCellRendererState flags
);
491 static gboolean
gtk_wx_cell_renderer_activate(
492 GtkCellRenderer
*cell
,
496 GdkRectangle
*background_area
,
497 GdkRectangle
*cell_area
,
498 GtkCellRendererState flags
);
500 static GObjectClass
*cell_parent_class
= NULL
;
505 gtk_wx_cell_renderer_get_type (void)
507 static GType cell_wx_type
= 0;
511 static const GTypeInfo cell_wx_info
=
513 sizeof (GtkWxCellRendererClass
),
514 NULL
, /* base_init */
515 NULL
, /* base_finalize */
516 (GClassInitFunc
) gtk_wx_cell_renderer_class_init
,
517 NULL
, /* class_finalize */
518 NULL
, /* class_data */
519 sizeof (GtkWxCellRenderer
),
521 (GInstanceInitFunc
) gtk_wx_cell_renderer_init
,
524 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER
,
525 "GtkWxCellRenderer", &cell_wx_info
, (GTypeFlags
)0 );
532 gtk_wx_cell_renderer_init (GtkWxCellRenderer
*cell
)
535 cell
->last_click
= 0;
539 gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass
*klass
)
541 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
542 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
544 cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
546 object_class
->finalize
= gtk_wx_cell_renderer_finalize
;
548 cell_class
->get_size
= gtk_wx_cell_renderer_get_size
;
549 cell_class
->render
= gtk_wx_cell_renderer_render
;
550 cell_class
->activate
= gtk_wx_cell_renderer_activate
;
554 gtk_wx_cell_renderer_finalize (GObject
*object
)
557 (* G_OBJECT_CLASS (cell_parent_class
)->finalize
) (object
);
561 gtk_wx_cell_renderer_new (void)
563 return (GtkCellRenderer
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER
, NULL
);
567 gtk_wx_cell_renderer_get_size (GtkCellRenderer
*renderer
,
569 GdkRectangle
*cell_area
,
575 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
576 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
578 wxSize size
= cell
->GetSize();
580 gint calc_width
= (gint
) renderer
->xpad
* 2 + size
.x
;
581 gint calc_height
= (gint
) renderer
->ypad
* 2 + size
.y
;
588 if (cell_area
&& size
.x
> 0 && size
.y
> 0)
592 *x_offset
= (gint
)((renderer
->xalign
*
593 (cell_area
->width
- calc_width
- 2 * renderer
->xpad
)));
594 *x_offset
= MAX (*x_offset
, 0) + renderer
->xpad
;
598 *y_offset
= (gint
)((renderer
->yalign
*
599 (cell_area
->height
- calc_height
- 2 * renderer
->ypad
)));
600 *y_offset
= MAX (*y_offset
, 0) + renderer
->ypad
;
608 *height
= calc_height
;
612 gtk_wx_cell_renderer_render (GtkCellRenderer
*renderer
,
615 GdkRectangle
*background_area
,
616 GdkRectangle
*cell_area
,
617 GdkRectangle
*expose_area
,
618 GtkCellRendererState flags
)
621 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
622 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
625 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
631 rect
.x
+= cell_area
->x
;
632 rect
.y
+= cell_area
->y
;
633 rect
.width
-= renderer
->xpad
* 2;
634 rect
.height
-= renderer
->ypad
* 2;
637 if (gdk_rectangle_intersect (expose_area
, &rect
, &dummy
))
639 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
640 wxWindowDC
* dc
= (wxWindowDC
*) cell
->GetDC();
641 if (dc
->m_window
== NULL
)
643 dc
->m_window
= window
;
648 if (flags
& GTK_CELL_RENDERER_SELECTED
)
649 state
|= wxDATAVIEW_CELL_SELECTED
;
650 if (flags
& GTK_CELL_RENDERER_PRELIT
)
651 state
|= wxDATAVIEW_CELL_PRELIT
;
652 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
653 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
654 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
655 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
656 if (flags
& GTK_CELL_RENDERER_FOCUSED
)
657 state
|= wxDATAVIEW_CELL_FOCUSED
;
658 cell
->Render( renderrect
, dc
, state
);
663 gtk_wx_cell_renderer_activate(
664 GtkCellRenderer
*renderer
,
668 GdkRectangle
*background_area
,
669 GdkRectangle
*cell_area
,
670 GtkCellRendererState flags
)
672 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
673 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
676 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
682 rect
.x
+= cell_area
->x
;
683 rect
.y
+= cell_area
->y
;
684 rect
.width
-= renderer
->xpad
* 2;
685 rect
.height
-= renderer
->ypad
* 2;
687 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
689 wxDataViewListModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
691 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
692 unsigned int model_row
= (unsigned int)gtk_tree_path_get_indices (treepath
)[0];
693 gtk_tree_path_free( treepath
);
695 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
697 if (event
->type
== GDK_BUTTON_PRESS
)
699 GdkEventButton
*button_event
= (GdkEventButton
*) event
;
700 wxPoint
pt( ((int) button_event
->x
) - renderrect
.x
,
701 ((int) button_event
->y
) - renderrect
.y
);
704 if (button_event
->button
== 1)
706 if (cell
->LeftClick( pt
, renderrect
, model
, model_col
, model_row
))
708 // TODO: query system double-click time
709 if (button_event
->time
- wxrenderer
->last_click
< 400)
710 if (cell
->Activate( renderrect
, model
, model_col
, model_row
))
713 if (button_event
->button
== 3)
715 if (cell
->RightClick( pt
, renderrect
, model
, model_col
, model_row
))
719 wxrenderer
->last_click
= button_event
->time
;
727 // ---------------------------------------------------------
728 // wxGtkDataViewListModelNotifier
729 // ---------------------------------------------------------
731 class wxGtkDataViewListModelNotifier
: public wxDataViewListModelNotifier
734 wxGtkDataViewListModelNotifier( GtkWxListStore
* gtk_store
, wxDataViewListModel
*wx_model
);
736 virtual bool RowAppended();
737 virtual bool RowPrepended();
738 virtual bool RowInserted( unsigned int before
);
739 virtual bool RowDeleted( unsigned int row
);
740 virtual bool RowChanged( unsigned int row
);
741 virtual bool ValueChanged( unsigned int col
, unsigned int row
);
742 virtual bool RowsReordered( unsigned int *new_order
);
743 virtual bool Cleared();
745 GtkWxListStore
*m_gtk_store
;
746 wxDataViewListModel
*m_wx_model
;
749 // ---------------------------------------------------------
750 // wxGtkDataViewListModelNotifier
751 // ---------------------------------------------------------
753 wxGtkDataViewListModelNotifier::wxGtkDataViewListModelNotifier(
754 GtkWxListStore
* gtk_store
, wxDataViewListModel
*wx_model
)
756 m_gtk_store
= gtk_store
;
757 m_wx_model
= wx_model
;
760 bool wxGtkDataViewListModelNotifier::RowAppended()
762 unsigned int pos
= m_wx_model
->GetNumberOfRows()-1;
765 iter
.stamp
= m_gtk_store
->stamp
;
766 iter
.user_data
= (gpointer
) pos
;
768 GtkTreePath
*path
= gtk_tree_path_new ();
769 gtk_tree_path_append_index (path
, (gint
) pos
);
770 gtk_tree_model_row_inserted (GTK_TREE_MODEL (m_gtk_store
), path
, &iter
);
771 gtk_tree_path_free (path
);
776 bool wxGtkDataViewListModelNotifier::RowPrepended()
779 iter
.stamp
= m_gtk_store
->stamp
;
780 iter
.user_data
= (gpointer
) 0;
782 GtkTreePath
*path
= gtk_tree_path_new ();
783 gtk_tree_path_append_index (path
, (gint
) 0);
784 gtk_tree_model_row_inserted (GTK_TREE_MODEL (m_gtk_store
), path
, &iter
);
785 gtk_tree_path_free (path
);
790 bool wxGtkDataViewListModelNotifier::RowInserted( unsigned int before
)
793 iter
.stamp
= m_gtk_store
->stamp
;
794 iter
.user_data
= (gpointer
) before
;
796 GtkTreePath
*path
= gtk_tree_path_new ();
797 gtk_tree_path_append_index (path
, (gint
) before
);
798 gtk_tree_model_row_inserted (GTK_TREE_MODEL (m_gtk_store
), path
, &iter
);
799 gtk_tree_path_free (path
);
804 bool wxGtkDataViewListModelNotifier::RowDeleted( unsigned int row
)
806 GtkTreePath
*path
= gtk_tree_path_new ();
807 gtk_tree_path_append_index (path
, (gint
) row
);
808 gtk_tree_model_row_deleted (GTK_TREE_MODEL (m_gtk_store
), path
);
809 gtk_tree_path_free (path
);
814 bool wxGtkDataViewListModelNotifier::RowChanged( unsigned int row
)
817 iter
.stamp
= m_gtk_store
->stamp
;
818 iter
.user_data
= (gpointer
) row
;
819 GtkTreePath
*path
= gtk_tree_model_get_path (GTK_TREE_MODEL (m_gtk_store
), &iter
);
820 gtk_tree_model_row_changed (GTK_TREE_MODEL (m_gtk_store
), path
, &iter
);
821 gtk_tree_path_free (path
);
826 bool wxGtkDataViewListModelNotifier::ValueChanged( unsigned int model_col
, unsigned int model_row
)
828 // This adds GTK+'s missing MVC logic for ValueChanged
829 wxNode
*node
= GetOwner()->m_viewingColumns
.GetFirst();
832 wxDataViewViewingColumn
* viewing_column
= (wxDataViewViewingColumn
*) node
->GetData();
833 if (viewing_column
->m_modelColumn
== model_col
)
835 GtkTreeView
*widget
= GTK_TREE_VIEW(viewing_column
->m_viewColumn
->GetOwner()->m_treeview
);
836 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(viewing_column
->m_viewColumn
->GetGtkHandle());
839 GtkTreePath
*path
= gtk_tree_path_new();
840 gtk_tree_path_append_index( path
, model_row
);
841 GdkRectangle cell_area
;
842 gtk_tree_view_get_cell_area( widget
, path
, column
, &cell_area
);
843 gtk_tree_path_free( path
);
845 int ydiff
= column
->button
->allocation
.height
;
847 gtk_widget_queue_draw_area( GTK_WIDGET(widget
),
848 cell_area
.x
, ydiff
+ cell_area
.y
, cell_area
.width
, cell_area
.height
);
851 node
= node
->GetNext();
857 bool wxGtkDataViewListModelNotifier::RowsReordered( unsigned int *new_order
)
859 // Assume sizeof(unsigned int)= == sizeof(gint)
861 GtkTreePath
*path
= gtk_tree_path_new ();
862 gtk_tree_model_rows_reordered (GTK_TREE_MODEL (m_gtk_store
), path
, NULL
, (gint
*)new_order
);
863 gtk_tree_path_free (path
);
865 // This adds GTK+'s missing MVC logic for RowsReordered
866 wxNode
*node
= GetOwner()->m_viewingColumns
.GetFirst();
869 wxDataViewViewingColumn
* viewing_column
= (wxDataViewViewingColumn
*) node
->GetData();
870 GtkTreeView
*widget
= GTK_TREE_VIEW(viewing_column
->m_viewColumn
->GetOwner()->m_treeview
);
871 // Doesn't work yet...
872 gtk_widget_queue_draw( GTK_WIDGET(widget
) );
874 node
= node
->GetNext();
880 bool wxGtkDataViewListModelNotifier::Cleared()
885 // ---------------------------------------------------------
886 // wxDataViewRenderer
887 // ---------------------------------------------------------
889 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
891 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
) :
892 wxDataViewRendererBase( varianttype
, mode
)
897 // ---------------------------------------------------------
898 // wxDataViewTextRenderer
899 // ---------------------------------------------------------
902 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
903 gchar
*arg1
, gchar
*arg2
, gpointer user_data
);
906 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
907 gchar
*arg1
, gchar
*arg2
, gpointer user_data
)
909 wxDataViewTextRenderer
*cell
= (wxDataViewTextRenderer
*) user_data
;
911 wxString tmp
= wxGTK_CONV_BACK( arg2
);
912 wxVariant value
= tmp
;
913 if (!cell
->Validate( value
))
916 wxDataViewListModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
918 GtkTreePath
*path
= gtk_tree_path_new_from_string( arg1
);
919 unsigned int model_row
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
920 gtk_tree_path_free( path
);
922 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
924 model
->SetValue( value
, model_col
, model_row
);
925 model
->ValueChanged( model_col
, model_row
);
928 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
930 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
) :
931 wxDataViewRenderer( varianttype
, mode
)
933 m_renderer
= (void*) gtk_cell_renderer_text_new();
935 if (m_mode
& wxDATAVIEW_CELL_EDITABLE
)
937 GValue gvalue
= { 0, };
938 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
939 g_value_set_boolean( &gvalue
, true );
940 g_object_set_property( G_OBJECT(m_renderer
), "editable", &gvalue
);
941 g_value_unset( &gvalue
);
943 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
947 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
949 wxString tmp
= value
;
951 GValue gvalue
= { 0, };
952 g_value_init( &gvalue
, G_TYPE_STRING
);
954 g_value_set_string( &gvalue
, wxGTK_CONV( tmp
) );
956 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( tmp
, GetOwner()->GetOwner()->GetFont() ) );
958 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
959 g_value_unset( &gvalue
);
964 bool wxDataViewTextRenderer::GetValue( wxVariant
&value
)
966 GValue gvalue
= { 0, };
967 g_value_init( &gvalue
, G_TYPE_STRING
);
968 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
969 wxString tmp
= wxGTK_CONV_BACK( g_value_get_string( &gvalue
) );
970 g_value_unset( &gvalue
);
977 // ---------------------------------------------------------
978 // wxDataViewBitmapRenderer
979 // ---------------------------------------------------------
981 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
983 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
) :
984 wxDataViewRenderer( varianttype
, mode
)
986 m_renderer
= (void*) gtk_cell_renderer_pixbuf_new();
989 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
991 if (value
.GetType() == wxT("wxBitmap"))
996 // This may create a Pixbuf representation in the
997 // wxBitmap object (and it will stay there)
998 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1000 GValue gvalue
= { 0, };
1001 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1002 g_value_set_object( &gvalue
, pixbuf
);
1003 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1004 g_value_unset( &gvalue
);
1009 if (value
.GetType() == wxT("wxIcon"))
1014 // This may create a Pixbuf representation in the
1015 // wxBitmap object (and it will stay there)
1016 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
1018 GValue gvalue
= { 0, };
1019 g_value_init( &gvalue
, G_TYPE_OBJECT
);
1020 g_value_set_object( &gvalue
, pixbuf
);
1021 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
1022 g_value_unset( &gvalue
);
1030 bool wxDataViewBitmapRenderer::GetValue( wxVariant
&value
)
1035 // ---------------------------------------------------------
1036 // wxDataViewToggleRenderer
1037 // ---------------------------------------------------------
1040 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1041 gchar
*path
, gpointer user_data
);
1044 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1045 gchar
*path
, gpointer user_data
)
1047 wxDataViewToggleRenderer
*cell
= (wxDataViewToggleRenderer
*) user_data
;
1050 GValue gvalue
= { 0, };
1051 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1052 g_object_get_property( G_OBJECT(renderer
), "active", &gvalue
);
1053 bool tmp
= g_value_get_boolean( &gvalue
);
1054 g_value_unset( &gvalue
);
1058 wxVariant value
= tmp
;
1059 if (!cell
->Validate( value
))
1062 wxDataViewListModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1064 GtkTreePath
*gtk_path
= gtk_tree_path_new_from_string( path
);
1065 unsigned int model_row
= (unsigned int)gtk_tree_path_get_indices (gtk_path
)[0];
1066 gtk_tree_path_free( gtk_path
);
1068 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1070 model
->SetValue( value
, model_col
, model_row
);
1071 model
->ValueChanged( model_col
, model_row
);
1074 IMPLEMENT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
1076 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
1077 wxDataViewCellMode mode
) :
1078 wxDataViewRenderer( varianttype
, mode
)
1080 m_renderer
= (void*) gtk_cell_renderer_toggle_new();
1082 if (m_mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
1084 g_signal_connect_after( m_renderer
, "toggled", G_CALLBACK(wxGtkToggleRendererToggledCallback
), this );
1089 GValue gvalue
= { 0, };
1090 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1091 g_value_set_boolean( &gvalue
, false );
1092 g_object_set_property( G_OBJECT(m_renderer
), "activatable", &gvalue
);
1093 g_value_unset( &gvalue
);
1095 GValue gvalue2
= { 0, };
1096 g_value_init( &gvalue2
, gtk_cell_renderer_mode_get_type() );
1097 g_value_set_enum( &gvalue2
, GTK_CELL_RENDERER_MODE_INERT
);
1098 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue2
);
1099 g_value_unset( &gvalue2
);
1104 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
1108 GValue gvalue
= { 0, };
1109 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1110 g_value_set_boolean( &gvalue
, tmp
);
1111 g_object_set_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1112 g_value_unset( &gvalue
);
1117 bool wxDataViewToggleRenderer::GetValue( wxVariant
&value
)
1119 GValue gvalue
= { 0, };
1120 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1121 g_object_get_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1122 bool tmp
= g_value_get_boolean( &gvalue
);
1123 g_value_unset( &gvalue
);
1130 // ---------------------------------------------------------
1131 // wxDataViewCustomRenderer
1132 // ---------------------------------------------------------
1134 class wxDataViewCtrlDC
: public wxWindowDC
1137 wxDataViewCtrlDC( wxDataViewCtrl
*window
)
1139 GtkWidget
*widget
= window
->m_treeview
;
1143 m_context
= window
->GtkGetPangoDefaultContext();
1144 m_layout
= pango_layout_new( m_context
);
1145 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
1147 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
1149 // Set m_window later
1151 // m_owner = window;
1155 // ---------------------------------------------------------
1156 // wxDataViewCustomRenderer
1157 // ---------------------------------------------------------
1159 IMPLEMENT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
1161 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
1162 wxDataViewCellMode mode
, bool no_init
) :
1163 wxDataViewRenderer( varianttype
, mode
)
1173 bool wxDataViewCustomRenderer::Init()
1175 GtkWxCellRenderer
*renderer
= (GtkWxCellRenderer
*) gtk_wx_cell_renderer_new();
1176 renderer
->cell
= this;
1178 m_renderer
= (void*) renderer
;
1180 if (m_mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
1182 GValue gvalue
= { 0, };
1183 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1184 g_value_set_enum( &gvalue
, GTK_CELL_RENDERER_MODE_ACTIVATABLE
);
1185 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue
);
1186 g_value_unset( &gvalue
);
1192 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
1198 wxDC
*wxDataViewCustomRenderer::GetDC()
1202 if (GetOwner() == NULL
)
1204 if (GetOwner()->GetOwner() == NULL
)
1206 m_dc
= new wxDataViewCtrlDC( GetOwner()->GetOwner() );
1212 // ---------------------------------------------------------
1213 // wxDataViewProgressRenderer
1214 // ---------------------------------------------------------
1216 IMPLEMENT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
1218 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
1219 const wxString
&varianttype
, wxDataViewCellMode mode
) :
1220 wxDataViewCustomRenderer( varianttype
, mode
, true )
1226 if (!gtk_check_version(2,6,0))
1228 m_renderer
= (void*) gtk_cell_renderer_progress_new();
1230 GValue gvalue
= { 0, };
1231 g_value_init( &gvalue
, G_TYPE_STRING
);
1233 g_value_set_string( &gvalue
, wxGTK_CONV(m_label
) );
1235 g_value_set_string( &gvalue
, wxGTK_CONV_SYS(m_label
) );
1237 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1238 g_value_unset( &gvalue
);
1243 // Use custom cell code
1244 wxDataViewCustomRenderer::Init();
1248 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
1252 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
1255 if (!gtk_check_version(2,6,0))
1257 gint tmp
= (long) value
;
1258 GValue gvalue
= { 0, };
1259 g_value_init( &gvalue
, G_TYPE_INT
);
1260 g_value_set_int( &gvalue
, tmp
);
1261 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
1262 g_value_unset( &gvalue
);
1267 m_value
= (long) value
;
1269 if (m_value
< 0) m_value
= 0;
1270 if (m_value
> 100) m_value
= 100;
1276 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1278 double pct
= (double)m_value
/ 100.0;
1280 bar
.width
= (int)(cell
.width
* pct
);
1281 dc
->SetPen( *wxTRANSPARENT_PEN
);
1282 dc
->SetBrush( *wxBLUE_BRUSH
);
1283 dc
->DrawRectangle( bar
);
1285 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1286 dc
->SetPen( *wxBLACK_PEN
);
1287 dc
->DrawRectangle( cell
);
1292 wxSize
wxDataViewProgressRenderer::GetSize()
1294 return wxSize(40,12);
1297 // ---------------------------------------------------------
1298 // wxDataViewDateRenderer
1299 // ---------------------------------------------------------
1301 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
1304 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
1305 wxDataViewListModel
*model
, unsigned int col
, unsigned int row
) :
1306 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
1311 m_cal
= new wxCalendarCtrl( this, -1, *value
);
1312 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
1313 sizer
->Add( m_cal
, 1, wxGROW
);
1318 virtual void OnDismiss()
1322 void OnCalendar( wxCalendarEvent
&event
);
1324 wxCalendarCtrl
*m_cal
;
1325 wxDataViewListModel
*m_model
;
1330 DECLARE_EVENT_TABLE()
1333 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
1334 EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar
)
1337 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
1339 wxDateTime date
= event
.GetDate();
1340 wxVariant value
= date
;
1341 m_model
->SetValue( value
, m_col
, m_row
);
1342 m_model
->ValueChanged( m_col
, m_row
);
1346 IMPLEMENT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
1348 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
1349 wxDataViewCellMode mode
) :
1350 wxDataViewCustomRenderer( varianttype
, mode
)
1354 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
1356 m_date
= value
.GetDateTime();
1361 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1363 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
1364 wxString tmp
= m_date
.FormatDate();
1365 dc
->DrawText( tmp
, cell
.x
, cell
.y
);
1370 wxSize
wxDataViewDateRenderer::GetSize()
1372 wxDataViewCtrl
* view
= GetOwner()->GetOwner();
1373 wxString tmp
= m_date
.FormatDate();
1375 view
->GetTextExtent( tmp
, &x
, &y
, &d
);
1376 return wxSize(x
,y
+d
);
1379 bool wxDataViewDateRenderer::Activate( wxRect cell
, wxDataViewListModel
*model
, unsigned int col
, unsigned int row
)
1382 model
->GetValue( variant
, col
, row
);
1383 wxDateTime value
= variant
.GetDateTime();
1385 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
1386 GetOwner()->GetOwner()->GetParent(), &value
, model
, col
, row
);
1387 wxPoint pos
= wxGetMousePosition();
1390 popup
->Popup( popup
->m_cal
);
1395 // ---------------------------------------------------------
1397 // ---------------------------------------------------------
1401 gtk_dataview_header_button_press_callback( GtkWidget
*widget
,
1402 GdkEventButton
*gdk_event
,
1403 wxDataViewColumn
*column
)
1405 if (gdk_event
->type
!= GDK_BUTTON_PRESS
)
1408 if (gdk_event
->button
== 1)
1410 wxDataViewCtrl
*dv
= column
->GetOwner();
1411 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, dv
->GetId() );
1412 event
.SetDataViewColumn( column
);
1413 event
.SetModel( dv
->GetModel() );
1414 dv
->GetEventHandler()->ProcessEvent( event
);
1421 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
1422 GtkCellRenderer
*cell
,
1423 GtkTreeModel
*model
,
1429 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
1430 GtkCellRenderer
*renderer
,
1431 GtkTreeModel
*model
,
1435 g_return_if_fail (GTK_IS_WX_LIST_STORE (model
));
1436 GtkWxListStore
*list_store
= (GtkWxListStore
*) model
;
1438 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
1440 unsigned int model_row
= (unsigned int) iter
->user_data
;
1443 list_store
->model
->GetValue( value
, cell
->GetOwner()->GetModelColumn(), model_row
);
1445 if (value
.GetType() != cell
->GetVariantType())
1446 wxLogError( wxT("Wrong type, required: %s but: %s"),
1447 value
.GetType().c_str(),
1448 cell
->GetVariantType().c_str() );
1450 cell
->SetValue( value
);
1453 IMPLEMENT_CLASS(wxDataViewColumn
, wxDataViewColumnBase
)
1455 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
, unsigned int model_column
,
1456 int width
, int flags
) :
1457 wxDataViewColumnBase( title
, cell
, model_column
, width
, flags
)
1459 m_isConnected
= false;
1461 GtkCellRenderer
*renderer
= (GtkCellRenderer
*) cell
->GetGtkHandle();
1463 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
1464 m_column
= (void*) column
;
1466 gtk_tree_view_column_set_clickable( column
, true );
1470 if (flags
& wxDATAVIEW_COL_RESIZABLE
)
1471 gtk_tree_view_column_set_resizable( column
, true );
1472 if (flags
& wxDATAVIEW_COL_HIDDEN
)
1473 gtk_tree_view_column_set_visible( column
, false );
1474 if (flags
& wxDATAVIEW_COL_SORTABLE
)
1475 gtk_tree_view_column_set_sort_indicator( column
, true );
1478 gtk_tree_view_column_set_fixed_width( column
, width
);
1480 gtk_tree_view_column_set_fixed_width( column
, 70 ); // FIXME
1482 gtk_tree_view_column_set_sizing( column
, GTK_TREE_VIEW_COLUMN_FIXED
);
1484 gtk_tree_view_column_pack_end( column
, renderer
, FALSE
);
1486 gtk_tree_view_column_set_cell_data_func( column
, renderer
,
1487 wxGtkTreeCellDataFunc
, (gpointer
) cell
, NULL
);
1491 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
, unsigned int model_column
,
1492 int width
, int flags
) :
1493 wxDataViewColumnBase( bitmap
, cell
, model_column
, width
, flags
)
1495 m_isConnected
= false;
1497 GtkCellRenderer
*renderer
= (GtkCellRenderer
*) cell
->GetGtkHandle();
1499 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
1500 m_column
= (void*) column
;
1502 SetBitmap( bitmap
);
1504 if (flags
& wxDATAVIEW_COL_RESIZABLE
)
1505 gtk_tree_view_column_set_resizable( column
, true );
1506 if (flags
& wxDATAVIEW_COL_HIDDEN
)
1507 gtk_tree_view_column_set_visible( column
, false );
1508 if (flags
& wxDATAVIEW_COL_SORTABLE
)
1509 gtk_tree_view_column_set_sort_indicator( column
, true );
1512 gtk_tree_view_column_set_fixed_width( column
, width
);
1514 gtk_tree_view_column_set_fixed_width( column
, 70 ); // FIXME
1516 gtk_tree_view_column_set_sizing( column
, GTK_TREE_VIEW_COLUMN_FIXED
);
1518 gtk_tree_view_column_pack_end( column
, renderer
, FALSE
);
1520 gtk_tree_view_column_set_cell_data_func( column
, renderer
,
1521 wxGtkTreeCellDataFunc
, (gpointer
) cell
, NULL
);
1524 wxDataViewColumn::~wxDataViewColumn()
1528 void wxDataViewColumn::OnInternalIdle()
1533 if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview
))
1535 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)m_column
;
1538 g_signal_connect(column
->button
, "button_press_event",
1539 G_CALLBACK (gtk_dataview_header_button_press_callback
), this);
1541 m_isConnected
= true;
1546 void wxDataViewColumn::SetOwner( wxDataViewCtrl
*owner
)
1548 wxDataViewColumnBase::SetOwner( owner
);
1550 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)m_column
;
1554 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
1558 void wxDataViewColumn::SetTitle( const wxString
&title
)
1560 wxDataViewColumnBase::SetTitle( title
);
1562 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)m_column
;
1566 // disconnect before column->button gets recreated
1567 g_signal_handlers_disconnect_by_func( column
->button
,
1568 (void*) gtk_dataview_header_button_press_callback
, this);
1570 m_isConnected
= false;
1574 gtk_tree_view_column_set_title( column
, wxGTK_CONV(title
) );
1577 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(title
, GetOwner()->GetFont() ) );
1579 gtk_tree_view_column_set_title( column
, "" );
1582 gtk_tree_view_column_set_widget( column
, NULL
);
1585 void wxDataViewColumn::SetBitmap( const wxBitmap
&bitmap
)
1587 wxDataViewColumnBase::SetBitmap( bitmap
);
1589 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)m_column
;
1592 GtkImage
*gtk_image
= GTK_IMAGE( gtk_image_new() );
1594 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
1595 if (bitmap
.GetMask())
1596 mask
= bitmap
.GetMask()->GetBitmap();
1598 if (bitmap
.HasPixbuf())
1600 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image
),
1601 bitmap
.GetPixbuf());
1605 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image
),
1606 bitmap
.GetPixmap(), mask
);
1608 gtk_widget_show( GTK_WIDGET(gtk_image
) );
1610 gtk_tree_view_column_set_widget( column
, GTK_WIDGET(gtk_image
) );
1614 gtk_tree_view_column_set_widget( column
, NULL
);
1618 void wxDataViewColumn::SetAlignment( wxAlignment align
)
1620 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)m_column
;
1622 gfloat xalign
= 0.0;
1623 if (align
== wxALIGN_RIGHT
)
1625 if (align
== wxALIGN_CENTER
)
1628 gtk_tree_view_column_set_alignment( column
, xalign
);
1631 void wxDataViewColumn::SetSortable( bool sortable
)
1633 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)m_column
;
1634 gtk_tree_view_column_set_sort_indicator( column
, sortable
);
1637 bool wxDataViewColumn::GetSortable()
1639 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)m_column
;
1640 return gtk_tree_view_column_get_sort_indicator( column
);
1643 void wxDataViewColumn::SetSortOrder( bool ascending
)
1645 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)m_column
;
1648 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_ASCENDING
);
1650 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_DESCENDING
);
1653 bool wxDataViewColumn::IsSortOrderAscending()
1655 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)m_column
;
1657 return (gtk_tree_view_column_get_sort_order( column
) != GTK_SORT_DESCENDING
);
1660 int wxDataViewColumn::GetWidth()
1662 return gtk_tree_view_column_get_width( (GtkTreeViewColumn
*)m_column
);
1665 void wxDataViewColumn::SetFixedWidth( int width
)
1667 gtk_tree_view_column_set_fixed_width( (GtkTreeViewColumn
*)m_column
, width
);
1670 int wxDataViewColumn::GetFixedWidth()
1672 return gtk_tree_view_column_get_fixed_width( (GtkTreeViewColumn
*)m_column
);
1675 //-----------------------------------------------------------------------------
1676 // wxDataViewCtrl signal callbacks
1677 //-----------------------------------------------------------------------------
1680 wxdataview_selection_changed_callback( GtkTreeSelection
* selection
, wxDataViewCtrl
*dv
)
1682 if (!GTK_WIDGET_REALIZED(dv
->m_widget
))
1685 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ROW_SELECTED
, dv
->GetId() );
1686 event
.SetRow( dv
->GetSelection() );
1687 event
.SetModel( dv
->GetModel() );
1688 dv
->GetEventHandler()->ProcessEvent( event
);
1692 wxdataview_row_activated_callback( GtkTreeView
* treeview
, GtkTreePath
*path
,
1693 GtkTreeViewColumn
*column
, wxDataViewCtrl
*dv
)
1695 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ROW_ACTIVATED
, dv
->GetId() );
1696 unsigned int row
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
1697 event
.SetRow( row
);
1698 event
.SetModel( dv
->GetModel() );
1699 dv
->GetEventHandler()->ProcessEvent( event
);
1702 //-----------------------------------------------------------------------------
1704 //-----------------------------------------------------------------------------
1706 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
1708 wxDataViewCtrl::~wxDataViewCtrl()
1711 GetModel()->RemoveNotifier( m_notifier
);
1714 void wxDataViewCtrl::Init()
1719 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
1720 const wxPoint
& pos
, const wxSize
& size
,
1721 long style
, const wxValidator
& validator
)
1725 m_needParent
= true;
1726 m_acceptsFocus
= true;
1728 if (!PreCreation( parent
, pos
, size
) ||
1729 !CreateBase( parent
, id
, pos
, size
, style
, validator
))
1731 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
1735 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
1737 GtkScrolledWindowSetBorder(m_widget
, style
);
1739 m_treeview
= gtk_tree_view_new();
1740 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
1743 if (!gtk_check_version(2,6,0))
1744 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), TRUE
);
1747 if (style
& wxDV_MULTIPLE
)
1749 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
1750 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
1753 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
1754 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
);
1755 gtk_widget_show (m_treeview
);
1757 m_parent
->DoAddChild( this );
1761 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
1762 g_signal_connect_after (selection
, "changed",
1763 G_CALLBACK (wxdataview_selection_changed_callback
), this);
1764 g_signal_connect_after (m_treeview
, "row_activated",
1765 G_CALLBACK (wxdataview_row_activated_callback
), this);
1770 void wxDataViewCtrl::OnInternalIdle()
1772 wxWindow::OnInternalIdle();
1774 unsigned int cols
= GetNumberOfColumns();
1776 for (i
= 0; i
< cols
; i
++)
1778 wxDataViewColumn
*col
= GetColumn( i
);
1779 col
->OnInternalIdle();
1783 bool wxDataViewCtrl::AssociateModel( wxDataViewListModel
*model
)
1785 if (!wxDataViewCtrlBase::AssociateModel( model
))
1788 GtkWxListStore
*gtk_store
= wxgtk_list_store_new();
1789 gtk_store
->model
= model
;
1791 m_notifier
= new wxGtkDataViewListModelNotifier( gtk_store
, model
);
1793 model
->AddNotifier( m_notifier
);
1795 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), GTK_TREE_MODEL(gtk_store
) );
1796 g_object_unref( gtk_store
);
1801 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
1803 if (!wxDataViewCtrlBase::AppendColumn(col
))
1806 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)col
->GetGtkHandle();
1808 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
), column
);
1813 void wxDataViewCtrl::SetSelection( int row
)
1815 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
1819 gtk_tree_selection_unselect_all( selection
);
1823 GtkTreePath
*path
= gtk_tree_path_new ();
1824 gtk_tree_path_append_index( path
, row
);
1826 gtk_tree_selection_select_path( selection
, path
);
1828 gtk_tree_path_free( path
);
1832 void wxDataViewCtrl::Unselect( unsigned int row
)
1834 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
1836 GtkTreePath
*path
= gtk_tree_path_new ();
1837 gtk_tree_path_append_index( path
, row
);
1839 gtk_tree_selection_unselect_path( selection
, path
);
1841 gtk_tree_path_free( path
);
1844 void wxDataViewCtrl::SetSelectionRange( unsigned int from
, unsigned int to
)
1848 void wxDataViewCtrl::SetSelections( const wxArrayInt
& aSelections
)
1852 bool wxDataViewCtrl::IsSelected( unsigned int row
) const
1854 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
1856 GtkTreePath
*path
= gtk_tree_path_new ();
1857 gtk_tree_path_append_index( path
, row
);
1859 gboolean ret
= gtk_tree_selection_path_is_selected( selection
, path
);
1861 gtk_tree_path_free( path
);
1866 int wxDataViewCtrl::GetSelection() const
1868 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
1869 if (HasFlag(wxDV_MULTIPLE
))
1871 GtkTreeModel
*model
;
1872 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
1877 // list = g_list_nth( list, 0 ); should be a noop
1878 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
1880 unsigned int row
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
1883 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
1884 g_list_free( list
);
1892 GtkTreeModel
*model
;
1894 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
1897 unsigned int row
= (wxUIntPtr
) iter
.user_data
;
1905 int wxDataViewCtrl::GetSelections(wxArrayInt
& aSelections
) const
1907 aSelections
.Clear();
1909 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
1910 if (HasFlag(wxDV_MULTIPLE
))
1912 GtkTreeModel
*model
;
1913 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
1919 // list = g_list_nth( list, 0 ); should be a noop
1920 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
1922 unsigned int row
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
1924 aSelections
.Add( (int) row
);
1926 list
= g_list_next( list
);
1930 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
1931 g_list_free( list
);
1937 GtkTreeModel
*model
;
1939 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
1942 unsigned int row
= (wxUIntPtr
) iter
.user_data
;
1943 aSelections
.Add( (int) row
);
1953 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1955 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
1960 // !wxUSE_GENERICDATAVIEWCTRL
1963 // wxUSE_DATAVIEWCTRL