1:
37:
38:
39: package ;
40:
41: import ;
42:
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56:
57: public class GtkDragSourceContextPeer
58: extends GtkGenericPeer
59: implements DragSourceContextPeer
60: {
61: private ComponentPeer peer;
62: private Cursor cursor;
63: private DragSourceContext context;
64: public static Component target;
65:
66: native void nativeStartDrag(Image i, int x, int y, int action, String target);
67: native void connectSignals(ComponentPeer comp);
68: native void create(ComponentPeer comp);
69: native void nativeSetCursor(int cursor);
70: native void setTarget(GtkDropTargetContextPeer target);
71:
72: public GtkDragSourceContextPeer(DragGestureEvent e)
73: {
74: super(e.getComponent());
75: Component comp = e.getComponent();
76: peer = getComponentPeer(comp);
77:
78: create(peer);
79: connectSignals(peer);
80: cursor = comp.getCursor();
81:
82:
83:
84: if ((target != null))
85: setTarget(new GtkDropTargetContextPeer(target));
86: }
87:
88: ComponentPeer getComponentPeer(Component c)
89: {
90: if (c == null)
91: return null;
92:
93: Component curr = c;
94: while (curr.getPeer() instanceof LightweightPeer)
95: curr = curr.getParent();
96:
97: if (curr != null)
98: return curr.getPeer();
99: return null;
100: }
101:
102: public void startDrag(DragSourceContext context, Cursor c, Image i, Point p)
103: throws InvalidDnDOperationException
104: {
105: this.context = context;
106:
107: if (p == null)
108: p = new Point();
109:
110:
111:
112:
113: setCursor(c);
114: nativeStartDrag(i, p.x, p.y, context.getTrigger().getDragAction(),
115: "text/plain");
116: }
117:
118: public Cursor getCursor()
119: {
120: return cursor;
121: }
122:
123: public void setCursor(Cursor c) throws InvalidDnDOperationException
124: {
125: if (c != null)
126: {
127: nativeSetCursor(c.getType());
128: cursor = c;
129: }
130: }
131:
132: public void transferablesFlavorsChanged()
133: {
134:
135: }
136:
137:
140:
141: public void dragEnter(int action, int modifiers)
142: {
143: context.dragEnter(new DragSourceDragEvent(context, action,
144: action
145: & context.getSourceActions(),
146: modifiers));
147: }
148:
149: public void dragExit(int action, int x, int y)
150: {
151: context.dragExit(new DragSourceEvent(context, x, y));
152: }
153:
154: public void dragDropEnd(int action, boolean success, int x, int y)
155: {
156: context.dragDropEnd(new DragSourceDropEvent(context, action, success, x, y));
157: }
158:
159: public void dragMouseMoved(int action, int modifiers)
160: {
161: context.dragMouseMoved(new DragSourceDragEvent(context,
162: action,
163: action
164: & context.getSourceActions(),
165: modifiers));
166: }
167:
168: public void dragOver(int action, int modifiers)
169: {
170: context.dragOver(new DragSourceDragEvent(context, action,
171: action
172: & context.getSourceActions(),
173: modifiers));
174: }
175:
176: public void dragActionChanged(int newAction, int modifiers)
177: {
178: context.dropActionChanged(new DragSourceDragEvent(context,
179: newAction,
180: newAction
181: & context.getSourceActions(),
182: modifiers));
183: }
184: }