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

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 6, 2019
1 parent 91968e9 commit dd1547a
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/subclass/application_window.rs
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
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
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
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 @@ -115,6 +116,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
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/event_box.rs
@@ -1,10 +1,13 @@
use glib::subclass::prelude::*;

use super::bin::BinImpl;
use BinClass;
use EventBoxClass;

pub trait EventBoxImpl: BinImpl + 'static {}

unsafe impl<T: ObjectSubclass + EventBoxImpl> IsSubclassable<T> for EventBoxClass {
fn override_vfuncs(&mut self) {}
fn override_vfuncs(&mut self) {
<BinClass as IsSubclassable<T>>::override_vfuncs(self);
}
}
5 changes: 4 additions & 1 deletion src/subclass/header_bar.rs
@@ -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);
}
}
5 changes: 4 additions & 1 deletion src/subclass/stack.rs
@@ -1,10 +1,13 @@
use glib::subclass::prelude::*;

use super::container::ContainerImpl;
use ContainerClass;
use StackClass;

pub trait StackImpl: ContainerImpl + 'static {}

unsafe impl<T: ObjectSubclass + ContainerImpl> IsSubclassable<T> for StackClass {
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
Expand Up @@ -3,6 +3,7 @@ use gtk_sys;
use glib::translate::*;

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

use crate::DragResult;
use crate::Inhibit;
Expand Down Expand Up @@ -689,6 +690,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.adjust_baseline_allocation = Some(widget_adjust_baseline_allocation::<T>);
Expand Down
2 changes: 2 additions & 0 deletions src/subclass/window.rs
Expand Up @@ -5,6 +5,7 @@ use glib::translate::*;
use glib::subclass::prelude::*;

use super::bin::BinImpl;
use BinClass;
use Widget;
use Window;
use WindowClass;
Expand Down Expand Up @@ -98,6 +99,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.set_focus = Some(window_set_focus::<T>);
Expand Down

0 comments on commit dd1547a

Please sign in to comment.