Home   |   Guides and Tutorials   |   What's New?   |   Comments   |   About
 

GtkVPaned - Vertical Split Container

by Brent Fox
Last Modified: Wednesday, 19-May-2004 11:54:44 EDT

Introduction
    This example covers a container called the GtkVPaned widget. The GtkVPaned container is a split plane with top and bottom sections separated by a divider. By default, the divider can be dragged up or down to alter the size of the split.
Screenshot



Source Code
Source code for this example is also available in the file vpane.c
/*
 *File name: vpane.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 *vpane;
  GtkWidget *text1;
  GtkWidget *text2;
  
  gchar *buffer1 = "This is the top text pane.";
  gchar *buffer2 = "This is the lower text pane.";

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

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

  /*-- Create the horizontal pane --*/
  vpane = gtk_vpaned_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 top text area to the hpane --*/
  gtk_paned_add1(GTK_PANED(vpane), text1);

  /*-- Add the lower text area to the hpane --*/
  gtk_paned_add2(GTK_PANED(vpane), text2);

  /*-- Add the vpane to the window --*/
  gtk_container_add(GTK_CONTAINER(window), vpane);

  /*-- 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 Vertical Panel");

  /*-- Display the widgets --*/
  gtk_widget_show(vpane);
  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;
}
  
  

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

Execute the Program
./vpane

What's Related


All Rights Reserved Linux Headquarters © 2000-2007
Linux is a registered trademark of Linus Torvalds
All logos are registered trademarks of their respective owners
Last modified: Wednesday, May 19, 2004