<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># Copyright (C) 2007-13  Stephane Galland &lt;galland@arakhne.org&gt;
#
# 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; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

=pod

=head1 NAME

AutoLaTeX::GUI::Gtk::Window - A GTK user interface

=head1 DESCRIPTION

AutoLaTeX::GUI::Gtk::Window is a Perl module, which permits to
display a Gtk user interface for AutoLaTeX.

=head1 SYNOPSYS

AutoLaTeX::GUI::Gtk-&gt;new() ;

=head1 METHOD DESCRIPTIONS

This section contains only the methods in Gtk.pm itself.

=over

=cut

package AutoLaTeX::GUI::Gtk::Window;

our @ISA = qw( AutoLaTeX::GUI::Gtk::WidgetUtil AutoLaTeX::GUI::AbstractGUI Gtk2::Window );
our @EXPORT = qw();
our @EXPORT_OK = qw();

require 5.014;
use strict;
use utf8;
use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION);
use Exporter;

use Glib qw(TRUE FALSE);
use Gtk2 qw/-init -threads-init/;

use AutoLaTeX::Core::Util;
use AutoLaTeX::Core::IntUtils;
use AutoLaTeX::GUI::AbstractGUI;
use AutoLaTeX::GUI::Gtk::WidgetUtil;
use AutoLaTeX::GUI::Gtk::ToolPanel;
use AutoLaTeX::GUI::Gtk::GeneralPanel;
use AutoLaTeX::GUI::Gtk::TranslatorPanel;

#------------------------------------------------------
#
# Global vars
#
#------------------------------------------------------

# Version number
my $VERSION = "7.0" ;

#------------------------------------------------------
#
# Functions
#
#------------------------------------------------------

=pod

=item * new(\%\%\%\%)

Contructor.

Parameters are:

=over 4

=item the current configuration extracted from the configuration files.

=item the system configuration extracted from the configuration file.

=item the user configuration extracted from the configuration file.

=item the project configuration extracted from the configuration file.

=back

=cut
sub new(\%\%\%\%) : method {
	my $proto = shift;
	my $class = ref($proto) || $proto;

	my $self = bless($class-&gt;SUPER::new('toplevel'), $class) ;

	die("The first parameter of AutoLaTeX::GUI::Gtk::Window::new() should be a hastable\nIf you pass a %v variable, please use the \%v syntax instead.\n")
		unless ((!defined($_[0]))||(isHash($_[0])));
	$self-&gt;attr('CONFIGURATIONS','FULL') = $_[0];

	die("The second parameter of AutoLaTeX::GUI::Gtk::Window::new() should be a hastable\nIf you pass a %v variable, please use the \%v syntax instead.\n")
		unless ((!defined($_[1]))||(isHash($_[1])));
	$self-&gt;attr('CONFIGURATIONS','SYSTEM') = $_[1];

	die("The third parameter of AutoLaTeX::GUI::Gtk::Window::new() should be a hastable\nIf you pass a %v variable, please use the \%v syntax instead.\n")
		unless ((!defined($_[2]))||(isHash($_[2])));
	$self-&gt;attr('CONFIGURATIONS','USER') = $_[2];

	die("The forth parameter of AutoLaTeX::GUI::Gtk::Window::new() should be a hastable\nIf you pass a %v variable, please use the \%v syntax instead.\n")
		unless ((!defined($_[3]))||(isHash($_[3])));
	$self-&gt;attr('CONFIGURATIONS','PROJECT') = $_[3];

	#Â&nbsp;Set the windows attributes
	$self-&gt;set_title (formatText(_T("AutoLaTeX {}"),getAutoLaTeXVersion()));
	$self-&gt;connectSignal($self,'delete-event','onQuit');

	return $self;
}

=pod

=item * setAdminUser($)

Set if the current user is an administrator.

=cut
sub setAdminUser($) : method {
	my $self = shift;
	$self-&gt;SUPER::setAdminUser($_[0]);
	my $title = $self-&gt;get_title ();
	if ($title =~ /^(.*?)\s*\*ADMINISTRATOR\*\s*$/) {
		$title = "$1";
	}
	if ($_[0]) {
		$title .= " "._T("*ADMINISTRATOR*");
	}
	$self-&gt;set_title ("$title");
}

=pod

=item * makeNotebookTab($$)

Replies the GTK component that could be used a a label inside notebook tabs.

=over 4

=item the label of the tab

=item the icon of the tab

=back

