gnumdk
(Cédric Bellegarde)
May 30, 2022, 5:22pm
1
Hello,
If I have an Object EMenuBar subclassing GtkMenuBar, is there a way to create a new MyImage instance from an existing GtkImage instance ?
Code below does not work, returned object is a GtkMenuBar due to “menu_bar->parent = *widget;”
EMenuBar *
e_menu_bar_new (GtkMenuBar *widget)
{
EMenuBar *menu_bar;
menu_bar = g_object_new (E_TYPE_MENU_BAR, NULL);
menu_bar->parent = *widget;
return menu_bar;
}
regards,
ebassi
(Emmanuele Bassi)
May 30, 2022, 6:56pm
2
I’m sorry, I don’t understand what you’re trying to achieve. What’s EMenuBar? What’s MyImage?
What’s this, and what is it supposed to do? You’re trying to change the parent instance field? Because that can’t ever work in any way, shape or form.
gnumdk
(Cédric Bellegarde)
May 30, 2022, 7:16pm
3
Oh sorry for “MyImage” instance, did not fix my comment after pasting code.
I have a GtkMenuBar object instance and want to extend it. I’ve subclassed GtkMenuBar with EMenuBar.
But for this to be useful, I need to be able to convert GtkMenuBar object instance to EMenuBar instance. But looks like it’s not possible.
ebassi
(Emmanuele Bassi)
May 30, 2022, 7:18pm
4
I still don’t understand this at all, sorry.
If EMenuBar is a GtkMenuBar—i.e. if you derived the GtkMenuBar type—then you can pass an EMenuBar instance to any API that takes a GtkMenuBar.
swilmet
(Sébastien Wilmet)
May 31, 2022, 8:05am
5
Maybe what you need is a cast like E_MENU_BAR (menu_bar)
, but I’m not sure too.
In such a case, we can forward you to a general tutorial, here is the one I wrote several years ago: The GLib/GTK Development Platform - A Getting Started Guide (still mostly relevant, but the intro/conclusion could be updated).
The GObject library documentation also has an introduction to the concepts, and a tutorial for creating GObject subclasses.
And, if you are using GTK 3 and GtkMenuBar directly, the Amtk library can be of help.
Good luck in any case
swilmet
(Sébastien Wilmet)
May 31, 2022, 11:40am
6
What you are trying to do: is it creating a subclass of GtkMenuBar? In that case, you need to read the docs to know how to create a GObject subclass in general (it needs some boilerplate code because the C language is not object-oriented).
Or do you want to “extend” a GtkMenuBar object (an instance of the GtkMenuBar class)? In that case it depends if you want to create custom properties or signals, or just adding more functions to GtkMenuBar. In the first case, look for example at the implementation of AmtkMenuShell (an extension of GtkMenuShell).
gnumdk
(Cédric Bellegarde)
June 4, 2022, 10:38am
7
I will try to be a little clearer.
I have an object EMenuBar subclassing a GtkMenuBar.
GtkUIManager gives me a GtkMenuBar but I have no idea how to downcasting it to a EMenuBar. I know it’s possible because Gtk-rs is able to.
https://gitlab.gnome.org/GNOME/evolution/-/merge_requests/106#note_1470617
jfrancis
(Jason Francis)
June 4, 2022, 11:59am
8
You cannot do this with GtkUIManager
, it does not support constructing custom types. I think you will have to either port it to GtkBuilder
or stick with the current method of storing the GtkMenuBar
.
gnumdk
(Cédric Bellegarde)
June 6, 2022, 12:54pm
9
Ok, thanks, that was my guess when I put GtkMenuBar inside EMenuBar.
system
(system)
Closed
July 6, 2022, 12:54pm
10
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.