1 // This file was generated by gir (https://github.com/gtk-rs/gir) 2 // from gir-files (https://github.com/gtk-rs/gir-files) 3 // DO NOT EDIT 4 5 use crate::IconInfo; 6 use crate::IconLookupFlags; 7 use glib::object::Cast; 8 use glib::object::IsA; 9 use glib::signal::connect_raw; 10 use glib::signal::SignalHandlerId; 11 use glib::translate::*; 12 use std::boxed::Box as Box_; 13 use std::fmt; 14 use std::mem::transmute; 15 use std::ptr; 16 17 glib::wrapper! { 18 #[doc(alias = "GtkIconTheme")] 19 pub struct IconTheme(Object<ffi::GtkIconTheme, ffi::GtkIconThemeClass>); 20 21 match fn { 22 type_ => || ffi::gtk_icon_theme_get_type(), 23 } 24 } 25 26 impl IconTheme { 27 #[doc(alias = "gtk_icon_theme_new")] new() -> IconTheme28 pub fn new() -> IconTheme { 29 assert_initialized_main_thread!(); 30 unsafe { from_glib_full(ffi::gtk_icon_theme_new()) } 31 } 32 33 #[doc(alias = "gtk_icon_theme_get_default")] 34 #[doc(alias = "get_default")] default() -> Option<IconTheme>35 pub fn default() -> Option<IconTheme> { 36 assert_initialized_main_thread!(); 37 unsafe { from_glib_none(ffi::gtk_icon_theme_get_default()) } 38 } 39 40 #[doc(alias = "gtk_icon_theme_get_for_screen")] 41 #[doc(alias = "get_for_screen")] for_screen(screen: &gdk::Screen) -> Option<IconTheme>42 pub fn for_screen(screen: &gdk::Screen) -> Option<IconTheme> { 43 assert_initialized_main_thread!(); 44 unsafe { from_glib_none(ffi::gtk_icon_theme_get_for_screen(screen.to_glib_none().0)) } 45 } 46 } 47 48 impl Default for IconTheme { default() -> Self49 fn default() -> Self { 50 Self::new() 51 } 52 } 53 54 pub const NONE_ICON_THEME: Option<&IconTheme> = None; 55 56 pub trait IconThemeExt: 'static { 57 #[doc(alias = "gtk_icon_theme_add_resource_path")] add_resource_path(&self, path: &str)58 fn add_resource_path(&self, path: &str); 59 60 #[doc(alias = "gtk_icon_theme_append_search_path")] append_search_path<P: AsRef<std::path::Path>>(&self, path: P)61 fn append_search_path<P: AsRef<std::path::Path>>(&self, path: P); 62 63 #[doc(alias = "gtk_icon_theme_get_example_icon_name")] 64 #[doc(alias = "get_example_icon_name")] example_icon_name(&self) -> Option<glib::GString>65 fn example_icon_name(&self) -> Option<glib::GString>; 66 67 #[doc(alias = "gtk_icon_theme_has_icon")] has_icon(&self, icon_name: &str) -> bool68 fn has_icon(&self, icon_name: &str) -> bool; 69 70 #[doc(alias = "gtk_icon_theme_list_contexts")] list_contexts(&self) -> Vec<glib::GString>71 fn list_contexts(&self) -> Vec<glib::GString>; 72 73 #[doc(alias = "gtk_icon_theme_list_icons")] list_icons(&self, context: Option<&str>) -> Vec<glib::GString>74 fn list_icons(&self, context: Option<&str>) -> Vec<glib::GString>; 75 76 #[doc(alias = "gtk_icon_theme_load_icon")] load_icon( &self, icon_name: &str, size: i32, flags: IconLookupFlags, ) -> Result<Option<gdk_pixbuf::Pixbuf>, glib::Error>77 fn load_icon( 78 &self, 79 icon_name: &str, 80 size: i32, 81 flags: IconLookupFlags, 82 ) -> Result<Option<gdk_pixbuf::Pixbuf>, glib::Error>; 83 84 #[doc(alias = "gtk_icon_theme_load_icon_for_scale")] load_icon_for_scale( &self, icon_name: &str, size: i32, scale: i32, flags: IconLookupFlags, ) -> Result<Option<gdk_pixbuf::Pixbuf>, glib::Error>85 fn load_icon_for_scale( 86 &self, 87 icon_name: &str, 88 size: i32, 89 scale: i32, 90 flags: IconLookupFlags, 91 ) -> Result<Option<gdk_pixbuf::Pixbuf>, glib::Error>; 92 93 #[doc(alias = "gtk_icon_theme_load_surface")] load_surface( &self, icon_name: &str, size: i32, scale: i32, for_window: Option<&gdk::Window>, flags: IconLookupFlags, ) -> Result<Option<cairo::Surface>, glib::Error>94 fn load_surface( 95 &self, 96 icon_name: &str, 97 size: i32, 98 scale: i32, 99 for_window: Option<&gdk::Window>, 100 flags: IconLookupFlags, 101 ) -> Result<Option<cairo::Surface>, glib::Error>; 102 103 #[doc(alias = "gtk_icon_theme_lookup_by_gicon")] lookup_by_gicon<P: IsA<gio::Icon>>( &self, icon: &P, size: i32, flags: IconLookupFlags, ) -> Option<IconInfo>104 fn lookup_by_gicon<P: IsA<gio::Icon>>( 105 &self, 106 icon: &P, 107 size: i32, 108 flags: IconLookupFlags, 109 ) -> Option<IconInfo>; 110 111 #[doc(alias = "gtk_icon_theme_lookup_by_gicon_for_scale")] lookup_by_gicon_for_scale<P: IsA<gio::Icon>>( &self, icon: &P, size: i32, scale: i32, flags: IconLookupFlags, ) -> Option<IconInfo>112 fn lookup_by_gicon_for_scale<P: IsA<gio::Icon>>( 113 &self, 114 icon: &P, 115 size: i32, 116 scale: i32, 117 flags: IconLookupFlags, 118 ) -> Option<IconInfo>; 119 120 #[doc(alias = "gtk_icon_theme_lookup_icon")] lookup_icon(&self, icon_name: &str, size: i32, flags: IconLookupFlags) -> Option<IconInfo>121 fn lookup_icon(&self, icon_name: &str, size: i32, flags: IconLookupFlags) -> Option<IconInfo>; 122 123 #[doc(alias = "gtk_icon_theme_lookup_icon_for_scale")] lookup_icon_for_scale( &self, icon_name: &str, size: i32, scale: i32, flags: IconLookupFlags, ) -> Option<IconInfo>124 fn lookup_icon_for_scale( 125 &self, 126 icon_name: &str, 127 size: i32, 128 scale: i32, 129 flags: IconLookupFlags, 130 ) -> Option<IconInfo>; 131 132 #[doc(alias = "gtk_icon_theme_prepend_search_path")] prepend_search_path<P: AsRef<std::path::Path>>(&self, path: P)133 fn prepend_search_path<P: AsRef<std::path::Path>>(&self, path: P); 134 135 #[doc(alias = "gtk_icon_theme_rescan_if_needed")] rescan_if_needed(&self) -> bool136 fn rescan_if_needed(&self) -> bool; 137 138 #[doc(alias = "gtk_icon_theme_set_custom_theme")] set_custom_theme(&self, theme_name: Option<&str>)139 fn set_custom_theme(&self, theme_name: Option<&str>); 140 141 #[doc(alias = "gtk_icon_theme_set_screen")] set_screen(&self, screen: &gdk::Screen)142 fn set_screen(&self, screen: &gdk::Screen); 143 144 #[doc(alias = "changed")] connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId145 fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; 146 } 147 148 impl<O: IsA<IconTheme>> IconThemeExt for O { add_resource_path(&self, path: &str)149 fn add_resource_path(&self, path: &str) { 150 unsafe { 151 ffi::gtk_icon_theme_add_resource_path( 152 self.as_ref().to_glib_none().0, 153 path.to_glib_none().0, 154 ); 155 } 156 } 157 append_search_path<P: AsRef<std::path::Path>>(&self, path: P)158 fn append_search_path<P: AsRef<std::path::Path>>(&self, path: P) { 159 unsafe { 160 ffi::gtk_icon_theme_append_search_path( 161 self.as_ref().to_glib_none().0, 162 path.as_ref().to_glib_none().0, 163 ); 164 } 165 } 166 example_icon_name(&self) -> Option<glib::GString>167 fn example_icon_name(&self) -> Option<glib::GString> { 168 unsafe { 169 from_glib_full(ffi::gtk_icon_theme_get_example_icon_name( 170 self.as_ref().to_glib_none().0, 171 )) 172 } 173 } 174 has_icon(&self, icon_name: &str) -> bool175 fn has_icon(&self, icon_name: &str) -> bool { 176 unsafe { 177 from_glib(ffi::gtk_icon_theme_has_icon( 178 self.as_ref().to_glib_none().0, 179 icon_name.to_glib_none().0, 180 )) 181 } 182 } 183 list_contexts(&self) -> Vec<glib::GString>184 fn list_contexts(&self) -> Vec<glib::GString> { 185 unsafe { 186 FromGlibPtrContainer::from_glib_full(ffi::gtk_icon_theme_list_contexts( 187 self.as_ref().to_glib_none().0, 188 )) 189 } 190 } 191 list_icons(&self, context: Option<&str>) -> Vec<glib::GString>192 fn list_icons(&self, context: Option<&str>) -> Vec<glib::GString> { 193 unsafe { 194 FromGlibPtrContainer::from_glib_full(ffi::gtk_icon_theme_list_icons( 195 self.as_ref().to_glib_none().0, 196 context.to_glib_none().0, 197 )) 198 } 199 } 200 load_icon( &self, icon_name: &str, size: i32, flags: IconLookupFlags, ) -> Result<Option<gdk_pixbuf::Pixbuf>, glib::Error>201 fn load_icon( 202 &self, 203 icon_name: &str, 204 size: i32, 205 flags: IconLookupFlags, 206 ) -> Result<Option<gdk_pixbuf::Pixbuf>, glib::Error> { 207 unsafe { 208 let mut error = ptr::null_mut(); 209 let ret = ffi::gtk_icon_theme_load_icon( 210 self.as_ref().to_glib_none().0, 211 icon_name.to_glib_none().0, 212 size, 213 flags.into_glib(), 214 &mut error, 215 ); 216 if error.is_null() { 217 Ok(from_glib_full(ret)) 218 } else { 219 Err(from_glib_full(error)) 220 } 221 } 222 } 223 load_icon_for_scale( &self, icon_name: &str, size: i32, scale: i32, flags: IconLookupFlags, ) -> Result<Option<gdk_pixbuf::Pixbuf>, glib::Error>224 fn load_icon_for_scale( 225 &self, 226 icon_name: &str, 227 size: i32, 228 scale: i32, 229 flags: IconLookupFlags, 230 ) -> Result<Option<gdk_pixbuf::Pixbuf>, glib::Error> { 231 unsafe { 232 let mut error = ptr::null_mut(); 233 let ret = ffi::gtk_icon_theme_load_icon_for_scale( 234 self.as_ref().to_glib_none().0, 235 icon_name.to_glib_none().0, 236 size, 237 scale, 238 flags.into_glib(), 239 &mut error, 240 ); 241 if error.is_null() { 242 Ok(from_glib_full(ret)) 243 } else { 244 Err(from_glib_full(error)) 245 } 246 } 247 } 248 load_surface( &self, icon_name: &str, size: i32, scale: i32, for_window: Option<&gdk::Window>, flags: IconLookupFlags, ) -> Result<Option<cairo::Surface>, glib::Error>249 fn load_surface( 250 &self, 251 icon_name: &str, 252 size: i32, 253 scale: i32, 254 for_window: Option<&gdk::Window>, 255 flags: IconLookupFlags, 256 ) -> Result<Option<cairo::Surface>, glib::Error> { 257 unsafe { 258 let mut error = ptr::null_mut(); 259 let ret = ffi::gtk_icon_theme_load_surface( 260 self.as_ref().to_glib_none().0, 261 icon_name.to_glib_none().0, 262 size, 263 scale, 264 for_window.to_glib_none().0, 265 flags.into_glib(), 266 &mut error, 267 ); 268 if error.is_null() { 269 Ok(from_glib_full(ret)) 270 } else { 271 Err(from_glib_full(error)) 272 } 273 } 274 } 275 lookup_by_gicon<P: IsA<gio::Icon>>( &self, icon: &P, size: i32, flags: IconLookupFlags, ) -> Option<IconInfo>276 fn lookup_by_gicon<P: IsA<gio::Icon>>( 277 &self, 278 icon: &P, 279 size: i32, 280 flags: IconLookupFlags, 281 ) -> Option<IconInfo> { 282 unsafe { 283 from_glib_full(ffi::gtk_icon_theme_lookup_by_gicon( 284 self.as_ref().to_glib_none().0, 285 icon.as_ref().to_glib_none().0, 286 size, 287 flags.into_glib(), 288 )) 289 } 290 } 291 lookup_by_gicon_for_scale<P: IsA<gio::Icon>>( &self, icon: &P, size: i32, scale: i32, flags: IconLookupFlags, ) -> Option<IconInfo>292 fn lookup_by_gicon_for_scale<P: IsA<gio::Icon>>( 293 &self, 294 icon: &P, 295 size: i32, 296 scale: i32, 297 flags: IconLookupFlags, 298 ) -> Option<IconInfo> { 299 unsafe { 300 from_glib_full(ffi::gtk_icon_theme_lookup_by_gicon_for_scale( 301 self.as_ref().to_glib_none().0, 302 icon.as_ref().to_glib_none().0, 303 size, 304 scale, 305 flags.into_glib(), 306 )) 307 } 308 } 309 lookup_icon(&self, icon_name: &str, size: i32, flags: IconLookupFlags) -> Option<IconInfo>310 fn lookup_icon(&self, icon_name: &str, size: i32, flags: IconLookupFlags) -> Option<IconInfo> { 311 unsafe { 312 from_glib_full(ffi::gtk_icon_theme_lookup_icon( 313 self.as_ref().to_glib_none().0, 314 icon_name.to_glib_none().0, 315 size, 316 flags.into_glib(), 317 )) 318 } 319 } 320 lookup_icon_for_scale( &self, icon_name: &str, size: i32, scale: i32, flags: IconLookupFlags, ) -> Option<IconInfo>321 fn lookup_icon_for_scale( 322 &self, 323 icon_name: &str, 324 size: i32, 325 scale: i32, 326 flags: IconLookupFlags, 327 ) -> Option<IconInfo> { 328 unsafe { 329 from_glib_full(ffi::gtk_icon_theme_lookup_icon_for_scale( 330 self.as_ref().to_glib_none().0, 331 icon_name.to_glib_none().0, 332 size, 333 scale, 334 flags.into_glib(), 335 )) 336 } 337 } 338 prepend_search_path<P: AsRef<std::path::Path>>(&self, path: P)339 fn prepend_search_path<P: AsRef<std::path::Path>>(&self, path: P) { 340 unsafe { 341 ffi::gtk_icon_theme_prepend_search_path( 342 self.as_ref().to_glib_none().0, 343 path.as_ref().to_glib_none().0, 344 ); 345 } 346 } 347 rescan_if_needed(&self) -> bool348 fn rescan_if_needed(&self) -> bool { 349 unsafe { 350 from_glib(ffi::gtk_icon_theme_rescan_if_needed( 351 self.as_ref().to_glib_none().0, 352 )) 353 } 354 } 355 set_custom_theme(&self, theme_name: Option<&str>)356 fn set_custom_theme(&self, theme_name: Option<&str>) { 357 unsafe { 358 ffi::gtk_icon_theme_set_custom_theme( 359 self.as_ref().to_glib_none().0, 360 theme_name.to_glib_none().0, 361 ); 362 } 363 } 364 set_screen(&self, screen: &gdk::Screen)365 fn set_screen(&self, screen: &gdk::Screen) { 366 unsafe { 367 ffi::gtk_icon_theme_set_screen(self.as_ref().to_glib_none().0, screen.to_glib_none().0); 368 } 369 } 370 connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId371 fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { 372 unsafe extern "C" fn changed_trampoline<P: IsA<IconTheme>, F: Fn(&P) + 'static>( 373 this: *mut ffi::GtkIconTheme, 374 f: glib::ffi::gpointer, 375 ) { 376 let f: &F = &*(f as *const F); 377 f(IconTheme::from_glib_borrow(this).unsafe_cast_ref()) 378 } 379 unsafe { 380 let f: Box_<F> = Box_::new(f); 381 connect_raw( 382 self.as_ptr() as *mut _, 383 b"changed\0".as_ptr() as *const _, 384 Some(transmute::<_, unsafe extern "C" fn()>( 385 changed_trampoline::<Self, F> as *const (), 386 )), 387 Box_::into_raw(f), 388 ) 389 } 390 } 391 } 392 393 impl fmt::Display for IconTheme { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result394 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 395 f.write_str("IconTheme") 396 } 397 } 398