GtkCellRendererCombo question
- From: Ludo Van Put <Ludo VanPut elis UGent be>
- To: gtk-app-devel-list gnome org
- Subject: GtkCellRendererCombo question
- Date: Fri, 07 Jul 2006 15:35:26 +0200
Hi all,
I am trying to create a TreeView, of which a column should display a
combo box.
So I have listmodel ListModelA with a GTK_TYPE_TREE_MODEL in it and then
this model is filled with data. I add listmodels (ListModelB) with 2
columns to the listmodel ListModelA, previously created or possibly a
NULL pointer.
Then for the TreeView of ListModelA I create a GtkCellRendererCombo and
I use gtk_tree_view_column_set_cell_data_func so I can set the model
property of the cell renderer if the model retrieved from ListModelA is
not NULL. (LancetSectionSymbolCellRendererSetModel)
Then I set
g_object_set(renderer,"has-entry",FALSE, "text-column",
SYMBOL_NAME_COLUMN, "editable", FALSE, NULL);
When I look at the result, I get no warnings at run-time or
compile-time, but I don't see any Combo in the resulting TreeViewColumn.
What am I doing wrong?
I've included the (relevant part of the) source below.
Thanks for any help.
Ludo
-------------------------
845 static void
LancetSectionSymbolCellRendererSetModel(GtkTreeViewColumn *col,
846 GtkCellRenderer *renderer,
847 GtkTreeModel *model,
848 GtkTreeIter *iter,
849 gpointer user_data)
850 {
851 gpointer data;
852 GtkTreeModel * combo_model;
853 gtk_tree_model_get(model, iter, SYMBOL_COLUMN, &data, -1);
854 combo_model = GTK_TREE_MODEL(data);
855 if (data)
856 g_object_set(renderer, "model", combo_model, NULL);
857 }
858
859 GtkWidget * LancetSectionGetTableView(t_section * section)
860 {
861 GtkListStore * list_store;
862 GtkTreeIter tree_iter;
863 GtkWidget * section_view;
864 GtkCellRenderer * renderer;
865 GtkTreeViewColumn *column;
866 GtkWidget * listscroll;
867 char* section_data;
868 t_symbol_ref * symref;
869 t_reloc_ref * relref;
870 t_uint32 i;
871
872 /* First we create a model to store the data and subsequently
fill it with the data */
873 list_store = gtk_list_store_new(N_SECTION_VIEW_COLUMNS,
G_TYPE_INT, GTK_TYPE_TREE_MODEL, G_TYPE_POINTER, G_TYPE_POINTER,
G_TYPE_POINTER);
874
875 section_data = SECTION_DATA(section);
876 listscroll=gtk_scrolled_window_new(NULL,NULL);
877
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(listscroll),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
878
879 symref = SECTION_REFED_BY_SYM(section);
880
881
882 for (i=0; i < SECTION_CSIZE(section); i+=4)
883 {
884 GtkListStore * combo_list_store = NULL;
885 GtkTreeIter combo_tree_iter;
886
887 /* Check if there is a symbol pointing to this offset */
888 while(symref &&
AddressIsLt(SYMBOL_OFFSET_FROM_START(symref->sym),AddressNewForSection(section,i)))
889 symref = symref->next;
890
891 /* If we have symbols, lets create a model to store them */
892 if(symref &&
AddressIsEq(SYMBOL_OFFSET_FROM_START(symref->sym),AddressNewForSection(section,i)))
893 {
894 combo_list_store = gtk_list_store_new(2, G_TYPE_STRING,
G_TYPE_POINTER);
895 }
896 while(symref &&
AddressIsEq(SYMBOL_OFFSET_FROM_START(symref->sym),AddressNewForSection(section,i)))
897 {
898 t_bool local_sym =
((SYMBOL_ORDER(symref->sym)<0)&&(SYMBOL_SEARCH(symref->sym)==FALSE));
899 t_string symbol_name = StringIo("(%s) %s",
900 local_sym?"l":"g",
901 SYMBOL_NAME(symref->sym));
902 if(local_sym)
903 gtk_list_store_append(combo_list_store, &combo_tree_iter);
904 else
905 gtk_list_store_prepend(combo_list_store, &combo_tree_iter);
906 gtk_list_store_set(combo_list_store, &combo_tree_iter,
SYMBOL_NAME_COLUMN, symbol_name, SYMBOL_POINTER_COLUMN, symref->sym, -1);
907 /* VERBOSE(0,("Symbol @S is pointing at this offset
(%d)",symref->sym,i));*/
908 Free(symbol_name);
909 symref = symref->next;
910 }
911
912
913 gtk_list_store_append(list_store, &tree_iter);
914
915 if(section_data)
916 {
917 printf("TM?: %d\n",GTK_IS_TREE_MODEL(combo_list_store));
918
919 gtk_list_store_set(list_store, &tree_iter, OFFSET_COLUMN,
i, SYMBOL_COLUMN, GTK_TREE_MODEL(combo_list_store), DATA_COLUMN,
section_data+i, REFERS_TO_COLUMN, NULL, REFED_BY_COLUMN, NULL, -1);
920 }
921 else
922 gtk_list_store_set(list_store, &tree_iter, OFFSET_COLUMN,
i, SYMBOL_COLUMN, GTK_TREE_MODEL(combo_list_store), DATA_COLUMN, NULL,
REFERS_TO_COLUMN, NULL, REFED_BY_COLUMN, NULL, -1);
923
...
942
943 section_view = gtk_tree_view_new_with_model
(GTK_TREE_MODEL(list_store));
944
945 /* The first column displays the offset */
946 renderer = gtk_cell_renderer_text_new();
947 column = gtk_tree_view_column_new();
948 gtk_tree_view_column_set_title(column, "Offset");
949 gtk_tree_view_column_pack_start(column, renderer, TRUE);
950 gtk_tree_view_column_set_cell_data_func(column, renderer,
LancetSectionOffsetCellRendererFunction, NULL, NULL);
951 gtk_tree_view_append_column(GTK_TREE_VIEW(section_view), column);
952 /* The second column display the data in hex values */
953 column = gtk_tree_view_column_new();
954 gtk_tree_view_column_set_title(column, "Data");
955 renderer = gtk_cell_renderer_text_new();
956 gtk_tree_view_column_pack_start(column, renderer, TRUE);
957 gtk_tree_view_column_set_cell_data_func(column, renderer,
LancetSectionDataCellRendererAsHex, NULL, NULL);
958 renderer = gtk_cell_renderer_text_new();
959 gtk_tree_view_column_pack_end(column, renderer, TRUE);
960 gtk_tree_view_column_set_cell_data_func(column, renderer,
LancetSectionDataCellRendererAsChar, NULL, NULL);
961 gtk_tree_view_append_column(GTK_TREE_VIEW(section_view), column);
962 /* The third column will show the symbols pointing to the
offset */
963 renderer = gtk_cell_renderer_combo_new();
964 /* column =
gtk_tree_view_column_new_with_attributes("Symbols", renderer, "model",
SYMBOL_COLUMN, NULL); This is not working as the model might be NULL...*/
965 g_object_set(renderer,"has-entry",FALSE, "text-column",
SYMBOL_NAME_COLUMN, "editable", FALSE, NULL);
966 column = gtk_tree_view_column_new();
967 gtk_tree_view_column_set_title(column, "Symbols");
968 gtk_tree_view_column_pack_start(column, renderer, TRUE);
969 gtk_tree_view_column_set_cell_data_func(column, renderer,
LancetSectionSymbolCellRendererSetModel, NULL, NULL);
970 gtk_tree_view_append_column(GTK_TREE_VIEW(section_view), column);
971
972 gtk_container_add(GTK_CONTAINER(listscroll), section_view);
973
974 return listscroll;
975 }
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]