~ubuntu-branches/ubuntu/dapper/ikvm/dapper

« back to all changes in this revision

Viewing changes to awt/toolkit.cs

  • Committer: Bazaar Package Importer
  • Author(s): John Goerzen
  • Date: 2004-08-26 10:18:19 UTC
  • Revision ID: james.westby@ubuntu.com-20040826101819-plz8au2mx4uk1cvc
Tags: upstream-0.8.0.0
ImportĀ upstreamĀ versionĀ 0.8.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (C) 2002 Jeroen Frijters
 
3
 
 
4
  This software is provided 'as-is', without any express or implied
 
5
  warranty.  In no event will the authors be held liable for any damages
 
6
  arising from the use of this software.
 
7
 
 
8
  Permission is granted to anyone to use this software for any purpose,
 
9
  including commercial applications, and to alter it and redistribute it
 
10
  freely, subject to the following restrictions:
 
11
 
 
12
  1. The origin of this software must not be misrepresented; you must not
 
13
     claim that you wrote the original software. If you use this software
 
14
     in a product, an acknowledgment in the product documentation would be
 
15
     appreciated but is not required.
 
16
  2. Altered source versions must be plainly marked as such, and must not be
 
17
     misrepresented as being the original software.
 
18
  3. This notice may not be removed or altered from any source distribution.
 
19
 
 
20
  Jeroen Frijters
 
21
  jeroen@frijters.net
 
22
  
 
23
*/
 
24
 
 
25
using System;
 
26
using System.Threading;
 
27
using System.Windows.Forms;
 
28
using System.Drawing;
 
29
using System.ComponentModel;
 
30
using java.awt.datatransfer;
 
31
using java.awt.image;
 
32
using java.awt.peer;
 
33
using java.net;
 
34
using java.util;
 
35
 
 
36
namespace ikvm.awt
 
