123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573 |
- /*
- *+------------------------------------------------------------------------+
- *| 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 += '<div style="margin-right:3px;"><button type="button" id="';
- html += this.m_id;
- html += '"';
- var oStyle = this.getStyle();
- if(oStyle)
- {
- html += ' class="' + oStyle.getActiveState() + '"';
- if (oStyle.getActiveState() != oStyle.getDisabledState())
- {
- html += ' tabIndex="0" hideFocus="true" accessKey="1"';
- }
- }
- if (this.m_toolTip != "")
- {
- html += ' title="' + this.m_toolTip + '"';
- }
- html += '>';
- if (this.m_icon != null)
- {
- html += this.m_icon.draw();
- }
- if (this.m_label != null)
- {
- html += this.m_label;
- }
- html += '</button>';
- if(this.m_menu != null && !this.m_bHideDropDown)
- {
- html += '<button type="button" id="';
- html += ('menu' + this.getId());
- html += '"';
- if(oStyle)
- {
- html += ' class="'+gDropDownButtonStyle.getActiveState() + '"';
- if (oStyle.getActiveState() != oStyle.getDisabledState())
- {
- html += ' tabIndex="0" hideFocus="true" accessKey="1"';
- }
- }
- if (this.m_dropDownToolTip != "")
- {
- html += ' title="' + this.m_dropDownToolTip + '"';
- }
- html += '><img border="0" src="../common/images/toolbar_drop_arrow.gif"';
- if (this.m_dropDownToolTip != "")
- {
- html += ' alt="' + this.m_dropDownToolTip + '"';
- html += ' title="' + this.m_dropDownToolTip + '"';
- }
- html += ' width="7" height="16"/></button>';
- }
- html += '</div>';
- 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;
|