Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / drawing / manager / Mouse.js @ 10

History | View | Annotate | Download (5.5 KB)

1 9 andrej.cim
/*
2
        Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3
        Available via Academic Free License >= 2.1 OR the modified BSD license.
4
        see: http://dojotoolkit.org/license for details
5
*/
6
7
8
if(!dojo._hasResource["dojox.drawing.manager.Mouse"]){
9
dojo._hasResource["dojox.drawing.manager.Mouse"]=true;
10
dojo.provide("dojox.drawing.manager.Mouse");
11
dojox.drawing.manager.Mouse=dojox.drawing.util.oo.declare(function(_1){
12
this.util=_1.util;
13
this.keys=_1.keys;
14
this.id=_1.id||this.util.uid("mouse");
15
this.currentNodeId="";
16
this.registered={};
17
},{doublClickSpeed:400,_lastx:0,_lasty:0,__reg:0,_downOnCanvas:false,init:function(_2){
18
this.container=_2;
19
this.setCanvas();
20
var c;
21
var _3=false;
22
dojo.connect(this.container,"rightclick",this,function(_4){
23
console.warn("RIGHTCLICK");
24
});
25
dojo.connect(document.body,"mousedown",this,function(_5){
26
});
27
dojo.connect(this.container,"mousedown",this,function(_6){
28
this.down(_6);
29
_3=true;
30
c=dojo.connect(document,"mousemove",this,"drag");
31
});
32
dojo.connect(document,"mouseup",this,function(_7){
33
dojo.disconnect(c);
34
_3=false;
35
this.up(_7);
36
});
37
dojo.connect(document,"mousemove",this,function(_8){
38
if(!_3){
39
this.move(_8);
40
}
41
});
42
dojo.connect(this.keys,"onEsc",this,function(_9){
43
this._dragged=false;
44
});
45
},setCanvas:function(){
46
var _a=dojo.coords(this.container.parentNode);
47
this.origin=dojo.clone(_a);
48
},scrollOffset:function(){
49
return {top:this.container.parentNode.scrollTop,left:this.container.parentNode.scrollLeft};
50
},resize:function(_b,_c){
51
if(this.origin){
52
this.origin.w=_b;
53
this.origin.h=_c;
54
}
55
},register:function(_d){
56
var _e=_d.id||"reg_"+(this.__reg++);
57
if(!this.registered[_e]){
58
this.registered[_e]=_d;
59
}
60
return _e;
61
},unregister:function(_f){
62
if(!this.registered[_f]){
63
return;
64
}
65
delete this.registered[_f];
66
},_broadcastEvent:function(_10,obj){
67
for(var nm in this.registered){
68
if(this.registered[nm][_10]){
69
this.registered[nm][_10](obj);
70
}
71
}
72
},onDown:function(obj){
73
this._broadcastEvent(this.eventName("down"),obj);
74
},onDrag:function(obj){
75
var nm=this.eventName("drag");
76
if(this._selected&&nm=="onDrag"){
77
nm="onStencilDrag";
78
}
79
this._broadcastEvent(nm,obj);
80
},onMove:function(obj){
81
this._broadcastEvent("onMove",obj);
82
},overName:function(obj,evt){
83
var nm=obj.id.split(".");
84
evt=evt.charAt(0).toUpperCase()+evt.substring(1);
85
if(nm[0]=="dojox"&&(dojox.drawing.defaults.clickable||!dojox.drawing.defaults.clickMode)){
86
return "onStencil"+evt;
87
}else{
88
return "on"+evt;
89
}
90
},onOver:function(obj){
91
this._broadcastEvent(this.overName(obj,"over"),obj);
92
},onOut:function(obj){
93
this._broadcastEvent(this.overName(obj,"out"),obj);
94
},onUp:function(obj){
95
var nm=this.eventName("up");
96
if(nm=="onStencilUp"){
97
this._selected=true;
98
}else{
99
if(this._selected&&nm=="onUp"){
100
nm="onStencilUp";
101
this._selected=false;
102
}
103
}
104
this._broadcastEvent(nm,obj);
105
if(dojox.gfx.renderer=="silverlight"){
106
return;
107
}
108
this._clickTime=new Date().getTime();
109
if(this._lastClickTime){
110
if(this._clickTime-this._lastClickTime<this.doublClickSpeed){
111
var dnm=this.eventName("doubleClick");
112
console.warn("DOUBLE CLICK",dnm,obj);
113
this._broadcastEvent(dnm,obj);
114
}else{
115
}
116
}
117
this._lastClickTime=this._clickTime;
118
},zoom:1,setZoom:function(_11){
119
this.zoom=1/_11;
120
},setEventMode:function(_12){
121
this.mode=_12?"on"+_12.charAt(0).toUpperCase()+_12.substring(1):"";
122
},eventName:function(_13){
123
_13=_13.charAt(0).toUpperCase()+_13.substring(1);
124
if(this.mode){
125
if(this.mode=="onPathEdit"){
126
return "on"+_13;
127
}
128
if(this.mode=="onUI"){
129
}
130
return this.mode+_13;
131
}else{
132
if(!dojox.drawing.defaults.clickable&&dojox.drawing.defaults.clickMode){
133
return "on"+_13;
134
}
135
var dt=!this.drawingType||this.drawingType=="surface"||this.drawingType=="canvas"?"":this.drawingType;
136
var t=!dt?"":dt.charAt(0).toUpperCase()+dt.substring(1);
137
return "on"+t+_13;
138
}
139
},up:function(evt){
140
this.onUp(this.create(evt));
141
},down:function(evt){
142
evt.preventDefault();
143
dojo.stopEvent(evt);
144
this._downOnCanvas=true;
145
var sc=this.scrollOffset();
146
var dim=this._getXY(evt);
147
this._lastpagex=dim.x;
148
this._lastpagey=dim.y;
149
var o=this.origin;
150
var x=dim.x-o.x+sc.left;
151
var y=dim.y-o.y+sc.top;
152
var _14=x>=0&&y>=0&&x<=o.w&&y<=o.h;
153
x*=this.zoom;
154
y*=this.zoom;
155
o.startx=x;
156
o.starty=y;
157
this._lastx=x;
158
this._lasty=y;
159
this.drawingType=this.util.attr(evt,"drawingType")||"";
160
var id=this._getId(evt);
161
this.onDown({mid:this.id,x:x,y:y,pageX:dim.x,pageY:dim.y,withinCanvas:_14,id:id});
162
},over:function(obj){
163
this.onOver(obj);
164
},out:function(obj){
165
this.onOut(obj);
166
},move:function(evt){
167
var obj=this.create(evt);
168
if(this.id=="MUI"){
169
}
170
if(obj.id!=this.currentNodeId){
171
var _15={};
172
for(var nm in obj){
173
_15[nm]=obj[nm];
174
}
175
_15.id=this.currentNodeId;
176
this.currentNodeId&&this.out(_15);
177
obj.id&&this.over(obj);
178
this.currentNodeId=obj.id;
179
}
180
this.onMove(obj);
181
},drag:function(evt){
182
this.onDrag(this.create(evt,true));
183
},create:function(evt,_16){
184
var sc=this.scrollOffset();
185
var dim=this._getXY(evt);
186
var _17=dim.x;
187
var _18=dim.y;
188
var o=this.origin;
189
var x=dim.x-o.x+sc.left;
190
var y=dim.y-o.y+sc.top;
191
var _19=x>=0&&y>=0&&x<=o.w&&y<=o.h;
192
x*=this.zoom;
193
y*=this.zoom;
194
var id=_19?this._getId(evt,_16):"";
195
var ret={mid:this.id,x:x,y:y,pageX:dim.x,pageY:dim.y,page:{x:dim.x,y:dim.y},orgX:o.x,orgY:o.y,last:{x:this._lastx,y:this._lasty},start:{x:this.origin.startx,y:this.origin.starty},move:{x:_17-this._lastpagex,y:_18-this._lastpagey},scroll:sc,id:id,withinCanvas:_19};
196
this._lastx=x;
197
this._lasty=y;
198
this._lastpagex=_17;
199
this._lastpagey=_18;
200
dojo.stopEvent(evt);
201
return ret;
202
},_getId:function(evt,_1a){
203
return this.util.attr(evt,"id",null,_1a);
204
},_getXY:function(evt){
205
return {x:evt.pageX,y:evt.pageY};
206
},setCursor:function(_1b,_1c){
207
if(!_1c){
208
dojo.style(this.container,"cursor",_1b);
209
}else{
210
dojo.style(_1c,"cursor",_1b);
211
}
212
}});
213
}