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
;
256 wxFAIL_MSG( _T("non-string columns not supported yet") );
263 wxgtk_list_store_get_iter (GtkTreeModel
*tree_model
,
267 GtkWxListStore
*list_store
= (GtkWxListStore
*) tree_model
;
268 g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model
), FALSE
);
269 g_return_val_if_fail (gtk_tree_path_get_depth (path
) > 0, FALSE
);
271 unsigned int i
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
273 if (i
>= list_store
->model
->GetNumberOfRows())
276 iter
->stamp
= list_store
->stamp
;
277 // user_data is just the index
278 iter
->user_data
= (gpointer
) i
;
284 wxgtk_list_store_get_path (GtkTreeModel
*tree_model
,
287 g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model
), NULL
);
288 g_return_val_if_fail (iter
->stamp
== GTK_WX_LIST_STORE (tree_model
)->stamp
, NULL
);
290 GtkTreePath
*retval
= gtk_tree_path_new ();
291 // user_data is just the index
292 int i
= (wxUIntPtr
) iter
->user_data
;
293 gtk_tree_path_append_index (retval
, i
);
298 wxgtk_list_store_get_value (GtkTreeModel
*tree_model
,
303 GtkWxListStore
*list_store
= (GtkWxListStore
*) tree_model
;
304 g_return_if_fail (GTK_IS_WX_LIST_STORE (tree_model
) );
306 wxDataViewListModel
*model
= list_store
->model
;
307 wxString mtype
= model
->GetColType( (unsigned int) column
);
308 if (mtype
== wxT("string"))
311 g_value_init( value
, G_TYPE_STRING
);
312 model
->GetValue( variant
,
313 (unsigned int) column
,
314 (unsigned int) iter
->user_data
);
316 // FIXME: we should support different encodings here
317 g_value_set_string( value
, wxGTK_CONV_SYS(variant
.GetString()) );
321 wxFAIL_MSG( _T("non-string columns not supported yet") );
326 wxgtk_list_store_iter_next (GtkTreeModel
*tree_model
,
329 g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model
), FALSE
);
330 GtkWxListStore
*list_store
= (GtkWxListStore
*) tree_model
;
332 g_return_val_if_fail (list_store
->stamp
== iter
->stamp
, FALSE
);
334 int n
= (wxUIntPtr
) iter
->user_data
;
339 if (n
>= (int) list_store
->model
->GetNumberOfRows()-1)
342 iter
->user_data
= (gpointer
) ++n
;
348 wxgtk_list_store_iter_children (GtkTreeModel
*tree_model
,
352 g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model
), FALSE
);
353 GtkWxListStore
*list_store
= (GtkWxListStore
*) tree_model
;
355 // this is a list, nodes have no children
359 iter
->stamp
= list_store
->stamp
;
360 iter
->user_data
= (gpointer
) -1;
366 wxgtk_list_store_iter_has_child (GtkTreeModel
*tree_model
,
373 wxgtk_list_store_iter_n_children (GtkTreeModel
*tree_model
,
376 g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model
), -1);
377 GtkWxListStore
*list_store
= (GtkWxListStore
*) tree_model
;
380 return (gint
) list_store
->model
->GetNumberOfRows();
382 g_return_val_if_fail (list_store
->stamp
== iter
->stamp
, -1);
388 wxgtk_list_store_iter_nth_child (GtkTreeModel
*tree_model
,
393 g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model
), FALSE
);
394 GtkWxListStore
*list_store
= (GtkWxListStore
*) tree_model
;
402 if (n
>= (gint
) list_store
->model
->GetNumberOfRows())
405 iter
->stamp
= list_store
->stamp
;
406 iter
->user_data
= (gpointer
) n
;
412 wxgtk_list_store_iter_parent (GtkTreeModel
*tree_model
,
419 //-----------------------------------------------------------------------------
420 // define new GTK+ class wxGtkRendererRenderer
421 //-----------------------------------------------------------------------------
425 #define GTK_TYPE_WX_CELL_RENDERER (gtk_wx_cell_renderer_get_type ())
426 #define GTK_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRenderer))
427 #define GTK_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
428 #define GTK_IS_WX_CELL_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WX_CELL_RENDERER))
429 #define GTK_IS_WX_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WX_CELL_RENDERER))
430 #define GTK_WX_CELL_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WX_CELL_RENDERER, GtkWxCellRendererClass))
432 GType
gtk_wx_cell_renderer_get_type (void);
434 typedef struct _GtkWxCellRenderer GtkWxCellRenderer
;
435 typedef struct _GtkWxCellRendererClass GtkWxCellRendererClass
;
437 struct _GtkWxCellRenderer
439 GtkCellRenderer parent
;
442 wxDataViewCustomRenderer
*cell
;
446 struct _GtkWxCellRendererClass
448 GtkCellRendererClass cell_parent_class
;
452 static GtkCellRenderer
*gtk_wx_cell_renderer_new (void);
453 static void gtk_wx_cell_renderer_init (
454 GtkWxCellRenderer
*cell
);
455 static void gtk_wx_cell_renderer_class_init(
456 GtkWxCellRendererClass
*klass
);
457 static void gtk_wx_cell_renderer_finalize (
459 static void gtk_wx_cell_renderer_get_size (
460 GtkCellRenderer
*cell
,
462 GdkRectangle
*rectangle
,
467 static void gtk_wx_cell_renderer_render (
468 GtkCellRenderer
*cell
,
471 GdkRectangle
*background_area
,
472 GdkRectangle
*cell_area
,
473 GdkRectangle
*expose_area
,
474 GtkCellRendererState flags
);
475 static gboolean
gtk_wx_cell_renderer_activate(
476 GtkCellRenderer
*cell
,
480 GdkRectangle
*background_area
,
481 GdkRectangle
*cell_area
,
482 GtkCellRendererState flags
);
484 static GObjectClass
*cell_parent_class
= NULL
;
489 gtk_wx_cell_renderer_get_type (void)
491 static GType cell_wx_type
= 0;
495 static const GTypeInfo cell_wx_info
=
497 sizeof (GtkWxCellRendererClass
),
498 NULL
, /* base_init */
499 NULL
, /* base_finalize */
500 (GClassInitFunc
) gtk_wx_cell_renderer_class_init
,
501 NULL
, /* class_finalize */
502 NULL
, /* class_data */
503 sizeof (GtkWxCellRenderer
),
505 (GInstanceInitFunc
) gtk_wx_cell_renderer_init
,
508 cell_wx_type
= g_type_register_static( GTK_TYPE_CELL_RENDERER
,
509 "GtkWxCellRenderer", &cell_wx_info
, (GTypeFlags
)0 );
516 gtk_wx_cell_renderer_init (GtkWxCellRenderer
*cell
)
519 cell
->last_click
= 0;
523 gtk_wx_cell_renderer_class_init (GtkWxCellRendererClass
*klass
)
525 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
526 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
528 cell_parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
530 object_class
->finalize
= gtk_wx_cell_renderer_finalize
;
532 cell_class
->get_size
= gtk_wx_cell_renderer_get_size
;
533 cell_class
->render
= gtk_wx_cell_renderer_render
;
534 cell_class
->activate
= gtk_wx_cell_renderer_activate
;
538 gtk_wx_cell_renderer_finalize (GObject
*object
)
541 (* G_OBJECT_CLASS (cell_parent_class
)->finalize
) (object
);
545 gtk_wx_cell_renderer_new (void)
547 return (GtkCellRenderer
*) g_object_new (GTK_TYPE_WX_CELL_RENDERER
, NULL
);
551 gtk_wx_cell_renderer_get_size (GtkCellRenderer
*renderer
,
553 GdkRectangle
*cell_area
,
559 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
560 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
562 wxSize size
= cell
->GetSize();
564 gint calc_width
= (gint
) renderer
->xpad
* 2 + size
.x
;
565 gint calc_height
= (gint
) renderer
->ypad
* 2 + size
.y
;
572 if (cell_area
&& size
.x
> 0 && size
.y
> 0)
576 *x_offset
= (gint
)((renderer
->xalign
*
577 (cell_area
->width
- calc_width
- 2 * renderer
->xpad
)));
578 *x_offset
= MAX (*x_offset
, 0) + renderer
->xpad
;
582 *y_offset
= (gint
)((renderer
->yalign
*
583 (cell_area
->height
- calc_height
- 2 * renderer
->ypad
)));
584 *y_offset
= MAX (*y_offset
, 0) + renderer
->ypad
;
592 *height
= calc_height
;
596 gtk_wx_cell_renderer_render (GtkCellRenderer
*renderer
,
599 GdkRectangle
*background_area
,
600 GdkRectangle
*cell_area
,
601 GdkRectangle
*expose_area
,
602 GtkCellRendererState flags
)
605 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
606 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
609 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
615 rect
.x
+= cell_area
->x
;
616 rect
.y
+= cell_area
->y
;
617 rect
.width
-= renderer
->xpad
* 2;
618 rect
.height
-= renderer
->ypad
* 2;
621 if (gdk_rectangle_intersect (expose_area
, &rect
, &dummy
))
623 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
624 wxWindowDC
* dc
= (wxWindowDC
*) cell
->GetDC();
625 if (dc
->m_window
== NULL
)
627 dc
->m_window
= window
;
632 if (flags
& GTK_CELL_RENDERER_SELECTED
)
633 state
|= wxDATAVIEW_CELL_SELECTED
;
634 if (flags
& GTK_CELL_RENDERER_PRELIT
)
635 state
|= wxDATAVIEW_CELL_PRELIT
;
636 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
637 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
638 if (flags
& GTK_CELL_RENDERER_INSENSITIVE
)
639 state
|= wxDATAVIEW_CELL_INSENSITIVE
;
640 if (flags
& GTK_CELL_RENDERER_FOCUSED
)
641 state
|= wxDATAVIEW_CELL_FOCUSED
;
642 cell
->Render( renderrect
, dc
, state
);
647 gtk_wx_cell_renderer_activate(
648 GtkCellRenderer
*renderer
,
652 GdkRectangle
*background_area
,
653 GdkRectangle
*cell_area
,
654 GtkCellRendererState flags
)
656 GtkWxCellRenderer
*wxrenderer
= (GtkWxCellRenderer
*) renderer
;
657 wxDataViewCustomRenderer
*cell
= wxrenderer
->cell
;
660 gtk_wx_cell_renderer_get_size (renderer
, widget
, cell_area
,
666 rect
.x
+= cell_area
->x
;
667 rect
.y
+= cell_area
->y
;
668 rect
.width
-= renderer
->xpad
* 2;
669 rect
.height
-= renderer
->ypad
* 2;
671 wxRect
renderrect( rect
.x
, rect
.y
, rect
.width
, rect
.height
);
673 wxDataViewListModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
675 GtkTreePath
*treepath
= gtk_tree_path_new_from_string( path
);
676 unsigned int model_row
= (unsigned int)gtk_tree_path_get_indices (treepath
)[0];
677 gtk_tree_path_free( treepath
);
679 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
681 if (event
->type
== GDK_BUTTON_PRESS
)
683 GdkEventButton
*button_event
= (GdkEventButton
*) event
;
684 wxPoint
pt( ((int) button_event
->x
) - renderrect
.x
,
685 ((int) button_event
->y
) - renderrect
.y
);
688 if (button_event
->button
== 1)
690 if (cell
->LeftClick( pt
, renderrect
, model
, model_col
, model_row
))
692 // TODO: query system double-click time
693 if (button_event
->time
- wxrenderer
->last_click
< 400)
694 if (cell
->Activate( renderrect
, model
, model_col
, model_row
))
697 if (button_event
->button
== 3)
699 if (cell
->RightClick( pt
, renderrect
, model
, model_col
, model_row
))
703 wxrenderer
->last_click
= button_event
->time
;
711 // ---------------------------------------------------------
712 // wxGtkDataViewListModelNotifier
713 // ---------------------------------------------------------
715 class wxGtkDataViewListModelNotifier
: public wxDataViewListModelNotifier
718 wxGtkDataViewListModelNotifier( GtkWxListStore
* gtk_store
, wxDataViewListModel
*wx_model
);
720 virtual bool RowAppended();
721 virtual bool RowPrepended();
722 virtual bool RowInserted( unsigned int before
);
723 virtual bool RowDeleted( unsigned int row
);
724 virtual bool RowChanged( unsigned int row
);
725 virtual bool ValueChanged( unsigned int col
, unsigned int row
);
726 virtual bool RowsReordered( unsigned int *new_order
);
727 virtual bool Cleared();
729 GtkWxListStore
*m_gtk_store
;
730 wxDataViewListModel
*m_wx_model
;
733 // ---------------------------------------------------------
734 // wxGtkDataViewListModelNotifier
735 // ---------------------------------------------------------
737 wxGtkDataViewListModelNotifier::wxGtkDataViewListModelNotifier(
738 GtkWxListStore
* gtk_store
, wxDataViewListModel
*wx_model
)
740 m_gtk_store
= gtk_store
;
741 m_wx_model
= wx_model
;
744 bool wxGtkDataViewListModelNotifier::RowAppended()
746 unsigned int pos
= m_wx_model
->GetNumberOfRows()-1;
749 iter
.stamp
= m_gtk_store
->stamp
;
750 iter
.user_data
= (gpointer
) pos
;
752 GtkTreePath
*path
= gtk_tree_path_new ();
753 gtk_tree_path_append_index (path
, (gint
) pos
);
754 gtk_tree_model_row_inserted (GTK_TREE_MODEL (m_gtk_store
), path
, &iter
);
755 gtk_tree_path_free (path
);
760 bool wxGtkDataViewListModelNotifier::RowPrepended()
763 iter
.stamp
= m_gtk_store
->stamp
;
764 iter
.user_data
= (gpointer
) 0;
766 GtkTreePath
*path
= gtk_tree_path_new ();
767 gtk_tree_path_append_index (path
, (gint
) 0);
768 gtk_tree_model_row_inserted (GTK_TREE_MODEL (m_gtk_store
), path
, &iter
);
769 gtk_tree_path_free (path
);
774 bool wxGtkDataViewListModelNotifier::RowInserted( unsigned int before
)
777 iter
.stamp
= m_gtk_store
->stamp
;
778 iter
.user_data
= (gpointer
) before
;
780 GtkTreePath
*path
= gtk_tree_path_new ();
781 gtk_tree_path_append_index (path
, (gint
) before
);
782 gtk_tree_model_row_inserted (GTK_TREE_MODEL (m_gtk_store
), path
, &iter
);
783 gtk_tree_path_free (path
);
788 bool wxGtkDataViewListModelNotifier::RowDeleted( unsigned int row
)
790 GtkTreePath
*path
= gtk_tree_path_new ();
791 gtk_tree_path_append_index (path
, (gint
) row
);
792 gtk_tree_model_row_deleted (GTK_TREE_MODEL (m_gtk_store
), path
);
793 gtk_tree_path_free (path
);
798 bool wxGtkDataViewListModelNotifier::RowChanged( unsigned int row
)
801 iter
.stamp
= m_gtk_store
->stamp
;
802 iter
.user_data
= (gpointer
) row
;
803 GtkTreePath
*path
= gtk_tree_model_get_path (GTK_TREE_MODEL (m_gtk_store
), &iter
);
804 gtk_tree_model_row_changed (GTK_TREE_MODEL (m_gtk_store
), path
, &iter
);
805 gtk_tree_path_free (path
);
810 bool wxGtkDataViewListModelNotifier::ValueChanged( unsigned int model_col
, unsigned int model_row
)
812 // This adds GTK+'s missing MVC logic for ValueChanged
813 wxNode
*node
= GetOwner()->m_viewingColumns
.GetFirst();
816 wxDataViewViewingColumn
* viewing_column
= (wxDataViewViewingColumn
*) node
->GetData();
817 if (viewing_column
->m_modelColumn
== model_col
)
819 GtkTreeView
*widget
= GTK_TREE_VIEW(viewing_column
->m_viewColumn
->GetOwner()->m_treeview
);
820 GtkTreeViewColumn
*column
= GTK_TREE_VIEW_COLUMN(viewing_column
->m_viewColumn
->GetGtkHandle());
823 GtkTreePath
*path
= gtk_tree_path_new();
824 gtk_tree_path_append_index( path
, model_row
);
825 GdkRectangle cell_area
;
826 gtk_tree_view_get_cell_area( widget
, path
, column
, &cell_area
);
827 gtk_tree_path_free( path
);
829 int ydiff
= column
->button
->allocation
.height
;
831 gtk_widget_queue_draw_area( GTK_WIDGET(widget
),
832 cell_area
.x
, ydiff
+ cell_area
.y
, cell_area
.width
, cell_area
.height
);
835 node
= node
->GetNext();
841 bool wxGtkDataViewListModelNotifier::RowsReordered( unsigned int *new_order
)
843 // Assume sizeof(unsigned int)= == sizeof(gint)
845 GtkTreePath
*path
= gtk_tree_path_new ();
846 gtk_tree_model_rows_reordered (GTK_TREE_MODEL (m_gtk_store
), path
, NULL
, (gint
*)new_order
);
847 gtk_tree_path_free (path
);
849 // This adds GTK+'s missing MVC logic for RowsReordered
850 wxNode
*node
= GetOwner()->m_viewingColumns
.GetFirst();
853 wxDataViewViewingColumn
* viewing_column
= (wxDataViewViewingColumn
*) node
->GetData();
854 GtkTreeView
*widget
= GTK_TREE_VIEW(viewing_column
->m_viewColumn
->GetOwner()->m_treeview
);
855 // Doesn't work yet...
856 gtk_widget_queue_draw( GTK_WIDGET(widget
) );
858 node
= node
->GetNext();
864 bool wxGtkDataViewListModelNotifier::Cleared()
869 // ---------------------------------------------------------
870 // wxDataViewRenderer
871 // ---------------------------------------------------------
873 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
875 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
) :
876 wxDataViewRendererBase( varianttype
, mode
)
881 // ---------------------------------------------------------
882 // wxDataViewTextRenderer
883 // ---------------------------------------------------------
886 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
887 gchar
*arg1
, gchar
*arg2
, gpointer user_data
);
890 static void wxGtkTextRendererEditedCallback( GtkCellRendererText
*renderer
,
891 gchar
*arg1
, gchar
*arg2
, gpointer user_data
)
893 wxDataViewTextRenderer
*cell
= (wxDataViewTextRenderer
*) user_data
;
895 wxString tmp
= wxGTK_CONV_BACK( arg2
);
896 wxVariant value
= tmp
;
897 if (!cell
->Validate( value
))
900 wxDataViewListModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
902 GtkTreePath
*path
= gtk_tree_path_new_from_string( arg1
);
903 unsigned int model_row
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
904 gtk_tree_path_free( path
);
906 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
908 model
->SetValue( value
, model_col
, model_row
);
909 model
->ValueChanged( model_col
, model_row
);
912 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewRenderer
)
914 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
) :
915 wxDataViewRenderer( varianttype
, mode
)
917 m_renderer
= (void*) gtk_cell_renderer_text_new();
919 if (m_mode
& wxDATAVIEW_CELL_EDITABLE
)
921 GValue gvalue
= { 0, };
922 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
923 g_value_set_boolean( &gvalue
, true );
924 g_object_set_property( G_OBJECT(m_renderer
), "editable", &gvalue
);
925 g_value_unset( &gvalue
);
927 g_signal_connect_after( m_renderer
, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback
), this );
931 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
933 wxString tmp
= value
;
935 GValue gvalue
= { 0, };
936 g_value_init( &gvalue
, G_TYPE_STRING
);
937 g_value_set_string( &gvalue
, wxGTK_CONV_FONT( tmp
, GetOwner()->GetOwner()->GetFont() ) );
938 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
939 g_value_unset( &gvalue
);
944 bool wxDataViewTextRenderer::GetValue( wxVariant
&value
)
946 GValue gvalue
= { 0, };
947 g_value_init( &gvalue
, G_TYPE_STRING
);
948 g_object_get_property( G_OBJECT(m_renderer
), "text", &gvalue
);
949 wxString tmp
= wxGTK_CONV_BACK( g_value_get_string( &gvalue
) );
950 g_value_unset( &gvalue
);
957 // ---------------------------------------------------------
958 // wxDataViewBitmapRenderer
959 // ---------------------------------------------------------
961 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewRenderer
)
963 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
, wxDataViewCellMode mode
) :
964 wxDataViewRenderer( varianttype
, mode
)
966 m_renderer
= (void*) gtk_cell_renderer_pixbuf_new();
969 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
971 if (value
.GetType() == wxT("wxBitmap"))
976 // This may create a Pixbuf representation in the
977 // wxBitmap object (and it will stay there)
978 GdkPixbuf
*pixbuf
= bitmap
.GetPixbuf();
980 GValue gvalue
= { 0, };
981 g_value_init( &gvalue
, G_TYPE_OBJECT
);
982 g_value_set_object( &gvalue
, pixbuf
);
983 g_object_set_property( G_OBJECT(m_renderer
), "pixbuf", &gvalue
);
984 g_value_unset( &gvalue
);
989 if (value
.GetType() == wxT("wxIcon"))
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
);
1010 bool wxDataViewBitmapRenderer::GetValue( wxVariant
&value
)
1015 // ---------------------------------------------------------
1016 // wxDataViewToggleRenderer
1017 // ---------------------------------------------------------
1020 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1021 gchar
*path
, gpointer user_data
);
1024 static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle
*renderer
,
1025 gchar
*path
, gpointer user_data
)
1027 wxDataViewToggleRenderer
*cell
= (wxDataViewToggleRenderer
*) user_data
;
1030 GValue gvalue
= { 0, };
1031 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1032 g_object_get_property( G_OBJECT(renderer
), "active", &gvalue
);
1033 bool tmp
= g_value_get_boolean( &gvalue
);
1034 g_value_unset( &gvalue
);
1038 wxVariant value
= tmp
;
1039 if (!cell
->Validate( value
))
1042 wxDataViewListModel
*model
= cell
->GetOwner()->GetOwner()->GetModel();
1044 GtkTreePath
*gtk_path
= gtk_tree_path_new_from_string( path
);
1045 unsigned int model_row
= (unsigned int)gtk_tree_path_get_indices (gtk_path
)[0];
1046 gtk_tree_path_free( gtk_path
);
1048 unsigned int model_col
= cell
->GetOwner()->GetModelColumn();
1050 model
->SetValue( value
, model_col
, model_row
);
1051 model
->ValueChanged( model_col
, model_row
);
1054 IMPLEMENT_CLASS(wxDataViewToggleRenderer
, wxDataViewRenderer
)
1056 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
1057 wxDataViewCellMode mode
) :
1058 wxDataViewRenderer( varianttype
, mode
)
1060 m_renderer
= (void*) gtk_cell_renderer_toggle_new();
1062 if (m_mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
1064 g_signal_connect_after( m_renderer
, "toggled", G_CALLBACK(wxGtkToggleRendererToggledCallback
), this );
1069 GValue gvalue
= { 0, };
1070 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1071 g_value_set_boolean( &gvalue
, false );
1072 g_object_set_property( G_OBJECT(m_renderer
), "activatable", &gvalue
);
1073 g_value_unset( &gvalue
);
1075 GValue gvalue2
= { 0, };
1076 g_value_init( &gvalue2
, gtk_cell_renderer_mode_get_type() );
1077 g_value_set_enum( &gvalue2
, GTK_CELL_RENDERER_MODE_INERT
);
1078 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue2
);
1079 g_value_unset( &gvalue2
);
1084 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
1088 GValue gvalue
= { 0, };
1089 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1090 g_value_set_boolean( &gvalue
, tmp
);
1091 g_object_set_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1092 g_value_unset( &gvalue
);
1097 bool wxDataViewToggleRenderer::GetValue( wxVariant
&value
)
1099 GValue gvalue
= { 0, };
1100 g_value_init( &gvalue
, G_TYPE_BOOLEAN
);
1101 g_object_get_property( G_OBJECT(m_renderer
), "active", &gvalue
);
1102 bool tmp
= g_value_get_boolean( &gvalue
);
1103 g_value_unset( &gvalue
);
1110 // ---------------------------------------------------------
1111 // wxDataViewCustomRenderer
1112 // ---------------------------------------------------------
1114 class wxDataViewCtrlDC
: public wxWindowDC
1117 wxDataViewCtrlDC( wxDataViewCtrl
*window
)
1119 GtkWidget
*widget
= window
->m_treeview
;
1123 m_context
= window
->GtkGetPangoDefaultContext();
1124 m_layout
= pango_layout_new( m_context
);
1125 m_fontdesc
= pango_font_description_copy( widget
->style
->font_desc
);
1127 m_cmap
= gtk_widget_get_colormap( widget
? widget
: window
->m_widget
);
1129 // Set m_window later
1131 // m_owner = window;
1135 // ---------------------------------------------------------
1136 // wxDataViewCustomRenderer
1137 // ---------------------------------------------------------
1139 IMPLEMENT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
1141 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
1142 wxDataViewCellMode mode
, bool no_init
) :
1143 wxDataViewRenderer( varianttype
, mode
)
1153 bool wxDataViewCustomRenderer::Init()
1155 GtkWxCellRenderer
*renderer
= (GtkWxCellRenderer
*) gtk_wx_cell_renderer_new();
1156 renderer
->cell
= this;
1158 m_renderer
= (void*) renderer
;
1160 if (m_mode
& wxDATAVIEW_CELL_ACTIVATABLE
)
1162 GValue gvalue
= { 0, };
1163 g_value_init( &gvalue
, gtk_cell_renderer_mode_get_type() );
1164 g_value_set_enum( &gvalue
, GTK_CELL_RENDERER_MODE_ACTIVATABLE
);
1165 g_object_set_property( G_OBJECT(m_renderer
), "mode", &gvalue
);
1166 g_value_unset( &gvalue
);
1172 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
1178 wxDC
*wxDataViewCustomRenderer::GetDC()
1182 if (GetOwner() == NULL
)
1184 if (GetOwner()->GetOwner() == NULL
)
1186 m_dc
= new wxDataViewCtrlDC( GetOwner()->GetOwner() );
1192 // ---------------------------------------------------------
1193 // wxDataViewProgressRenderer
1194 // ---------------------------------------------------------
1196 IMPLEMENT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
1198 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
1199 const wxString
&varianttype
, wxDataViewCellMode mode
) :
1200 wxDataViewCustomRenderer( varianttype
, mode
, true )
1206 if (!gtk_check_version(2,6,0))
1208 m_renderer
= (void*) gtk_cell_renderer_progress_new();
1210 GValue gvalue
= { 0, };
1211 g_value_init( &gvalue
, G_TYPE_STRING
);
1213 g_value_set_string( &gvalue
, wxGTK_CONV(m_label
) );
1215 g_value_set_string( &gvalue
, wxGTK_CONV_SYS(m_label
) );
1217 g_object_set_property( G_OBJECT(m_renderer
), "text", &gvalue
);
1218 g_value_unset( &gvalue
);
1223 // Use custom cell code
1224 wxDataViewCustomRenderer::Init();
1228 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
1232 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
1235 if (!gtk_check_version(2,6,0))
1237 gint tmp
= (long) value
;
1238 GValue gvalue
= { 0, };
1239 g_value_init( &gvalue
, G_TYPE_INT
);
1240 g_value_set_int( &gvalue
, tmp
);
1241 g_object_set_property( G_OBJECT(m_renderer
), "value", &gvalue
);
1242 g_value_unset( &gvalue
);
1247 m_value
= (long) value
;
1249 if (m_value
< 0) m_value
= 0;
1250 if (m_value
> 100) m_value
= 100;
1256 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1258 double pct
= (double)m_value
/ 100.0;
1260 bar
.width
= (int)(cell
.width
* pct
);
1261 dc
->SetPen( *wxTRANSPARENT_PEN
);
1262 dc
->SetBrush( *wxBLUE_BRUSH
);
1263 dc
->DrawRectangle( bar
);
1265 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1266 dc
->SetPen( *wxBLACK_PEN
);
1267 dc
->DrawRectangle( cell
);
1272 wxSize
wxDataViewProgressRenderer::GetSize()
1274 return wxSize(40,12);
1277 // ---------------------------------------------------------
1278 // wxDataViewDateRenderer
1279 // ---------------------------------------------------------
1281 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
1284 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
1285 wxDataViewListModel
*model
, unsigned int col
, unsigned int row
) :
1286 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
)
1291 m_cal
= new wxCalendarCtrl( this, -1, *value
);
1292 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
1293 sizer
->Add( m_cal
, 1, wxGROW
);
1298 virtual void OnDismiss()
1302 void OnCalendar( wxCalendarEvent
&event
);
1304 wxCalendarCtrl
*m_cal
;
1305 wxDataViewListModel
*m_model
;
1310 DECLARE_EVENT_TABLE()
1313 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
1314 EVT_CALENDAR( -1, wxDataViewDateRendererPopupTransient::OnCalendar
)
1317 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
1319 wxDateTime date
= event
.GetDate();
1320 wxVariant value
= date
;
1321 m_model
->SetValue( value
, m_col
, m_row
);
1322 m_model
->ValueChanged( m_col
, m_row
);
1326 IMPLEMENT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
1328 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
1329 wxDataViewCellMode mode
) :
1330 wxDataViewCustomRenderer( varianttype
, mode
)
1334 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
1336 m_date
= value
.GetDateTime();
1341 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1343 dc
->SetFont( GetOwner()->GetOwner()->GetFont() );
1344 wxString tmp
= m_date
.FormatDate();
1345 dc
->DrawText( tmp
, cell
.x
, cell
.y
);
1350 wxSize
wxDataViewDateRenderer::GetSize()
1352 wxDataViewCtrl
* view
= GetOwner()->GetOwner();
1353 wxString tmp
= m_date
.FormatDate();
1355 view
->GetTextExtent( tmp
, &x
, &y
, &d
);
1356 return wxSize(x
,y
+d
);
1359 bool wxDataViewDateRenderer::Activate( wxRect cell
, wxDataViewListModel
*model
, unsigned int col
, unsigned int row
)
1362 model
->GetValue( variant
, col
, row
);
1363 wxDateTime value
= variant
.GetDateTime();
1365 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
1366 GetOwner()->GetOwner()->GetParent(), &value
, model
, col
, row
);
1367 wxPoint pos
= wxGetMousePosition();
1370 popup
->Popup( popup
->m_cal
);
1375 // ---------------------------------------------------------
1377 // ---------------------------------------------------------
1381 gtk_dataview_header_button_press_callback( GtkWidget
*widget
,
1382 GdkEventButton
*gdk_event
,
1383 wxDataViewColumn
*column
)
1385 if (gdk_event
->type
!= GDK_BUTTON_PRESS
)
1388 if (gdk_event
->button
== 1)
1390 wxDataViewCtrl
*dv
= column
->GetOwner();
1391 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, dv
->GetId() );
1392 event
.SetDataViewColumn( column
);
1393 event
.SetModel( dv
->GetModel() );
1394 dv
->GetEventHandler()->ProcessEvent( event
);
1401 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
1402 GtkCellRenderer
*cell
,
1403 GtkTreeModel
*model
,
1409 static void wxGtkTreeCellDataFunc( GtkTreeViewColumn
*column
,
1410 GtkCellRenderer
*renderer
,
1411 GtkTreeModel
*model
,
1415 g_return_if_fail (GTK_IS_WX_LIST_STORE (model
));
1416 GtkWxListStore
*list_store
= (GtkWxListStore
*) model
;
1418 wxDataViewRenderer
*cell
= (wxDataViewRenderer
*) data
;
1420 unsigned int model_row
= (unsigned int) iter
->user_data
;
1423 list_store
->model
->GetValue( value
, cell
->GetOwner()->GetModelColumn(), model_row
);
1425 if (value
.GetType() != cell
->GetVariantType())
1426 wxLogError( wxT("Wrong type, required: %s but: %s"),
1427 value
.GetType().c_str(),
1428 cell
->GetVariantType().c_str() );
1430 cell
->SetValue( value
);
1433 IMPLEMENT_CLASS(wxDataViewColumn
, wxDataViewColumnBase
)
1435 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
, unsigned int model_column
,
1436 int width
, int flags
) :
1437 wxDataViewColumnBase( title
, cell
, model_column
, width
, flags
)
1439 m_isConnected
= false;
1441 GtkCellRenderer
*renderer
= (GtkCellRenderer
*) cell
->GetGtkHandle();
1443 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
1444 m_column
= (void*) column
;
1446 gtk_tree_view_column_set_clickable( column
, true );
1450 if (flags
& wxDATAVIEW_COL_RESIZABLE
)
1451 gtk_tree_view_column_set_resizable( column
, true );
1452 if (flags
& wxDATAVIEW_COL_HIDDEN
)
1453 gtk_tree_view_column_set_visible( column
, false );
1454 if (flags
& wxDATAVIEW_COL_SORTABLE
)
1455 gtk_tree_view_column_set_sort_indicator( column
, true );
1458 gtk_tree_view_column_set_fixed_width( column
, width
);
1460 gtk_tree_view_column_set_fixed_width( column
, 70 ); // FIXME
1462 gtk_tree_view_column_set_sizing( column
, GTK_TREE_VIEW_COLUMN_FIXED
);
1464 gtk_tree_view_column_pack_end( column
, renderer
, FALSE
);
1466 gtk_tree_view_column_set_cell_data_func( column
, renderer
,
1467 wxGtkTreeCellDataFunc
, (gpointer
) cell
, NULL
);
1471 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
, unsigned int model_column
,
1472 int width
, int flags
) :
1473 wxDataViewColumnBase( bitmap
, cell
, model_column
, width
, flags
)
1475 m_isConnected
= false;
1477 GtkCellRenderer
*renderer
= (GtkCellRenderer
*) cell
->GetGtkHandle();
1479 GtkTreeViewColumn
*column
= gtk_tree_view_column_new();
1480 m_column
= (void*) column
;
1482 SetBitmap( bitmap
);
1484 if (flags
& wxDATAVIEW_COL_RESIZABLE
)
1485 gtk_tree_view_column_set_resizable( column
, true );
1486 if (flags
& wxDATAVIEW_COL_HIDDEN
)
1487 gtk_tree_view_column_set_visible( column
, false );
1488 if (flags
& wxDATAVIEW_COL_SORTABLE
)
1489 gtk_tree_view_column_set_sort_indicator( column
, true );
1492 gtk_tree_view_column_set_fixed_width( column
, width
);
1494 gtk_tree_view_column_set_fixed_width( column
, 70 ); // FIXME
1496 gtk_tree_view_column_set_sizing( column
, GTK_TREE_VIEW_COLUMN_FIXED
);
1498 gtk_tree_view_column_pack_end( column
, renderer
, FALSE
);
1500 gtk_tree_view_column_set_cell_data_func( column
, renderer
,
1501 wxGtkTreeCellDataFunc
, (gpointer
) cell
, NULL
);
1504 wxDataViewColumn::~wxDataViewColumn()
1508 void wxDataViewColumn::OnInternalIdle()
1513 if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview
))
1515 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)m_column
;
1518 g_signal_connect(column
->button
, "button_press_event",
1519 G_CALLBACK (gtk_dataview_header_button_press_callback
), this);
1521 m_isConnected
= true;
1526 void wxDataViewColumn::SetOwner( wxDataViewCtrl
*owner
)
1528 wxDataViewColumnBase::SetOwner( owner
);
1530 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)m_column
;
1534 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
1538 void wxDataViewColumn::SetTitle( const wxString
&title
)
1540 wxDataViewColumnBase::SetTitle( title
);
1542 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)m_column
;
1546 // disconnect before column->button gets recreated
1547 g_signal_handlers_disconnect_by_func( column
->button
,
1548 (void*) gtk_dataview_header_button_press_callback
, this);
1550 m_isConnected
= false;
1554 gtk_tree_view_column_set_title( column
, wxGTK_CONV(title
) );
1557 gtk_tree_view_column_set_title( column
, wxGTK_CONV_FONT(title
, GetOwner()->GetFont() ) );
1559 gtk_tree_view_column_set_title( column
, "" );
1562 gtk_tree_view_column_set_widget( column
, NULL
);
1565 void wxDataViewColumn::SetBitmap( const wxBitmap
&bitmap
)
1567 wxDataViewColumnBase::SetBitmap( bitmap
);
1569 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)m_column
;
1572 GtkImage
*gtk_image
= GTK_IMAGE( gtk_image_new() );
1574 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
1575 if (bitmap
.GetMask())
1576 mask
= bitmap
.GetMask()->GetBitmap();
1578 if (bitmap
.HasPixbuf())
1580 gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image
),
1581 bitmap
.GetPixbuf());
1585 gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image
),
1586 bitmap
.GetPixmap(), mask
);
1588 gtk_widget_show( GTK_WIDGET(gtk_image
) );
1590 gtk_tree_view_column_set_widget( column
, GTK_WIDGET(gtk_image
) );
1594 gtk_tree_view_column_set_widget( column
, NULL
);
1598 void wxDataViewColumn::SetAlignment( wxAlignment align
)
1600 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)m_column
;
1602 gfloat xalign
= 0.0;
1603 if (align
== wxALIGN_RIGHT
)
1605 if (align
== wxALIGN_CENTER
)
1608 gtk_tree_view_column_set_alignment( column
, xalign
);
1611 void wxDataViewColumn::SetSortable( bool sortable
)
1613 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)m_column
;
1614 gtk_tree_view_column_set_sort_indicator( column
, sortable
);
1617 bool wxDataViewColumn::GetSortable()
1619 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)m_column
;
1620 return gtk_tree_view_column_get_sort_indicator( column
);
1623 void wxDataViewColumn::SetSortOrder( bool ascending
)
1625 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)m_column
;
1628 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_ASCENDING
);
1630 gtk_tree_view_column_set_sort_order( column
, GTK_SORT_DESCENDING
);
1633 bool wxDataViewColumn::IsSortOrderAscending()
1635 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)m_column
;
1637 return (gtk_tree_view_column_get_sort_order( column
) != GTK_SORT_DESCENDING
);
1640 int wxDataViewColumn::GetWidth()
1642 return gtk_tree_view_column_get_width( (GtkTreeViewColumn
*)m_column
);
1645 void wxDataViewColumn::SetFixedWidth( int width
)
1647 gtk_tree_view_column_set_fixed_width( (GtkTreeViewColumn
*)m_column
, width
);
1650 int wxDataViewColumn::GetFixedWidth()
1652 return gtk_tree_view_column_get_fixed_width( (GtkTreeViewColumn
*)m_column
);
1655 //-----------------------------------------------------------------------------
1656 // wxDataViewCtrl signal callbacks
1657 //-----------------------------------------------------------------------------
1660 wxdataview_selection_changed_callback( GtkTreeSelection
* selection
, wxDataViewCtrl
*dv
)
1662 if (!GTK_WIDGET_REALIZED(dv
->m_widget
))
1665 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ROW_SELECTED
, dv
->GetId() );
1666 event
.SetRow( dv
->GetSelection() );
1667 event
.SetModel( dv
->GetModel() );
1668 dv
->GetEventHandler()->ProcessEvent( event
);
1672 wxdataview_row_activated_callback( GtkTreeView
* treeview
, GtkTreePath
*path
,
1673 GtkTreeViewColumn
*column
, wxDataViewCtrl
*dv
)
1675 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ROW_ACTIVATED
, dv
->GetId() );
1676 unsigned int row
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
1677 event
.SetRow( row
);
1678 event
.SetModel( dv
->GetModel() );
1679 dv
->GetEventHandler()->ProcessEvent( event
);
1682 //-----------------------------------------------------------------------------
1684 //-----------------------------------------------------------------------------
1686 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
1688 wxDataViewCtrl::~wxDataViewCtrl()
1691 GetModel()->RemoveNotifier( m_notifier
);
1694 void wxDataViewCtrl::Init()
1699 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
1700 const wxPoint
& pos
, const wxSize
& size
,
1701 long style
, const wxValidator
& validator
)
1705 m_needParent
= true;
1706 m_acceptsFocus
= true;
1708 if (!PreCreation( parent
, pos
, size
) ||
1709 !CreateBase( parent
, id
, pos
, size
, style
, validator
))
1711 wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
1715 m_widget
= gtk_scrolled_window_new (NULL
, NULL
);
1717 GtkScrolledWindowSetBorder(m_widget
, style
);
1719 m_treeview
= gtk_tree_view_new();
1720 gtk_container_add (GTK_CONTAINER (m_widget
), m_treeview
);
1723 if (!gtk_check_version(2,6,0))
1724 gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview
), TRUE
);
1727 if (style
& wxDV_MULTIPLE
)
1729 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
1730 gtk_tree_selection_set_mode( selection
, GTK_SELECTION_MULTIPLE
);
1733 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget
),
1734 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
);
1735 gtk_widget_show (m_treeview
);
1737 m_parent
->DoAddChild( this );
1741 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
1742 g_signal_connect_after (selection
, "changed",
1743 G_CALLBACK (wxdataview_selection_changed_callback
), this);
1744 g_signal_connect_after (m_treeview
, "row_activated",
1745 G_CALLBACK (wxdataview_row_activated_callback
), this);
1750 void wxDataViewCtrl::OnInternalIdle()
1752 wxWindow::OnInternalIdle();
1754 unsigned int cols
= GetNumberOfColumns();
1756 for (i
= 0; i
< cols
; i
++)
1758 wxDataViewColumn
*col
= GetColumn( i
);
1759 col
->OnInternalIdle();
1763 bool wxDataViewCtrl::AssociateModel( wxDataViewListModel
*model
)
1765 if (!wxDataViewCtrlBase::AssociateModel( model
))
1768 GtkWxListStore
*gtk_store
= wxgtk_list_store_new();
1769 gtk_store
->model
= model
;
1771 m_notifier
= new wxGtkDataViewListModelNotifier( gtk_store
, model
);
1773 model
->AddNotifier( m_notifier
);
1775 gtk_tree_view_set_model( GTK_TREE_VIEW(m_treeview
), GTK_TREE_MODEL(gtk_store
) );
1776 g_object_unref( gtk_store
);
1781 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
1783 if (!wxDataViewCtrlBase::AppendColumn(col
))
1786 GtkTreeViewColumn
*column
= (GtkTreeViewColumn
*)col
->GetGtkHandle();
1788 gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview
), column
);
1793 void wxDataViewCtrl::SetSelection( int row
)
1795 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
1799 gtk_tree_selection_unselect_all( selection
);
1803 GtkTreePath
*path
= gtk_tree_path_new ();
1804 gtk_tree_path_append_index( path
, row
);
1806 gtk_tree_selection_select_path( selection
, path
);
1808 gtk_tree_path_free( path
);
1812 void wxDataViewCtrl::Unselect( unsigned int row
)
1814 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
1816 GtkTreePath
*path
= gtk_tree_path_new ();
1817 gtk_tree_path_append_index( path
, row
);
1819 gtk_tree_selection_unselect_path( selection
, path
);
1821 gtk_tree_path_free( path
);
1824 void wxDataViewCtrl::SetSelectionRange( unsigned int from
, unsigned int to
)
1828 void wxDataViewCtrl::SetSelections( const wxArrayInt
& aSelections
)
1832 bool wxDataViewCtrl::IsSelected( unsigned int row
) const
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 gboolean ret
= gtk_tree_selection_path_is_selected( selection
, path
);
1841 gtk_tree_path_free( path
);
1846 int wxDataViewCtrl::GetSelection() const
1848 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
1849 if (HasFlag(wxDV_MULTIPLE
))
1851 GtkTreeModel
*model
;
1852 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
1857 // list = g_list_nth( list, 0 ); should be a noop
1858 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
1860 unsigned int row
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
1863 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
1864 g_list_free( list
);
1872 GtkTreeModel
*model
;
1874 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
1877 unsigned int row
= (wxUIntPtr
) iter
.user_data
;
1885 int wxDataViewCtrl::GetSelections(wxArrayInt
& aSelections
) const
1887 aSelections
.Clear();
1889 GtkTreeSelection
*selection
= gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview
) );
1890 if (HasFlag(wxDV_MULTIPLE
))
1892 GtkTreeModel
*model
;
1893 GList
*list
= gtk_tree_selection_get_selected_rows( selection
, &model
);
1899 // list = g_list_nth( list, 0 ); should be a noop
1900 GtkTreePath
*path
= (GtkTreePath
*) list
->data
;
1902 unsigned int row
= (unsigned int)gtk_tree_path_get_indices (path
)[0];
1904 aSelections
.Add( (int) row
);
1906 list
= g_list_next( list
);
1910 g_list_foreach( list
, (GFunc
) gtk_tree_path_free
, NULL
);
1911 g_list_free( list
);
1917 GtkTreeModel
*model
;
1919 gboolean has_selection
= gtk_tree_selection_get_selected( selection
, &model
, &iter
);
1922 unsigned int row
= (wxUIntPtr
) iter
.user_data
;
1923 aSelections
.Add( (int) row
);
1933 wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1935 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
);
1940 // !wxUSE_GENERICDATAVIEWCTRL
1943 // wxUSE_DATAVIEWCTRL