=cut
sub makeNotebookTab($$) : method {
	my $self = shift;
	my $tabname = shift;

	my $hbox = Gtk2::HBox-&gt;new (FALSE,2);

	my $iconwgt;

	if (@_&gt;1) {
		my $icon = $self-&gt;getIcon (shift);
		my $animation = Gtk2::Gdk::PixbufSimpleAnim-&gt;new (
					$icon-&gt;get_width (),
					$icon-&gt;get_height (),
					1); #Â&nbsp;Rate in fps
		$animation-&gt;add_frame ($icon);
		foreach my $iconName (@_) {
			$icon = $self-&gt;getIcon ($iconName);
			$animation-&gt;add_frame ($icon);
		}
		$iconwgt = Gtk2::Image-&gt;new_from_animation ($animation);
	}
	else {
		$iconwgt = Gtk2::Image-&gt;new_from_pixbuf ($self-&gt;getIcon ($_[0]));
	}

	$hbox-&gt;add ($iconwgt);

	my $labelwgt = Gtk2::Label-&gt;new ($tabname);
	$hbox-&gt;add ($labelwgt);
	$hbox-&gt;show_all ();

	return $hbox;
}

=pod

=item * savePanelContents()

Save the content of the panels.

=cut
sub savePanelContents() : method {
	my $self = shift;
	my $tab;
	my @panels = (
			'translatorConfiguration',
			'systemConfiguration',
			'userConfiguration',
			'projectConfiguration',
			'toolPanel',
	);
	foreach my $k (@panels) {
		$tab = $self-&gt;attr('NOTEBOOK_PANEL',"$k");
		if (($tab)&amp;&amp;($tab-&gt;can('savePanelContent'))) {
			$tab-&gt;savePanelContent()
		}
	}
}

=pod

=item * initializeDialogContent()

Initializing the dialog content before displaying.

=cut
sub initializeDialogContent() : method {
	my $self = shift;

	$self-&gt;SUPER::initializeDialogContent();

	#Â&nbsp;Main layout
	my $mainLayout = Gtk2::Table-&gt;new (
						2, #rows
						1, #columns
						FALSE); #non uniform
	$self-&gt;add ($mainLayout);
	
	# Initialize the panel notebook
	my $notebook = Gtk2::Notebook-&gt;new ();
	$self-&gt;attr('NOTEBOOK') = $notebook;
	$mainLayout-&gt;attach ($notebook, 
				0,1,0,1, # left, right, top and bottom columns
				['fill','expand'],['fill','expand'], # x and y options
				5,5); # horizontal and vertical paddings
	$self-&gt;connectSignal($notebook,'switch-page','onNotebookPageChanged');	

	# Close button
	my $buttonAlignment = Gtk2::HButtonBox-&gt;new ();
	$buttonAlignment-&gt;set_layout('end');

	my $closeButton = Gtk2::Button-&gt;new_from_stock ('gtk-close');
	$self-&gt;connectSignal($closeButton,'clicked','onQuit');
	$buttonAlignment-&gt;add ($closeButton);

	$mainLayout-&gt;attach ($buttonAlignment, 
				0,1,1,2, # left, right, top and bottom columns
				['fill','expand'],'shrink', # x and y options
				5,5); # horizontal and vertical paddings

	# Open the tool panel
	my $toolTab = AutoLaTeX::GUI::Gtk::ToolPanel-&gt;new ($self-&gt;attr('CONFIGURATIONS','FULL'));
	$toolTab-&gt;setAdminUser( $self-&gt;isAdminUser() );
	$self-&gt;attr('NOTEBOOK_PANEL','toolPanel') = $toolTab;
	$notebook-&gt;append_page($toolTab, $self-&gt;makeNotebookTab(
				_T("Tools"), "tools.png"));

	# Open the project configuration
	if ($self-&gt;hasProject ()) {
		my $projectConfTab = AutoLaTeX::GUI::Gtk::GeneralPanel-&gt;new (
					$self-&gt;attr('CONFIGURATIONS','PROJECT'),
					'getProjectConfigFilename');
		$projectConfTab-&gt;setAdminUser( $self-&gt;isAdminUser() );
		$self-&gt;attr('NOTEBOOK_PANEL','projectConfiguration') = $projectConfTab;
		$notebook-&gt;append_page($projectConfTab, $self-&gt;makeNotebookTab(
				_T("Project Configuration"), "projectLevel.png"));
	}

	#Â&nbsp;Create the user configuration panel
	my $userConfTab = AutoLaTeX::GUI::Gtk::GeneralPanel-&gt;new (
					$self-&gt;attr('CONFIGURATIONS','USER'),
					'getUserConfigFilename');
	$userConfTab-&gt;setAdminUser( $self-&gt;isAdminUser() );
	$self-&gt;attr('NOTEBOOK_PANEL','userConfiguration') = $userConfTab;
	$notebook-&gt;append_page($userConfTab, $self-&gt;makeNotebookTab(
				_T("User Configuration"), "userLevel.png"));

	# Open the system configuration only if root
	if ($self-&gt;isAdminUser ()) {
		my $systemConfTab = AutoLaTeX::GUI::Gtk::GeneralPanel-&gt;new (
						$self-&gt;attr('CONFIGURATIONS','SYSTEM'),
						'getSystemConfigFilename');
		$systemConfTab-&gt;setAdminUser( $self-&gt;isAdminUser() );
		$self-&gt;attr('NOTEBOOK_PANEL','systemConfiguration') = $systemConfTab;
		$notebook-&gt;append_page($systemConfTab, $self-&gt;makeNotebookTab(
				_T("System Configuration"), "systemLevel.png"));
	}

	#Â&nbsp;Create the translator panel
	my $translatorTab = AutoLaTeX::GUI::Gtk::TranslatorPanel-&gt;new (
				$self-&gt;attr('CONFIGURATIONS','FULL'),
				$self-&gt;attr('CONFIGURATIONS','SYSTEM'),
				$self-&gt;attr('CONFIGURATIONS','USER'),
				$self-&gt;attr('CONFIGURATIONS','PROJECT'),
				$self);
	$translatorTab-&gt;setAdminUser( $self-&gt;isAdminUser() );
	$self-&gt;attr('NOTEBOOK_PANEL','translatorConfiguration') = $translatorTab;

}

