properties for GtkCellRenderText -- Whoohoo it works!



This message ties into an earlier message where I stated I would try out
some code to see if I could change the attributes of text in my
GtkListStore. It works quite nicely. Here's what happens:

1) user selects an item in my GtkTreeView (note: in this case just a
single column view).

2) User clicks a button and the text at that selection turns red!

Here's what I did:

1) I have an enumerated type for the storage model

enum
{
  DATA_COLUMN,
  MODEL_ATTRIBUTES,
  N_COLUMNS
}

2) Created a callback for the the button press:

void on_button_clicked (GtkButton *button, gpointer *userData)
{
  do_color_test(gtk_widget_get_toplevel(button));
}

3) now, in the do_color_test routine, I need to do several things:
 - get the view
 - get the model
 - get the current selection
 - return the proper iter for the selection
 - set the attribute to "red" for the current selection

void do_color_test (GtkWidget *theWindow)
{
  GtkWidget *theView = NULL;
  GtkListStore *theListStore = NULL;
  GtkTreeIter theIter;
  GtkTreeModel *theModel = NULL;
  GtkTreeSelection *currentSelection;
  
  theView = lookup_widget(theWindow, "atreeview");
  theModel = gtk_tree_view_get_model(theView);
  
  if (GTK_IS_LIST_STORE (theModel))
  {
    theListStore = GTK_LIST_STORE (theModel);
    g_print("theModel is a ListStore\n");
  }
    
  /* get the current selection from theView  */
  currentSelection = gtk_tree_view_get_selection(theView);
  
  /* now that we have a selection, get the exact location in theIter
   */
  if (!gtk_tree_selection_get_selected(currentSelection, &theListStore,
    &theIter)) 
  {
    g_print("no current selection!!\n");
  }
  
  /* set the color for that row to red */
  gtk_list_store_set(theListStore, &theIter, MODEL_ATTRIBUTES, "red",
  -1);
  
}

There are probably more efficient methods of doing this. For example, do
I need to call gtk_tree_view_get_selection at all? Some obvious debug
code can also be elminated but that's the jist of it.

-- 
 .''`.      Carl B. Constantine
: :' :     duckwing duckwing ca
`. `'    GnuPG: 135F FC30 7A02 B0EB 61DB  34E3 3AF1 DC6C 9F7A 3FF8
  `-  Debian GNU/Linux -- The power of freedom

Attachment: pgpPH3I60AL1R.pgp
Description: PGP signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]