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