Gtk--: Item_Factory and Radio_Button group question
- From: Robert_Gasch/PeopleSoft peoplesoft com
- To: gtk-list redhat com
- Subject: Gtk--: Item_Factory and Radio_Button group question
- Date: Tue, 5 Jan 1999 19:13:42 +0100
Hi,
attached is a program which uses an item factory to hang a group
of radio buttons into a menu. Everything seems to work OK, but I
have been unable to solve the following 2 problems/questions:
1) When I select an option from the View menu, 2 events are generated: one
for the old active choice, one for the new selected choice. Is there any
way to collapse these into 1 event or selectiveley only catch the event for
the radio button chosen by the user?
2) How can I make a radio button other than the first one I insert
the default of the group? I haven't been able to find a method of doing
this.
Thanks for any advice
--> Robert
PS: I'm using Gtk-- 0.10.3 and Gtk+ 1.1.10
------------------------------ cut here -----------------------------
#include <gtk--.h>
#include <gtk/gtk.h>
#define MENU_FILE_BRANCH "/File"
#define MENU_FILE_EXIT "/File/Exit"
#define MENU_VIEW_BRANCH "/View"
#define MENU_VIEW_2DPLANE "/View/2D Plane"
#define MENU_VIEW_3DWIRE "/View/3D Wire"
#define MENU_VIEW_3DHEIGHT "/View/3D Height"
#define MENU_VIEW_3DLIGHT "/View/3D Light"
class TFWindow : public Gtk_DrawingArea
{
public:
TFWindow ();
~TFWindow ();
virtual void quit ();
virtual void fileMenuCallback (string m);
virtual void viewMenuCallback (string m);
protected:
Gtk_Window d_win;
Gtk_VBox d_vbox;
Gtk_ObjectHandle<Gtk_MenuBar> d_menuBarHandle;
Gtk_ItemFactory *d_itemFactory;
int d_nameCount;
char **d_mNames;
};
TFWindow::TFWindow() : Gtk_DrawingArea (),
d_win (GTK_WINDOW_TOPLEVEL),
d_vbox (FALSE, 0),
d_itemFactory (new Gtk_ItemFactory_MenuBar("<Main>"))
{
char *s;
Gtk_Style style;
cout << "+++ TFWindow\n";
d_win.add (&d_vbox);
//d_menuBarHandle = static_cast<Gtk_ObjectHandle<Gtk_MenuBar>&>
(d_itemFactory->get_menubar_widget(""));
{
// uglier than above but without compiler warning
Gtk_ObjectHandle<Gtk_MenuBar>
a(d_itemFactory->get_menubar_widget(""));
d_menuBarHandle = a;
}
d_menuBarHandle.get_object();
d_mNames = new char*[50];
s = d_mNames[d_nameCount++] = strdup (MENU_FILE_BRANCH);
d_itemFactory->create_item (s, 0, "<Branch>", 0);
s = d_mNames[d_nameCount++] = strdup (MENU_FILE_EXIT);
d_itemFactory->create_item (s, 0, "",
ItemFactoryConnector<TFWindow, string>(this,&fileMenuCallback,
MENU_FILE_EXIT));
s = d_mNames[d_nameCount++] = strdup (MENU_VIEW_BRANCH);
d_itemFactory->create_item (s, 0, "<Branch>", 0);
s = d_mNames[d_nameCount++] = strdup (MENU_VIEW_2DPLANE);
d_itemFactory->create_item (s, 0, "<RadioItem>",
ItemFactoryConnector<TFWindow, string>(this,&viewMenuCallback,
MENU_VIEW_2DPLANE));
s = d_mNames[d_nameCount++] = strdup (MENU_VIEW_3DWIRE);
d_itemFactory->create_item (s, 0, MENU_VIEW_2DPLANE,
ItemFactoryConnector<TFWindow, string>(this,&viewMenuCallback,
MENU_VIEW_3DWIRE));
s = d_mNames[d_nameCount++] = strdup (MENU_VIEW_3DHEIGHT);
d_itemFactory->create_item (s, 0, MENU_VIEW_2DPLANE,
ItemFactoryConnector<TFWindow, string>(this,&viewMenuCallback,
MENU_VIEW_3DHEIGHT));
s = d_mNames[d_nameCount++] = strdup (MENU_VIEW_3DLIGHT);
d_itemFactory->create_item (s, 0, MENU_VIEW_2DPLANE,
ItemFactoryConnector<TFWindow, string>(this,&viewMenuCallback,
MENU_VIEW_3DLIGHT));
d_vbox.pack_start(*d_menuBarHandle, FALSE, FALSE, 0);
// create and attach drawing area
this->size (200, 200);
d_vbox.pack_start (*this, TRUE, TRUE, 0);
// catch destroy event
connect_to_method (destroy, this, &quit);
d_win.show (); // GTK window
d_vbox.show(); // vbox
d_menuBarHandle->show();
this->show();
}
TFWindow::~TFWindow()
{
cout << "--- TFWindow\n";
}
void TFWindow::quit ()
{
gtk_exit (0);
}
void TFWindow::fileMenuCallback(string m)
{
quit ();
}
void TFWindow::viewMenuCallback(string m)
{
cout << "Callback " << m << " caught " << endl;
}
int main (int argc, char **argv)
{
Gtk_Main gtkMain (&argc, &argv);
TFWindow *tfw = new TFWindow ();
tfw->show ();
gtkMain.run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]