1// Package gtk was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package gtk
3
4import (
5 "structs"
6 "unsafe"
7
8 "github.com/ebitengine/purego"
9
10 "github.com/bnema/puregotk/pkg/core"
11 "github.com/bnema/puregotk/v4/gdk"
12 "github.com/bnema/puregotk/v4/gio"
13 "github.com/bnema/puregotk/v4/gobject"
14 "github.com/bnema/puregotk/v4/gobject/types"
15)
16
17type ShortcutControllerClass struct {
18 _ structs.HostLayout
19}
20
21func (x *ShortcutControllerClass) GoPointer() uintptr {
22 return uintptr(unsafe.Pointer(x))
23}
24
25// Manages keyboard shortcuts and their activation.
26//
27// Most common shortcuts are using this controller implicitly, e.g. by
28// adding a mnemonic underline to a [class@Gtk.Label], or by installing a key
29// binding using [method@Gtk.WidgetClass.add_binding], or by adding accelerators
30// to global actions using [method@Gtk.Application.set_accels_for_action].
31//
32// But it is possible to create your own shortcut controller, and add
33// shortcuts to it.
34//
35// `GtkShortcutController` implements [iface@Gio.ListModel] for querying the
36// shortcuts that have been added to it.
37//
38// # GtkShortcutController as GtkBuildable
39//
40// `GtkShortcutController`s can be created in [class@Gtk.Builder] ui files, to set up
41// shortcuts in the same place as the widgets.
42//
43// An example of a UI definition fragment with `GtkShortcutController`:
44// ```xml
45//
46// <object class='GtkButton'>
47// <child>
48// <object class='GtkShortcutController'>
49// <property name='scope'>managed</property>
50// <child>
51// <object class='GtkShortcut'>
52// <property name='trigger'>&lt;Control&gt;k</property>
53// <property name='action'>activate</property>
54// </object>
55// </child>
56// </object>
57// </child>
58// </object>
59//
60// ```
61//
62// This example creates a [class@Gtk.ActivateAction] for triggering the
63// `activate` signal of the [class@Gtk.Button]. See [ctor@Gtk.ShortcutAction.parse_string]
64// for the syntax for other kinds of [class@Gtk.ShortcutAction]. See
65// [ctor@Gtk.ShortcutTrigger.parse_string] to learn more about the syntax
66// for triggers.
67type ShortcutController struct {
68 EventController
69}
70
71var xShortcutControllerGLibType func() types.GType
72
73func ShortcutControllerGLibType() types.GType {
74 return xShortcutControllerGLibType()
75}
76
77func ShortcutControllerNewFromInternalPtr(ptr uintptr) *ShortcutController {
78 cls := &ShortcutController{}
79 cls.Ptr = ptr
80 return cls
81}
82
83var xNewShortcutController func() uintptr
84
85// Creates a new shortcut controller.
86func NewShortcutController() *ShortcutController {
87 var cls *ShortcutController
88
89 cret := xNewShortcutController()
90
91 if cret == 0 {
92 return nil
93 }
94 cls = &ShortcutController{}
95 cls.Ptr = cret
96 return cls
97}
98
99var xNewShortcutControllerForModel func(uintptr) uintptr
100
101// Creates a new shortcut controller that takes its shortcuts from
102// the given list model.
103//
104// A controller created by this function does not let you add or
105// remove individual shortcuts using the shortcut controller api,
106// but you can change the contents of the model.
107func NewShortcutControllerForModel(ModelVar gio.ListModel) *ShortcutController {
108 var cls *ShortcutController
109
110 cret := xNewShortcutControllerForModel(ModelVar.GoPointer())
111
112 if cret == 0 {
113 return nil
114 }
115 cls = &ShortcutController{}
116 cls.Ptr = cret
117 return cls
118}
119
120var xShortcutControllerAddShortcut func(uintptr, uintptr)
121
122// Adds @shortcut to the list of shortcuts handled by @self.
123//
124// If this controller uses an external shortcut list, this
125// function does nothing.
126func (x *ShortcutController) AddShortcut(ShortcutVar *Shortcut) {
127
128 xShortcutControllerAddShortcut(x.GoPointer(), ShortcutVar.GoPointer())
129
130}
131
132var xShortcutControllerGetMnemonicsModifiers func(uintptr) gdk.ModifierType
133
134// Gets the mnemonics modifiers for when this controller activates its shortcuts.
135func (x *ShortcutController) GetMnemonicsModifiers() gdk.ModifierType {
136
137 cret := xShortcutControllerGetMnemonicsModifiers(x.GoPointer())
138 return cret
139}
140
141var xShortcutControllerGetScope func(uintptr) ShortcutScope
142
143// Gets the scope for when this controller activates its shortcuts.
144//
145// See [method@Gtk.ShortcutController.set_scope] for details.
146func (x *ShortcutController) GetScope() ShortcutScope {
147
148 cret := xShortcutControllerGetScope(x.GoPointer())
149 return cret
150}
151
152var xShortcutControllerRemoveShortcut func(uintptr, uintptr)
153
154// Removes @shortcut from the list of shortcuts handled by @self.
155//
156// If @shortcut had not been added to @controller or this controller
157// uses an external shortcut list, this function does nothing.
158func (x *ShortcutController) RemoveShortcut(ShortcutVar *Shortcut) {
159
160 xShortcutControllerRemoveShortcut(x.GoPointer(), ShortcutVar.GoPointer())
161
162}
163
164var xShortcutControllerSetMnemonicsModifiers func(uintptr, gdk.ModifierType)
165
166// Sets the controller to use the given modifier for mnemonics.
167//
168// The mnemonics modifiers determines which modifiers need to be pressed to allow
169// activation of shortcuts with mnemonics triggers.
170//
171// GTK normally uses the Alt modifier for mnemonics, except in `GtkPopoverMenu`s,
172// where mnemonics can be triggered without any modifiers. It should be very
173// rarely necessary to change this, and doing so is likely to interfere with
174// other shortcuts.
175//
176// This value is only relevant for local shortcut controllers. Global and managed
177// shortcut controllers will have their shortcuts activated from other places which
178// have their own modifiers for activating mnemonics.
179func (x *ShortcutController) SetMnemonicsModifiers(ModifiersVar gdk.ModifierType) {
180
181 xShortcutControllerSetMnemonicsModifiers(x.GoPointer(), ModifiersVar)
182
183}
184
185var xShortcutControllerSetScope func(uintptr, ShortcutScope)
186
187// Sets the controller to have the given @scope.
188//
189// The scope allows shortcuts to be activated outside of the normal
190// event propagation. In particular, it allows installing global
191// keyboard shortcuts that can be activated even when a widget does
192// not have focus.
193//
194// With %GTK_SHORTCUT_SCOPE_LOCAL, shortcuts will only be activated
195// when the widget has focus.
196func (x *ShortcutController) SetScope(ScopeVar ShortcutScope) {
197
198 xShortcutControllerSetScope(x.GoPointer(), ScopeVar)
199
200}
201
202func (c *ShortcutController) GoPointer() uintptr {
203 if c == nil {
204 return 0
205 }
206 return c.Ptr
207}
208
209func (c *ShortcutController) SetGoPointer(ptr uintptr) {
210 c.Ptr = ptr
211}
212
213// GetPropertyNItems gets the "n-items" property.
214// The number of items. See [method@Gio.ListModel.get_n_items].
215func (x *ShortcutController) GetPropertyNItems() uint {
216 var v gobject.Value
217 x.GetProperty("n-items", &v)
218 return v.GetUint()
219}
220
221// Get the item at @position.
222//
223// If @position is greater than the number of items in @list, %NULL is
224// returned.
225//
226// %NULL is never returned for an index that is smaller than the length
227// of the list.
228//
229// See also: g_list_model_get_n_items()
230func (x *ShortcutController) GetItem(PositionVar uint) uintptr {
231
232 cret := gio.XGListModelGetItem(x.GoPointer(), PositionVar)
233 return cret
234}
235
236// Gets the type of the items in @list.
237//
238// All items returned from g_list_model_get_item() are of the type
239// returned by this function, or a subtype, or if the type is an
240// interface, they are an implementation of that interface.
241//
242// The item type of a #GListModel can not change during the life of the
243// model.
244func (x *ShortcutController) GetItemType() types.GType {
245
246 cret := gio.XGListModelGetItemType(x.GoPointer())
247 return cret
248}
249
250// Gets the number of items in @list.
251//
252// Depending on the model implementation, calling this function may be
253// less efficient than iterating the list with increasing values for
254// @position until g_list_model_get_item() returns %NULL.
255func (x *ShortcutController) GetNItems() uint {
256
257 cret := gio.XGListModelGetNItems(x.GoPointer())
258 return cret
259}
260
261// Get the item at @position.
262//
263// If @position is greater than the number of items in @list, %NULL is
264// returned.
265//
266// %NULL is never returned for an index that is smaller than the length
267// of the list.
268//
269// This function is meant to be used by language bindings in place
270// of g_list_model_get_item().
271//
272// See also: g_list_model_get_n_items()
273func (x *ShortcutController) GetObject(PositionVar uint) *gobject.Object {
274 var cls *gobject.Object
275
276 cret := gio.XGListModelGetObject(x.GoPointer(), PositionVar)
277
278 if cret == 0 {
279 return nil
280 }
281 cls = &gobject.Object{}
282 cls.Ptr = cret
283 return cls
284}
285
286// Emits the #GListModel::items-changed signal on @list.
287//
288// This function should only be called by classes implementing
289// #GListModel. It has to be called after the internal representation
290// of @list has been updated, because handlers connected to this signal
291// might query the new state of the list.
292//
293// Implementations must only make changes to the model (as visible to
294// its consumer) in places that will not cause problems for that
295// consumer. For models that are driven directly by a write API (such
296// as #GListStore), changes can be reported in response to uses of that
297// API. For models that represent remote data, changes should only be
298// made from a fresh mainloop dispatch. It is particularly not
299// permitted to make changes in response to a call to the #GListModel
300// consumer API.
301//
302// Stated another way: in general, it is assumed that code making a
303// series of accesses to the model via the API, without returning to the
304// mainloop, and without calling other code, will continue to view the
305// same contents of the model.
306func (x *ShortcutController) ItemsChanged(PositionVar uint, RemovedVar uint, AddedVar uint) {
307
308 gio.XGListModelItemsChanged(x.GoPointer(), PositionVar, RemovedVar, AddedVar)
309
310}
311
312// Gets the ID of the @buildable object.
313//
314// `GtkBuilder` sets the name based on the ID attribute
315// of the `<object>` tag used to construct the @buildable.
316func (x *ShortcutController) GetBuildableId() string {
317
318 cret := XGtkBuildableGetBuildableId(x.GoPointer())
319 return cret
320}
321
322func init() {
323 core.SetPackageName("GTK", "gtk4")
324 core.SetSharedLibraries("GTK", []string{"libgtk-4.so.1"})
325 var libs []uintptr
326 for _, libPath := range core.GetPaths("GTK") {
327 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
328 if err != nil {
329 panic(err)
330 }
331 libs = append(libs, lib)
332 }
333
334 core.PuregoSafeRegister(&xShortcutControllerGLibType, libs, "gtk_shortcut_controller_get_type")
335
336 core.PuregoSafeRegister(&xNewShortcutController, libs, "gtk_shortcut_controller_new")
337 core.PuregoSafeRegister(&xNewShortcutControllerForModel, libs, "gtk_shortcut_controller_new_for_model")
338
339 core.PuregoSafeRegister(&xShortcutControllerAddShortcut, libs, "gtk_shortcut_controller_add_shortcut")
340 core.PuregoSafeRegister(&xShortcutControllerGetMnemonicsModifiers, libs, "gtk_shortcut_controller_get_mnemonics_modifiers")
341 core.PuregoSafeRegister(&xShortcutControllerGetScope, libs, "gtk_shortcut_controller_get_scope")
342 core.PuregoSafeRegister(&xShortcutControllerRemoveShortcut, libs, "gtk_shortcut_controller_remove_shortcut")
343 core.PuregoSafeRegister(&xShortcutControllerSetMnemonicsModifiers, libs, "gtk_shortcut_controller_set_mnemonics_modifiers")
344 core.PuregoSafeRegister(&xShortcutControllerSetScope, libs, "gtk_shortcut_controller_set_scope")
345
346}