/*
*+------------------------------------------------------------------------+
*| Licensed Materials - Property of IBM
*| IBM Cognos Products: Viewer
*| (C) Copyright IBM Corp. 2001, 2011
*|
*| 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) {
this.m_id = 'tbbutton'+makeId();
this.m_bVisible = true;
this.m_action = action;
this.m_toolTip = toolTip;
this.m_icon = (iconPath) ? new CIcon(iconPath, toolTip) : null;
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='';
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
}
var htmlContainer = this.getParent().getHTMLContainer();
if(htmlContainer == null) {
return;
}
var hTbItem = eval(document.all ? htmlContainer.document.getElementById(this.m_id) : htmlContainer.ownerDocument.getElementById(this.m_id));
if(hTbItem == null) {
return; // just to be safe
}
hTbItem.onmouseover = this.onmouseover;
hTbItem.onmouseout = this.onmouseout;
hTbItem.onclick = this.onclick;
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)
{
var 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.onclick = this.onclick;
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_onmouseover(evt)
{
var toolbarButton = this.tbItem;
if(typeof toolbarButton == "object")
{
if(!toolbarButton.isEnabled()) {
return;
}
if(toolbarButton.getMenu() != null && !toolbarButton.m_bHideDropDown && ('menu'+toolbarButton.getId()) == this.id) {
this.className = gDropDownButtonStyle.getActiveRolloverState();
}
else
{
if(typeof toolbarButton.getStyle() == "object") {
this.className = toolbarButton.getStyle().getActiveRolloverState();
}
if(toolbarButton.getMenu() != null && !toolbarButton.m_bHideDropDown)
{
var dropDownArrow = document.all ? this.document.getElementById('menu'+toolbarButton.getId()) : this.ownerDocument.getElementById('menu'+toolbarButton.getId());
if(typeof dropDownArrow == "object") {
dropDownArrow.className = gDropDownButtonStyle.getActiveRolloverState();
}
}
}
// send the message up to our parent
var oParent = toolbarButton.getParent();
if(oParent && typeof oParent.onmouseover == "function") {
oParent.onmouseover(evt);
}
// notify our observers of this event
toolbarButton.getObservers().notify(CToolbarButton_onmouseover);
}
}
function CToolbarButton_onmouseout(evt) {
var toolbarButton = this.tbItem;
if(typeof toolbarButton == "object")
{
if(!toolbarButton.isEnabled()) {
return;
}
if(toolbarButton.getMenu() != null && !toolbarButton.m_bHideDropDown && ('menu'+toolbarButton.getId()) == this.id) {
this.className = gDropDownButtonStyle.getActiveState();
}
else
{
if(typeof toolbarButton.getStyle() == "object") {
this.className = toolbarButton.getStyle().getActiveState();
}
if(toolbarButton.getMenu() != null && !toolbarButton.m_bHideDropDown)
{
var dropDownArrow = document.all ? this.document.getElementById('menu'+toolbarButton.getId()) : this.ownerDocument.getElementById('menu'+toolbarButton.getId());
if(typeof dropDownArrow == "object") {
dropDownArrow.className = gDropDownButtonStyle.getActiveState();
}
}
}
// send the message up to our parent
var oParent = toolbarButton.getParent();
if(oParent && typeof oParent.onmouseout == "function") {
oParent.onmouseout(evt);
}
// notify our observers of this event
toolbarButton.getObservers().notify(CToolbarButton_onmouseout);
}
}
function CToolbarButton_onclick(evt) {
//get the event in a cross-browser fashion
evt = (evt) ? evt : ((event) ? event : null);
// get the toolbar button from the html element
var toolbarButton = this.tbItem;
if(toolbarButton != null) {
if(!toolbarButton.isEnabled()) {
return;
}
var menu = toolbarButton.getMenu();
var sButtonId = toolbarButton.getId();
if(menu && ((this.id == ('menu'+sButtonId)) || (toolbarButton.m_bHideDropDown && this.id == sButtonId))) {
if(menu.isVisible()) {
menu.remove();
} else {
// the user clicked the drop down arrow
if(typeof menu.setHTMLContainer != "undefined") {
menu.setHTMLContainer(document.all ? this.document.body : this.ownerDocument.body);
}
//Close all the other dropdown menus first
if(typeof toolbarButton.m_parent.closeMenus == "function") {
toolbarButton.m_parent.closeMenus();
}
menu.draw();
menu.show();
}
} else {
eval(this.tbItem.m_action);
}
// send the message up to our parent
var oParent = toolbarButton.getParent();
if(oParent && typeof oParent.onclick == "function") {
oParent.onclick(evt);
}
// notify our observers of this event
toolbarButton.getObservers().notify(CToolbarButton_onclick);
}
if (this.blur) {
this.blur();
}
evt.cancelBubble = true;
return false;
}
function CToolbarButton_onkeypress(evt) {
//get the event in a cross-browser fashion
evt = (evt) ? evt : ((event) ? event : null);
//check for the Enter key
if (evt.keyCode == 13) {
// get the toolbar button from the html element
var toolbarButton = this.tbItem;
if(toolbarButton != null) {
if(!toolbarButton.isEnabled()) {
return;
}
var menu = toolbarButton.getMenu();
var sButtonId = toolbarButton.getId();
if(menu && ((this.id == ('menu'+sButtonId)) || (toolbarButton.m_bHideDropDown && this.id == sButtonId))) {
if(menu.isVisible()) {
menu.remove();
} else {
// the user clicked the drop down arrow
if(typeof menu.setHTMLContainer != "undefined") {
menu.setHTMLContainer(document.all ? this.document.body : this.ownerDocument.body);
}
menu.draw();
menu.show();
}
} else {
eval(this.tbItem.m_action);
}
// send the message up to our parent
var oParent = toolbarButton.getParent();
if(oParent && typeof oParent.onkeypress == "function") {
oParent.onkeypress(evt);
}
// notify our observers of this event
toolbarButton.getObservers().notify(CToolbarButton_onkeypress);
}
}
evt.cancelBubble = true;
return false;
}
function CToolbarButton_getMenu() {
return this.m_menu;
}
function CToolbarButton_getMenuType() {
// current toolbar buttons only support drop down menus
return 'dropDown';
}
function CToolbarButton_setStyle(style) {
this.m_style = style;
}
function CToolbarButton_getStyle() {
return this.m_style;
}
function CToolbarButton_isVisible() {
return this.m_bVisible;
}
function CToolbarButton_hide() {
this.m_bVisible = false;
}
function CToolbarButton_show() {
this.m_bVisible = true;
}
function CToolbarButton_enable() {
var oStyle = this.getStyle();
oStyle.setActiveState('normal');
oStyle.setActiveRolloverState('normal');
var oIcon = this.getIcon();
if (oIcon)
{
oIcon.enable();
}
this.updateHTML();
}
function CToolbarButton_disable() {
var oStyle = this.getStyle();
oStyle.setActiveState('disabled');
oStyle.setActiveRolloverState('disabled');
var oIcon = this.getIcon();
if (oIcon)
{
oIcon.disable();
}
this.updateHTML();
}
function CToolbarButton_isEnabled() {
if (this.getIcon())
{
return this.getIcon().isEnabled();
}
else
{
return true;
}
}
function CToolbarButton_pressed() {
var oStyle = this.getStyle();
oStyle.setActiveState('depressed');
oStyle.setActiveRolloverState('depressed');
this.updateHTML();
}
function CToolbarButton_reset() {
var oStyle = this.getStyle();
oStyle.setActiveState('normal');
oStyle.setActiveRolloverState('normal');
this.updateHTML();
}
function CToolbarButton_updateHTML() {
var oStyle = this.getStyle();
if(oStyle) {
if(typeof this.getParent().getHTMLContainer == "function") {
var htmlContainer = this.getParent().getHTMLContainer();
if(htmlContainer != null) {
var htmlElement = document.all ? htmlContainer.document.getElementById(this.getId()) : htmlContainer.ownerDocument.getElementById(this.getId());
if(htmlElement != null) {
var toolbarImage = htmlElement.getElementsByTagName("img");
if(typeof toolbarImage != 'undefined') {
if (this.getIcon())
{
if(this.getIcon().isEnabled()) {
toolbarImage[0].src = this.getIcon().getPath();
} else {
toolbarImage[0].src = this.getIcon().getDisabledImagePath();
}
}
}
if(oStyle.getActiveState() != oStyle.getDisabledState()) {
htmlElement.tabIndex = 0;
if (this.getMenu() != null && !this.m_bHideDropDown) {
htmlElement.nextSibling.tabIndex = 0;
htmlElement.nextSibling.accessKey = 1;
}
} else {
if (htmlElement.tabIndex != 'undefined') {
htmlElement.removeAttribute("tabIndex");
htmlElement.removeAttribute("accessKey");
if (this.getMenu() != null) {
htmlElement.nextSibling.removeAttribute("tabIndex");
htmlElement.nextSibling.removeAttribute("accessKey");
}
}
}
htmlElement.className = oStyle.getActiveState();
}
}
}
}
}
function CToolbarButton_getObservers() {
return this.m_observers;
}
function CToolbarButton_setFocus() {
if (this.m_menu != null && !this.m_bHideDropDown) {
document.getElementById(this.m_id).nextSibling.focus();
}
else {
document.getElementById(this.m_id).focus();
}
}
CToolbarButton.prototype.draw = CToolbarButton_draw;
CToolbarButton.prototype.attachEvents = CToolbarButton_attachEvents;
CToolbarButton.prototype.onblur = CToolbarButton_onmouseout;
CToolbarButton.prototype.onfocus = CToolbarButton_onmouseover;
CToolbarButton.prototype.onkeypress = CToolbarButton_onkeypress;
CToolbarButton.prototype.onmouseover = CToolbarButton_onmouseover;
CToolbarButton.prototype.onmouseout = CToolbarButton_onmouseout;
CToolbarButton.prototype.onclick = CToolbarButton_onclick;
CToolbarButton.prototype.setParent = CToolbarButton_setParent;
CToolbarButton.prototype.getParent = CToolbarButton_getParent;
CToolbarButton.prototype.getAction = CToolbarButton_getAction;
CToolbarButton.prototype.setAction = CToolbarButton_setAction;
CToolbarButton.prototype.getToolTip = CToolbarButton_getToolTip;
CToolbarButton.prototype.setToolTip = CToolbarButton_setToolTip;
CToolbarButton.prototype.getDropDownToolTip = CToolbarButton_getDropDownToolTip;
CToolbarButton.prototype.setDropDownToolTip = CToolbarButton_setDropDownToolTip;
CToolbarButton.prototype.getIcon = CToolbarButton_getIcon;
CToolbarButton.prototype.setIcon = CToolbarButton_setIcon;
CToolbarButton.prototype.getMenu = CToolbarButton_getMenu;
CToolbarButton.prototype.getMenuType = CToolbarButton_getMenuType;
CToolbarButton.prototype.getId = CToolbarButton_getId;
CToolbarButton.prototype.setStyle = CToolbarButton_setStyle;
CToolbarButton.prototype.getStyle = CToolbarButton_getStyle;
CToolbarButton.prototype.createDropDownMenu = CToolbarButton_createDropDownMenu;
CToolbarButton.prototype.addOwnerDrawControl = CToolbarButton_addOwnerDrawControl;
CToolbarButton.prototype.getObservers = CToolbarButton_getObservers;
CToolbarButton.prototype.update = new Function("return true");
CToolbarButton.prototype.isVisible = CToolbarButton_isVisible;
CToolbarButton.prototype.hide = CToolbarButton_hide;
CToolbarButton.prototype.show = CToolbarButton_show;
CToolbarButton.prototype.isEnabled = CToolbarButton_isEnabled;
CToolbarButton.prototype.enable = CToolbarButton_enable;
CToolbarButton.prototype.disable = CToolbarButton_disable;
CToolbarButton.prototype.pressed = CToolbarButton_pressed;
CToolbarButton.prototype.reset = CToolbarButton_reset;
CToolbarButton.prototype.setFocus = CToolbarButton_setFocus;
CToolbarButton.prototype.updateHTML = CToolbarButton_updateHTML;