/*
 * Created on 17.12.2003
 *
 */

package LumiSoft.UI.Controls.WOutlookBar;

import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import LumiSoft.UI.Controls.*;
import LumiSoft.UI.Controls.Paint;

/**
 * Outlookbar control.
 */
public class WOutlookBar extends WControl implements MouseListener,MouseMotionListener,MouseWheelListener
{	
	private EventListenerList m_pListners            = null;
	private ImageList         m_ImageList            = null;
	private ImageList         m_ImageListSmall       = null;
	private int               m_ActiveBarIndex       = -1;
	private int               m_DefaultTextSpacing   = 3;
	private boolean	          m_AllowItemsStuck      = true;
	private Bars              m_pBars                = null;	
	private HitInfo           m_LastHitInfo          = null;   // Holds last hitted object info.
	private Item              m_StuckenItem          = null;   // Holds referance to Stucken item.
	private boolean           m_BeginUpdate          = false;  // Holds beginupdate falg.	
	private Rectangle         m_ActiveBarClientRect;
	private Point             m_MousePos             = new Point(0,0);
	private int               m_MouseModifiers       = 0;
	private boolean           m_NeedCalcDrawInfo     = true;
	private Dimension         m_Size                 = new Dimension(0,0); 
        
	/**
	 * Default constructor.
	 */
	public WOutlookBar()
	{	
		super();
		
		m_pBars     = new Bars(this);
		m_pListners = new EventListenerList();
		m_Size      = this.getSize();

		this.addMouseListener(this);
		this.addMouseMotionListener(this);
		this.addMouseWheelListener(this);
		
		this.setFont(new Font("SansSerif",Font.PLAIN,12));
	}
	
	/**
	 * Clean up any resources being used.
	 */
	public void Dispose()
	{
		super.Dispose();
	}

/*
	

	private void OnStaticViewStyleChanged(object sender,ViewStyle_EventArgs e)
	{	
		if(m_UseStaticViewStyle){
			m_ViewStyle.CopyFrom(ViewStyle.staticViewStyle);
		}
	}

	private void OnViewStyleChanged(object sender,ViewStyle_EventArgs e)
	{		
		this.UpdateAll();
	}

	*/
	
