feaef7fd259380b502545b86c72ab4c1647372a5
[nit.git] / lib / gtk / gtk_widgets_ext.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 module gtk_widgets_ext
19 import gtk_core
20
21 #Displays a calendar and allows the user to select a date
22 #@https://developer.gnome.org/gtk3/3.2/GtkCalendar.html
23 extern GtkCalendar `{GtkCalendar *`}
24 super GtkWidget
25
26 new is extern `{
27 return (GtkCalendar *)gtk_calendar_new();
28 `}
29
30 fun month=( month : Int, year : Int ) is extern `{
31 gtk_calendar_select_month( recv, month, year );
32 `}
33
34 fun day=( day : Int ) is extern `{
35 gtk_calendar_select_day( recv, day );
36 `}
37
38 fun mark_day( day : Int ) is extern `{
39 gtk_calendar_mark_day( recv, day );
40 `}
41
42 fun unmark_day( day : Int ) is extern `{
43 gtk_calendar_unmark_day( recv, day );
44 `}
45
46 fun is_marked( day : Int ): Bool is extern `{
47 return gtk_calendar_get_day_is_marked( recv, day );
48 `}
49
50 fun clear_marks is extern `{
51 gtk_calendar_clear_marks( recv );
52 `}
53
54 fun display_options : GtkCalendarDisplayOptions is extern `{
55 return gtk_calendar_get_display_options( recv );
56 `}
57
58
59 fun display_options=( options : GtkCalendarDisplayOptions) is extern `{
60 gtk_calendar_set_display_options( recv, options );
61 `}
62
63 #date en nit...
64 fun date: String is abstract
65 end
66
67 #enum GtkCalendarDisplayOptions
68 #@https://developer.gnome.org/gtk3/3.2/GtkCalendar.html#GtkCalendarDisplayOptions
69 extern GtkCalendarDisplayOptions `{GtkCalendarDisplayOptions`}
70 new show_heading `{ return GTK_CALENDAR_SHOW_HEADING; `}
71 new show_day_names `{ return GTK_CALENDAR_SHOW_DAY_NAMES; `}
72 new no_month_change `{ return GTK_CALENDAR_NO_MONTH_CHANGE; `}
73 new show_week_numbers `{ return GTK_CALENDAR_SHOW_WEEK_NUMBERS; `}
74 new show_details `{ return GTK_CALENDAR_SHOW_DETAILS; `}
75 end
76
77 #A separator widget
78 #@https://developer.gnome.org/gtk3/stable/GtkSeparator.html
79 extern GtkSeparator `{GtkSeparator *`}
80 super GtkWidget
81
82 new ( orientation : GtkOrientation ) is extern `{
83 return (GtkSeparator *)gtk_separator_new( orientation );
84 `}
85
86 end
87
88 #A widget which indicates progress visually
89 #@https://developer.gnome.org/gtk3/3.2/GtkProgressBar.html
90 extern GtkProgressBar `{GtkProgressBar *`}
91 super GtkWidget
92
93 new is extern `{
94 return (GtkProgressBar *)gtk_progress_bar_new();
95 `}
96
97 fun pulse is extern `{
98 gtk_progress_bar_pulse( recv );
99 `}
100
101 fun pulse_step : Float is extern `{
102 return gtk_progress_bar_get_pulse_step( recv );
103 `}
104
105 fun pulse_step=( step : Float ) is extern `{
106 gtk_progress_bar_set_pulse_step( recv, step);
107 `}
108
109 fun fraction : Float is extern `{
110 return gtk_progress_bar_get_fraction( recv );
111 `}
112
113 fun fraction=( fraction : Float) is extern `{
114 gtk_progress_bar_set_fraction( recv, fraction );
115 `}
116
117 fun inverted : Bool is extern `{
118 return gtk_progress_bar_get_inverted( recv );
119 `}
120
121 fun inverted=( is_inverted : Bool) is extern `{
122 gtk_progress_bar_set_inverted( recv, is_inverted );
123 `}
124
125 fun show_text : Bool is extern `{
126 return gtk_progress_bar_get_show_text( recv );
127 `}
128
129 fun show_text=( show : Bool) is extern `{
130 gtk_progress_bar_set_show_text( recv, show );
131 `}
132
133 fun text : String is extern import String::to_cstring`{
134 return new_String_from_cstring( (char *)gtk_progress_bar_get_text( recv ) );
135 `}
136
137 fun text=( value : String) is extern import String::to_cstring`{
138 gtk_progress_bar_set_text( recv, String_to_cstring( value ) );
139 `}
140
141 fun ellipsize is abstract
142
143 end
144
145 extern GtkColorSelectionDialog
146 super GtkWidget
147 new ( title : String, parent : GtkWindow ) is extern import String::to_cstring `{
148 return gtk_color_chooser_dialog_new( String_to_cstring( title ), parent );
149 `}
150
151 #fun color_selection : is extern `{
152 # return gtk_color_selection_dialog_get_color_selection( GTK_COLOR_SELECTION_DIALOG( recv ) );
153 #`}
154
155 #fun color : Float is extern `{
156 # return gtk_color_selection_dialog_get_color_selection( GTK_COLOR_SELECTION_DIALOG( recv ) );
157 #`}
158 end
159
160 #Retrieve an integer or floating-point number from the user
161 #@https://developer.gnome.org/gtk3/3.2/GtkSpinButton.html
162 extern GtkSpinButton `{GtkSpinButton *`}
163 super GtkEntry
164
165 new ( adjustment : GtkAdjustment, climb_rate : Float, digits : Int )is extern `{
166 return (GtkSpinButton *)gtk_spin_button_new( adjustment, climb_rate, digits );
167 `}
168
169 new with_range( min : Float, max : Float, step : Float )is extern `{
170 return (GtkSpinButton *)gtk_spin_button_new_with_range( min, max, step );
171 `}
172
173 fun configure ( adjustment : GtkAdjustment, climb_rate : Float, digits : Int ) is extern `{
174 gtk_spin_button_configure( recv, adjustment, climb_rate, digits );
175 `}
176
177 fun adjustment : GtkAdjustment is extern `{
178 return gtk_spin_button_get_adjustment( recv );
179 `}
180
181 fun adjustment=( value : GtkAdjustment ) is extern `{
182 gtk_spin_button_set_adjustment( recv, value );
183 `}
184
185 fun digits : Int is extern `{
186 return gtk_spin_button_get_digits( recv );
187 `}
188
189 fun digits=( nb_digits : Int ) is extern `{
190 gtk_spin_button_set_digits( recv, nb_digits );
191 `}
192
193 fun value : Float is extern `{
194 return gtk_spin_button_get_value( recv );
195 `}
196
197 fun val=( val : Float ) is extern `{
198 gtk_spin_button_set_value( recv, val );
199 `}
200
201 fun spin( direction : GtkSpinType, increment : Float ) is extern`{
202 gtk_spin_button_spin( recv, direction, increment );
203 `}
204 end
205
206 #enum GtkSpinType
207 #The values of the GtkSpinType enumeration are used to specify the change to make in gtk_spin_button_spin().
208 #@https://developer.gnome.org/gtk3/stable/GtkSpinButton.html#GtkSpinType
209 extern GtkSpinType `{GtkSpinType`}
210 #Increment by the adjustments step increment.
211 new step_forward `{ return GTK_SPIN_STEP_FORWARD; `}
212
213 #Decrement by the adjustments step increment.
214 new step_backward `{ return GTK_SPIN_STEP_BACKWARD; `}
215
216 #Increment by the adjustments page increment.
217 new page_forward `{ return GTK_SPIN_PAGE_FORWARD; `}
218
219 #Decrement by the adjustments page increment.
220 new page_backward `{ return GTK_SPIN_PAGE_BACKWARD; `}
221
222 #Go to the adjustments lower bound.
223 new lower_bound `{ return GTK_SPIN_HOME; `}
224
225 #Go to the adjustments upper bound.
226 new upper_bound `{ return GTK_SPIN_END; `}
227
228 #Change by a specified amount.
229 new user_defined `{ return GTK_SPIN_USER_DEFINED; `}
230 end
231
232 #An entry which shows a search icon
233 #@https://developer.gnome.org/gtk3/stable/GtkSearchEntry.html
234 extern GtkSearchEntry `{GtkSearchEntry *`}
235 super GtkEntry
236
237 new is extern `{
238 return (GtkSearchEntry *)gtk_search_entry_new( );
239 `}
240 end
241
242 #A widget to unlock or lock privileged operations
243 #@https://developer.gnome.org/gtk3/stable/GtkLockButton.html
244 extern GtkLockButton
245 super GtkButton
246 end
247
248 #A button to launch a color selection dialog
249 #@https://developer.gnome.org/gtk3/stable/GtkColorButton.html
250 extern GtkColorButton `{GtkColorButton *`}
251 super GtkButton
252
253 new is extern `{
254 return (GtkColorButton *)gtk_color_button_new( );
255 `}
256
257 fun color=( col : GdkColor ) is extern `{
258
259 /* deprecated
260 GdkColor *c = malloc(sizeof(GdkColor));
261 c->pixel = 50;
262 c->red = 50;
263 c->green = 50;
264 c->blue = 50;
265
266 gtk_color_button_set_color( (GtkColorButton*)recv, c );*/
267 `}
268 end
269