c3617f131e01df39e1f8f5d2d81f923c35cae7b7
[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 import CString.to_s_with_copy `{
335 return CString_to_s_with_copy((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 set_alignment(x, y: Float) `{
461 gtk_misc_set_alignment(self, x, y);
462 `}
463
464 fun set_padding(x, y: Float) `{
465 gtk_misc_set_padding(self, x, y);
466 `}
467 end
468
469 # A single line text entry field
470 # See: https://developer.gnome.org/gtk3/3.2/GtkEntry.html
471 extern class GtkEntry `{GtkEntry *`}
472 super GtkWidget
473
474 new `{
475 return (GtkEntry *)gtk_entry_new();
476 `}
477
478 fun text: String import CString.to_s_with_copy `{
479 return CString_to_s_with_copy((char *)gtk_entry_get_text(self));
480 `}
481
482 fun text=(value: String) import String.to_cstring `{
483 gtk_entry_set_text(self, String_to_cstring(value));
484 `}
485
486 # Is the text visible or is it the invisible char (such as '*')?
487 fun visiblility: Bool `{
488 return gtk_entry_get_visibility(self);
489 `}
490
491 # Set the text visiblility
492 # If false, will use the invisible char (such as '*')
493 fun visibility=(is_visible: Bool) `{
494 gtk_entry_set_visibility(self, is_visible);
495 `}
496
497 fun max_length: Int `{
498 return gtk_entry_get_max_length(self);
499 `}
500
501 fun max_length=(max: Int) `{
502 gtk_entry_set_max_length(self, max);
503 `}
504 end
505
506 # Base class for widgets which visualize an adjustment
507 # See: https://developer.gnome.org/gtk3/3.2/GtkRange.html
508 extern class GtkRange `{GtkRange *`}
509 super GtkWidget
510
511 # Gets the current position of the fill level indicator.
512 fun fill_level: Float `{
513 return gtk_range_get_fill_level(self);
514 `}
515
516 fun fill_level=(level: Float) `{
517 gtk_range_set_fill_level(self, level);
518 `}
519
520 # Gets whether the range is restricted to the fill level.
521 fun restricted_to_fill_level: Bool `{
522 return gtk_range_get_restrict_to_fill_level(self);
523 `}
524
525 fun restricted_to_fill_level=(restricted: Bool) `{
526 gtk_range_set_restrict_to_fill_level(self, restricted);
527 `}
528
529 # Gets whether the range displays the fill level graphically.
530 fun show_fill_level: Bool `{
531 return gtk_range_get_show_fill_level(self);
532 `}
533
534 fun show_fill_level=(is_displayed: Bool) `{
535 gtk_range_set_show_fill_level(self, is_displayed);
536 `}
537
538 fun adjustment: GtkAdjustment `{
539 return gtk_range_get_adjustment(self);
540 `}
541
542 fun adjustment=(value: GtkAdjustment) `{
543 gtk_range_set_adjustment(self, value);
544 `}
545
546 fun inverted: Bool `{
547 return gtk_range_get_inverted(self);
548 `}
549
550 fun inverted=(setting: Bool) `{
551 gtk_range_set_inverted(self, setting);
552 `}
553
554 fun value: Float `{
555 return gtk_range_get_value(self);
556 `}
557
558 fun value=(val: Float) `{
559 gtk_range_set_value(self, val);
560 `}
561
562 fun set_increments(step: Float, page: Float) `{
563 gtk_range_set_increments(self, step, page);
564 `}
565
566 fun set_range(min: Float, max: Float) `{
567 gtk_range_set_range(self, min, max);
568 `}
569
570 fun round_digits: Int `{
571 return gtk_range_get_round_digits(self);
572 `}
573
574 fun round_digits=(nb: Int) `{
575 gtk_range_set_round_digits(self, nb);
576 `}
577
578 fun size_fixed: Bool `{
579 return gtk_range_get_slider_size_fixed(self);
580 `}
581
582 fun size_fixed=(is_fixed: Bool) `{
583 return gtk_range_set_slider_size_fixed(self, is_fixed);
584 `}
585
586 fun flippable: Bool `{
587 return gtk_range_get_flippable(self);
588 `}
589
590 fun min_size=(is_flippable: Bool) `{
591 return gtk_range_set_flippable(self, is_flippable);
592 `}
593
594 fun min_slider_size: Int `{
595 return gtk_range_get_min_slider_size(self);
596 `}
597
598 fun min_slider_size=(size: Int) `{
599 return gtk_range_set_min_slider_size(self, size);
600 `}
601 end
602
603 # A slider widget for selecting a value from a range
604 # See: https://developer.gnome.org/gtk3/3.2/GtkScale.html
605 extern class GtkScale `{GtkScale *`}
606 super GtkRange
607
608 new (orientation: GtkOrientation, adjustment: GtkAdjustment) `{
609 return (GtkScale *)gtk_scale_new(orientation, adjustment);
610 `}
611
612 new with_range (orientation: GtkOrientation, min: Float, max: Float, step: Float) `{
613 return (GtkScale *)gtk_scale_new_with_range(orientation, min, max, step);
614 `}
615
616 fun digits: Int `{
617 return gtk_scale_get_digits(self);
618 `}
619
620 fun digits=(nb_digits: Int) `{
621 gtk_scale_set_digits(self, nb_digits);
622 `}
623
624 fun draw_value: Bool `{
625 return gtk_scale_get_draw_value(self);
626 `}
627
628 fun draw_value=(is_displayed: Bool) `{
629 gtk_scale_set_draw_value(self, is_displayed);
630 `}
631
632 fun value_position: GtkPositionType `{
633 return gtk_scale_get_value_pos(self);
634 `}
635
636 fun value_position=(pos: GtkPositionType) `{
637 gtk_scale_set_value_pos(self, pos);
638 `}
639
640 fun has_origin: Bool `{
641 return gtk_scale_get_has_origin(self);
642 `}
643
644 fun has_origin=(orig: Bool) `{
645 gtk_scale_set_has_origin(self, orig);
646 `}
647
648 fun add_mark(value: Float, position: GtkPositionType, markup: String)
649 import String.to_cstring `{
650 gtk_scale_add_mark(self, value, position, String_to_cstring(markup));
651 `}
652
653 # Removes any marks that have been added with gtk_scale_add_mark().
654 fun clear_marks `{
655 gtk_scale_clear_marks(self);
656 `}
657 end
658
659 # A scrollbar
660 # See: https://developer.gnome.org/gtk3/3.2/GtkScrollbar.html
661 extern class GtkScrollbar `{GtkScrollbar *`}
662 super GtkRange
663
664 new (orientation: GtkOrientation, adjustment: GtkAdjustment) `{
665 return (GtkScrollbar *)gtk_scrollbar_new(orientation, adjustment);
666 `}
667 end
668
669 # A widget that displays a small to medium amount of text
670 # See: https://developer.gnome.org/gtk3/3.2/GtkLabel.html
671 extern class GtkLabel `{GtkLabel *`}
672 super GtkMisc
673
674 # Create a GtkLabel with text
675 new (text: String) import String.to_cstring `{
676 return (GtkLabel*)gtk_label_new(String_to_cstring(text));
677 `}
678
679 # Set the text of the label
680 fun text=(text: String) import String.to_cstring `{
681 gtk_label_set_text(self, String_to_cstring(text));
682 `}
683
684 # Returns the text of the label
685 fun text: String import CString.to_s_with_copy `{
686 return CString_to_s_with_copy((char*)gtk_label_get_text(self));
687 `}
688
689 # Sets the angle of rotation for the label.
690 # An angle of 90 reads from from bottom to top, an angle of 270, from top to bottom.
691 fun angle=(degre: Float) `{
692 gtk_label_set_angle(self, degre);
693 `}
694
695 # Returns the angle of rotation for the label.
696 fun angle: Float `{
697 return gtk_label_get_angle(self);
698 `}
699
700 # Set simple formatted text content from a `format` string and the `content` which is escaped
701 #
702 # ~~~nitish
703 # GtkLabel lbl = new GtkLabel("Non-formatted text")
704 # lbl.set_markup("<span style=\"italic\">\%s</span>".to_cstring,
705 # "Italic content")
706 # ~~~
707 fun set_markup(format, content: CString) `{
708 char *formatted = g_markup_printf_escaped(format, content);
709 gtk_label_set_markup(self, formatted);
710 g_free(formatted);
711 `}
712
713 # Set justification of the lines in the label relative to each other
714 fun justify=(value: GtkJustification) `{ gtk_label_set_justify(self, value); `}
715
716 # Get justification of the lines in the label relative to each other
717 fun justify: GtkJustification `{ return gtk_label_get_justify(self); `}
718 end
719
720 # A widget displaying an image
721 # See: https://developer.gnome.org/gtk3/3.2/GtkImage.html
722 extern class GtkImage `{GtkImage *`}
723 super GtkMisc
724
725 # Create a GtkImage
726 new `{
727 return (GtkImage*)gtk_image_new();
728 `}
729
730 # Create a GtkImage with text
731 new file(filename: String) import String.to_cstring `{
732 return (GtkImage*)gtk_image_new_from_file(String_to_cstring(filename));
733 `}
734
735 fun pixel_size: Int `{
736 return gtk_image_get_pixel_size(self);
737 `}
738
739 fun pixel_size=(size: Int) `{
740 gtk_image_set_pixel_size(self, size);
741 `}
742
743 fun clear `{
744 gtk_image_clear(self);
745 `}
746 end
747
748 # enum GtkImageType
749 # Describes the image data representation used by a GtkImage.
750 # See: https://developer.gnome.org/gtk3/3.2/GtkImage.html#GtkImageType
751 extern class GtkImageType `{GtkImageType`}
752 # There is no image displayed by the widget.
753 new empty `{ return GTK_IMAGE_EMPTY; `}
754
755 # The widget contains a GdkPixbuf.
756 new pixbuf `{ return GTK_IMAGE_PIXBUF; `}
757
758 # The widget contains a stock icon name.
759 new stock `{ return GTK_IMAGE_STOCK; `}
760
761 # The widget contains a GtkIconSet.
762 new icon_set `{ return GTK_IMAGE_ICON_SET; `}
763
764 # The widget contains a GdkPixbufAnimation.
765 new animation `{ return GTK_IMAGE_ANIMATION; `}
766
767 # The widget contains a named icon.
768 new icon_name `{ return GTK_IMAGE_ICON_NAME; `}
769
770 # The widget contains a GIcon.
771 new gicon `{ return GTK_IMAGE_GICON; `}
772 end
773
774 # Displays an arrow
775 # See: https://developer.gnome.org/gtk3/3.2/GtkArrow.html
776 extern class GtkArrow `{GtkArrow *`}
777 super GtkMisc
778
779 new (arrow_type: GtkArrowType, shadow_type: GtkShadowType) `{
780 return (GtkArrow *)gtk_arrow_new(arrow_type, shadow_type);
781 `}
782
783 fun set(arrow_type: GtkArrowType, shadow_type: GtkShadowType) `{
784 gtk_arrow_set(self, arrow_type, shadow_type);
785 `}
786 end
787
788 # A widget that emits a signal when clicked on
789 # See: https://developer.gnome.org/gtk3/stable/GtkButton.html
790 extern class GtkButton `{GtkButton *`}
791 super GtkBin
792
793 new `{
794 return (GtkButton *)gtk_button_new();
795 `}
796
797 # Create a GtkButton with text
798 new with_label(text: String) import String.to_cstring `{
799 return (GtkButton *)gtk_button_new_with_label(String_to_cstring(text));
800 `}
801
802 new from_stock(stock_id: String) import String.to_cstring `{
803 return (GtkButton *)gtk_button_new_from_stock(String_to_cstring(stock_id));
804 `}
805
806 fun text: String import CString.to_s_with_copy `{
807 return CString_to_s_with_copy((char *)gtk_button_get_label(self));
808 `}
809
810 fun text=(value: String) import String.to_cstring `{
811 gtk_button_set_label(self, String_to_cstring(value));
812 `}
813
814 fun on_click(to_call: GtkCallable, user_data: nullable Object) do
815 signal_connect("clicked", to_call, user_data)
816 end
817
818 # Set the image of button to the given widget
819 fun image=(image: GtkWidget) `{
820 gtk_button_set_image(self, image);
821 `}
822
823 # Get the widget that is currenty set as the image of button
824 fun image: GtkWidget `{
825 return gtk_button_get_image(self);
826 `}
827 end
828
829 # A button which pops up a scale
830 # See: https://developer.gnome.org/gtk3/stable/GtkScaleButton.html
831 extern class GtkScaleButton `{GtkScaleButton *`}
832 super GtkButton
833
834 # const gchar **icons
835 new(size: GtkIconSize, min: Float, max: Float, step: Float) `{
836 return (GtkScaleButton *)gtk_scale_button_new(size, min, max, step, (const char **)0);
837 `}
838 end
839
840 # Create buttons bound to a URL
841 # See: https://developer.gnome.org/gtk3/stable/GtkLinkButton.html
842 extern class GtkLinkButton `{GtkLinkButton *`}
843 super GtkButton
844
845 new(uri: String) import String.to_cstring `{
846 return (GtkLinkButton *)gtk_link_button_new(String_to_cstring(uri));
847 `}
848 end
849
850 # A container which can hide its child
851 # https://developer.gnome.org/gtk3/stable/GtkExpander.html
852 extern class GtkExpander `{GtkExpander *`}
853 super GtkBin
854
855 new(lbl: String) import String.to_cstring `{
856 return (GtkExpander *)gtk_expander_new(String_to_cstring(lbl));
857 `}
858
859 new with_mnemonic(lbl: String) import String.to_cstring `{
860 return (GtkExpander *)gtk_expander_new_with_mnemonic(String_to_cstring(lbl));
861 `}
862
863 fun expanded: Bool `{
864 return gtk_expander_get_expanded(self);
865 `}
866
867 fun expanded=(is_expanded: Bool) `{
868 gtk_expander_set_expanded(self, is_expanded);
869 `}
870
871 fun spacing: Int `{
872 return gtk_expander_get_spacing(self);
873 `}
874
875 fun spacing=(pixels: Int) `{
876 gtk_expander_set_spacing(self, pixels);
877 `}
878
879 fun label_text: String import CString.to_s_with_copy `{
880 return CString_to_s_with_copy((char *)gtk_expander_get_label(self));
881 `}
882
883 fun label_text=(lbl: String) import String.to_cstring `{
884 gtk_expander_set_label(self, String_to_cstring(lbl));
885 `}
886
887 fun use_underline: Bool `{
888 return gtk_expander_get_use_underline(self);
889 `}
890
891 fun use_underline=(used: Bool) `{
892 gtk_expander_set_use_underline(self, used);
893 `}
894
895 fun use_markup: Bool `{
896 return gtk_expander_get_use_markup(self);
897 `}
898
899 fun use_markup=(used: Bool) `{
900 gtk_expander_set_use_markup(self, used);
901 `}
902
903 fun label_widget: GtkWidget `{
904 return gtk_expander_get_label_widget(self);
905 `}
906
907 fun label_widget=(widget: GtkWidget) `{
908 gtk_expander_set_label_widget(self, widget);
909 `}
910
911 fun label_fill: Bool `{
912 return gtk_expander_get_label_fill(self);
913 `}
914
915 fun label_fill=(fill: Bool) `{
916 gtk_expander_set_label_fill(self, fill);
917 `}
918
919 fun resize_toplevel: Bool `{
920 return gtk_expander_get_resize_toplevel(self);
921 `}
922
923 fun resize_toplevel=(resize: Bool) `{
924 gtk_expander_set_resize_toplevel(self, resize);
925 `}
926
927 end
928
929 # An abstract class for laying out GtkCellRenderers
930 # See: https://developer.gnome.org/gtk3/stable/GtkCellArea.html
931 extern class GtkComboBox `{GtkComboBox *`}
932 super GtkBin
933
934 new `{
935 return (GtkComboBox *)gtk_combo_box_new();
936 `}
937
938 new with_entry `{
939 return (GtkComboBox *)gtk_combo_box_new_with_entry();
940 `}
941
942 new with_model(model: GtkTreeModel) `{
943 return (GtkComboBox *)gtk_combo_box_new_with_model(model);
944 `}
945
946 new with_model_and_entry(model: GtkTreeModel) `{
947 return (GtkComboBox *)gtk_combo_box_new_with_model_and_entry(model);
948 `}
949
950 new with_area(area: GtkCellArea) `{
951 return (GtkComboBox *)gtk_combo_box_new_with_area(area);
952 `}
953
954 new with_area_and_entry(area: GtkCellArea) `{
955 return (GtkComboBox *)gtk_combo_box_new_with_area_and_entry(area);
956 `}
957
958 fun wrap_width: Int `{
959 return gtk_combo_box_get_wrap_width(self);
960 `}
961
962 fun wrap_width=(width: Int) `{
963 gtk_combo_box_set_wrap_width(self, width);
964 `}
965
966 fun row_span_col: Int `{
967 return gtk_combo_box_get_row_span_column(self);
968 `}
969
970 fun row_span_col=(row_span: Int) `{
971 gtk_combo_box_set_row_span_column(self, row_span);
972 `}
973
974 fun col_span_col: Int `{
975 return gtk_combo_box_get_column_span_column(self);
976 `}
977
978 fun col_span_col=(col_span: Int) `{
979 gtk_combo_box_set_column_span_column(self, col_span);
980 `}
981
982 fun active_item: Int `{
983 return gtk_combo_box_get_active(self);
984 `}
985
986 fun active_item=(active: Int) `{
987 gtk_combo_box_set_active(self, active);
988 `}
989
990 fun column_id: Int `{
991 return gtk_combo_box_get_id_column(self);
992 `}
993
994 fun column_id=(id_column: Int) `{
995 gtk_combo_box_set_id_column(self, id_column);
996 `}
997
998 fun active_id: String import CString.to_s_with_copy `{
999 return CString_to_s_with_copy((char *)gtk_combo_box_get_active_id(self));
1000 `}
1001
1002 fun active_id=(id_active: String) import String.to_cstring `{
1003 gtk_combo_box_set_active_id(self, String_to_cstring(id_active));
1004 `}
1005
1006 fun model: GtkTreeModel `{
1007 return gtk_combo_box_get_model(self);
1008 `}
1009
1010 fun model=(model: GtkTreeModel) `{
1011 gtk_combo_box_set_model(self, model);
1012 `}
1013
1014 fun popup `{
1015 gtk_combo_box_popup(self);
1016 `}
1017
1018 fun popdown `{
1019 gtk_combo_box_popdown(self);
1020 `}
1021
1022 fun title: String import CString.to_s_with_copy `{
1023 return CString_to_s_with_copy((char *)gtk_combo_box_get_title(self));
1024 `}
1025
1026 fun title=(t: String) import String.to_cstring `{
1027 gtk_combo_box_set_title(self, String_to_cstring(t));
1028 `}
1029
1030 fun has_entry: Bool `{
1031 return gtk_combo_box_get_has_entry(self);
1032 `}
1033
1034 fun with_fixed: Bool `{
1035 return gtk_combo_box_get_popup_fixed_width(self);
1036 `}
1037
1038 fun with_fixed=(fixed: Bool) `{
1039 gtk_combo_box_set_popup_fixed_width(self, fixed);
1040 `}
1041 end
1042
1043 # Show a spinner animation
1044 # See: https://developer.gnome.org/gtk3/3.2/GtkSpinner.html
1045 extern class GtkSpinner `{GtkSpinner *`}
1046 super GtkWidget
1047
1048 new `{
1049 return (GtkSpinner *)gtk_spinner_new();
1050 `}
1051
1052 fun start `{
1053 return gtk_spinner_start(self);
1054 `}
1055
1056 fun stop `{
1057 return gtk_spinner_stop(self);
1058 `}
1059 end
1060
1061 # A "light switch" style toggle
1062 # See: https://developer.gnome.org/gtk3/3.2/GtkSwitch.html
1063 extern class GtkSwitch `{GtkSwitch *`}
1064 super GtkWidget
1065
1066 new `{
1067 return (GtkSwitch *)gtk_switch_new();
1068 `}
1069
1070 fun active: Bool `{
1071 return gtk_switch_get_active(self);
1072 `}
1073
1074 fun active=(is_active: Bool) `{
1075 return gtk_switch_set_active(self, is_active);
1076 `}
1077 end
1078
1079 # A widget which controls the alignment and size of its child
1080 # https://developer.gnome.org/gtk3/stable/GtkAlignment.html
1081 extern class GtkAlignment `{GtkAlignment *`}
1082 super GtkBin
1083
1084 new (xalign: Float, yalign: Float, xscale: Float, yscale: Float) `{
1085 return (GtkAlignment *)gtk_alignment_new(xalign, yalign, xscale, yscale);
1086 `}
1087
1088 fun set (xalign: Float, yalign: Float, xscale: Float, yscale: Float) `{
1089 gtk_alignment_set(self, xalign, yalign, xscale, yscale);
1090 `}
1091
1092 end
1093
1094 # A representation of an adjustable bounded value
1095 # See: https://developer.gnome.org/gtk3/stable/GtkAdjustment.html#GtkAdjustment.description
1096 extern class GtkAdjustment `{GtkAdjustment *`}
1097 end
1098
1099 extern class GdkColor `{GdkColor*`}
1100 new (color_name: String) import String.to_cstring `{
1101 GdkColor *color = malloc(sizeof(GdkColor));
1102 gdk_color_parse(String_to_cstring(color_name), color);
1103 return color;
1104 `}
1105 end
1106
1107 extern class GdkRGBA `{GdkRGBA*`}
1108 end