| 1 |
define(["dojo", "../../util/oo", "../../plugins/_Plugin", "../../manager/_registry"], |
| 2 |
function(dojo, oo, Plugin, registry){ |
| 3 |
dojo.deprecated("dojox.drawing.ui.dom.Pan", "It may not even make it to the 1.4 release.", 1.4); |
| 4 |
|
| 5 |
var Pan = oo.declare( |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
Plugin, |
| 24 |
function(options){ |
| 25 |
|
| 26 |
this.domNode = options.node; |
| 27 |
var _scrollTimeout; |
| 28 |
dojo.connect(this.domNode, "click", this, "onSetPan"); |
| 29 |
dojo.connect(this.keys, "onKeyUp", this, "onKeyUp"); |
| 30 |
dojo.connect(this.keys, "onKeyDown", this, "onKeyDown"); |
| 31 |
dojo.connect(this.anchors, "onAnchorUp", this, "checkBounds"); |
| 32 |
dojo.connect(this.stencils, "register", this, "checkBounds"); |
| 33 |
dojo.connect(this.canvas, "resize", this, "checkBounds"); |
| 34 |
dojo.connect(this.canvas, "setZoom", this, "checkBounds"); |
| 35 |
dojo.connect(this.canvas, "onScroll", this, function(){ |
| 36 |
if(this._blockScroll){ |
| 37 |
this._blockScroll = false; |
| 38 |
return; |
| 39 |
} |
| 40 |
_scrollTimeout && clearTimeout(_scrollTimeout); |
| 41 |
_scrollTimeout = setTimeout(dojo.hitch(this, "checkBounds"), 200); |
| 42 |
}); |
| 43 |
this._mouseHandle = this.mouse.register(this); |
| 44 |
|
| 45 |
|
| 46 |
},{ |
| 47 |
selected:false, |
| 48 |
type:"dojox.drawing.ui.dom.Pan", |
| 49 |
|
| 50 |
onKeyUp: function(evt){ |
| 51 |
if(evt.keyCode == 32){ |
| 52 |
this.onSetPan(false); |
| 53 |
} |
| 54 |
}, |
| 55 |
|
| 56 |
onKeyDown: function(evt){ |
| 57 |
if(evt.keyCode == 32){ |
| 58 |
this.onSetPan(true); |
| 59 |
} |
| 60 |
}, |
| 61 |
|
| 62 |
onSetPan: function( bool){ |
| 63 |
if(bool === true || bool === false){ |
| 64 |
this.selected = !bool; |
| 65 |
} |
| 66 |
if(this.selected){ |
| 67 |
this.selected = false; |
| 68 |
dojo.removeClass(this.domNode, "selected"); |
| 69 |
}else{ |
| 70 |
this.selected = true; |
| 71 |
dojo.addClass(this.domNode, "selected"); |
| 72 |
} |
| 73 |
this.mouse.setEventMode(this.selected ? "pan" : ""); |
| 74 |
}, |
| 75 |
|
| 76 |
onPanDrag: function(obj){ |
| 77 |
var x = obj.x - obj.last.x; |
| 78 |
var y = obj.y - obj.last.y; |
| 79 |
this.canvas.domNode.parentNode.scrollTop -= obj.move.y; |
| 80 |
this.canvas.domNode.parentNode.scrollLeft -= obj.move.x; |
| 81 |
this.canvas.onScroll(); |
| 82 |
}, |
| 83 |
|
| 84 |
onStencilUp: function(obj){ |
| 85 |
|
| 86 |
|
| 87 |
this.checkBounds(); |
| 88 |
}, |
| 89 |
onStencilDrag: function(obj){ |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
}, |
| 94 |
|
| 95 |
checkBounds: function(){ |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
var log = function(){ |
| 109 |
|
| 110 |
}; |
| 111 |
var warn = function(){ |
| 112 |
|
| 113 |
}; |
| 114 |
|
| 115 |
|
| 116 |
var t=Infinity, r=-Infinity, b=-Infinity, l=Infinity, |
| 117 |
sx=0, sy=0, dy=0, dx=0, |
| 118 |
mx = this.stencils.group ? this.stencils.group.getTransform() : {dx:0, dy:0}, |
| 119 |
sc = this.mouse.scrollOffset(), |
| 120 |
|
| 121 |
scY = sc.left ? 10 : 0, |
| 122 |
scX = sc.top ? 10 : 0, |
| 123 |
|
| 124 |
ch = this.canvas.height, |
| 125 |
cw = this.canvas.width, |
| 126 |
z = this.canvas.zoom, |
| 127 |
|
| 128 |
|
| 129 |
pch = this.canvas.parentHeight, |
| 130 |
pcw = this.canvas.parentWidth; |
| 131 |
|
| 132 |
|
| 133 |
this.stencils.withSelected(function(m){ |
| 134 |
var o = m.getBounds(); |
| 135 |
warn("SEL BOUNDS:", o); |
| 136 |
t = Math.min(o.y1 + mx.dy, t); |
| 137 |
r = Math.max(o.x2 + mx.dx, r); |
| 138 |
b = Math.max(o.y2 + mx.dy, b); |
| 139 |
l = Math.min(o.x1 + mx.dx, l); |
| 140 |
}); |
| 141 |
|
| 142 |
this.stencils.withUnselected(function(m){ |
| 143 |
var o = m.getBounds(); |
| 144 |
warn("UN BOUNDS:", o); |
| 145 |
t = Math.min(o.y1, t); |
| 146 |
r = Math.max(o.x2, r); |
| 147 |
b = Math.max(o.y2, b); |
| 148 |
l = Math.min(o.x1, l); |
| 149 |
}); |
| 150 |
|
| 151 |
b *= z; |
| 152 |
var xscroll = 0, yscroll = 0; |
| 153 |
log("Bottom test", "b:", b, "z:", z, "ch:", ch, "pch:", pch, "top:", sc.top, "sy:", sy); |
| 154 |
if(b > pch || sc.top ){ |
| 155 |
log("*bottom scroll*"); |
| 156 |
|
| 157 |
ch = Math.max(b, pch + sc.top); |
| 158 |
sy = sc.top; |
| 159 |
xscroll += this.canvas.getScrollWidth(); |
| 160 |
}else if(!sy && ch>pch){ |
| 161 |
log("*bottom remove*"); |
| 162 |
|
| 163 |
ch = pch; |
| 164 |
} |
| 165 |
|
| 166 |
r *= z; |
| 167 |
if(r > pcw || sc.left){ |
| 168 |
|
| 169 |
|
| 170 |
cw = Math.max(r, pcw + sc.left); |
| 171 |
sx = sc.left; |
| 172 |
yscroll += this.canvas.getScrollWidth(); |
| 173 |
}else if(!sx && cw>pcw){ |
| 174 |
|
| 175 |
|
| 176 |
cw = pcw; |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
cw += xscroll*2; |
| 182 |
ch += yscroll*2; |
| 183 |
|
| 184 |
this._blockScroll = true; |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
this.stencils.group && this.stencils.group.applyTransform({dx:dx, dy:dy}); |
| 189 |
|
| 190 |
|
| 191 |
this.stencils.withUnselected(function(m){ |
| 192 |
m.transformPoints({dx:dx, dy:dy}); |
| 193 |
}); |
| 194 |
|
| 195 |
this.canvas.setDimensions(cw, ch, sx, sy); |
| 196 |
|
| 197 |
|
| 198 |
} |
| 199 |
} |
| 200 |
); |
| 201 |
|
| 202 |
dojo.setObject("dojox.drawing.ui.dom.Pan", Pan); |
| 203 |
Pan.setup = { |
| 204 |
name:"dojox.drawing.ui.dom.Pan", |
| 205 |
tooltip:"Pan Tool", |
| 206 |
iconClass:"iconPan" |
| 207 |
}; |
| 208 |
|
| 209 |
registry.register(Pan.setup, "plugin"); |
| 210 |
|
| 211 |
return Pan; |
| 212 |
}); |