37
{
 
38
        delegate void SetVoid();
 
39
        delegate void SetBool(bool b);
 
40
        delegate void SetInt(int i);
 
41
        delegate void SetXYWH(int x, int y, int w, int h);
 
42
        delegate void SetString(string s);
 
43
        delegate string GetString();
 
44
        delegate void SetStringInt(string s, int i);
 
45
        delegate void SetRectangle(Rectangle r);
 
46
        delegate void SetColor(Color c);
 
47
        delegate java.awt.Dimension GetDimension();
 
48
 
 
49
        class UndecoratedForm : Form
 
50
        {
 
51
                public UndecoratedForm()
 
52
                {
 
53
                        this.FormBorderStyle = FormBorderStyle.None;
 
54
                }
 
55
        }
 
56
 
 
57
        public class NetToolkit : gnu.java.awt.ClasspathToolkit
 
58
        {
 
59
                private static java.awt.EventQueue eventQueue = new java.awt.EventQueue();
 
60
                private static Form bogusForm;
 
61
                private static Delegate createControlInstance;
 
62
                private int resolution;
 
63
 
 
64
                private delegate Control CreateControlInstanceDelegate(Type type);
 
65
 
 
66
                private static void MessageLoop()
 
67
                {
 
68
                        createControlInstance = new CreateControlInstanceDelegate(CreateControlImpl);
 
69
                        Form form = new Form();
 
70
                        form.CreateControl();
 
71
                        // HACK I have no idea why this line is necessary...
 
72
                        IntPtr p = form.Handle;
 
73
                        bogusForm = form;
 
74
                        Application.Run();
 
75
                }
 
76
 
 
77
                internal static Control CreateControlImpl(Type type)
 
78
                {
 
79
                        Control control = (Control)Activator.CreateInstance(type);
 
80
                        control.CreateControl();
 
81
                        // HACK here we go again...
 
82
                        IntPtr p = control.Handle;
 
83
                        return control;
 
84
                }
 
85
 
 
86
                internal static Control CreateControl(Type type)
 
87
                {
 
88
                        return (Control)bogusForm.Invoke(createControlInstance, new object[] { type });
 
89
                }
 
90
 
 
91
                public NetToolkit()
 
92
                {
 
93
                        lock(typeof(NetToolkit))
 
94
                        {
 
95
                                System.Diagnostics.Debug.Assert(bogusForm == null);
 
96
 
 
97
                                Thread thread = new Thread(new ThreadStart(MessageLoop));
 
98
                                thread.Start();
 
99
                                // TODO don't use polling...
 
100
                                while(bogusForm == null)
 
101
                                {
 
102
                                        Thread.Sleep(1);
 
103
                                }
 
104
                        }
 
105
                }
 
106
 
 
107
                protected override void loadSystemColors(int[] systemColors)
 
108
                {
 
109
                        // initialize all colors to purple to make the ones we might have missed stand out
 
110
                        for(int i = 0; i < systemColors.Length; i++)
 
111
                        {
 
112
                                systemColors[i] = Color.Purple.ToArgb();
 
113
                        }
 
114
                        systemColors[java.awt.SystemColor.DESKTOP] = SystemColors.Desktop.ToArgb();
 
115
                        systemColors[java.awt.SystemColor.ACTIVE_CAPTION] = SystemColors.ActiveCaption.ToArgb();
 
116
                        systemColors[java.awt.SystemColor.ACTIVE_CAPTION_TEXT] = SystemColors.ActiveCaptionText.ToArgb();
 
117
                        systemColors[java.awt.SystemColor.ACTIVE_CAPTION_BORDER] = SystemColors.ActiveBorder.ToArgb();
 
118
                        systemColors[java.awt.SystemColor.INACTIVE_CAPTION] = SystemColors.InactiveCaption.ToArgb();
 
119
                        systemColors[java.awt.SystemColor.INACTIVE_CAPTION_TEXT] = SystemColors.InactiveCaptionText.ToArgb();
 
120
                        systemColors[java.awt.SystemColor.INACTIVE_CAPTION_BORDER] = SystemColors.InactiveBorder.ToArgb();
 
121
                        systemColors[java.awt.SystemColor.WINDOW] = SystemColors.Window.ToArgb();
 
122
                        systemColors[java.awt.SystemColor.WINDOW_BORDER] = SystemColors.WindowFrame.ToArgb();
 
123
                        systemColors[java.awt.SystemColor.WINDOW_TEXT] = SystemColors.WindowText.ToArgb();
 
124
                        systemColors[java.awt.SystemColor.MENU] = SystemColors.Menu.ToArgb();
 
125
                        systemColors[java.awt.SystemColor.MENU_TEXT] = SystemColors.MenuText.ToArgb();
 
126
                        systemColors[java.awt.SystemColor.TEXT] = SystemColors.Window.ToArgb();
 
127
                        systemColors[java.awt.SystemColor.TEXT_TEXT] = SystemColors.WindowText.ToArgb();
 
128
                        systemColors[java.awt.SystemColor.TEXT_HIGHLIGHT] = SystemColors.Highlight.ToArgb();
 
129
                        systemColors[java.awt.SystemColor.TEXT_HIGHLIGHT_TEXT] = SystemColors.HighlightText.ToArgb();
 
130
                        systemColors[java.awt.SystemColor.TEXT_INACTIVE_TEXT] = SystemColors.GrayText.ToArgb();
 
131
                        systemColors[java.awt.SystemColor.CONTROL] = SystemColors.Control.ToArgb();
 
132
                        systemColors[java.awt.SystemColor.CONTROL_TEXT] = SystemColors.ControlText.ToArgb();
 
133
                        systemColors[java.awt.SystemColor.CONTROL_HIGHLIGHT] = SystemColors.ControlLight.ToArgb();
 
134
                        systemColors[java.awt.SystemColor.CONTROL_LT_HIGHLIGHT] = SystemColors.ControlLightLight.ToArgb();
 
135
                        systemColors[java.awt.SystemColor.CONTROL_SHADOW] = SystemColors.ControlDark.ToArgb();
 
136
                        systemColors[java.awt.SystemColor.CONTROL_DK_SHADOW] = SystemColors.ControlDarkDark.ToArgb();
 
137
                        systemColors[java.awt.SystemColor.SCROLLBAR] = SystemColors.ScrollBar.ToArgb();
 
138
                        systemColors[java.awt.SystemColor.INFO] = SystemColors.Info.ToArgb();
 
139
                        systemColors[java.awt.SystemColor.INFO_TEXT] = SystemColors.InfoText.ToArgb();
 
140
                }
 
141
 
 
142
                protected override java.awt.peer.ButtonPeer createButton(java.awt.Button target)
 
143
                {
 
144
                        return new NetButtonPeer(target, (Button)CreateControl(typeof(Button)));
 
145
                }
 
146
 
 
147
                protected override java.awt.peer.TextFieldPeer createTextField(java.awt.TextField target)
 
148
                {
 
149
                        return new NetTextFieldPeer(target, (TextBox)CreateControl(typeof(TextBox)));
 
150
                }
 
151
 
 
152
                protected override java.awt.peer.LabelPeer createLabel(java.awt.Label target)
 
153
                {
 
154
                        return new NetLabelPeer(target, (Label)CreateControl(typeof(Label)));
 
155
                }
 
156
 
 
157
                protected override java.awt.peer.ListPeer createList(java.awt.List target)
 
158
                {
 
159
                        return new NetListPeer(target, (ListBox)CreateControl(typeof(ListBox)));
 
160
                }
 
161
 
 
162
                protected override java.awt.peer.CheckboxPeer createCheckbox(java.awt.Checkbox target)
 
163
                {
 
164
                        throw new NotImplementedException();
 
165
                }
 
166
 
 
167
                protected override java.awt.peer.ScrollbarPeer createScrollbar(java.awt.Scrollbar target)
 
168
                {
 
169
                        throw new NotImplementedException();
 
170
                }
 
171
 
 
172
                protected override java.awt.peer.ScrollPanePeer createScrollPane(java.awt.ScrollPane target)
 
173
                {
 
174
                        throw new NotImplementedException();
 
175
                }
 
176
 
 
177
                protected override java.awt.peer.TextAreaPeer createTextArea(java.awt.TextArea target)
 
178
                {
 
179
                        return new NetTextAreaPeer(target, (TextBox)CreateControl(typeof(TextBox)));
 
180
                }
 
181
 
 
182
                protected override java.awt.peer.ChoicePeer createChoice(java.awt.Choice target)
 
183
                {
 
184
                        throw new NotImplementedException();
 
185
                }
 
186
 
 
187
                protected override java.awt.peer.FramePeer createFrame(java.awt.Frame target)
 
188
                {
 
189
                        return new NetFramePeer(target, (Form)CreateControl(typeof(Form)));
 
190
                }
 
191
 
 
192
                protected override java.awt.peer.CanvasPeer createCanvas(java.awt.Canvas target)
 
193
                {
 
194
                        return new NewCanvasPeer(target, (Control)CreateControl(typeof(Control)));
 
195
                }
 
196
 
 
197
                protected override java.awt.peer.PanelPeer createPanel(java.awt.Panel target)
 
198
                {
 
199
                        return new NetPanelPeer(target, (ContainerControl)CreateControl(typeof(ContainerControl)));
 
200
                }
 
201
 
 
202
                protected override java.awt.peer.WindowPeer createWindow(java.awt.Window target)
 
203
                {
 
204
                        return new NetWindowPeer(target, (Form)CreateControl(typeof(UndecoratedForm)));
 
205
                }
 
206
 
 
207
                protected override java.awt.peer.DialogPeer createDialog(java.awt.Dialog target)
 
208
                {
 
209
                        throw new NotImplementedException();
 
210
                }
 
211
                protected override java.awt.peer.MenuBarPeer createMenuBar(java.awt.MenuBar target)
 
212
                {
 
213
                        throw new NotImplementedException();
 
214
                }
 
215
                protected override java.awt.peer.MenuPeer createMenu(java.awt.Menu target)
 
216
                {
 
217
                        throw new NotImplementedException();
 
218
                }
 
219
                protected override java.awt.peer.PopupMenuPeer createPopupMenu(java.awt.PopupMenu target)
 
220
                {
 
221
                        throw new NotImplementedException();
 
222
                }
 
223
                protected override java.awt.peer.MenuItemPeer createMenuItem(java.awt.MenuItem target)
 
224
                {
 
225
                        throw new NotImplementedException();
 
226
                }
 
227
                protected override java.awt.peer.FileDialogPeer createFileDialog(java.awt.FileDialog target)
 
228
                {
 
229
                        throw new NotImplementedException();
 
230
                }
 
231
                protected override java.awt.peer.CheckboxMenuItemPeer createCheckboxMenuItem(java.awt.CheckboxMenuItem target)
 
232
                {
 
233
                        throw new NotImplementedException();
 
234
                }
 
235
                protected override java.awt.peer.FontPeer getFontPeer(string name, int style)
 
236
                {
 
237
                        throw new NotImplementedException();
 
238
                }
 
239
 
 
240
                public override java.awt.Dimension getScreenSize()
 
241
                {
 
242
                        return new java.awt.Dimension(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
 
243
                }
 
244
 
 
245
                public override int getScreenResolution()
 
246
                {
 
247
                        if(resolution == 0)
 
248
                        {
 
249
                                using(Graphics g = bogusForm.CreateGraphics())
 
250
                                {
 
251
                                        resolution = (int)Math.Round(g.DpiY);
 
252
                                }
 
253
                        }
 
254
                        return resolution;
 
255
                }
 
256
 
 
257
                public override ColorModel getColorModel()
 
258
                {
 
259
                        throw new NotImplementedException();
 
260
                }
 
261
 
 
262
                public override string[] getFontList()
 
263
                {
 
264
                        throw new NotImplementedException();
 
265
                }
 
266
 
 
267
                public override java.awt.FontMetrics getFontMetrics(java.awt.Font font)
 
268
                {
 
269
                        return new NetFontMetrics(font, NetGraphics.NetFontFromJavaFont(font, getScreenResolution()), null, null);
 
270
                }
 
271
 
 
272
                public override void sync()
 
273
                {
 
274
                        throw new NotImplementedException();
 
275
                }
 
276
 
 
277
                public override java.awt.Image getImage(string filename)
 
278
                {
 
279
                        try
 
280
                        {
 
281
                                using(System.IO.FileStream stream = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite))
 
282
                                {
 
283
                                        return new NetBufferedImage(new Bitmap(Image.FromStream(stream)));
 
284
                                }
 
285
                        }
 
286
                        catch(Exception)
 
287
                        {
 
288
                                return new NoImage();
 
289
                        }
 
290
                }
 
291
 
 
292
                public override java.awt.Image getImage(URL url)
 
293
                {
 
294
                        throw new NotImplementedException();
 
295
                }
 
296
 
 
297
                public override java.awt.Image createImage(string filename)
 
298
                {
 
299
                        throw new NotImplementedException();
 
300
                }
 
301
                public override java.awt.Image createImage(URL url)
 
302
                {
 
303
                        throw new NotImplementedException();
 
304
                }
 
305
 
 
306
                public override bool prepareImage(java.awt.Image image, int width, int height, java.awt.image.ImageObserver observer)
 
307
                {
 
308
                        // HACK for now we call checkImage to obtain the status and fire the observer
 
309
                        return (checkImage(image, width, height, observer) & 32) != 0;
 
310
                }
 
311
 
 
312
                public override int checkImage(java.awt.Image image, int width, int height, java.awt.image.ImageObserver observer)
 
313
                {
 
314
                        if(image.getWidth(null) == -1)
 
315
                        {
 
316
                                if(observer != null)
 
317
                                {
 
318
                                        observer.imageUpdate(image, 64, 0, 0, -1, -1);
 
319
                                }
 
320
                                return 64; // ERROR
 
321
                        }
 
322
                        if(observer != null)
 
323
                        {
 
324
                                observer.imageUpdate(image, 1 + 2 + 16 + 32, 0, 0, image.getWidth(null), image.getHeight(null));
 
325
                        }
 
326
                        // HACK we cannot use the constants defined in the interface from C#, so we hardcode the flags
 
327
                        return 1 + 2 + 16 + 32; // WIDTH + HEIGHT + FRAMEBITS + ALLBITS
 
328
                }
 
329
 
 
330
                public override java.awt.Image createImage(java.awt.image.ImageProducer producer)
 
331
                {
 
332
                        throw new NotImplementedException();
 
333
                }
 
334
 
 
335
                public override java.awt.Image createImage(sbyte[] imagedata, int imageoffset, int imagelength)
 
336
                {
 
337
                        throw new NotImplementedException();
 
338
                }
 
339
 
 
340
                public override java.awt.PrintJob getPrintJob(java.awt.Frame frame, string jobtitle, Properties props)
 
341
                {
 
342
                        throw new NotImplementedException();
 
343
                }
 
344
 
 
345
                public override void beep()
 
346
                {
 
347
                        throw new NotImplementedException();
 
348
                }
 
349
 
 
350
                public override java.awt.datatransfer.Clipboard getSystemClipboard()
 
351
                {
 
352
                        throw new NotImplementedException();
 
353
                }
 
354
 
 
355
                protected override java.awt.EventQueue getSystemEventQueueImpl()
 
356
                {
 
357
                        return eventQueue;
 
358
                }
 
359
 
 
360
                public override java.awt.dnd.peer.DragSourceContextPeer createDragSourceContextPeer(java.awt.dnd.DragGestureEvent dge)
 
361
                {
 
362
                        throw new NotImplementedException();
 
363
                }
 
364
 
 
365
                public override Map mapInputMethodHighlight(java.awt.im.InputMethodHighlight highlight)
 
366
                {
 
367
                        throw new NotImplementedException();
 
368
                }
 
369
 
 
370
                protected override java.awt.peer.LightweightPeer createComponent(java.awt.Component target)
 
371
                {
 
372
                        if(target is java.awt.Container)
 
373
                        {
 
374
                                return new NetLightweightContainerPeer((java.awt.Container)target);
 
375
                        }
 
376
                        return new NetLightweightComponentPeer(target);
 
377
                }
 
378
 
 
379
                public override java.awt.Font createFont(int format, java.io.InputStream stream)
 
380
                {
 
381
                        throw new NotImplementedException();
 
382
                }
 
383
 
 
384
                public override gnu.java.awt.peer.ClasspathFontPeer getClasspathFontPeer(string name, java.util.Map attrs)
 
385
                {
 
386
                        return new NetFontPeer(name, attrs);
 
387
                }
 
388
 
 
389
                public override java.awt.GraphicsEnvironment getLocalGraphicsEnvironment()
 
390
                {
 
391
                        throw new NotImplementedException();
 
392
                }
 
393
        }
 
394
 
 
395
        class NetFontPeer : gnu.java.awt.peer.ClasspathFontPeer
 
396
        {
 
397
                internal NetFontPeer(string name, java.util.Map attrs)
 
398
                        : base(name, attrs)
 
399
                {
 
400
                }
 
401
 
 
402
                public override bool canDisplay(java.awt.Font param1, char param2)
 
403
                {
 
404
                        throw new NotImplementedException();
 
405
                }
 
406
 
 
407
                public override int canDisplayUpTo(java.awt.Font param1, java.text.CharacterIterator param2, int param3, int param4)
 
408
                {
 
409
                        throw new NotImplementedException();
 
410
                }
 
411
 
 
412
                public override java.awt.font.GlyphVector createGlyphVector(java.awt.Font param1, java.awt.font.FontRenderContext param2, int[] param3)
 
413
                {
 
414
                        throw new NotImplementedException();
 
415
                }
 
416
 
 
417
                public override java.awt.font.GlyphVector createGlyphVector(java.awt.Font param1, java.awt.font.FontRenderContext param2, java.text.CharacterIterator param3)
 
418
                {
 
419
                        throw new NotImplementedException();
 
420
                }
 
421
 
 
422
                public override sbyte getBaselineFor(java.awt.Font param1, char param2)
 
423
                {
 
424
                        throw new NotImplementedException();
 
425
                }
 
426
 
 
427
                public override java.awt.FontMetrics getFontMetrics(java.awt.Font param)
 
428
                {
 
429
                        throw new NotImplementedException();
 
430
                }
 
431
 
 
432
                public override string getGlyphName(java.awt.Font param1, int param2)
 
433
                {
 
434
                        throw new NotImplementedException();
 
435
                }
 
436
 
 
437
                public override java.awt.font.LineMetrics getLineMetrics(java.awt.Font param1, java.text.CharacterIterator param2, int param3, int param4, java.awt.font.FontRenderContext param5)
 
438
                {
 
439
                        throw new NotImplementedException();
 
440
                }
 
441
 
 
442
                public override java.awt.geom.Rectangle2D getMaxCharBounds(java.awt.Font param1, java.awt.font.FontRenderContext param2)
 
443
                {
 
444
                        throw new NotImplementedException();
 
445
                }
 
446
 
 
447
                public override int getMissingGlyphCode(java.awt.Font param)
 
448
                {
 
449
                        throw new NotImplementedException();
 
450
                }
 
451
 
 
452
                public override int getNumGlyphs(java.awt.Font param)
 
453
                {
 
454
                        throw new NotImplementedException();
 
455
                }
 
456
 
 
457
                public override string getPostScriptName(java.awt.Font param)
 
458
                {
 
459
                        throw new NotImplementedException();
 
460
                }
 
461
 
 
462
                public override java.awt.geom.Rectangle2D getStringBounds(java.awt.Font param1, java.text.CharacterIterator param2, int param3, int param4, java.awt.font.FontRenderContext param5)
 
463
                {
 
464
                        throw new NotImplementedException();
 
465
                }
 
466
 
 
467
                public override bool hasUniformLineMetrics(java.awt.Font param)
 
468
                {
 
469
                        throw new NotImplementedException();
 
470
                }
 
471
 
 
472
                public override java.awt.font.GlyphVector layoutGlyphVector(java.awt.Font param1, java.awt.font.FontRenderContext param2, char[] param3, int param4, int param5, int param6)
 
473
                {
 
474
                        throw new NotImplementedException();
 
475
                }
 
476
 
 
477
                public override string getSubFamilyName(java.awt.Font param1, Locale param2)
 
478
                {
 
479
                        throw new NotImplementedException();
 
480
                }
 
481
        }
 
482
 
 
483
        class NetLightweightComponentPeer : NetComponentPeer, java.awt.peer.LightweightPeer
 
484
        {
 
485
                public NetLightweightComponentPeer(java.awt.Component target)
 
486
                        : base(target, ((NetComponentPeer)target.getParent().getPeer()).control)
 
487
                {
 
488
                }
 
489
        }
 
490
 
 
491
        class NetLightweightContainerPeer : NetContainerPeer, java.awt.peer.LightweightPeer
 
492
        {
 
493
                public NetLightweightContainerPeer(java.awt.Container target)
 
494
                        : base(target, (ContainerControl)((NetContainerPeer)target.getParent().getPeer()).control)
 
495
                {
 
496
                }
 
497
        }
 
498
 
 
499
        class NoImage : java.awt.Image
 
500
        {
 
501
                public override int getWidth(java.awt.image.ImageObserver observer)
 
502
                {
 
503
                        return -1;
 
504
                }
 
505
 
 
506
                public override int getHeight(java.awt.image.ImageObserver observer)
 
507
                {
 
508
                        return -1;
 
509
                }
 
510
 
 
511
                public override ImageProducer getSource()
 
512
                {
 
513
                        return null;
 
514
                }
 
515
 
 
516
                public override java.awt.Graphics getGraphics()
 
517
                {
 
518
                        // TODO throw java.lang.IllegalAccessError: getGraphics() only valid for images created with createImage(w, h)
 
519
                        return null;
 
520
                }
 
521
 
 
522
                public override object getProperty(string name, java.awt.image.ImageObserver observer)
 
523
                {
 
524
                        return null;
 
525
                }
 
526
 
 
527
                public override void flush()
 
528
                {
 
529
                }
 
530
        }
 
531
 
 
532
        class NetGraphics : java.awt.Graphics2D
 
533
        {
 
534
                private bool disposable;
 
535
                private Graphics g;
 
536
                private java.awt.Color jcolor;
 
537
                private Color color = SystemColors.WindowText;
 
538
                private Color bgcolor;
 
539
                private java.awt.Font font;
 
540
                private Font netfont;
 
541
                private java.awt.Rectangle _clip;
 
542
 
 
543
                public NetGraphics(Graphics g, java.awt.Font font, Color bgcolor, bool disposable)
 
544
                {
 
545
                        if(font == null)
 
546
                        {
 
547
                                font = new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12);
 
548
                        }
 
549
                        this.g = g;
 
550
                        this.font = font;
 
551
                        netfont = NetFontFromJavaFont(font, g.DpiY);
 
552
                        this.bgcolor = bgcolor;
 
553
                        this.disposable = disposable;
 
554
                        if(!g.IsClipEmpty)
 
555
                        {
 
556
                                _clip = new java.awt.Rectangle((int)Math.Round(g.ClipBounds.Left), (int)Math.Round(g.ClipBounds.Top), (int)Math.Round(g.ClipBounds.Width), (int)Math.Round(g.ClipBounds.Height));
 
557
                        }
 
558
                }
 
559
 
 
560
                public override void clearRect(int x, int y, int width, int height)
 
561
                {
 
562
                        using(SolidBrush b = new SolidBrush(bgcolor))
 
563
                        {
 
564
                                g.FillRectangle(b, x, y, width, height);
 
565
                        }
 
566
                }
 
567
 
 
568
                public override void clipRect(int param1, int param2, int param3, int param4)
 
569
                {
 
570
                
 
571
                }
 
572
 
 
573
                public override void copyArea(int param1, int param2, int param3, int param4, int param5, int param6)
 
574
                {
 
575
                
 
576
                }
 
577
 
 
578
                public override java.awt.Graphics create(int param1, int param2, int param3, int param4)
 
579
                {
 
580
                        return null;
 
581
                }
 
582
 
 
583
                public override java.awt.Graphics create()
 
584
                {
 
585
                        // TODO we need to actually recreate a new underlying Graphics object, but .NET doesn't
 
586
                        // seem to have a way of doing that, so we probably need access to the underlying surface.
 
587
                        // Sigh...
 
588
                        NetGraphics newg = new NetGraphics(g, font, bgcolor, false);
 
589
                        // TODO copy other attributes
 
590
                        return newg;
 
591
                }
 
592
 
 
593
                public override void dispose()
 
594
                {
 
595
                        if(disposable)
 
596
                        {
 
597
                                disposable = false;
 
598
                                g.Dispose();
 
599
                        }
 
600
                        netfont.Dispose();
 
601
                }
 
602
 
 
603
                public override void draw3DRect(int param1, int param2, int param3, int param4, bool param5)
 
604
                {
 
605
                
 
606
                }
 
607
 
 
608
                public override void drawArc(int param1, int param2, int param3, int param4, int param5, int param6)
 
609
                {
 
610
                
 
611
                }
 
612
 
 
613
                public override void drawBytes(sbyte[] param1, int param2, int param3, int param4, int param5)
 
614
                {
 
615
                
 
616
                }
 
617
 
 
618
                public override void drawChars(char[] param1, int param2, int param3, int param4, int param5)
 
619
                {
 
620
                
 
621
                }
 
622
 
 
623
                public override bool drawImage(java.awt.Image param1, int param2, int param3, int param4, int param5, int param6, int param7, int param8, int param9, java.awt.Color param10, java.awt.image.ImageObserver param11)
 
624
                {
 
625
                        return true;
 
626
                }
 
627
 
 
628
                public override bool drawImage(java.awt.Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, java.awt.image.ImageObserver observer)
 
629
                {
 
630
                        if(img is NetBufferedImage)
 
631
                        {
 
632
                                Rectangle destRect = new Rectangle(dx1, dy1, dx2 - dx1, dy2 - dy1);
 
633
                                Rectangle srcRect = new Rectangle(sx1, sy1, sx2 - sx1, sy2 - sy1);
 
634
                                g.DrawImage(((NetBufferedImage)img).bitmap, destRect, srcRect, GraphicsUnit.Pixel);
 
635
                        }
 
636
                        else
 
637
                        {
 
638
                                throw new NotImplementedException();
 
639
                        }
 
640
                        return true;
 
641
                }
 
642
 
 
643
                public override bool drawImage(java.awt.Image param1, int param2, int param3, int param4, int param5, java.awt.Color param6, java.awt.image.ImageObserver param7)
 
644
                {
 
645
                        return true;
 
646
                }
 
647
 
 
648
                public override bool drawImage(java.awt.Image param1, int param2, int param3, java.awt.Color param4, java.awt.image.ImageObserver param5)
 
649
                {
 
650
                        return true;
 
651
                }
 
652
 
 
653
                public override bool drawImage(java.awt.Image param1, int param2, int param3, int param4, int param5, java.awt.image.ImageObserver param6)
 
654
                {
 
655
                        return true;
 
656
                }
 
657
 
 
658
                public override bool drawImage(java.awt.Image img, int x, int y, java.awt.image.ImageObserver observer)
 
659
                {
 
660
                        if(img is NetBufferedImage)
 
661
                        {
 
662
                                g.DrawImage(((NetBufferedImage)img).bitmap, x, y);
 
663
                        }
 
664
                        else
 
665
                        {
 
666
                                throw new NotImplementedException();
 
667
                        }
 
668
                        return true;
 
669
                }
 
670
 
 
671
                public override void drawLine(int x1, int y1, int x2, int y2)
 
672
                {
 
673
                        using(Pen p = new Pen(color, 1))
 
674
                        {
 
675
                                // HACK DrawLine doesn't appear to draw the last pixel, so for single pixel lines, we have
 
676
                                // a freaky workaround
 
677
                                if(x1 == x2 && y1 == y2)
 
678
                                {
 
679
                                        g.DrawLine(p, x1, y1, x1 + 0.01f, y2 + 0.01f);
 
680
                                }
 
681
                                else
 
682
                                {
 
683
                                        g.DrawLine(p, x1, y1, x2, y2);
 
684
                                }
 
685
                        }
 
686
                }
 
687
 
 
688
                public override void drawOval(int param1, int param2, int param3, int param4)
 
689
                {
 
690
                
 
691
                }
 
692
 
 
693
                public override void drawPolygon(java.awt.Polygon param)
 
694
                {
 
695
                
 
696
                }
 
697
 
 
698
                public override void drawPolygon(int[] param1, int[] param2, int param3)
 
699
                {
 
700
                
 
701
                }
 
702
 
 
703
                public override void drawPolyline(int[] param1, int[] param2, int param3)
 
704
                {
 
705
                
 
706
                }
 
707
 
 
708
                public override void drawRect(int x, int y, int width, int height)
 
709
                {
 
710
                        using(Pen pen = new Pen(color))
 
711
                        {
 
712
                                g.DrawRectangle(pen, x, y, width, height);
 
713
                        }               
 
714
                }
 
715
 
 
716
                public override void drawRoundRect(int param1, int param2, int param3, int param4, int param5, int param6)
 
717
                {
 
718
                
 
719
                }
 
720
 
 
721
                public override void drawString(java.text.AttributedCharacterIterator param1, int param2, int param3)
 
722
                {
 
723
                
 
724
                }
 
725
 
 
726
                public override void drawString(string str, int x, int y)
 
727
                {
 
728
                        using(Brush brush = new SolidBrush(color))
 
729
                        {
 
730
                                int descent = netfont.FontFamily.GetCellDescent(netfont.Style);
 
731
                                int descentPixel = (int)Math.Round(netfont.Size * descent / netfont.FontFamily.GetEmHeight(netfont.Style));
 
732
                                g.DrawString(str, netfont, brush, x, y - netfont.Height + descentPixel);
 
733
                        }
 
734
                }
 
735
 
 
736
                public override void fill3DRect(int param1, int param2, int param3, int param4, bool param5)
 
737
                {
 
738
                
 
739
                }
 
740
 
 
741
                public override void fillArc(int param1, int param2, int param3, int param4, int param5, int param6)
 
742
                {
 
743
                
 
744
                }
 
745
 
 
746
                public override void fillOval(int param1, int param2, int param3, int param4)
 
747
                {
 
748
                
 
749
                }
 
750
 
 
751
                public override void fillPolygon(java.awt.Polygon param)
 
752
                {
 
753
                
 
754
                }
 
755
 
 
756
                public override void fillPolygon(int[] param1, int[] param2, int param3)
 
757
                {
 
758
                
 
759
                }
 
760
 
 
761
                public override void fillRect(int x, int y, int width, int height)
 
762
                {
 
763
                        using(Brush brush = new SolidBrush(color))
 
764
                        {
 
765
                                g.FillRectangle(brush, x, y, width, height);
 
766
                        }
 
767
                }
 
768
 
 
769
                public override void fillRoundRect(int param1, int param2, int param3, int param4, int param5, int param6)
 
770
                {
 
771
                
 
772
                }
 
773
 
 
774
                public override java.awt.Shape getClip()
 
775
                {
 
776
                        return getClipBounds();
 
777
                }
 
778
 
 
779
                public override java.awt.Rectangle getClipBounds(java.awt.Rectangle r)
 
780
                {
 
781
                        if(_clip != null)
 
782
                        {
 
783
                                r.x = _clip.x;
 
784
                                r.y = _clip.y;
 
785
                                r.width = _clip.width;
 
786
                                r.height = _clip.height;
 
787
                        }
 
788
                        return r;
 
789
                }
 
790
 
 
791
                public override java.awt.Rectangle getClipBounds()
 
792
                {
 
793
                        return getClipRect();
 
794
                }
 
795
 
 
796
                public override java.awt.Rectangle getClipRect()
 
797
                {
 
798
                        if(_clip != null)
 
799
                        {
 
800
                                return (java.awt.Rectangle)_clip.clone();
 
801
                        }
 
802
                        return null;
 
803
                }
 
804
 
 
805
                public override java.awt.Color getColor()
 
806
                {
 
807
                        if(jcolor == null)
 
808
                        {
 
809
                                jcolor = new java.awt.Color(color.ToArgb());
 
810
                        }
 
811
                        return jcolor;
 
812
                }
 
813
 
 
814
                public override java.awt.Font getFont()
 
815
                {
 
816
                        return font;
 
817
                }
 
818
 
 
819
                internal static Font NetFontFromJavaFont(java.awt.Font f, float dpi)
 
820
                {
 
821
                        FontFamily fam;
 
822
                        switch(f.getName())
 
823
                        {
 
824
                                case "Monospaced":
 
825
                                case "Courier":
 
826
                                case "courier":
 
827
                                        fam = FontFamily.GenericMonospace;
 
828
                                        break;
 
829
                                case "Serif":
 
830
                                        fam = FontFamily.GenericSerif;
 
831
                                        break;
 
832
                                case "SansSerif":
 
833
                                case "Dialog":
 
834
                                case "DialogInput":
 
835
                                case null:
 
836
                                case "Default":
 
837
                                        fam = FontFamily.GenericSansSerif;
 
838
                                        break;
 
839
                                default:
 
840
                                        try
 
841
                                        {
 
842
                                                fam = new FontFamily(f.getName());
 
843
                                        }
 
844
                                        catch(ArgumentException)
 
845
                                        {
 
846
                                                fam = FontFamily.GenericSansSerif;
 
847
                                        }
 
848
                                        break;
 
849
                        }
 
850
                        // NOTE Regular is guaranteed zero
 
851
                        FontStyle style = FontStyle.Regular;
 
852
                        if(f.isBold())
 
853
                        {
 
854
                                style |= FontStyle.Bold;
 
855
                        }
 
856
                        if(f.isItalic())
 
857
                        {
 
858
                                style |= FontStyle.Italic;
 
859
                        }
 
860
                        float em = fam.GetEmHeight(style);
 
861
                        float line = fam.GetLineSpacing(style);
 
862
                        return new Font(fam, (int)Math.Round(((f.getSize() * dpi) / 72) * em / line), style, GraphicsUnit.Pixel);
 
863
                }
 
864
 
 
865
                public override java.awt.FontMetrics getFontMetrics(java.awt.Font f)
 
866
                {
 
867
                        return new NetFontMetrics(f, NetFontFromJavaFont(f, g.DpiY), g, null);
 
868
                }
 
869
 
 
870
                public override java.awt.FontMetrics getFontMetrics()
 
871
                {
 
872
                        return new NetFontMetrics(font, netfont, g, null);
 
873
                }
 
874
 
 
875
                public override bool hitClip(int param1, int param2, int param3, int param4)
 
876
                {
 
877
                        return true;
 
878
                }
 
879
 
 
880
                public override void setClip(int x, int y, int width, int height)
 
881
                {
 
882
                        _clip = new java.awt.Rectangle(x, y, width, height);
 
883
                        g.Clip = new Region(new Rectangle(x, y, width, height));
 
884
                }
 
885
 
 
886
                public override void setClip(java.awt.Shape param)
 
887
                {
 
888
                        // NOTE we only support rectangular clipping for the moment
 
889
                        java.awt.Rectangle r = param.getBounds();                       
 
890
                        setClip(r.x, r.y, r.width, r.height);
 
891
                }
 
892
 
 
893
                public override void setColor(java.awt.Color color)
 
894
                {
 
895
                        this.jcolor = color;
 
896
                        this.color = Color.FromArgb(color.getRGB());
 
897
                }
 
898
 
 
899
                public override void setFont(java.awt.Font f)
 
900
                {
 
901
                        Font newfont = NetFontFromJavaFont(f, g.DpiY);
 
902
                        netfont.Dispose();
 
903
                        netfont = newfont;
 
904
                        font = f;
 
905
                }
 
906
 
 
907
                public override void setPaintMode()
 
908
                {
 
909
                
 
910
                }
 
911
 
 
912
                public override void setXORMode(java.awt.Color param)
 
913
                {
 
914
                
 
915
                }
 
916
 
 
917
                public override void translate(int x, int y)
 
918
                {
 
919
                        System.Drawing.Drawing2D.Matrix matrix = g.Transform;
 
920
                        matrix.Translate(x, y);
 
921
                        g.Transform = matrix;
 
922
                }
 
923
 
 
924
                public override void draw(java.awt.Shape shape)
 
925
                {
 
926
                }
 
927
 
 
928
                public override bool drawImage(java.awt.Image image, java.awt.geom.AffineTransform xform, ImageObserver obs)
 
929
                {
 
930
                        return false;
 
931
                }
 
932
 
 
933
                public override void drawImage(java.awt.image.BufferedImage image, BufferedImageOp op, int x, int y)
 
934
                {
 
935
                }
 
936
 
 
937
                public override void drawRenderedImage(java.awt.image.RenderedImage image, java.awt.geom.AffineTransform xform)
 
938
                {
 
939
                }
 
940
 
 
941
                public override void drawRenderableImage(java.awt.image.renderable.RenderableImage image, java.awt.geom.AffineTransform xform)
 
942
                {
 
943
                }
 
944
 
 
945
                public override void drawString(string text, float x, float y)
 
946
                {
 
947
                }
 
948
    
 
949
                public override void drawString(java.text.AttributedCharacterIterator iterator, float x, float y)
 
950
                {
 
951
                }
 
952
 
 
953
                public override void fill(java.awt.Shape shape)
 
954
                {
 
955
                }
 
956
    
 
957
                public override bool hit(java.awt.Rectangle rect, java.awt.Shape text, bool onStroke)
 
958
                {
 
959
                        return false;
 
960
                }
 
961
 
 
962
                public override java.awt.GraphicsConfiguration getDeviceConfiguration()
 
963
                {
 
964
                        return null;
 
965
                }
 
966
 
 
967
                public override void setComposite(java.awt.Composite comp)
 
968
                {
 
969
                }
 
970
    
 
971
                public override void setPaint(java.awt.Paint paint)
 
972
                {
 
973
                }
 
974
 
 
975
                public override void setStroke(java.awt.Stroke stroke)
 
976
                {
 
977
                }
 
978
 
 
979
                public override void setRenderingHint(java.awt.RenderingHints.Key hintKey, Object hintValue)
 
980
                {
 
981
                }
 
982
 
 
983
                public override object getRenderingHint(java.awt.RenderingHints.Key hintKey)
 
984
                {
 
985
                        return null;
 
986
                }
 
987
  
 
988
                public override void setRenderingHints(java.util.Map hints)
 
989
                {
 
990
                }
 
991
 
 
992
                public override void addRenderingHints(java.util.Map hints)
 
993
                {
 
994
                }
 
995
 
 
996
                public override java.awt.RenderingHints getRenderingHints()
 
997
                {
 
998
                        return null;
 
999
                }
 
1000
 
 
1001
                public override void translate(double tx, double ty)
 
1002
                {
 
1003
                }
 
1004
    
 
1005
                public override void rotate(double theta)
 
1006
                {
 
1007
                }
 
1008
 
 
1009
                public override void rotate(double theta, double x, double y)
 
1010
                {
 
1011
                }
 
1012
 
 
1013
                public override void scale(double scaleX, double scaleY)
 
1014
                {
 
1015
                }
 
1016
 
 
1017
                public override void shear(double shearX, double shearY)
 
1018
                {
 
1019
                }
 
1020
 
 
1021
                public override void transform(java.awt.geom.AffineTransform Tx)
 
1022
                {
 
1023
                }
 
1024
  
 
1025
                public override void setTransform(java.awt.geom.AffineTransform Tx)
 
1026
                {
 
1027
                }
 
1028
 
 
1029
                public override java.awt.geom.AffineTransform getTransform()
 
1030
                {
 
1031
                        return null;
 
1032
                }
 
1033
 
 
1034
                public override java.awt.Paint getPaint()
 
1035
                {
 
1036
                        return null;
 
1037
                }
 
1038
 
 
1039
                public override java.awt.Composite getComposite()
 
1040
                {
 
1041
                        return null;
 
1042
                }
 
1043
 
 
1044
                public override void setBackground(java.awt.Color color)
 
1045
                {
 
1046
                }
 
1047
 
 
1048
                public override java.awt.Color getBackground()
 
1049
                {
 
1050
                        return null;
 
1051
                }
 
1052
 
 
1053
                public override java.awt.Stroke getStroke()
 
1054
                {
 
1055
                        return null;
 
1056
                }
 
1057
 
 
1058
                public override void clip(java.awt.Shape s)
 
1059
                {
 
1060
                }
 
1061
 
 
1062
                public override java.awt.font.FontRenderContext getFontRenderContext()
 
1063
                {
 
1064
                        return null;
 
1065
                }
 
1066
 
 
1067
                public override void drawGlyphVector(java.awt.font.GlyphVector g, float x, float y)
 
1068
                {
 
1069
                }
 
1070
        }
 
