Example #1
0
func gListboxSelMultiTexts(widget *C.GtkWidget) (texts []string) {
	var model *C.GtkTreeModel
	var iter C.GtkTreeIter
	var gs *C.gchar

	tv := getTreeViewFrom(widget)
	sel := C.gtk_tree_view_get_selection(tv)
	rows := C.gtk_tree_selection_get_selected_rows(sel, &model)
	defer C.g_list_free_full(rows, C.GDestroyNotify(unsafe.Pointer(C.gtk_tree_path_free)))
	len := C.g_list_length(rows)
	if len == 0 {
		return nil
	}
	texts = make([]string, len)
	for i := C.guint(0); i < len; i++ {
		path := (*C.GtkTreePath)(unsafe.Pointer(rows.data))
		if C.gtk_tree_model_get_iter(model, &iter, path) == C.FALSE {
			panic("gtk_tree_model_get_iter() failed getting Listbox selected texts; reason unknown")
		}
		C.gtkTreeModelGet(model, &iter, &gs)
		texts[i] = fromgstr(gs)
		rows = rows.next
	}
	return texts
}
Example #2
0
func (g *glib) Tracks() []Track {
	ptr := g.db.tracks
	len := C.g_list_length(ptr)
	arr := make([]Track, 0, len)
	for ptr != nil {
		track := newTrack(g, (*C.Itdb_Track)(ptr.data), false)
		arr = append(arr, track)
		ptr = ptr.next
	}
	return arr
}
Example #3
0
func (c *Client) QueryBySubsystem(subsystem string) []Device {
	l := C.g_udev_client_query_by_subsystem(c.p, (*C.gchar)(C.CString(subsystem)))
	result := make([]Device, C.g_list_length(l))
	for i := range result {
		p := (*C.struct__GUdevDevice)(l.data)
		device := Device{
			p: p,
		}
		runtime.SetFinalizer(&device, func(device *Device) {
			C.g_object_unref((C.gpointer)(device.p))
		})
		result[i] = device
		l = l.next
	}
	C.g_list_free(l)

	return result
}
Example #4
0
func gListboxSelectedMulti(widget *C.GtkWidget) (indices []int) {
	var model *C.GtkTreeModel

	tv := getTreeViewFrom(widget)
	sel := C.gtk_tree_view_get_selection(tv)
	rows := C.gtk_tree_selection_get_selected_rows(sel, &model)
	defer C.g_list_free_full(rows, C.GDestroyNotify(unsafe.Pointer(C.gtk_tree_path_free)))
	// g_list_length() is O(N), but we need the length below, alas
	len := C.g_list_length(rows)
	if len == 0 {
		return nil
	}
	indices = make([]int, len)
	for i := C.guint(0); i < len; i++ {
		path := (*C.GtkTreePath)(unsafe.Pointer(rows.data))
		idx := C.gtk_tree_path_get_indices(path)
		indices[i] = int(*idx)
		rows = rows.next
	}
	return indices
}
Example #5
0
File: glib.go Project: leif/go-gtk
func (v List) Length() uint {
	return uint(C.g_list_length(v.GList))
}
Example #6
0
func (self *GList) Length() uint {
	return uint(C.g_list_length(self.object))
}
Example #7
0
// Length is a wrapper around g_list_length().
func (v *List) Length() uint {
	glist := (*C.GList)(unsafe.Pointer(v))
	return uint(C.g_list_length(glist))
}