Table not visible
- From: Rudra Banerjee <bnrj rudra gmail com>
- To: gtk-app-devel-list gnome org
- Subject: Table not visible
- Date: Wed, 09 May 2012 01:10:51 -0400
Dear friends,
I am a newbie in GTK and also in C itself. I am trying to develop a
table (thanks to awesome tutorials available). I am currently facing a
problem.
In the given code, its working fine. Posted is a minimal example I
managed to generate. The problem is in line 88 and 89, either of table
or menu is working. If I comment one line, other one is working. Where I
went wrong? Please show.
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
GtkWidget *window ; GtkWidget *vbox1 ;GtkWidget *menubar ;GtkWidget
*filemenu ;
GtkWidget *filemenu_menu ;GtkWidget *filenew ;GtkWidget
*fileopen ;GtkWidget *filesave ;
GtkWidget *separator_1 ;GtkWidget *filequit ;GtkWidget
*editmenu ;GtkWidget *editmenu_menu ;
GtkWidget *editcut ;GtkWidget *editcopy ;GtkWidget
*editpaste ;GtkWidget *separator_2 ;
GtkWidget *editselectall ;GtkWidget *editdeselect ;GtkWidget
*helpmenu ;
GtkWidget *helpmenu_menu ;GtkWidget *helphelp ;GtkWidget *helpabout ;
GtkWidget *toolbar1 ;GtkToolItem *tooleditcut ;GtkToolItem
*tooleditcopy ;
GtkToolItem *tooleditpaste ;GtkToolItem *separator_3 ;GtkToolItem
*tooleditselectall ;
GtkWidget *label1 ;GtkWidget *hbox1 ;GtkWidget *button1 ;GtkWidget
*button2 ;
GtkAccelGroup *menuGroup;GtkWidget *window;GtkWidget *button;GtkWidget
*table;
void MessageBox (GtkWindow *parentWindow, char *messageValue)
{
GtkWidget *dialog;
dialog = gtk_message_dialog_new (parentWindow, GTK_DIALOG_MODAL,
GTK_MESSAGE_INFO, GTK_BUTTONS_OK, messageValue);
gtk_window_set_title (GTK_WINDOW (dialog), "Information");
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
}
static void callback( GtkWidget *widget,
gpointer data )
{
g_print ("Hello again - %s was pressed\n", (char *) data);
}
/* Stop the GTK+ main loop function. */
static void destroy_window (GtkWidget *window, gpointer data)
{
gtk_main_quit ();
}
/* Return FALSE to destroy the widget. By returning TRUE, you can cancel
a delete-event. This can be used to confirm quitting the application. */
static gboolean delete_event_window (GtkWidget *window, GdkEvent *event,
gpointer data)
{
return (FALSE);
}
static void helphelp_activated (GtkMenuItem *helphelp, GtkWindow
*parentWindow)
{
MessageBox(parentWindow, "Menu helphelp was clicked.");
}
static void helpabout_activated (GtkMenuItem *helpabout, GtkWindow
*parentWindow)
{
MessageBox(parentWindow, "Help Help Created.");
}
int main (int argc, char *argv[])
{
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Toolbar Test");
gtk_window_set_default_size (GTK_WINDOW (window), 400, 200);
// gtk_window_maximize (GTK_WINDOW (window));
/* Connect the main window to the destroy and delete-event signals.
*/
g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK
(destroy_window), NULL);
g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK
(delete_event_window), NULL);
vbox1 = gtk_vbox_new (FALSE, 0);
menubar = gtk_menu_bar_new ();
gtk_box_pack_start (GTK_BOX (vbox1), menubar, FALSE, FALSE, 2);
helpmenu = gtk_menu_item_new_with_label ("Help");
helpmenu_menu = gtk_menu_new ();
gtk_menu_item_set_submenu (GTK_MENU_ITEM (helpmenu), helpmenu_menu);
gtk_menu_shell_append (GTK_MENU_SHELL (menubar), helpmenu);
helphelp = gtk_image_menu_item_new_from_stock (GTK_STOCK_HELP,
menuGroup);
gtk_menu_shell_append (GTK_MENU_SHELL (helpmenu_menu), helphelp);
g_signal_connect (G_OBJECT (helphelp), "activate", G_CALLBACK
(helphelp_activated), (gpointer) window);
helpabout = gtk_image_menu_item_new_from_stock (GTK_STOCK_ABOUT,
menuGroup);
gtk_menu_shell_append (GTK_MENU_SHELL (helpmenu_menu), helpabout);
g_signal_connect (G_OBJECT (helpabout), "activate", G_CALLBACK
(helpabout_activated), (gpointer) window);
/* Create a 2x2 table */
table = gtk_table_new (2, 2, TRUE);
/* Put the table in the main window */
// gtk_container_add (GTK_CONTAINER (window), vbox1);
gtk_container_add (GTK_CONTAINER (window), table);
/* Color Scheme */
GdkColor colorBlue = { 0x0000, 3598, 57054, 61937 };
/*
* CREATE FIRST ROW */
/* Create first button */
button = gtk_button_new_with_label ("T1");
/* When the button is clicked, we call the "callback" function
* with a pointer to "button 1" as its argument */
g_signal_connect (button, "clicked",
G_CALLBACK (callback), (gpointer) "T1");
/* Insert button 1 into the upper left quadrant of the table */
gtk_table_attach_defaults (GTK_TABLE (table), button, 0, 1, 0, 1);
// without mouse hovering
gtk_widget_modify_bg( button, GTK_STATE_NORMAL, &colorBlue );
// with mouse hovering
gtk_widget_modify_bg( button, GTK_STATE_PRELIGHT, &colorBlue );
gtk_widget_show (button);
/* Create second button */
button = gtk_button_new_with_label ("T2");
/* When the button is clicked, we call the "callback" function
* with a pointer to "button 2" as its argument */
g_signal_connect (button, "clicked",
G_CALLBACK (callback), (gpointer) "T2");
/* Insert button 2 into the upper right quadrant of the table */
gtk_table_attach_defaults (GTK_TABLE (table), button, 1, 2, 0, 1);
// without mouse hovering
gtk_widget_modify_bg( button, GTK_STATE_NORMAL, &colorBlue );
// with mouse hovering
gtk_widget_modify_bg( button, GTK_STATE_PRELIGHT, &colorBlue );
gtk_widget_show (button);
gtk_widget_show_all (window);
gtk_main ();
return (0);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]