History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/awt/iWindowPeer.java (1 of 18352 files). Show all

Unified · Split

java/pkg/awt/iWindowPeer.java+411−0
@@ -0,0 +1,411 @@
1+/*
2+ * %W% - %E%
3+ */
4+
5+package inferno.awt;
6+
7+import java.awt.*;
8+import java.awt.event.*;
9+import java.awt.peer.*;
10+import java.awt.image.ImageProducer;
11+import java.awt.image.ImageObserver;
12+import java.awt.image.ColorModel;
13+import java.awt.image.DirectColorModel;
14+import java.util.*;
15+import inferno.awt.iGraphics;
16+
17+public class iWindowPeer implements WindowPeer, DoubleBufferingPeer {
18+ Object pCanvas; // Set inside create()
19+ Window target;
20+ int leftInset=0; // How much canvas is inset from window
21+ int rightInset=0;
22+ int topInset=0;
23+ int bottomInset=0;
24+ int left; // x position of left of window
25+ int top; // y position of top of window
26+
27+ private Point oldMousePoint;
28+ private boolean buttonState[];
29+
30+ public iWindowPeer(Window target) {
31+ this.target = target;
32+ oldMousePoint=new Point(-1,-1);
33+ buttonState=new boolean[3];
34+ for (int i=0;i<3;i++) buttonState[i]=false; //up
35+ create(this);
36+ Font f = target.getFont();
37+ if (f == null) {
38+ f = new Font("Dialog", Font.PLAIN, 12);
39+ target.setFont(f);
40+ setFont(f);
41+ }
42+ Color c = target.getBackground();
43+ if (c == null) {
44+ c = SystemColor.window;
45+ target.setBackground(c);
46+ setBackground(c);
47+ }
48+ c = target.getForeground();
49+ if (c == null) {
50+ target.setForeground(Color.black);
51+ setForeground(Color.black);
52+ }
53+
54+ }
55+
56+ /* implementation of java.awt.peer.DoubleBufferingPeer */
57+ public boolean isDoubleBuffered() {
58+ return true;
59+ }
60+
61+ native Object getRefImage(); // Returns $Draw->Image of canvas
62+ native Object getRefOffScreenImage(); // Returns off-screen buffer image
63+
64+ native void pReshape(int x, int y, int width, int height);
65+
66+ native void pHide(); // Hide window
67+
68+ native void pShow(iWindowPeer fp); // Show window
69+
70+ native int getXYLoc(int coord); // get x or y value of the global position
71+
72+ public native void create(iWindowPeer fp); // Create window putting canvas in pcanvas
73+
74+ public native void pDispose(); // Destroy window
75+
76+ public native void setCursor(int cursorType); // Set cursor
77+
78+
79+ /* New 1.1 API */
80+ public Point getLocationOnScreen() // Return position on screen
81+ {
82+ Point p = new Point();
83+ p.x = getXYLoc(0);
84+ p.y = getXYLoc(1);
85+ return p;
86+ }
87+
88+ public void setCursor(Cursor c)
89+ {
90+ if (c!=null)
91+ setCursor(c.getType());
92+ }
93+
94+ public native void toFront(); // Move window to front
95+
96+ public native void toBack(); // Move window to back
97+
98+ public Insets getInsets()
99+ {
100+ Insets i=new Insets(topInset,leftInset,bottomInset,rightInset);
101+ return i;
102+ }
103+
104+ public Insets insets()
105+ {
106+ return getInsets();
107+ }
108+
109+ public void endValidate()
110+ {
111+
112+ }
113+
114+ public void beginValidate()
115+ {
116+
117+ }
118+
119+ public void setBounds(int x, int y, int width, int height) {
120+ pReshape(x, y, width, height);
121+ }
122+
123+ public void reshape(int x, int y, int width, int height) {
124+ pReshape(x, y, width, height);
125+ }
126+
127+
128+ public void dispose()
129+ {
130+ pDispose();
131+ pCanvas=null;
132+ }
133+
134+ public void disable()
135+ {
136+ setEnabled(false);
137+ }
138+
139+ public void enable()
140+ {
141+ setEnabled(false);
142+ }
143+
144+ public void setEnabled(boolean b)
145+ {
146+
147+ }
148+
149+ public void hide()
150+ {
151+ setVisible(false);
152+ }
153+
154+ public void show()
155+ {
156+ setVisible(true);
157+ }
158+
159+ public void setVisible(boolean b)
160+ {
161+ if (b)
162+ pShow(this);
163+ else
164+ pHide();
165+ }
166+
167+ public Dimension getMinimumSize() {
168+ return target.getSize();
169+ }
170+
171+ public Dimension getPreferredSize() {
172+ return getMinimumSize();
173+ }
174+
175+ public Dimension minimumSize() {
176+ return getMinimumSize();
177+ }
178+
179+ public Dimension preferredSize() {
180+ return getPreferredSize();
181+ }
182+
183+
184+ public int checkImage(Image img, int w, int h, ImageObserver o) {
185+ return 0;
186+ }
187+
188+ public FontMetrics getFontMetrics(Font font) {
189+ return iFontMetrics.getFontMetrics(font);
190+ }
191+
192+ public boolean prepareImage(Image img, int w, int h, ImageObserver o) {
193+ return false;
194+ }
195+
196+
197+ public Image createImage(ImageProducer producer) {
198+ return null/*new Win32Image(producer)*/;
199+ }
200+ public Image createImage(int width, int height) {
201+ return null/*new Win32Image(target, width, height)*/;
202+ }
203+
204+ public boolean isFocusTraversable() {
205+ return false;
206+ }
207+
208+ public void requestFocus()
209+ {
210+ }
211+
212+ public void nextFocus()
213+ {
214+ }
215+
216+ public void setFont(Font f)
217+ {
218+
219+ }
220+
221+ public Font getFont()
222+ {
223+ return null;
224+ }
225+
226+ public void setBackground(Color c)
227+ {
228+
229+ }
230+
231+ public void setForeground(Color c)
232+ {
233+
234+ }
235+
236+ public Graphics getGraphics()
237+ {
238+ if (pCanvas == null) {
239+ System.out.println("iWindowPeer:getGraphics()s: pCanvas == null, continuing!"); // jfs -remove
240+ return null;
241+ }
242+ Rectangle bounds = target.getBounds();
243+ Rectangle clip = new Rectangle(bounds.x+leftInset,
244+ bounds.y+topInset,
245+ bounds.width-leftInset-rightInset,
246+ bounds.height-topInset-bottomInset);
247+ Graphics g=new iGraphics(getRefImage(),getRefOffScreenImage(), clip,
248+target);
249+ g.translate(bounds.x,bounds.y);
250+ return g;
251+ }
252+
253+ public java.awt.Toolkit getToolkit() {
254+ // XXX: bogus
255+ return Toolkit.getDefaultToolkit();
256+ }
257+
258+ public ColorModel getColorModel() {
259+ return iToolkit.getStaticColorModel();
260+ }
261+
262+ public void handleEvent(AWTEvent e)
263+ {
264+
265+ }
266+
267+ public void print(Graphics g)
268+ {
269+ }
270+
271+ public void paint(Graphics g)
272+ {
273+ g.setColor(target.getForeground());
274+ g.setFont(target.getFont());
275+ target.paint(g);
276+ }
277+
278+
279+ public void repaint(long tm, int x, int y, int width, int height) {
280+ iToolkit.postEvent(new PaintEvent((Component)target, PaintEvent.UPDATE,
281+ new Rectangle(x, y, width, height)));
282+
283+ }
284+
285+ public void handleKeyEvents(int ch)
286+ {
287+ char keyChar = (char)ch;
288+ boolean control = ch >= 0 && ch <= 31;
289+ boolean lowercase = ch >= (int)'a' && ch <= (int)'z';
290+ boolean uppercase = ch >= (int)'A' && ch <= (int)'Z';
291+ int modifiers = control?InputEvent.CTRL_MASK:
292+ uppercase?InputEvent.SHIFT_MASK:0;
293+ int keyCode = control?ch+64:lowercase?ch-32:ch;
294+ Date d = new Date();
295+ long when = d.getTime();
296+
297+ iToolkit.postEvent(new KeyEvent(target,KeyEvent.KEY_PRESSED,
298+ when,modifiers,keyCode,keyChar));
299+
300+ }
301+
302+private void handleMouseEvents(int m,int button,int x,int y)
303+{
304+ char mode=(char)m;
305+ // System.out.println("Mouse event "+mode+" "+button+" "+x+" "+y);
306+ switch(mode)
307+ {
308+ case 'd':
309+ case 'r':
310+ case 'm':
311+ case 'p':
312+ Rectangle bounds = target.getBounds();
313+ int xx=x-bounds.x-leftInset;
314+ int yy=y-bounds.y; // -topInset;
315+
316+ Point mousePoint=new Point(xx,yy);
317+ //Date d = new Date();
318+ //long when = d.getTime();
319+ long when=0;
320+ int modifier;
321+
322+ switch(button)
323+ {
324+ case 1:
325+ modifier=InputEvent.BUTTON1_MASK;
326+ break;
327+
328+ case 2:
329+ modifier=InputEvent.BUTTON2_MASK;
330+ break;
331+
332+ case 3:
333+ modifier=InputEvent.BUTTON3_MASK;
334+ break;
335+
336+ default:
337+ modifier=0;
338+ }
339+
340+ switch(mode)
341+ {
342+ case 'p': // Pressed
343+ case 'd': // Double click
344+ {
345+ if (button>0 && button<=3 && buttonState[button-1]==false)
346+ {
347+ oldMousePoint=mousePoint;
348+ buttonState[button-1]=true;
349+ iToolkit.postEvent(new MouseEvent(target,MouseEvent.MOUSE_PRESSED,
350+ when,modifier,xx,yy,1,false));
351+
352+ }
353+ break;
354+ }
355+ case 'r': // Released
356+ {
357+ if (button>0 && button<=3 && buttonState[button-1]==true)
358+ {
359+ buttonState[button-1]=false;
360+ iToolkit.postEvent(new MouseEvent(target,MouseEvent.MOUSE_RELEASED,
361+ when,modifier,xx,yy,1,false));
362+ if (mousePoint.equals(oldMousePoint))
363+ {
364+ iToolkit.postEvent(new MouseEvent(target,MouseEvent.MOUSE_CLICKED,
365+ when,modifier,xx,yy,1,button==2));
366+ }
367+ }
368+ break;
369+ }
370+ case 'm': // Moved
371+ {
372+ modifier=0;
373+ if (buttonState[0]) modifier|=InputEvent.BUTTON1_MASK;
374+ if (buttonState[1]) modifier|=InputEvent.BUTTON2_MASK;
375+ if (buttonState[2]) modifier|=InputEvent.BUTTON3_MASK;
376+ iToolkit.postEvent(new MouseEvent(target,
377+ modifier==0?MouseEvent.MOUSE_MOVED:MouseEvent.MOUSE_DRAGGED,
378+ when,modifier,xx,yy,1,false));
379+
380+ break;
381+ }
382+ default:
383+ // System.out.println("MouseString: " + mouseString);
384+ }
385+ break;
386+ }
387+}
388+
389+ private void movesize(int x, int y, int width, int height)
390+ {
391+ Rectangle old = target.getBounds();
392+ Rectangle n = new Rectangle(x, y, width, height);
393+ if (!n.equals(old)){
394+ target.setBounds(x, y, width, height);
395+ target.repaint();
396+ }
397+ }
398+
399+ public void handleFocusGained()
400+ {
401+
402+ }
403+}
404+
405+
406+
407+
408+
409+
410+
411+