1071
 
 
1072
        class NetFontMetrics : java.awt.FontMetrics
 
1073
        {
 
1074
                private Font netFont;
 
1075
                private Graphics g;
 
1076
                private Control c;
 
1077
 
 
1078
                public NetFontMetrics(java.awt.Font f, Font netFont, Graphics g, Control c) : base(f)
 
1079
                {
 
1080
                        this.netFont = netFont;
 
1081
                        this.g = g;
 
1082
                        this.c = c;
 
1083
                }
 
1084
 
 
1085
                public override int getHeight()
 
1086
                {
 
1087
                        return netFont.Height;
 
1088
                }
 
1089
 
 
1090
                public override int getLeading()
 
1091
                {
 
1092
                        // HACK we always return 1
 
1093
                        return 1;
 
1094
                }
 
1095
 
 
1096
                public override int getMaxAdvance()
 
1097
                {
 
1098
                        // HACK very lame
 
1099
                        return charWidth('M');
 
1100
                }
 
1101
 
 
1102
                public override int charWidth(char ch)
 
1103
                {
 
1104
                        // HACK we average 20 characters to decrease the influence of the pre/post spacing
 
1105
                        return stringWidth(new String(ch, 20)) / 20;
 
1106
                }
 
1107
 
 
1108
                public override int charsWidth(char[] data, int off, int len)
 
1109
                {
 
1110
                        return stringWidth(new String(data, off, len));
 
1111
                }
 
1112
 
 
1113
                public override int getAscent()
 
1114
                {
 
1115
                        int ascent = netFont.FontFamily.GetCellAscent(netFont.Style);
 
1116
                        return (int)Math.Round(netFont.Size * ascent / netFont.FontFamily.GetEmHeight(netFont.Style));
 
1117
                }
 
1118
 
 
1119
                public override int getDescent()
 
1120
                {
 
1121
                        int descent = netFont.FontFamily.GetCellDescent(netFont.Style);
 
1122
                        return (int)Math.Round(netFont.Size * descent / netFont.FontFamily.GetEmHeight(netFont.Style));
 
1123
                }
 
1124
 
 
1125
                public override int stringWidth(string s)
 
1126
                {
 
1127
                        if(g != null)
 
1128
                        {
 
1129
                                try
 
1130
                                {
 
1131
                                        return (int)Math.Round(g.MeasureString(s, netFont).Width);
 
1132
                                }
 
1133
                                catch(ObjectDisposedException)
 
1134
                                {
 
1135
                                        g = null;
 
1136
                                }
 
1137
                        }
 
1138
                        if(c != null)
 
1139
                        {
 
1140
                                using(Graphics g1 = c.CreateGraphics())
 
1141
                                {
 
1142
                                        return (int)Math.Round(g1.MeasureString(s, netFont).Width);
 
1143
                                }
 
1144
                        }
 
1145
                        // as a last resort, we make a lame guess
 
1146
                        return s.Length * getHeight() / 2;
 
1147
                }
 
1148
        }
 
