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

/**
 * Outlookbar item.
 */
public class Item 
{
	private String    m_Text       = "";
	private String    m_TextID     = "";
	private Object    m_Tag        = null;
	private int       m_ImageIndex = -1;
	private boolean   m_Enabled    = true;
	private boolean   m_Visible    = true; 
	private boolean   m_AllowStuck = true;
	private Items     m_pItems     = null;
	private Rectangle m_Bounds;
	
	/**
	 * Default constructor.
	 * @param items
	 */
	public Item(Items items)
	{
		m_pItems     = items;
		m_AllowStuck = this.getWOutlookBar().getAllowItemsStuck();
		m_Bounds     = new Rectangle(-1,-1,0,0);
	}

	
	/**
	 * Gets item text.
	 * @return
	 */
	public String getText()
	{
		if(m_pItems.getBar().getBars().getWOutlookBar().getWText() != null && getTextID().length() > 0){
			return m_pItems.getBar().getBars().getWOutlookBar().getWText().get(getTextID());
		}
		else{
			return m_Text;
		}
	}
	/**
	 * Sets item text.
	 * @param value
	 */
	public void setText(String value)
	{
		if(m_Text != value){
			m_Text = value;
						
			getWOutlookBar().UpdateAll();
		}
	}
	
	/**
	 * Gets item text ID.
	 * @return
	 */
	public String getTextID()
	{
		return m_TextID;
	}
	/**
	 * Sets item text ID.
	 * @param value
	 */
	public void setTextID(String value)
	{
		if(m_TextID != value){
			m_TextID = value;
			
			getWOutlookBar().UpdateAll();
		}
	}
	
	/**
	 * Gets if item enabled.
	 * @return
	 */
	public boolean getEnabled()
	{
		return m_Enabled;
	}
	/**
	 * Sets if item enabled.
	 * @param value
	 */
	public void setEnabled(boolean value)
	{
		if(m_Enabled != value){
			m_Enabled = value;
			
			getWOutlookBar().UpdateAll();
		}
	}
	
	/**
	 * Gets if item is visible.
	 * @return
	 */
	public boolean getVisible()
	{
		return m_Visible;
	}
	/**
	 * Sets if item visible.
	 * @param value
	 */
	public void setVisible(boolean value)
	{
		if(m_Visible = value){
			m_Visible = value;
			
			getWOutlookBar().UpdateAll();
		}
	}
	
	/**
	 * Gets item tag.
	 * @return
	 */
	public Object getTag()
	{
		return m_Tag;
	}
	/**
	 * Sets item tag.
	 * @param value
	 */
	public void setTag(Object value)
	{
		if(m_Tag != value){
			m_Tag = value;
		}
	}
	
	/**
	 * Gets item image index.
	 * @return
	 */
	public int getImageIndex()
	{
		return m_ImageIndex;
	}
	/**
	 * Sets item image index.
	 * @param value
	 */
	public void setImageIndex(int value)
	{
		if(m_ImageIndex != value){
			m_ImageIndex = value;
			
			getWOutlookBar().UpdateAll();
		}
	}
		
	/**
	 * Gets if item may stuck.
	 * @return
	 */
	public boolean getAllowStuck()
	{
		return m_AllowStuck;
	}
	/**
	 * Sets if item may stuck.
	 * @param value
	 */
	public void setAllowStuck(boolean value)
	{
		if(m_AllowStuck != value){
			m_AllowStuck = value;
			
			getWOutlookBar().UpdateAll();
		}
	}
	
	/**
	 * Gets item physical index. NOTE: Invisible items are included.
	 * @return
	 */
	public int getIndex()
	{
		return m_pItems.IndexOf(this);
	}	
	
	/**
	 * Gets item image.
	 * @return
	 */
	public Image getImage()
	{		
		if(this.getImageIndex() > -1){
			if(this.getBar().getItemsStyleCurrent() == ItemsStyle.SmallIcon){
				if(this.getWOutlookBar().getImageListSmall() != null && this.getImageIndex() < this.getWOutlookBar().getImageListSmall().getCount()){
					return this.getWOutlookBar().getImageListSmall().get(this.getImageIndex());
				}
			}
			else{
				if(this.getWOutlookBar().getImageList() != null && this.getImageIndex() < this.getWOutlookBar().getImageList().getCount()){
					return this.getWOutlookBar().getImageList().get(this.getImageIndex());
				}
			}
		}

		return null;		
	}
	

	public Rectangle getBounds()
	{
		return m_Bounds;
	}
	protected void setBounds(Rectangle value)
	{
		if(m_Bounds != value){
			m_Bounds = value;
		}
	}
	
	public Rectangle getImageRect()
	{
		if(this.getBar().getItemsStyleCurrent() == ItemsStyle.SmallIcon){
			return new Rectangle(3,(int)this.getBounds().getY() + 2,16,16);
		}
		else{
			return new Rectangle((int)(this.getBounds().getWidth() - 32 + 4)/2,(int)this.getBounds().getY() + 4,32,32);
		}
	}
	
	public Rectangle getTextRect()
	{
		if(this.getBar().getItemsStyleCurrent() == ItemsStyle.SmallIcon){
			return new Rectangle((int)this.getBounds().getX() + 20,(int)this.getBounds().getY() + 1,(int)this.getBounds().getWidth() - 20,(int)this.getBounds().getHeight() - 2);
		}
		else{
			return new Rectangle((int)this.getBounds().getX() + 2,(int)this.getImageRect().getMaxY() + 3,(int)this.getBounds().getWidth(),(int)this.getBounds().getMaxY() - (int)this.getImageRect().getMaxY());
		}
	}	
	
	/**
	 * Gets referance to items collection.
	 * @return
	 */
	public Items getItems()
	{
		return m_pItems;
	}
	
	/**
	 * Gets owner bar of item.
	 * @return
	 */
	public Bar getBar()
	{
		return m_pItems.getBar();
	}

	/**
	 * Gets referance to OutlookBar control.
	 * @return
	 */
	public WOutlookBar getWOutlookBar()
	{
		return m_pItems.getBar().getBars().getWOutlookBar();
	}

	/**
	 * Gets referance to OutlookBar control ViewStyle.
	 * @return
	 */
	public ViewStyle getViewStyle()
	{
		return m_pItems.getBar().getBars().getWOutlookBar().getViewStyle();
	}

}
