On Fri, May 22, 2009 at 05:08:08PM +0200, Cornelius Hald wrote:
> The result now is:
> - gtk_toggle_button_new() is working but it displays the buttons as
> toggle buttons not as radio buttons.
Well, that's what looks better in the Fremantle UI style. So even
if you use gtk radio buttons directly (i.e, without gtk actions) I
suggest you to do something like this:
gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (radio_button), FALSE);
Of course you can still use the traditional radio button look if you
want, see the attached example (it might help you with the keyboard
accelerators too).
Berto
#include <hildon/hildon.h>
static void
radio_action_changed (GtkAction *action,
GtkAction *current)
{
g_debug ("Radio action changed: %s", gtk_action_get_name (current));
}
static void
action_activated (GtkAction *action)
{
g_debug ("Button clicked: %s", gtk_action_get_name (action));
}
static GtkAction *
create_action (const gchar *name,
const gchar *accel,
GtkActionGroup *actiongroup,
GtkAccelGroup *accelgroup)
{
GtkAction *action = gtk_action_new (name, name, NULL, NULL);
gtk_action_group_add_action_with_accel (actiongroup, action, accel);
gtk_action_set_accel_group (action, accelgroup);
gtk_action_connect_accelerator (action);
g_signal_connect (action, "activate", G_CALLBACK (action_activated), NULL);
return action;
}
static GtkButton *
create_item (GtkAction *action)
{
HildonSizeType buttonsize = HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH;
GtkWidget *button = hildon_gtk_button_new (buttonsize);
gtk_action_connect_proxy (action, button);
return GTK_BUTTON (button);
}
static GtkRadioAction *
create_radio_action (const gchar *name,
GtkRadioAction *previous)
{
static gint count = 0;
GtkRadioAction *action = gtk_radio_action_new (name, name, NULL, NULL, count++);
if (previous) {
gtk_radio_action_set_group (action, gtk_radio_action_get_group (previous));
}
return action;
}
static GtkButton *
create_radio_item (GtkRadioAction *action)
{
static GSList *group = NULL;
HildonSizeType buttonsize = HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH;
GtkWidget *button = hildon_gtk_radio_button_new (buttonsize, group);
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
gtk_action_connect_proxy (GTK_ACTION (action), button);
return GTK_BUTTON (button);
}
static HildonAppMenu *
create_menu (GtkAccelGroup *accel)
{
HildonAppMenu *menu = HILDON_APP_MENU (hildon_app_menu_new ());
GtkActionGroup *group = gtk_action_group_new ("actiongroup");
GtkAction *action;
GtkRadioAction *radioaction;
/* Items */
action = create_action ("Action one", "<Ctrl>1", group, accel);
hildon_app_menu_append (menu, create_item (action));
action = create_action ("Action two", "<Ctrl>2", group, accel);
hildon_app_menu_append (menu, create_item (action));
action = create_action ("Action three", "<Ctrl>3", group, accel);
hildon_app_menu_append (menu, create_item (action));
action = create_action ("Action four", "<Ctrl>4", group, accel);
hildon_app_menu_append (menu, create_item (action));
/* Filters */
radioaction = create_radio_action ("Radio one", NULL);
g_signal_connect (radioaction, "changed", G_CALLBACK (radio_action_changed), NULL);
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (radioaction), TRUE);
hildon_app_menu_add_filter (menu, create_radio_item (radioaction));
radioaction = create_radio_action ("Radio two", radioaction);
hildon_app_menu_add_filter (menu, create_radio_item (radioaction));
radioaction = create_radio_action ("Radio three", radioaction);
hildon_app_menu_add_filter (menu, create_radio_item (radioaction));
gtk_widget_show_all (GTK_WIDGET (menu));
return menu;
}
int
main (int argc,
char **argv)
{
GtkWidget *win;
GtkWidget *label;
HildonAppMenu *menu;
GtkAccelGroup *accel;
hildon_gtk_init (&argc, &argv);
label = gtk_label_new ("This is an example of the\nHildonAppMenu widget.\n\n"
"Click on the titlebar\nto pop up the menu.");
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
win = hildon_stackable_window_new ();
accel = gtk_accel_group_new ();
menu = create_menu (accel);
hildon_window_set_app_menu (HILDON_WINDOW (win), menu);
gtk_window_add_accel_group (GTK_WINDOW (win), accel);
g_object_unref (accel);
gtk_container_set_border_width (GTK_CONTAINER (win), 20);
gtk_container_add (GTK_CONTAINER (win), label);
g_signal_connect (win, "delete_event", G_CALLBACK (gtk_main_quit), NULL);
gtk_widget_show_all (win);
gtk_main ();
return 0;
}
_______________________________________________
maemo-developers mailing list
[email protected]
https://lists.maemo.org/mailman/listinfo/maemo-developers