1use crate::{
6 ffi, Accessible, AccessibleRole, Actionable, Align, Buildable, Button, ConstraintTarget,
7 LayoutManager, Overflow, Widget,
8};
9use glib::{
10 object::ObjectType as _,
11 prelude::*,
12 signal::{connect_raw, SignalHandlerId},
13 translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18 #[doc(alias = "GtkLinkButton")]
19 pub struct LinkButton(Object<ffi::GtkLinkButton>) @extends Button, Widget, @implements Accessible, Buildable, ConstraintTarget, Actionable;
20
21 match fn {
22 type_ => || ffi::gtk_link_button_get_type(),
23 }
24}
25
26impl LinkButton {
27 #[doc(alias = "gtk_link_button_new")]
28 pub fn new(uri: &str) -> LinkButton {
29 assert_initialized_main_thread!();
30 unsafe {
31 Widget::from_glib_none(ffi::gtk_link_button_new(uri.to_glib_none().0)).unsafe_cast()
32 }
33 }
34
35 #[doc(alias = "gtk_link_button_new_with_label")]
36 #[doc(alias = "new_with_label")]
37 pub fn with_label(uri: &str, label: &str) -> LinkButton {
38 assert_initialized_main_thread!();
39 unsafe {
40 Widget::from_glib_none(ffi::gtk_link_button_new_with_label(
41 uri.to_glib_none().0,
42 label.to_glib_none().0,
43 ))
44 .unsafe_cast()
45 }
46 }
47
48 pub fn builder() -> LinkButtonBuilder {
53 LinkButtonBuilder::new()
54 }
55
56 #[doc(alias = "gtk_link_button_get_uri")]
57 #[doc(alias = "get_uri")]
58 pub fn uri(&self) -> glib::GString {
59 unsafe { from_glib_none(ffi::gtk_link_button_get_uri(self.to_glib_none().0)) }
60 }
61
62 #[doc(alias = "gtk_link_button_get_visited")]
63 #[doc(alias = "get_visited")]
64 #[doc(alias = "visited")]
65 pub fn is_visited(&self) -> bool {
66 unsafe { from_glib(ffi::gtk_link_button_get_visited(self.to_glib_none().0)) }
67 }
68
69 #[doc(alias = "gtk_link_button_set_uri")]
70 #[doc(alias = "uri")]
71 pub fn set_uri(&self, uri: &str) {
72 unsafe {
73 ffi::gtk_link_button_set_uri(self.to_glib_none().0, uri.to_glib_none().0);
74 }
75 }
76
77 #[doc(alias = "gtk_link_button_set_visited")]
78 #[doc(alias = "visited")]
79 pub fn set_visited(&self, visited: bool) {
80 unsafe {
81 ffi::gtk_link_button_set_visited(self.to_glib_none().0, visited.into_glib());
82 }
83 }
84
85 #[doc(alias = "activate-link")]
86 pub fn connect_activate_link<F: Fn(&Self) -> glib::Propagation + 'static>(
87 &self,
88 f: F,
89 ) -> SignalHandlerId {
90 unsafe extern "C" fn activate_link_trampoline<
91 F: Fn(&LinkButton) -> glib::Propagation + 'static,
92 >(
93 this: *mut ffi::GtkLinkButton,
94 f: glib::ffi::gpointer,
95 ) -> glib::ffi::gboolean {
96 let f: &F = &*(f as *const F);
97 f(&from_glib_borrow(this)).into_glib()
98 }
99 unsafe {
100 let f: Box_<F> = Box_::new(f);
101 connect_raw(
102 self.as_ptr() as *mut _,
103 c"activate-link".as_ptr() as *const _,
104 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
105 activate_link_trampoline::<F> as *const (),
106 )),
107 Box_::into_raw(f),
108 )
109 }
110 }
111
112 #[doc(alias = "uri")]
113 pub fn connect_uri_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
114 unsafe extern "C" fn notify_uri_trampoline<F: Fn(&LinkButton) + 'static>(
115 this: *mut ffi::GtkLinkButton,
116 _param_spec: glib::ffi::gpointer,
117 f: glib::ffi::gpointer,
118 ) {
119 let f: &F = &*(f as *const F);
120 f(&from_glib_borrow(this))
121 }
122 unsafe {
123 let f: Box_<F> = Box_::new(f);
124 connect_raw(
125 self.as_ptr() as *mut _,
126 c"notify::uri".as_ptr() as *const _,
127 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
128 notify_uri_trampoline::<F> as *const (),
129 )),
130 Box_::into_raw(f),
131 )
132 }
133 }
134
135 #[doc(alias = "visited")]
136 pub fn connect_visited_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
137 unsafe extern "C" fn notify_visited_trampoline<F: Fn(&LinkButton) + 'static>(
138 this: *mut ffi::GtkLinkButton,
139 _param_spec: glib::ffi::gpointer,
140 f: glib::ffi::gpointer,
141 ) {
142 let f: &F = &*(f as *const F);
143 f(&from_glib_borrow(this))
144 }
145 unsafe {
146 let f: Box_<F> = Box_::new(f);
147 connect_raw(
148 self.as_ptr() as *mut _,
149 c"notify::visited".as_ptr() as *const _,
150 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
151 notify_visited_trampoline::<F> as *const (),
152 )),
153 Box_::into_raw(f),
154 )
155 }
156 }
157}
158
159impl Default for LinkButton {
160 fn default() -> Self {
161 glib::object::Object::new::<Self>()
162 }
163}
164
165#[must_use = "The builder must be built to be used"]
170pub struct LinkButtonBuilder {
171 builder: glib::object::ObjectBuilder<'static, LinkButton>,
172}
173
174impl LinkButtonBuilder {
175 fn new() -> Self {
176 Self {
177 builder: glib::object::Object::builder(),
178 }
179 }
180
181 pub fn uri(self, uri: impl Into<glib::GString>) -> Self {
182 Self {
183 builder: self.builder.property("uri", uri.into()),
184 }
185 }
186
187 pub fn visited(self, visited: bool) -> Self {
188 Self {
189 builder: self.builder.property("visited", visited),
190 }
191 }
192
193 #[cfg(feature = "v4_12")]
194 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
195 pub fn can_shrink(self, can_shrink: bool) -> Self {
196 Self {
197 builder: self.builder.property("can-shrink", can_shrink),
198 }
199 }
200
201 pub fn child(self, child: &impl IsA<Widget>) -> Self {
202 Self {
203 builder: self.builder.property("child", child.clone().upcast()),
204 }
205 }
206
207 pub fn has_frame(self, has_frame: bool) -> Self {
208 Self {
209 builder: self.builder.property("has-frame", has_frame),
210 }
211 }
212
213 pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
214 Self {
215 builder: self.builder.property("icon-name", icon_name.into()),
216 }
217 }
218
219 pub fn label(self, label: impl Into<glib::GString>) -> Self {
220 Self {
221 builder: self.builder.property("label", label.into()),
222 }
223 }
224
225 pub fn use_underline(self, use_underline: bool) -> Self {
226 Self {
227 builder: self.builder.property("use-underline", use_underline),
228 }
229 }
230
231 pub fn can_focus(self, can_focus: bool) -> Self {
232 Self {
233 builder: self.builder.property("can-focus", can_focus),
234 }
235 }
236
237 pub fn can_target(self, can_target: bool) -> Self {
238 Self {
239 builder: self.builder.property("can-target", can_target),
240 }
241 }
242
243 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
244 Self {
245 builder: self.builder.property("css-classes", css_classes.into()),
246 }
247 }
248
249 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
250 Self {
251 builder: self.builder.property("css-name", css_name.into()),
252 }
253 }
254
255 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
256 Self {
257 builder: self.builder.property("cursor", cursor.clone()),
258 }
259 }
260
261 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
262 Self {
263 builder: self.builder.property("focus-on-click", focus_on_click),
264 }
265 }
266
267 pub fn focusable(self, focusable: bool) -> Self {
268 Self {
269 builder: self.builder.property("focusable", focusable),
270 }
271 }
272
273 pub fn halign(self, halign: Align) -> Self {
274 Self {
275 builder: self.builder.property("halign", halign),
276 }
277 }
278
279 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
280 Self {
281 builder: self.builder.property("has-tooltip", has_tooltip),
282 }
283 }
284
285 pub fn height_request(self, height_request: i32) -> Self {
286 Self {
287 builder: self.builder.property("height-request", height_request),
288 }
289 }
290
291 pub fn hexpand(self, hexpand: bool) -> Self {
292 Self {
293 builder: self.builder.property("hexpand", hexpand),
294 }
295 }
296
297 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
298 Self {
299 builder: self.builder.property("hexpand-set", hexpand_set),
300 }
301 }
302
303 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
304 Self {
305 builder: self
306 .builder
307 .property("layout-manager", layout_manager.clone().upcast()),
308 }
309 }
310
311 #[cfg(feature = "v4_18")]
312 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
313 pub fn limit_events(self, limit_events: bool) -> Self {
314 Self {
315 builder: self.builder.property("limit-events", limit_events),
316 }
317 }
318
319 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
320 Self {
321 builder: self.builder.property("margin-bottom", margin_bottom),
322 }
323 }
324
325 pub fn margin_end(self, margin_end: i32) -> Self {
326 Self {
327 builder: self.builder.property("margin-end", margin_end),
328 }
329 }
330
331 pub fn margin_start(self, margin_start: i32) -> Self {
332 Self {
333 builder: self.builder.property("margin-start", margin_start),
334 }
335 }
336
337 pub fn margin_top(self, margin_top: i32) -> Self {
338 Self {
339 builder: self.builder.property("margin-top", margin_top),
340 }
341 }
342
343 pub fn name(self, name: impl Into<glib::GString>) -> Self {
344 Self {
345 builder: self.builder.property("name", name.into()),
346 }
347 }
348
349 pub fn opacity(self, opacity: f64) -> Self {
350 Self {
351 builder: self.builder.property("opacity", opacity),
352 }
353 }
354
355 pub fn overflow(self, overflow: Overflow) -> Self {
356 Self {
357 builder: self.builder.property("overflow", overflow),
358 }
359 }
360
361 pub fn receives_default(self, receives_default: bool) -> Self {
362 Self {
363 builder: self.builder.property("receives-default", receives_default),
364 }
365 }
366
367 pub fn sensitive(self, sensitive: bool) -> Self {
368 Self {
369 builder: self.builder.property("sensitive", sensitive),
370 }
371 }
372
373 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
374 Self {
375 builder: self
376 .builder
377 .property("tooltip-markup", tooltip_markup.into()),
378 }
379 }
380
381 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
382 Self {
383 builder: self.builder.property("tooltip-text", tooltip_text.into()),
384 }
385 }
386
387 pub fn valign(self, valign: Align) -> Self {
388 Self {
389 builder: self.builder.property("valign", valign),
390 }
391 }
392
393 pub fn vexpand(self, vexpand: bool) -> Self {
394 Self {
395 builder: self.builder.property("vexpand", vexpand),
396 }
397 }
398
399 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
400 Self {
401 builder: self.builder.property("vexpand-set", vexpand_set),
402 }
403 }
404
405 pub fn visible(self, visible: bool) -> Self {
406 Self {
407 builder: self.builder.property("visible", visible),
408 }
409 }
410
411 pub fn width_request(self, width_request: i32) -> Self {
412 Self {
413 builder: self.builder.property("width-request", width_request),
414 }
415 }
416
417 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
418 Self {
419 builder: self.builder.property("accessible-role", accessible_role),
420 }
421 }
422
423 pub fn action_name(self, action_name: impl Into<glib::GString>) -> Self {
424 Self {
425 builder: self.builder.property("action-name", action_name.into()),
426 }
427 }
428
429 pub fn action_target(self, action_target: &glib::Variant) -> Self {
430 Self {
431 builder: self
432 .builder
433 .property("action-target", action_target.clone()),
434 }
435 }
436
437 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
440 pub fn build(self) -> LinkButton {
441 assert_initialized_main_thread!();
442 self.builder.build()
443 }
444}