Index: FCKeditor/trunk/editor/_source/classes/fcktoolbarstylecombo.js
===================================================================
--- FCKeditor/trunk/editor/_source/classes/fcktoolbarstylecombo.js	(revision 714)
+++ FCKeditor/trunk/editor/_source/classes/fcktoolbarstylecombo.js	(revision 774)
@@ -24,9 +24,12 @@
 var FCKToolbarStyleCombo = function( tooltip, style )
 {
+	if ( tooltip === false )
+		return ;
+
 	this.CommandName = 'Style' ;
 	this.Label		= this.GetLabel() ;
 	this.Tooltip	= tooltip ? tooltip : this.Label ;
 	this.Style		= style ? style : FCK_TOOLBARITEM_ICONTEXT ;
-	
+
 	this.DefaultLabel = FCKConfig.DefaultStyleLabel || '' ;
 }
@@ -35,6 +38,4 @@
 FCKToolbarStyleCombo.prototype = new FCKToolbarSpecialCombo ;
 
-FCKToolbarStyleCombo.prototype.TypeOf = 'FCKToolbarStyleCombo' ;		// @Packager.RemoveLine
-
 FCKToolbarStyleCombo.prototype.GetLabel = function()
 {
@@ -42,70 +43,156 @@
 }
 
+FCKToolbarStyleCombo.prototype.GetStyles = function()
+{
+	var styles = {} ;
+	var allStyles = FCK.ToolbarSet.CurrentInstance.Styles.GetStyles() ;
+
+	for ( var styleName in allStyles )
+	{
+		var style = allStyles[ styleName ] ;
+		if ( !style.IsCore )
+			styles[ styleName ] = style ;
+	}
+	return styles ;
+}
+
 FCKToolbarStyleCombo.prototype.CreateItems = function( targetSpecialCombo )
 {
-	var oTargetDoc = targetSpecialCombo._Panel.Document ;
+	var targetDoc = targetSpecialCombo._Panel.Document ;
 
 	// Add the Editor Area CSS to the panel so the style classes are previewed correctly.
-	FCKTools.AppendStyleSheet( oTargetDoc, FCKConfig.ToolbarComboPreviewCSS ) ;
-	FCKTools.AppendStyleString( oTargetDoc, FCKConfig.EditorAreaStyles ) ;
-	oTargetDoc.body.className += ' ForceBaseFont' ;
+	FCKTools.AppendStyleSheet( targetDoc, FCKConfig.ToolbarComboPreviewCSS ) ;
+	FCKTools.AppendStyleString( targetDoc, FCKConfig.EditorAreaStyles ) ;
+	targetDoc.body.className += ' ForceBaseFont' ;
 
-	// Add ID and Class to the body
-	FCKConfig.ApplyBodyAttributes( oTargetDoc.body ) ;
+	// Add ID and Class to the body.
+	FCKConfig.ApplyBodyAttributes( targetDoc.body ) ;
 
-	// For some reason Gecko is blocking inside the "RefreshVisibleItems" function.
-	// The problem is present only in old versions
-	if ( !( FCKBrowserInfo.IsGecko && FCKBrowserInfo.IsGecko10 ) )
-		targetSpecialCombo.OnBeforeClick = this.RefreshVisibleItems ;
+	// Get the styles list.
+	var styles = this.GetStyles() ;
 
-	// Add the styles to the special combo.
-	var aCommandStyles = FCK.ToolbarSet.CurrentInstance.Commands.GetCommand( this.CommandName ).Styles ;
-	for ( var s in aCommandStyles )
+	for ( var styleName in styles )
 	{
-		var oStyle = aCommandStyles[s] ;
-		var oItem ;
+		var style = styles[ styleName ] ;
 
-		if ( oStyle.IsObjectElement )
-			oItem = targetSpecialCombo.AddItem( s, s ) ;
-		else
-			oItem = targetSpecialCombo.AddItem( s, oStyle.GetOpenerTag() + s + oStyle.GetCloserTag() ) ;
+		// Object type styles have no preview.
+		var caption = style.GetType() == FCK_STYLE_OBJECT ? 
+			styleName : 
+			FCKToolbarStyleCombo_BuildPreview( style, style.Label || styleName ) ;
+	
+		var item = targetSpecialCombo.AddItem( styleName, caption ) ;
 
-		oItem.Style = oStyle ;
+		item.Style = style ;
 	}
+
+	// We must prepare the list before showing it.
+	targetSpecialCombo.OnBeforeClick = this.StyleCombo_OnBeforeClick ;
 }
 
 FCKToolbarStyleCombo.prototype.RefreshActiveItems = function( targetSpecialCombo )
 {
-	// Clear the actual selection.
+	var startElement = FCKSelection.GetBoundaryParentElement( true ) ;
+
+	if ( startElement )
+	{
+		var path = new FCKElementPath( startElement ) ;
+		var elements = path.Elements ;
+
+		for ( var e = 0 ; e < elements.length ; e++ )
+		{
+			for ( var i in targetSpecialCombo.Items )
+			{
+				var item = targetSpecialCombo.Items[i] ;
+				var style = item.Style ;
+
+				if ( style.CheckElementRemovable( elements[ e ] ) )
+				{
+					targetSpecialCombo.SetLabel( style.Label || style.Name ) ;
+					return ;
+				}
+			}
+		}
+	}
+
+	targetSpecialCombo.SetLabel( this.DefaultLabel ) ;
+}
+
+FCKToolbarStyleCombo.prototype.StyleCombo_OnBeforeClick = function( targetSpecialCombo )
+{
+	// Two things are done here:
+	//	- In a control selection, get the element name, so we'll display styles
+	//	  for that element only.
+	//	- Select the styles that are active for the current selection.
+	
+	// Clear the current selection.
 	targetSpecialCombo.DeselectAll() ;
 
-	// Get the active styles.
-	var aStyles = FCK.ToolbarSet.CurrentInstance.Commands.GetCommand( this.CommandName ).GetActiveStyles() ;
-
-	if ( aStyles.length > 0 )
+	var startElement ;
+	var path ;
+	var tagName ;
+	
+	if ( FCKSelection.GetType() == 'Control' )
 	{
-		// Select the active styles in the combo.
-		for ( var i = 0 ; i < aStyles.length ; i++ )
-			targetSpecialCombo.SelectItem( aStyles[i].Name ) ;
-
-		// Set the combo label to the first style in the collection.
-		targetSpecialCombo.SetLabelById( aStyles[0].Name ) ;
+		startElement = FCKSelection.GetSelectedElement() ;
+		tagName = startElement.nodeName.toLowerCase() ;
 	}
 	else
-		targetSpecialCombo.SetLabel(this.DefaultLabel) ;
-}
-
-FCKToolbarStyleCombo.prototype.RefreshVisibleItems = function( targetSpecialCombo )
-{
-	if ( FCKSelection.GetType() == 'Control' )
-		var sTagName = FCKSelection.GetSelectedElement().tagName ;
+	{
+		startElement = FCKSelection.GetBoundaryParentElement( true ) ;
+		path = new FCKElementPath( startElement ) ;
+	}
 
 	for ( var i in targetSpecialCombo.Items )
 	{
-		var oItem = targetSpecialCombo.Items[i] ;
-		if ( ( sTagName && oItem.Style.Element == sTagName ) || ( ! sTagName && ! oItem.Style.IsObjectElement ) )
-			oItem.style.display = '' ;
+		var item = targetSpecialCombo.Items[i] ;
+		var style = item.Style ;
+		
+		if ( ( tagName && style.Element == tagName ) || ( !tagName && style.GetType() != FCK_STYLE_OBJECT ) )
+		{
+			item.style.display = '' ;
+
+			if ( ( path && style.CheckActive( path ) ) || ( !path && style.CheckElementRemovable( startElement, true ) ) )
+				targetSpecialCombo.SelectItem( style.Name ) ;
+		}
 		else
-			oItem.style.display = 'none' ;	// For some reason Gecko is blocking here.
+			item.style.display = 'none' ;
 	}
 }
+
+function FCKToolbarStyleCombo_BuildPreview( style, caption ) 
+{
+	var styleType = style.GetType() ;
+	var html = [] ;
+	
+	if ( styleType == FCK_STYLE_BLOCK )
+		html.push( '<div class="BaseFont">' ) ;
+	
+	var elementName = style.Element ;
+	
+	// Avoid <bdo> in the preview.
+	if ( elementName == 'bdo' )
+		elementName = 'span' ;
+
+	html = [ '<', elementName ] ;
+
+	// Assign all defined attributes.
+	var attribs	= style._StyleDesc.Attributes ;
+	if ( attribs )
+	{
+		for ( var att in attribs )
+		{
+			html.push( ' ', att, '="', style.GetFinalAttributeValue( att ), '"' ) ;
+		}
+	}
+
+	// Assign the style attribute.
+	if ( style._GetStyleText().length > 0 )
+		html.push( ' style="', style.GetFinalStyleValue(), '"' ) ;
+
+	html.push( '>', caption, '</', elementName, '>' ) ;
+
+	if ( styleType == FCK_STYLE_BLOCK )
+		html.push( '</div>' ) ;
+
+	return html.join( '' ) ;
+}
