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:
65: native void nativeStartDrag(Image i, int x, int y, int action, String target);
66: native void connectSignals(ComponentPeer comp);
67: native void create(ComponentPeer comp);
68: native void nativeSetCursor(int cursor);
69:
70: public GtkDragSourceContextPeer(DragGestureEvent e)
71: {
72: super(e.getComponent());
73: Component comp = e.getComponent();
74: peer = getComponentPeer(comp);
75:
76: create(peer);
77: connectSignals(peer);
78: cursor = comp.getCursor();
79: }
80:
81: ComponentPeer getComponentPeer(Component c)
82: {
83: Component curr = c;
84: while (curr.getPeer() instanceof LightweightPeer)
85: curr = curr.getParent();
86:
87: if (curr != null)
88: return curr.getPeer();
89: return null;
90: }
91:
92: public void startDrag(DragSourceContext context, Cursor c, Image i, Point p)
93: throws InvalidDnDOperationException
94: {
95: this.context = context;
96:
97: if (p == null)
98: p = new Point();
99:
100:
101:
102:
103: setCursor(c);
104: nativeStartDrag(i, p.x, p.y, context.getTrigger().getDragAction(),
105: "text/plain");
106: }
107:
108: public Cursor getCursor()
109: {
110: return cursor;
111: }
112:
113: public void setCursor(Cursor c) throws InvalidDnDOperationException
114: {
115: if (c != null)
116: {
117: nativeSetCursor(c.getType());
118: cursor = c;
119: }
120: }
121:
122: public void transferablesFlavorsChanged()
123: {
124:
125: }
126:
127:
130:
131: public void dragEnter(int action, int modifiers)
132: {
133: context.dragEnter(new DragSourceDragEvent(context, action,
134: action
135: & context.getSourceActions(),
136: modifiers));
137: }
138:
139: public void dragExit(int action, int x, int y)
140: {
141: context.dragExit(new DragSourceEvent(context, x, y));
142: }
143:
144: public void dragDropEnd(int action, boolean success, int x, int y)
145: {
146: context.dragDropEnd(new DragSourceDropEvent(context, action, success, x, y));
147: }
148:
149: public void dragMouseMoved(int action, int modifiers)
150: {
151: context.dragMouseMoved(new DragSourceDragEvent(context,
152: action,
153: action
154: & context.getSourceActions(),
155: modifiers));
156: }
157:
158: public void dragOver(int action, int modifiers)
159: {
160: context.dragOver(new DragSourceDragEvent(context, action,
161: action
162: & context.getSourceActions(),
163: modifiers));
164: }
165:
166: public void dragActionChanged(int newAction, int modifiers)
167: {
168: context.dropActionChanged(new DragSourceDragEvent(context,
169: newAction,
170: newAction
171: & context.getSourceActions(),
172: modifiers));
173: }
174: }