/*
 * Created on 17.12.2003
 *
 */
 
package LumiSoft.UI.Controls.WOutlookBar;

import java.awt.*;
import LumiSoft.UI.Controls.*;

/**
 * Outlookbar bar.
 */
public class Bar 
{	
	private String     m_Text             = "";
	private String     m_TextID           = "";
	private int        m_TextAlign        = HorizontalAlignment.Center;
	private int        m_ItemsTextAlign   = HorizontalAlignment.Center;
	private boolean    m_Visible          = true;
	private Font       m_Font             = null;
	private Object     m_Tag              = null;
	private Items      m_pItems           = null;
	private Font       m_ItemsFont        = null;
	private int        m_ItemsStyle       = ItemsStyle.UseDefault;
	private Bars       m_pBars            = null;   
	private Rectangle  m_BarRect;
	private Rectangle  m_BarClientRect;
	private int        m_FirstVisibleItem = 0;

	/**
	 * Default constructor.
	 * @param bars
	 */
	protected Bar(Bars bars)
	{
		m_pItems  = new Items(this);
		m_pBars   = bars;
	}

	
	protected void OnBarNeedsUpdate()
	{
		m_pBars.getWOutlookBar().UpdateAll();
	}


	/**
	 * Gets bar text.
	 * @return
	 */
	public String getText()
	{
		if(m_pBars.getWOutlookBar().getWText() != null && getTextID().length() > 0){
			return m_pBars.getWOutlookBar().getWText().get(getTextID());
		}
		else{
			return m_Text;
		}
	}
	/**
	 * Sets bar text.
	 * @param value
	 */
	public void setText(String value)
	{
		if(m_Text != value){
			m_Text = value;
			OnBarNeedsUpdate();
		}
	}
	
	/**
	 * Gets bar text ID.
	 * @return
	 */
	public String getTextID()
	{
		return m_TextID;
	}
	/**
	 * Sets bar text ID.
	 * @param value
	 */
	public void setTextID(String value)
	{
		if(m_TextID != value){
			m_TextID = value;
			OnBarNeedsUpdate();
		}
	}
	
	/**
	 * Gets bar text alignment.
	 * @return
	 */
	public int getTextAlign()
	{
		return m_TextAlign;
	}
	/**
	 * 
	 * @param value
	 */
	public void setTextAlign(int value)
	{
		if(m_TextAlign != value){
			m_TextAlign = value;
			OnBarNeedsUpdate();
		}
	}
	
	/**
	 * Gets if item is visible.
	 * @return
	 */
	public boolean getVisible()
	{
		return m_Visible;
	}
	/**
	 * Sets if item is visible.
	 * @param value
	 */
	public void setVisible(boolean value)
	{
		if(m_Visible != value){
			m_Visible = value;
		}
	}

	/**
	 * Gets bar tag.
	 * @return
	 */
	public Object getTag()
	{
		return m_Tag;
	}
	/**
	 * Sets bar tag.
	 * @param value
	 */
	public void setTag(Object value)
	{
		if(m_Tag != value){
			m_Tag = value;
		}
	}
	
	/**
	 * Gets bar text font.
	 * @return 
	 */
	public Font getFont()
	{
		if(m_Font == null){
			return m_pBars.getWOutlookBar().getFont();
		}
		else{
			return m_Font;
		}
	}
	/**
	 * Sets bar text font.
	 * @param value
	 */
	public void setFont(Font value)
	{
		if(m_Font != value){
			m_Font = value;
			OnBarNeedsUpdate();
		}
	}

	/**
	 * Gets bar index.
	 * @return
	 */
	public int getIndex()
	{
		return m_pBars.indexOf(this); 
	}

	/**
	 * Gets bar items collection.
	 * @return
	 */
	public Items getItems()
	{
		return m_pItems;
	}
	
	/**
	 * Gets bar items text alignment.
	 * @return
	 */
	public int getItemsTextAlign()
	{
		return m_ItemsTextAlign;
	}
	/**
	 * Gets bar items text alignmet.
	 * @param value
	 */
	public void setItemsTextAlign(int value)
	{
		if(m_ItemsTextAlign != value){
			m_ItemsTextAlign = value;
			OnBarNeedsUpdate();
		}
	}
	
	/**
	 * Gets bar itmes style.
	 * @return
	 */
	public int getItemsStyle()
	{		
		return m_ItemsStyle;
	}
	/**
	 * Set bar items style.
	 * @param value
	 */
	public void setItemsStyle(int value)
	{
		if(m_ItemsStyle != value){
			m_ItemsStyle = value;
			
			if(value == ItemsStyle.SmallIcon){
				m_ItemsTextAlign = HorizontalAlignment.Left;				
			}
			else{
				m_ItemsTextAlign = HorizontalAlignment.Center;
			}
			
			OnBarNeedsUpdate();
		}
	}

	/**
	 * Gets bar items text font.
	 * @return
	 */
	public Font getItemsFont()
	{
		if(m_ItemsFont == null){
			return m_pBars.getWOutlookBar().getFont();
		}
		else{
			return m_ItemsFont;
		}
	}
	/**
	 * Sets bar items text font.
	 * @param value
	 */
	public void setItemsFont(Font value)
	{
		if(m_ItemsFont != value){
			m_ItemsFont = value;
			OnBarNeedsUpdate();
		}
	}


	/**
	 * Gets bar items style. UseDefault is excluded. 
	 * @return
	 */
	public int getItemsStyleCurrent()
	{
		int itemStyle = this.getItemsStyle();
		//--- First load from ViewStyle
		if(this.getItemsStyle() == ItemsStyle.UseDefault){
			itemStyle = this.getBars().getWOutlookBar().getViewStyle().getBarItemsStyle();				
		}
	
		//--- If ViewStyle retuned UseDefault, set IconSelect as default
		if(itemStyle == ItemsStyle.UseDefault){
			itemStyle = ItemsStyle.IconSelect;
		}
		//-------------------------------------------//
		return itemStyle;		
	}

	public Rectangle getBarRect()
	{
		return m_BarRect;
	}
	public void setBarRect(Rectangle value)
	{
		if(m_BarRect != value){
			m_BarRect = value;
		}		
	}
	
	public Rectangle getBarClientRect()
	{
		return m_BarClientRect;
	}
	public void setBarClientRect(Rectangle value)
	{
		if(m_BarClientRect != value){
			m_BarClientRect = value;
		}		
	}
	
	public int getFirstVisibleIndex()
	{
		return m_FirstVisibleItem;
	}
	public void setFirstVisibleIndex(int value)
	{
		if(m_FirstVisibleItem != value){
			m_FirstVisibleItem = value;
		}		
	}
	
	public boolean getIsLastVisible()	
	{			
		if(this.getItems().getCount() < 1 || this.getBarClientRect().contains(((Item)(this.getItems().get(this.getItems().getCount() - 1))).getBounds())){
	//	if(this.getItems().size() < 1 || (this.getItems().get(this.Items.Count-1).getBounds(). < this.getBarClientRect().getY() + this.getBarClientRect().getWidth())){
			return true;
		}
		else{
			return false;
		}
	}
	
	public Bars getBars()
	{
		return m_pBars;
	}

}
