1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2011-2013 Alexis Laferrière <alexis.laf@xymus.net>
4 # Copyright 2013 Nathan Heu <heu.nathan@courrier.uqam.ca>
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
10 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 # Classes and services to use libGTK widgets
21 cflags
"-Wno-deprecated-declarations"
32 /* callback user data */
35 nullable_Object user_data;
38 void nit_gtk_callback_func(GtkWidget *widget, gpointer callback_data) {
40 data = (NitGtkSignal*)callback_data;
41 GtkCallable_signal(data->to_call, widget, data->user_data);
45 # Initialize the GTK system
46 fun gtk_init
`{ gtk_init(0, NULL); `}
48 # Hand over control to the GTK event loop
49 fun gtk_main `{ gtk_main(); `}
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(); `}
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); `}
57 # Quit the GTK event loop and clean up the system
58 fun gtk_main_quit
`{ gtk_main_quit(); `}
61 # return true to stop event processing, false to let it propagate
62 fun signal(sender: GtkWidget, user_data: nullable Object) is abstract
65 extern class GdkEvent `{GdkEvent *`}
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); `}
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));
76 GtkCallable_incr_ref(to_call);
77 Object_incr_ref(user_data);
79 data->to_call = to_call;
80 data->user_data = user_data;
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),
89 redef fun ==(o
) do return o
isa GtkWidget and equal_to_gtk_widget
(o
)
91 private fun equal_to_gtk_widget
(o
: GtkWidget): Bool `{
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);
100 fun bg_color
=(state
: GtkStateType, color
: GdkRGBA) `{
101 gtk_widget_override_background_color(self, state, color);
104 # with gtk it's possible to set fg_color to all widget: is it correct? is fg color inherited?
106 fun fg_color
=(state
: GtkStateType, color
: GdkRGBA) `{
107 gtk_widget_override_color(self, state, color);
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);
116 # return the sensitivity of the widget
117 fun sensitive
: Bool `{
118 return gtk_widget_get_sensitive(self);
121 # Set the visibility of the widget
122 fun visible
=(visible
: Bool) `{
123 gtk_widget_set_visible(self, visible);
126 # Get the visibility of the widget only
127 fun visible_self
: Bool `{
128 return gtk_widget_get_visible(self);
132 fun destroy
`{ gtk_widget_destroy(self); `}
134 # Show the widget on screen
136 # See: `show_all
` to recursively show this widget and contained widgets.
137 fun show `{ gtk_widget_show(self); `}
139 # Hide the widget (reverse the effects of `show`)
140 fun hide
`{ gtk_widget_hide(self); `}
142 # Vertical alignement of this widget
143 fun valign=(value: GtkAlign) `{ gtk_widget_set_valign(self, value); `}
145 # Horizontal alignement of this widget
146 fun halign
=(value
: GtkAlign) `{ gtk_widget_set_halign(self, value); `}
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; `}
158 # Base class for widgets which contain other widgets
159 # See: https://developer.gnome.org/gtk3/stable/GtkContainer.html
160 extern class GtkContainer `{GtkContainer *`}
163 # Add a widget to the container
164 fun add
(widget
: GtkWidget) `{
165 gtk_container_add(self, widget);
168 # Remove the widget from the container
169 fun remove
(widget
: GtkWidget) `{
170 gtk_container_remove(self, widget);
173 # Get the resize mode of the container
174 fun resize_mode
: GtkResizeMode `{
175 return gtk_container_get_resize_mode(self);
178 # Set the resize mode of the container
179 fun resize_mode
=(resize_mode
: GtkResizeMode) `{
180 gtk_container_set_resize_mode(self, resize_mode);
184 # A container with just one child
185 # See: https://developer.gnome.org/gtk3/stable/GtkBin.html
186 extern class GtkBin `{GtkBin *`}
189 fun child: GtkWidget `{
190 return gtk_bin_get_child
(self);
194 # Toplevel which can contain other widgets
195 # See: https://developer.gnome.org/gtk3/stable/GtkWindow.html
196 extern class GtkWindow `{GtkWindow *`}
199 new (typ
: GtkWindowType) `{
200 return (GtkWindow *)gtk_window_new(typ);
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);
208 fun title
=(title
: String) import String.to_cstring
`{
209 gtk_window_set_title(self, String_to_cstring(title));
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)
215 signal_connect
("destroy", to_call
, user_data
)
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);
223 fun resizable
: Bool `{
224 return gtk_window_get_resizable(self);
227 fun resizable
=(is_resizable
: Bool) `{
228 return gtk_window_set_resizable(self, is_resizable);
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);
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);
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);
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);
256 fun gravity
: GdkGravity `{
257 return gtk_window_get_gravity(self);
260 fun gravity
=(window_grav
: GdkGravity) `{
261 gtk_window_set_gravity(self, window_grav);
264 # fun position: GtkWindowPosition `{
265 # return gtk_window_get_position(self);
268 # fun position=(window_pos: GtkWindowPosition) `{
269 # gtk_window_set_position(self, window_pos);
273 return gtk_window_is_active(self);
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);
281 fun get_focus
: GtkWidget `{
282 return gtk_window_get_focus(self);
285 fun set_focus
(widget
: GtkWidget) `{
286 return gtk_window_set_focus(self, widget);
289 fun get_default_widget
: GtkWidget `{
290 return gtk_window_get_default_widget(self);
293 fun set_default_widget
(widget
: GtkWidget) `{
294 return gtk_window_set_default(self, widget);
298 return gtk_window_maximize(self);
302 return gtk_window_unmaximize(self);
306 return gtk_window_fullscreen(self);
310 return gtk_window_unfullscreen(self);
313 fun keep_above
=(setting
: Bool) `{
314 gtk_window_set_keep_above(self, setting);
317 fun keep_below
=(setting
: Bool) `{
318 gtk_window_set_keep_below(self, setting);
321 # Try to convince the window manage to decorate or not this window
322 fun decorated
=(setting
: Bool) `{ gtk_window_set_decorated(self, setting); `}
325 # A bin with a decorative frame and optional label
326 # https://developer.gnome.org/gtk3/stable/GtkFrame.html
327 extern class GtkFrame `{GtkFrame *`}
330 new (lbl
: String) import String.to_cstring
`{
331 return (GtkFrame *)gtk_frame_new(String_to_cstring(lbl));
334 fun frame_label
: String import CString.to_s_with_copy
`{
335 return CString_to_s_with_copy((char *)gtk_frame_get_label(self));
338 fun frame_label
=(lbl
: String) import String.to_cstring
`{
339 gtk_frame_set_label(self, String_to_cstring(lbl));
342 fun label_widget
: GtkWidget `{
343 return gtk_frame_get_label_widget(self);
346 fun label_widget
=(widget
: GtkWidget) `{
347 gtk_frame_set_label_widget(self, widget);
350 fun shadow_type
: GtkShadowType `{
351 return gtk_frame_get_shadow_type(self);
354 fun shadow_type
=(stype
: GtkShadowType) `{
355 gtk_frame_set_shadow_type(self, stype);
358 fun label_align
=(xalign
: Float, yalign
: Float) `{
359 gtk_frame_set_label_align(self, xalign, yalign);
363 # Pack widgets in a rows and columns
364 # See: https://developer.gnome.org/gtk3/3.3/GtkGrid.html
365 extern class GtkGrid `{GtkGrid *`}
370 return (GtkGrid*)gtk_grid_new
();
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
);
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
);
383 # Insert a row at the specified position
384 fun insert_row(position:Int) `{
385 gtk_grid_insert_row
(self, position
);
388 # Insert a column at the specified position
389 fun insert_column(position: Int) `{
390 gtk_grid_insert_column
(self, position
);
394 # A widget that can switch orientation
395 extern class GtkOrientable `{GtkOrientable *`}
398 # Get the orientation of this widget
399 fun orientation
: GtkOrientation `{
400 return gtk_orientable_get_orientation(self);
403 # Set the orientation of this widget
404 fun orientation
=(orientation
: GtkOrientation) `{
405 gtk_orientable_set_orientation(self, orientation);
411 # See: https://developer.gnome.org/gtk3/3.4/GtkBox.html
412 extern class GtkBox `{ GtkBox * `}
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
);
421 # Give the children of `self` equal space in the box?
422 fun homogeneous: Bool `{ return gtk_box_get_homogeneous(self); `}
424 # Give the children of `self` equal space in the box?
425 fun homogeneous
=(homogeneous
: Bool) `{
426 gtk_box_set_homogeneous(self, homogeneous);
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);
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);
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);
445 # The tree interface used by GtkTreeView
446 # See: https://developer.gnome.org/gtk3/stable/GtkTreeModel.html
447 extern class GtkTreeModel `{GtkTreeModel *`}
450 # An abstract class for laying out GtkCellRenderers
451 # See: https://developer.gnome.org/gtk3/stable/GtkCellArea.html
452 extern class GtkCellArea `{GtkCellArea *`}
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 *`}
460 fun set_alignment(x, y: Float) `{
461 gtk_misc_set_alignment
(self, x
, y
);
464 fun set_padding(x, y: Float) `{
465 gtk_misc_set_padding
(self, x
, y
);
469 # A single line text entry field
470 # See: https://developer.gnome.org/gtk3/3.2/GtkEntry.html
471 extern class GtkEntry `{GtkEntry *`}
475 return (GtkEntry *)gtk_entry_new();
478 fun text
: String import CString.to_s_with_copy
`{
479 return CString_to_s_with_copy((char *)gtk_entry_get_text(self));
482 fun text
=(value
: String) import String.to_cstring
`{
483 gtk_entry_set_text(self, String_to_cstring(value));
486 # Is the text visible or is it the invisible char (such as '*')?
487 fun visiblility
: Bool `{
488 return gtk_entry_get_visibility(self);
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);
497 fun max_length
: Int `{
498 return gtk_entry_get_max_length(self);
501 fun max_length
=(max
: Int) `{
502 gtk_entry_set_max_length(self, max);
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 *`}
511 # Gets the current position of the fill level indicator.
512 fun fill_level: Float `{
513 return gtk_range_get_fill_level
(self);
516 fun fill_level=(level: Float) `{
517 gtk_range_set_fill_level
(self, level
);
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);
525 fun restricted_to_fill_level=(restricted: Bool) `{
526 gtk_range_set_restrict_to_fill_level
(self, restricted
);
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);
534 fun show_fill_level=(is_displayed: Bool) `{
535 gtk_range_set_show_fill_level
(self, is_displayed
);
538 fun adjustment: GtkAdjustment `{
539 return gtk_range_get_adjustment
(self);
542 fun adjustment=(value: GtkAdjustment) `{
543 gtk_range_set_adjustment
(self, value
);
546 fun inverted: Bool `{
547 return gtk_range_get_inverted
(self);
550 fun inverted=(setting: Bool) `{
551 gtk_range_set_inverted
(self, setting
);
555 return gtk_range_get_value
(self);
558 fun value=(val: Float) `{
559 gtk_range_set_value
(self, val
);
562 fun set_increments(step: Float, page: Float) `{
563 gtk_range_set_increments
(self, step
, page
);
566 fun set_range(min: Float, max: Float) `{
567 gtk_range_set_range
(self, min
, max
);
570 fun round_digits: Int `{
571 return gtk_range_get_round_digits
(self);
574 fun round_digits=(nb: Int) `{
575 gtk_range_set_round_digits
(self, nb
);
578 fun size_fixed: Bool `{
579 return gtk_range_get_slider_size_fixed
(self);
582 fun size_fixed=(is_fixed: Bool) `{
583 return gtk_range_set_slider_size_fixed
(self, is_fixed
);
586 fun flippable: Bool `{
587 return gtk_range_get_flippable
(self);
590 fun min_size=(is_flippable: Bool) `{
591 return gtk_range_set_flippable
(self, is_flippable
);
594 fun min_slider_size: Int `{
595 return gtk_range_get_min_slider_size
(self);
598 fun min_slider_size=(size: Int) `{
599 return gtk_range_set_min_slider_size
(self, size
);
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 *`}
608 new (orientation
: GtkOrientation, adjustment
: GtkAdjustment) `{
609 return (GtkScale *)gtk_scale_new(orientation, adjustment);
612 new with_range
(orientation
: GtkOrientation, min
: Float, max
: Float, step
: Float) `{
613 return (GtkScale *)gtk_scale_new_with_range(orientation, min, max, step);
617 return gtk_scale_get_digits(self);
620 fun digits
=(nb_digits
: Int) `{
621 gtk_scale_set_digits(self, nb_digits);
624 fun draw_value
: Bool `{
625 return gtk_scale_get_draw_value(self);
628 fun draw_value
=(is_displayed
: Bool) `{
629 gtk_scale_set_draw_value(self, is_displayed);
632 fun value_position
: GtkPositionType `{
633 return gtk_scale_get_value_pos(self);
636 fun value_position
=(pos
: GtkPositionType) `{
637 gtk_scale_set_value_pos(self, pos);
640 fun has_origin
: Bool `{
641 return gtk_scale_get_has_origin(self);
644 fun has_origin
=(orig
: Bool) `{
645 gtk_scale_set_has_origin(self, orig);
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));
653 # Removes any marks that have been added with gtk_scale_add_mark().
655 gtk_scale_clear_marks(self);
660 # See: https://developer.gnome.org/gtk3/3.2/GtkScrollbar.html
661 extern class GtkScrollbar `{GtkScrollbar *`}
664 new (orientation: GtkOrientation, adjustment: GtkAdjustment) `{
665 return (GtkScrollbar *)gtk_scrollbar_new
(orientation
, adjustment
);
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 *`}
674 # Create a GtkLabel with text
675 new (text
: String) import String.to_cstring
`{
676 return (GtkLabel*)gtk_label_new(String_to_cstring(text));
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));
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));
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);
695 # Returns the angle of rotation for the label.
697 return gtk_label_get_angle(self);
700 # Set simple formatted text content from a `format` string and the `content` which is escaped
703 # GtkLabel lbl = new GtkLabel("Non-formatted text")
704 # lbl.set_markup("<span style=\"italic\">\%s</span>".to_cstring,
707 fun set_markup
(format
, content
: CString) `{
708 char *formatted = g_markup_printf_escaped(format, content);
709 gtk_label_set_markup(self, formatted);
713 # Set justification of the lines in the label relative to each other
714 fun justify
=(value
: GtkJustification) `{ gtk_label_set_justify(self, value); `}
716 # Get justification of the lines in the label relative to each other
717 fun justify: GtkJustification `{ return gtk_label_get_justify(self); `}
720 # A widget displaying an image
721 # See: https://developer.gnome.org/gtk3/3.2/GtkImage.html
722 extern class GtkImage `{GtkImage *`}
727 return (GtkImage*)gtk_image_new
();
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
));
735 fun pixel_size: Int `{
736 return gtk_image_get_pixel_size
(self);
739 fun pixel_size=(size: Int) `{
740 gtk_image_set_pixel_size
(self, size
);
744 gtk_image_clear
(self);
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; `}
755 # The widget contains a GdkPixbuf.
756 new pixbuf `{ return GTK_IMAGE_PIXBUF; `}
758 # The widget contains a stock icon name.
759 new stock
`{ return GTK_IMAGE_STOCK; `}
761 # The widget contains a GtkIconSet.
762 new icon_set `{ return GTK_IMAGE_ICON_SET; `}
764 # The widget contains a GdkPixbufAnimation.
765 new animation
`{ return GTK_IMAGE_ANIMATION; `}
767 # The widget contains a named icon.
768 new icon_name `{ return GTK_IMAGE_ICON_NAME; `}
770 # The widget contains a GIcon.
771 new gicon
`{ return GTK_IMAGE_GICON; `}
775 # See: https://developer.gnome.org/gtk3/3.2/GtkArrow.html
776 extern class GtkArrow `{GtkArrow *`}
779 new (arrow_type
: GtkArrowType, shadow_type
: GtkShadowType) `{
780 return (GtkArrow *)gtk_arrow_new(arrow_type, shadow_type);
783 fun set
(arrow_type
: GtkArrowType, shadow_type
: GtkShadowType) `{
784 gtk_arrow_set(self, arrow_type, shadow_type);
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 *`}
794 return (GtkButton *)gtk_button_new
();
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
));
802 new from_stock(stock_id: String) import String.to_cstring `{
803 return (GtkButton *)gtk_button_new_from_stock
(String_to_cstring(stock_id
));
806 fun text: String import CString.to_s_with_copy `{
807 return CString_to_s_with_copy((char
*)gtk_button_get_label
(self));
810 fun text=(value: String) import String.to_cstring `{
811 gtk_button_set_label
(self, String_to_cstring(value
));
814 fun on_click(to_call: GtkCallable, user_data: nullable Object) do
815 signal_connect("clicked", to_call, user_data)
818 # Set the image of button to the given widget
819 fun image=(image: GtkWidget) `{
820 gtk_button_set_image
(self, image
);
823 # Get the widget that is currenty set as the image of button
824 fun image: GtkWidget `{
825 return gtk_button_get_image
(self);
829 # A button which pops up a scale
830 # See: https://developer.gnome.org/gtk3/stable/GtkScaleButton.html
831 extern class GtkScaleButton `{GtkScaleButton *`}
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);
840 # Create buttons bound to a URL
841 # See: https://developer.gnome.org/gtk3/stable/GtkLinkButton.html
842 extern class GtkLinkButton `{GtkLinkButton *`}
845 new(uri: String) import String.to_cstring `{
846 return (GtkLinkButton *)gtk_link_button_new
(String_to_cstring(uri
));
850 # A container which can hide its child
851 # https://developer.gnome.org/gtk3/stable/GtkExpander.html
852 extern class GtkExpander `{GtkExpander *`}
855 new(lbl
: String) import String.to_cstring
`{
856 return (GtkExpander *)gtk_expander_new(String_to_cstring(lbl));
859 new with_mnemonic
(lbl
: String) import String.to_cstring
`{
860 return (GtkExpander *)gtk_expander_new_with_mnemonic(String_to_cstring(lbl));
863 fun expanded
: Bool `{
864 return gtk_expander_get_expanded(self);
867 fun expanded
=(is_expanded
: Bool) `{
868 gtk_expander_set_expanded(self, is_expanded);
872 return gtk_expander_get_spacing(self);
875 fun spacing
=(pixels
: Int) `{
876 gtk_expander_set_spacing(self, pixels);
879 fun label_text
: String import CString.to_s_with_copy
`{
880 return CString_to_s_with_copy((char *)gtk_expander_get_label(self));
883 fun label_text
=(lbl
: String) import String.to_cstring
`{
884 gtk_expander_set_label(self, String_to_cstring(lbl));
887 fun use_underline
: Bool `{
888 return gtk_expander_get_use_underline(self);
891 fun use_underline
=(used
: Bool) `{
892 gtk_expander_set_use_underline(self, used);
895 fun use_markup
: Bool `{
896 return gtk_expander_get_use_markup(self);
899 fun use_markup
=(used
: Bool) `{
900 gtk_expander_set_use_markup(self, used);
903 fun label_widget
: GtkWidget `{
904 return gtk_expander_get_label_widget(self);
907 fun label_widget
=(widget
: GtkWidget) `{
908 gtk_expander_set_label_widget(self, widget);
911 fun label_fill
: Bool `{
912 return gtk_expander_get_label_fill(self);
915 fun label_fill
=(fill
: Bool) `{
916 gtk_expander_set_label_fill(self, fill);
919 fun resize_toplevel
: Bool `{
920 return gtk_expander_get_resize_toplevel(self);
923 fun resize_toplevel
=(resize
: Bool) `{
924 gtk_expander_set_resize_toplevel(self, resize);
929 # An abstract class for laying out GtkCellRenderers
930 # See: https://developer.gnome.org/gtk3/stable/GtkCellArea.html
931 extern class GtkComboBox `{GtkComboBox *`}
935 return (GtkComboBox *)gtk_combo_box_new
();
939 return (GtkComboBox *)gtk_combo_box_new_with_entry
();
942 new with_model(model: GtkTreeModel) `{
943 return (GtkComboBox *)gtk_combo_box_new_with_model
(model
);
946 new with_model_and_entry(model: GtkTreeModel) `{
947 return (GtkComboBox *)gtk_combo_box_new_with_model_and_entry
(model
);
950 new with_area(area: GtkCellArea) `{
951 return (GtkComboBox *)gtk_combo_box_new_with_area
(area
);
954 new with_area_and_entry(area: GtkCellArea) `{
955 return (GtkComboBox *)gtk_combo_box_new_with_area_and_entry
(area
);
958 fun wrap_width: Int `{
959 return gtk_combo_box_get_wrap_width
(self);
962 fun wrap_width=(width: Int) `{
963 gtk_combo_box_set_wrap_width
(self, width
);
966 fun row_span_col: Int `{
967 return gtk_combo_box_get_row_span_column
(self);
970 fun row_span_col=(row_span: Int) `{
971 gtk_combo_box_set_row_span_column
(self, row_span
);
974 fun col_span_col: Int `{
975 return gtk_combo_box_get_column_span_column
(self);
978 fun col_span_col=(col_span: Int) `{
979 gtk_combo_box_set_column_span_column
(self, col_span
);
982 fun active_item: Int `{
983 return gtk_combo_box_get_active
(self);
986 fun active_item=(active: Int) `{
987 gtk_combo_box_set_active
(self, active
);
990 fun column_id: Int `{
991 return gtk_combo_box_get_id_column
(self);
994 fun column_id=(id_column: Int) `{
995 gtk_combo_box_set_id_column
(self, id_column
);
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));
1002 fun active_id=(id_active: String) import String.to_cstring `{
1003 gtk_combo_box_set_active_id
(self, String_to_cstring(id_active
));
1006 fun model: GtkTreeModel `{
1007 return gtk_combo_box_get_model
(self);
1010 fun model=(model: GtkTreeModel) `{
1011 gtk_combo_box_set_model
(self, model
);
1015 gtk_combo_box_popup
(self);
1019 gtk_combo_box_popdown
(self);
1022 fun title: String import CString.to_s_with_copy `{
1023 return CString_to_s_with_copy((char
*)gtk_combo_box_get_title
(self));
1026 fun title=(t: String) import String.to_cstring `{
1027 gtk_combo_box_set_title
(self, String_to_cstring(t
));
1030 fun has_entry: Bool `{
1031 return gtk_combo_box_get_has_entry
(self);
1034 fun with_fixed: Bool `{
1035 return gtk_combo_box_get_popup_fixed_width
(self);
1038 fun with_fixed=(fixed: Bool) `{
1039 gtk_combo_box_set_popup_fixed_width
(self, fixed
);
1043 # Show a spinner animation
1044 # See: https://developer.gnome.org/gtk3/3.2/GtkSpinner.html
1045 extern class GtkSpinner `{GtkSpinner *`}
1049 return (GtkSpinner *)gtk_spinner_new();
1053 return gtk_spinner_start(self);
1057 return gtk_spinner_stop(self);
1061 # A "light switch" style toggle
1062 # See: https://developer.gnome.org/gtk3/3.2/GtkSwitch.html
1063 extern class GtkSwitch `{GtkSwitch *`}
1067 return (GtkSwitch *)gtk_switch_new
();
1071 return gtk_switch_get_active
(self);
1074 fun active=(is_active: Bool) `{
1075 return gtk_switch_set_active
(self, is_active
);
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 *`}
1084 new (xalign
: Float, yalign
: Float, xscale
: Float, yscale
: Float) `{
1085 return (GtkAlignment *)gtk_alignment_new(xalign, yalign, xscale, yscale);
1088 fun set
(xalign
: Float, yalign
: Float, xscale
: Float, yscale
: Float) `{
1089 gtk_alignment_set(self, xalign, yalign, xscale, yscale);
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 *`}
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);
1107 extern class GdkRGBA `{GdkRGBA*`}