rename `NativeString` to `CString`
[nit.git] / lib / gtk / v3_4 / gtk_widgets_ext.nit
index 05d5ace..63cdb1e 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-module gtk_widgets_ext is pkgconfig("gtk+-3.0")
+module gtk_widgets_ext is pkgconfig "gtk+-3.0"
 
 import gtk_core
 
-#Displays a calendar and allows the user to select a date
-#@https://developer.gnome.org/gtk3/3.2/GtkCalendar.html
+# Displays a calendar and allows the user to select a date
+# See: https://developer.gnome.org/gtk3/3.2/GtkCalendar.html
 extern class GtkCalendar `{GtkCalendar *`}
        super GtkWidget
 
-       new is extern `{
+       new `{
                 return (GtkCalendar *)gtk_calendar_new();
        `}
 
-       fun month=( month : Int, year : Int ) is extern `{
-               gtk_calendar_select_month( recv, month, year );
+       fun month=(month: Int, year: Int) `{
+               gtk_calendar_select_month(self, month, year);
        `}
 
-       fun day=( day : Int ) is extern `{
-               gtk_calendar_select_day( recv, day );
+       fun day=(day: Int) `{
+               gtk_calendar_select_day(self, day);
        `}
 
-       fun mark_day( day : Int ) is extern `{
-               gtk_calendar_mark_day( recv, day );
+       fun mark_day(day: Int) `{
+               gtk_calendar_mark_day(self, day);
        `}
 
-       fun unmark_day( day : Int ) is extern `{
-               gtk_calendar_unmark_day( recv, day );
+       fun unmark_day(day: Int) `{
+               gtk_calendar_unmark_day(self, day);
        `}
 
-       fun is_marked( day : Int ): Bool is extern `{
-               return gtk_calendar_get_day_is_marked( recv, day );
+       fun is_marked(day: Int): Bool `{
+               return gtk_calendar_get_day_is_marked(self, day);
        `}
 
-   fun clear_marks is extern `{
-               gtk_calendar_clear_marks( recv );
+   fun clear_marks `{
+               gtk_calendar_clear_marks(self);
        `}
 
-       fun display_options : GtkCalendarDisplayOptions is extern `{
-               return gtk_calendar_get_display_options( recv );
+       fun display_options: GtkCalendarDisplayOptions `{
+               return gtk_calendar_get_display_options(self);
        `}
 
 
-       fun display_options=( options : GtkCalendarDisplayOptions) is extern `{
-               gtk_calendar_set_display_options( recv, options );
+       fun display_options=(options: GtkCalendarDisplayOptions) `{
+               gtk_calendar_set_display_options(self, options);
        `}
 
-       #date en nit...
+       # date en nit...
        fun date: String is abstract
 end
 
-#enum GtkCalendarDisplayOptions
-#@https://developer.gnome.org/gtk3/3.2/GtkCalendar.html#GtkCalendarDisplayOptions
+# enum GtkCalendarDisplayOptions
+# See: https://developer.gnome.org/gtk3/3.2/GtkCalendar.html#GtkCalendarDisplayOptions
 extern class GtkCalendarDisplayOptions `{GtkCalendarDisplayOptions`}
        new show_heading `{ return GTK_CALENDAR_SHOW_HEADING; `}
        new show_day_names `{ return GTK_CALENDAR_SHOW_DAY_NAMES; `}
@@ -75,68 +75,68 @@ extern class GtkCalendarDisplayOptions `{GtkCalendarDisplayOptions`}
        new show_details `{ return GTK_CALENDAR_SHOW_DETAILS; `}
 end
 
-#A separator widget
-#@https://developer.gnome.org/gtk3/stable/GtkSeparator.html
+# A separator widget
+# See: https://developer.gnome.org/gtk3/stable/GtkSeparator.html
 extern class GtkSeparator `{GtkSeparator *`}
        super GtkWidget
 
-       new ( orientation : GtkOrientation ) is extern `{
-                return (GtkSeparator *)gtk_separator_new( orientation );
+       new (orientation: GtkOrientation) `{
+                return (GtkSeparator *)gtk_separator_new(orientation);
        `}
 
 end
 
-#A widget which indicates progress visually
-#@https://developer.gnome.org/gtk3/3.2/GtkProgressBar.html
+# A widget which indicates progress visually
+# See: https://developer.gnome.org/gtk3/3.2/GtkProgressBar.html
 extern class GtkProgressBar `{GtkProgressBar *`}
        super GtkWidget
 
-       new is extern `{
+       new `{
                 return (GtkProgressBar *)gtk_progress_bar_new();
        `}
 
-       fun pulse is extern `{
-               gtk_progress_bar_pulse( recv );
+       fun pulse `{
+               gtk_progress_bar_pulse(self);
        `}
 
-       fun pulse_step : Float is extern `{
-               return gtk_progress_bar_get_pulse_step( recv );
+       fun pulse_step: Float `{
+               return gtk_progress_bar_get_pulse_step(self);
        `}
 
-       fun pulse_step=( step : Float ) is extern `{
-               gtk_progress_bar_set_pulse_step( recv, step);
+       fun pulse_step=(step: Float) `{
+               gtk_progress_bar_set_pulse_step(self, step);
        `}
 
-       fun fraction : Float is extern `{
-               return gtk_progress_bar_get_fraction( recv );
+       fun fraction: Float `{
+               return gtk_progress_bar_get_fraction(self);
        `}
 
-       fun fraction=( fraction : Float) is extern `{
-               gtk_progress_bar_set_fraction( recv, fraction );
+       fun fraction=(fraction: Float) `{
+               gtk_progress_bar_set_fraction(self, fraction);
        `}
 
-       fun inverted : Bool is extern `{
-               return gtk_progress_bar_get_inverted( recv );
+       fun inverted: Bool `{
+               return gtk_progress_bar_get_inverted(self);
        `}
 
-       fun inverted=( is_inverted : Bool) is extern `{
-               gtk_progress_bar_set_inverted( recv, is_inverted );
+       fun inverted=(is_inverted: Bool) `{
+               gtk_progress_bar_set_inverted(self, is_inverted);
        `}
 
-       fun show_text : Bool is extern `{
-               return gtk_progress_bar_get_show_text( recv );
+       fun show_text: Bool `{
+               return gtk_progress_bar_get_show_text(self);
        `}
 
-       fun show_text=( show : Bool) is extern `{
-               gtk_progress_bar_set_show_text( recv, show );
+       fun show_text=(show: Bool) `{
+               gtk_progress_bar_set_show_text(self, show);
        `}
 
-       fun text : String is extern import NativeString.to_s `{
-               return NativeString_to_s( (char *)gtk_progress_bar_get_text( recv ) );
+       fun text: String import CString.to_s_with_copy `{
+               return CString_to_s_with_copy((char *)gtk_progress_bar_get_text(self));
        `}
 
-       fun text=( value : String) is extern import String.to_cstring`{
-               gtk_progress_bar_set_text( recv, String_to_cstring( value ) );
+       fun text=(value: String) import String.to_cstring `{
+               gtk_progress_bar_set_text(self, String_to_cstring(value));
        `}
 
        fun ellipsize is abstract
@@ -145,116 +145,135 @@ end
 
 extern class GtkColorSelectionDialog
        super GtkWidget
-       new ( title : String, parent : GtkWindow ) is extern  import String.to_cstring `{
-                return gtk_color_chooser_dialog_new( String_to_cstring( title ), parent );
+       new (title: String, parent: GtkWindow)  import String.to_cstring `{
+                return gtk_color_chooser_dialog_new(String_to_cstring(title), parent);
        `}
 
-       #fun color_selection :  is extern `{
-       #       return gtk_color_selection_dialog_get_color_selection( GTK_COLOR_SELECTION_DIALOG( recv ) );
-       #`}
+       # fun color_selection:  `{
+       #       return gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(self));
+       # `}
 
-       #fun color : Float is extern `{
-       #       return gtk_color_selection_dialog_get_color_selection( GTK_COLOR_SELECTION_DIALOG( recv ) );
-       #`}
+       # fun color: Float `{
+       #       return gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(self));
+       # `}
 end
 
-#Retrieve an integer or floating-point number from the user
-#@https://developer.gnome.org/gtk3/3.2/GtkSpinButton.html
+# Retrieve an integer or floating-point number from the user
+# See: https://developer.gnome.org/gtk3/3.2/GtkSpinButton.html
 extern class GtkSpinButton `{GtkSpinButton *`}
        super GtkEntry
 
-       new ( adjustment : GtkAdjustment, climb_rate : Float, digits : Int )is extern `{
-               return (GtkSpinButton *)gtk_spin_button_new( adjustment, climb_rate, digits );
+       new (adjustment: GtkAdjustment, climb_rate: Float, digits: Int)is extern `{
+               return (GtkSpinButton *)gtk_spin_button_new(adjustment, climb_rate, digits);
        `}
 
-       new with_range( min : Float, max : Float, step : Float )is extern `{
-               return (GtkSpinButton *)gtk_spin_button_new_with_range( min, max, step );
+       new with_range(min: Float, max: Float, step: Float)is extern `{
+               return (GtkSpinButton *)gtk_spin_button_new_with_range(min, max, step);
        `}
 
-       fun configure ( adjustment : GtkAdjustment, climb_rate : Float, digits : Int ) is extern `{
-               gtk_spin_button_configure( recv, adjustment, climb_rate, digits );
+       fun configure (adjustment: GtkAdjustment, climb_rate: Float, digits: Int) `{
+               gtk_spin_button_configure(self, adjustment, climb_rate, digits);
        `}
 
-       fun adjustment : GtkAdjustment is extern `{
-               return gtk_spin_button_get_adjustment( recv );
+       fun adjustment: GtkAdjustment `{
+               return gtk_spin_button_get_adjustment(self);
        `}
 
-       fun adjustment=( value : GtkAdjustment ) is extern `{
-               gtk_spin_button_set_adjustment( recv, value );
+       fun adjustment=(value: GtkAdjustment) `{
+               gtk_spin_button_set_adjustment(self, value);
        `}
 
-       fun digits : Int is extern `{
-               return gtk_spin_button_get_digits( recv );
+       fun digits: Int `{
+               return gtk_spin_button_get_digits(self);
        `}
 
-       fun digits=( nb_digits : Int ) is extern `{
-               gtk_spin_button_set_digits( recv, nb_digits );
+       fun digits=(nb_digits: Int) `{
+               gtk_spin_button_set_digits(self, nb_digits);
        `}
 
-       fun value : Float is extern `{
-               return gtk_spin_button_get_value( recv );
+       fun value: Float `{
+               return gtk_spin_button_get_value(self);
        `}
 
-       fun val=( val : Float ) is extern `{
-               gtk_spin_button_set_value( recv, val );
+       fun val=(val: Float) `{
+               gtk_spin_button_set_value(self, val);
        `}
 
-       fun spin( direction : GtkSpinType, increment : Float ) is extern`{
-               gtk_spin_button_spin( recv, direction, increment );
+       fun spin(direction: GtkSpinType, increment: Float)`{
+               gtk_spin_button_spin(self, direction, increment);
        `}
 end
 
-#enum GtkSpinType
-#The values of the GtkSpinType enumeration are used to specify the change to make in gtk_spin_button_spin().
-#@https://developer.gnome.org/gtk3/stable/GtkSpinButton.html#GtkSpinType
+# enum GtkSpinType
+# The values of the GtkSpinType enumeration are used to specify the change to make in gtk_spin_button_spin().
+# See: https://developer.gnome.org/gtk3/stable/GtkSpinButton.html#GtkSpinType
 extern class GtkSpinType `{GtkSpinType`}
-       #Increment by the adjustments step increment.
+       # Increment by the adjustments step increment.
        new step_forward `{ return GTK_SPIN_STEP_FORWARD; `}
 
-       #Decrement by the adjustments step increment.
+       # Decrement by the adjustments step increment.
        new step_backward `{ return GTK_SPIN_STEP_BACKWARD; `}
 
-       #Increment by the adjustments page increment.
+       # Increment by the adjustments page increment.
        new page_forward `{ return GTK_SPIN_PAGE_FORWARD; `}
 
-       #Decrement by the adjustments page increment.
+       # Decrement by the adjustments page increment.
        new page_backward `{ return GTK_SPIN_PAGE_BACKWARD; `}
 
-       #Go to the adjustments lower bound.
+       # Go to the adjustments lower bound.
        new lower_bound `{ return GTK_SPIN_HOME; `}
 
-       #Go to the adjustments upper bound.
+       # Go to the adjustments upper bound.
        new upper_bound `{ return GTK_SPIN_END; `}
 
-       #Change by a specified amount.
+       # Change by a specified amount.
        new user_defined `{ return GTK_SPIN_USER_DEFINED; `}
 end
 
-#A widget to unlock or lock privileged operations
-#@https://developer.gnome.org/gtk3/stable/GtkLockButton.html
+# A widget to unlock or lock privileged operations
+# See: https://developer.gnome.org/gtk3/stable/GtkLockButton.html
 extern class GtkLockButton
        super GtkButton
 end
 
-#A button to launch a color selection dialog
-#@https://developer.gnome.org/gtk3/stable/GtkColorButton.html
+# Contains a single widget and scrollbars
+extern class GtkScrolledWindow `{ GtkScrolledWindow * `}
+       super GtkBin
+
+       new `{ return (GtkScrolledWindow *)gtk_scrolled_window_new(NULL, NULL); `}
+
+       # Set horizontal and vertical scrollbar policies
+       fun set_policy(hscrollbar_policy, vscrollbar_policy: GtkPolicyType) `{
+               gtk_scrolled_window_set_policy(self, hscrollbar_policy, vscrollbar_policy);
+       `}
+end
+
+# A button to launch a color selection dialog
+# See: https://developer.gnome.org/gtk3/stable/GtkColorButton.html
 extern class GtkColorButton `{GtkColorButton *`}
        super GtkButton
 
-       new is extern `{
-               return (GtkColorButton *)gtk_color_button_new(  );
+       new `{
+               return (GtkColorButton *)gtk_color_button_new();
        `}
+end
 
-       fun color=( col : GdkColor ) is extern `{
+# Button remaining "pressed-in" when clicked
+extern class GtkToggleButton `{ GtkToggleButton * `}
+       super GtkButton
 
-               /* deprecated
-               GdkColor *c = malloc(sizeof(GdkColor));
-               c->pixel = 50;
-               c->red = 50;
-               c->green = 50;
-               c->blue = 50;
+       # Current state, returns `true` if pressed/checked
+       fun active: Bool `{ return gtk_toggle_button_get_active(self); `}
 
-               gtk_color_button_set_color( (GtkColorButton*)recv, c );*/
-       `}
+       # Set current state, `true` for pressed/checked
+       fun active=(value: Bool) `{ gtk_toggle_button_set_active(self, value); `}
 end
 
+# Check box next to a label
+extern class GtkCheckButton `{ GtkCheckButton * `}
+       super GtkToggleButton
+
+       new `{ return (GtkCheckButton *)gtk_check_button_new(); `}
+
+       new with_label(lbl: CString) `{ return (GtkCheckButton *)gtk_check_button_new_with_label((gchar *)lbl); `}
+end