Beispiel #1
0
func (a *area) OpenTextFieldAt(x, y int) {
	if x < 0 || x >= a.width || y < 0 || y >= a.height {
		panic(fmt.Errorf("point (%d,%d) outside Area in Area.OpenTextFieldAt()", x, y))
	}
	a.textfieldx = x
	a.textfieldy = y
	a.inmenu = false // to start
	// we disabled this for the initial Area show; we don't need to anymore
	C.gtk_widget_set_no_show_all(a.textfieldw, C.FALSE)
	C.gtk_widget_show_all(a.textfieldw)
	C.gtk_widget_grab_focus(a.textfieldw)
}
Beispiel #2
0
func newArea(ab *areabase) Area {
	widget := C.gtk_drawing_area_new()
	// the Area's size will be set later
	// we need to explicitly subscribe to mouse events with GtkDrawingArea
	C.gtk_widget_add_events(widget,
		C.GDK_BUTTON_PRESS_MASK|C.GDK_BUTTON_RELEASE_MASK|C.GDK_POINTER_MOTION_MASK|C.GDK_BUTTON_MOTION_MASK|C.GDK_ENTER_NOTIFY_MASK|C.GDK_LEAVE_NOTIFY_MASK)
	// and we need to allow focusing on a GtkDrawingArea to enable keyboard events
	C.gtk_widget_set_can_focus(widget, C.TRUE)
	textfieldw := C.gtk_entry_new()
	a := &area{
		areabase:      ab,
		_widget:       widget,
		drawingarea:   (*C.GtkDrawingArea)(unsafe.Pointer(widget)),
		scroller:      newScroller(widget, false, false, true), // not natively scrollable; no border; have an overlay for OpenTextFieldAt()
		clickCounter:  new(clickCounter),
		textfieldw:    textfieldw,
		textfield:     (*C.GtkEntry)(unsafe.Pointer(textfieldw)),
		textfielddone: newEvent(),
	}
	for _, c := range areaCallbacks {
		g_signal_connect(
			C.gpointer(unsafe.Pointer(a.drawingarea)),
			c.name,
			c.callback,
			C.gpointer(unsafe.Pointer(a)))
	}
	a.SetSize(a.width, a.height)
	C.gtk_overlay_add_overlay(a.scroller.overlay, a.textfieldw)
	g_signal_connect(
		C.gpointer(unsafe.Pointer(a.scroller.overlay)),
		"get-child-position",
		area_get_child_position_callback,
		C.gpointer(unsafe.Pointer(a)))
	// this part is important
	// entering the context menu is considered focusing out
	// so we connect to populate-popup to mark that we're entering the context menu (thanks slaf in irc.gimp.net/#gtk+)
	// and we have to connect_after to focus-out-event so that it runs after the populate-popup
	g_signal_connect(
		C.gpointer(unsafe.Pointer(a.textfield)),
		"populate-popup",
		area_textfield_populate_popup_callback,
		C.gpointer(unsafe.Pointer(a)))
	g_signal_connect_after(
		C.gpointer(unsafe.Pointer(a.textfield)),
		"focus-out-event",
		area_textfield_focus_out_event_callback,
		C.gpointer(unsafe.Pointer(a)))
	// the widget shows up initially
	C.gtk_widget_set_no_show_all(a.textfieldw, C.TRUE)
	return a
}
Beispiel #3
0
// SetNoShowAll is a wrapper around gtk_widget_set_no_show_all().
func (v *Widget) SetNoShowAll(noShowAll bool) {
	C.gtk_widget_set_no_show_all(v.native(), gbool(noShowAll))
}