/*
 * Sample GUI application front end.
 *
 * Auth: Eric Harlow
 *
 */

#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <gtk/gtk.h>
#include "notepad.h"

#include <locale.h>
#include <libintl.h>
#define _(STRING) gettext(STRING)



/* 
 * --- Global variables
 */
GtkWidget           *win_main;
GtkAccelGroup       *accel_group;
GtkWidget           *toolbar;

#if 0
/*
 * --- Bitmap for "new"
 */ 
static const gchar *xpm_new[] = {
"16 16 3 1",
"  c None",
"B c #000000000000",
"W c #FFFFFFFFFFFF",
"                ",
"  BBBBBBBBB     ",
"  BWWWWWWWBB    ",
"  BWWWWWWWBWB   ",
"  BWWWWWWWBBBB  ",
"  BWWWWWWWWWWB  ",
"  BWWWWWWWWWWB  ",
"  BWWWWWWWWWWB  ",
"  BWWWWWWWWWWB  ",
"  BWWWWWWWWWWB  ",
"  BWWWWWWWWWWB  ",
"  BWWWWWWWWWWB  ",
"  BWWWWWWWWWWB  ",
"  BWWWWWWWWWWB  ",
"  BBBBBBBBBBBB  ",
"                ",
};

/*
 * --- Bitmap for "open"
 */ 
static const gchar *xpm_open[] = {
"16 16 4 1",
"  c None",
"B c #000000000000",
"Y c #FFFFFFFF0000",
"y c #999999990000",
"                ",
"          BBB   ",
"  BBBBB  B   BB ",
"  BYYYB      BB ",
" BYYYYYBBBBB    ",
" BYYYYYYYYYB    ",
" BYYYYYYYYYB    ",
" BYYYYYYYYYB    ",
" BYYBBBBBBBBBBB ",
" BYYByyyyyyyyyB ",
" BYByyyyyyyyyB  ",
" BYByyyyyyyyyB  ",
" BByyyyyyyyyB   ",
" BByyyyyyyyyB   ",
" BBBBBBBBBBB    ",
"                ",
};

/*
 * --- Bitmap for "cut"
 */
static const char *xpm_cut[] = {
"16 16 2 1",
"  c None",
"B c #000000000000",
"                ",
"                ",
"     B   B      ",
"     B   B      ",
"      B B       ",
"      B B       ",
"       B        ",
"       B        ",
"      B B       ",
"    BBB BBB     ",
"   B  B B  B    ",
"   B  B B  B    ",
"   B  B  BB     ",
"    BB          ",
"                ",
"                ",
};

/*
 * --- Bitmap for "copy"
 */
static const char *xpm_copy[] = {
"16 16 4 1",
"  c None",
"B c #000000000000",
"W c #FFFFFFFFFFFF",
"G c #666666666666",
"                ",
" BBBBBBB        ",
" BWWWWBWB       ",
" BWGGWBBB       ",
" BWWWWWWB       ",
" BWGGGGWB       ",
" BWWWWBBBBBBB   ",
" BWGGGBWWWWBWB  ",
" BWWWWBWGGWBBB  ",
" BBBBBBWWWWWWB  ",
"      BWGGGGWB  ",
"      BWWWWWWB  ",
"      BWGGGGWB  ",
"      BWWWWWWB  ",
"      BBBBBBBB  ",
"                ",
};


/*
 * --- Bitmap for "paste"
 */
static const char *xpm_paste[] = {
"16 16 5 1",
"  c None",
"B c #000000000000",
"W c #FFFFFFFFFFFF",
"G c #666666666666",
"Y c #888888880000",
"                ",
"       BB       ",
"  BBBBBYYBBBBB  ",
"  BYYBBBBBBYYB  ",
"  BYYYYYYYYYYB  ",
"  BYYYYYYYYYYB  ",
"  BYYYYBBBBBBBB ",
"  BYYYYBWWWWBWB ",
"  BYYYYBWGGWBBB ",
"  BYYYYBWWWWWWB ",
"  BYYYYBWGGGGWB ",
"  BYYYYBWWWWWWB ",
"  BYYYYBWGGGGWB ",
"  BBBBBBWWWWWWB ",
"       BBBBBBBB ",
"                ",
};
#endif

/*
 * CreateMenu
 *
 * Create the main window and the menu/toolbar associated with it
 */
