Example #1
0
func (v *Format) GetExtensions() []string {
	gstrv := C.gdk_pixbuf_format_get_extensions(v.GPixbufFormat)
	defer C.g_strfreev(gstrv)
	s := make([]string, 0)
	for i := 0; C.getGstr(gstrv, C.int(i)) != nil; i++ {
		s = append(s, gostring(C.getGstr(gstrv, C.int(i))))
	}
	return s
}
// ListActionDescriptions is a wrapper around gtk_application_list_action_descriptions().
func (v *Application) ListActionDescriptions() []string {
	var descs []string
	c := C.gtk_application_list_action_descriptions(v.native())
	originalc := c
	defer C.g_strfreev(originalc)

	for *c != nil {
		descs = append(descs, C.GoString((*C.char)(*c)))
		c = C.next_gcharptr(c)
	}

	return descs
}
Example #3
0
func toGoStringArray(c **C.gchar) []string {
	var strs []string
	originalc := c
	defer C.g_strfreev(originalc)

	for *c != nil {
		strs = append(strs, C.GoString((*C.char)(*c)))
		c = C.next_gcharptr(c)
	}

	return strs

}
Example #4
0
// Convert gchar** null-terminated glib string array to []string, frees "arr"
func _GStringArrayToGoStringSlice(arr **C.gchar) []string {
	var slice []string
	if arr == nil {
		return slice
	}

	iter := arr
	for *iter != nil {
		slice = append(slice, _GStringToGoString(*iter))
		iter = C.next_gcharptr(iter)
	}
	C.g_strfreev(arr)
	return slice
}
// GetActionsForAccel is a wrapper around gtk_application_get_actions_for_accel().
func (v *Application) GetActionsForAccel(acc string) []string {
	cstr1 := (*C.gchar)(C.CString(acc))
	defer C.free(unsafe.Pointer(cstr1))

	var acts []string
	c := C.gtk_application_get_actions_for_accel(v.native(), cstr1)
	originalc := c
	defer C.g_strfreev(originalc)

	for *c != nil {
		acts = append(acts, C.GoString((*C.char)(*c)))
		c = C.next_gcharptr(c)
	}

	return acts
}
Example #6
0
File: dialog.go Project: sqp/godock
// NewDialog creates a custom dialog.
//
func NewDialog(icon gldi.Icon, container *gldi.Container, dialog cdtype.DialogData) *Dialog {
	dialogCall = nil

	// Common dialog attributes.
	attr := new(C.CairoDialogAttr)
	if icon != nil {
		attr.pIcon = (*C.Icon)(unsafe.Pointer(icon.ToNative()))
	}
	attr.pContainer = (*C.GldiContainer)(unsafe.Pointer(container.Ptr))

	if dialog.Icon != "" {
		// w,h :=
		// 		cairo_dock_get_icon_extent (pIcon, &w, &h);
		// 		cImageFilePath = cairo_dock_search_icon_s_path (g_value_get_string (v), MAX (w, h));
		attr.cImageFilePath = gchar(dialog.Icon)
	} else {
		attr.cImageFilePath = gchar("same icon")
	}

	if dialog.Message != "" {
		attr.cText = gchar(dialog.Message)
	}

	if dialog.Buttons != "" {
		cstr := gchar(dialog.Buttons)
		csep := gchar(";")
		clist := C.g_strsplit(cstr, csep, -1) // NULL-terminated
		C.free(unsafe.Pointer((*C.char)(cstr)))
		C.free(unsafe.Pointer((*C.char)(csep)))
		defer C.g_strfreev(clist)
		attr.cButtonsImage = C.constListString(clist)

		// Set the common C callback for all methods.
		attr.pActionFunc = C.CairoDockActionOnAnswerFunc(C.onDialogAnswer)
	}

	attr.iTimeLength = C.gint(1000 * dialog.TimeLength)
	attr.bForceAbove = cbool(dialog.ForceAbove)
	attr.bUseMarkup = cbool(dialog.UseMarkup)

	attr.pUserData = C.intToPointer(1) // unused, but it seems it must be set so the onDialogDestroyed can be called.
	attr.pFreeDataFunc = C.GFreeFunc(C.onDialogDestroyed)

	var widget *gtk.Widget
	var getValue = func() interface{} { return nil }
	switch typed := dialog.Widget.(type) {

	case cdtype.DialogWidgetText:
		widget, getValue = dialogWidgetText(typed)

	case cdtype.DialogWidgetScale:
		widget, getValue = dialogWidgetScale(typed)

	case cdtype.DialogWidgetList:
		widget, getValue = dialogWidgetList(typed)

		// default:
		// return errors.New("PopupDialog: invalid widget type")
	}

	if widget != nil {
		attr.pInteractiveWidget = (*C.GtkWidget)(unsafe.Pointer(widget.Native()))
	}

	if dialog.Buttons != "" && dialog.Callback != nil {
		dialogCall = func(clickedButton int, _ *gtk.Widget) { // No special widget, return button ID.
			dialog.Callback(clickedButton, getValue())
		}
	}

	removeDialog()
	c := C.gldi_dialog_new(attr)
	dialogPtr = NewDialogFromNative(unsafe.Pointer(c))
	return dialogPtr
}