	/**
	 * Is called by system when control need to repaint.
	 */
	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);

		if(m_BeginUpdate){
			return;
		}
		
		if(m_NeedCalcDrawInfo || (m_Size.height != this.getSize().height || m_Size.width != this.getSize().width)){
			CalculateBarInfo((Graphics2D)g);
			m_Size = this.getSize();
		}

		// Fill default backround
		g.setColor(getViewStyle().getBarClientAreaColor());
		g.fillRect(0,0,this.getWidth(),this.getHeight());
	
		if(getBars().getCount() > 0){			
			DrawBars((Graphics2D)g);				
			DrawVisibleBarItems((Graphics2D)g);
			DrawScrollButtons((Graphics2D)g);
		}		
	}

	/** Draws bars.
	 * @param g Graphics object to use for drawing.
	 */
	private void DrawBars(Graphics2D g)
	{			
		for(Bar bar : m_pBars){
			// Draw bar only if it is in drawing area.
			if(g.getClip().getBounds().intersects(bar.getBarRect())){
				DrawBar(g,bar,bar.getBarRect().contains(m_MousePos),m_MouseModifiers == MouseEvent.BUTTON1_DOWN_MASK);		
			}			
		}
	}

	/** Draws bar.
	 * @param g Graphics object to use for drawing.
	 * @param bar Bar to draw.
	 * @param hot Sepcifies if bar hot.
	 * @param pressed Specifies if bar pressed.
	 */
	private void DrawBar(Graphics2D g,Bar bar,boolean hot,boolean pressed)
	{
		Rectangle barRect = bar.getBarRect();
	
		//---- Draw bar
		if(hot){
			if(pressed){
				g.setColor(getViewStyle().getBarPressedColor());
			}
			else{
				g.setColor(getViewStyle().getBarHotColor());				
			}
			g.fillRect((int)barRect.getX(),(int)barRect.getY(),(int)barRect.getWidth(),(int)barRect.getHeight());
		
			g.setColor(getViewStyle().getBarHotBorderColor());
			g.drawRect((int)barRect.getX(),(int)barRect.getY(),(int)barRect.getWidth(),(int)barRect.getHeight());
		}
		else{
			g.setColor(getViewStyle().getBarColor());
			g.fillRect((int)barRect.getX(),(int)barRect.getY(),(int)barRect.getWidth(),(int)barRect.getHeight());
			
			g.setColor(getViewStyle().getBarBorderColor());
			g.drawRect((int)barRect.getX(),(int)barRect.getY(),(int)barRect.getWidth(),(int)barRect.getHeight());
		}
		
		//---- Draw bar caption -----------------------//	
		if(hot){
			g.setColor(getViewStyle().getBarHotTextColor());
		}
		else{
			g.setColor(getViewStyle().getBarTextColor());
		}
		
		Paint.DrawText(g,bar.getFont(),bar.getText(),bar.getBarRect(),bar.getTextAlign());
		//----------------------------------------------//
	}

	/** Draws visible items.
	 * @param g Graphics object to use for drawing.
	 */
	private void DrawVisibleBarItems(Graphics2D g)
	{			
		Bar bar = this.getActiveBar();
		if(bar != null){
			Shape clip = g.getClip();
			g.setClip(bar.getBarClientRect());
						
			for(int i=bar.getFirstVisibleIndex();i<bar.getItems().getCount();i++){
				Item item = bar.getItems().get(i);
									
				if(IsItemVisible(item)){
					// Draw item only if it is in drawing area.	
					if(clip.getBounds().intersects(item.getBounds())){
						boolean hot = bar.getBarClientRect().contains(m_MousePos) && item.getBounds().contains(m_MousePos) && !this.getUpScrollBtnRect().contains(m_MousePos) && !this.getDownScrollBtnRect().contains(m_MousePos);
	
						DrawItem(g,item,bar,hot,m_MouseModifiers == MouseEvent.BUTTON1_DOWN_MASK);
					}			
				}
			}

			// Restore old clip area
			g.setClip(clip);
		}
	}

	/** Draws item.
	 * @param g Graphics object to use for drawing.
	 * @param item Item to draw.
	 * @param bar Bar where item belongs.
	 * @param hot Sepcifies if item hot.
	 * @param pressed Specifies if item pressed.
	 */
	private void DrawItem(Graphics2D g,Item item,Bar bar,boolean hot,boolean pressed)
	{
		int itemStyle = bar.getItemsStyleCurrent();

		// Fill item backround
		g.setColor(getViewStyle().getBarClientAreaColor());
		g.fill(item.getBounds());
	//	g.draw(item.getBounds());
		
		if(hot || item.equals(m_StuckenItem)){
			Rectangle iRect = item.getBounds();
	//		Rectangle iRect = new Rectangle(item.getBounds.Location,item.Bounds.Size);												
			//--- If item style is IconSelect
			if(itemStyle == ItemsStyle.IconSelect){
				iRect = item.getImageRect();
	//			iRect = new Rectangle(((this.Width-32)/2)-1,item.Bounds.Y+2,34,34);
			}

			//--- if not stucken(selected) item
			if(!item.equals(m_StuckenItem)){
				if(pressed){
					g.setColor(getViewStyle().getBarItemPressedColor());
				}
				else{
					g.setColor(getViewStyle().getBarItemHotColor());
				}
				g.fillRect(iRect.x,iRect.y,iRect.width,iRect.height);
			}
			else{ //---- If stucken(selected) item
				g.setColor(getViewStyle().getBarItemSelectedColor());
				g.fillRect(iRect.x,iRect.y,iRect.width,iRect.height);
			}

			// Draw border
			g.setColor(getViewStyle().getBarItemBorderHotColor());
			g.drawRect(iRect.x,iRect.y,iRect.width,iRect.height);
		}
	//	else{			
	//		g.setColor(getViewStyle().getBarClientAreaColor());
	//		g.fill(item.getBounds());
	//		g.draw(item.getBounds());
	//	}
					
		//---- Draw item image 
		if(item.getImage() != null){
			g.drawImage(item.getImage(),(int)item.getImageRect().getX(),(int)item.getImageRect().getY(),this);
		}
		
		//---- Draw item text
		if(item.equals(m_StuckenItem)){
			g.setColor(getViewStyle().getBarItemSelectedTextColor());
		}
		else{
			g.setColor(getViewStyle().getBarItemTextColor());			
		}
		Paint.DrawText(g,item.getBar().getItemsFont(),item.getText(),item.getTextRect(),bar.getItemsTextAlign());
	}

	/** Draws scroll buttons.
	 * @param g Graphics object to use for drawing.
	 */
	private void DrawScrollButtons(Graphics2D g)
	{	
		// Draw scroll buttons only if they are in drawing area.
		if(g.getClip().getBounds().contains(this.getUpScrollBtnRect().getLocation()) || g.getClip().getBounds().contains(this.getDownScrollBtnRect().getLocation())){	
			g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
			
			//--- up arrow
			if(this.getIsUpScrollBtnVisible()){
				Rectangle upRect = this.getUpScrollBtnRect();
				boolean   hot    = upRect.contains(m_MousePos);
				
				g.setColor(getViewStyle().GetButtonColor(hot,m_MouseModifiers == MouseEvent.BUTTON1_DOWN_MASK));
				g.fill(upRect);
				
				g.setColor(getViewStyle().GetBorderColor(hot));
				g.draw(upRect);
				
				g.setColor(Color.BLACK);
				g.fillPolygon(new int[]{(int)upRect.getX() + 4,(int)upRect.getX() + 4 + 4,(int)upRect.getX() + 7 + 4},new int[]{(int)upRect.getY() + 9,(int)upRect.getY() - 4 + 9,(int)upRect.getY() + 9},3);			
			}
				
			//--- down arrow
			if(this.getIsDownScrollBtnVisible()){
				Rectangle downRect = this.getDownScrollBtnRect();
				boolean   hot      = downRect.contains(m_MousePos);
				
				g.setColor(getViewStyle().GetButtonColor(hot,m_MouseModifiers == MouseEvent.BUTTON1_DOWN_MASK));
				g.fill(downRect);
				
				g.setColor(getViewStyle().GetBorderColor(hot));
				g.draw(downRect);			
				
				g.setColor(Color.BLACK);					
				g.fillPolygon(new int[]{(int)downRect.getX() + 4,(int)downRect.getX() + 4 + 4,(int)downRect.getX() + 7 + 4},new int[]{(int)downRect.getY() + 6,(int)downRect.getY() + 4 + 6,(int)downRect.getY() + 6},3);				
			}
			
			g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
		}
	}

	/** Calculates outlookbar drawing info (bar,items,scroll buttons location,size, ...).
	 * @param g Graphics object to use for calculation.
	 */
	private void CalculateBarInfo(Graphics2D g)
	{
		int barTop = 1;

		//--- Calculate visible Bar's client rectangle
		int visibleBarClientHeight = (int)this.getBounds().getHeight() - (CalculateBarsHeight(g)) - 2 - 1;

		//--- loop through all bars ------//
		for(int i=0;i<m_pBars.getCount();i++){
			Bar bar = this.getBars().get(i);
			bar.setBarClientRect(new Rectangle(0,0,0,0));

			//--- Calculate text rect Height
			int barTextHeight = Paint.CalcTextHeight(g,bar.getFont(),bar.getText(),(int)this.getBounds().getWidth() - 3);
			int barHeight = barTextHeight + m_DefaultTextSpacing * 2;
				
			//--- If upper bars ---------
			if(i < m_ActiveBarIndex + 1){
				bar.setBarRect(new Rectangle(1,barTop,(int)this.getBounds().getWidth() - 3,barHeight));
					
				//--- If active bar
				if(i == m_ActiveBarIndex){
					Rectangle barClntRect = new Rectangle(1,(int)bar.getBarRect().getY() + (int)bar.getBarRect().getHeight(),this.getWidth() - 2,visibleBarClientHeight - 1);
					bar.setBarClientRect(barClntRect);
					m_ActiveBarClientRect = barClntRect;

					int top = (int)bar.getBarRect().getY() + bar.getBarRect().height + 3;
					
					// Reset item bounds
					for(int it=0;it<bar.getItems().getCount();it++){
						Item item = (Item)bar.getItems().get(it);
						item.setBounds(new Rectangle(-1,-1,0,0));
					}

					//--- Calculate items rect --------------------------//
					for(int it=bar.getFirstVisibleIndex();it<bar.getItems().getCount();it++){
						Item item = (Item)bar.getItems().get(it);
						
						int itemWidth  = this.getWidth() - 3;
						int itemHeight = CalculateItemHeight(g,item);
					
						item.setBounds(new Rectangle(1,top,itemWidth,itemHeight));
						top += itemHeight + 1;
					}
					//---------------------------------------------------//
				}
			}
			//--- If lower bars
			else{
				bar.setBarRect(new Rectangle(1,barTop + visibleBarClientHeight,this.getWidth() - 3,barHeight));
			}

			barTop += barHeight + 1;
		}
		//--------------------------------//
		
		m_NeedCalcDrawInfo = false;	
	}
	
	private void DrawHittedObject(HitInfo hitInfo)
	{
		if(hitInfo == null){
			return;
		}
		
		Rectangle rect = null;
		
		switch(hitInfo.getHittedObject())
		{
			case HittedObject.Bar:
				rect = hitInfo.getHittedBar().getBarRect();
				break;
				
			case HittedObject.Item:
				rect = hitInfo.getHittedItem().getBounds();
				break;
							
			case HittedObject.UpScrollButton:
				rect = this.getUpScrollBtnRect();
				break;
							
			case HittedObject.DownScrollButton:
				rect = this.getDownScrollBtnRect();
				break;
				
			default:
				return;
		}
		
		this.repaint(new Rectangle(rect.x,rect.y,rect.width + 1,rect.height + 1));
		
		// See if scroll buttons must be repainted
		if(rect.intersects(this.getUpScrollBtnRect())){
			rect = this.getUpScrollBtnRect();
			this.repaint(new Rectangle(rect.x,rect.y,rect.width + 1,rect.height + 1));
		}
		if(rect.intersects(this.getDownScrollBtnRect())){
			rect = this.getDownScrollBtnRect();
			this.repaint(new Rectangle(rect.x,rect.y,rect.width + 1,rect.height + 1));
		}
	}
		
	/** Calculates height which is needed for bars.
	 * @param g Graphics object to use for calculation.
	 * @param item Item which height to calculate.
	 * @return Returns bars height.
	 */
	private int CalculateBarsHeight(Graphics2D g)
	{
		int retVal = 0;
		
		for(Bar bar : m_pBars){			
			int barTextHeight = Paint.CalcTextHeight(g,bar.getFont(),bar.getText(),(int)this.getBounds().getWidth() - 3);
			retVal += barTextHeight + m_DefaultTextSpacing * 2 + 1;
		}

		retVal--;

		return retVal;
	}

	/** Calculates Item height.
	 * @param g Graphics object to use for calculation.
	 * @param item Item which height to calculate.
	 * @return Returns item height.
	 */
	private int CalculateItemHeight(Graphics2D g,Item item)
	{
		int retVal = 0;
		int height = 0;

		switch(item.getBar().getItemsStyleCurrent())
		{
			case ItemsStyle.SmallIcon:
			//	height = Paint.CalcTextHeight(g,item.getBar().getItemsFont(),item.getCaption(),(int)item.getTextRect().getWidth());
				height = Paint.CalcTextHeight(g,item.getBar().getItemsFont(),item.getText(),(int)this.getBounds().getWidth() - 16 - 7);
				retVal = height + 8; // item spacing
				break;

			default:
				height = Paint.CalcTextHeight(g,item.getBar().getItemsFont(),item.getText(),(int)this.getBounds().getWidth() - 2 - 0);
				retVal = height + 36 + 8; // Icon + spacing
				break;
		}

		return retVal;
	}
	
	/** Checks if specified item is visible.
	 * @param item Item what to check.
	 * @return Returns true if item visible.
	 */
	private boolean IsItemVisible(Item item)
	{		
		if(this.getActiveBar() != null && this.getActiveBar().getItems().Contains(item)){
			if(m_ActiveBarClientRect.contains(item.getBounds().getLocation())){
				return true;
			}
		}
			
		return false;
	}
	
	public void mousePressed(MouseEvent e)
	{		
		m_MouseModifiers = e.getModifiersEx();
		this.repaint();
		
	//	if(m_LastHitInfo != null){		
	//		DrawObject(m_LastHitInfo,false);
	//	}
	}

	public void mouseReleased(MouseEvent e)
	{		
		if(m_MouseModifiers != MouseEvent.BUTTON1_DOWN_MASK){
			return;
		}
	
		// Reset, we don't need them anymore
		m_MouseModifiers = 0;

		HitInfo hitInfo = new HitInfo(e.getPoint(),this);
					
		//--- If bar clicked
		if(hitInfo.getHittedObject() == HittedObject.Bar){
			// Bar changed
			if(hitInfo.getHittedBar().getIndex() != m_ActiveBarIndex){
				m_ActiveBarIndex = hitInfo.getHittedBar().getIndex();
				this.UpdateAll();
				
				// Raise bar clicked event
				OnBarClicked(hitInfo.getHittedBar());			
			}
			else{
				this.repaint();
			}
			
			return;
		}

		//--- If item clicked
		if(hitInfo.getHittedObject() == HittedObject.Item){
			if(hitInfo.getHittedItem().getAllowStuck()){
				if(!hitInfo.getHittedItem().equals(m_StuckenItem)){
					Item oldItem  = m_StuckenItem;
					m_StuckenItem = hitInfo.getHittedItem();

					//--- Redraw old stucken item					
				//	if(oldItem != null && oldItem.getBar().IsItemVisible(oldItem)){
				//		using(Graphics g = this.CreateGraphics()){
				//			g.SetClip(this.ActiveBar.BarClientRect);
				//			DrawItem(g,oldItem,oldItem.Bar,false,false);
				//		}
				//	}

					// Raise item clicked event
					OnItemClicked(hitInfo.getHittedItem());
					this.repaint();
				}
			}
			else{
				// Raise item clicked event
				OnItemClicked(hitInfo.getHittedItem());
				this.repaint();
			}			
		}

		//--- If up scroll button clicked
		Bar activeBar = this.getActiveBar();
		if(hitInfo.getHittedObject() == HittedObject.UpScrollButton){
			activeBar.setFirstVisibleIndex(activeBar.getFirstVisibleIndex() - 1);
			this.UpdateAll();
			return;
		}

		//--- If down scroll button clicked
		if(hitInfo.getHittedObject() == HittedObject.DownScrollButton){
			activeBar.setFirstVisibleIndex(activeBar.getFirstVisibleIndex() + 1);
			this.UpdateAll();
			return;
		}
		
	//	this.repaint();

		// By default, redraw last hitted object
	//	DrawObject(hitInfo,false);						
	}


	public void mouseEntered(MouseEvent e)
	{
		m_MousePos = e.getPoint();
	//	this.repaint();	
	}

	public void mouseExited(MouseEvent e)
	{
		m_MousePos = new Point(0,0);
		DrawHittedObject(m_LastHitInfo);
		m_LastHitInfo = null;
	}
		
	public void mouseWheelMoved(MouseWheelEvent event) 
	{
		if(this.getActiveBar() != null){
			if(event.getWheelRotation() < 0 && this.getActiveBar().getFirstVisibleIndex() > 0){
				this.getActiveBar().setFirstVisibleIndex(this.getActiveBar().getFirstVisibleIndex() - 1);
				this.UpdateAll();
			}

			if(event.getWheelRotation() > 0 && !this.getActiveBar().getIsLastVisible()){
				this.getActiveBar().setFirstVisibleIndex(this.getActiveBar().getFirstVisibleIndex() + 1);
				this.UpdateAll();
			}
		}
	}
	
	public void mouseMoved(MouseEvent e)
	{	
		m_MousePos = e.getPoint();
	
		// If draw info isn't calculated, skip this.			
		if(!m_NeedCalcDrawInfo){
			HitInfo hitInfo = new HitInfo(e.getPoint(),this);
						
			if(!hitInfo.Compare(m_LastHitInfo)){
				DrawHittedObject(m_LastHitInfo);
				DrawHittedObject(hitInfo);
					
				m_LastHitInfo = hitInfo;
			}	
		}				
	}
		
	
	public void mouseClicked(MouseEvent e) {}	
	public void mouseDragged(MouseEvent e) {}
		

	/// <summary>
	/// Calculates bar info and redraws all.
	/// </summary>
	public void UpdateAll()
	{
		m_NeedCalcDrawInfo = true;
		
		if(this.getBars().getCount() > 0 && m_ActiveBarIndex == -1){
			m_ActiveBarIndex = 0;
		}

		if(!m_BeginUpdate){
			this.repaint();								
		}
	}

	/** Suspends drwaing.
	 */
	public void BeginUpdate()
	{
		m_BeginUpdate = true;
	}

	/** Ends BeginUpdate and redraws control.
	 */
	public void EndUpdate()
	{
		m_BeginUpdate = false;
		this.UpdateAll();
	}

	/// <summary>
	/// Gets currently hitted object.
	/// </summary>
	/// <returns></returns>
	public HitInfo GetHittedObject()
	{			
		return new HitInfo(m_MousePos,this);
	}
		
	public ImageList getImageList()
	{
		return m_ImageList;
	}
	public void setImageList(ImageList value)
	{
		if(value != null){
			m_ImageList = value;
			if(this.getBars().getCount() > 0){
				this.repaint();
			}
		}		
	}
	
	public ImageList getImageListSmall()
	{
		return m_ImageListSmall;
	}
	public void setImageListSmall(ImageList value)
	{
		if(value != null){
			m_ImageListSmall = value;
			if(this.getBars().getCount() > 0){
				this.repaint();
			}
		}		
	}

	/// <summary>
	/// Gets bars collection.
	/// </summary>
	public Bars getBars()
	{
		return m_pBars;
	}

	public Bar getActiveBar()
	{
		if(m_ActiveBarIndex > -1){
			return this.getBars().get(m_ActiveBarIndex);
		}
		else{
			return null;
		}
	}
	public void setActiveBar(Bar value)
	{
		if(value != null){
			m_ActiveBarIndex = value.getIndex();
			this.UpdateAll();
		}
		else{
			m_ActiveBarIndex = -1;
			this.UpdateAll();
		}
	}


	public boolean getAllowItemsStuck()
	{
		return m_AllowItemsStuck;
	}
	public void setAllowItemsStuck(boolean value)
	{
		if(m_AllowItemsStuck != value){
			m_AllowItemsStuck = value;
		}
	}
	
	public Item getStuckenItem()
	{
		return m_StuckenItem;
	}
	public void setStuckenItem(Item value)
	{
		if(m_StuckenItem != value){		
			m_StuckenItem = value;
			if(m_StuckenItem != null && m_StuckenItem.getAllowStuck()){
				this.setActiveBar(m_StuckenItem.getBar());					
	
				// Raise event
				OnItemClicked(m_StuckenItem);
			}
			else{
				m_StuckenItem = null;
			}
	
			this.repaint();
		}
	}
	
	public Rectangle getUpScrollBtnRect()
	{
		if(this.getIsUpScrollBtnVisible()){
			Rectangle upRect = new Rectangle((int)this.getActiveBar().getBarClientRect().getWidth() - 16,(int)this.getActiveBar().getBarClientRect().getY() + 6,14,14);				
			return upRect; 
		}
		else{
			return new Rectangle(0,0,0,0);
		}
	}
	
	public Rectangle getDownScrollBtnRect()
	{
		if(this.getIsDownScrollBtnVisible()){
			Rectangle downRect = new Rectangle((int)this.getActiveBar().getBarClientRect().getWidth() - 16,(int)this.getActiveBar().getBarClientRect().getY() + (int)this.getActiveBar().getBarClientRect().getHeight() - 19,14,14);
			return downRect; 
		}
		else{
			return new Rectangle(0,0,0,0);
		}
	}

	public boolean getIsUpScrollBtnVisible()
	{
		if(this.getActiveBar() != null && this.getActiveBar().getFirstVisibleIndex() > 0){
			return true; 
		}
		else{
			return false;
		}
	}

	public boolean getIsDownScrollBtnVisible()
	{
		if(this.getActiveBar() != null){
			return !this.getActiveBar().getIsLastVisible();
		}
		else{
			return false;
		}						
	}

	
	/**
	 * Is called when ViewStyle has changed.
	 *
	 */
	protected void OnViewStyleChaned()
	{
		this.UpdateAll();
		for(Bar bar : getBars()){
	//		if(bar.getItemsStyle() == ItemsStyle.UseDefault){
				bar.setItemsStyle(getViewStyle().getBarItemsStyle());
	//		}
		}
		repaint();
	}
		
	protected void OnLanguageChanged()
	{
		m_NeedCalcDrawInfo = true;
		this.repaint();
	}
	
	
	/**
	 * Adds the specified action listener to receive action events
	 * from this button.
	 * @param l the action listener
	 */ 
	public void addClickedListener(OutlookBarListener l) 
	{
		m_pListners.add(OutlookBarListener.class,l);
	}

	/**
	 * Removes the specified action listener so it no longer receives
	 * action events from this button.
	 * @param l the action listener
	 */ 
	public void removeClickedListener(OutlookBarListener l) 
	{
		m_pListners.remove(OutlookBarListener.class,l);
	}
	
	
	protected void OnItemClicked(Item item)
	{
		Object[] listeners = m_pListners.getListenerList();
		// loop through each listener and pass on the event if needed		
		for(int i=0;i < listeners.length;i++){
			if(listeners[i] == OutlookBarListener.class){
				// pass the event to the listeners event dispatch method
				((OutlookBarListener)listeners[i+1]).ItemClicked(this,item);
			}            
		}
	}

	
	protected void OnBarClicked(Bar bar)
	{
		Object[] listeners = m_pListners.getListenerList();
		// loop through each listener and pass on the event if needed		
		for(int i=0;i < listeners.length;i++){
			if(listeners[i] == OutlookBarListener.class){
				// pass the event to the listeners event dispatch method
				((OutlookBarListener)listeners[i+1]).BarClicked(this,bar);
			}            
		}
	}

}
