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