PageRenderTime 22ms CodeModel.GetById 15ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/Frameworks/Debug/AppKit/rhino.platform/CPDragServer.j

http://github.com/jfahrenkrug/MapKit-HelloWorld
Unknown | 214 lines | 213 code | 1 blank | 0 comment | 0 complexity | 6f116ff43bb4ca57f6ca9b68d0735c06 MD5 | raw file
  1I;15;AppKit/CPView.jI;16;AppKit/CPEvent.jI;21;AppKit/CPPasteboard.jI;20;AppKit/CPImageView.jc;12323;
  2var CPSharedDragServer = nil;
  3var CPDragServerView = nil,
  4    CPDragServerSource = nil,
  5    CPDragServerWindow = nil,
  6    CPDragServerOffset = nil,
  7    CPDragServerLocation = nil,
  8    CPDragServerPasteboard = nil,
  9    CPDragServerDestination = nil,
 10    CPDragServerDraggingInfo = nil,
 11    CPDragServerPreviousEvent = nil,
 12    CPDragServerAutoscrollInterval = nil;
 13var CPDragServerIsDraggingImage = NO,
 14    CPDragServerShouldSendDraggedViewMovedTo = NO,
 15    CPDragServerShouldSendDraggedImageMovedTo = NO,
 16    CPDragServerShouldSendDraggedViewEndedAtOperation = NO,
 17    CPDragServerShouldSendDraggedImageEndedAtOperation = NO;
 18var CPDragServerAutoscroll = function()
 19{
 20    objj_msgSend(CPDragServerSource, "autoscroll:", CPDragServerPreviousEvent);
 21}
 22var CPDragServerStartDragging = function(anEvent)
 23{
 24    CPDragServerUpdateDragging(anEvent);
 25}
 26var CPDragServerUpdateDragging = function(anEvent)
 27{
 28    if(objj_msgSend(anEvent, "type") == CPLeftMouseUp)
 29    {
 30        if (CPDragServerAutoscrollInterval !== nil)
 31            clearInterval(CPDragServerAutoscrollInterval);
 32        CPDragServerAutoscrollInterval = nil;
 33        CPDragServerLocation = objj_msgSend((objj_msgSend(CPDragServerDestination, "isKindOfClass:", objj_msgSend(CPWindow, "class")) ? CPDragServerDestination : objj_msgSend(CPDragServerDestination, "window")), "convertBridgeToBase:", objj_msgSend(objj_msgSend(anEvent, "window"), "convertBaseToBridge:", objj_msgSend(anEvent, "locationInWindow")));
 34        objj_msgSend(CPDragServerView, "removeFromSuperview");
 35        objj_msgSend(CPSharedDragServer._dragWindow, "orderOut:", nil);
 36        if (CPDragServerDestination &&
 37            (!objj_msgSend(CPDragServerDestination, "respondsToSelector:", sel_getUid("prepareForDragOperation:")) || objj_msgSend(CPDragServerDestination, "prepareForDragOperation:", CPDragServerDraggingInfo)) &&
 38            (!objj_msgSend(CPDragServerDestination, "respondsToSelector:", sel_getUid("performDragOperation:")) || objj_msgSend(CPDragServerDestination, "performDragOperation:", CPDragServerDraggingInfo)) &&
 39            objj_msgSend(CPDragServerDestination, "respondsToSelector:", sel_getUid("concludeDragOperation:")))
 40            objj_msgSend(CPDragServerDestination, "concludeDragOperation:", CPDragServerDraggingInfo);
 41        if (CPDragServerShouldSendDraggedImageEndedAtOperation)
 42            objj_msgSend(CPDragServerSource, "draggedImage:endedAt:operation:", objj_msgSend(CPDragServerView, "image"), CPDragServerLocation, NO);
 43        else if (CPDragServerShouldSendDraggedViewEndedAtOperation)
 44            objj_msgSend(CPDragServerSource, "draggedView:endedAt:operation:", CPDragServerView, CPDragServerLocation, NO);
 45        CPDragServerIsDraggingImage = NO;
 46        CPDragServerDestination = nil;
 47        return;
 48    }
 49    if (CPDragServerAutoscrollInterval === nil)
 50    {
 51        if (objj_msgSend(CPDragServerSource, "respondsToSelector:", sel_getUid("autoscroll:")))
 52            CPDragServerAutoscrollInterval = setInterval(CPDragServerAutoscroll, 100);
 53    }
 54    CPDragServerPreviousEvent = anEvent;
 55    objj_msgSend(CPApp, "setCallback:forNextEventMatchingMask:untilDate:inMode:dequeue:", CPDragServerUpdateDragging, CPMouseMovedMask | CPLeftMouseDraggedMask | CPLeftMouseUpMask, nil, 0, NO);
 56    var location = objj_msgSend(anEvent, "locationInWindow"),
 57        operation =
 58        bridgeLocation = objj_msgSend(objj_msgSend(anEvent, "window"), "convertBaseToBridge:", location);
 59    var draggingDestination = objj_msgSend(objj_msgSend(CPDOMWindowBridge, "sharedDOMWindowBridge"), "_dragHitTest:pasteboard:", bridgeLocation, CPDragServerPasteboard);
 60    CPDragServerLocation = objj_msgSend((objj_msgSend(draggingDestination, "isKindOfClass:", objj_msgSend(CPWindow, "class")) ? draggingDestination : objj_msgSend(draggingDestination, "window")), "convertBridgeToBase:", bridgeLocation);
 61    if(draggingDestination != CPDragServerDestination)
 62    {
 63        if (CPDragServerDestination && objj_msgSend(CPDragServerDestination, "respondsToSelector:", sel_getUid("draggingExited:")))
 64            objj_msgSend(CPDragServerDestination, "draggingExited:", CPDragServerDraggingInfo);
 65        CPDragServerDestination = draggingDestination;
 66        if (CPDragServerDestination && objj_msgSend(CPDragServerDestination, "respondsToSelector:", sel_getUid("draggingEntered:")))
 67            objj_msgSend(CPDragServerDestination, "draggingEntered:", CPDragServerDraggingInfo);
 68    }
 69    else if (CPDragServerDestination && objj_msgSend(CPDragServerDestination, "respondsToSelector:", sel_getUid("draggingUpdated:")))
 70        objj_msgSend(CPDragServerDestination, "draggingUpdated:", CPDragServerDraggingInfo);
 71    location.x -= CPDragServerOffset.x;
 72    location.y -= CPDragServerOffset.y;
 73    objj_msgSend(CPDragServerView, "setFrameOrigin:", location);
 74    if (CPDragServerShouldSendDraggedImageMovedTo)
 75        objj_msgSend(CPDragServerSource, "draggedImage:movedTo:", objj_msgSend(CPDragServerView, "image"), location);
 76    else if (CPDragServerShouldSendDraggedViewMovedTo)
 77        objj_msgSend(CPDragServerSource, "draggedView:movedTo:", CPDragServerView, location);
 78}
 79{var the_class = objj_allocateClassPair(CPObject, "CPDraggingInfo"),
 80meta_class = the_class.isa;objj_registerClassPair(the_class);
 81objj_addClassForBundle(the_class, objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
 82class_addMethods(the_class, [new objj_method(sel_getUid("draggingSource"), function $CPDraggingInfo__draggingSource(self, _cmd)
 83{ with(self)
 84{
 85    return CPDragServerSource;
 86}
 87}), new objj_method(sel_getUid("draggingLocation"), function $CPDraggingInfo__draggingLocation(self, _cmd)
 88{ with(self)
 89{
 90    return CPDragServerLocation;
 91}
 92}), new objj_method(sel_getUid("draggingPasteboard"), function $CPDraggingInfo__draggingPasteboard(self, _cmd)
 93{ with(self)
 94{
 95    return CPDragServerPasteboard;
 96}
 97}), new objj_method(sel_getUid("draggedImage"), function $CPDraggingInfo__draggedImage(self, _cmd)
 98{ with(self)
 99{
100    return objj_msgSend(CPDragServerView, "image");
101}
102}), new objj_method(sel_getUid("draggedImageLocation"), function $CPDraggingInfo__draggedImageLocation(self, _cmd)
103{ with(self)
104{
105    return objj_msgSend(self, "draggedViewLocation");
106}
107}), new objj_method(sel_getUid("draggedViewLocation"), function $CPDraggingInfo__draggedViewLocation(self, _cmd)
108{ with(self)
109{
110    return objj_msgSend((objj_msgSend(CPDragServerDestination, "isKindOfClass:", objj_msgSend(CPWindow, "class")) ? CPDragServerDestination : objj_msgSend(CPDragServerDestination, "window")), "convertBridgeToBase:", objj_msgSend(CPDragServerView, "frame").origin);
111}
112}), new objj_method(sel_getUid("draggedView"), function $CPDraggingInfo__draggedView(self, _cmd)
113{ with(self)
114{
115    return CPDragServerView;
116}
117})]);
118}
119{var the_class = objj_allocateClassPair(CPObject, "CPDragServer"),
120meta_class = the_class.isa;class_addIvars(the_class, [new objj_ivar("_dragWindow"), new objj_ivar("_imageView")]);
121objj_registerClassPair(the_class);
122objj_addClassForBundle(the_class, objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
123class_addMethods(the_class, [new objj_method(sel_getUid("init"), function $CPDragServer__init(self, _cmd)
124{ with(self)
125{
126    self = objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPObject") }, "init");
127    if (self)
128    {
129        _dragWindow = objj_msgSend(objj_msgSend(CPWindow, "alloc"), "initWithContentRect:styleMask:", CPRectMakeZero(), CPBorderlessWindowMask);
130        objj_msgSend(_dragWindow, "setLevel:", CPDraggingWindowLevel);
131    }
132    return self;
133}
134}), new objj_method(sel_getUid("dragView:fromWindow:at:offset:event:pasteboard:source:slideBack:"), function $CPDragServer__dragView_fromWindow_at_offset_event_pasteboard_source_slideBack_(self, _cmd, aView, aWindow, viewLocation, mouseOffset, anEvent, aPasteboard, aSourceObject, slideBack)
135{ with(self)
136{
137    var eventLocation = objj_msgSend(anEvent, "locationInWindow");
138    CPDragServerView = aView;
139    CPDragServerSource = aSourceObject;
140    CPDragServerWindow = aWindow;
141    CPDragServerOffset = CPPointMake(eventLocation.x - viewLocation.x, eventLocation.y - viewLocation.y);
142    CPDragServerPasteboard = objj_msgSend(CPPasteboard, "pasteboardWithName:", CPDragPboard);
143    objj_msgSend(_dragWindow, "setFrameSize:", CGSizeMakeCopy(objj_msgSend(objj_msgSend(CPDOMWindowBridge, "sharedDOMWindowBridge"), "frame").size));
144    objj_msgSend(_dragWindow, "orderFront:", self);
145    objj_msgSend(aView, "setFrameOrigin:", viewLocation);
146    objj_msgSend(objj_msgSend(_dragWindow, "contentView"), "addSubview:", aView);
147    if (CPDragServerIsDraggingImage)
148    {
149        if (objj_msgSend(CPDragServerSource, "respondsToSelector:", sel_getUid("draggedImage:beganAt:")))
150            objj_msgSend(CPDragServerSource, "draggedImage:beganAt:", objj_msgSend(aView, "image"), viewLocation);
151        CPDragServerShouldSendDraggedImageMovedTo = objj_msgSend(CPDragServerSource, "respondsToSelector:", sel_getUid("draggedImage:movedTo:"));
152        CPDragServerShouldSendDraggedImageEndedAtOperation = objj_msgSend(CPDragServerSource, "respondsToSelector:", sel_getUid("draggedImage:endAt:operation:"));
153        CPDragServerShouldSendDraggedViewMovedTo = NO;
154        CPDragServerShouldSendDraggedViewEndedAtOperation = NO;
155    }
156    else
157    {
158        if (objj_msgSend(CPDragServerSource, "respondsToSelector:", sel_getUid("draggedView:beganAt:")))
159            objj_msgSend(CPDragServerSource, "draggedView:beganAt:", aView, viewLocation);
160        CPDragServerShouldSendDraggedViewMovedTo = objj_msgSend(CPDragServerSource, "respondsToSelector:", sel_getUid("draggedView:movedTo:"));
161        CPDragServerShouldSendDraggedViewEndedAtOperation = objj_msgSend(CPDragServerSource, "respondsToSelector:", sel_getUid("draggedView:endedAt:operation:"));
162        CPDragServerShouldSendDraggedImageMovedTo = NO;
163        CPDragServerShouldSendDraggedImageEndedAtOperation = NO;
164    }
165    CPDragServerStartDragging(anEvent);
166}
167}), new objj_method(sel_getUid("dragImage:fromWindow:at:offset:event:pasteboard:source:slideBack:"), function $CPDragServer__dragImage_fromWindow_at_offset_event_pasteboard_source_slideBack_(self, _cmd, anImage, aWindow, imageLocation, mouseOffset, anEvent, aPasteboard, aSourceObject, slideBack)
168{ with(self)
169{
170    CPDragServerIsDraggingImage = YES;
171    if (!_imageView)
172        _imageView = objj_msgSend(objj_msgSend(CPImageView, "alloc"), "initWithFrame:", CPRectMakeZero());
173    objj_msgSend(_imageView, "setImage:", anImage);
174    objj_msgSend(_imageView, "setFrameSize:", CGSizeMakeCopy(objj_msgSend(anImage, "size")));
175    objj_msgSend(self, "dragView:fromWindow:at:offset:event:pasteboard:source:slideBack:", _imageView, aWindow, imageLocation, mouseOffset, anEvent, aPasteboard, aSourceObject, slideBack);
176}
177})]);
178class_addMethods(meta_class, [new objj_method(sel_getUid("initialize"), function $CPDragServer__initialize(self, _cmd)
179{ with(self)
180{
181    if (self != objj_msgSend(CPDragServer, "class"))
182        return;
183    CPDragServerDraggingInfo = objj_msgSend(objj_msgSend(CPDraggingInfo, "alloc"), "init");
184}
185}), new objj_method(sel_getUid("sharedDragServer"), function $CPDragServer__sharedDragServer(self, _cmd)
186{ with(self)
187{
188    if (!CPSharedDragServer)
189        CPSharedDragServer = objj_msgSend(objj_msgSend(CPDragServer, "alloc"), "init");
190    return CPSharedDragServer;
191}
192})]);
193}
194{
195var the_class = objj_getClass("CPWindow")
196if(!the_class) objj_exception_throw(new objj_exception(OBJJClassNotFoundException, "*** Could not find definition for class \"CPWindow\""));
197var meta_class = the_class.isa;class_addMethods(the_class, [new objj_method(sel_getUid("_dragHitTest:pasteboard:"), function $CPWindow___dragHitTest_pasteboard_(self, _cmd, aPoint, aPasteboard)
198{ with(self)
199{
200    if (!_inclusiveRegisteredDraggedTypes)
201        return nil;
202    var adjustedPoint = { x:aPoint.x - (_frame.origin.x), y:aPoint.y - (_frame.origin.y) },
203        hitView = objj_msgSend(_windowView, "hitTest:", adjustedPoint);
204    while (hitView && !objj_msgSend(aPasteboard, "availableTypeFromArray:", objj_msgSend(hitView, "registeredDraggedTypes")))
205        hitView = objj_msgSend(hitView, "superview");
206    if (hitView)
207        return hitView;
208    if (objj_msgSend(aPasteboard, "availableTypeFromArray:", objj_msgSend(self, "registeredDraggedTypes")))
209        return self;
210    return nil;
211}
212})]);
213}
214