/*  $Id$ */

/*  ----------------------------------------------------------------------

    gtail -- A "tail -f" for GTK+.
    Copyright (c) 1999 Colin Marquardt <colin.marquardt@gmx.de>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

    ---------------------------------------------------------------------- */

#include <stdio.h>
#include <gtk/gtk.h>
#include "gtail.h"

static char AppName[] = "gtail";
static char RevId[] = "$Id: main_window.c,v 1.1 1999/06/04 20:01:25 colin Exp colin $";
static char MajorVer[] = "0";
static char MinorVer[] = "2";

GtkWidget *
create_main_window (void) {

  GtkWidget *MainWindow;
  GtkWidget *CloseButton;
  gchar Title[sizeof(AppName)+sizeof(RevId)+sizeof(MajorVer)+sizeof(MinorVer)];
  
  GtkWidget *Separator;
  GtkWidget *VBox;
  
  /* create the top level window */
  MainWindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_widget_set_usize (MainWindow, 550, 400);
  gtk_container_border_width (GTK_CONTAINER (MainWindow), 0);
  gtk_window_set_policy (GTK_WINDOW (MainWindow), TRUE, TRUE, FALSE);
  sprintf(Title, "%s %s.%s %s",
	  AppName, MajorVer, MinorVer, RevId);
  gtk_window_set_title (GTK_WINDOW (MainWindow), Title);
  
  /* ------------------------------------------------------------------------ */
  
  VBox = gtk_vbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER (MainWindow), VBox);
  
  Notebook = gtk_notebook_new ();
  Separator = gtk_hseparator_new ();
  Menubar = gtk_menu_bar_new ();
  
  /* the File menu: */
  menuItemTop_File = gtk_menu_item_new_with_label ("File");
  gtk_container_add (GTK_CONTAINER (Menubar), menuItemTop_File);
  
  menuContainer_File = gtk_menu_new ();
  gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuItemTop_File), menuContainer_File);
  
  menuItem_Add = gtk_menu_item_new_with_label ("Add File");
  gtk_container_add (GTK_CONTAINER (menuContainer_File), menuItem_Add);

  menuItem_Remove = gtk_menu_item_new_with_label ("Remove File");
  gtk_container_add (GTK_CONTAINER (menuContainer_File), menuItem_Remove);

  menuItem_Close = gtk_menu_item_new_with_label ("Close");
  gtk_container_add (GTK_CONTAINER (menuContainer_File), menuItem_Close);
  
  /* the Help menu: */
  menuItemTop_Help = gtk_menu_item_new_with_label ("Help");
  gtk_container_add (GTK_CONTAINER (Menubar), menuItemTop_Help);
  gtk_menu_item_right_justify (GTK_MENU_ITEM (menuItemTop_Help));
  
  menuContainer_Help = gtk_menu_new ();
  gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuItemTop_Help), menuContainer_Help);
  
  menuItem_About = gtk_menu_item_new_with_label ("About");
  gtk_container_add (GTK_CONTAINER (menuContainer_Help), menuItem_About);
  
  CloseButton = gtk_button_new_with_label ("Close");
  gtk_container_border_width (GTK_CONTAINER (CloseButton), 0);
  GTK_WIDGET_SET_FLAGS (CloseButton, GTK_CAN_DEFAULT);
  gtk_widget_grab_default (CloseButton);
  
  /* pack the widget into the VBox (in that order): */
  gtk_box_pack_start (GTK_BOX (VBox), Menubar, FALSE, FALSE, 0);
  gtk_box_pack_start (GTK_BOX (VBox), Notebook, TRUE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (VBox), Separator, FALSE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (VBox), CloseButton, FALSE, TRUE, 0);
  
  
  /* connect the signals to the callback functions: */
  gtk_signal_connect (GTK_OBJECT (MainWindow), "destroy",
		      GTK_SIGNAL_FUNC (close_application),
		      FileLog);
  gtk_signal_connect (GTK_OBJECT (menuItem_Add), "activate",
		      GTK_SIGNAL_FUNC (on_add_activate),
		      FileLog);
  gtk_signal_connect (GTK_OBJECT (menuItem_Remove), "activate",
		      GTK_SIGNAL_FUNC (on_remove_activate),
		      FileLog);
  gtk_signal_connect (GTK_OBJECT (menuItem_Close), "activate",
		      GTK_SIGNAL_FUNC (close_application),
		      FileLog);
  gtk_signal_connect (GTK_OBJECT (menuItem_About), "activate",
		      GTK_SIGNAL_FUNC (on_about_activate),
		      NULL);
  gtk_signal_connect (GTK_OBJECT (CloseButton), "clicked",
		      GTK_SIGNAL_FUNC(close_application),
		      FileLog);
  
  /* show all the widgets except the top level window: */
  gtk_widget_show (VBox);
  gtk_widget_show (Notebook);
  gtk_widget_show (Separator);
  gtk_widget_show (CloseButton);
  gtk_widget_show (Menubar);
  gtk_widget_show (menuItemTop_File);
  gtk_widget_show (menuItem_Add);
  gtk_widget_show (menuItem_Remove);
  gtk_widget_show (menuItem_Close);
  gtk_widget_show (menuItemTop_Help);
  gtk_widget_show (menuItem_About);

  return MainWindow;
}
