Ejemplo n.º 1
0
func newWindow(title string, width int, height int, control Control) *window {
	widget := C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL)
	ctitle := togstr(title)
	defer freegstr(ctitle)
	w := &window{
		widget:  widget,
		wc:      (*C.GtkContainer)(unsafe.Pointer(widget)),
		bin:     (*C.GtkBin)(unsafe.Pointer(widget)),
		window:  (*C.GtkWindow)(unsafe.Pointer(widget)),
		closing: newEvent(),
	}
	C.gtk_window_set_title(w.window, ctitle)
	g_signal_connect(
		C.gpointer(unsafe.Pointer(w.window)),
		"delete-event",
		C.GCallback(C.windowClosing),
		C.gpointer(unsafe.Pointer(w)))
	C.gtk_window_resize(w.window, C.gint(width), C.gint(height))
	w.container = newContainer(control)
	w.container.setParent(&controlParent{w.wc})
	// for dialogs; otherwise, they will be modal to all windows, not just this one
	w.group = C.gtk_window_group_new()
	C.gtk_window_group_add_window(w.group, w.window)
	return w
}
Ejemplo n.º 2
0
func NewWindowGroup() *WindowGroup {
	ret := C.gtk_window_group_new()
	if ret == nil {
		return nil
	}
	return &WindowGroup{ret}
}
Ejemplo n.º 3
0
func _msgBox(parent *Window, primarytext string, secondarytext string, msgtype C.GtkMessageType, buttons C.GtkButtonsType) (result C.gint) {
	ret := make(chan C.gint)
	defer close(ret)
	uitask <- func() {
		var pwin *C.GtkWindow = nil

		// to implement parent, we need to put the GtkMessageDialog into a new window group along with parent
		// a GtkWindow can only be part of one group
		// so we use this to save the parent window group (if there is one) and store the new window group
		// after showing the message box, we restore the previous window group, so future parent == nil can work properly
		// thanks to pbor and mclasen in irc.gimp.net/#gtk+
		var prevgroup *C.GtkWindowGroup = nil
		var newgroup *C.GtkWindowGroup

		if parent != nil {
			pwin = togtkwindow(parent.sysData.widget)
			// we can't remove a window from the "default window group"; otherwise this throws up Gtk-CRITICAL warnings
			if C.gtk_window_has_group(pwin) != C.FALSE {
				prevgroup = C.gtk_window_get_group(pwin)
				C.gtk_window_group_remove_window(prevgroup, pwin)
			}
			newgroup = C.gtk_window_group_new()
			C.gtk_window_group_add_window(newgroup, pwin)
		}

		cprimarytext := C.CString(primarytext)
		defer C.free(unsafe.Pointer(cprimarytext))
		csecondarytext := (*C.char)(nil)
		if secondarytext != "" {
			csecondarytext = C.CString(secondarytext)
			defer C.free(unsafe.Pointer(csecondarytext))
		}
		box := C.gtkNewMsgBox(pwin, msgtype, buttons, cprimarytext, csecondarytext)
		response := C.gtk_dialog_run((*C.GtkDialog)(unsafe.Pointer(box)))
		C.gtk_widget_destroy(box)

		if parent != nil {
			C.gtk_window_group_remove_window(newgroup, pwin)
			C.g_object_unref(C.gpointer(unsafe.Pointer(newgroup))) // free the group
			if prevgroup != nil {
				C.gtk_window_group_add_window(prevgroup, pwin)
			} // otherwise it'll go back into the default group on its own
		}

		ret <- response
	}
	return <-ret
}
Ejemplo n.º 4
0
func (d *dialog) prepare() {
	// to implement parent, we need to put the GtkMessageDialog into a new window group along with parent
	// a GtkWindow can only be part of one group
	// so we use this to save the parent window group (if there is one) and store the new window group
	// after showing the message box, we restore the previous window group, so future parent == dialogWindow can work properly
	// thanks to pbor and mclasen in irc.gimp.net/#gtk+
	if d.parent != dialogWindow {
		d.pwin = togtkwindow(d.parent.sysData.widget)
		d.hadgroup = C.gtk_window_has_group(d.pwin)
		// we can't remove a window from the "default window group"; otherwise this throws up Gtk-CRITICAL warnings
		if d.hadgroup != C.FALSE {
			d.prevgroup = C.gtk_window_get_group(d.pwin)
			C.gtk_window_group_remove_window(d.prevgroup, d.pwin)
		}
		d.newgroup = C.gtk_window_group_new()
		C.gtk_window_group_add_window(d.newgroup, d.pwin)
	}
}