Re: [gtk-list] Gtk--: Upgrading from MenuFactory to ItemFactory
- From: Tero Pulkkinen <terop students cc tut fi>
- To: gtk-list redhat com
- cc: gtkmm modeemi cs tut fi
- Subject: Re: [gtk-list] Gtk--: Upgrading from MenuFactory to ItemFactory
- Date: 17 Dec 1998 20:42:32 +0200
Robert_Gasch/PeopleSoft@peoplesoft.com writes:
> -- I'm now doing this:
> static GtkItemFactoryEntry menu_items[] = {
> {"/File", 0, 0, 0, "<Branch>" },
> {"/File/New", 0, 0, 0, 0 },
> {"/File/Open", 0, 0, 0, 0 } };
The problem is that this kind of table of menuitems did not work well with
C++'s type checking etc... The types of callbacks are different and cannot
be easily placed to this kind of array without breaking type safety.
Use several create_item -calls instead:
void tc::cb1(gint) {
..
}
void scb() {
..
}
d_menuFactory->create_item ("/File", 0, "<Separator>", this, &tc::cb1, 0);
d_menuFactory->create_item ("/File", 0, "<Separator>", &scb);
This only works if your C++ compiler supports member templates, if not,
you'll want to use itemfactoryconnector classes :)
(anyway, I found inconsistency in itemfactory - why do we have
Gtk_Widget& create_item(const string & path,
const _gtk_string & accelerator,
const string & item_type, void (*target_func)());
and
template <class RECEIVER, class ARG_TYPE>
Gtk_Widget& create_item(const string &path,
const _gtk_string &accelerator,
const string &item_type,
RECEIVER *target_widget,
void (RECEIVER::*target_method)(ARG_TYPE),
ARG_TYPE target_method_arg);
I mean the template version has extra arg given, but there's no version
where extra arg is not given and the other create_item does not have
possibility to add extra arg at all :)
)
> d_menuFactory = new Gtk_ItemFactory_MenuBar("<Main>");
> d_menuFactory->create_items (nmenu_items, menu_items, 0);
> { // ugly
> Gtk_ObjectHandle<Gtk_MenuBar> a(d_menuFactory->get_menubar_widget(""));
> d_menuBar = a;
> }
why not keep d_menuBar as Gtk_ObjectHandle<Gtk_MenuBar>, instead of
Gtk_MenuBar*?
> d_vbox.pack_start (*d_menuBar, FALSE, FALSE, 0);
> d_menuBar->show ();
> This works, but I can't figure out how to add the callback info to the
> menu_items definition. I've tried a c-style functions (as in the old code
> above), a C++ style method but keep getting compile errors or
> just non-working code. So after more than an hour of putzing around
> I gave up.
Note that the types of the methods needs to be correct...
--
-- Tero Pulkkinen -- terop@modeemi.cs.tut.fi --
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]