use CssSection;
use JunctionSides;
use RegionFlags;
use StateFlags;
use StateType;
use StyleProvider;
use TextDirection;
use ffi;
use gdk;
use glib::object::IsA;
use glib::signal::connect;
use glib::translate::*;
use glib_ffi;
use std::boxed::Box as Box_;
use std::mem;
use std::mem::transmute;
glib_wrapper! {
pub struct StyleContext(Object<ffi::GtkStyleContext>);
match fn {
get_type => || ffi::gtk_style_context_get_type(),
}
}
impl StyleContext {
pub fn new() -> StyleContext {
assert_initialized_main_thread!();
unsafe {
from_glib_full(ffi::gtk_style_context_new())
}
}
pub fn add_class(&self, class_name: &str) {
unsafe {
ffi::gtk_style_context_add_class(self.to_glib_none().0, class_name.to_glib_none().0);
}
}
pub fn add_provider<T: IsA<StyleProvider>>(&self, provider: &T, priority: u32) {
unsafe {
ffi::gtk_style_context_add_provider(self.to_glib_none().0, provider.to_glib_none().0, priority);
}
}
pub fn add_region(&self, region_name: &str, flags: RegionFlags) {
unsafe {
ffi::gtk_style_context_add_region(self.to_glib_none().0, region_name.to_glib_none().0, flags.to_glib());
}
}
pub fn get_direction(&self) -> TextDirection {
unsafe {
from_glib(ffi::gtk_style_context_get_direction(self.to_glib_none().0))
}
}
#[cfg(feature = "v3_8")]
pub fn get_frame_clock(&self) -> Option<gdk::FrameClock> {
unsafe {
from_glib_none(ffi::gtk_style_context_get_frame_clock(self.to_glib_none().0))
}
}
pub fn get_junction_sides(&self) -> JunctionSides {
unsafe {
from_glib(ffi::gtk_style_context_get_junction_sides(self.to_glib_none().0))
}
}
pub fn get_parent(&self) -> Option<StyleContext> {
unsafe {
from_glib_none(ffi::gtk_style_context_get_parent(self.to_glib_none().0))
}
}
#[cfg(feature = "v3_10")]
pub fn get_scale(&self) -> i32 {
unsafe {
ffi::gtk_style_context_get_scale(self.to_glib_none().0)
}
}
pub fn get_screen(&self) -> Option<gdk::Screen> {
unsafe {
from_glib_none(ffi::gtk_style_context_get_screen(self.to_glib_none().0))
}
}
pub fn get_section(&self, property: &str) -> Option<CssSection> {
unsafe {
from_glib_full(ffi::gtk_style_context_get_section(self.to_glib_none().0, property.to_glib_none().0))
}
}
pub fn get_state(&self) -> StateFlags {
unsafe {
from_glib(ffi::gtk_style_context_get_state(self.to_glib_none().0))
}
}
pub fn has_class(&self, class_name: &str) -> bool {
unsafe {
from_glib(ffi::gtk_style_context_has_class(self.to_glib_none().0, class_name.to_glib_none().0))
}
}
pub fn has_region(&self, region_name: &str) -> Option<RegionFlags> {
unsafe {
let mut flags_return = mem::uninitialized();
let ret = from_glib(ffi::gtk_style_context_has_region(self.to_glib_none().0, region_name.to_glib_none().0, &mut flags_return));
if ret { Some(from_glib(flags_return)) } else { None }
}
}
pub fn invalidate(&self) {
unsafe {
ffi::gtk_style_context_invalidate(self.to_glib_none().0);
}
}
pub fn list_classes(&self) -> Vec<String> {
unsafe {
FromGlibPtrContainer::from_glib_container(ffi::gtk_style_context_list_classes(self.to_glib_none().0))
}
}
pub fn list_regions(&self) -> Vec<String> {
unsafe {
FromGlibPtrContainer::from_glib_container(ffi::gtk_style_context_list_regions(self.to_glib_none().0))
}
}
pub fn pop_animatable_region(&self) {
unsafe {
ffi::gtk_style_context_pop_animatable_region(self.to_glib_none().0);
}
}
pub fn remove_class(&self, class_name: &str) {
unsafe {
ffi::gtk_style_context_remove_class(self.to_glib_none().0, class_name.to_glib_none().0);
}
}
pub fn remove_provider<T: IsA<StyleProvider>>(&self, provider: &T) {
unsafe {
ffi::gtk_style_context_remove_provider(self.to_glib_none().0, provider.to_glib_none().0);
}
}
pub fn remove_region(&self, region_name: &str) {
unsafe {
ffi::gtk_style_context_remove_region(self.to_glib_none().0, region_name.to_glib_none().0);
}
}
pub fn restore(&self) {
unsafe {
ffi::gtk_style_context_restore(self.to_glib_none().0);
}
}
pub fn save(&self) {
unsafe {
ffi::gtk_style_context_save(self.to_glib_none().0);
}
}
pub fn scroll_animations(&self, window: &gdk::Window, dx: i32, dy: i32) {
unsafe {
ffi::gtk_style_context_scroll_animations(self.to_glib_none().0, window.to_glib_none().0, dx, dy);
}
}
pub fn set_background(&self, window: &gdk::Window) {
unsafe {
ffi::gtk_style_context_set_background(self.to_glib_none().0, window.to_glib_none().0);
}
}
pub fn set_direction(&self, direction: TextDirection) {
unsafe {
ffi::gtk_style_context_set_direction(self.to_glib_none().0, direction.to_glib());
}
}
#[cfg(feature = "v3_8")]
pub fn set_frame_clock(&self, frame_clock: &gdk::FrameClock) {
unsafe {
ffi::gtk_style_context_set_frame_clock(self.to_glib_none().0, frame_clock.to_glib_none().0);
}
}
pub fn set_junction_sides(&self, sides: JunctionSides) {
unsafe {
ffi::gtk_style_context_set_junction_sides(self.to_glib_none().0, sides.to_glib());
}
}
pub fn set_parent(&self, parent: Option<&StyleContext>) {
unsafe {
ffi::gtk_style_context_set_parent(self.to_glib_none().0, parent.to_glib_none().0);
}
}
#[cfg(feature = "v3_10")]
pub fn set_scale(&self, scale: i32) {
unsafe {
ffi::gtk_style_context_set_scale(self.to_glib_none().0, scale);
}
}
pub fn set_screen(&self, screen: &gdk::Screen) {
unsafe {
ffi::gtk_style_context_set_screen(self.to_glib_none().0, screen.to_glib_none().0);
}
}
pub fn set_state(&self, flags: StateFlags) {
unsafe {
ffi::gtk_style_context_set_state(self.to_glib_none().0, flags.to_glib());
}
}
pub fn state_is_running(&self, state: StateType) -> Option<f64> {
unsafe {
let mut progress = mem::uninitialized();
let ret = from_glib(ffi::gtk_style_context_state_is_running(self.to_glib_none().0, state.to_glib(), &mut progress));
if ret { Some(progress) } else { None }
}
}
pub fn add_provider_for_screen<T: IsA<StyleProvider>>(screen: &gdk::Screen, provider: &T, priority: u32) {
skip_assert_initialized!();
unsafe {
ffi::gtk_style_context_add_provider_for_screen(screen.to_glib_none().0, provider.to_glib_none().0, priority);
}
}
pub fn remove_provider_for_screen<T: IsA<StyleProvider>>(screen: &gdk::Screen, provider: &T) {
skip_assert_initialized!();
unsafe {
ffi::gtk_style_context_remove_provider_for_screen(screen.to_glib_none().0, provider.to_glib_none().0);
}
}
pub fn reset_widgets(screen: &gdk::Screen) {
assert_initialized_main_thread!();
unsafe {
ffi::gtk_style_context_reset_widgets(screen.to_glib_none().0);
}
}
pub fn connect_changed<F: Fn(&StyleContext) + 'static>(&self, f: F) -> u64 {
unsafe {
let f: Box_<Box_<Fn(&StyleContext) + 'static>> = Box_::new(Box_::new(f));
connect(self.to_glib_none().0, "changed",
transmute(changed_trampoline as usize), Box_::into_raw(f) as *mut _)
}
}
}
unsafe extern "C" fn changed_trampoline(this: *mut ffi::GtkStyleContext, f: glib_ffi::gpointer) {
callback_guard!();
let f: &Box_<Fn(&StyleContext) + 'static> = transmute(f);
f(&from_glib_none(this))
}