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