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