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