Пример #1
0
/* 
 * get the top or bottom visible row in the connection list
 * returns TOP row if (int top) is > 0  and list is not empty
 * returns BOTTOM row if (int top) is 0 and visible area is full
 */
static void gtkui_connection_list_row(int top, struct row_pairs *pair) {
   GtkTreeIter iter;            /* points to a specific row */
   GtkTreePath *path = NULL;    /* for finding the first visible row */
   GtkTreeModel *model = NULL;  /* points to the list data */
   GdkRectangle rect;           /* holds coordinates of visible rows */
   int wx = 0, wy = 0;          /* for converting tree view coords to widget coords */
   void *row = NULL;

   if(!ls_conns || !pair)
      return;

   /* in case we don't get a row */
   pair->conn = NULL;

   model = GTK_TREE_MODEL (ls_conns);
   if(gtk_tree_model_get_iter_first(model, &iter)) {
      gtk_tree_view_get_visible_rect(GTK_TREE_VIEW(treeview), &rect);

      /* get the first visible row */
      gtk_tree_view_tree_to_widget_coords(GTK_TREE_VIEW(treeview), rect.x, (top)?rect.y:rect.height, &wx, &wy);
      path = gtk_tree_path_new();
      if(gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(treeview), wx+2, (top)?wy+2:wy-2, &path, NULL, NULL, NULL)) {
         gtk_tree_model_get_iter(model, &iter, path);
         gtk_tree_model_get (model, &iter, 9, &row, -1);

         pair->iter = iter;
         pair->conn = row;
      }
      if(path)
         gtk_tree_path_free(path);
   }

   return;
}
Пример #2
0
static VALUE
rg_tree_to_widget_coords(VALUE self, VALUE tx, VALUE ty)
{
    gint wx, wy;
    gtk_tree_view_tree_to_widget_coords(_SELF(self),
                                        NUM2INT(tx), NUM2INT(ty), 
                                        &wx, &wy);
    return rb_ary_new3(2, INT2NUM(wx), INT2NUM(wy));
}
Пример #3
0
static gboolean
tree_event (GtkTreeView *tree,
	    GdkEvent    *event)
{
  GtkTreeViewColumn *column;
  gint cx, cy, atrow;
  switch (event->type)
    {
      GdkRectangle rect;
      gint wx, wy;
    case GDK_BUTTON_PRESS:
      atrow = gtk_tree_view_get_path_at_pos (tree, event->button.x, event->button.y,
					     NULL, &column, &cx, &cy);
      g_print ("got button_press at %f,%f [%u] (%p %d %d)\n", event->button.x, event->button.y, atrow, column, cx, cy);
      break;
    case GDK_BUTTON_RELEASE:
      atrow = gtk_tree_view_get_path_at_pos (tree, event->button.x, event->button.y,
					     NULL, &column, &cx, &cy);
      g_print ("got button_release at %f,%f [%u] (%p %d %d)\n", event->button.x, event->button.y, atrow, column, cx, cy);
      break;
    case GDK_MOTION_NOTIFY:
      atrow = gtk_tree_view_get_path_at_pos (tree, event->motion.x, event->motion.y,
					     NULL, &column, &cx, &cy);
      gtk_tree_view_get_visible_rect (tree, &rect);
      gtk_tree_view_tree_to_widget_coords (tree, rect.x, rect.y, &wx, &wy);
      g_print ("got motion at %f,%f [%u] (%p %d %d) widget(%d %d)\n", event->motion.x, event->motion.y, atrow, column,
	       cx, cy, wx, wy);
      break;
    default:
    }
  return FALSE;
}

static GtkWidget*
pack_test_widget (void)
{
  GtkWidget *scwin, *tree;
  GtkTreeSelection *tsel;
  GxkListWrapper *plist = gxk_list_wrapper_new (3 /* N_COLS */,
						G_TYPE_STRING,  /* 0 */
						G_TYPE_STRING,  /* 1 */
						G_TYPE_STRING   /* 2 */
						);
  g_signal_connect_object (plist, "fill-value",
			   G_CALLBACK (plist_fill_value),
			   NULL, G_CONNECT_SWAPPED);
  gxk_list_wrapper_notify_prepend (plist, 200);

  scwin = g_object_new (GTK_TYPE_SCROLLED_WINDOW,
			"visible", TRUE,
			"hscrollbar_policy", GTK_POLICY_AUTOMATIC,
			"vscrollbar_policy", GTK_POLICY_ALWAYS,
			"height_request", 320,
			"width_request", 320,
			"border_width", 5,
			"shadow_type", GTK_SHADOW_IN,
			NULL);
  tree = g_object_new (GTK_TYPE_TREE_VIEW,
		       "visible", TRUE,
		       "can_focus", TRUE,
		       "model", plist,
		       "border_width", 10,
		       "parent", scwin,
		       NULL);
  gxk_tree_view_append_text_columns (GTK_TREE_VIEW (tree), 3 /* N_COLS */,
				     0, "", 0.0, "Foo Name",
				     1, "", 0.0, "Bar Name",
				     2, "", 0.0, "Baz Type"
				     );
  gtk_tree_view_add_column (GTK_TREE_VIEW (tree), -1,
			    g_object_new (GTK_TYPE_TREE_VIEW_COLUMN,
					  "title", "PTrack",
					  "sizing", GTK_TREE_VIEW_COLUMN_GROW_ONLY,
					  "resizable", TRUE,
					  NULL),
			    g_object_new (BST_TYPE_CELL_PTRACK,
					  "xalign", 0.0,
					  NULL),
			    // "text", 3,
			    NULL);
  g_object_connect (tree,
		    "signal::event", tree_event, NULL,
		    NULL);
#if 0
  g_object_connect (tree,
		    "swapped_object_signal::row_activated", tree_row_activated, self,
		    NULL);
#endif

  /* ensure selection
   */
  tsel = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree));
  gtk_tree_selection_set_mode (tsel, GTK_SELECTION_SINGLE);
  gxk_tree_selection_select_spath (tsel, "0");

  return scwin;
}