void notepad_CreateMenu (GtkWidget *window, GtkWidget *vbox_main)
{
    GtkWidget *menubar;
    GtkWidget *menu;
    GtkWidget *menuitem;
	GtkWidget *hbox;
	GtkWidget *find_button;

    win_main = window;

    /* --- Create accel table --- */
    accel_group = gtk_accel_group_new ();
    gtk_accel_group_attach (accel_group, GTK_OBJECT (window));

	hbox = gtk_hbox_new(FALSE, 0);
    gtk_box_pack_start (GTK_BOX (vbox_main), hbox, FALSE, TRUE, 0);
    gtk_widget_show (hbox);

    /* --- Menu Bar --- */
    menubar = gtk_menu_bar_new ();
	gtk_menu_bar_set_shadow_type (GTK_MENU_BAR(menubar), GTK_SHADOW_NONE);

    gtk_box_pack_start (GTK_BOX (hbox), menubar, FALSE, TRUE, 0);
    gtk_widget_show (menubar);


    find_button = gtk_button_new_with_label(_("Find..."));
    gtk_box_pack_end (GTK_BOX (hbox), find_button, FALSE, FALSE, 0);
    gtk_signal_connect(GTK_OBJECT(find_button), "clicked", menu_Find, NULL);
    gtk_widget_show (find_button);


    /* -----------------
       --- File menu ---
       ----------------- */
    menu = CreateBarSubMenu (menubar, _("Notepad"), FALSE);

    menuitem = CreateMenuItem (menu, _("New"), NULL,NULL,
                     /*"Create a new item", */
                     GTK_SIGNAL_FUNC (menu_New), "new");

    menuitem = CreateMenuItem (menu, _("Open"), NULL, NULL,
                     //"Open an existing item", 
                     GTK_SIGNAL_FUNC (menu_Open), "open");



#if 0
    menuitem = CreateMenuItem (menu, "Import RTF", "",NULL, 
                     //"Import RTF file", 
                     GTK_SIGNAL_FUNC (menu_ImportRTF), "import rtf");
#endif



    menuitem = CreateMenuItem (menu, _("Save"), NULL, NULL,
                     //"Save current item", 
                     GTK_SIGNAL_FUNC (menu_Save), "save");

    menuitem = CreateMenuItem (menu, _("Save As..."), "", NULL,
                     //"Save current item with new name", 
                     GTK_SIGNAL_FUNC (menu_SaveAs), "save as");





#if 0
    menuitem = CreateMenuItem (menu, NULL, NULL, 
                     NULL, NULL, NULL);

    menuitem = CreateMenuItem (menu, "Quit", "",NULL, 
                     //"What's more descriptive than quit?", 
                     GTK_SIGNAL_FUNC (menu_Quit), "quit");

    /* -----------------
       --- Edit menu ---
       ----------------- */
    menu = CreateBarSubMenu (menubar, "Edit", FALSE);

    menuitem = CreateMenuItem (menu, "Cut", "^X", NULL,
                     //"Remove item and place into clipboard", 
                     GTK_SIGNAL_FUNC (menu_Cut), "cut");

    menuitem = CreateMenuItem (menu, "Copy", "^C",NULL, 
                     //"Place a copy of the item in the clipboard", 
                     GTK_SIGNAL_FUNC (menu_Copy), "copy");

    menuitem = CreateMenuItem (menu, "Paste", "^V", NULL,
                     //"Paste item", 
                     GTK_SIGNAL_FUNC (menu_Paste), "paste");
   
    /* ---------------------
       --- Find sub menu ---
       --------------------- */
    menu = CreateBarSubMenu (menubar, "Search", FALSE);

    menuitem = CreateMenuItem (menu, "Find", "^F", NULL,
                     //"Find item", 
                     GTK_SIGNAL_FUNC (menu_Find), "paste");

    /* ---------------------
       --- Help sub menu ---
       --------------------- */
    menu = CreateBarSubMenu (menubar, "Help", FALSE);

    menuitem = CreateMenuItem (menu, "About", "", NULL, 
                     //"About", 
                     GTK_SIGNAL_FUNC (menu_About), "about");

//      gtk_menu_item_right_justify(menuitem);
    /* --- Create the toolbar --- */
    CreateToolbar (vbox_main);

#endif



}

#if 0

/*
 * CreateToolbar
 * 
 * Create the toolbar for commonly used options
 */
void CreateToolbar (GtkWidget *vbox_main)
{

    /* --- Create the toolbar and add it to the window --- */
    toolbar = gtk_toolbar_new (GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_ICONS);
    gtk_box_pack_start (GTK_BOX (vbox_main), toolbar, FALSE, TRUE, 0);
    gtk_widget_show (toolbar);

    /*            -------
     * --- Create | new | button
     *            -------
     */
    gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
			   NULL, NULL, NULL,
                           CreateWidgetFromXpm (win_main, (gchar **) xpm_new),
			   (GtkSignalFunc) menu_New,
                           NULL);

    /*            --------
     * --- Create | open | button
     *            --------
     */
    gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
			   "Open Dialog", NULL, "",
                           CreateWidgetFromXpm (win_main, (gchar **) xpm_open),
			   (GtkSignalFunc) menu_Open,
                           NULL);

    /* --- Little gap --- */
    gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
    gtk_toolbar_append_widget(GTK_TOOLBAR (toolbar),CreateFindToolEntry(),
			   "FInd String", "");

    /*            -------
     * --- Create | cut | button
     *            -------
     */
    gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
			   "Cut", "Cut", "",
                           CreateWidgetFromXpm (win_main, (gchar **) xpm_cut),
			   (GtkSignalFunc) menu_Cut,
                           NULL);

    /*            --------
     * --- Create | copy | button
     *            --------
     */
    gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
			   "Copy", "Copy", "",
                           CreateWidgetFromXpm (win_main, (gchar **) xpm_copy),
			   (GtkSignalFunc) menu_Copy,
                           NULL);

    /*            ---------
     * --- Create | paste | button
     *            ---------
     */
    gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
			   "Paste", "Paste", "",
                           CreateWidgetFromXpm (win_main, (gchar **) xpm_paste),
			   (GtkSignalFunc) menu_Paste,
                           NULL);
}

#endif