=pod

=item * doLoop()

Do the GUI interaction loop. It means that the dialog
must be displayed now and ready for interaction.

=cut
sub doLoop() : method {
	my $self = shift;
	$self-&gt;show_all;
	my $quit = FALSE;
	my $lastmsg = '';
	resetQuitGtkFlag();
	while (!mustQuitGtk()) {
		while (Gtk2-&gt;events_pending()) {
			Gtk2-&gt;main_iteration();
		}
		notifySystemCommandListeners();
	}

}

=pod

=item * destroyDialogContent()

Destroying the dialog content after the application was quitted.

=cut
sub destroyDialogContent() : method {
	my $self = shift;

	$self-&gt;savePanelContents();

	$self-&gt;SUPER::destroyDialogContent();
}

=pod

=item * onTranslatorPanelStateChanged($$)

Invoked when the translator panel has its state changed.

=cut
sub onTranslatorPanelStateChanged($$) {
	my $self = shift;
	my $panel = shift;
	my $conflict = shift;

	my $tabTitle;
	if ($conflict) {
		$tabTitle = $self-&gt;makeNotebookTab(_T("Translators"), "translators_err.png", "translators.png", "translators_err.png", "translators.png", "translators_err.png", "translators.png", "translators_err.png");
	}
	else {
		$tabTitle = $self-&gt;makeNotebookTab(_T("Translators"), "translators.png");
	}

	if ($self-&gt;hasattr('NOTEBOOK_PANEL','translatorConfiguration')) {
		$self-&gt;attr('NOTEBOOK')-&gt;set_tab_label (
				$panel,
				$tabTitle);
	}
	else {
		$self-&gt;attr('NOTEBOOK')-&gt;append_page(
				$panel,
				$tabTitle);
	}
}

=pod

=item * onTranslatorPanelStateChanged($$)

Invoked when the translator panel has its state changed.

=cut
sub onNotebookPageChanged($$) {
	my $self = shift;
	my $notebook = $_[0];
	my $newpagenum = $_[2]|| 0;
	my $oldpagenum = $notebook-&gt;get_current_page ();
	if ($oldpagenum&gt;=0) {
		my $pageObj = $notebook-&gt;get_nth_page ($oldpagenum);
		if ($pageObj-&gt;can('savePanelContent')) {
			printDbgFor(3,_T("Saving hidden notebook panel"));
			$pageObj-&gt;savePanelContent ();
		}
	}
}

1;
__END__

=back

=head1 COPYRIGHT

(c) Copyright 2007-13 Stephane Galland E&lt;lt&gt;galland@arakhne.orgE&lt;gt&gt;, under GPL.

=head1 AUTHORS

=over

=item *

Conceived and initially developed by StÃ©phane Galland E&lt;lt&gt;galland@arakhne.orgE&lt;gt&gt;.

=back

=head1 SEE ALSO

L&lt;autolatex&gt;
</pre></body></html>