예제 #1
0
파일: dialog.go 프로젝트: sqp/godock
// ShowWithQuestion opens a dialog with a question to answer.
//
func ShowWithQuestion(str string, icon gldi.Icon, container *gldi.Container, iconPath string, onAnswer func(int, *gtk.Widget)) {
	cstr := (*C.gchar)(C.CString(str))
	defer C.free(unsafe.Pointer((*C.char)(cstr)))
	cpath := (*C.gchar)(C.CString(iconPath))
	defer C.free(unsafe.Pointer((*C.char)(cpath)))

	cicon := (*C.Icon)(unsafe.Pointer(icon.ToNative()))
	ccontainer := (*C.GldiContainer)(unsafe.Pointer(container.Ptr))

	dialogCall = onAnswer
	removeDialog()
	c := C.gldi_dialog_show_with_question(cstr, cicon, ccontainer, cpath, C.CairoDockActionOnAnswerFunc(C.onDialogAnswer), nil, nil)
	dialogPtr = NewDialogFromNative(unsafe.Pointer(c))
}
예제 #2
0
파일: dialog.go 프로젝트: 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
}