<?xml version="1.0" encoding="UTF-8"?>
<rmml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="L:\collaborative-nir\program\Cscl3DWS\rmml\RMML.xsd">
	<include src="../kmbutton.xml"/>
	<composition _name="CKMToolbar">
		<script><![CDATA[
			this.buttons = new Array();
			this.isVertical = false;
			this.margins = 3;
			this.radioGroup="";
			this.basePath=KMRESPATH;

			function getToolbarLength()
			{
				var length=0;
				var i=0;
				for(; i<this.buttons.length; i++)
				{
					if( !this.isVertical)	length += this.buttons[i].width + this.margins;
					else 	length += this.buttons[i].height + this.margins;
				}
				return length;
			}

			function addButton(btn, clickFunc)
			{
				var currentSize = getToolbarLength();
				if( !this.isVertical)
				{
					btn.x = currentSize;
					btn.y = 0;
				}
				else
				{
					btn.x = 0;
					btn.y = currentSize;
				}
				this.buttons.push(btn);
				btn.parent = this;
				if( this.radioGroup != "")
				{
					btn.radioGroup = this.radioGroup;
				}
				btn.updateButtonImage();
				btn.PressedChanged=function()
				{
					this.parent.HandleClick( this);
					if( typeof(clickFunc) == "function")
					{
						clickFunc();
					}
				}
			}

			function addButtons(btns)
			{
				var i=0;
				for(; i<btns.length; i++)
				{
					addButton( btns[i]);
				}
			}

			function removeButton(btnName)
			{
				var btn=eval("this."+btnName);
				if( btn!=null && typeof(btn)!="undefined")
				{
					for (var i=0; i<this.buttons.length; i++)
					{
						if (this.buttons[i].name == btnName)
						{
							this.buttons.splice(i,1);
						}
					}
					btn.visible=false;
					btn.parent=null;
				}
				UpdateButtonsPosition();
			}

			function UpdateButtonsPosition()
			{
				var currentSize = 0;
				for (var i=0; i<this.buttons.length; i++)
				{
					var btn = this.buttons[i];
					if( !this.isVertical)
					{
						btn.x = currentSize;
						btn.y = 0;
						currentSize += this.buttons[i].width + this.margins;
					}
					else
					{
						btn.x = 0;
						btn.y = currentSize;
						currentSize += this.buttons[i].height + this.margins;
					}
				}
			}

			function createButton(name, asrc, help, clickFunc)
			{
				var newButton = new Composition;
				newButton._class = "CKMButton";
				newButton.name=name;
				newButton.img.src = eval('\"' + this.basePath + asrc + '\"');
				addButton( newButton, clickFunc);
				newButton.sHelp=help;
				return newButton;
			}

			function HandleClick(btn)
			{
trace("btn.radioGroup="+btn.radioGroup);
				if( btn == null)			return;
				if( !btn.checkButton)		return;
				if( btn.radioGroup == "")	return;
				if( !btn.isPressed())		return;
				//
				var i=0;
				for(; i<this.buttons.length; i++)
				{
					if( this.buttons[i] == btn)
					{
						if( btn.radioDisabledWhenPressed)
						{
							btn.setEnabled( false);
						}
					}
					else
					{
						if( this.buttons[i].radioGroup == btn.radioGroup)
						{
							this.buttons[i].setEnabled( true);
							this.buttons[i].setPressed( false);
						}
					}
				}
			}

			function getButton(aname)
			{
				return eval(this.target + "." + aname);
			}

			function setPressed(name, val)
			{
				var btn = this.getButton(name);
				if( btn!=null)
				{
					btn.setPressed( val);
				}
			}

			function setEnabled(name, val)
			{
				var btn = this.getButton(name);
				if( btn!=null)
				{
					btn.setEnabled( val);
				}
			}

			function onShowHelp( ax,ay,atxt)
			{
				if( typeof(this.parent.ShowHelp) == "function")
				{
					this.parent.ShowHelp( this.x+ax, this.y+ay, atxt);
				}
			}
			function onHideHelp()
			{
				if( typeof(this.parent.HideHelp) == "function")
				{
					this.parent.HideHelp();
				}
			}

			function arrangeButtons()
			{
				for (var i=0; i<this.buttons.length; i++)
				{
					this.buttons[i].x = i*getToolbarLength()/this.buttons.length;
				}
			}
		]]></script>
	</composition>
</rmml>