func (ds *displaySettings) control(w *gtk.Widget) { doInUIThread(func() { styleContext, _ := w.GetStyleContext() styleContext.AddProvider(ds.provider, 9999) styleContext.AddClass("currentFontSetting") }) }
func (ds *displaySettings) unifiedBackgroundColor(w *gtk.Widget) { doInUIThread(func() { styleContext, _ := w.GetStyleContext() styleContext.AddProvider(ds.provider, 9999) styleContext.AddClass("currentBackgroundColor") }) }
func detectCurrentDisplaySettingsFrom(w *gtk.Widget) *displaySettings { styleContext, _ := w.GetStyleContext() property, _ := styleContext.GetProperty("font", gtk.STATE_FLAG_NORMAL) fontDescription := property.(*pango.FontDescription) size := uint(fontDescription.GetSize() / pango.PANGO_SCALE) ds := newDisplaySettings() ds.fontSize = size return ds }
func dialogWidgetText(data cdtype.DialogWidgetText) (*gtk.Widget, func() interface{}) { var widget *gtk.Widget var getValue func() interface{} if data.MultiLines { textview := newgtk.TextView() scroll := newgtk.ScrolledWindow(nil, nil) scroll.SetPolicy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) scroll.Add(textview) scroll.Set("width-request", 230) scroll.Set("height-request", 130) if data.InitialValue != "" { buffer, e := textview.GetBuffer() if e == nil { buffer.SetText(data.InitialValue) } } if data.Locked { textview.SetEditable(false) } widget = &scroll.Widget getValue = func() interface{} { buffer, e := textview.GetBuffer() if e != nil { return "" } start, end := buffer.GetBounds() answer, _ := buffer.GetText(start, end, true) return answer } } else { entry := newgtk.Entry() entry.SetHasFrame(false) if data.InitialValue != "" { entry.SetText(data.InitialValue) } if data.Locked { entry.SetEditable(false) } if data.Hidden { entry.SetVisibility(false) } widget = &entry.Widget getValue = func() interface{} { answer, _ := entry.GetText() return answer } // g_object_set (pOneWidget, "width-request", CAIRO_DIALOG_MIN_ENTRY_WIDTH, NULL); } // if (iNbCharsMax != 0) // { // gchar *cLabel = g_strdup_printf ("<b>%zd</b>", cInitialText ? strlen (cInitialText) : 0); // GtkWidget *pLabel = gtk_label_new (cLabel); // g_free (cLabel); // gtk_label_set_use_markup (GTK_LABEL (pLabel), TRUE); // GtkWidget *pBox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3); // gtk_box_pack_start (GTK_BOX (pBox), pInteractiveWidget, TRUE, TRUE, 0); // gtk_box_pack_start (GTK_BOX (pBox), pLabel, FALSE, FALSE, 0); // pInteractiveWidget = pBox; // if (bMultiLines) // { // GtkTextBuffer *pBuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (pOneWidget)); // g_signal_connect (pBuffer, "changed", G_CALLBACK (_on_text_changed), pLabel); // g_object_set_data (G_OBJECT (pBuffer), "nb-chars-max", GINT_TO_POINTER (iNbCharsMax)); // } // else // { // g_signal_connect (pOneWidget, "changed", G_CALLBACK (_on_text_changed), pLabel); // g_object_set_data (G_OBJECT (pOneWidget), "nb-chars-max", GINT_TO_POINTER (iNbCharsMax)); // gtk_entry_set_width_chars (GTK_ENTRY (pOneWidget), MIN (iNbCharsMax/2, 100)); // a rough estimate is: 140 chars ~ 1024 pixels // } // } // cstr := (*C.gchar)(C.CString("cd-widget")) // defer C.free(unsafe.Pointer((*C.char)(cstr))) // p := unsafe.Pointer(widget.GObject) // C.g_object_set_data((*C.GObject)(p), cstr, C.gpointer(p)) widget.GrabFocus() return widget, getValue }
// 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 }
func (ds *displaySettings) defaultSettingsOn(w *gtk.Widget) { doInUIThread(func() { styleContext, _ := w.GetStyleContext() styleContext.AddProvider(ds.provider, 9999) }) }