Re: [gtk-list] Code examples for CTree in EXTENDED selection mode?



"Andrew P. Lentvorski" wrote:
> 
> Anybody have any examples of how to get at the text on selected lines
> of a CTree?  I attempted to use the row accessor functions on the embedded
> CList but got a core dump.  Any help/examples would be appreciated.
> 
> Andy L.
> 
> --
> To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null


This is an example of the code I use to get the selection and the
user data from a ctree. Sorry it is c++ (gtk--) but you can probably
figure it out from there. The example is a little different that what
you are looking for but it should be close enough ( I know this works,
unless I goofed up cutting and pasting it here:)

Hope this helps.

Todd.


void TreeView::dragDataGet( /* GtkWidget          *widget, */
		    GdkDragContext     *context,
		    GtkSelectionData   *selection_data,
		    guint               info,
		    guint32             time) {
  /*
    void gtk_selection_data_set (GtkSelectionData *selection_data,
    GdkAtom           type,
    gint              format,
    guchar           *data,
    gint              length);
  */
  cout << "TreeView::dragDataGet" << endl;
  // create a new MacroItemPL with the selection in it
  MacroItemPL * selection = new MacroItemPL;
  GList * glist = ctree->gtkobj()->clist.selection;
  if (bSelectionEmpty) {
    cout << "there is no selection" << endl;
    // if there is no selection, get the row under the mouse, it
    // should be at treeDragX, treeDragY
    gint  row, column;
    cout << "treeDragX is " << treeDragX << endl;
    if (ctree->get_selection_info( treeDragX, treeDragY, &row, &column))
{
      cout << "the mouse is over an item at row " << row << endl;
      Gtk_CTreeNode ctree_node = ctree->get_node(row);
      if ( ctree_node.gtkobj()) {
	// GTK_CTREE_ROW(ctree_node)->row->data is a PaletteItemView*
	PaletteItemView * piv = 
	 
static_cast<PaletteItemView*>(GTK_CTREE_ROW(ctree_node.gtkobj())->row.data);
	if ( piv) {
	  if ( piv->getItem().getName() != RAPTOR_NEW_MACRO &&
	       piv->isLeaf() ) {
	    // dont include the <new macro> item, only drag leaves
	    // was :selection->push_back(piv->getItem()->clone());
	    selection->push_back(piv->getItem().getAsReference());
	  } 
	}
      }
    }
  } else {
    while (glist) {
      GtkCTreeNode * ctree_node =
static_cast<GtkCTreeNode*>(glist->data);
      if ( ctree_node) {
	// GTK_CTREE_ROW(ctree_node)->row->data is a PaletteItemView*
	PaletteItemView * piv = 
	  static_cast<PaletteItemView*>(GTK_CTREE_ROW(ctree_node)->row.data);
	if ( piv) {
	  if ( piv->getItem().getName() != RAPTOR_NEW_MACRO &&
	       piv->isLeaf() ) {
	    // dont include the <new macro> item, only drag leaves
	    // was :selection->push_back(piv->getItem()->clone());
	    selection->push_back(piv->getItem().getAsReference());
	  } 
	} else {
	  cout << "Warning: ItemView missed dynamic cast." 
	       << __FILE__ << ":" << __LINE__
	       << endl;
	}
      }
      glist = glist->next;
    }
  }
  gtk_selection_data_set( selection_data,             // selection_data
(GtkSelectionData *)
			  selection_data->type,       // type ( GdkAtom)
			  8,                          // format ( gint)
			  (guchar*)selection,    // data   ( guchar *)
			  sizeof(MacroItemPL*)       // length ( gint)
			  );
}




-- 
-----------------------------------------
Todd & Lisa Dukes
tjdukes@flash.net



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