1149
 
 
1150
        class NetComponentPeer : ComponentPeer
 
1151
        {
 
1152
                internal readonly java.awt.Component component;
 
1153
                internal readonly Control control;
 
1154
                private int offsetX;
 
1155
                private int offsetY;
 
1156
 
 
1157
                public NetComponentPeer(java.awt.Component component, Control control)
 
1158
                {
 
1159
                        this.control = control;
 
1160
                        this.component = component;
 
1161
                        java.awt.Container parent = component.getParent();
 
1162
                        if(parent != null && !(this is java.awt.peer.LightweightPeer))
 
1163
                        {
 
1164
                                if(control is Form)
 
1165
                                {
 
1166
                                        ((Form)control).Owner = (Form)((NetComponentPeer)parent.getPeer()).control;
 
1167
                                }
 
1168
                                else
 
1169
                                {
 
1170
                                        control.Parent = ((NetComponentPeer)parent.getPeer()).control;
 
1171
                                }
 
1172
                                if(parent is java.awt.Frame)
 
1173
                                {
 
1174
                                        java.awt.Insets ins = ((NetFramePeer)parent.getPeer()).getInsets();
 
1175
                                        offsetX = -ins.left;
 
1176
                                        offsetY = -ins.top;
 
1177
                                }
 
1178
                        }
 
1179
                        if(component.isFontSet())
 
1180
                        {
 
1181
                                setFont(component.getFont());
 
1182
                        }
 
1183
                        // we need the null check, because for a Window, at this time it doesn't have a foreground yet
 
1184
                        if(component.getForeground() != null)
 
1185
                        {
 
1186
                                setForeground(component.getForeground());
 
1187
                        }
 
1188
                        // we need the null check, because for a Window, at this time it doesn't have a background yet
 
1189
                        if(component.getBackground() != null)
 
1190
                        {
 
1191
                                setBackground(component.getBackground());
 
1192
                        }
 
1193
                        setEnabled(component.isEnabled());
 
1194
                        //setBounds(component.getX(), component.getY(), component.getWidth(), component.getHeight());
 
1195
                        control.Invoke(new SetVoid(Setup));
 
1196
                        control.Paint += new PaintEventHandler(OnPaint);
 
1197
                        component.invalidate();
 
1198
                }
 
1199
 
 
1200
                private void OnPaint(object sender, PaintEventArgs e)
 
1201
                {
 
1202
                        // TODO figure out if we need an update or a paint
 
1203
                        java.awt.Rectangle rect = new java.awt.Rectangle(e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width, e.ClipRectangle.Height);
 
1204
                        //postEvent(new java.awt.@event.PaintEvent(component, java.awt.@event.PaintEvent.UPDATE, rect));
 
1205
                        postEvent(new java.awt.@event.PaintEvent(component, java.awt.@event.PaintEvent.PAINT, rect));
 
1206
                }
 
1207
 
 
1208
                private void Setup()
 
1209
                {
 
1210
                        // TODO we really only should hook these events when they are needed...
 
1211
                        control.KeyDown += new KeyEventHandler(OnKeyDown);
 
1212
                        control.KeyUp += new KeyEventHandler(OnKeyUp);
 
1213
                        control.KeyPress += new KeyPressEventHandler(OnKeyPress);
 
1214
                        control.MouseMove += new MouseEventHandler(OnMouseMove);
 
1215
                        control.MouseDown += new MouseEventHandler(OnMouseDown);
 
1216
                        control.MouseUp += new MouseEventHandler(OnMouseUp);
 
1217
                }
 
1218
 
 
1219
                private static int MapKeyCode(Keys key)
 
1220
                {
 
1221
                        switch(key)
 
1222
                        {
 
1223
                                default:
 
1224
                                        return (int)key;
 
1225
                        }
 
1226
                }
 
1227
 
 
1228
                protected virtual void OnKeyDown(object sender, KeyEventArgs e)
 
1229
                {
 
1230
                        // TODO set all this stuff...
 
1231
                        long when = 0;
 
1232
                        int modifiers = 0;
 
1233
                        int keyCode = MapKeyCode(e.KeyCode);
 
1234
                        char keyChar = ' ';
 
1235
                        int keyLocation = 0;
 
1236
                        postEvent(new java.awt.@event.KeyEvent(component, java.awt.@event.KeyEvent.KEY_PRESSED, when, modifiers, keyCode, keyChar, keyLocation));
 
1237
                }
 
1238
 
 
1239
                protected virtual void OnKeyUp(object sender, KeyEventArgs e)
 
1240
                {
 
1241
                        // TODO set all this stuff...
 
1242
                        long when = 0;
 
1243
                        int modifiers = 0;
 
1244
                        int keyCode = MapKeyCode(e.KeyCode);
 
1245
                        char keyChar = ' ';
 
1246
                        int keyLocation = 0;
 
1247
                        postEvent(new java.awt.@event.KeyEvent(component, java.awt.@event.KeyEvent.KEY_RELEASED, when, modifiers, keyCode, keyChar, keyLocation));
 
1248
                }
 
1249
 
 
1250
                protected virtual void OnKeyPress(object sender, KeyPressEventArgs e)
 
1251
                {
 
1252
                        // TODO set all this stuff...
 
1253
                        long when = 0;
 
1254
                        int modifiers = 0;
 
1255
                        int keyCode = 0;
 
1256
                        char keyChar = e.KeyChar;
 
1257
                        int keyLocation = 0;
 
1258
                        postEvent(new java.awt.@event.KeyEvent(component, java.awt.@event.KeyEvent.KEY_TYPED, when, modifiers, keyCode, keyChar, keyLocation));
 
1259
                }
 
1260
 
 
1261
                protected virtual void OnMouseMove(object sender, MouseEventArgs e)
 
1262
                {
 
1263
                        // TODO set all this stuff...
 
1264
                        long when = 0;
 
1265
                        int modifiers = 0;
 
1266
                        postEvent(new java.awt.@event.MouseEvent(component, java.awt.@event.MouseEvent.MOUSE_MOVED, when, modifiers, e.X, e.Y, 0, false));
 
1267
                }
 
1268
 
 
1269
                protected virtual void OnMouseDown(object sender, MouseEventArgs e)
 
1270
                {
 
1271
                        // TODO set all this stuff...
 
1272
                        long when = 0;
 
1273
                        int modifiers = 0;
 
1274
                        postEvent(new java.awt.@event.MouseEvent(component, java.awt.@event.MouseEvent.MOUSE_PRESSED, when, modifiers, e.X, e.Y, e.Clicks, false));
 
1275
                }
 
1276
 
 
1277
                protected virtual void OnMouseUp(object sender, MouseEventArgs e)
 
1278
                {
 
1279
                        // TODO set all this stuff...
 
1280
                        long when = 0;
 
1281
                        int modifiers = 0;
 
1282
                        // TODO set popupTrigger
 
1283
                        postEvent(new java.awt.@event.MouseEvent(component, java.awt.@event.MouseEvent.MOUSE_RELEASED, when, modifiers, e.X, e.Y, e.Clicks, false));
 
1284
                        // TODO send MOUSE_CLICKED if the mouse didn't move more than whatever the threshold is 
 
1285
                }
 
1286
 
 
1287
                protected void postEvent(java.awt.AWTEvent evt)
 
1288
                {
 
1289
                        getToolkit().getSystemEventQueue().postEvent(evt);
 
1290
                }
 
1291
 
 
1292
                public int checkImage(java.awt.Image img, int width, int height, java.awt.image.ImageObserver ob)
 
1293
                {
 
1294
                        return getToolkit().checkImage(img, width, height, ob);
 
1295
                }
 
1296
 
 
1297
                public java.awt.Image createImage(java.awt.image.ImageProducer prod)
 
1298
                {
 
1299
                        throw new NotImplementedException();
 
1300
                }
 
1301
 
 
1302
                public java.awt.Image createImage(int width, int height)
 
1303
                {
 
1304
                        return new NetBufferedImage(width, height);
 
1305
                }
 
1306
 
 
1307
                public void disable()
 
1308
                {
 
1309
                        throw new NotImplementedException();
 
1310
                }
 
1311
 
 
1312
                public void dispose()
 
1313
                {
 
1314
                        control.Invoke(new SetVoid(disposeImpl));
 
1315
                }
 
1316
 
 
1317
                private void disposeImpl()
 
1318
                {
 
1319
                        // HACK we should dispose the control here, but that hangs in an infinite loop...
 
1320
                        control.Hide();
 
1321
                }
 
1322
 
 
1323
                public void enable()
 
1324
                {
 
1325
                        throw new NotImplementedException();
 
1326
                }
 
1327
 
 
1328
                public ColorModel getColorModel()
 
1329
                {
 
1330
                        throw new NotImplementedException();
 
1331
                }
 
1332
 
 
1333
                public java.awt.FontMetrics getFontMetrics(java.awt.Font f)
 
1334
                {
 
1335
                        // HACK this is a very heavy weight way to determine DPI, it should be possible
 
1336
                        // to do this without creating a Graphics object
 
1337
                        using(Graphics g = control.CreateGraphics())
 
1338
                        {
 
1339
                                return new NetFontMetrics(f, NetGraphics.NetFontFromJavaFont(f, g.DpiY), null, control);
 
1340
                        }
 
1341
                }
 
1342
 
 
1343
                public virtual java.awt.Graphics getGraphics()
 
1344
                {
 
1345
                        return new NetGraphics(control.CreateGraphics(), component.getFont(), control.BackColor, true);
 
1346
                }
 
1347
 
 
1348
                public java.awt.Point getLocationOnScreen()
 
1349
                {
 
1350
                        throw new NotImplementedException();
 
1351
                }
 
1352
 
 
1353
                public java.awt.Dimension getMinimumSize()
 
1354
                {
 
1355
                        return minimumSize();
 
1356
                }
 
1357
 
 
1358
                public virtual java.awt.Dimension getPreferredSize()
 
1359
                {
 
1360
                        return preferredSize();
 
1361
                }
 
1362
 
 
1363
                public java.awt.Toolkit getToolkit()
 
1364
                {
 
1365
                        return java.awt.Toolkit.getDefaultToolkit();
 
1366
                }
 
1367
 
 
1368
                public void handleEvent(java.awt.AWTEvent e)
 
1369
                {
 
1370
                        if(e is java.awt.@event.PaintEvent)
 
1371
                        {
 
1372
                                java.awt.Graphics g = component.getGraphics();
 
1373
                                try
 
1374
                                {
 
1375
                                        component.update(g);
 
1376
                                }
 
1377
                                finally
 
1378
                                {
 
1379
                                        g.dispose();
 
1380
                                }
 
1381
                        }
 
1382
                        else
 
1383
                        {
 
1384
                                Console.WriteLine("NOTE: NetComponentPeer.handleEvent not implemented: " + e);
 
1385
                        }
 
1386
                }
 
1387
 
 
1388
                public void hide()
 
1389
                {
 
1390
                        throw new NotImplementedException();
 
1391
                }
 
1392
 
 
1393
                public bool isFocusTraversable()
 
1394
                {
 
1395
                        throw new NotImplementedException();
 
1396
                }
 
1397
 
 
1398
                public java.awt.Dimension minimumSize()
 
1399
                {
 
1400
                        return component.getSize();
 
1401
                }
 
1402
 
 
1403
                public java.awt.Dimension preferredSize()
 
1404
                {
 
1405
                        return minimumSize();
 
1406
                }
 
1407
 
 
1408
                public void paint(java.awt.Graphics graphics)
 
1409
                {
 
1410
                        //throw new NotImplementedException();
 
1411
                }
 
1412
 
 
1413
                public bool prepareImage(java.awt.Image img, int width, int height, ImageObserver ob)
 
1414
                {
 
1415
                        return getToolkit().prepareImage(img, width, height, ob);
 
1416
                }
 
1417
 
 
1418
                public void print(java.awt.Graphics graphics)
 
1419
                {
 
1420
                        throw new NotImplementedException();
 
1421
                }
 
1422
 
 
1423
                public void repaint(long tm, int x, int y, int width, int height)
 
1424
                {
 
1425
                        // TODO do something with the tm parameter
 
1426
                        Rectangle rect = new Rectangle(x, y, width, height);
 
1427
                        rect.Offset(offsetX, offsetY);
 
1428
                        control.Invoke(new SetRectangle(control.Invalidate), new object[] { rect });
 
1429
                }
 
1430
 
 
1431
                public void requestFocus()
 
1432
                {
 
1433
                        control.Invoke(new SetVoid(requestFocusImpl), null);
 
1434
                }
 
1435
 
 
1436
                private void requestFocusImpl()
 
1437
                {
 
1438
                        control.Focus();
 
1439
                }
 
1440
 
 
1441
                public bool requestFocus(java.awt.Component source, bool bool1, bool bool2, long x)
 
1442
                {
 
1443
                        throw new NotImplementedException();
 
1444
                }
 
1445
 
 
1446
                public void reshape(int x, int y, int width, int height)
 
1447
                {
 
1448
                        throw new NotImplementedException();
 
1449
                }
 
1450
 
 
1451
                public void setBackground(java.awt.Color color)
 
1452
                {
 
1453
                        control.Invoke(new SetColor(SetBackColorImpl), new object[] { Color.FromArgb(color.getRGB()) });
 
1454
                }
 
1455
 
 
1456
                private void SetBackColorImpl(Color c)
 
1457
                {
 
1458
                        control.BackColor = c;
 
1459
                }
 
1460
 
 
1461
                private void setBoundsImpl(int x, int y, int width, int height)
 
1462
                {
 
1463
                        control.SetBounds(x, y, width, height);
 
1464
                }
 
1465
 
 
1466
                public void setBounds(int x, int y, int width, int height)
 
1467
                {
 
1468
                        control.Invoke(new SetXYWH(setBoundsImpl), new object[] { x + offsetX, y + offsetY, width, height });
 
1469
                }
 
1470
 
 
1471
                public void setCursor(java.awt.Cursor cursor)
 
1472
                {
 
1473
                        switch(cursor.getType())
 
1474
                        {
 
1475
                                case java.awt.Cursor.WAIT_CURSOR:
 
1476
                                        control.Cursor = Cursors.WaitCursor;
 
1477
                                        break;
 
1478
                                case java.awt.Cursor.DEFAULT_CURSOR:
 
1479
                                        control.Cursor = Cursors.Default;
 
1480
                                        break;
 
1481
                                default:
 
1482
                                        Console.WriteLine("setCursor not implement for: " + cursor);
 
1483
                                        break;
 
1484
                        }
 
1485
                }
 
1486
 
 
1487
                private void setEnabledImpl(bool enabled)
 
1488
                {
 
1489
                        control.Enabled = enabled;
 
1490
                }
 
1491
 
 
1492
                public void setEnabled(bool enabled)
 
1493
                {
 
1494
                        control.Invoke(new SetBool(setEnabledImpl), new object[] { enabled });
 
1495
                }
 
1496
 
 
1497
                public void setFont(java.awt.Font font)
 
1498
                {
 
1499
                        // TODO use control.Invoke
 
1500
                        control.Font = NetGraphics.NetFontFromJavaFont(font, component.getToolkit().getScreenResolution());
 
1501
                }
 
1502
 
 
1503
                public void setForeground(java.awt.Color color)
 
1504
                {
 
1505
                        control.Invoke(new SetColor(SetForeColorImpl), new object[] { Color.FromArgb(color.getRGB()) });
 
1506
                }
 
1507
 
 
1508
                private void SetForeColorImpl(Color c)
 
1509
                {
 
1510
                        control.ForeColor = c;
 
1511
                }
 
1512
 
 
1513
                private void setVisibleImpl(bool visible)
 
1514
                {
 
1515
                        control.Visible = visible;
 
1516
                        postEvent(new java.awt.@event.ComponentEvent(component,
 
1517
                                visible ? java.awt.@event.ComponentEvent.COMPONENT_SHOWN : java.awt.@event.ComponentEvent.COMPONENT_HIDDEN));
 
1518
                }
 
1519
 
 
1520
                public void setVisible(bool visible)
 
1521
                {
 
1522
                        control.Invoke(new SetBool(setVisibleImpl), new object[] { visible });
 
1523
                }
 
1524
 
 
1525
                public void show()
 
1526
                {
 
1527
                        throw new NotImplementedException();
 
1528
                }
 
1529
 
 
1530
                public java.awt.GraphicsConfiguration getGraphicsConfiguration()
 
1531
                {
 
1532
                        return new NetGraphicsConfiguration();
 
1533
                }
 
1534
 
 
1535
                public void setEventMask (long mask)
 
1536
                {
 
1537
                        Console.WriteLine("NOTE: NetComponentPeer.setEventMask not implemented");
 
1538
                }
 
1539
 
 
1540
                public bool isObscured()
 
1541
                {
 
1542
                        throw new NotImplementedException();
 
1543
                }
 
1544
 
 
1545
                public bool canDetermineObscurity()
 
1546
                {
 
1547
                        throw new NotImplementedException();
 
1548
                }
 
1549
 
 
1550
                public void coalescePaintEvent(java.awt.@event.PaintEvent e)
 
1551
                {
 
1552
                        throw new NotImplementedException();
 
1553
                }
 
1554
 
 
1555
                public void updateCursorImmediately()
 
1556
                {
 
1557
                        throw new NotImplementedException();
 
1558
                }
 
1559
 
 
1560
                public VolatileImage createVolatileImage(int width, int height)
 
1561
                {
 
1562
                        throw new NotImplementedException();
 
1563
                }
 
1564
 
 
1565
                public bool handlesWheelScrolling()
 
1566
                {
 
1567
                        throw new NotImplementedException();
 
1568
                }
 
1569
 
 
1570
                public void createBuffers(int x, java.awt.BufferCapabilities capabilities)
 
1571
                {
 
1572
                        throw new NotImplementedException();
 
1573
                }
 
1574
 
 
1575
                public java.awt.Image getBackBuffer()
 
1576
                {
 
1577
                        throw new NotImplementedException();
 
1578
                }
 
1579
 
 
1580
                public void flip(java.awt.BufferCapabilities.FlipContents contents)
 
1581
                {
 
1582
                        throw new NotImplementedException();
 
1583
                }
 
1584
 
 
1585
                public void destroyBuffers()
 
1586
                {
 
1587
                        throw new NotImplementedException();
 
1588
                }
 
1589
 
 
1590
                public bool isFocusable()
 
1591
                {
 
1592
                        // TODO
 
1593
                        return true;
 
1594
                }
 
1595
        }
 
