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