/********************************************************************************************************************************
* Licensed Materials - Property of IBM *
* *
* IBM Cognos Products: AGS *
* *
* (C) Copyright IBM Corp. 2005, 2014 *
* *
* US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *
*********************************************************************************************************************************/
/*-----------------------------------------------------------------------------------------------------
Class : CToolbarButton
Description :
-----------------------------------------------------------------------------------------------------*/
var tbUniqueId = 0;
function makeId() {
return tbUniqueId++;
}
gDropDownButtonStyle = new CUIStyle('dropDownArrow','dropDownArrowOver','','','');
function CToolbarButton(parent, action, iconPath, toolTip, style, bHideDropDown, label, dropDownToolTip, iconWidth, capability) {
this.m_id = 'tbbutton'+makeId();
this.m_bVisible = true;
this.m_action = action;
this.m_toolTip = toolTip;
this.m_capability = capability;
this.m_icon = (iconPath) ? new CIcon(iconPath, toolTip) : null;
if(iconWidth!=null && iconPath!=null){
this.m_icon.setWidth(iconWidth);
}
this.m_parent = parent;
this.m_menu = null;
if (typeof bHideDropDown == "boolean")
this.m_bHideDropDown = bHideDropDown;
else
this.m_bHideDropDown = false;
this.m_style = new CUIStyle(style.getNormalState(),style.getRolloverState(),style.getDepressedState(),style.getDepressedRolloverState(),style.getDisabledState());
this.m_observers = new CObserver(this);
if(typeof this.m_parent == "object" && typeof this.m_parent.add == "function")
this.m_parent.add(this);
this.m_label = (label) ? label : null;
this.m_dropDownToolTip = (dropDownToolTip) ? dropDownToolTip : this.m_toolTip;
}
function CToolbarButton_getId() {
return this.m_id;
}
function CToolbarButton_draw() {
var html='';
var tabindexVal = -1 ;
if (AccessibilityHandler.isEnabled()) {
tabindexVal = AccessibilityHandler.getTabindex(this);
}
html += '
';
if(this.m_menu != null && !this.m_bHideDropDown) {
html += '';
}
html += '
';
return html;
}
function CToolbarButton_attachEvents() {
if(typeof this.getParent().getHTMLContainer != "function")
return; // this method must be implemented by the parent
htmlContainer = this.getParent().getHTMLContainer();
if(htmlContainer == null)
return;
if(document.all && typeof(htmlContainer.document) != 'undefined'){
hTbItem = eval(htmlContainer.document.getElementById(this.m_id));
}else{
hTbItem = eval(htmlContainer.ownerDocument.getElementById(this.m_id));
}
if(hTbItem == null)
return; // just to be safe
hTbItem.onmouseover = this.onmouseover;
hTbItem.onmouseout = this.onmouseout;
hTbItem.onmouseup = this.onmouseup;
hTbItem.onkeypress = this.onkeypress;
hTbItem.onfocus = this.onfocus;
hTbItem.onblur = this.onblur;
hTbItem.tbItem = eval(this);
// attach the drop down arrow event handlers to the toolbar button as well
if(this.m_menu != null && !this.m_bHideDropDown) {
if(document.all && typeof(htmlContainer.document) != 'undefined'){
hmenu = eval(htmlContainer.document.getElementById('menu'+this.getId()));
}else{
hmenu = eval(htmlContainer.ownerDocument.getElementById('menu'+this.getId()));
}
//hmenu = eval(document.all ? htmlContainer.document.getElementById('menu'+this.getId()) : htmlContainer.ownerDocument.getElementById('menu'+this.getId()));
hmenu.onmouseover = this.onmouseover;
hmenu.onmouseout = this.onmouseout;
hmenu.onmouseup = this.onmouseup;
hmenu.onkeypress = this.onkeypress;
hmenu.onfocus = this.onfocus;
hmenu.onblur = this.onblur;
hmenu.tbItem = eval(this);
}
}
function CToolbarButton_createDropDownMenu(menuStyle, dropDownToolTip) {
this.m_dropDownToolTip = (dropDownToolTip) ? dropDownToolTip : this.m_toolTip;
this.m_menu = new CMenu('dropDown'+this.getId(),menuStyle);
this.m_menu.setParent(this);
return this.m_menu;
}
function CToolbarButton_addOwnerDrawControl(control) {
this.m_menu = control
if(typeof control.setParent != "undefined")
this.m_menu.setParent(this);
}
function CToolbarButton_getParent() {
return this.m_parent;
}
function CToolbarButton_setParent(parent) {
this.m_parent = parent;
}
function CToolbarButton_getAction() {
return this.m_action;
}
function CToolbarButton_setAction(action) {
this.m_action = action
}
function CToolbarButton_getToolTip() {
return this.m_toolTip;
}
function CToolbarButton_setToolTip(tooltip) {
this.m_toolTip = tooltip;
}
function CToolbarButton_getDropDownToolTip() {
return this.m_dropDownToolTip;
}
function CToolbarButton_setDropDownToolTip(tooltip) {
this.m_dropDownToolTip = tooltip;
}
function CToolbarButton_getIcon() {
return this.m_icon;
}
function CToolbarButton_setIcon(iconPath) {
this.m_icon.setPath(iconPath);
}
function CToolbarButton_enableTabindex() {
this.getHTMLElement().setAttribute("tabindex", "0");
}
function CToolbarButton_disableTabindex() {
this.getHTMLElement().setAttribute("tabindex", "-1");
}
function CToolbarButton_onfocus(evt) {
//get the event in a cross-browser fashion
evt = (evt) ? evt : ((event) ? event : null);
var toolbarButton = this.tbItem;
if(toolbarButton == null || !(toolbarButton instanceof CToolbarButton) || !toolbarButton.isEnabled())
return;
var parent = toolbarButton.getParent();
if (toolbarButton.getMenu() != null && toolbarButton.getMenu().isVisible()) {
toolbarButton.getMenu().remove();
}
if (AccessibilityHandler.isEnabled()) {
for (var i=0; i