1use crate::{CellRenderer, CellRendererMode, ffi};
6use glib::{
7 prelude::*,
8 signal::{SignalHandlerId, connect_raw},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 #[doc(alias = "GtkCellRendererPixbuf")]
156 pub struct CellRendererPixbuf(Object<ffi::GtkCellRendererPixbuf, ffi::GtkCellRendererPixbufClass>) @extends CellRenderer;
157
158 match fn {
159 type_ => || ffi::gtk_cell_renderer_pixbuf_get_type(),
160 }
161}
162
163impl CellRendererPixbuf {
164 pub const NONE: Option<&'static CellRendererPixbuf> = None;
165
166 #[doc(alias = "gtk_cell_renderer_pixbuf_new")]
178 pub fn new() -> CellRendererPixbuf {
179 assert_initialized_main_thread!();
180 unsafe { CellRenderer::from_glib_none(ffi::gtk_cell_renderer_pixbuf_new()).unsafe_cast() }
181 }
182
183 pub fn builder() -> CellRendererPixbufBuilder {
188 CellRendererPixbufBuilder::new()
189 }
190}
191
192impl Default for CellRendererPixbuf {
193 fn default() -> Self {
194 Self::new()
195 }
196}
197
198#[must_use = "The builder must be built to be used"]
203pub struct CellRendererPixbufBuilder {
204 builder: glib::object::ObjectBuilder<'static, CellRendererPixbuf>,
205}
206
207impl CellRendererPixbufBuilder {
208 fn new() -> Self {
209 Self {
210 builder: glib::object::Object::builder(),
211 }
212 }
213
214 pub fn gicon(self, gicon: &impl IsA<gio::Icon>) -> Self {
218 Self {
219 builder: self.builder.property("gicon", gicon.clone().upcast()),
220 }
221 }
222
223 pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
227 Self {
228 builder: self.builder.property("icon-name", icon_name.into()),
229 }
230 }
231
232 pub fn pixbuf(self, pixbuf: &gdk_pixbuf::Pixbuf) -> Self {
233 Self {
234 builder: self.builder.property("pixbuf", pixbuf.clone()),
235 }
236 }
237
238 pub fn pixbuf_expander_closed(self, pixbuf_expander_closed: &gdk_pixbuf::Pixbuf) -> Self {
239 Self {
240 builder: self
241 .builder
242 .property("pixbuf-expander-closed", pixbuf_expander_closed.clone()),
243 }
244 }
245
246 pub fn pixbuf_expander_open(self, pixbuf_expander_open: &gdk_pixbuf::Pixbuf) -> Self {
247 Self {
248 builder: self
249 .builder
250 .property("pixbuf-expander-open", pixbuf_expander_open.clone()),
251 }
252 }
253
254 pub fn stock_detail(self, stock_detail: impl Into<glib::GString>) -> Self {
255 Self {
256 builder: self.builder.property("stock-detail", stock_detail.into()),
257 }
258 }
259
260 pub fn stock_size(self, stock_size: u32) -> Self {
262 Self {
263 builder: self.builder.property("stock-size", stock_size),
264 }
265 }
266
267 pub fn surface(self, surface: &cairo::Surface) -> Self {
268 Self {
269 builder: self.builder.property("surface", surface),
270 }
271 }
272
273 pub fn cell_background(self, cell_background: impl Into<glib::GString>) -> Self {
274 Self {
275 builder: self
276 .builder
277 .property("cell-background", cell_background.into()),
278 }
279 }
280
281 pub fn cell_background_rgba(self, cell_background_rgba: &gdk::RGBA) -> Self {
283 Self {
284 builder: self
285 .builder
286 .property("cell-background-rgba", cell_background_rgba),
287 }
288 }
289
290 pub fn cell_background_set(self, cell_background_set: bool) -> Self {
291 Self {
292 builder: self
293 .builder
294 .property("cell-background-set", cell_background_set),
295 }
296 }
297
298 pub fn height(self, height: i32) -> Self {
299 Self {
300 builder: self.builder.property("height", height),
301 }
302 }
303
304 pub fn is_expanded(self, is_expanded: bool) -> Self {
305 Self {
306 builder: self.builder.property("is-expanded", is_expanded),
307 }
308 }
309
310 pub fn is_expander(self, is_expander: bool) -> Self {
311 Self {
312 builder: self.builder.property("is-expander", is_expander),
313 }
314 }
315
316 pub fn mode(self, mode: CellRendererMode) -> Self {
317 Self {
318 builder: self.builder.property("mode", mode),
319 }
320 }
321
322 pub fn sensitive(self, sensitive: bool) -> Self {
323 Self {
324 builder: self.builder.property("sensitive", sensitive),
325 }
326 }
327
328 pub fn visible(self, visible: bool) -> Self {
329 Self {
330 builder: self.builder.property("visible", visible),
331 }
332 }
333
334 pub fn width(self, width: i32) -> Self {
335 Self {
336 builder: self.builder.property("width", width),
337 }
338 }
339
340 pub fn xalign(self, xalign: f32) -> Self {
341 Self {
342 builder: self.builder.property("xalign", xalign),
343 }
344 }
345
346 pub fn xpad(self, xpad: u32) -> Self {
347 Self {
348 builder: self.builder.property("xpad", xpad),
349 }
350 }
351
352 pub fn yalign(self, yalign: f32) -> Self {
353 Self {
354 builder: self.builder.property("yalign", yalign),
355 }
356 }
357
358 pub fn ypad(self, ypad: u32) -> Self {
359 Self {
360 builder: self.builder.property("ypad", ypad),
361 }
362 }
363
364 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
367 pub fn build(self) -> CellRendererPixbuf {
368 assert_initialized_main_thread!();
369 self.builder.build()
370 }
371}
372
373pub trait CellRendererPixbufExt: IsA<CellRendererPixbuf> + 'static {
379 fn gicon(&self) -> Option<gio::Icon> {
383 ObjectExt::property(self.as_ref(), "gicon")
384 }
385
386 fn set_gicon<P: IsA<gio::Icon>>(&self, gicon: Option<&P>) {
390 ObjectExt::set_property(self.as_ref(), "gicon", gicon)
391 }
392
393 #[doc(alias = "icon-name")]
397 fn icon_name(&self) -> Option<glib::GString> {
398 ObjectExt::property(self.as_ref(), "icon-name")
399 }
400
401 #[doc(alias = "icon-name")]
405 fn set_icon_name(&self, icon_name: Option<&str>) {
406 ObjectExt::set_property(self.as_ref(), "icon-name", icon_name)
407 }
408
409 fn pixbuf(&self) -> Option<gdk_pixbuf::Pixbuf> {
410 ObjectExt::property(self.as_ref(), "pixbuf")
411 }
412
413 fn set_pixbuf(&self, pixbuf: Option<&gdk_pixbuf::Pixbuf>) {
414 ObjectExt::set_property(self.as_ref(), "pixbuf", pixbuf)
415 }
416
417 #[doc(alias = "pixbuf-expander-closed")]
418 fn pixbuf_expander_closed(&self) -> Option<gdk_pixbuf::Pixbuf> {
419 ObjectExt::property(self.as_ref(), "pixbuf-expander-closed")
420 }
421
422 #[doc(alias = "pixbuf-expander-closed")]
423 fn set_pixbuf_expander_closed(&self, pixbuf_expander_closed: Option<&gdk_pixbuf::Pixbuf>) {
424 ObjectExt::set_property(
425 self.as_ref(),
426 "pixbuf-expander-closed",
427 pixbuf_expander_closed,
428 )
429 }
430
431 #[doc(alias = "pixbuf-expander-open")]
432 fn pixbuf_expander_open(&self) -> Option<gdk_pixbuf::Pixbuf> {
433 ObjectExt::property(self.as_ref(), "pixbuf-expander-open")
434 }
435
436 #[doc(alias = "pixbuf-expander-open")]
437 fn set_pixbuf_expander_open(&self, pixbuf_expander_open: Option<&gdk_pixbuf::Pixbuf>) {
438 ObjectExt::set_property(self.as_ref(), "pixbuf-expander-open", pixbuf_expander_open)
439 }
440
441 #[doc(alias = "stock-detail")]
442 fn stock_detail(&self) -> Option<glib::GString> {
443 ObjectExt::property(self.as_ref(), "stock-detail")
444 }
445
446 #[doc(alias = "stock-detail")]
447 fn set_stock_detail(&self, stock_detail: Option<&str>) {
448 ObjectExt::set_property(self.as_ref(), "stock-detail", stock_detail)
449 }
450
451 fn surface(&self) -> Option<cairo::Surface> {
452 ObjectExt::property(self.as_ref(), "surface")
453 }
454
455 fn set_surface(&self, surface: Option<&cairo::Surface>) {
456 ObjectExt::set_property(self.as_ref(), "surface", surface)
457 }
458
459 #[doc(alias = "gicon")]
460 fn connect_gicon_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
461 unsafe extern "C" fn notify_gicon_trampoline<
462 P: IsA<CellRendererPixbuf>,
463 F: Fn(&P) + 'static,
464 >(
465 this: *mut ffi::GtkCellRendererPixbuf,
466 _param_spec: glib::ffi::gpointer,
467 f: glib::ffi::gpointer,
468 ) {
469 unsafe {
470 let f: &F = &*(f as *const F);
471 f(CellRendererPixbuf::from_glib_borrow(this).unsafe_cast_ref())
472 }
473 }
474 unsafe {
475 let f: Box_<F> = Box_::new(f);
476 connect_raw(
477 self.as_ptr() as *mut _,
478 c"notify::gicon".as_ptr(),
479 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
480 notify_gicon_trampoline::<Self, F> as *const (),
481 )),
482 Box_::into_raw(f),
483 )
484 }
485 }
486
487 #[doc(alias = "icon-name")]
488 fn connect_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
489 unsafe extern "C" fn notify_icon_name_trampoline<
490 P: IsA<CellRendererPixbuf>,
491 F: Fn(&P) + 'static,
492 >(
493 this: *mut ffi::GtkCellRendererPixbuf,
494 _param_spec: glib::ffi::gpointer,
495 f: glib::ffi::gpointer,
496 ) {
497 unsafe {
498 let f: &F = &*(f as *const F);
499 f(CellRendererPixbuf::from_glib_borrow(this).unsafe_cast_ref())
500 }
501 }
502 unsafe {
503 let f: Box_<F> = Box_::new(f);
504 connect_raw(
505 self.as_ptr() as *mut _,
506 c"notify::icon-name".as_ptr(),
507 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
508 notify_icon_name_trampoline::<Self, F> as *const (),
509 )),
510 Box_::into_raw(f),
511 )
512 }
513 }
514
515 #[doc(alias = "pixbuf")]
516 fn connect_pixbuf_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
517 unsafe extern "C" fn notify_pixbuf_trampoline<
518 P: IsA<CellRendererPixbuf>,
519 F: Fn(&P) + 'static,
520 >(
521 this: *mut ffi::GtkCellRendererPixbuf,
522 _param_spec: glib::ffi::gpointer,
523 f: glib::ffi::gpointer,
524 ) {
525 unsafe {
526 let f: &F = &*(f as *const F);
527 f(CellRendererPixbuf::from_glib_borrow(this).unsafe_cast_ref())
528 }
529 }
530 unsafe {
531 let f: Box_<F> = Box_::new(f);
532 connect_raw(
533 self.as_ptr() as *mut _,
534 c"notify::pixbuf".as_ptr(),
535 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
536 notify_pixbuf_trampoline::<Self, F> as *const (),
537 )),
538 Box_::into_raw(f),
539 )
540 }
541 }
542
543 #[doc(alias = "pixbuf-expander-closed")]
544 fn connect_pixbuf_expander_closed_notify<F: Fn(&Self) + 'static>(
545 &self,
546 f: F,
547 ) -> SignalHandlerId {
548 unsafe extern "C" fn notify_pixbuf_expander_closed_trampoline<
549 P: IsA<CellRendererPixbuf>,
550 F: Fn(&P) + 'static,
551 >(
552 this: *mut ffi::GtkCellRendererPixbuf,
553 _param_spec: glib::ffi::gpointer,
554 f: glib::ffi::gpointer,
555 ) {
556 unsafe {
557 let f: &F = &*(f as *const F);
558 f(CellRendererPixbuf::from_glib_borrow(this).unsafe_cast_ref())
559 }
560 }
561 unsafe {
562 let f: Box_<F> = Box_::new(f);
563 connect_raw(
564 self.as_ptr() as *mut _,
565 c"notify::pixbuf-expander-closed".as_ptr(),
566 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
567 notify_pixbuf_expander_closed_trampoline::<Self, F> as *const (),
568 )),
569 Box_::into_raw(f),
570 )
571 }
572 }
573
574 #[doc(alias = "pixbuf-expander-open")]
575 fn connect_pixbuf_expander_open_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
576 unsafe extern "C" fn notify_pixbuf_expander_open_trampoline<
577 P: IsA<CellRendererPixbuf>,
578 F: Fn(&P) + 'static,
579 >(
580 this: *mut ffi::GtkCellRendererPixbuf,
581 _param_spec: glib::ffi::gpointer,
582 f: glib::ffi::gpointer,
583 ) {
584 unsafe {
585 let f: &F = &*(f as *const F);
586 f(CellRendererPixbuf::from_glib_borrow(this).unsafe_cast_ref())
587 }
588 }
589 unsafe {
590 let f: Box_<F> = Box_::new(f);
591 connect_raw(
592 self.as_ptr() as *mut _,
593 c"notify::pixbuf-expander-open".as_ptr(),
594 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
595 notify_pixbuf_expander_open_trampoline::<Self, F> as *const (),
596 )),
597 Box_::into_raw(f),
598 )
599 }
600 }
601
602 #[doc(alias = "stock-detail")]
603 fn connect_stock_detail_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
604 unsafe extern "C" fn notify_stock_detail_trampoline<
605 P: IsA<CellRendererPixbuf>,
606 F: Fn(&P) + 'static,
607 >(
608 this: *mut ffi::GtkCellRendererPixbuf,
609 _param_spec: glib::ffi::gpointer,
610 f: glib::ffi::gpointer,
611 ) {
612 unsafe {
613 let f: &F = &*(f as *const F);
614 f(CellRendererPixbuf::from_glib_borrow(this).unsafe_cast_ref())
615 }
616 }
617 unsafe {
618 let f: Box_<F> = Box_::new(f);
619 connect_raw(
620 self.as_ptr() as *mut _,
621 c"notify::stock-detail".as_ptr(),
622 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
623 notify_stock_detail_trampoline::<Self, F> as *const (),
624 )),
625 Box_::into_raw(f),
626 )
627 }
628 }
629
630 #[doc(alias = "stock-size")]
631 fn connect_stock_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
632 unsafe extern "C" fn notify_stock_size_trampoline<
633 P: IsA<CellRendererPixbuf>,
634 F: Fn(&P) + 'static,
635 >(
636 this: *mut ffi::GtkCellRendererPixbuf,
637 _param_spec: glib::ffi::gpointer,
638 f: glib::ffi::gpointer,
639 ) {
640 unsafe {
641 let f: &F = &*(f as *const F);
642 f(CellRendererPixbuf::from_glib_borrow(this).unsafe_cast_ref())
643 }
644 }
645 unsafe {
646 let f: Box_<F> = Box_::new(f);
647 connect_raw(
648 self.as_ptr() as *mut _,
649 c"notify::stock-size".as_ptr(),
650 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
651 notify_stock_size_trampoline::<Self, F> as *const (),
652 )),
653 Box_::into_raw(f),
654 )
655 }
656 }
657
658 #[doc(alias = "surface")]
659 fn connect_surface_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
660 unsafe extern "C" fn notify_surface_trampoline<
661 P: IsA<CellRendererPixbuf>,
662 F: Fn(&P) + 'static,
663 >(
664 this: *mut ffi::GtkCellRendererPixbuf,
665 _param_spec: glib::ffi::gpointer,
666 f: glib::ffi::gpointer,
667 ) {
668 unsafe {
669 let f: &F = &*(f as *const F);
670 f(CellRendererPixbuf::from_glib_borrow(this).unsafe_cast_ref())
671 }
672 }
673 unsafe {
674 let f: Box_<F> = Box_::new(f);
675 connect_raw(
676 self.as_ptr() as *mut _,
677 c"notify::surface".as_ptr(),
678 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
679 notify_surface_trampoline::<Self, F> as *const (),
680 )),
681 Box_::into_raw(f),
682 )
683 }
684 }
685}
686
687impl<O: IsA<CellRendererPixbuf>> CellRendererPixbufExt for O {}