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 * FCKToolbarSpecialCombo Class: This is a "abstract" base class to be used 22 * by the special combo toolbar elements like font name, font size, paragraph format, etc... 23 * 24 * The following properties and methods must be implemented when inheriting from 25 * this class: 26 * - Property: CommandName [ The command name to be executed ] 27 * - Method: GetLabel() [ Returns the label ] 28 * - CreateItems( targetSpecialCombo ) [ Add all items in the special combo ] 29 */ 30 31var FCKToolbarSpecialCombo = function() 32{ 33 this.SourceView = false ; 34 this.ContextSensitive = true ; 35 //this._LastValue = null ; 36} 37 38 39FCKToolbarSpecialCombo.prototype.DefaultLabel = '' ; 40 41function FCKToolbarSpecialCombo_OnSelect( itemId, item ) 42{ 43 FCK.ToolbarSet.CurrentInstance.Commands.GetCommand( this.CommandName ).Execute( itemId, item ) ; 44} 45 46FCKToolbarSpecialCombo.prototype.Create = function( targetElement ) 47{ 48 this._Combo = new FCKSpecialCombo( this.GetLabel(), this.FieldWidth, this.PanelWidth, this.PanelMaxHeight, FCKBrowserInfo.IsIE ? window : FCKTools.GetElementWindow( targetElement ).parent ) ; 49 50 /* 51 this._Combo.FieldWidth = this.FieldWidth != null ? this.FieldWidth : 100 ; 52 this._Combo.PanelWidth = this.PanelWidth != null ? this.PanelWidth : 150 ; 53 this._Combo.PanelMaxHeight = this.PanelMaxHeight != null ? this.PanelMaxHeight : 150 ; 54 */ 55 56 //this._Combo.Command.Name = this.Command.Name; 57// this._Combo.Label = this.Label ; 58 this._Combo.Tooltip = this.Tooltip ; 59 this._Combo.Style = this.Style ; 60 61 this.CreateItems( this._Combo ) ; 62 63 this._Combo.Create( targetElement ) ; 64 65 this._Combo.CommandName = this.CommandName ; 66 67 this._Combo.OnSelect = FCKToolbarSpecialCombo_OnSelect ; 68} 69 70function FCKToolbarSpecialCombo_RefreshActiveItems( combo, value ) 71{ 72 combo.DeselectAll() ; 73 combo.SelectItem( value ) ; 74 combo.SetLabelById( value ) ; 75} 76 77FCKToolbarSpecialCombo.prototype.RefreshState = function() 78{ 79 // Gets the actual state. 80 var eState ; 81 82// if ( FCK.EditMode == FCK_EDITMODE_SOURCE && ! this.SourceView ) 83// eState = FCK_TRISTATE_DISABLED ; 84// else 85// { 86 var sValue = FCK.ToolbarSet.CurrentInstance.Commands.GetCommand( this.CommandName ).GetState() ; 87 88// FCKDebug.Output( 'RefreshState of Special Combo "' + this.TypeOf + '" - State: ' + sValue ) ; 89 90 if ( sValue != FCK_TRISTATE_DISABLED ) 91 { 92 eState = FCK_TRISTATE_ON ; 93 94 if ( this.RefreshActiveItems ) 95 this.RefreshActiveItems( this._Combo, sValue ) ; 96 else 97 { 98 if ( this._LastValue !== sValue) 99 { 100 this._LastValue = sValue ; 101 102 if ( !sValue || sValue.length == 0 ) 103 { 104 this._Combo.DeselectAll() ; 105 this._Combo.SetLabel( this.DefaultLabel ) ; 106 } 107 else 108 FCKToolbarSpecialCombo_RefreshActiveItems( this._Combo, sValue ) ; 109 } 110 } 111 } 112 else 113 eState = FCK_TRISTATE_DISABLED ; 114// } 115 116 // If there are no state changes then do nothing and return. 117 if ( eState == this.State ) return ; 118 119 if ( eState == FCK_TRISTATE_DISABLED ) 120 { 121 this._Combo.DeselectAll() ; 122 this._Combo.SetLabel( '' ) ; 123 } 124 125 // Sets the actual state. 126 this.State = eState ; 127 128 // Updates the graphical state. 129 this._Combo.SetEnabled( eState != FCK_TRISTATE_DISABLED ) ; 130} 131 132FCKToolbarSpecialCombo.prototype.Enable = function() 133{ 134 this.RefreshState() ; 135} 136 137FCKToolbarSpecialCombo.prototype.Disable = function() 138{ 139 this.State = FCK_TRISTATE_DISABLED ; 140 this._Combo.DeselectAll() ; 141 this._Combo.SetLabel( '' ) ; 142 this._Combo.SetEnabled( false ) ; 143} 144