1/*
2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
3 * Copyright (C) 2003-2007 Frederico Caldeira Knabben
4 *
5 * == BEGIN LICENSE ==
6 *
7 * Licensed under the terms of any of the following licenses at your
8 * choice:
9 *
10 *  - GNU General Public License Version 2 or later (the "GPL")
11 *    http://www.gnu.org/licenses/gpl.html
12 *
13 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14 *    http://www.gnu.org/licenses/lgpl.html
15 *
16 *  - Mozilla Public License Version 1.1 or later (the "MPL")
17 *    http://www.mozilla.org/MPL/MPL-1.1.html
18 *
19 * == END LICENSE ==
20 *
21 * FCKToolbarButton Class: represents a button in the toolbar.
22 */
23
24var FCKToolbarButton = function( commandName, label, tooltip, style, sourceView, contextSensitive, icon )
25{
26	this.CommandName		= commandName ;
27	this.Label				= label ;
28	this.Tooltip			= tooltip ;
29	this.Style				= style ;
30	this.SourceView			= sourceView ? true : false ;
31	this.ContextSensitive	= contextSensitive ? true : false ;
32
33	if ( icon == null )
34		this.IconPath = FCKConfig.SkinPath + 'toolbar/' + commandName.toLowerCase() + '.gif' ;
35	else if ( typeof( icon ) == 'number' )
36		this.IconPath = [ FCKConfig.SkinPath + 'fck_strip.gif', 16, icon ] ;
37	else
38		this.IconPath = icon ;
39}
40
41FCKToolbarButton.prototype.Create = function( targetElement )
42{
43	this._UIButton = new FCKToolbarButtonUI( this.CommandName, this.Label, this.Tooltip, this.IconPath, this.Style ) ;
44	this._UIButton.OnClick = this.Click ;
45	this._UIButton._ToolbarButton = this ;
46	this._UIButton.Create( targetElement ) ;
47}
48
49FCKToolbarButton.prototype.RefreshState = function()
50{
51	// Gets the actual state.
52	var eState = FCK.ToolbarSet.CurrentInstance.Commands.GetCommand( this.CommandName ).GetState() ;
53
54	// If there are no state changes than do nothing and return.
55	if ( eState == this._UIButton.State ) return ;
56
57	// Sets the actual state.
58	this._UIButton.ChangeState( eState ) ;
59}
60
61FCKToolbarButton.prototype.Click = function()
62{
63	var oToolbarButton = this._ToolbarButton || this ;
64	FCK.ToolbarSet.CurrentInstance.Commands.GetCommand( oToolbarButton.CommandName ).Execute() ;
65}
66
67FCKToolbarButton.prototype.Enable = function()
68{
69	this.RefreshState() ;
70}
71
72FCKToolbarButton.prototype.Disable = function()
73{
74	// Sets the actual state.
75	this._UIButton.ChangeState( FCK_TRISTATE_DISABLED ) ;
76}