//*****************************************************************************************
// Truevision - a 3d modeler for gnome and povray
//
// toolbar.cc
//
// Vincent LE PRINCE <vincentleprince@users.sourceforge.net>
// Copyright (C) 2000-2001 Vincent LE PRINCE
// This file is part of the TRUEVISION Package

//   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 "include/toolbar.h"
#include "include/preferences.h"
#include "include/scene.h"
#include "include/povfe.h"
#include "include/undo.h"
#include "include/dlgutils.h"

ToolBar::ToolBar( app_objs* appref, GtkWidget *app )
{
app_ref = appref;
appref->toolbar = this;
PREF_DEF
UNDO_DEF
SCENE_DEF
pmode_loc = TV_PMODE_CUSTOM;
mode_change = false;
	
char *trackball = tv_get_pixmap( "trackball_icon.png" );
char *select = tv_get_pixmap( "select_icon.png" );
char *scale = tv_get_pixmap( "scale_icon.png" );
char *rotate = tv_get_pixmap( "rotate_icon.png" );
char *move = tv_get_pixmap( "move_icon.png" );

// TOOLBAR
static GnomeUIInfo toolbar_info[] = {
	// File
	GNOMEUIINFO_ITEM_STOCK( N_("Quit"), _("Quit"), app_exit, GNOME_STOCK_PIXMAP_QUIT ),
	{ GNOME_APP_UI_ITEM, N_("New"), N_("New scene"), (void*)sign_scene_new, app_ref->scene, NULL, GNOME_APP_PIXMAP_STOCK,GNOME_STOCK_PIXMAP_NEW, 0, (GdkModifierType)0, NULL },
//	GNOMEUIINFO_ITEM_STOCK( N_("Open"), _("Open"), app_exit, GNOME_STOCK_PIXMAP_OPEN ),
	{ GNOME_APP_UI_ITEM, N_("Open"), N_("Load scene"), (void*)sign_scene_load, app_ref->scene, NULL, GNOME_APP_PIXMAP_STOCK,GNOME_STOCK_PIXMAP_OPEN, 0, (GdkModifierType)0, NULL },	
	{ GNOME_APP_UI_ITEM, N_("Save"), N_("Save the scene"), (void*)sign_scene_save, app_ref->scene, NULL, GNOME_APP_PIXMAP_STOCK,GNOME_STOCK_PIXMAP_SAVE, 0, (GdkModifierType)0, NULL },

	// Edition
	GNOMEUIINFO_SEPARATOR,
	/*GNOMEUIINFO_ITEM_STOCK( N_("Cut"), _("Cut"), app_exit, GNOME_STOCK_PIXMAP_CUT ),
	GNOMEUIINFO_ITEM_STOCK( N_("Copy"), _("Copy"), app_exit, GNOME_STOCK_PIXMAP_COPY ),
	GNOMEUIINFO_ITEM_STOCK( N_("Paste"), _("Paste"), app_exit, GNOME_STOCK_PIXMAP_PASTE ),*/
	{ GNOME_APP_UI_ITEM, N_("Undo"), N_("Undo"), (void*)sign_undoman_undo, app_ref->undoman, NULL, GNOME_APP_PIXMAP_STOCK,GNOME_STOCK_PIXMAP_UNDO, 0, (GdkModifierType)0, NULL },
	{ GNOME_APP_UI_ITEM, N_("Redo"), N_("Redo"), (void*)sign_undoman_redo, app_ref->undoman, NULL, GNOME_APP_PIXMAP_STOCK,GNOME_STOCK_PIXMAP_REDO, 0, (GdkModifierType)0, NULL },

	// Rendering
	GNOMEUIINFO_SEPARATOR,	
	{ GNOME_APP_UI_ITEM, N_("Scene"), N_("Edit scene parameters"), (void*)sign_options_box, app_ref->povfe, NULL, GNOME_APP_PIXMAP_STOCK,GNOME_STOCK_PIXMAP_PROPERTIES, 0, (GdkModifierType)0, NULL },
	{ GNOME_APP_UI_ITEM, N_("Render"), N_("Render the scene"), (void*)sign_render_box, app_ref->povfe, NULL, GNOME_APP_PIXMAP_STOCK,GNOME_STOCK_PIXMAP_EXEC, 0, (GdkModifierType)0, NULL },

	// Modes de Pointage
	GNOMEUIINFO_SEPARATOR,
	{ GNOME_APP_UI_TOGGLEITEM, N_("Trackball"), N_("Trackball"), (void*)chg_pmode, this, NULL, GNOME_APP_PIXMAP_FILENAME, trackball, 0, (GdkModifierType)0, NULL },
	//{ GNOME_APP_UI_TOGGLEITEM, N_("Create"), N_("Create"), (void*)chg_pmode, this, NULL, GNOME_APP_PIXMAP_FILENAME, "truevision/create_icon.png", 0, (GdkModifierType)0, NULL },	
	{ GNOME_APP_UI_TOGGLEITEM, N_("Select"), N_("Select"), (void*)chg_pmode, this, NULL, GNOME_APP_PIXMAP_FILENAME, select, 0, (GdkModifierType)0, NULL },	
	//{ GNOME_APP_UI_TOGGLEITEM, N_("UScale"), N_("UScale"), (void*)chg_pmode, this, NULL, GNOME_APP_PIXMAP_FILENAME, "truevision/uscale_icon.png", 0, (GdkModifierType)0, NULL },		
	{ GNOME_APP_UI_TOGGLEITEM, N_("Scale"), N_("Scale"), (void*)chg_pmode, this, NULL, GNOME_APP_PIXMAP_FILENAME, scale, 0, (GdkModifierType)0, NULL },		
	{ GNOME_APP_UI_TOGGLEITEM, N_("Rotate"), N_("Rotate"), (void*)chg_pmode, this, NULL, GNOME_APP_PIXMAP_FILENAME, rotate, 0, (GdkModifierType)0, NULL },		
	{ GNOME_APP_UI_TOGGLEITEM, N_("Move"), N_("Move"), (void*)chg_pmode, this, NULL, GNOME_APP_PIXMAP_FILENAME, move, 0, (GdkModifierType)0, NULL },	

	// Aide
	GNOMEUIINFO_SEPARATOR,
	GNOMEUIINFO_ITEM_STOCK( N_("Help"), _("Help"), about, GNOME_STOCK_PIXMAP_HELP ),	
	GNOMEUIINFO_END
	};
	

// Création
toolbar = gtk_toolbar_new();
gtk_toolbar_set_orientation( GTK_TOOLBAR(toolbar),	GTK_ORIENTATION_HORIZONTAL );
gtk_toolbar_set_style( GTK_TOOLBAR(toolbar), 	pref->toolbar_text->value() ? GTK_TOOLBAR_BOTH : GTK_TOOLBAR_ICONS );
gnome_app_fill_toolbar( GTK_TOOLBAR(toolbar), toolbar_info, NULL );
gnome_app_set_toolbar( GNOME_APP(app), GTK_TOOLBAR(toolbar) );// "Truevision toolbar", NULL, NULL, NULL, NULL, NULL );
gtk_toolbar_set_tooltips( GTK_TOOLBAR(toolbar), pref->tooltips->value() );
//gnome_app_create_toolbar( GNOME_APP(app), toolbar_info );
	
// Récupération des widgets
const int tb_offset = 11;
int j = tb_offset;
undoman->set_undo_tb_widgets(  toolbar_info[5].widget,  toolbar_info[6].widget );
scene->set_save_tb_widget( toolbar_info[3].widget );
gtk_widget_set_sensitive(  toolbar_info[3].widget, FALSE );
for ( register int i = 0 ; i < MAX_TBPMODE_BUT ; i++ )
	pmode_wid[i] = toolbar_info[j++].widget;

delete trackball;
delete rotate;
delete scale;
delete move;
delete select;
}

//****************************************************
// Pref changed
//****************************************************
void ToolBar::pref_changed()
{
PREF_DEF
gtk_toolbar_set_style( GTK_TOOLBAR(toolbar), pref->toolbar_text->value() ? GTK_TOOLBAR_BOTH : GTK_TOOLBAR_ICONS );
gtk_toolbar_set_tooltips( GTK_TOOLBAR(toolbar), pref->tooltips->value() );
}

//*****************************************************
// Change pointer mode
//*****************************************************
void ToolBar::change_pmode( PointerMode pmode )
{
pmode_loc = pmode;
mode_change = true;
for ( int i = 0 ; i < MAX_TBPMODE_BUT ; i++ )
	gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(pmode_wid[i]), ( i == pmode_loc ) ? TRUE : FALSE );
mode_change = false;
}

void ToolBar::change_pmode_cb( GtkWidget *wid )
{
if ( mode_change ) return;
for ( int i = 0 ; i < MAX_TBPMODE_BUT ; i++ )
	if ( GTK_TOGGLE_BUTTON(pmode_wid[i])->active && i != pmode_loc ) { pmode_loc = (PointerMode)i; break; }

VMAN_DEF
vmanager->set_pointer_mode( pmode_loc );
}
