Beispiel #1
0
func gtkAreaNew() *C.GtkWidget {
	drawingarea := 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(drawingarea,
		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(drawingarea, C.TRUE)
	scrollarea := C.gtk_scrolled_window_new((*C.GtkAdjustment)(nil), (*C.GtkAdjustment)(nil))
	// need a viewport because GtkDrawingArea isn't natively scrollable
	C.gtk_scrolled_window_add_with_viewport((*C.GtkScrolledWindow)(unsafe.Pointer(scrollarea)), drawingarea)
	return scrollarea
}
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
func (self *Widget) AddEvents(events gdk3.GdkEventMask) {
	C.gtk_widget_add_events(self.object, C.gint(events))
}
Beispiel #4
0
// AddEvents is a wrapper around gtk_widget_add_events().
func (v *Widget) AddEvents(events int) {
	C.gtk_widget_add_events(v.native(), C.gint(events))
}