Linux Headquarters

I've installed Linux… now what???

GtkHButtonBox – Horizontal Button Container

Introduction
This example covers a container called the GtkHButtonBox. The GtkHButtonBox container is used to group buttons together in a horizontal box from left to right. From what I can tell, the GtkHButtonBox is designed to contain only buttons. However, you can pack other widgets such as GTKLabel widgets and it seems to work fine. Since GtkHButtonBox seems to accept widgets other than buttons, it is essentially the same as the GtkHBox container except that GtkHButtonBox places more space between the widgets by default that GtkHBox. In this example, the GtkHBox contains five GtkButton widgets.

Source Code

/*
*File name: hbuttonbox.c
*/

#include
#include

/*– This function allows the program to exit properly when the window is closed –*/
gint destroyapp (GtkWidget *widget, gpointer gdata)
{
g_print (“Quitting…\n”);
gtk_main_quit();
return (FALSE);
}

/*– This function responds to the mouse click on the button –*/
void button_clicked(GtkWidget *widget, gpointer gdata)
{
g_print(“Button was clicked.\n”);
}

int main (int argc, char *argv[])
{
/*– Declare the GTK Widgets used in the program –*/
GtkWidget *window;
GtkWidget *button1;
GtkWidget *button2;
GtkWidget *button3;
GtkWidget *button4;
GtkWidget *button5;
GtkWidget *hbuttonbox;

/*– Initialize GTK –*/
gtk_init (&argc, &argv);

/*– Create the new window –*/
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

/*– Create some buttons to fill the vbox with –*/
button1 = gtk_button_new_with_label(“Button 1″);
button2 = gtk_button_new_with_label(“Button 2″);
button3 = gtk_button_new_with_label(“Button 3″);
button4 = gtk_button_new_with_label(“Button 4″);
button5 = gtk_button_new_with_label(“Button 5″);

/*– Create the hbox –*/
hbuttonbox = gtk_hbutton_box_new();

/*– Connect the window to the destroyapp function –*/
gtk_signal_connect(GTK_OBJECT(window), “delete_event”, GTK_SIGNAL_FUNC(destroyapp), NULL);

/*– Connect all the buttons to the button_was_clicked function –*/
gtk_signal_connect(GTK_OBJECT(button1), “clicked”, GTK_SIGNAL_FUNC(button_clicked), NULL);
gtk_signal_connect(GTK_OBJECT(button2), “clicked”, GTK_SIGNAL_FUNC(button_clicked), NULL);
gtk_signal_connect(GTK_OBJECT(button3), “clicked”, GTK_SIGNAL_FUNC(button_clicked), NULL);
gtk_signal_connect(GTK_OBJECT(button4), “clicked”, GTK_SIGNAL_FUNC(button_clicked), NULL);
gtk_signal_connect(GTK_OBJECT(button5), “clicked”, GTK_SIGNAL_FUNC(button_clicked), NULL);

/*– Add all the buttons to the vbox –*/
gtk_box_pack_start(GTK_BOX(hbuttonbox), button1, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbuttonbox), button2, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbuttonbox), button3, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbuttonbox), button4, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbuttonbox), button5, FALSE, FALSE, 0);

/*– Add the button to the window –*/
gtk_container_add(GTK_CONTAINER (window), hbuttonbox);

/*– Add a border to the window to give the buttons a little room –*/
gtk_container_border_width (GTK_CONTAINER (window), 15);

/*– Display the widgets –*/
gtk_widget_show(hbuttonbox);
gtk_widget_show(button1);
gtk_widget_show(button2);
gtk_widget_show(button3);
gtk_widget_show(button4);
gtk_widget_show(button5);
gtk_widget_show(window);

/*– Start the GTK event loop –*/
gtk_main();

/*– Return 0 if exit is successful –*/
return 0;
}

Compile the Source Code
gcc -Wall -g hbuttonbox.c -o hbuttonbox `gtk-config –cflags` `gtk-config –libs`

Execute the Program
./hbuttonbox

What is Related

Comments are closed.

Subscribe to email feed

  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

Dedicated Linux Serv

Linux is the popular system nowadays, offering all the benefits ...

StarOffice 5.1

Introduction StarOffice 5.1 is a complete office suite with a word ...

AxY FTP

Introduction AxY FTP, formerly known as wxFTP, is a graphical FTP ...

Adobe Acrobat PDF Re

Introduction Many of you are probably familar with Adobe Acrobat Reader ...

Macromedia Shockwave

Introduction Macromedia has developed a version of its popular Shockwave plugin ...

Twitter updates

No public Twitter messages.