Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Commit

Permalink
subclass/{widget, application, dialog, window}: Implement default han…
Browse files Browse the repository at this point in the history
…dling for parent events

Close #916
  • Loading branch information
alatiera committed Dec 6, 2019
1 parent 14b34cf commit 98e6ae9
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 172 deletions.
14 changes: 6 additions & 8 deletions src/subclass/application.rs
Expand Up @@ -31,10 +31,9 @@ impl<T: GtkApplicationImpl + ObjectImpl> GtkApplicationImplExt for T {
let data = self.get_type_data();
let parent_class =
data.as_ref().get_parent_class() as *mut gtk_sys::GtkApplicationClass;
let f = (*parent_class)
.window_added
.expect("No parent class implementation for \"window_added\"");
f(application.to_glib_none().0, window.to_glib_none().0)
if let Some(f) = (*parent_class).window_added {
f(application.to_glib_none().0, window.to_glib_none().0)
}
}
}

Expand All @@ -43,10 +42,9 @@ impl<T: GtkApplicationImpl + ObjectImpl> GtkApplicationImplExt for T {
let data = self.get_type_data();
let parent_class =
data.as_ref().get_parent_class() as *mut gtk_sys::GtkApplicationClass;
let f = (*parent_class)
.window_removed
.expect("No parent class implementation for \"window_added\"");
f(application.to_glib_none().0, window.to_glib_none().0)
if let Some(f) = (*parent_class).window_removed {
f(application.to_glib_none().0, window.to_glib_none().0)
}
}
}
}
Expand Down
14 changes: 6 additions & 8 deletions src/subclass/dialog.rs
Expand Up @@ -30,21 +30,19 @@ impl<T: DialogImpl + ObjectImpl> DialogImplExt for T {
unsafe {
let data = self.get_type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gtk_sys::GtkDialogClass;
let f = (*parent_class)
.response
.expect("No parent class impl for \"response\"");
f(dialog.to_glib_none().0, response.to_glib())
if let Some(f) = (*parent_class).response {
f(dialog.to_glib_none().0, response.to_glib())
}
}
}

fn parent_close(&self, dialog: &Dialog) {
unsafe {
let data = self.get_type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gtk_sys::GtkDialogClass;
let f = (*parent_class)
.close
.expect("No parent class impl for \"close\"");
f(dialog.to_glib_none().0)
if let Some(f) = (*parent_class).close {
f(dialog.to_glib_none().0)
}
}
}
}
Expand Down

0 comments on commit 98e6ae9

Please sign in to comment.