Source code for this example is also available in the file hpane.c
/*
*File name: hpane.c
*/
#include <gtk/gtk.h>
#include <glib.h>
/*-- 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);
}
int main (int argc, char *argv[])
{
/*-- Declare the GTK Widgets used in the program --*/
GtkWidget *window;
GtkWidget *hpane;
GtkWidget *text1;
GtkWidget *text2;
gchar *buffer1 = "This is the left text pane.";
gchar *buffer2 = "This is the right text pane.";
/*-- Initialize GTK --*/
gtk_init (&argc, &argv);
/*-- Create the new window --*/
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
/*-- Create the horizontal pane --*/
hpane = gtk_hpaned_new();
/*-- Create two text areas --*/
text1 = gtk_text_new(NULL, NULL);
text2 = gtk_text_new(NULL, NULL);
/*-- Set text areas to be editable --*/
gtk_text_set_editable(GTK_TEXT (text1), TRUE);
gtk_text_set_editable(GTK_TEXT (text2), TRUE);
/*-- Connect the window to the destroyapp function --*/
gtk_signal_connect(GTK_OBJECT(window), "delete_event", GTK_SIGNAL_FUNC(destroyapp), NULL);
/*-- Add the left text area to the hpane --*/
gtk_paned_add1(GTK_PANED(hpane), text1);
/*-- Add the right text area to the hpane --*/
gtk_paned_add2(GTK_PANED(hpane), text2);
/*-- Add the hpane to the window --*/
gtk_container_add(GTK_CONTAINER(window), hpane);
/*-- Add some text to the window --*/
gtk_text_insert(GTK_TEXT(text1), NULL, NULL, NULL, buffer1, strlen(buffer1));
gtk_text_insert(GTK_TEXT(text2), NULL, NULL, NULL, buffer2, strlen(buffer2));
/*-- Set window border to zero so that text area takes up the whole window --*/
gtk_container_border_width (GTK_CONTAINER (window), 0);
/*-- Set the window to be 640 x 200 pixels --*/
gtk_window_set_default_size (GTK_WINDOW(window), 640, 200);
/*-- Set the window title --*/
gtk_window_set_title(GTK_WINDOW (window), "A Horizontal Panel");
/*-- Display the widgets --*/
gtk_widget_show(hpane);
gtk_widget_show(text1);
gtk_widget_show(text2);
gtk_widget_show(window);
/*-- Start the GTK event loop --*/
gtk_main();
/*-- Return 0 if exit is successful --*/
return 0;
}
|