1596
 
 
1597
        // HACK Classpath should have a working BufferedImage, but currently it doesn't, until then, we
 
1598
        // provide a hacked up version
 
1599
        class NetBufferedImage : java.awt.image.BufferedImage
 
1600
        {
 
1601
                internal Bitmap bitmap;
 
1602
 
 
1603
                internal NetBufferedImage(Bitmap bitmap)
 
1604
                        : base(bitmap.Width, bitmap.Height, java.awt.image.BufferedImage.TYPE_INT_RGB)
 
1605
                {
 
1606
                        this.bitmap = bitmap;
 
1607
                }
 
1608
 
 
1609
                internal NetBufferedImage(int width, int height)
 
1610
                        : base(width, height, java.awt.image.BufferedImage.TYPE_INT_RGB)
 
1611
                {
 
1612
                        bitmap = new Bitmap(width, height);
 
1613
                        using(Graphics g = Graphics.FromImage(bitmap))
 
1614
                        {
 
1615
                                g.Clear(Color.White);
 
1616
                        }
 
1617
                }
 
1618
 
 
1619
                public override java.awt.Graphics2D createGraphics()
 
1620
                {
 
1621
                        Graphics g = Graphics.FromImage(bitmap);
 
1622
                        // HACK for off-screen images we don't want ClearType or anti-aliasing
 
1623
                        // TODO I'm sure Java 2D has a way to control text rendering quality, we should honor that
 
1624
                        g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
 
1625
                        return new NetGraphics(g, null, Color.White, true);
 
1626
                }
 
1627
 
 
1628
                public override java.awt.image.ImageProducer getSource()
 
1629
                {
 
1630
                        int[] pix = new int[bitmap.Width * bitmap.Height];
 
1631
                        for(int y = 0; y < bitmap.Height; y++)
 
1632
                        {
 
1633
                                for(int x = 0; x < bitmap.Width; x++)
 
1634
                                {
 
1635
                                        pix[x + y * bitmap.Width] = bitmap.GetPixel(x, y).ToArgb();
 
1636
                                }
 
1637
                        }
 
1638
                        return new java.awt.image.MemoryImageSource(bitmap.Width, bitmap.Height, pix, 0, bitmap.Width);
 
1639
                }
 
1640
        }
 
