Skip to content

Commit

Permalink
subclass: Always allow to override the vfuns of classes
Browse files Browse the repository at this point in the history
  • Loading branch information
alatiera committed Nov 18, 2019
1 parent ce98539 commit f2f441f
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/subclass/application_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ use glib::subclass::prelude::*;

use super::window::WindowImpl;
use ApplicationWindowClass;
use WindowClass;

pub trait ApplicationWindowImpl: WindowImpl + 'static {}

unsafe impl<T: ObjectSubclass + ApplicationWindowImpl> IsSubclassable<T>
for ApplicationWindowClass
{
fn override_vfuncs(&mut self) {}
fn override_vfuncs(&mut self) {
<WindowClass as IsSubclassable<T>>::override_vfuncs(self);
}
}
5 changes: 4 additions & 1 deletion src/subclass/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ use glib::subclass::prelude::*;

use super::container::ContainerImpl;
use BinClass;
use ContainerClass;

pub trait BinImpl: ContainerImpl + 'static {}

unsafe impl<T: ObjectSubclass + BinImpl> IsSubclassable<T> for BinClass {
fn override_vfuncs(&mut self) {}
fn override_vfuncs(&mut self) {
<ContainerClass as IsSubclassable<T>>::override_vfuncs(self);
}
}
5 changes: 4 additions & 1 deletion src/subclass/box_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ use glib::subclass::prelude::*;

use super::container::ContainerImpl;
use BoxClass;
use ContainerClass;

pub trait BoxImpl: ContainerImpl + 'static {}

unsafe impl<T: ObjectSubclass + BoxImpl> IsSubclassable<T> for BoxClass {
fn override_vfuncs(&mut self) {}
fn override_vfuncs(&mut self) {
<ContainerClass as IsSubclassable<T>>::override_vfuncs(self);
}
}
2 changes: 2 additions & 0 deletions src/subclass/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use super::widget::WidgetImpl;
use Container;
use ContainerClass;
use Widget;
use WidgetClass;
use WidgetPath;

pub trait ContainerImpl: ContainerImplExt + WidgetImpl + 'static {
Expand Down Expand Up @@ -99,6 +100,7 @@ impl<T: ContainerImpl + ObjectImpl> ContainerImplExt for T {

unsafe impl<T: ObjectSubclass + ContainerImpl> IsSubclassable<T> for ContainerClass {
fn override_vfuncs(&mut self) {
<WidgetClass as IsSubclassable<T>>::override_vfuncs(self);
unsafe {
let klass = &mut *(self as *mut Self as *mut gtk_sys::GtkContainerClass);
klass.add = Some(container_add::<T>);
Expand Down
2 changes: 2 additions & 0 deletions src/subclass/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use super::window::WindowImpl;
use Dialog;
use DialogClass;
use ResponseType;
use WindowClass;

pub trait DialogImpl: DialogImplExt + WindowImpl + 'static {
fn response(&self, dialog: &Dialog, response: ResponseType) {
Expand Down Expand Up @@ -50,6 +51,7 @@ impl<T: DialogImpl + ObjectImpl> DialogImplExt for T {

unsafe impl<T: ObjectSubclass + DialogImpl> IsSubclassable<T> for DialogClass {
fn override_vfuncs(&mut self) {
<WindowClass as IsSubclassable<T>>::override_vfuncs(self);
unsafe {
let klass = &mut *(self as *mut Self as *mut gtk_sys::GtkDialogClass);
klass.response = Some(dialog_response::<T>);
Expand Down
5 changes: 4 additions & 1 deletion src/subclass/header_bar.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use glib::subclass::prelude::*;

use super::container::ContainerImpl;
use ContainerClass;
use HeaderBarClass;

pub trait HeaderBarImpl: ContainerImpl + 'static {}

unsafe impl<T: ObjectSubclass + HeaderBarImpl> IsSubclassable<T> for HeaderBarClass {
fn override_vfuncs(&mut self) {}
fn override_vfuncs(&mut self) {
<ContainerClass as IsSubclassable<T>>::override_vfuncs(self);
}
}
2 changes: 2 additions & 0 deletions src/subclass/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use gtk_sys;
use glib::translate::*;

use glib::subclass::prelude::*;
use glib::ObjectClass;

use crate::DragResult;
use crate::SelectionData;
Expand Down Expand Up @@ -292,6 +293,7 @@ impl<T: WidgetImpl + ObjectImpl> WidgetImplExt for T {

unsafe impl<T: ObjectSubclass + WidgetImpl> IsSubclassable<T> for WidgetClass {
fn override_vfuncs(&mut self) {
<ObjectClass as IsSubclassable<T>>::override_vfuncs(self);
unsafe {
let klass = &mut *(self as *mut Self as *mut gtk_sys::GtkWidgetClass);
// klass.can_activate_accel = Some(widget_can_activate_accel::<T>);
Expand Down
2 changes: 2 additions & 0 deletions src/subclass/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use glib::translate::*;
use glib::subclass::prelude::*;

use super::bin::BinImpl;
use BinClass;
use Window;
use WindowClass;

Expand Down Expand Up @@ -97,6 +98,7 @@ impl<T: WindowImpl + ObjectImpl> WindowImplExt for T {

unsafe impl<T: ObjectSubclass + WindowImpl> IsSubclassable<T> for WindowClass {
fn override_vfuncs(&mut self) {
<BinClass as IsSubclassable<T>>::override_vfuncs(self);
unsafe {
let klass = &mut *(self as *mut Self as *mut gtk_sys::GtkWindowClass);
klass.activate_focus = Some(window_activate_focus::<T>);
Expand Down

0 comments on commit f2f441f

Please sign in to comment.