Merge: Annotation lateinit
[nit.git] / lib / gtk / v3_4 / gtk_core.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2011-2013 Alexis Laferrière <alexis.laf@xymus.net>
4 # Copyright 2013 Nathan Heu <heu.nathan@courrier.uqam.ca>
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17
18 # Classes and services to use libGTK widgets
19 module gtk_core is
20 pkgconfig "gtk+-3.0"
21 cflags "-Wno-deprecated-declarations"
22 end
23
24 import gtk_enums
25 import gdk_enums
26
27 in "C Header" `{
28 #include <gtk/gtk.h>
29 `}
30
31 `{
32 /* callback user data */
33 typedef struct {
34 GtkCallable to_call;
35 nullable_Object user_data;
36 } NitGtkSignal;
37
38 void nit_gtk_callback_func(GtkWidget *widget, gpointer callback_data) {
39 NitGtkSignal *data;
40 data = (NitGtkSignal*)callback_data;
41 GtkCallable_signal(data->to_call, widget, data->user_data);
42 }
43 `}
44
45 # Initialize the GTK system
46 fun init_gtk `{ gtk_init(0, NULL); `}
47
48 # Hand over control to the GTK event loop
49 fun run_gtk `{ gtk_main(); `}
50
51 # Quit the GTK event loop and clean up the system
52 fun quit_gtk `{ gtk_main_quit(); `}
53
54 interface GtkCallable
55 # return true to stop event processing, false to let it propagate
56 fun signal(sender: GtkWidget, user_data: nullable Object) is abstract
57 end
58
59 extern class GdkEvent `{GdkEvent *`}
60 end
61
62 # Base class for all widgets
63 # See: https://developer.gnome.org/gtk3/stable/GtkWidget.html
64 extern class GtkWidget `{GtkWidget *`}
65 fun show_all `{ gtk_widget_show_all(self); `}
66
67 fun signal_connect(signal_name: String, to_call: GtkCallable, user_data: nullable Object) import String.to_cstring, GtkCallable.signal, Object.as not nullable `{
68 NitGtkSignal *data = malloc(sizeof(NitGtkSignal));
69
70 GtkCallable_incr_ref(to_call);
71 Object_incr_ref(user_data);
72
73 data->to_call = to_call;
74 data->user_data = user_data;
75
76 /*Use G_CALLBACK() to cast the callback function to a GCallback*/
77 g_signal_connect(self,
78 String_to_cstring(signal_name),
79 G_CALLBACK(nit_gtk_callback_func),
80 data);
81 `}
82
83 redef fun ==(o) do return o isa GtkWidget and equal_to_gtk_widget(o)
84
85 private fun equal_to_gtk_widget(o: GtkWidget): Bool `{
86 return self == o;
87 `}
88
89 fun request_size(width, height: Int) `{
90 gtk_widget_set_size_request(self, width, height);
91 `}
92
93 fun bg_color=(state: GtkStateType, color: GdkRGBA) `{
94 gtk_widget_override_background_color(self, state, color);
95 `}
96
97 # with gtk it's possible to set fg_color to all widget: is it correct? is fg color inherited?
98 # GdkColor color;
99 fun fg_color=(state: GtkStateType, color: GdkRGBA) `{
100 gtk_widget_override_color(self, state, color);
101 `}
102
103 # Sets the sensitivity of a widget. sensitive -> the user can interact with it.
104 # Insensitive -> widget "grayed out" and the user can"t interact with them
105 fun sensitive=(sensitive: Bool) `{
106 gtk_widget_set_sensitive(self, sensitive);
107 `}
108
109 # return the sensitivity of the widget
110 fun sensitive: Bool `{
111 return gtk_widget_get_sensitive(self);
112 `}
113
114 # Set the visibility of the widget
115 fun visible=(visible: Bool) `{
116 gtk_widget_set_visible(self, visible);
117 `}
118
119 # Get the visibility of the widget only
120 fun visible_self: Bool `{
121 return gtk_widget_get_visible(self);
122 `}
123
124 # Destroy the widget
125 fun destroy `{ gtk_widget_destroy(self); `}
126
127 # Show the widget on screen
128 #
129 # See: `show_all` to recursively show this widget and contained widgets.
130 fun show `{ gtk_widget_show(self); `}
131
132 # Hide the widget (reverse the effects of `show`)
133 fun hide `{ gtk_widget_hide(self); `}
134 end
135
136 # Base class for widgets which contain other widgets
137 # See: https://developer.gnome.org/gtk3/stable/GtkContainer.html
138 extern class GtkContainer `{GtkContainer *`}
139 super GtkWidget
140
141 # Add a widget to the container
142 fun add(widget: GtkWidget) `{
143 gtk_container_add(self, widget);
144 `}
145 # Remove the widget from the container
146 fun remove_widget(widget: GtkWidget) `{
147 gtk_container_remove(self, widget);
148 `}
149
150 # Get the resize mode of the container
151 fun resize_mode: GtkResizeMode `{
152 return gtk_container_get_resize_mode(self);
153 `}
154
155 # Set the resize mode of the container
156 fun resize_mode=(resize_mode: GtkResizeMode) `{
157 gtk_container_set_resize_mode(self, resize_mode);
158 `}
159
160 end
161
162 # A container with just one child
163 # See: https://developer.gnome.org/gtk3/stable/GtkBin.html
164 extern class GtkBin `{GtkBin *`}
165 super GtkContainer
166
167 fun child: GtkWidget `{
168 return gtk_bin_get_child(self);
169 `}
170 end
171
172 # Toplevel which can contain other widgets
173 # See: https://developer.gnome.org/gtk3/stable/GtkWindow.html
174 extern class GtkWindow `{GtkWindow *`}
175 super GtkBin
176
177 new (typ: GtkWindowType) `{
178 return (GtkWindow *)gtk_window_new(typ);
179 `}
180
181 # Connect the "destroy" signal to `quit_gtk`
182 fun connect_destroy_signal_to_quit `{
183 g_signal_connect(self, "destroy", G_CALLBACK(gtk_main_quit), NULL);
184 `}
185
186 fun title=(title: String) import String.to_cstring `{
187 gtk_window_set_title(self, String_to_cstring(title));
188 `}
189
190 # The "destroy" signal is emitted when a widget is destroyed, either by explicitly calling gtk_widget_destroy() or when the widget is unparented. Top-level GtkWindows are also destroyed when the Close window control button is clicked.
191 fun on_close(to_call: GtkCallable, user_data: nullable Object)
192 do
193 signal_connect("destroy", to_call, user_data)
194 end
195
196 fun resizable: Bool `{
197 return gtk_window_get_resizable(self);
198 `}
199
200 fun resizable=(is_resizable: Bool) `{
201 return gtk_window_set_resizable(self, is_resizable);
202 `}
203
204 # Activates the current focused widget within the window.
205 # returns TRUE if a widget got activated.
206 fun activate_focus: Bool `{
207 return gtk_window_activate_focus(self);
208 `}
209
210 # Sets a window modal or non-modal. Modal windows prevent interaction with other windows in the same application.
211 fun modal=(is_modal: Bool) `{
212 gtk_window_set_modal(self, is_modal);
213 `}
214
215 # Windows can't actually be 0x0 in size, they must be at least 1x1
216 # but passing 0 for width and height is OK, resulting in a 1x1 default size.
217 # params width in pixels, or -1 to unset the default width
218 # params height in pixels, or -1 to unset the default height
219 fun default_size(width: Int, height: Int) `{
220 gtk_window_set_default_size(self, width, height);
221 `}
222
223 # Activates the default widget for the window
224 # unless the current focused widget has been configured to receive the default action (see gtk_widget_set_receives_default()), in which case the focused widget is activated.
225 fun activate_default: Bool `{
226 return gtk_window_activate_default(self);
227 `}
228
229 fun gravity: GdkGravity `{
230 return gtk_window_get_gravity(self);
231 `}
232
233 fun gravity=(window_grav: GdkGravity) `{
234 gtk_window_set_gravity(self, window_grav);
235 `}
236
237 # fun position: GtkWindowPosition `{
238 # return gtk_window_get_position(self);
239 # `}
240 #
241 # fun position=(window_pos: GtkWindowPosition) `{
242 # gtk_window_set_position(self, window_pos);
243 # `}
244
245 fun active: Bool `{
246 return gtk_window_is_active(self);
247 `}
248
249 # Returns whether the input focus is within this GtkWindow. For real toplevel windows, this is identical to gtk_window_is_active(), but for embedded windows, like GtkPlug, the results will differ.
250 fun has_toplevel_focus: Bool `{
251 return gtk_window_has_toplevel_focus(self);
252 `}
253
254 fun get_focus: GtkWidget `{
255 return gtk_window_get_focus(self);
256 `}
257
258 fun set_focus(widget: GtkWidget) `{
259 return gtk_window_set_focus(self, widget);
260 `}
261
262 fun get_default_widget: GtkWidget `{
263 return gtk_window_get_default_widget(self);
264 `}
265
266 fun set_default_widget(widget: GtkWidget) `{
267 return gtk_window_set_default(self, widget);
268 `}
269
270 fun maximize `{
271 return gtk_window_maximize(self);
272 `}
273
274 fun unmaximize `{
275 return gtk_window_unmaximize(self);
276 `}
277
278 fun fullscreen `{
279 return gtk_window_fullscreen(self);
280 `}
281
282 fun unfullscreen `{
283 return gtk_window_unfullscreen(self);
284 `}
285
286 fun keep_above=(setting: Bool) `{
287 gtk_window_set_keep_above(self, setting);
288 `}
289
290 fun keep_below=(setting: Bool) `{
291 gtk_window_set_keep_below(self, setting);
292 `}
293 end
294
295 # A bin with a decorative frame and optional label
296 # https://developer.gnome.org/gtk3/stable/GtkFrame.html
297 extern class GtkFrame `{GtkFrame *`}
298 super GtkBin
299
300 new (lbl: String) import String.to_cstring `{
301 return (GtkFrame *)gtk_frame_new(String_to_cstring(lbl));
302 `}
303
304 fun frame_label: String `{
305 return NativeString_to_s((char *)gtk_frame_get_label(self));
306 `}
307
308 fun frame_label=(lbl: String) import String.to_cstring `{
309 gtk_frame_set_label(self, String_to_cstring(lbl));
310 `}
311
312 fun label_widget: GtkWidget `{
313 return gtk_frame_get_label_widget(self);
314 `}
315
316 fun label_widget=(widget: GtkWidget) `{
317 gtk_frame_set_label_widget(self, widget);
318 `}
319
320 fun shadow_type: GtkShadowType `{
321 return gtk_frame_get_shadow_type(self);
322 `}
323
324 fun shadow_type=(stype: GtkShadowType) `{
325 gtk_frame_set_shadow_type(self, stype);
326 `}
327
328 fun label_align=(xalign: Float, yalign: Float) `{
329 gtk_frame_set_label_align(self, xalign, yalign);
330 `}
331 end
332
333 # Pack widgets in a rows and columns
334 # See: https://developer.gnome.org/gtk3/3.3/GtkGrid.html
335 extern class GtkGrid `{GtkGrid *`}
336 super GtkContainer
337
338 # Create a new grid
339 new `{
340 return (GtkGrid*)gtk_grid_new();
341 `}
342
343 # Set a widget child inside the grid at a given position
344 fun attach(child: GtkWidget, left, top, width, height: Int) `{
345 gtk_grid_attach(self, child, left, top, width, height);
346 `}
347
348 # Get the child of the Grid at the given position
349 fun get_child_at(left: Int, top: Int): GtkWidget `{
350 return gtk_grid_get_child_at(self, left, top);
351 `}
352
353 # Insert a row at the specified position
354 fun insert_row(position:Int) `{
355 gtk_grid_insert_row(self, position);
356 `}
357
358 # Insert a column at the specified position
359 fun insert_column(position: Int) `{
360 gtk_grid_insert_column(self, position);
361 `}
362 end
363
364 # A widget that can switch orientation
365 extern class GtkOrientable `{GtkOrientable *`}
366 super GtkWidget
367
368 # Get the orientation of this widget
369 fun orientation: GtkOrientation `{
370 return gtk_orientable_get_orientation(self);
371 `}
372
373 # Set the orientation of this widget
374 fun orientation=(orientation: GtkOrientation) `{
375 gtk_orientable_set_orientation(self, orientation);
376 `}
377 end
378
379 # A container box
380 #
381 # See: https://developer.gnome.org/gtk3/3.4/GtkBox.html
382 extern class GtkBox `{ GtkBox * `}
383 super GtkContainer
384 super GtkOrientable
385
386 # Create a new `GtkBox` with the given `orientation` and `spacing` between its children
387 new (orientation: GtkOrientation, spacing: Int) `{
388 return (GtkBox *)gtk_box_new(orientation, spacing);
389 `}
390
391 # Give the children of `self` equal space in the box?
392 fun homogeneous: Bool `{ return gtk_box_get_homogeneous(self); `}
393
394 # Give the children of `self` equal space in the box?
395 fun homogeneous=(homogeneous: Bool) `{
396 gtk_box_set_homogeneous(self, homogeneous);
397 `}
398
399 # Add `child` and pack it at the start of the box
400 fun pack_start(child: GtkWidget, expand, fill: Bool, padding: Int) `{
401 gtk_box_pack_start(self, child, expand, fill, padding);
402 `}
403
404 # Add `child` and pack it at the end of the box
405 fun pack_end(child: GtkWidget, expand, fill: Bool, padding: Int) `{
406 gtk_box_pack_end(self, child, expand, fill, padding);
407 `}
408
409 # Set the way `child` is packed in `self`
410 fun set_child_packing(child: GtkWidget, expand, fill: Bool, padding: Int, packing: GtkPackType) `{
411 gtk_box_set_child_packing(self, child, expand, fill, padding, packing);
412 `}
413 end
414
415 # The tree interface used by GtkTreeView
416 # See: https://developer.gnome.org/gtk3/stable/GtkTreeModel.html
417 extern class GtkTreeModel `{GtkTreeModel *`}
418 end
419
420 # An abstract class for laying out GtkCellRenderers
421 # See: https://developer.gnome.org/gtk3/stable/GtkCellArea.html
422 extern class GtkCellArea `{GtkCellArea *`}
423 end
424
425 # Base class for widgets with alignments and padding
426 # See: https://developer.gnome.org/gtk3/3.2/GtkMisc.html
427 extern class GtkMisc `{GtkMisc *`}
428 super GtkWidget
429
430 fun alignment: GtkAlignment is abstract
431
432 fun alignment=(x: Float, y: Float) `{
433 gtk_misc_set_alignment(self, x, y);
434 `}
435
436 fun padding: GtkAlignment is abstract
437
438 fun padding=(x: Float, y: Float) `{
439 gtk_misc_set_padding(self, x, y);
440 `}
441
442 end
443
444 # A single line text entry field
445 # See: https://developer.gnome.org/gtk3/3.2/GtkEntry.html
446 extern class GtkEntry `{GtkEntry *`}
447 super GtkWidget
448
449 new `{
450 return (GtkEntry *)gtk_entry_new();
451 `}
452
453 fun text: String import NativeString.to_s_with_copy `{
454 return NativeString_to_s_with_copy((char *)gtk_entry_get_text(self));
455 `}
456
457 fun text=(value: String) import String.to_cstring `{
458 gtk_entry_set_text(self, String_to_cstring(value));
459 `}
460
461 # Is the text visible or is it the invisible char (such as '*')?
462 fun visiblility: Bool `{
463 return gtk_entry_get_visibility(self);
464 `}
465
466 # Set the text visiblility
467 # If false, will use the invisible char (such as '*')
468 fun visibility=(is_visible: Bool) `{
469 gtk_entry_set_visibility(self, is_visible);
470 `}
471
472 fun max_length: Int `{
473 return gtk_entry_get_max_length(self);
474 `}
475
476 fun max_length=(max: Int) `{
477 gtk_entry_set_max_length(self, max);
478 `}
479 end
480
481 # Base class for widgets which visualize an adjustment
482 # See: https://developer.gnome.org/gtk3/3.2/GtkRange.html
483 extern class GtkRange `{GtkRange *`}
484 super GtkWidget
485
486 # Gets the current position of the fill level indicator.
487 fun fill_level: Float `{
488 return gtk_range_get_fill_level(self);
489 `}
490
491 fun fill_level=(level: Float) `{
492 gtk_range_set_fill_level(self, level);
493 `}
494
495 # Gets whether the range is restricted to the fill level.
496 fun restricted_to_fill_level: Bool `{
497 return gtk_range_get_restrict_to_fill_level(self);
498 `}
499
500 fun restricted_to_fill_level=(restricted: Bool) `{
501 gtk_range_set_restrict_to_fill_level(self, restricted);
502 `}
503
504 # Gets whether the range displays the fill level graphically.
505 fun show_fill_level: Bool `{
506 return gtk_range_get_show_fill_level(self);
507 `}
508
509 fun show_fill_level=(is_displayed: Bool) `{
510 gtk_range_set_show_fill_level(self, is_displayed);
511 `}
512
513 fun adjustment: GtkAdjustment `{
514 return gtk_range_get_adjustment(self);
515 `}
516
517 fun adjustment=(value: GtkAdjustment) `{
518 gtk_range_set_adjustment(self, value);
519 `}
520
521 fun inverted: Bool `{
522 return gtk_range_get_inverted(self);
523 `}
524
525 fun inverted=(setting: Bool) `{
526 gtk_range_set_inverted(self, setting);
527 `}
528
529 fun value: Float `{
530 return gtk_range_get_value(self);
531 `}
532
533 fun value=(val: Float) `{
534 gtk_range_set_value(self, val);
535 `}
536
537 fun set_increments(step: Float, page: Float) `{
538 gtk_range_set_increments(self, step, page);
539 `}
540
541 fun set_range(min: Float, max: Float) `{
542 gtk_range_set_range(self, min, max);
543 `}
544
545 fun round_digits: Int `{
546 return gtk_range_get_round_digits(self);
547 `}
548
549 fun round_digits=(nb: Int) `{
550 gtk_range_set_round_digits(self, nb);
551 `}
552
553 fun size_fixed: Bool `{
554 return gtk_range_get_slider_size_fixed(self);
555 `}
556
557 fun size_fixed=(is_fixed: Bool) `{
558 return gtk_range_set_slider_size_fixed(self, is_fixed);
559 `}
560
561 fun flippable: Bool `{
562 return gtk_range_get_flippable(self);
563 `}
564
565 fun min_size=(is_flippable: Bool) `{
566 return gtk_range_set_flippable(self, is_flippable);
567 `}
568
569 fun min_slider_size: Int `{
570 return gtk_range_get_min_slider_size(self);
571 `}
572
573 fun min_slider_size=(size: Int) `{
574 return gtk_range_set_min_slider_size(self, size);
575 `}
576 end
577
578 # A slider widget for selecting a value from a range
579 # See: https://developer.gnome.org/gtk3/3.2/GtkScale.html
580 extern class GtkScale `{GtkScale *`}
581 super GtkRange
582
583 new (orientation: GtkOrientation, adjustment: GtkAdjustment) `{
584 return (GtkScale *)gtk_scale_new(orientation, adjustment);
585 `}
586
587 new with_range (orientation: GtkOrientation, min: Float, max: Float, step: Float) `{
588 return (GtkScale *)gtk_scale_new_with_range(orientation, min, max, step);
589 `}
590
591 fun digits: Int `{
592 return gtk_scale_get_digits(self);
593 `}
594
595 fun digits=(nb_digits: Int) `{
596 gtk_scale_set_digits(self, nb_digits);
597 `}
598
599 fun draw_value: Bool `{
600 return gtk_scale_get_draw_value(self);
601 `}
602
603 fun draw_value=(is_displayed: Bool) `{
604 gtk_scale_set_draw_value(self, is_displayed);
605 `}
606
607 fun value_position: GtkPositionType `{
608 return gtk_scale_get_value_pos(self);
609 `}
610
611 fun value_position=(pos: GtkPositionType) `{
612 gtk_scale_set_value_pos(self, pos);
613 `}
614
615 fun has_origin: Bool `{
616 return gtk_scale_get_has_origin(self);
617 `}
618
619 fun has_origin=(orig: Bool) `{
620 gtk_scale_set_has_origin(self, orig);
621 `}
622
623 fun add_mark(value: Float, position: GtkPositionType, markup: String)
624 import String.to_cstring `{
625 gtk_scale_add_mark(self, value, position, String_to_cstring(markup));
626 `}
627
628 # Removes any marks that have been added with gtk_scale_add_mark().
629 fun clear_marks `{
630 gtk_scale_clear_marks(self);
631 `}
632 end
633
634 # A scrollbar
635 # See: https://developer.gnome.org/gtk3/3.2/GtkScrollbar.html
636 extern class GtkScrollbar `{GtkScrollbar *`}
637 super GtkRange
638
639 new (orientation: GtkOrientation, adjustment: GtkAdjustment) `{
640 return (GtkScrollbar *)gtk_scrollbar_new(orientation, adjustment);
641 `}
642 end
643
644 # A widget that displays a small to medium amount of text
645 # See: https://developer.gnome.org/gtk3/3.2/GtkLabel.html
646 extern class GtkLabel `{GtkLabel *`}
647 super GtkMisc
648
649 # Create a GtkLabel with text
650 new (text: String) import String.to_cstring `{
651 return (GtkLabel*)gtk_label_new(String_to_cstring(text));
652 `}
653
654 # Set the text of the label
655 fun text=(text: String) import String.to_cstring `{
656 gtk_label_set_text(self, String_to_cstring(text));
657 `}
658
659 # Returns the text of the label
660 fun text: String import NativeString.to_s `{
661 return NativeString_to_s((char*)gtk_label_get_text(self));
662 `}
663
664 # Sets the angle of rotation for the label.
665 # An angle of 90 reads from from bottom to top, an angle of 270, from top to bottom.
666 fun angle=(degre: Float) `{
667 gtk_label_set_angle(self, degre);
668 `}
669
670 # Returns the angle of rotation for the label.
671 fun angle: Float `{
672 return gtk_label_get_angle(self);
673 `}
674
675 end
676
677 # A widget displaying an image
678 # See: https://developer.gnome.org/gtk3/3.2/GtkImage.html
679 extern class GtkImage `{GtkImage *`}
680 super GtkMisc
681
682 # Create a GtkImage
683 new `{
684 return (GtkImage*)gtk_image_new();
685 `}
686
687 # Create a GtkImage with text
688 new file(filename: String) import String.to_cstring `{
689 return (GtkImage*)gtk_image_new_from_file(String_to_cstring(filename));
690 `}
691
692 fun pixel_size: Int `{
693 return gtk_image_get_pixel_size(self);
694 `}
695
696 fun pixel_size=(size: Int) `{
697 gtk_image_set_pixel_size(self, size);
698 `}
699
700 fun clear `{
701 gtk_image_clear(self);
702 `}
703 end
704
705 # enum GtkImageType
706 # Describes the image data representation used by a GtkImage.
707 # See: https://developer.gnome.org/gtk3/3.2/GtkImage.html#GtkImageType
708 extern class GtkImageType `{GtkImageType`}
709 # There is no image displayed by the widget.
710 new empty `{ return GTK_IMAGE_EMPTY; `}
711
712 # The widget contains a GdkPixbuf.
713 new pixbuf `{ return GTK_IMAGE_PIXBUF; `}
714
715 # The widget contains a stock icon name.
716 new stock `{ return GTK_IMAGE_STOCK; `}
717
718 # The widget contains a GtkIconSet.
719 new icon_set `{ return GTK_IMAGE_ICON_SET; `}
720
721 # The widget contains a GdkPixbufAnimation.
722 new animation `{ return GTK_IMAGE_ANIMATION; `}
723
724 # The widget contains a named icon.
725 new icon_name `{ return GTK_IMAGE_ICON_NAME; `}
726
727 # The widget contains a GIcon.
728 new gicon `{ return GTK_IMAGE_GICON; `}
729 end
730
731 # Displays an arrow
732 # See: https://developer.gnome.org/gtk3/3.2/GtkArrow.html
733 extern class GtkArrow `{GtkArrow *`}
734 super GtkMisc
735
736 new (arrow_type: GtkArrowType, shadow_type: GtkShadowType) `{
737 return (GtkArrow *)gtk_arrow_new(arrow_type, shadow_type);
738 `}
739
740 fun set(arrow_type: GtkArrowType, shadow_type: GtkShadowType) `{
741 gtk_arrow_set(self, arrow_type, shadow_type);
742 `}
743 end
744
745 # A widget that emits a signal when clicked on
746 # See: https://developer.gnome.org/gtk3/stable/GtkButton.html
747 extern class GtkButton `{GtkButton *`}
748 super GtkBin
749
750 new `{
751 return (GtkButton *)gtk_button_new();
752 `}
753
754 # Create a GtkButton with text
755 new with_label(text: String) import String.to_cstring `{
756 return (GtkButton *)gtk_button_new_with_label(String_to_cstring(text));
757 `}
758
759 new from_stock(stock_id: String) import String.to_cstring `{
760 return (GtkButton *)gtk_button_new_from_stock(String_to_cstring(stock_id));
761 `}
762
763 fun text: String `{
764 return NativeString_to_s((char *)gtk_button_get_label(self));
765 `}
766
767 fun text=(value: String) import String.to_cstring `{
768 gtk_button_set_label(self, String_to_cstring(value));
769 `}
770
771 fun on_click(to_call: GtkCallable, user_data: nullable Object) do
772 signal_connect("clicked", to_call, user_data)
773 end
774
775 end
776
777 # A button which pops up a scale
778 # See: https://developer.gnome.org/gtk3/stable/GtkScaleButton.html
779 extern class GtkScaleButton `{GtkScaleButton *`}
780 super GtkButton
781
782 # const gchar **icons
783 new(size: GtkIconSize, min: Float, max: Float, step: Float) `{
784 return (GtkScaleButton *)gtk_scale_button_new(size, min, max, step, (const char **)0);
785 `}
786 end
787
788 # Create buttons bound to a URL
789 # See: https://developer.gnome.org/gtk3/stable/GtkLinkButton.html
790 extern class GtkLinkButton `{GtkLinkButton *`}
791 super GtkButton
792
793 new(uri: String) import String.to_cstring `{
794 return (GtkLinkButton *)gtk_link_button_new(String_to_cstring(uri));
795 `}
796 end
797
798 # A container which can hide its child
799 # https://developer.gnome.org/gtk3/stable/GtkExpander.html
800 extern class GtkExpander `{GtkExpander *`}
801 super GtkBin
802
803 new(lbl: String) import String.to_cstring `{
804 return (GtkExpander *)gtk_expander_new(String_to_cstring(lbl));
805 `}
806
807 new with_mnemonic(lbl: String) import String.to_cstring `{
808 return (GtkExpander *)gtk_expander_new_with_mnemonic(String_to_cstring(lbl));
809 `}
810
811 fun expanded: Bool `{
812 return gtk_expander_get_expanded(self);
813 `}
814
815 fun expanded=(is_expanded: Bool) `{
816 gtk_expander_set_expanded(self, is_expanded);
817 `}
818
819 fun spacing: Int `{
820 return gtk_expander_get_spacing(self);
821 `}
822
823 fun spacing=(pixels: Int) `{
824 gtk_expander_set_spacing(self, pixels);
825 `}
826
827 fun label_text: String `{
828 return NativeString_to_s((char *)gtk_expander_get_label(self));
829 `}
830
831 fun label_text=(lbl: String) import String.to_cstring `{
832 gtk_expander_set_label(self, String_to_cstring(lbl));
833 `}
834
835 fun use_underline: Bool `{
836 return gtk_expander_get_use_underline(self);
837 `}
838
839 fun use_underline=(used: Bool) `{
840 gtk_expander_set_use_underline(self, used);
841 `}
842
843 fun use_markup: Bool `{
844 return gtk_expander_get_use_markup(self);
845 `}
846
847 fun use_markup=(used: Bool) `{
848 gtk_expander_set_use_markup(self, used);
849 `}
850
851 fun label_widget: GtkWidget `{
852 return gtk_expander_get_label_widget(self);
853 `}
854
855 fun label_widget=(widget: GtkWidget) `{
856 gtk_expander_set_label_widget(self, widget);
857 `}
858
859 fun label_fill: Bool `{
860 return gtk_expander_get_label_fill(self);
861 `}
862
863 fun label_fill=(fill: Bool) `{
864 gtk_expander_set_label_fill(self, fill);
865 `}
866
867 fun resize_toplevel: Bool `{
868 return gtk_expander_get_resize_toplevel(self);
869 `}
870
871 fun resize_toplevel=(resize: Bool) `{
872 gtk_expander_set_resize_toplevel(self, resize);
873 `}
874
875 end
876
877 # An abstract class for laying out GtkCellRenderers
878 # See: https://developer.gnome.org/gtk3/stable/GtkCellArea.html
879 extern class GtkComboBox `{GtkComboBox *`}
880 super GtkBin
881
882 new `{
883 return (GtkComboBox *)gtk_combo_box_new();
884 `}
885
886 new with_entry `{
887 return (GtkComboBox *)gtk_combo_box_new_with_entry();
888 `}
889
890 new with_model(model: GtkTreeModel) `{
891 return (GtkComboBox *)gtk_combo_box_new_with_model(model);
892 `}
893
894 new with_model_and_entry(model: GtkTreeModel) `{
895 return (GtkComboBox *)gtk_combo_box_new_with_model_and_entry(model);
896 `}
897
898 new with_area(area: GtkCellArea) `{
899 return (GtkComboBox *)gtk_combo_box_new_with_area(area);
900 `}
901
902 new with_area_and_entry(area: GtkCellArea) `{
903 return (GtkComboBox *)gtk_combo_box_new_with_area_and_entry(area);
904 `}
905
906 fun wrap_width: Int `{
907 return gtk_combo_box_get_wrap_width(self);
908 `}
909
910 fun wrap_width=(width: Int) `{
911 gtk_combo_box_set_wrap_width(self, width);
912 `}
913
914 fun row_span_col: Int `{
915 return gtk_combo_box_get_row_span_column(self);
916 `}
917
918 fun row_span_col=(row_span: Int) `{
919 gtk_combo_box_set_row_span_column(self, row_span);
920 `}
921
922 fun col_span_col: Int `{
923 return gtk_combo_box_get_column_span_column(self);
924 `}
925
926 fun col_span_col=(col_span: Int) `{
927 gtk_combo_box_set_column_span_column(self, col_span);
928 `}
929
930 fun active_item: Int `{
931 return gtk_combo_box_get_active(self);
932 `}
933
934 fun active_item=(active: Int) `{
935 gtk_combo_box_set_active(self, active);
936 `}
937
938 fun column_id: Int `{
939 return gtk_combo_box_get_id_column(self);
940 `}
941
942 fun column_id=(id_column: Int) `{
943 gtk_combo_box_set_id_column(self, id_column);
944 `}
945
946 fun active_id: String `{
947 return NativeString_to_s((char *)gtk_combo_box_get_active_id(self));
948 `}
949
950 fun active_id=(id_active: String) import String.to_cstring `{
951 gtk_combo_box_set_active_id(self, String_to_cstring(id_active));
952 `}
953
954 fun model: GtkTreeModel `{
955 return gtk_combo_box_get_model(self);
956 `}
957
958 fun model=(model: GtkTreeModel) `{
959 gtk_combo_box_set_model(self, model);
960 `}
961
962 fun popup `{
963 gtk_combo_box_popup(self);
964 `}
965
966 fun popdown `{
967 gtk_combo_box_popdown(self);
968 `}
969
970 fun title: String `{
971 return NativeString_to_s((char *)gtk_combo_box_get_title(self));
972 `}
973
974 fun title=(t: String) import String.to_cstring `{
975 gtk_combo_box_set_title(self, String_to_cstring(t));
976 `}
977
978 fun has_entry: Bool `{
979 return gtk_combo_box_get_has_entry(self);
980 `}
981
982 fun with_fixed: Bool `{
983 return gtk_combo_box_get_popup_fixed_width(self);
984 `}
985
986 fun with_fixed=(fixed: Bool) `{
987 gtk_combo_box_set_popup_fixed_width(self, fixed);
988 `}
989 end
990
991 # Show a spinner animation
992 # See: https://developer.gnome.org/gtk3/3.2/GtkSpinner.html
993 extern class GtkSpinner `{GtkSpinner *`}
994 super GtkWidget
995
996 new `{
997 return (GtkSpinner *)gtk_spinner_new();
998 `}
999
1000 fun start `{
1001 return gtk_spinner_start(self);
1002 `}
1003
1004 fun stop `{
1005 return gtk_spinner_stop(self);
1006 `}
1007 end
1008
1009 # A "light switch" style toggle
1010 # See: https://developer.gnome.org/gtk3/3.2/GtkSwitch.html
1011 extern class GtkSwitch `{GtkSwitch *`}
1012 super GtkWidget
1013
1014 new `{
1015 return (GtkSwitch *)gtk_switch_new();
1016 `}
1017
1018 fun active: Bool `{
1019 return gtk_switch_get_active(self);
1020 `}
1021
1022 fun active=(is_active: Bool) `{
1023 return gtk_switch_set_active(self, is_active);
1024 `}
1025 end
1026
1027 # A widget which controls the alignment and size of its child
1028 # https://developer.gnome.org/gtk3/stable/GtkAlignment.html
1029 extern class GtkAlignment `{GtkAlignment *`}
1030 super GtkBin
1031
1032 new (xalign: Float, yalign: Float, xscale: Float, yscale: Float) `{
1033 return (GtkAlignment *)gtk_alignment_new(xalign, yalign, xscale, yscale);
1034 `}
1035
1036 fun set (xalign: Float, yalign: Float, xscale: Float, yscale: Float) `{
1037 gtk_alignment_set(self, xalign, yalign, xscale, yscale);
1038 `}
1039
1040 end
1041
1042 # A representation of an adjustable bounded value
1043 # See: https://developer.gnome.org/gtk3/stable/GtkAdjustment.html#GtkAdjustment.description
1044 extern class GtkAdjustment `{GtkAdjustment *`}
1045 end
1046
1047 extern class GdkColor `{GdkColor*`}
1048 new (color_name: String) import String.to_cstring `{
1049 GdkColor *color = malloc(sizeof(GdkColor));
1050 gdk_color_parse(String_to_cstring(color_name), color);
1051 return color;
1052 `}
1053 end
1054
1055 extern class GdkRGBA `{GdkRGBA*`}
1056 end
1057