1641
 
 
1642
        class NetGraphicsConfiguration : java.awt.GraphicsConfiguration
 
1643
        {
 
1644
                public override java.awt.image.BufferedImage createCompatibleImage(int param1, int param2, int param3)
 
1645
                {
 
1646
                        throw new NotImplementedException();
 
1647
                }
 
1648
 
 
1649
                public override java.awt.image.BufferedImage createCompatibleImage(int width, int height)
 
1650
                {
 
1651
                        return new NetBufferedImage(width, height);
 
1652
                }
 
1653
 
 
1654
                public override java.awt.image.VolatileImage createCompatibleVolatileImage(int param1, int param2, java.awt.ImageCapabilities param3)
 
1655
                {
 
1656
                        throw new NotImplementedException();
 
1657
                }
 
1658
 
 
1659
                public override java.awt.image.VolatileImage createCompatibleVolatileImage(int param1, int param2)
 
1660
                {
 
1661
                        throw new NotImplementedException();
 
1662
                }
 
1663
 
 
1664
                public override java.awt.Rectangle getBounds()
 
1665
                {
 
1666
                        throw new NotImplementedException();
 
1667
                }
 
1668
 
 
1669
                public override java.awt.BufferCapabilities getBufferCapabilities()
 
1670
                {
 
1671
                        throw new NotImplementedException();
 
1672
                }
 
1673
 
 
1674
                public override java.awt.image.ColorModel getColorModel(int param)
 
1675
                {
 
1676
                        throw new NotImplementedException();
 
1677
                }
 
1678
 
 
1679
                public override java.awt.image.ColorModel getColorModel()
 
1680
                {
 
1681
                        throw new NotImplementedException();
 
1682
                }
 
1683
 
 
1684
                public override java.awt.geom.AffineTransform getDefaultTransform()
 
1685
                {
 
1686
                        throw new NotImplementedException();
 
1687
                }
 
1688
 
 
1689
                public override java.awt.GraphicsDevice getDevice()
 
1690
                {
 
1691
                        throw new NotImplementedException();
 
1692
                }
 
1693
 
 
1694
                public override java.awt.ImageCapabilities getImageCapabilities()
 
1695
                {
 
1696
                        throw new NotImplementedException();
 
1697
                }
 
1698
 
 
1699
                public override java.awt.geom.AffineTransform getNormalizingTransform()
 
1700
                {
 
1701
                        throw new NotImplementedException();
 
1702
                }
 
1703
        }
 
