func newGroup(text string, control Control) Group { ctext := togstr(text) defer freegstr(ctext) widget := C.gtk_frame_new(ctext) g := &group{ controlSingleWidget: newControlSingleWidget(widget), gcontainer: (*C.GtkContainer)(unsafe.Pointer(widget)), frame: (*C.GtkFrame)(unsafe.Pointer(widget)), child: control, } // with GTK+, groupboxes by default have frames and slightly x-offset regular text // they should have no frame and fully left-justified, bold text var yalign C.gfloat // preserve default y-alignment C.gtk_frame_get_label_align(g.frame, nil, &yalign) C.gtk_frame_set_label_align(g.frame, 0, yalign) C.gtk_frame_set_shadow_type(g.frame, C.GTK_SHADOW_NONE) label := (*C.GtkLabel)(unsafe.Pointer(C.gtk_frame_get_label_widget(g.frame))) // this is the boldness level used by GtkPrintUnixDialog // (it technically uses "bold" but see pango's pango-enum-types.c for the name conversion; GType is weird) bold := C.pango_attr_weight_new(C.PANGO_WEIGHT_BOLD) boldlist := C.pango_attr_list_new() C.pango_attr_list_insert(boldlist, bold) C.gtk_label_set_attributes(label, boldlist) C.pango_attr_list_unref(boldlist) // thanks baedert in irc.gimp.net/#gtk+ g.container = newContainer() g.child.setParent(g.container.parent()) g.container.resize = g.child.resize C.gtk_container_add(g.gcontainer, g.container.widget) return g }
func CreateXWindow(width, height int) (*XWindow, error) { C.XInitThreads() W := &XWindow{} W.Display = C.XOpenDisplay(nil) if W.Display == nil { return &XWindow{}, errors.New("Can't open display") } W.Window = C.XCreateSimpleWindow(W.Display, C.XDefaultRootWindow(W.Display), 0, 0, C.uint(width), C.uint(height), 0, 0, 0xFF151515) C.XSetWindowBackgroundPixmap(W.Display, W.Window, 0) // This avoids flickering on resize C.XMapWindow(W.Display, W.Window) C.XStoreName(W.Display, W.Window, C.CString("gowitt")) C.XSelectInput(W.Display, W.Window, C.ExposureMask|C.KeyPressMask|C.ButtonPressMask) C.XFlush(W.Display) // Cairo W.Surface = C.cairo_xlib_surface_create(W.Display, C.Drawable(W.Window), C.XDefaultVisual(W.Display, 0), C.int(width), C.int(height)) C.cairo_xlib_surface_set_size(W.Surface, C.int(width), C.int(height)) W.Cairo = C.cairo_create(W.Surface) // Pango InitLayoutsCache(W.Cairo) W.PangoContext = C.pango_cairo_create_context(W.Cairo) W.FontDesc = C.pango_font_description_from_string(C.CString("Sans 10")) W.AttrList = C.pango_attr_list_new() placeholderImage = C.cairo_image_surface_create_from_png(C.CString("test.png")) W.UserImages = NewImageCache(func() { var ev C.XEvent exev := (*C.XExposeEvent)(unsafe.Pointer(&ev)) exev._type = C.Expose exev.count = 0 exev.window = W.Window exev.send_event = 1 exev.display = W.Display C.XSendEvent(W.Display, W.Window, 0, C.ExposureMask, &ev) C.XFlush(W.Display) }) return W, nil }