cee996c9bbfaf0072e0d55ed40758015ec3277cf
[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 # A container box
352 #
353 # @https://developer.gnome.org/gtk3/3.4/GtkBox.html
354 extern class GtkBox `{ GtkBox * `}
355 super GtkContainer
356 end
357
358 #The tree interface used by GtkTreeView
359 #@https://developer.gnome.org/gtk3/stable/GtkTreeModel.html
360 extern class GtkTreeModel `{GtkTreeModel *`}
361 end
362
363 #An abstract class for laying out GtkCellRenderers
364 #@https://developer.gnome.org/gtk3/stable/GtkCellArea.html
365 extern class GtkCellArea `{GtkCellArea *`}
366 end
367
368 #Base class for widgets with alignments and padding
369 #@https://developer.gnome.org/gtk3/3.2/GtkMisc.html
370 extern class GtkMisc `{GtkMisc *`}
371 super GtkWidget
372
373 fun alignment : GtkAlignment is abstract
374
375 fun alignment=( x : Float, y : Float ) is extern `{
376 gtk_misc_set_alignment( recv, x, y );
377 `}
378
379 fun padding : GtkAlignment is abstract
380
381 fun padding=( x : Float, y : Float ) is extern `{
382 gtk_misc_set_padding( recv, x, y );
383 `}
384
385 end
386
387 #A single line text entry field
388 #@https://developer.gnome.org/gtk3/3.2/GtkEntry.html
389 extern class GtkEntry `{GtkEntry *`}
390 super GtkWidget
391
392 new is extern `{
393 return (GtkEntry *)gtk_entry_new();
394 `}
395
396 fun text : String is extern import String.to_cstring`{
397 return NativeString_to_s( (char *)gtk_entry_get_text( recv ) );
398 `}
399
400 fun text=( value : String) is extern import String.to_cstring`{
401 gtk_entry_set_text( recv, String_to_cstring( value ) );
402 `}
403
404 # Is the text visible or is it the invisible char (such as '*')?
405 fun visiblility: Bool is extern `{
406 return gtk_entry_get_visibility( recv );
407 `}
408
409 # Set the text visiblility
410 # If false, will use the invisible char (such as '*')
411 fun visibility=( is_visible : Bool) is extern `{
412 gtk_entry_set_visibility( recv, is_visible );
413 `}
414
415 fun max_length : Int is extern `{
416 return gtk_entry_get_max_length( recv );
417 `}
418
419 fun max_length=( max : Int) is extern `{
420 gtk_entry_set_max_length( recv, max );
421 `}
422 end
423
424 #Base class for widgets which visualize an adjustment
425 #@https://developer.gnome.org/gtk3/3.2/GtkRange.html
426 extern class GtkRange `{GtkRange *`}
427 super GtkWidget
428
429 #Gets the current position of the fill level indicator.
430 fun fill_level : Float is extern `{
431 return gtk_range_get_fill_level( recv );
432 `}
433
434 fun fill_level=( level : Float ) is extern `{
435 gtk_range_set_fill_level( recv, level );
436 `}
437
438 #Gets whether the range is restricted to the fill level.
439 fun restricted_to_fill_level : Bool is extern `{
440 return gtk_range_get_restrict_to_fill_level( recv );
441 `}
442
443 fun restricted_to_fill_level=( restricted : Bool ) is extern `{
444 gtk_range_set_restrict_to_fill_level( recv, restricted );
445 `}
446
447 #Gets whether the range displays the fill level graphically.
448 fun show_fill_level : Bool is extern `{
449 return gtk_range_get_show_fill_level( recv );
450 `}
451
452 fun show_fill_level=( is_displayed : Bool ) is extern `{
453 gtk_range_set_show_fill_level( recv, is_displayed );
454 `}
455
456 fun adjustment : GtkAdjustment is extern `{
457 return gtk_range_get_adjustment( recv );
458 `}
459
460 fun adjustment=( value : GtkAdjustment ) is extern `{
461 gtk_range_set_adjustment( recv, value );
462 `}
463
464 fun inverted : Bool is extern `{
465 return gtk_range_get_inverted( recv );
466 `}
467
468 fun inverted=( setting : Bool ) is extern `{
469 gtk_range_set_inverted( recv, setting );
470 `}
471
472 fun value : Float is extern `{
473 return gtk_range_get_value( recv );
474 `}
475
476 fun value=( val : Float ) is extern `{
477 gtk_range_set_value( recv, val );
478 `}
479
480 fun set_increments( step : Float, page : Float ) is extern `{
481 gtk_range_set_increments( recv, step, page );
482 `}
483
484 fun set_range( min : Float, max : Float ) is extern `{
485 gtk_range_set_range( recv, min, max );
486 `}
487
488 fun round_digits : Int is extern `{
489 return gtk_range_get_round_digits( recv );
490 `}
491
492 fun round_digits=( nb : Int ) is extern `{
493 gtk_range_set_round_digits( recv, nb );
494 `}
495
496 fun size_fixed : Bool is extern `{
497 return gtk_range_get_slider_size_fixed( recv );
498 `}
499
500 fun size_fixed=( is_fixed : Bool ) is extern `{
501 return gtk_range_set_slider_size_fixed( recv, is_fixed );
502 `}
503
504 fun flippable : Bool is extern `{
505 return gtk_range_get_flippable( recv );
506 `}
507
508 fun min_size=( is_flippable : Bool ) is extern `{
509 return gtk_range_set_flippable( recv, is_flippable );
510 `}
511
512 fun min_slider_size : Int is extern `{
513 return gtk_range_get_min_slider_size( recv );
514 `}
515
516 fun min_slider_size=( size : Int ) is extern `{
517 return gtk_range_set_min_slider_size( recv, size );
518 `}
519 end
520
521 #A slider widget for selecting a value from a range
522 #@https://developer.gnome.org/gtk3/3.2/GtkScale.html
523 extern class GtkScale `{GtkScale *`}
524 super GtkRange
525
526 new ( orientation : GtkOrientation, adjustment : GtkAdjustment ) is extern `{
527 return (GtkScale *)gtk_scale_new( orientation, adjustment );
528 `}
529
530 new with_range ( orientation : GtkOrientation, min : Float, max : Float, step : Float ) is extern `{
531 return (GtkScale *)gtk_scale_new_with_range( orientation, min, max, step );
532 `}
533
534 fun digits : Int is extern `{
535 return gtk_scale_get_digits( recv );
536 `}
537
538 fun digits=( nb_digits : Int ) is extern `{
539 gtk_scale_set_digits( recv, nb_digits );
540 `}
541
542 fun draw_value : Bool is extern `{
543 return gtk_scale_get_draw_value( recv );
544 `}
545
546 fun draw_value=( is_displayed : Bool ) is extern `{
547 gtk_scale_set_draw_value( recv, is_displayed );
548 `}
549
550 fun value_position : GtkPositionType is extern `{
551 return gtk_scale_get_value_pos( recv );
552 `}
553
554 fun value_position=( pos : GtkPositionType ) is extern `{
555 gtk_scale_set_value_pos( recv, pos );
556 `}
557
558 fun has_origin : Bool is extern `{
559 return gtk_scale_get_has_origin( recv );
560 `}
561
562 fun has_origin=( orig : Bool ) is extern `{
563 gtk_scale_set_has_origin( recv, orig );
564 `}
565
566 fun add_mark( value : Float, position : GtkPositionType, markup : String ) is extern import String.to_cstring`{
567 gtk_scale_add_mark( recv, value, position, String_to_cstring( markup ) );
568 `}
569
570 #Removes any marks that have been added with gtk_scale_add_mark().
571 fun clear_marks is extern `{
572 gtk_scale_clear_marks( recv );
573 `}
574
575 #get layout
576 #get layout offsets
577
578 end
579
580 #A scrollbar
581 #@https://developer.gnome.org/gtk3/3.2/GtkScrollbar.html
582 extern class GtkScrollbar `{GtkScrollbar *`}
583 super GtkRange
584
585 new ( orientation : GtkOrientation, adjustment : GtkAdjustment ) is extern `{
586 return (GtkScrollbar *)gtk_scrollbar_new( orientation, adjustment );
587 `}
588 end
589
590 #A widget that displays a small to medium amount of text
591 #@https://developer.gnome.org/gtk3/3.2/GtkLabel.html
592 extern class GtkLabel `{GtkLabel *`}
593 super GtkMisc
594
595 # Create a GtkLabel with text
596 new ( text : String ) is extern import String.to_cstring `{
597 return (GtkLabel*)gtk_label_new( String_to_cstring( text ) );
598 `}
599
600 # Set the text of the label
601 fun text=( text : String ) import String.to_cstring `{
602 gtk_label_set_text( recv, String_to_cstring( text ) );
603 `}
604
605 # Returns the text of the label
606 fun text : String import NativeString.to_s `{
607 return NativeString_to_s( (char*)gtk_label_get_text( recv ) );
608 `}
609
610 # Sets the angle of rotation for the label.
611 # An angle of 90 reads from from bottom to top, an angle of 270, from top to bottom.
612 fun angle=( degre : Float ) `{
613 gtk_label_set_angle( recv, degre );
614 `}
615
616 # Returns the angle of rotation for the label.
617 fun angle : Float `{
618 return gtk_label_get_angle( recv );
619 `}
620
621 end
622
623 #A widget displaying an image
624 #@https://developer.gnome.org/gtk3/3.2/GtkImage.html
625 extern class GtkImage `{GtkImage *`}
626 super GtkMisc
627
628 # Create a GtkImage
629 new is extern `{
630 return (GtkImage*)gtk_image_new( );
631 `}
632
633 # Create a GtkImage with text
634 new file( filename : String ) is extern import String.to_cstring `{
635 return (GtkImage*)gtk_image_new_from_file( String_to_cstring( filename ) );
636 `}
637
638 fun pixel_size : Int is extern `{
639 return gtk_image_get_pixel_size( recv );
640 `}
641
642 fun pixel_size=( size : Int) is extern `{
643 gtk_image_set_pixel_size( recv, size );
644 `}
645
646 fun clear is extern `{
647 gtk_image_clear( recv );
648 `}
649 end
650
651 #enum GtkImageType
652 #Describes the image data representation used by a GtkImage.
653 #@https://developer.gnome.org/gtk3/3.2/GtkImage.html#GtkImageType
654 extern class GtkImageType `{GtkImageType`}
655 # There is no image displayed by the widget.
656 new empty `{ return GTK_IMAGE_EMPTY; `}
657
658 # The widget contains a GdkPixbuf.
659 new pixbuf `{ return GTK_IMAGE_PIXBUF; `}
660
661 # The widget contains a stock icon name.
662 new stock `{ return GTK_IMAGE_STOCK; `}
663
664 # The widget contains a GtkIconSet.
665 new icon_set `{ return GTK_IMAGE_ICON_SET; `}
666
667 # The widget contains a GdkPixbufAnimation.
668 new animation `{ return GTK_IMAGE_ANIMATION; `}
669
670 # The widget contains a named icon.
671 new icon_name `{ return GTK_IMAGE_ICON_NAME; `}
672
673 # The widget contains a GIcon.
674 new gicon `{ return GTK_IMAGE_GICON; `}
675 end
676
677 #Displays an arrow
678 #@https://developer.gnome.org/gtk3/3.2/GtkArrow.html
679 extern class GtkArrow `{GtkArrow *`}
680 super GtkMisc
681
682 new ( arrow_type : GtkArrowType, shadow_type : GtkShadowType ) is extern `{
683 return (GtkArrow *)gtk_arrow_new( arrow_type, shadow_type );
684 `}
685
686 fun set( arrow_type : GtkArrowType, shadow_type : GtkShadowType ) is extern `{
687 gtk_arrow_set( recv, arrow_type, shadow_type );
688 `}
689 end
690
691 #A widget that emits a signal when clicked on
692 #@https://developer.gnome.org/gtk3/stable/GtkButton.html
693 extern class GtkButton `{GtkButton *`}
694 super GtkBin
695
696 new is extern `{
697 return (GtkButton *)gtk_button_new( );
698 `}
699
700 #Create a GtkButton with text
701 new with_label( text : String ) is extern import String.to_cstring `{
702 return (GtkButton *)gtk_button_new_with_label( String_to_cstring( text ) );
703 `}
704
705 new from_stock( stock_id : String ) is extern import String.to_cstring `{
706 return (GtkButton *)gtk_button_new_from_stock( String_to_cstring( stock_id ) );
707 `}
708
709 fun text : String is extern `{
710 return NativeString_to_s( (char *)gtk_button_get_label( recv ) );
711 `}
712
713 fun text=( value : String ) is extern import String.to_cstring`{
714 gtk_button_set_label( recv, String_to_cstring( value ) );
715 `}
716
717 fun on_click( to_call : GtkCallable, user_data : nullable Object ) do
718 signal_connect( "clicked", to_call, user_data )
719 end
720
721 end
722
723 #A button which pops up a scale
724 #@https://developer.gnome.org/gtk3/stable/GtkScaleButton.html
725 extern class GtkScaleButton `{GtkScaleButton *`}
726 super GtkButton
727
728 #const gchar **icons
729 new( size: GtkIconSize, min: Float, max: Float, step: Float ) is extern `{
730 return (GtkScaleButton *)gtk_scale_button_new( size, min, max, step, (const char **)0 );
731 `}
732 end
733
734 #Create buttons bound to a URL
735 #@https://developer.gnome.org/gtk3/stable/GtkLinkButton.html
736 extern class GtkLinkButton `{GtkLinkButton *`}
737 super GtkButton
738
739 new( uri: String ) is extern import String.to_cstring `{
740 return (GtkLinkButton *)gtk_link_button_new( String_to_cstring(uri) );
741 `}
742 end
743
744 #A container which can hide its child
745 #https://developer.gnome.org/gtk3/stable/GtkExpander.html
746 extern class GtkExpander `{GtkExpander *`}
747 super GtkBin
748
749 new( lbl : String) is extern import String.to_cstring`{
750 return (GtkExpander *)gtk_expander_new( String_to_cstring( lbl ) );
751 `}
752
753 new with_mnemonic( lbl : String) is extern import String.to_cstring`{
754 return (GtkExpander *)gtk_expander_new_with_mnemonic(String_to_cstring( lbl ));
755 `}
756
757 fun expanded : Bool is extern `{
758 return gtk_expander_get_expanded( recv );
759 `}
760
761 fun expanded=( is_expanded : Bool ) is extern `{
762 gtk_expander_set_expanded( recv, is_expanded );
763 `}
764
765 fun spacing : Int is extern `{
766 return gtk_expander_get_spacing( recv );
767 `}
768
769 fun spacing=( pixels : Int ) is extern `{
770 gtk_expander_set_spacing( recv, pixels );
771 `}
772
773 fun label_text : String is extern `{
774 return NativeString_to_s( (char *)gtk_expander_get_label( recv ) );
775 `}
776
777 fun label_text=( lbl : String ) is extern import String.to_cstring`{
778 gtk_expander_set_label( recv, String_to_cstring( lbl ) );
779 `}
780
781 fun use_underline : Bool is extern `{
782 return gtk_expander_get_use_underline( recv );
783 `}
784
785 fun use_underline=( used : Bool) is extern `{
786 gtk_expander_set_use_underline( recv, used );
787 `}
788
789 fun use_markup : Bool is extern `{
790 return gtk_expander_get_use_markup( recv );
791 `}
792
793 fun use_markup=( used : Bool) is extern `{
794 gtk_expander_set_use_markup( recv, used );
795 `}
796
797 fun label_widget : GtkWidget is extern `{
798 return gtk_expander_get_label_widget( recv );
799 `}
800
801 fun label_widget=( widget : GtkWidget ) is extern `{
802 gtk_expander_set_label_widget( recv, widget );
803 `}
804
805 fun label_fill : Bool is extern `{
806 return gtk_expander_get_label_fill( recv );
807 `}
808
809 fun label_fill=( fill : Bool ) is extern `{
810 gtk_expander_set_label_fill( recv, fill );
811 `}
812
813 fun resize_toplevel : Bool is extern `{
814 return gtk_expander_get_resize_toplevel( recv );
815 `}
816
817 fun resize_toplevel=( resize : Bool ) is extern `{
818 gtk_expander_set_resize_toplevel( recv, resize );
819 `}
820
821 end
822
823 #An abstract class for laying out GtkCellRenderers
824 #@https://developer.gnome.org/gtk3/stable/GtkCellArea.html
825 extern class GtkComboBox `{GtkComboBox *`}
826 super GtkBin
827
828 new is extern `{
829 return (GtkComboBox *)gtk_combo_box_new( );
830 `}
831
832 new with_entry is extern `{
833 return (GtkComboBox *)gtk_combo_box_new_with_entry( );
834 `}
835
836 new with_model( model : GtkTreeModel ) is extern `{
837 return (GtkComboBox *)gtk_combo_box_new_with_model( model );
838 `}
839
840 new with_model_and_entry( model : GtkTreeModel ) is extern `{
841 return (GtkComboBox *)gtk_combo_box_new_with_model_and_entry( model );
842 `}
843
844 new with_area( area : GtkCellArea ) is extern `{
845 return (GtkComboBox *)gtk_combo_box_new_with_area( area );
846 `}
847
848 new with_area_and_entry( area : GtkCellArea ) is extern `{
849 return (GtkComboBox *)gtk_combo_box_new_with_area_and_entry( area );
850 `}
851
852 fun wrap_width : Int is extern `{
853 return gtk_combo_box_get_wrap_width( recv );
854 `}
855
856 fun wrap_width=( width : Int ) is extern `{
857 gtk_combo_box_set_wrap_width( recv, width );
858 `}
859
860 fun row_span_col : Int is extern `{
861 return gtk_combo_box_get_row_span_column( recv );
862 `}
863
864 fun row_span_col=( row_span : Int ) is extern `{
865 gtk_combo_box_set_row_span_column( recv, row_span );
866 `}
867
868 fun col_span_col : Int is extern `{
869 return gtk_combo_box_get_column_span_column( recv );
870 `}
871
872 fun col_span_col=( col_span : Int ) is extern `{
873 gtk_combo_box_set_column_span_column( recv, col_span );
874 `}
875
876 fun active_item : Int is extern `{
877 return gtk_combo_box_get_active( recv );
878 `}
879
880 fun active_item=( active : Int ) is extern `{
881 gtk_combo_box_set_active( recv, active );
882 `}
883
884 #fun active_iter : GtkTreeIter is extern `{
885 #`}
886 #
887 #fun active_iter=( active : Bool ) is extern `{
888 #`}
889
890 fun column_id : Int is extern `{
891 return gtk_combo_box_get_id_column( recv );
892 `}
893
894 fun column_id=( id_column : Int ) is extern `{
895 gtk_combo_box_set_id_column( recv, id_column );
896 `}
897
898 fun active_id : String is extern `{
899 return NativeString_to_s( (char *)gtk_combo_box_get_active_id( recv ) );
900 `}
901
902 fun active_id=( id_active : String ) is extern import String.to_cstring`{
903 gtk_combo_box_set_active_id( recv, String_to_cstring( id_active ) );
904 `}
905
906 fun model : GtkTreeModel is extern `{
907 return gtk_combo_box_get_model( recv );
908 `}
909
910 fun model=( model : GtkTreeModel ) is extern `{
911 gtk_combo_box_set_model( recv, model );
912 `}
913
914 fun popup is extern `{
915 gtk_combo_box_popup( recv );
916 `}
917
918 fun popdown is extern `{
919 gtk_combo_box_popdown( recv );
920 `}
921
922 fun title : String is extern`{
923 return NativeString_to_s( (char *)gtk_combo_box_get_title( recv ) );
924 `}
925
926 fun title=( t : String ) is extern import String.to_cstring `{
927 gtk_combo_box_set_title( recv, String_to_cstring( t ) );
928 `}
929
930 fun has_entry : Bool is extern `{
931 return gtk_combo_box_get_has_entry( recv );
932 `}
933
934 fun with_fixed : Bool is extern `{
935 return gtk_combo_box_get_popup_fixed_width( recv );
936 `}
937
938 fun with_fixed=( fixed : Bool ) is extern `{
939 gtk_combo_box_set_popup_fixed_width( recv, fixed );
940 `}
941 end
942
943 #Show a spinner animation
944 #@https://developer.gnome.org/gtk3/3.2/GtkSpinner.html
945 extern class GtkSpinner `{GtkSpinner *`}
946 super GtkWidget
947
948 new is extern `{
949 return (GtkSpinner *)gtk_spinner_new();
950 `}
951
952 fun start is extern `{
953 return gtk_spinner_start( recv );
954 `}
955
956 fun stop is extern `{
957 return gtk_spinner_stop( recv );
958 `}
959 end
960
961 #A "light switch" style toggle
962 #@https://developer.gnome.org/gtk3/3.2/GtkSwitch.html
963 extern class GtkSwitch `{GtkSwitch *`}
964 super GtkWidget
965
966 new is extern `{
967 return (GtkSwitch *)gtk_switch_new();
968 `}
969
970 fun active : Bool is extern `{
971 return gtk_switch_get_active( recv );
972 `}
973
974 fun active=( is_active : Bool ) is extern `{
975 return gtk_switch_set_active( recv, is_active );
976 `}
977 end
978
979
980 #A widget which controls the alignment and size of its child
981 #https://developer.gnome.org/gtk3/stable/GtkAlignment.html
982 extern class GtkAlignment `{GtkAlignment *`}
983 super GtkBin
984
985 new ( xalign : Float, yalign : Float, xscale : Float, yscale : Float ) is extern `{
986 return (GtkAlignment *)gtk_alignment_new( xalign, yalign, xscale, yscale );
987 `}
988
989 fun set ( xalign : Float, yalign : Float, xscale : Float, yscale : Float ) is extern `{
990 gtk_alignment_set( recv, xalign, yalign, xscale, yscale );
991 `}
992
993 #get_padding
994 #set_padding
995 end
996
997 #A representation of an adjustable bounded value
998 #@https://developer.gnome.org/gtk3/stable/GtkAdjustment.html#GtkAdjustment.description
999 extern class GtkAdjustment `{GtkAdjustment *`}
1000
1001 end
1002
1003 extern class GdkColor `{GdkColor*`}
1004 new is extern `{
1005 GdkColor * col = malloc(sizeof(GdkColor));
1006 /*gdk_color_parse( "red", recv );*/
1007 gdk_color_parse( "red", col);
1008 return col;
1009 `}
1010 end
1011
1012 extern class GdkRGBA `{GdkRGBA*`}
1013 new is extern `{
1014 `}
1015 end
1016