1704
 
 
1705
        class NetButtonPeer : NetComponentPeer, ButtonPeer
 
1706
        {
 
1707
                public NetButtonPeer(java.awt.Button awtbutton, Button button)
 
1708
                        : base(awtbutton, button)
 
1709
                {
 
1710
                        if(!awtbutton.isBackgroundSet())
 
1711
                        {
 
1712
                                awtbutton.setBackground(java.awt.SystemColor.control);
 
1713
                        }
 
1714
                        button.BackColor = Color.FromArgb(awtbutton.getBackground().getRGB());
 
1715
                        setLabel(awtbutton.getLabel());
 
1716
                        control.Invoke(new SetVoid(Setup));
 
1717
                }
 
1718
 
 
1719
                private void Setup()
 
1720
                {
 
1721
                        ((Button)control).Click += new EventHandler(OnClick);
 
1722
                }
 
1723
 
 
1724
                private void OnClick(object sender, EventArgs e)
 
1725
                {
 
1726
                        // TODO set all these properties correctly
 
1727
                        string cmd = "";
 
1728
                        long when = 0;
 
1729
                        int modifiers = 0;
 
1730
                        postEvent(new java.awt.@event.ActionEvent(component, java.awt.@event.ActionEvent.ACTION_PERFORMED, cmd, when, modifiers));
 
1731
                }
 
1732
 
 
1733
                private void setLabelImpl(string label)
 
1734
                {
 
1735
                        control.Text = label;
 
1736
                }
 
1737
 
 
1738
                public void setLabel(string label)
 
1739
                {
 
1740
                        control.Invoke(new SetString(setLabelImpl), new object[] { label });
 
1741
                }
 
1742
 
 
1743
                public override java.awt.Dimension getPreferredSize()
 
1744
                {
 
1745
                        using(Graphics g = control.CreateGraphics())
 
1746
                        {
 
1747
                                // TODO get these fudge factors from somewhere
 
1748
                                return new java.awt.Dimension((int)Math.Round(12 + g.MeasureString(control.Text, control.Font).Width) * 8 / 7, 6 + control.Font.Height * 8 / 7);
 
1749
                        }
 
1750
                }
 
1751
        }
 
1752
 
 
1753
        class NetTextComponentPeer : NetComponentPeer, TextComponentPeer
 
1754
        {
 
1755
                public NetTextComponentPeer(java.awt.TextComponent textComponent, TextBox textBox)
 
1756
                        : base(textComponent, textBox)
 
1757
                {
 
1758
                        control.Invoke(new SetVoid(Setup));
 
1759
                }
 
1760
 
 
1761
                private void Setup()
 
1762
                {
 
1763
                        if(!component.isBackgroundSet())
 
1764
                        {
 
1765
                                component.setBackground(java.awt.SystemColor.window);
 
1766
                        }
 
1767
                        TextBox textBox = (TextBox)control;
 
1768
                        setBackground(component.getBackground());
 
1769
                        textBox.AutoSize = false;
 
1770
                        textBox.Text = ((java.awt.TextComponent)component).getText();
 
1771
                }
 
1772
 
 
1773
                protected override void OnKeyPress(object sender, KeyPressEventArgs e)
 
1774
                {
 
1775
                        base.OnKeyPress(sender, e);
 
1776
                        // TODO for TextAreas this probably isn't the right behaviour
 
1777
                        if(e.KeyChar == '\r')
 
1778
                        {
 
1779
                                // TODO set all these properties correctly
 
1780
                                string cmd = "";
 
1781
                                long when = 0;
 
1782
                                int modifiers = 0;
 
1783
                                postEvent(new java.awt.@event.ActionEvent(component, java.awt.@event.ActionEvent.ACTION_PERFORMED, cmd, when, modifiers));
 
1784
                        }
 
1785
                }
 
1786
 
 
1787
                public int getSelectionEnd()
 
1788
                {
 
1789
                        throw new NotImplementedException();
 
1790
                }
 
1791
                public int getSelectionStart()
 
1792
                {
 
1793
                        throw new NotImplementedException();
 
1794
                }
 
1795
 
 
1796
                private string getTextImpl()
 
1797
                {
 
1798
                        return control.Text;
 
1799
                }
 
1800
 
 
1801
                public string getText()
 
1802
                {
 
1803
                        return (string)control.Invoke(new GetString(getTextImpl));
 
1804
                }
 
1805
 
 
1806
                private void setTextImpl(string text)
 
1807
                {
 
1808
                        control.Text = text;
 
1809
                }
 
1810
 
 
1811
                public void setText(string text)
 
1812
                {
 
1813
                        control.Invoke(new SetString(setTextImpl), new object[] { text });
 
1814
                }
 
1815
 
 
1816
                public void select(int start_pos, int end_pos)
 
1817
                {
 
1818
                        throw new NotImplementedException();
 
1819
                }
 
1820
                public void setEditable(bool editable)
 
1821
                {
 
1822
                        throw new NotImplementedException();
 
1823
                }
 
1824
                public int getCaretPosition()
 
1825
                {
 
1826
                        throw new NotImplementedException();
 
1827
                }
 
1828
                public void setCaretPosition(int pos)
 
1829
                {
 
1830
                        throw new NotImplementedException();
 
1831
                }
 
1832
                public long filterEvents(long filter)
 
1833
                {
 
1834
                        throw new NotImplementedException();
 
1835
                }
 
1836
                public int getIndexAtPoint(int x, int y)
 
1837
                {
 
1838
                        throw new NotImplementedException();
 
1839
                }
 
1840
                public java.awt.Rectangle getCharacterBounds(int pos)
 
1841
                {
 
1842
                        throw new NotImplementedException();
 
1843
                }
 
1844
        }
 
1845
 
 
1846
        class NetLabelPeer : NetComponentPeer, LabelPeer
 
1847
        {
 
1848
                public NetLabelPeer(java.awt.Label jlabel, Label label)
 
1849
                        : base(jlabel, label)
 
1850
                {
 
1851
                        label.Text = jlabel.getText();
 
1852
                        setAlignment(jlabel.getAlignment());
 
1853
                }
 
1854
 
 
1855
                public void setAlignment(int align)
 
1856
                {
 
1857
                        switch(align)
 
1858
                        {
 
1859
                                case java.awt.Label.LEFT:
 
1860
                                        control.Invoke(new SetInt(setAlignImpl), new object[] { ContentAlignment.TopLeft });
 
1861
                                        break;
 
1862
                                case java.awt.Label.CENTER:
 
1863
                                        control.Invoke(new SetInt(setAlignImpl), new object[] { ContentAlignment.TopCenter });
 
1864
                                        break;
 
1865
                                case java.awt.Label.RIGHT:
 
1866
                                        control.Invoke(new SetInt(setAlignImpl), new object[] { ContentAlignment.TopRight });
 
1867
                                        break;
 
1868
                        }
 
1869
                }
 
1870
 
 
1871
                private void setAlignImpl(int align)
 
1872
                {
 
1873
                        ((Label)control).TextAlign = (ContentAlignment)align;
 
1874
                }
 
1875
 
 
1876
                public void setText(string s)
 
1877
                {
 
1878
                        control.Invoke(new SetString(setTextImpl), new Object[] { s });
 
1879
                }
 
1880
 
 
1881
                private void setTextImpl(string s)
 
1882
                {
 
1883
                        control.Text = s;
 
1884
                }
 
1885
 
 
1886
                public override java.awt.Dimension getPreferredSize()
 
1887
                {
 
1888
                        return (java.awt.Dimension)control.Invoke(new GetDimension(getPreferredSizeImpl), null);
 
1889
                }
 
1890
 
 
1891
                private java.awt.Dimension getPreferredSizeImpl()
 
1892
                {
 
1893
                        Label lab = (Label)control;
 
1894
                        // HACK get these fudge factors from somewhere
 
1895
                        return new java.awt.Dimension(lab.PreferredWidth, 2 + lab.PreferredHeight);
 
1896
                }
 
1897
        }
 
1898
 
 
1899
        class NetTextFieldPeer : NetTextComponentPeer, TextFieldPeer
 
1900
        {
 
1901
                public NetTextFieldPeer(java.awt.TextField textField, TextBox textBox)
 
1902
                        : base(textField, textBox)
 
1903
                {
 
1904
                }
 
1905
 
 
1906
                public java.awt.Dimension minimumSize(int len)
 
1907
                {
 
1908
                        throw new NotImplementedException();
 
1909
                }
 
1910
 
 
1911
                public java.awt.Dimension preferredSize(int len)
 
1912
                {
 
1913
                        throw new NotImplementedException();
 
1914
                }
 
1915
 
 
1916
                public java.awt.Dimension getMinimumSize(int len)
 
1917
                {
 
1918
                        return getPreferredSize(len);
 
1919
                }
 
1920
 
 
1921
                public java.awt.Dimension getPreferredSize(int len)
 
1922
                {
 
1923
                        // TODO use control.Invoke
 
1924
                        using(Graphics g = control.CreateGraphics())
 
1925
                        {
 
1926
                                return new java.awt.Dimension((int)Math.Round((g.MeasureString("abcdefghijklm", control.Font).Width * len) / 13), ((TextBox)control).PreferredHeight);
 
1927
                        }
 
1928
                }
 
1929
 
 
1930
                public void setEchoChar(char echo_char)
 
1931
                {
 
1932
                        throw new NotImplementedException();
 
1933
                }
 
1934
 
 
1935
                public void setEchoCharacter(char echo_char)
 
1936
                {
 
1937
                        throw new NotImplementedException();
 
1938
                }
 
1939
        }
 
1940
 
 
1941
        class NetTextAreaPeer : NetTextComponentPeer, TextAreaPeer
 
