//Création du namespace SereniXScrollPaneManager = {}; SereniXScrollPaneManager.NAME = 'SereniXScrollPaneManager'; SereniXScrollPaneManager.VERSION = '1.0'; /** * Cette valeur permet de savoir que la barre de défilement ne sera jamais visble */ SereniXScrollPaneManager.NEVER_POLICY = 0; /** * Cette valeur permet de savoir que la barre de défilement ne sera visible que si nécessaire */ SereniXScrollPaneManager.AS_REQUIRED_POLICY = 1; /** * Cette valeur permet de savoir que la barre de défilement sera toujours visible */ SereniXScrollPaneManager.ALWAYS_POLICY = 2; /** * */ SereniXScrollPaneManager.DEFAULT_SCROLLPANE_WIDTH = 500; /** * */ SereniXScrollPaneManager.DEFAULT_SCROLLPANE_HEIGHT = 300; SereniXScrollPaneManager.cache=new SereniXHashMap(); /** * */ SereniXScrollPaneManager.build=function(p_scrollpane) { /**** Construction de l'ossature *****/ if (p_scrollpane.component != null) { p_scrollpane.element.appendChild(p_scrollpane.component.element); // Mise à jour des corrdonnées du composant para rapport au scrollpane p_scrollpane.component.setX(SereniXGuiUtils.getComponentX(p_scrollpane.component.element)); p_scrollpane.component.setY(SereniXGuiUtils.getComponentY(p_scrollpane.component.element)); } if (p_scrollpane.verticalScrollbar != null) { p_scrollpane.element.appendChild(p_scrollpane.verticalScrollbar.element); } if (p_scrollpane.horizontalScrollbar != null) { p_scrollpane.element.appendChild(p_scrollpane.horizontalScrollbar.element); } if (p_scrollpane.corner != null) { p_scrollpane.element.appendChild(p_scrollpane.corner.element); } //Dessine (représente) le scrollpane p_scrollpane.paint(); //Rattachement aux scrollbars du listener qui permet de scroller les composant du scollpane. p_scrollpane.addMoveListener(new Function(SereniXScrollPaneManager.getScrollTextHandler(p_scrollpane))); } /** * Renvoie true pour spécifier que l'évenement s'est produit sur l'indicateur de niveau du scroll horizontal et false dans le cas contraire. */ SereniXScrollPaneManager.isHorizontalSliderScroll=function(p_scrollpane,p_evt) { if (p_scrollpane.horizontalScrollbar == null) return false; var target = SereniXEventManager.getTarget(p_evt); return p_scrollpane.horizontalScrollbar.isSliderlevelIndicator(target); } /** * Renvoie true pour spécifier que l'évenement s'est produit sur l'indicateur de niveau du scroll vertical et false dans le cas contraire. */ SereniXScrollPaneManager.isVerticalSliderScroll=function(p_scrollpane,p_evt) { if (p_scrollpane.verticalScrollbar == null) return false; var target = SereniXEventManager.getTarget(p_evt); return p_scrollpane.verticalScrollbar.isSliderlevelIndicator(target); } /** * Déplace le composant du scollpane proprotionnellment au déplacement de l'indicateur de niveau */ SereniXScrollPaneManager.scroll=function(p_scrollpane,p_evt) { if (!p_evt) { p_evt = window.event; } var mousePosition = SereniXEventManager.getMousePosition(p_evt); var sb; var newPos; var lastPosition; if (SereniXScrollPaneManager.isHorizontalSliderScroll(p_scrollpane,p_evt)) { //cas de scroll horizontal lastPosition = p_scrollpane.horizontalScrollbar.slider.startDragPosition; //Détermination de l'amplitude du mouvement de l'indicateur de niveau //du scroll bar vertical sliderAmplitude = mousePosition.x -lastPosition.x; sb = p_scrollpane.horizontalScrollbar; //Détermination la nouvelle position correspondante au mouvement de //l'indicateur de niveau du scroll bar vertical newPos = sb.getCompOrientationNewPosition(sliderAmplitude, p_scrollpane.component.getWidth(), p_scrollpane.getViewport().width); p_scrollpane.component.setX(newPos); } else if (SereniXScrollPaneManager.isVerticalSliderScroll(p_scrollpane,p_evt)) { //cas du scroll vertical lastPosition = p_scrollpane.verticalScrollbar.slider.startDragPosition; //Détermination de l'amplitude du mouvement de l'indicateur de niveau //du scroll bar vertical sliderAmplitude = mousePosition.y -lastPosition.y; sb = p_scrollpane.verticalScrollbar; //Détermination la nouvelle position correspondante au mouvement de //l'indicateur de niveau du scroll bar vertical newPos = sb.getCompOrientationNewPosition(sliderAmplitude, p_scrollpane.component.getHeight(), p_scrollpane.getViewport().height); p_scrollpane.component.setY(newPos); } } /** * */ SereniXScrollPaneManager.getScrollPane=function(p_id) { return SereniXScrollPaneManager.cache.get(p_id); } /** * */ SereniXScrollPaneManager.getScrollTextHandler=function(p_scrollpane) { var id; if (typeof p_scrollpane == 'string') { id = p_scrollpane; } else { id = p_scrollpane.id; } var txt = "SereniXScrollPaneManager.scroll(SereniXScrollPaneManager.getScrollPane('"+id+"'),"; txt += "arguments.length == 0?window.event:arguments[0]);"; return txt; } SereniXScrollPaneManager.paint=function(scrollpane) { var pane; if (typeof scrollpane == 'string') pane = SereniXComponentManager.getComponent(scrollpane); if (SerenixClassManager.isInstanceof(pane,SereniXScrollPane)) pane.paint(); } /** * */ var SereniXScrollPane = SereniXClassMgr.ext(SereniXComponent,function() { var def = arguments[0]; this.horizontalScrollbar = null; this.verticalScrollbar = null; this.corner = null; this.cornerImagePath = null; this.cornerBackground = ""; this.element = document.createElement('div'); this.element.style.position = "absolute"; this.element.style.overflow = "hidden"; if (typeof def.id != 'undefined') { this.id = def.id;; } else { this.id = "sys_serenix_scrollpane"+SereniXUtils.getTime(); } this.element.id = this.id; if (typeof def.name != 'undefined') { this.element.name = def.name; } else { this.element.name = this.element.id; } SereniXScrollPaneManager.cache.put(this.id,this); if (typeof def.width != 'undefined') { this.width = def.width; } else { this.width = SereniXScrollPaneManager.DEFAULT_SCROLLPANE_WIDTH; } if (typeof def.height != 'undefined') { this.height = def.height; } else { this.height = SereniXScrollPaneManager.DEFAULT_SCROLLPANE_HEIGHT; } SereniXGuiUtils.setElementSize(this.element,this.width,this.height); //Construit si nécessaire le composant et l'ajoute au scrollpane this.addComponent(def); //Détermine les épaisseurs (hauteur scrollbar horizontal et largeur //scrollbar vertical) des barres de défilements. //Le résultat est affecté à l'objet def this.getScrollbarThicknesses(def); //Affecte les politiques de gestion des barres de défilements et les //construit si nécessaire. this.setScrollbars(def); if (def.cornerImagePath != null && typeof def.cornerImagePath != 'undefined') { this.cornerImagePath = def.cornerImagePath; } if (def.cornerBackground != null && typeof def.cornerBackground != 'undefined') { this.cornerBackground = def.cornerBackground; } //Assemble les différents éléments construits. SereniXScrollPaneManager.build(this); },false,null); /** * Construit si nécessaire le composant et l'ajoute au scrollpane en fonction * du champ component de l'objet des metadonnées du scrollpane. */ SereniXScrollPane.prototype.addComponent=function() { var def = arguments[0]; if (typeof def.component == 'string') { var comp = SereniXUtils.getEltById(def.component); if (comp == null) { comp = SereniXContentMgr.createDivision(def.component); } this.component = new SereniXComponent(comp); } else if (def.component) { if (def.component instanceof SereniXComponent) { this.component = def.component; } else { def.component.style.position = "absolute"; if (SereniXUtils.isTextContentOnly(def.component)) { SereniXGuiUtils.setWidth(def.component,this.width); } this.component = SereniXComponentFactory.getComponent(def.component); } } else { this.component == null; } if (this.component != null) { if (SereniXUtils.isTextContentOnly(this.component.element)) { SereniXGuiUtils.setWidth(this.component.element,this.width); } this.component.element.style.position = "absolute"; size = SereniXGuiUtils.getSize(this.component.element); if (size.width == 0 || size.height == 0) { var div = document.createElement('div'); div.style.position = "absolute"; div.innerHTML = this.component.element.innerHTML; SereniXUtils.getPageContainer().appendChild(div); size.width = div.offsetWidth; size.height = div.offsetHeight; SereniXGuiUtils.setElementSize(this.component.element,size.width,size.height); this.component.width = size.width; this.component.height = size.height; SereniXUtils.getPageContainer().removeChild(div); } if (typeof this.paintFunction == 'undefined' || this.paintFunction == null) this.paintFunction = new Function('SereniXComponentManager.getComponent("'+this.id+'").paint();'); this.component.addResizeListener(this.paintFunction); } } /** * */ SereniXScrollPane.prototype.getComponentSize=function() { if (this.component == null) return {width:"null",height:"null"}; return this.component.getSize(); } /** * */ SereniXScrollPane.prototype.getComponentWidth=function() { if (this.component == null) return "null"; return this.component.getWidth(); } /** * */ SereniXScrollPane.prototype.getComponentHeight=function() { if (this.component == null) return "null"; return this.component.getHeight(); } /** * Affecte les politiques de gestion des barres de défilements et les construit * si nécessaire. */ SereniXScrollPane.prototype.setScrollbars=function() { var def = arguments[0]; if (def.horizontalScrollPolicy) { this.horizontalScrollPolicy = def.horizontalScrollPolicy; } else { this.horizontalScrollPolicy = SereniXScrollPaneManager.AS_REQUIRED_POLICY; } if (def.verticalScrollPolicy) { this.verticalScrollPolicy = def.verticalScrollPolicy; } else { this.verticalScrollPolicy = SereniXScrollPaneManager.AS_REQUIRED_POLICY; } if (this.cornerImagePath == null || typeof this.cornerImagePath == 'undefined') { this.cornerImagePath = "images/serenix_corner.gif"; } var scrollbarDef; if (this.horizontalScrollPolicy != SereniXScrollPaneManager.NEVER_POLICY) { scrollbarDef = {}; this.vScrollbarWidth = def.vScrollbarWidth; scrollbarDef.orientation = SereniXSliderMgr.HORIZONTAL; scrollbarDef.width = this.width-def.vScrollbarWidth; scrollbarDef.height = def.hScrollbarHeight; scrollbarDef.component = this.component; this.horizontalScrollbar = new SereniXScrollbar(scrollbarDef); this.horizontalScrollbar.setX(0); if (this.horizontalScrollPolicy == SereniXScrollPaneManager.ALWAYS_POLICY) { this.horizontalScrollbar.element.style.display="block"; } } else { this.horizontalScrollbar = null; this.vScrollbarWidth = 0; } if (this.verticalScrollPolicy != SereniXScrollPaneManager.NEVER_POLICY) { scrollbarDef = {}; this.hScrollbarHeight = def.hScrollbarHeight; scrollbarDef.orientation = SereniXSliderMgr.VERTICAL; scrollbarDef.width = def.vScrollbarWidth; scrollbarDef.height = this.height-def.hScrollbarHeight; scrollbarDef.component = this.component; this.verticalScrollbar = new SereniXScrollbar(scrollbarDef); this.verticalScrollbar.setY(0); if (this.verticalScrollPolicy == SereniXScrollPaneManager.ALWAYS_POLICY) { this.verticalScrollbar.element.style.display="block"; } } else { this.verticalScrollbar = null; this.hScrollbarHeight = 0; } if (this.verticalScrollPolicy != SereniXScrollPaneManager.NEVER_POLICY && this.horizontalScrollPolicy != SereniXScrollPaneManager.NEVER_POLICY) { this.buildCorner(); } } /** * */ SereniXScrollPane.prototype.buildCorner=function() { this.corner = document.createElement('div'); if (this.cornerBackground != null && this.cornerBackground != '') { this.corner.style.background = this.cornerBackground; } this.corner.style.position = "absolute"; if (this.cornerImagePath != 'undefined' && this.cornerImagePath != '') { var cornerElt = document.createElement('img'); cornerElt.style.position = "absolute"; cornerElt.setAttribute('src',this.cornerImagePath); w = this.getVerticalScrollbarWidth(); h = this.getHorizontalScrollbarHeight(); SereniXGuiUtils.setElementSize(cornerElt,w,h); this.corner.appendChild(cornerElt); } SereniXGuiUtils.setElementSize(this.corner,w,h); this.corner = new SereniXComponent(this.corner); } /** * */ SereniXScrollPane.prototype.setScrollbarsVisibility=function() { var verticalScrollbarVisible = false; if (this.horizontalScrollPolicy == SereniXScrollPaneManager.AS_REQUIRED_POLICY) { if (this.component == null) { this.horizontalScrollbar.element.style.display="none"; } else if (this.getWidth() < this.component.getWidth()) { this.horizontalScrollbar.element.style.display="block"; if (this.getHeight() - this.horizontalScrollbar.getHeight() < this.component.getHeight()) { this.verticalScrollbar.element.style.display="block"; this.corner.element.style.display="block"; verticalScrollbarVisible = true; } } else { this.horizontalScrollbar.element.style.display="none"; } } if (verticalScrollbarVisible) return; if (this.verticalScrollPolicy == SereniXScrollPaneManager.AS_REQUIRED_POLICY) { if (this.component == null) { this.verticalScrollbar.element.style.display="none"; } else if (this.getHeight() < this.component.getHeight()) { this.verticalScrollbar.element.style.display="block"; var width = this.getWidth(); var cw = this.component.getWidth(); var vsw = this.verticalScrollbar.getWidth(); if (width - vsw < cw) { this.horizontalScrollbar.element.style.display="block"; this.corner.element.style.display="block"; } } else { this.verticalScrollbar.element.style.display="none"; } } } /** * */ SereniXScrollPane.prototype.getComponentInvisibleWidth=function() { return this.component.getWidth()-this.width + this.getVerticalScrollbarWidth(); } /** * */ SereniXScrollPane.prototype.getComponentInvisibleHeight=function() { return this.component.getHeight()-this.height + this.getHorizontalScrollbarHeight(); } /** * Déplace le composant des distances spécifiées et déplace aussi proportionnellement les indicateurs de niveau des barres de défilement. * 1- dx < 0 signifie déplacement du composant de la droite vers la gauche et dx > 0 : le déplacement dans le sens contraire * 2- dy < 0 signifie déplacement du composant du bas vers le haut et dy > 0 : le déplacement dans le sens contraire. * NB : Les mouvements du composant et des indicateurs des barres de défilement sont en sens contraire */ SereniXScrollPane.prototype.scrollComponent=function(dx,dy) { if (dx != 0) { if (this.horizontalScrollbar == null) return; else d = this.horizontalScrollbar.getMaxMoveDistance(); var D = this.getComponentInvisibleWidth(); if (d != 0) this.horizontalScrollbar.scroll(Math.ceil(-dx*d/D)); } if (dy != 0) { if (this.verticalScrollbar == null) return; else d = this.verticalScrollbar.getMaxMoveDistance(); var D = this.getComponentInvisibleHeight(); if (d!=0) this.verticalScrollbar.scroll(Math.ceil(-dy*d/D)); } } /** * Détermine les épaisseurs (hauteur scrollbar horizontal et largeur scrollbar * vertical) des barres de défilements suivant que les élements suivants sont * définis ou non dans les métadonnées : * - scrollbarThickness : épaisseur globale des barres de défilement * - hScrollbarHeight : hauteur (épaisseur) de la barre horizontale * - vScrollbarWidth : largeur (épaisseur) de la barre verticale * - leftScrollButton : image du bouton de scroll de la gauche vers la droite * - rightScrollButton : image du bouton de scroll de la droite vers la gauche * - topScrollButton : image du bouton de scroll du haut vers le bas * - bottomScrollButton : image du bouton de scroll du bas vers le haut */ SereniXScrollPane.prototype.getScrollbarThicknesses=function() { var def = arguments[0]; //Si l'épaisseur des scrollbars est définie if (typeof def.scrollbarThickness != 'undefined') { //Si aucune épaisseur n'est explicitement définie pour la barre horizontale if (typeof def.hScrollbarHeight == 'undefined') { def.hScrollbarHeight = def.scrollbarThickness; } //Si aucune épaisseur n'est explicitement définie pour la barre verticale if (typeof def.vScrollbarWidth == 'undefined') { def.vScrollbarWidth = def.scrollbarThickness; } } if (typeof def.hScrollbarHeight == 'undefined') { var imgSize1; var imgSize2; if (typeof def.leftScrollButton != 'undefined') { imgSize1 = SereniXUtils.getImageSize(def.leftScrollButton); } else { imgSize1 = SereniXUtils.getImageSize(SereniXScrollButtonMgr.LEFT_TO_RIGHT_DEFAULT_IMAGE); } if (typeof def.rightScrollButton != 'undefined') { imgSize2 = SereniXUtils.getImageSize(def.rightScrollButton); } else { imgSize2 = SereniXUtils.getImageSize(SereniXScrollButtonMgr.RIGHT_TO_LEFT_DEFAULT_IMAGE); } def.hScrollbarHeight = Math.max(imgSize1.height,imgSize2.height); } if (typeof def.vScrollbarWidth == 'undefined') { if (typeof def.bottomScrollButton != 'undefined') { imgSize1 = SereniXUtils.getImageSize(def.bottomScrollButton); } else { imgSize1 = SereniXUtils.getImageSize(SereniXScrollButtonMgr.BOTTOM_TO_TOP_DEFAULT_IMAGE); } if (typeof def.topScrollButton != 'undefined') { imgSize2 = SereniXUtils.getImageSize(def.topScrollButton); } else { imgSize2 = SereniXUtils.getImageSize(SereniXScrollButtonMgr.TOP_TO_BOTTOM_DEFAULT_IMAGE); } def.vScrollbarWidth = Math.max(imgSize1.width,imgSize2.width); } } /** * */ SereniXScrollPane.prototype.setWidth=function(p_width) { if (p_width < this.minWidth) { p_width = this.minWidth; } deltaWidth = p_width - this.width; SereniXGuiUtils.setWidth(this.element,p_width); if (this.horizontalScrollbar != null) { this.horizontalScrollbar.addWidth(deltaWidth); } if (this.verticalScrollbar != null) { this.verticalScrollbar.moveX(deltaWidth); } if (this.corner != null) { this.corner.moveX(deltaWidth); } this.width = p_width; this.paint(); } /** * */ SereniXScrollPane.prototype.setHeight=function(p_height) { if (p_height < this.minHeight) { p_height = this.minHeight; } deltaHeight = p_height - this.height; SereniXGuiUtils.setHeight(this.element,p_height); if (this.verticalScrollbar != null) { this.verticalScrollbar.addHeight(deltaHeight); } if (this.horizontalScrollbar != null) { this.horizontalScrollbar.moveY(deltaHeight); } if (this.corner != null) { this.corner.moveY(deltaHeight); } this.height = p_height; this.paint(); } /** * */ SereniXScrollPane.prototype.addWidth = function(delta) { if (typeof this.height == 'undefined') { size = SereniXGuiUtils.getSize(this.element); this.width = size.width; this.height = size.height; } this.setWidth(this.width + delta); } /** * */ SereniXScrollPane.prototype.addHeight = function(delta) { if (typeof this.height == 'undefined') { size = SereniXGuiUtils.getSize(this.element); this.width = size.width; this.height = size.height; } this.setHeight(this.height + delta); } /** * Affiche ou non des scrollbars en fonction de la taille du scrollpane et de * la taille du composant contenu dans le scrollpane. * Redimensionne aussi en fonction de ces tailles, le viewport. */ SereniXScrollPane.prototype.paint=function() { this.setScrollbarsVisibility(); var viewport = this.getViewport(); if (this.horizontalScrollbar != null) { if (typeof this.horizontalScrollbar.x == 'undefined') { this.horizontalScrollbar.setX(0); } this.horizontalScrollbar.setY(viewport.height); this.horizontalScrollbar.setWidth(viewport.width); } if (this.verticalScrollbar != null) { this.verticalScrollbar.setX(viewport.width); if (typeof this.verticalScrollbar.y == 'undefined') { this.verticalScrollbar.setY(0); } this.verticalScrollbar.setHeight(viewport.height); } if (this.corner != null) { this.corner.setX(this.horizontalScrollbar.getWidth()); this.corner.setY(this.verticalScrollbar.getHeight()); if (this.horizontalScrollbar.element.style.display == "block" && this.verticalScrollbar.element.style.display == "block"){ this.corner.element.style.display = "block"; } else { this.corner.element.style.display = "none"; } } } /** * */ SereniXScrollPane.prototype.getHorizontalScrollbarHeight=function() { if (this.horizontalScrollbar == null) return 0; return this.horizontalScrollbar.getHeight(); } /** * */ SereniXScrollPane.prototype.getHorizontalScrollbarWidth=function() { if (this.horizontalScrollbar == null) return 0; return this.horizontalScrollbar.getWidth(); } /** * */ SereniXScrollPane.prototype.getVerticalScrollbarHeight=function() { if (this.verticalScrollbar == null) return 0; return this.verticalScrollbar.getHeight(); } /** * */ SereniXScrollPane.prototype.getVerticalScrollbarWidth=function() { if (this.verticalScrollbar == null) return 0; return this.verticalScrollbar.getWidth(); } /** * */ SereniXScrollPane.prototype.setComponent=function(p_comp) { this.component = SereniXComponentFactory.getComponent(p_comp); this.component.setX(0); this.component.setY(0); if (typeof this.paintFunction == 'undefined' || this.paintFunction == null) this.paintFunction = new Function('SereniXComponentManager.getComponent("'+this.id+'").paint();'); this.component.addResizeListener(this.paintFunction); if (this.horizontalScrollbar != null) { this.horizontalScrollbar.component = this.component; this.horizontalScrollbar.slider.setLevelIndicatorWidth( this.horizontalScrollbar.slider.getProportionnalIndicatorSize()); this.horizontalScrollbar.slider.levelIndicator.setX(0); this.horizontalScrollbar.slider.levelIndicator.setY(0); } if (this.verticalScrollbar != null) { this.verticalScrollbar.component = this.component; this.verticalScrollbar.slider.setLevelIndicatorHeight( this.verticalScrollbar.slider.getProportionnalIndicatorSize()); this.verticalScrollbar.slider.levelIndicator.setX(0); this.verticalScrollbar.slider.levelIndicator.setY(0); } this.paint(); } /** * */ SereniXScrollPane.prototype.setSize=function(p_width,p_height) { this.setWidth(p_width); this.setHeight(p_height); } /** * */ SereniXScrollPane.prototype.getViewport=function() { var cornerSize = this.corner.getSize(); if (this.corner!= null && this.corner.element.style.display == "block") { return {width:this.getWidth()-cornerSize.width, height:this.getHeight()-cornerSize.height}; } else if (this.horizontalScrollbar != null && this.horizontalScrollbar.element.style.display == "block") { return {width:this.getWidth(), height:this.getHeight()-this.horizontalScrollbar.getHeight()}; } else if (this.verticalScrollbar != null && this.verticalScrollbar.element.style.display == "block") { return {width:this.getWidth()-this.verticalScrollbar.getWidth(), height:this.getHeight()}; } else { return {width:this.getWidth(), height:this.getHeight()}; } } /** * Ajoute une fonction (listner) qui va être exécutée à chaque déplacement de * l'indicateur de niveau. */ SereniXScrollPane.prototype.addMoveListener=function(p_lsnr) { if (this.horizontalScrollbar != null) { this.horizontalScrollbar.addMoveListener(p_lsnr); } if (this.verticalScrollbar != null) { this.verticalScrollbar.addMoveListener(p_lsnr); } } /** * Retire un listener (écouteur) de mouvement de l'indicateur de niveau. */ SereniXScrollPane.prototype.removeMoveListener=function(p_lsnr) { if (this.horizontalScrollbar != null) { this.horizontalScrollbar.removeMoveListener(p_lsnr); } if (this.verticalScrollbar != null) { this.verticalScrollbar.removeMoveListener(p_lsnr); } } /** * */ SereniXScrollPane.prototype.toString=function() { return "[SereniXScrollPane id = "+this.id+ (typeof this.element.name != 'undefined'?" name= "+this.element.name:'')+ "; offsetPosition = {x:"+this.x+",y:"+this.y+"};"+ "size = {width:"+this.width+",height:"+this.height+ this.element == null?"":"tag = "+SereniXUtils.getTag(this.element)+"]"; }