1942
        {
 
1943
                public NetTextAreaPeer(java.awt.TextArea textArea, TextBox textBox)
 
1944
                        : base(textArea, textBox)
 
1945
                {
 
1946
                        control.Invoke(new SetVoid(Setup));
 
1947
                }
 
1948
 
 
1949
                private void Setup()
 
1950
                {
 
1951
                        TextBox textBox = (TextBox)control;
 
1952
                        textBox.ReadOnly = !((java.awt.TextArea)component).isEditable();
 
1953
                        textBox.WordWrap = false;
 
1954
                        textBox.ScrollBars = ScrollBars.Both;
 
1955
                        textBox.Multiline = true;
 
1956
                }
 
1957
 
 
1958
                private void insertImpl(string text, int pos)
 
1959
                {
 
1960
                        control.Text = control.Text.Insert(pos, text);
 
1961
                }
 
1962
 
 
1963
                public void insert(string text, int pos)
 
1964
                {
 
1965
                        control.Invoke(new SetStringInt(insertImpl), new Object[] { text, pos });
 
1966
                }
 
1967
 
 
1968
                public void insertText(string text, int pos)
 
1969
                {
 
1970
                        throw new NotImplementedException();
 
1971
                }
 
1972
                public java.awt.Dimension minimumSize(int rows, int cols)
 
1973
                {
 
1974
                        throw new NotImplementedException();
 
1975
                }
 
1976
                public java.awt.Dimension getMinimumSize(int rows, int cols)
 
1977
                {
 
1978
                        throw new NotImplementedException();
 
1979
                }
 
1980
                public java.awt.Dimension preferredSize(int rows, int cols)
 
1981
                {
 
1982
                        throw new NotImplementedException();
 
1983
                }
 
1984
 
 
1985
                public java.awt.Dimension getPreferredSize(int rows, int cols)
 
1986
                {
 
1987
                        Console.WriteLine("NOTE: NetTextAreaPeer.getPreferredSize not implemented");
 
1988
                        return new java.awt.Dimension(10 * cols, 15 * rows);
 
1989
                }
 
1990
 
 
1991
                public void replaceRange(string text, int start_pos, int end_pos)
 
1992
                {
 
1993
                        throw new NotImplementedException();
 
1994
                }
 
1995
                public void replaceText(string text, int start_pos, int end_pos)
 
1996
                {
 
1997
                        throw new NotImplementedException();
 
1998
                }
 
1999
        }
 
2000
 
 
2001
        class NetContainerPeer : NetComponentPeer, ContainerPeer
 
2002
        {
 
2003
                public NetContainerPeer(java.awt.Container awtcontainer, ContainerControl container)
 
2004
                        : base(awtcontainer, container)
 
2005
                {
 
2006
                }
 
2007
 
 
2008
                public java.awt.Insets insets()
 
2009
                {
 
2010
                        throw new NotImplementedException();
 
2011
                }
 
2012
 
 
2013
                public virtual java.awt.Insets getInsets()
 
2014
                {
 
2015
                        Console.WriteLine("NOTE: NetContainerPeer.getInsets not implemented");
 
2016
                        return new java.awt.Insets(0, 0, 0, 0);
 
2017
                }
 
2018
 
 
2019
                public void beginValidate()
 
2020
                {
 
2021
                        Console.WriteLine("NOTE: NetContainerPeer.beginValidate not implemented");
 
2022
                }
 
2023
 
 
2024
                public void endValidate()
 
2025
                {
 
2026
                        Console.WriteLine("NOTE: NetContainerPeer.endValidate not implemented");
 
2027
                }
 
2028
                public void beginLayout()
 
2029
                {
 
2030
                        throw new NotImplementedException();
 
2031
                }
 
2032
                public void endLayout()
 
2033
                {
 
2034
                        throw new NotImplementedException();
 
2035
                }
 
2036
                public bool isPaintPending()
 
2037
                {
 
2038
                        throw new NotImplementedException();
 
2039
                }
 
2040
        }
 
2041
 
 
2042
        class NetPanelPeer : NetContainerPeer, PanelPeer
 
2043
        {
 
2044
                public NetPanelPeer(java.awt.Panel panel, ContainerControl container)
 
2045
                        : base(panel, container)
 
2046
                {
 
2047
                }
 
2048
        }
 
2049
 
 
2050
        class NewCanvasPeer : NetComponentPeer, CanvasPeer
 
2051
        {
 
2052
                public NewCanvasPeer(java.awt.Canvas canvas, Control control)
 
2053
                        : base(canvas, control)
 
2054
                {
 
2055
                }
 
2056
        }
 
2057
 
 
2058
        class NetWindowPeer : NetContainerPeer, WindowPeer
 
2059
        {
 
2060
                public NetWindowPeer(java.awt.Window window, Form form)
 
2061
                        : base(window, form)
 
2062
                {
 
2063
                        if(!window.isFontSet())
 
2064
                        {
 
2065
                                window.setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12));
 
2066
                        }
 
2067
                        if(!window.isForegroundSet())
 
2068
                        {
 
2069
                                window.setForeground(java.awt.SystemColor.windowText);
 
2070
                        }
 
2071
                        if(!window.isBackgroundSet())
 
2072
                        {
 
2073
                                window.setBackground(java.awt.SystemColor.window);
 
2074
                        }
 
2075
                        setFont(window.getFont());
 
2076
                        setForeground(window.getForeground());
 
2077
                        setBackground(window.getBackground());
 
2078
                        form.SetBounds(window.getX(), window.getY(), window.getWidth(), window.getHeight());
 
2079
                }
 
2080
 
 
2081
                public void toBack()
 
2082
                {
 
2083
                        ((Form)control).SendToBack();
 
2084
                }
 
2085
 
 
2086
                public void toFront()
 
2087
                {
 
2088
                        ((Form)control).Activate();
 
2089
                }
 
2090
        }
 
2091
 
 
2092
        class NetFramePeer : NetWindowPeer, FramePeer
 
2093
        {
 
2094
                public NetFramePeer(java.awt.Frame frame, Form form)
 
2095
                        : base(frame, form)
 
2096
                {
 
2097
                        setTitle(frame.getTitle());
 
2098
                        control.Invoke(new SetVoid(Setup));
 
2099
                }
 
2100
 
 
2101
                private void Setup()
 
2102
                {
 
2103
                        Form form = (Form)control;
 
2104
                        form.Resize += new EventHandler(Resize);
 
2105
                        form.Closing += new CancelEventHandler(Closing);
 
2106
                }
 
2107
 
 
2108
                private void Closing(object sender, CancelEventArgs e)
 
2109
                {
 
2110
                        e.Cancel = true;
 
2111
                        postEvent(new java.awt.@event.WindowEvent((java.awt.Window)component, java.awt.@event.WindowEvent.WINDOW_CLOSING));
 
2112
                }
 
2113
 
 
2114
                private void Resize(object sender, EventArgs e)
 
2115
                {
 
2116
                        // TODO I have no clue what I should do here...
 
2117
                        Rectangle r = control.Bounds;
 
2118
                        component.setBounds(r.X, r.Y, r.Width, r.Height);
 
2119
                        component.invalidate();
 
2120
                        component.validate();
 
2121
                        postEvent(new java.awt.@event.ComponentEvent(component, java.awt.@event.ComponentEvent.COMPONENT_RESIZED));
 
2122
                }
 
2123
 
 
2124
                public override java.awt.Graphics getGraphics()
 
2125
                {
 
2126
                        NetGraphics g = new NetGraphics(control.CreateGraphics(), component.getFont(), control.BackColor, true);
 
2127
                        java.awt.Insets insets = ((java.awt.Frame)component).getInsets();
 
2128
                        g.translate(-insets.left, -insets.top);
 
2129
                        g.setClip(insets.left, insets.top, control.ClientRectangle.Width, control.ClientRectangle.Height);
 
2130
                        return g;
 
2131
                }
 
2132
 
 
2133
                public void setIconImage(java.awt.Image image)
 
2134
                {
 
2135
                        throw new NotImplementedException();
 
2136
                }
 
2137
                public void setMenuBar(java.awt.MenuBar mb)
 
2138
                {
 
2139
                        throw new NotImplementedException();
 
2140
                }
 
2141
                public void setResizable(bool resizable)
 
2142
                {
 
2143
                        throw new NotImplementedException();
 
2144
                }
 
2145
                private void setTitleImpl(string title)
 
2146
                {
 
2147
                        control.Text = title;
 
2148
                }
 
2149
                public void setTitle(string title)
 
2150
                {
 
2151
                        control.Invoke(new SetString(setTitleImpl), new object[] { title });
 
2152
                }
 
2153
 
 
2154
                public override java.awt.Insets getInsets()
 
2155
                {
 
2156
                        // TODO use control.Invoke
 
2157
                        Form f = (Form)control;
 
2158
                        Rectangle client = f.ClientRectangle;
 
2159
                        Rectangle r = f.RectangleToScreen(client);
 
2160
                        int x = r.Location.X - f.Location.X;
 
2161
                        int y = r.Location.Y - f.Location.Y;
 
2162
                        return new java.awt.Insets(y, x, control.Height - client.Height - y, control.Width - client.Width - x);
 
2163
                }
 
2164
 
 
2165
                public int getState()
 
2166
                {
 
2167
                        throw new NotImplementedException();
 
2168
                }
 
2169
                public void setState(int state)
 
2170
                {
 
2171
                        throw new NotImplementedException();
 
2172
                }
 
2173
                public void setMaximizedBounds(java.awt.Rectangle r)
 
2174
                {
 
2175
                        throw new NotImplementedException();
 
2176
                }
 
2177
        }
 
2178
 
 
2179
        class NetListPeer : NetComponentPeer, ListPeer
 
2180
        {
 
2181
                internal NetListPeer(java.awt.List target, ListBox listbox)
 
2182
                        : base(target, listbox)
 
2183
                {
 
2184
                }
 
2185
 
 
2186
                public void add(String item, int index)
 
2187
                {
 
2188
                        throw new NotImplementedException();
 
2189
                }
 
2190
 
 
2191
                public void addItem(String item, int index)
 
2192
                {
 
2193
                        throw new NotImplementedException();
 
2194
                }
 
2195
 
 
2196
                public void clear()
 
2197
                {
 
2198
                        throw new NotImplementedException();
 
2199
                }
 
2200
 
 
2201
                public void delItems(int start_index, int end_index)
 
2202
                {
 
2203
                        throw new NotImplementedException();
 
2204
                }
 
2205
 
 
2206
                public void deselect(int index)
 
2207
                {
 
2208
                        throw new NotImplementedException();
 
2209
                }
 
2210
 
 
2211
                public int[] getSelectedIndexes()
 
2212
                {
 
2213
                        throw new NotImplementedException();
 
2214
                }
 
2215
 
 
2216
                public void makeVisible(int index)
 
2217
                {
 
2218
                        throw new NotImplementedException();
 
2219
                }
 
2220
 
 
2221
                public java.awt.Dimension minimumSize(int s)
 
2222
                {
 
2223
                        throw new NotImplementedException();
 
2224
                }
 
2225
 
 
2226
                public java.awt.Dimension preferredSize(int s)
 
2227
                {
 
2228
                        throw new NotImplementedException();
 
2229
                }
 
2230
 
 
2231
                public void removeAll()
 
2232
                {
 
2233
                        throw new NotImplementedException();
 
2234
                }
 
2235
 
 
2236
                public void select(int index)
 
2237
                {
 
2238
                        throw new NotImplementedException();
 
2239
                }
 
2240
 
 
2241
                public void setMultipleMode(bool multi)
 
2242
                {
 
2243
                        throw new NotImplementedException();
 
2244
                }
 
2245
 
 
2246
                public void setMultipleSelections(bool multi)
 
2247
                {
 
2248
                        throw new NotImplementedException();
 
2249
                }
 
2250
 
 
2251
                public java.awt.Dimension getPreferredSize(int s)
 
2252
                {
 
2253
                        throw new NotImplementedException();
 
2254
                }
 
2255
 
 
2256
                public java.awt.Dimension getMinimumSize(int s)
 
2257
                {
 
2258
                        throw new NotImplementedException();
 
2259
                }
 
2260
        }
 
2261
}