ikvm-fork/awt/toolkit.cs

2733 строки
69 KiB
C#
Исходник Обычный вид История

2002-12-18 19:00:25 +03:00
/*
2005-01-05 15:11:50 +03:00
Copyright (C) 2002, 2004, 2005 Jeroen Frijters
2002-12-18 19:00:25 +03:00
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
using System;
using System.Threading;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;
using java.awt.datatransfer;
using java.awt.image;
using java.awt.peer;
using java.net;
using java.util;
namespace ikvm.awt
{
delegate void SetVoid();
delegate void SetBool(bool b);
2003-07-21 16:12:40 +04:00
delegate void SetInt(int i);
2002-12-18 19:00:25 +03:00
delegate void SetXYWH(int x, int y, int w, int h);
delegate void SetString(string s);
delegate string GetString();
delegate void SetStringInt(string s, int i);
2003-07-21 16:12:40 +04:00
delegate void SetRectangle(Rectangle r);
delegate void SetColor(Color c);
delegate java.awt.Dimension GetDimension();
2002-12-18 19:00:25 +03:00
2004-03-26 13:19:21 +03:00
class UndecoratedForm : Form
{
public UndecoratedForm()
{
this.FormBorderStyle = FormBorderStyle.None;
}
}
2004-03-16 20:10:09 +03:00
public class NetToolkit : gnu.java.awt.ClasspathToolkit
2002-12-18 19:00:25 +03:00
{
2005-02-02 18:11:26 +03:00
internal static System.Collections.ArrayList nativeQueue = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList());
2002-12-18 19:00:25 +03:00
private static java.awt.EventQueue eventQueue = new java.awt.EventQueue();
2004-12-02 19:06:37 +03:00
private static volatile Form bogusForm;
2002-12-18 19:00:25 +03:00
private static Delegate createControlInstance;
2003-07-21 16:12:40 +04:00
private int resolution;
2002-12-18 19:00:25 +03:00
private delegate Control CreateControlInstanceDelegate(Type type);
private static void MessageLoop()
{
createControlInstance = new CreateControlInstanceDelegate(CreateControlImpl);
2004-12-02 19:06:37 +03:00
using(Form form = new Form())
{
form.CreateControl();
// HACK I have no idea why this line is necessary...
IntPtr p = form.Handle;
bogusForm = form;
2005-01-03 11:26:21 +03:00
// FXBUG to make sure we can be aborted (Thread.Abort) we need to periodically
2004-12-02 19:06:37 +03:00
// fire an event (because otherwise we'll be blocking in unmanaged code and
// the Abort cannot be handled there).
System.Windows.Forms.Timer t = new System.Windows.Forms.Timer();
t.Interval = 100;
t.Start();
Application.Run();
}
2002-12-18 19:00:25 +03:00
}
2003-07-21 16:12:40 +04:00
internal static Control CreateControlImpl(Type type)
2002-12-18 19:00:25 +03:00
{
Control control = (Control)Activator.CreateInstance(type);
control.CreateControl();
// HACK here we go again...
IntPtr p = control.Handle;
return control;
}
internal static Control CreateControl(Type type)
{
return (Control)bogusForm.Invoke(createControlInstance, new object[] { type });
}
public NetToolkit()
{
lock(typeof(NetToolkit))
{
2004-01-11 16:14:42 +03:00
System.Diagnostics.Debug.Assert(bogusForm == null);
2002-12-18 19:00:25 +03:00
Thread thread = new Thread(new ThreadStart(MessageLoop));
thread.Start();
// TODO don't use polling...
2004-12-02 19:06:37 +03:00
while(bogusForm == null && thread.IsAlive)
2002-12-18 19:00:25 +03:00
{
Thread.Sleep(1);
}
}
}
2003-07-21 16:12:40 +04:00
protected override void loadSystemColors(int[] systemColors)
{
// initialize all colors to purple to make the ones we might have missed stand out
for(int i = 0; i < systemColors.Length; i++)
{
systemColors[i] = Color.Purple.ToArgb();
}
systemColors[java.awt.SystemColor.DESKTOP] = SystemColors.Desktop.ToArgb();
systemColors[java.awt.SystemColor.ACTIVE_CAPTION] = SystemColors.ActiveCaption.ToArgb();
systemColors[java.awt.SystemColor.ACTIVE_CAPTION_TEXT] = SystemColors.ActiveCaptionText.ToArgb();
systemColors[java.awt.SystemColor.ACTIVE_CAPTION_BORDER] = SystemColors.ActiveBorder.ToArgb();
systemColors[java.awt.SystemColor.INACTIVE_CAPTION] = SystemColors.InactiveCaption.ToArgb();
systemColors[java.awt.SystemColor.INACTIVE_CAPTION_TEXT] = SystemColors.InactiveCaptionText.ToArgb();
systemColors[java.awt.SystemColor.INACTIVE_CAPTION_BORDER] = SystemColors.InactiveBorder.ToArgb();
systemColors[java.awt.SystemColor.WINDOW] = SystemColors.Window.ToArgb();
systemColors[java.awt.SystemColor.WINDOW_BORDER] = SystemColors.WindowFrame.ToArgb();
systemColors[java.awt.SystemColor.WINDOW_TEXT] = SystemColors.WindowText.ToArgb();
systemColors[java.awt.SystemColor.MENU] = SystemColors.Menu.ToArgb();
systemColors[java.awt.SystemColor.MENU_TEXT] = SystemColors.MenuText.ToArgb();
systemColors[java.awt.SystemColor.TEXT] = SystemColors.Window.ToArgb();
systemColors[java.awt.SystemColor.TEXT_TEXT] = SystemColors.WindowText.ToArgb();
systemColors[java.awt.SystemColor.TEXT_HIGHLIGHT] = SystemColors.Highlight.ToArgb();
systemColors[java.awt.SystemColor.TEXT_HIGHLIGHT_TEXT] = SystemColors.HighlightText.ToArgb();
systemColors[java.awt.SystemColor.TEXT_INACTIVE_TEXT] = SystemColors.GrayText.ToArgb();
systemColors[java.awt.SystemColor.CONTROL] = SystemColors.Control.ToArgb();
systemColors[java.awt.SystemColor.CONTROL_TEXT] = SystemColors.ControlText.ToArgb();
systemColors[java.awt.SystemColor.CONTROL_HIGHLIGHT] = SystemColors.ControlLight.ToArgb();
systemColors[java.awt.SystemColor.CONTROL_LT_HIGHLIGHT] = SystemColors.ControlLightLight.ToArgb();
systemColors[java.awt.SystemColor.CONTROL_SHADOW] = SystemColors.ControlDark.ToArgb();
systemColors[java.awt.SystemColor.CONTROL_DK_SHADOW] = SystemColors.ControlDarkDark.ToArgb();
systemColors[java.awt.SystemColor.SCROLLBAR] = SystemColors.ScrollBar.ToArgb();
systemColors[java.awt.SystemColor.INFO] = SystemColors.Info.ToArgb();
systemColors[java.awt.SystemColor.INFO_TEXT] = SystemColors.InfoText.ToArgb();
}
2002-12-18 19:00:25 +03:00
protected override java.awt.peer.ButtonPeer createButton(java.awt.Button target)
{
return new NetButtonPeer(target, (Button)CreateControl(typeof(Button)));
}
protected override java.awt.peer.TextFieldPeer createTextField(java.awt.TextField target)
{
return new NetTextFieldPeer(target, (TextBox)CreateControl(typeof(TextBox)));
}
protected override java.awt.peer.LabelPeer createLabel(java.awt.Label target)
{
2003-07-21 16:12:40 +04:00
return new NetLabelPeer(target, (Label)CreateControl(typeof(Label)));
2002-12-18 19:00:25 +03:00
}
protected override java.awt.peer.ListPeer createList(java.awt.List target)
{
2003-08-12 17:09:31 +04:00
return new NetListPeer(target, (ListBox)CreateControl(typeof(ListBox)));
2002-12-18 19:00:25 +03:00
}
protected override java.awt.peer.CheckboxPeer createCheckbox(java.awt.Checkbox target)
{
2005-05-25 17:44:08 +04:00
return new NetCheckboxPeer(target, (CheckBox)CreateControl(typeof(CheckBox)));
2002-12-18 19:00:25 +03:00
}
protected override java.awt.peer.ScrollbarPeer createScrollbar(java.awt.Scrollbar target)
{
throw new NotImplementedException();
}
protected override java.awt.peer.ScrollPanePeer createScrollPane(java.awt.ScrollPane target)
{
throw new NotImplementedException();
}
protected override java.awt.peer.TextAreaPeer createTextArea(java.awt.TextArea target)
{
return new NetTextAreaPeer(target, (TextBox)CreateControl(typeof(TextBox)));
}
protected override java.awt.peer.ChoicePeer createChoice(java.awt.Choice target)
{
2005-05-25 17:44:08 +04:00
return new NetChoicePeer(target, (ComboBox)CreateControl(typeof(ComboBox)));
2002-12-18 19:00:25 +03:00
}
protected override java.awt.peer.FramePeer createFrame(java.awt.Frame target)
{
return new NetFramePeer(target, (Form)CreateControl(typeof(Form)));
}
protected override java.awt.peer.CanvasPeer createCanvas(java.awt.Canvas target)
{
2003-07-21 16:12:40 +04:00
return new NewCanvasPeer(target, (Control)CreateControl(typeof(Control)));
2002-12-18 19:00:25 +03:00
}
protected override java.awt.peer.PanelPeer createPanel(java.awt.Panel target)
{
return new NetPanelPeer(target, (ContainerControl)CreateControl(typeof(ContainerControl)));
}
protected override java.awt.peer.WindowPeer createWindow(java.awt.Window target)
{
2004-03-26 13:19:21 +03:00
return new NetWindowPeer(target, (Form)CreateControl(typeof(UndecoratedForm)));
2002-12-18 19:00:25 +03:00
}
2004-03-26 13:19:21 +03:00
2002-12-18 19:00:25 +03:00
protected override java.awt.peer.DialogPeer createDialog(java.awt.Dialog target)
{
2004-09-27 14:17:34 +04:00
return new NetDialogPeer(target, (Form)CreateControl(typeof(Form)));
2002-12-18 19:00:25 +03:00
}
2004-09-27 14:17:34 +04:00
2002-12-18 19:00:25 +03:00
protected override java.awt.peer.MenuBarPeer createMenuBar(java.awt.MenuBar target)
{
throw new NotImplementedException();
}
protected override java.awt.peer.MenuPeer createMenu(java.awt.Menu target)
{
throw new NotImplementedException();
}
protected override java.awt.peer.PopupMenuPeer createPopupMenu(java.awt.PopupMenu target)
{
throw new NotImplementedException();
}
protected override java.awt.peer.MenuItemPeer createMenuItem(java.awt.MenuItem target)
{
throw new NotImplementedException();
}
protected override java.awt.peer.FileDialogPeer createFileDialog(java.awt.FileDialog target)
{
throw new NotImplementedException();
}
protected override java.awt.peer.CheckboxMenuItemPeer createCheckboxMenuItem(java.awt.CheckboxMenuItem target)
{
throw new NotImplementedException();
}
2004-11-04 15:50:28 +03:00
[Obsolete]
2002-12-18 19:00:25 +03:00
protected override java.awt.peer.FontPeer getFontPeer(string name, int style)
{
throw new NotImplementedException();
}
2004-03-26 13:19:21 +03:00
2002-12-18 19:00:25 +03:00
public override java.awt.Dimension getScreenSize()
{
2004-03-26 13:19:21 +03:00
return new java.awt.Dimension(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
2002-12-18 19:00:25 +03:00
}
2003-07-21 16:12:40 +04:00
2002-12-18 19:00:25 +03:00
public override int getScreenResolution()
{
2003-07-21 16:12:40 +04:00
if(resolution == 0)
{
using(Graphics g = bogusForm.CreateGraphics())
{
resolution = (int)Math.Round(g.DpiY);
}
}
return resolution;
2002-12-18 19:00:25 +03:00
}
2003-07-21 16:12:40 +04:00
2002-12-18 19:00:25 +03:00
public override ColorModel getColorModel()
{
throw new NotImplementedException();
}
2003-07-21 16:12:40 +04:00
2004-11-04 15:50:28 +03:00
[Obsolete]
2002-12-18 19:00:25 +03:00
public override string[] getFontList()
{
2004-11-04 15:50:28 +03:00
// This method is deprecated and Sun's JDK only returns these fonts as well
return new string[] { "Dialog", "SansSerif", "Serif", "Monospaced", "DialogInput" };
2002-12-18 19:00:25 +03:00
}
2003-07-21 16:12:40 +04:00
2002-12-18 19:00:25 +03:00
public override java.awt.FontMetrics getFontMetrics(java.awt.Font font)
{
2003-07-21 16:12:40 +04:00
return new NetFontMetrics(font, NetGraphics.NetFontFromJavaFont(font, getScreenResolution()), null, null);
2002-12-18 19:00:25 +03:00
}
2003-07-21 16:12:40 +04:00
2002-12-18 19:00:25 +03:00
public override void sync()
{
throw new NotImplementedException();
}
2003-07-21 16:12:40 +04:00
2002-12-18 19:00:25 +03:00
public override java.awt.Image getImage(string filename)
{
2003-07-21 16:12:40 +04:00
try
{
2003-07-23 16:50:11 +04:00
using(System.IO.FileStream stream = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite))
2003-07-21 16:12:40 +04:00
{
return new NetBufferedImage(new Bitmap(Image.FromStream(stream)));
}
}
catch(Exception)
{
return new NoImage();
}
2002-12-18 19:00:25 +03:00
}
2003-07-21 16:12:40 +04:00
2002-12-18 19:00:25 +03:00
public override java.awt.Image getImage(URL url)
{
2004-09-27 14:17:34 +04:00
// TODO extremely lame...
System.IO.MemoryStream mem = new System.IO.MemoryStream();
java.io.InputStream inS = url.openStream();
int b;
while((b = inS.read()) >= 0)
{
mem.WriteByte((byte)b);
}
try
{
mem.Position = 0;
return new NetBufferedImage(new Bitmap(Image.FromStream(mem)));
}
catch
{
return new NoImage();
}
2003-07-21 16:12:40 +04:00
}
public override java.awt.Image createImage(string filename)
{
2004-09-27 14:17:34 +04:00
return getImage(filename);
2003-07-21 16:12:40 +04:00
}
2004-09-27 14:17:34 +04:00
2003-07-21 16:12:40 +04:00
public override java.awt.Image createImage(URL url)
{
2004-09-27 14:17:34 +04:00
return getImage(url);
2003-07-21 16:12:40 +04:00
}
2003-07-23 16:50:11 +04:00
2005-01-03 11:26:21 +03:00
const int ERROR = java.awt.image.ImageObserver.__Fields.ERROR;
2005-04-15 15:45:49 +04:00
const int ABORT = java.awt.image.ImageObserver.__Fields.ABORT;
2005-01-03 11:26:21 +03:00
const int WIDTH = java.awt.image.ImageObserver.__Fields.WIDTH;
const int HEIGHT = java.awt.image.ImageObserver.__Fields.HEIGHT;
const int FRAMEBITS = java.awt.image.ImageObserver.__Fields.FRAMEBITS;
const int ALLBITS = java.awt.image.ImageObserver.__Fields.ALLBITS;
2003-07-23 16:50:11 +04:00
public override bool prepareImage(java.awt.Image image, int width, int height, java.awt.image.ImageObserver observer)
2003-07-21 16:12:40 +04:00
{
2003-07-23 16:50:11 +04:00
// HACK for now we call checkImage to obtain the status and fire the observer
2005-04-15 15:45:49 +04:00
return (checkImage(image, width, height, observer) & (ALLBITS | ERROR | ABORT)) != 0;
2003-07-21 16:12:40 +04:00
}
2003-07-23 16:50:11 +04:00
public override int checkImage(java.awt.Image image, int width, int height, java.awt.image.ImageObserver observer)
2003-07-21 16:12:40 +04:00
{
if(image.getWidth(null) == -1)
{
2003-07-23 16:50:11 +04:00
if(observer != null)
{
2005-04-15 15:45:49 +04:00
observer.imageUpdate(image, ERROR | ABORT, 0, 0, -1, -1);
2003-07-23 16:50:11 +04:00
}
2005-04-15 15:45:49 +04:00
return ERROR | ABORT;
2003-07-21 16:12:40 +04:00
}
2003-07-23 16:50:11 +04:00
if(observer != null)
{
2005-01-03 11:26:21 +03:00
observer.imageUpdate(image, WIDTH + HEIGHT + FRAMEBITS + ALLBITS, 0, 0, image.getWidth(null), image.getHeight(null));
2003-07-23 16:50:11 +04:00
}
2005-01-03 11:26:21 +03:00
return WIDTH + HEIGHT + FRAMEBITS + ALLBITS;
2003-07-21 16:12:40 +04:00
}
public override java.awt.Image createImage(java.awt.image.ImageProducer producer)
{
2004-09-27 14:17:34 +04:00
NetProducerImage img = new NetProducerImage(producer);
if(producer != null)
{
producer.startProduction(img);
}
return img;
2003-07-21 16:12:40 +04:00
}
2003-07-23 16:50:11 +04:00
2005-02-02 18:11:26 +03:00
public override java.awt.Image createImage(byte[] imagedata, int imageoffset, int imagelength)
2003-07-21 16:12:40 +04:00
{
throw new NotImplementedException();
}
2003-07-23 16:50:11 +04:00
public override java.awt.PrintJob getPrintJob(java.awt.Frame frame, string jobtitle, Properties props)
2003-07-21 16:12:40 +04:00
{
throw new NotImplementedException();
}
2003-07-23 16:50:11 +04:00
2003-07-21 16:12:40 +04:00
public override void beep()
{
throw new NotImplementedException();
}
2003-07-23 16:50:11 +04:00
2003-07-21 16:12:40 +04:00
public override java.awt.datatransfer.Clipboard getSystemClipboard()
{
throw new NotImplementedException();
}
protected override java.awt.EventQueue getSystemEventQueueImpl()
{
return eventQueue;
}
public override java.awt.dnd.peer.DragSourceContextPeer createDragSourceContextPeer(java.awt.dnd.DragGestureEvent dge)
{
throw new NotImplementedException();
}
public override Map mapInputMethodHighlight(java.awt.im.InputMethodHighlight highlight)
{
throw new NotImplementedException();
}
2003-07-23 16:50:11 +04:00
protected override java.awt.peer.LightweightPeer createComponent(java.awt.Component target)
{
if(target is java.awt.Container)
{
return new NetLightweightContainerPeer((java.awt.Container)target);
}
return new NetLightweightComponentPeer(target);
}
2004-03-16 20:10:09 +03:00
public override java.awt.Font createFont(int format, java.io.InputStream stream)
{
throw new NotImplementedException();
}
public override gnu.java.awt.peer.ClasspathFontPeer getClasspathFontPeer(string name, java.util.Map attrs)
{
return new NetFontPeer(name, attrs);
}
public override java.awt.GraphicsEnvironment getLocalGraphicsEnvironment()
{
2005-05-25 17:44:08 +04:00
return new NetGraphicsEnvironment();
2004-03-16 20:10:09 +03:00
}
2004-10-19 17:43:55 +04:00
public override gnu.java.awt.peer.ClasspathTextLayoutPeer getClasspathTextLayoutPeer(java.text.AttributedString str, java.awt.font.FontRenderContext ctxt)
{
throw new NotImplementedException();
}
2005-01-05 15:11:50 +03:00
public override RobotPeer createRobot(java.awt.GraphicsDevice param)
{
throw new NotImplementedException();
}
2005-02-02 18:11:26 +03:00
public override bool nativeQueueEmpty()
{
return nativeQueue.Count == 0;
}
public override void wakeNativeQueue()
{
// TODO if we're blocking in iterateNativeQueue() we should release that thread
}
public override void iterateNativeQueue(java.awt.EventQueue locked, bool block)
{
lock(nativeQueue)
{
if(nativeQueue.Count > 0)
{
locked.postEvent((java.awt.AWTEvent)nativeQueue[0]);
nativeQueue.RemoveAt(0);
return;
}
}
if(block)
{
Monitor.Exit(locked);
try
{
//Application.DoEvents();
Thread.Sleep(100);
}
finally
{
Monitor.Enter(locked);
}
}
}
2004-03-16 20:10:09 +03:00
}
2005-05-25 17:44:08 +04:00
class NetGraphicsEnvironment : java.awt.GraphicsEnvironment
{
public override java.awt.Graphics2D createGraphics(BufferedImage bi)
{
throw new NotImplementedException();
}
public override java.awt.Font[] getAllFonts()
{
throw new NotImplementedException();
}
public override string[] getAvailableFontFamilyNames()
{
throw new NotImplementedException();
}
public override string[] getAvailableFontFamilyNames(Locale l)
{
throw new NotImplementedException();
}
public override java.awt.GraphicsDevice getDefaultScreenDevice()
{
return new NetGraphicsDevice();
}
public override java.awt.GraphicsDevice[] getScreenDevices()
{
throw new NotImplementedException();
}
}
class NetGraphicsDevice : java.awt.GraphicsDevice
{
public override java.awt.GraphicsConfiguration[] getConfigurations()
{
throw new NotImplementedException();
}
public override java.awt.GraphicsConfiguration getDefaultConfiguration()
{
return new NetGraphicsConfiguration();
}
public override string getIDstring()
{
throw new NotImplementedException();
}
public override int getType()
{
throw new NotImplementedException();
}
}
2004-03-16 20:10:09 +03:00
class NetFontPeer : gnu.java.awt.peer.ClasspathFontPeer
{
internal NetFontPeer(string name, java.util.Map attrs)
: base(name, attrs)
{
}
public override bool canDisplay(java.awt.Font param1, char param2)
{
throw new NotImplementedException();
}
public override int canDisplayUpTo(java.awt.Font param1, java.text.CharacterIterator param2, int param3, int param4)
{
throw new NotImplementedException();
}
public override java.awt.font.GlyphVector createGlyphVector(java.awt.Font param1, java.awt.font.FontRenderContext param2, int[] param3)
{
throw new NotImplementedException();
}
public override java.awt.font.GlyphVector createGlyphVector(java.awt.Font param1, java.awt.font.FontRenderContext param2, java.text.CharacterIterator param3)
{
throw new NotImplementedException();
}
2005-02-02 18:11:26 +03:00
public override byte getBaselineFor(java.awt.Font param1, char param2)
2004-03-16 20:10:09 +03:00
{
throw new NotImplementedException();
}
public override java.awt.FontMetrics getFontMetrics(java.awt.Font param)
{
throw new NotImplementedException();
}
public override string getGlyphName(java.awt.Font param1, int param2)
{
throw new NotImplementedException();
}
public override java.awt.font.LineMetrics getLineMetrics(java.awt.Font param1, java.text.CharacterIterator param2, int param3, int param4, java.awt.font.FontRenderContext param5)
{
throw new NotImplementedException();
}
public override java.awt.geom.Rectangle2D getMaxCharBounds(java.awt.Font param1, java.awt.font.FontRenderContext param2)
{
throw new NotImplementedException();
}
public override int getMissingGlyphCode(java.awt.Font param)
{
throw new NotImplementedException();
}
public override int getNumGlyphs(java.awt.Font param)
{
throw new NotImplementedException();
}
public override string getPostScriptName(java.awt.Font param)
{
throw new NotImplementedException();
}
public override java.awt.geom.Rectangle2D getStringBounds(java.awt.Font param1, java.text.CharacterIterator param2, int param3, int param4, java.awt.font.FontRenderContext param5)
{
throw new NotImplementedException();
}
public override bool hasUniformLineMetrics(java.awt.Font param)
{
throw new NotImplementedException();
}
public override java.awt.font.GlyphVector layoutGlyphVector(java.awt.Font param1, java.awt.font.FontRenderContext param2, char[] param3, int param4, int param5, int param6)
{
throw new NotImplementedException();
}
public override string getSubFamilyName(java.awt.Font param1, Locale param2)
{
throw new NotImplementedException();
}
2003-07-23 16:50:11 +04:00
}
class NetLightweightComponentPeer : NetComponentPeer, java.awt.peer.LightweightPeer
{
public NetLightweightComponentPeer(java.awt.Component target)
: base(target, ((NetComponentPeer)target.getParent().getPeer()).control)
{
}
}
class NetLightweightContainerPeer : NetContainerPeer, java.awt.peer.LightweightPeer
{
public NetLightweightContainerPeer(java.awt.Container target)
: base(target, (ContainerControl)((NetContainerPeer)target.getParent().getPeer()).control)
{
}
2003-07-21 16:12:40 +04:00
}
class NoImage : java.awt.Image
{
public override int getWidth(java.awt.image.ImageObserver observer)
{
2005-04-15 15:45:49 +04:00
if(observer != null)
{
observer.imageUpdate(this, java.awt.image.ImageObserver.__Fields.ERROR | java.awt.image.ImageObserver.__Fields.ABORT, 0, 0, -1, -1);
}
2003-07-21 16:12:40 +04:00
return -1;
}
public override int getHeight(java.awt.image.ImageObserver observer)
{
2005-04-15 15:45:49 +04:00
if(observer != null)
{
observer.imageUpdate(this, java.awt.image.ImageObserver.__Fields.ERROR | java.awt.image.ImageObserver.__Fields.ABORT, 0, 0, -1, -1);
}
2003-07-21 16:12:40 +04:00
return -1;
}
public override ImageProducer getSource()
{
return null;
}
public override java.awt.Graphics getGraphics()
{
// TODO throw java.lang.IllegalAccessError: getGraphics() only valid for images created with createImage(w, h)
return null;
}
public override object getProperty(string name, java.awt.image.ImageObserver observer)
{
2005-04-15 15:45:49 +04:00
if(observer != null)
{
observer.imageUpdate(this, java.awt.image.ImageObserver.__Fields.ERROR | java.awt.image.ImageObserver.__Fields.ABORT, 0, 0, -1, -1);
}
2003-07-21 16:12:40 +04:00
return null;
}
public override void flush()
{
}
}
class NetGraphics : java.awt.Graphics2D
{
private bool disposable;
private Graphics g;
private java.awt.Color jcolor;
private Color color = SystemColors.WindowText;
2003-07-25 01:01:48 +04:00
private Color bgcolor;
2003-07-21 16:12:40 +04:00
private java.awt.Font font;
private Font netfont;
private java.awt.Rectangle _clip;
2003-07-25 01:01:48 +04:00
public NetGraphics(Graphics g, java.awt.Font font, Color bgcolor, bool disposable)
2003-07-21 16:12:40 +04:00
{
if(font == null)
{
font = new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12);
}
this.g = g;
this.font = font;
netfont = NetFontFromJavaFont(font, g.DpiY);
2003-07-25 01:01:48 +04:00
this.bgcolor = bgcolor;
2003-07-21 16:12:40 +04:00
this.disposable = disposable;
if(!g.IsClipEmpty)
{
_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));
}
}
public override void clearRect(int x, int y, int width, int height)
{
2003-07-25 01:01:48 +04:00
using(SolidBrush b = new SolidBrush(bgcolor))
{
g.FillRectangle(b, x, y, width, height);
}
2003-07-21 16:12:40 +04:00
}
public override void clipRect(int param1, int param2, int param3, int param4)
{
}
public override void copyArea(int param1, int param2, int param3, int param4, int param5, int param6)
{
}
public override java.awt.Graphics create(int param1, int param2, int param3, int param4)
{
return null;
}
public override java.awt.Graphics create()
{
2003-07-23 16:50:11 +04:00
// TODO we need to actually recreate a new underlying Graphics object, but .NET doesn't
// seem to have a way of doing that, so we probably need access to the underlying surface.
// Sigh...
2003-07-25 01:01:48 +04:00
NetGraphics newg = new NetGraphics(g, font, bgcolor, false);
2003-07-23 16:50:11 +04:00
// TODO copy other attributes
return newg;
2003-07-21 16:12:40 +04:00
}
public override void dispose()
{
if(disposable)
{
disposable = false;
g.Dispose();
}
netfont.Dispose();
}
public override void draw3DRect(int param1, int param2, int param3, int param4, bool param5)
{
}
public override void drawArc(int param1, int param2, int param3, int param4, int param5, int param6)
{
}
2005-02-02 18:11:26 +03:00
public override void drawBytes(byte[] param1, int param2, int param3, int param4, int param5)
2003-07-21 16:12:40 +04:00
{
}
public override void drawChars(char[] param1, int param2, int param3, int param4, int param5)
{
}
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)
{
return true;
}
2003-07-23 16:50:11 +04:00
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)
2003-07-21 16:12:40 +04:00
{
2003-07-23 16:50:11 +04:00
if(img is NetBufferedImage)
{
Rectangle destRect = new Rectangle(dx1, dy1, dx2 - dx1, dy2 - dy1);
Rectangle srcRect = new Rectangle(sx1, sy1, sx2 - sx1, sy2 - sy1);
g.DrawImage(((NetBufferedImage)img).bitmap, destRect, srcRect, GraphicsUnit.Pixel);
}
else
{
throw new NotImplementedException();
}
2003-07-21 16:12:40 +04:00
return true;
}
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)
{
return true;
}
public override bool drawImage(java.awt.Image param1, int param2, int param3, java.awt.Color param4, java.awt.image.ImageObserver param5)
{
return true;
}
public override bool drawImage(java.awt.Image param1, int param2, int param3, int param4, int param5, java.awt.image.ImageObserver param6)
{
return true;
}
2003-07-23 16:50:11 +04:00
public override bool drawImage(java.awt.Image img, int x, int y, java.awt.image.ImageObserver observer)
2003-07-21 16:12:40 +04:00
{
2003-07-23 16:50:11 +04:00
if(img is NetBufferedImage)
{
g.DrawImage(((NetBufferedImage)img).bitmap, x, y);
}
2004-09-27 14:17:34 +04:00
else if(img is NetProducerImage)
{
Console.WriteLine("TODO: Draw NetProducerImage");
}
2003-07-23 16:50:11 +04:00
else
{
throw new NotImplementedException();
}
2003-07-21 16:12:40 +04:00
return true;
}
public override void drawLine(int x1, int y1, int x2, int y2)
{
2003-07-25 01:01:48 +04:00
using(Pen p = new Pen(color, 1))
2003-07-21 16:12:40 +04:00
{
2003-07-25 01:01:48 +04:00
// HACK DrawLine doesn't appear to draw the last pixel, so for single pixel lines, we have
// a freaky workaround
2003-07-23 16:50:11 +04:00
if(x1 == x2 && y1 == y2)
{
2003-07-25 01:01:48 +04:00
g.DrawLine(p, x1, y1, x1 + 0.01f, y2 + 0.01f);
}
else
{
g.DrawLine(p, x1, y1, x2, y2);
2003-07-23 16:50:11 +04:00
}
2003-07-21 16:12:40 +04:00
}
}
public override void drawOval(int param1, int param2, int param3, int param4)
{
}
public override void drawPolygon(java.awt.Polygon param)
{
}
public override void drawPolygon(int[] param1, int[] param2, int param3)
{
}
public override void drawPolyline(int[] param1, int[] param2, int param3)
{
}
public override void drawRect(int x, int y, int width, int height)
{
using(Pen pen = new Pen(color))
{
g.DrawRectangle(pen, x, y, width, height);
}
}
public override void drawRoundRect(int param1, int param2, int param3, int param4, int param5, int param6)
{
}
public override void drawString(java.text.AttributedCharacterIterator param1, int param2, int param3)
{
}
public override void drawString(string str, int x, int y)
{
using(Brush brush = new SolidBrush(color))
{
int descent = netfont.FontFamily.GetCellDescent(netfont.Style);
int descentPixel = (int)Math.Round(netfont.Size * descent / netfont.FontFamily.GetEmHeight(netfont.Style));
g.DrawString(str, netfont, brush, x, y - netfont.Height + descentPixel);
}
}
public override void fill3DRect(int param1, int param2, int param3, int param4, bool param5)
{
}
public override void fillArc(int param1, int param2, int param3, int param4, int param5, int param6)
{
}
public override void fillOval(int param1, int param2, int param3, int param4)
{
}
public override void fillPolygon(java.awt.Polygon param)
{
}
public override void fillPolygon(int[] param1, int[] param2, int param3)
{
}
public override void fillRect(int x, int y, int width, int height)
{
using(Brush brush = new SolidBrush(color))
{
g.FillRectangle(brush, x, y, width, height);
}
}
public override void fillRoundRect(int param1, int param2, int param3, int param4, int param5, int param6)
{
}
public override java.awt.Shape getClip()
{
return getClipBounds();
}
public override java.awt.Rectangle getClipBounds(java.awt.Rectangle r)
{
if(_clip != null)
{
r.x = _clip.x;
r.y = _clip.y;
r.width = _clip.width;
r.height = _clip.height;
}
return r;
}
public override java.awt.Rectangle getClipBounds()
{
return getClipRect();
}
2004-11-04 15:50:28 +03:00
[Obsolete]
2003-07-21 16:12:40 +04:00
public override java.awt.Rectangle getClipRect()
{
if(_clip != null)
{
return (java.awt.Rectangle)_clip.clone();
}
return null;
}
public override java.awt.Color getColor()
{
if(jcolor == null)
{
jcolor = new java.awt.Color(color.ToArgb());
}
return jcolor;
}
public override java.awt.Font getFont()
{
return font;
}
internal static Font NetFontFromJavaFont(java.awt.Font f, float dpi)
{
FontFamily fam;
switch(f.getName())
{
case "Monospaced":
case "Courier":
2003-08-10 13:31:06 +04:00
case "courier":
2003-07-21 16:12:40 +04:00
fam = FontFamily.GenericMonospace;
break;
case "Serif":
fam = FontFamily.GenericSerif;
break;
case "SansSerif":
case "Dialog":
case "DialogInput":
case null:
case "Default":
fam = FontFamily.GenericSansSerif;
break;
default:
2003-08-12 17:09:31 +04:00
try
{
fam = new FontFamily(f.getName());
}
catch(ArgumentException)
{
fam = FontFamily.GenericSansSerif;
}
2003-07-21 16:12:40 +04:00
break;
}
// NOTE Regular is guaranteed zero
FontStyle style = FontStyle.Regular;
if(f.isBold())
{
style |= FontStyle.Bold;
}
if(f.isItalic())
{
style |= FontStyle.Italic;
}
float em = fam.GetEmHeight(style);
float line = fam.GetLineSpacing(style);
return new Font(fam, (int)Math.Round(((f.getSize() * dpi) / 72) * em / line), style, GraphicsUnit.Pixel);
}
public override java.awt.FontMetrics getFontMetrics(java.awt.Font f)
{
return new NetFontMetrics(f, NetFontFromJavaFont(f, g.DpiY), g, null);
}
public override java.awt.FontMetrics getFontMetrics()
{
return new NetFontMetrics(font, netfont, g, null);
}
public override bool hitClip(int param1, int param2, int param3, int param4)
{
return true;
}
public override void setClip(int x, int y, int width, int height)
{
_clip = new java.awt.Rectangle(x, y, width, height);
g.Clip = new Region(new Rectangle(x, y, width, height));
}
public override void setClip(java.awt.Shape param)
{
// NOTE we only support rectangular clipping for the moment
java.awt.Rectangle r = param.getBounds();
setClip(r.x, r.y, r.width, r.height);
}
public override void setColor(java.awt.Color color)
{
2004-09-27 14:17:34 +04:00
if(color == null)
{
// TODO is this the correct default color?
color = java.awt.SystemColor.controlText;
}
2003-07-21 16:12:40 +04:00
this.jcolor = color;
this.color = Color.FromArgb(color.getRGB());
}
public override void setFont(java.awt.Font f)
{
Font newfont = NetFontFromJavaFont(f, g.DpiY);
netfont.Dispose();
netfont = newfont;
font = f;
}
public override void setPaintMode()
{
}
public override void setXORMode(java.awt.Color param)
{
}
public override void translate(int x, int y)
{
System.Drawing.Drawing2D.Matrix matrix = g.Transform;
matrix.Translate(x, y);
g.Transform = matrix;
}
public override void draw(java.awt.Shape shape)
{
}
public override bool drawImage(java.awt.Image image, java.awt.geom.AffineTransform xform, ImageObserver obs)
{
return false;
}
public override void drawImage(java.awt.image.BufferedImage image, BufferedImageOp op, int x, int y)
{
}
public override void drawRenderedImage(java.awt.image.RenderedImage image, java.awt.geom.AffineTransform xform)
{
}
public override void drawRenderableImage(java.awt.image.renderable.RenderableImage image, java.awt.geom.AffineTransform xform)
{
}
public override void drawString(string text, float x, float y)
{
}
public override void drawString(java.text.AttributedCharacterIterator iterator, float x, float y)
{
}
public override void fill(java.awt.Shape shape)
{
}
public override bool hit(java.awt.Rectangle rect, java.awt.Shape text, bool onStroke)
{
return false;
}
public override java.awt.GraphicsConfiguration getDeviceConfiguration()
{
return null;
}
public override void setComposite(java.awt.Composite comp)
{
}
public override void setPaint(java.awt.Paint paint)
{
}
public override void setStroke(java.awt.Stroke stroke)
{
}
public override void setRenderingHint(java.awt.RenderingHints.Key hintKey, Object hintValue)
{
}
public override object getRenderingHint(java.awt.RenderingHints.Key hintKey)
{
return null;
}
public override void setRenderingHints(java.util.Map hints)
{
}
public override void addRenderingHints(java.util.Map hints)
{
}
public override java.awt.RenderingHints getRenderingHints()
{
return null;
}
public override void translate(double tx, double ty)
{
}
public override void rotate(double theta)
{
}
public override void rotate(double theta, double x, double y)
{
}
public override void scale(double scaleX, double scaleY)
{
}
public override void shear(double shearX, double shearY)
{
}
public override void transform(java.awt.geom.AffineTransform Tx)
{
}
public override void setTransform(java.awt.geom.AffineTransform Tx)
{
}
public override java.awt.geom.AffineTransform getTransform()
{
return null;
}
public override java.awt.Paint getPaint()
{
return null;
}
public override java.awt.Composite getComposite()
{
return null;
}
public override void setBackground(java.awt.Color color)
{
}
public override java.awt.Color getBackground()
{
return null;
}
public override java.awt.Stroke getStroke()
{
return null;
2002-12-18 19:00:25 +03:00
}
2003-07-21 16:12:40 +04:00
public override void clip(java.awt.Shape s)
2002-12-18 19:00:25 +03:00
{
}
2003-07-21 16:12:40 +04:00
public override java.awt.font.FontRenderContext getFontRenderContext()
2002-12-18 19:00:25 +03:00
{
2003-07-21 16:12:40 +04:00
return null;
2002-12-18 19:00:25 +03:00
}
2003-07-21 16:12:40 +04:00
public override void drawGlyphVector(java.awt.font.GlyphVector g, float x, float y)
2002-12-18 19:00:25 +03:00
{
}
2003-07-21 16:12:40 +04:00
}
class NetFontMetrics : java.awt.FontMetrics
{
private Font netFont;
private Graphics g;
private Control c;
public NetFontMetrics(java.awt.Font f, Font netFont, Graphics g, Control c) : base(f)
2002-12-18 19:00:25 +03:00
{
2003-07-21 16:12:40 +04:00
this.netFont = netFont;
this.g = g;
this.c = c;
2002-12-18 19:00:25 +03:00
}
2003-07-21 16:12:40 +04:00
public override int getHeight()
2002-12-18 19:00:25 +03:00
{
2003-07-21 16:12:40 +04:00
return netFont.Height;
2002-12-18 19:00:25 +03:00
}
2003-07-21 16:12:40 +04:00
public override int getLeading()
2002-12-18 19:00:25 +03:00
{
2003-07-21 16:12:40 +04:00
// HACK we always return 1
return 1;
2002-12-18 19:00:25 +03:00
}
2003-07-21 16:12:40 +04:00
public override int getMaxAdvance()
2002-12-18 19:00:25 +03:00
{
2003-07-21 16:12:40 +04:00
// HACK very lame
return charWidth('M');
2002-12-18 19:00:25 +03:00
}
2003-07-21 16:12:40 +04:00
public override int charWidth(char ch)
2002-12-18 19:00:25 +03:00
{
2003-07-21 16:12:40 +04:00
// HACK we average 20 characters to decrease the influence of the pre/post spacing
return stringWidth(new String(ch, 20)) / 20;
2002-12-18 19:00:25 +03:00
}
2003-07-21 16:12:40 +04:00
public override int charsWidth(char[] data, int off, int len)
2002-12-18 19:00:25 +03:00
{
2003-07-21 16:12:40 +04:00
return stringWidth(new String(data, off, len));
2002-12-18 19:00:25 +03:00
}
2003-07-21 16:12:40 +04:00
public override int getAscent()
2002-12-18 19:00:25 +03:00
{
2003-07-21 16:12:40 +04:00
int ascent = netFont.FontFamily.GetCellAscent(netFont.Style);
return (int)Math.Round(netFont.Size * ascent / netFont.FontFamily.GetEmHeight(netFont.Style));
2002-12-18 19:00:25 +03:00
}
2003-07-21 16:12:40 +04:00
public override int getDescent()
2002-12-18 19:00:25 +03:00
{
2003-07-21 16:12:40 +04:00
int descent = netFont.FontFamily.GetCellDescent(netFont.Style);
return (int)Math.Round(netFont.Size * descent / netFont.FontFamily.GetEmHeight(netFont.Style));
2002-12-18 19:00:25 +03:00
}
2003-07-21 16:12:40 +04:00
public override int stringWidth(string s)
2002-12-18 19:00:25 +03:00
{
2003-07-21 16:12:40 +04:00
if(g != null)
{
try
{
return (int)Math.Round(g.MeasureString(s, netFont).Width);
}
catch(ObjectDisposedException)
{
g = null;
}
}
if(c != null)
{
using(Graphics g1 = c.CreateGraphics())
{
return (int)Math.Round(g1.MeasureString(s, netFont).Width);
}
}
// as a last resort, we make a lame guess
return s.Length * getHeight() / 2;
2002-12-18 19:00:25 +03:00
}
}
class NetComponentPeer : ComponentPeer
{
internal readonly java.awt.Component component;
internal readonly Control control;
2003-07-21 16:12:40 +04:00
private int offsetX;
private int offsetY;
2005-05-25 17:44:08 +04:00
private Point mouseDown;
private long lastClick;
private int clickCount;
2002-12-18 19:00:25 +03:00
public NetComponentPeer(java.awt.Component component, Control control)
{
this.control = control;
this.component = component;
2005-05-25 17:44:08 +04:00
control.TabStop = false;
2002-12-18 19:00:25 +03:00
java.awt.Container parent = component.getParent();
2003-07-23 16:50:11 +04:00
if(parent != null && !(this is java.awt.peer.LightweightPeer))
2002-12-18 19:00:25 +03:00
{
2004-03-26 13:19:21 +03:00
if(control is Form)
{
((Form)control).Owner = (Form)((NetComponentPeer)parent.getPeer()).control;
}
else
{
control.Parent = ((NetComponentPeer)parent.getPeer()).control;
}
2003-07-21 16:12:40 +04:00
if(parent is java.awt.Frame)
{
java.awt.Insets ins = ((NetFramePeer)parent.getPeer()).getInsets();
offsetX = -ins.left;
offsetY = -ins.top;
}
}
if(component.isFontSet())
{
setFont(component.getFont());
}
// we need the null check, because for a Window, at this time it doesn't have a foreground yet
if(component.getForeground() != null)
{
setForeground(component.getForeground());
}
// we need the null check, because for a Window, at this time it doesn't have a background yet
if(component.getBackground() != null)
{
setBackground(component.getBackground());
2002-12-18 19:00:25 +03:00
}
setEnabled(component.isEnabled());
//setBounds(component.getX(), component.getY(), component.getWidth(), component.getHeight());
control.Invoke(new SetVoid(Setup));
2003-07-21 16:12:40 +04:00
control.Paint += new PaintEventHandler(OnPaint);
component.invalidate();
}
private void OnPaint(object sender, PaintEventArgs e)
{
// TODO figure out if we need an update or a paint
java.awt.Rectangle rect = new java.awt.Rectangle(e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width, e.ClipRectangle.Height);
//postEvent(new java.awt.@event.PaintEvent(component, java.awt.@event.PaintEvent.UPDATE, rect));
postEvent(new java.awt.@event.PaintEvent(component, java.awt.@event.PaintEvent.PAINT, rect));
2002-12-18 19:00:25 +03:00
}
private void Setup()
{
// TODO we really only should hook these events when they are needed...
control.KeyDown += new KeyEventHandler(OnKeyDown);
control.KeyUp += new KeyEventHandler(OnKeyUp);
control.KeyPress += new KeyPressEventHandler(OnKeyPress);
2003-07-25 01:01:48 +04:00
control.MouseMove += new MouseEventHandler(OnMouseMove);
control.MouseDown += new MouseEventHandler(OnMouseDown);
control.MouseUp += new MouseEventHandler(OnMouseUp);
2005-05-25 17:44:08 +04:00
control.MouseEnter += new EventHandler(OnMouseEnter);
control.MouseLeave += new EventHandler(OnMouseLeave);
control.GotFocus += new EventHandler(OnGotFocus);
control.LostFocus += new EventHandler(OnLostFocus);
2002-12-18 19:00:25 +03:00
}
private static int MapKeyCode(Keys key)
{
switch(key)
{
default:
return (int)key;
}
}
2005-05-25 17:44:08 +04:00
private static int GetModifiers(Keys keys)
2002-12-18 19:00:25 +03:00
{
int modifiers = 0;
2005-05-25 17:44:08 +04:00
if((keys & Keys.Shift) != 0)
{
modifiers |= java.awt.@event.KeyEvent.SHIFT_DOWN_MASK;
}
if((keys & Keys.Control) != 0)
{
modifiers |= java.awt.@event.KeyEvent.CTRL_DOWN_MASK;
}
if((keys & Keys.Alt) != 0)
{
modifiers |= java.awt.@event.KeyEvent.ALT_DOWN_MASK;
}
if((Control.MouseButtons & MouseButtons.Left) != 0)
{
modifiers |= java.awt.@event.KeyEvent.BUTTON1_DOWN_MASK;
}
if((Control.MouseButtons & MouseButtons.Middle) != 0)
{
modifiers |= java.awt.@event.KeyEvent.BUTTON2_DOWN_MASK;
}
if((Control.MouseButtons & MouseButtons.Right) != 0)
{
modifiers |= java.awt.@event.KeyEvent.BUTTON3_DOWN_MASK;
}
return modifiers;
}
protected virtual void OnKeyDown(object sender, KeyEventArgs e)
{
long when = java.lang.System.currentTimeMillis();
int modifiers = GetModifiers(e.Modifiers);
2002-12-18 19:00:25 +03:00
int keyCode = MapKeyCode(e.KeyCode);
2005-05-25 17:44:08 +04:00
// TODO set keyChar
2002-12-18 19:00:25 +03:00
char keyChar = ' ';
2005-05-25 17:44:08 +04:00
int keyLocation = java.awt.@event.KeyEvent.KEY_LOCATION_STANDARD;
2002-12-18 19:00:25 +03:00
postEvent(new java.awt.@event.KeyEvent(component, java.awt.@event.KeyEvent.KEY_PRESSED, when, modifiers, keyCode, keyChar, keyLocation));
}
protected virtual void OnKeyUp(object sender, KeyEventArgs e)
{
2005-05-25 17:44:08 +04:00
long when = java.lang.System.currentTimeMillis();
int modifiers = GetModifiers(e.Modifiers);
2002-12-18 19:00:25 +03:00
int keyCode = MapKeyCode(e.KeyCode);
2005-05-25 17:44:08 +04:00
// TODO set keyChar
2002-12-18 19:00:25 +03:00
char keyChar = ' ';
2005-05-25 17:44:08 +04:00
int keyLocation = java.awt.@event.KeyEvent.KEY_LOCATION_STANDARD;
2002-12-18 19:00:25 +03:00
postEvent(new java.awt.@event.KeyEvent(component, java.awt.@event.KeyEvent.KEY_RELEASED, when, modifiers, keyCode, keyChar, keyLocation));
}
protected virtual void OnKeyPress(object sender, KeyPressEventArgs e)
{
2005-05-25 17:44:08 +04:00
long when = java.lang.System.currentTimeMillis();
int modifiers = GetModifiers(Control.ModifierKeys);
int keyCode = java.awt.@event.KeyEvent.VK_UNDEFINED;
2002-12-18 19:00:25 +03:00
char keyChar = e.KeyChar;
2005-05-25 17:44:08 +04:00
int keyLocation = java.awt.@event.KeyEvent.KEY_LOCATION_STANDARD;
2002-12-18 19:00:25 +03:00
postEvent(new java.awt.@event.KeyEvent(component, java.awt.@event.KeyEvent.KEY_TYPED, when, modifiers, keyCode, keyChar, keyLocation));
}
2003-07-25 01:01:48 +04:00
protected virtual void OnMouseMove(object sender, MouseEventArgs e)
{
2005-05-25 17:44:08 +04:00
long when = java.lang.System.currentTimeMillis();
int modifiers = GetModifiers(Control.ModifierKeys);
if((e.Button & (MouseButtons.Left | MouseButtons.Right)) != 0)
{
postEvent(new java.awt.@event.MouseEvent(component, java.awt.@event.MouseEvent.MOUSE_DRAGGED, when, modifiers, e.X, e.Y, 0, false));
}
else
{
postEvent(new java.awt.@event.MouseEvent(component, java.awt.@event.MouseEvent.MOUSE_MOVED, when, modifiers, e.X, e.Y, 0, false));
}
}
private static int GetButton(MouseEventArgs e)
{
if((e.Button & MouseButtons.Left) != 0)
{
return java.awt.@event.MouseEvent.BUTTON1;
}
else if((e.Button & MouseButtons.Middle) != 0)
{
return java.awt.@event.MouseEvent.BUTTON2;
}
else if((e.Button & MouseButtons.Right) != 0)
{
return java.awt.@event.MouseEvent.BUTTON3;
}
else
{
return java.awt.@event.MouseEvent.NOBUTTON;
}
}
private static bool IsWithinDoubleClickRectangle(Point p, int x, int y)
{
return Math.Abs(x - p.X) <= SystemInformation.DoubleClickSize.Width / 2 &&
Math.Abs(y - p.Y) <= SystemInformation.DoubleClickSize.Height / 2;
2003-07-25 01:01:48 +04:00
}
protected virtual void OnMouseDown(object sender, MouseEventArgs e)
{
2005-05-25 17:44:08 +04:00
long when = java.lang.System.currentTimeMillis();
if(when > lastClick + SystemInformation.DoubleClickTime
|| !IsWithinDoubleClickRectangle(mouseDown, e.X, e.Y))
{
clickCount = 0;
}
clickCount++;
lastClick = when;
mouseDown = new Point(e.X, e.Y);
int modifiers = GetModifiers(Control.ModifierKeys);
int button = GetButton(e);
postEvent(new java.awt.@event.MouseEvent(component, java.awt.@event.MouseEvent.MOUSE_PRESSED, when, modifiers, e.X, e.Y, clickCount, false, button));
2003-07-25 01:01:48 +04:00
}
protected virtual void OnMouseUp(object sender, MouseEventArgs e)
{
2005-05-25 17:44:08 +04:00
long when = java.lang.System.currentTimeMillis();
int modifiers = GetModifiers(Control.ModifierKeys);
int button = GetButton(e);
postEvent(new java.awt.@event.MouseEvent(component, java.awt.@event.MouseEvent.MOUSE_RELEASED, when, modifiers, e.X, e.Y, clickCount, (e.Button & MouseButtons.Right) != 0, button));
if(mouseDown.X == e.X && mouseDown.Y == e.Y)
{
postEvent(new java.awt.@event.MouseEvent(component, java.awt.@event.MouseEvent.MOUSE_CLICKED, when, modifiers, e.X, e.Y, clickCount, false, button));
}
}
private void OnMouseEnter(object sender, EventArgs e)
{
long when = java.lang.System.currentTimeMillis();
int modifiers = GetModifiers(Control.ModifierKeys);
int x = Control.MousePosition.X;
int y = Control.MousePosition.Y;
postEvent(new java.awt.@event.MouseEvent(component, java.awt.@event.MouseEvent.MOUSE_ENTERED, when, modifiers, x, y, 0, false));
}
private void OnMouseLeave(object sender, EventArgs e)
{
long when = java.lang.System.currentTimeMillis();
int modifiers = GetModifiers(Control.ModifierKeys);
int x = Control.MousePosition.X;
int y = Control.MousePosition.Y;
postEvent(new java.awt.@event.MouseEvent(component, java.awt.@event.MouseEvent.MOUSE_EXITED, when, modifiers, x, y, 0, false));
}
private void OnGotFocus(object sender, EventArgs e)
{
postEvent(new java.awt.@event.FocusEvent(component, java.awt.@event.FocusEvent.FOCUS_GAINED));
}
private void OnLostFocus(object sender, EventArgs e)
{
postEvent(new java.awt.@event.FocusEvent(component, java.awt.@event.FocusEvent.FOCUS_LOST));
2003-07-25 01:01:48 +04:00
}
2002-12-18 19:00:25 +03:00
protected void postEvent(java.awt.AWTEvent evt)
{
2005-02-02 18:11:26 +03:00
NetToolkit.nativeQueue.Add(evt);
//getToolkit().getSystemEventQueue().postEvent(evt);
2002-12-18 19:00:25 +03:00
}
public int checkImage(java.awt.Image img, int width, int height, java.awt.image.ImageObserver ob)
{
2003-07-23 16:50:11 +04:00
return getToolkit().checkImage(img, width, height, ob);
2002-12-18 19:00:25 +03:00
}
2003-07-21 16:12:40 +04:00
2002-12-18 19:00:25 +03:00
public java.awt.Image createImage(java.awt.image.ImageProducer prod)
{
throw new NotImplementedException();
}
2003-07-21 16:12:40 +04:00
2002-12-18 19:00:25 +03:00
public java.awt.Image createImage(int width, int height)
{
2004-03-16 20:10:09 +03:00
return new NetBufferedImage(width, height);
2002-12-18 19:00:25 +03:00
}
2003-07-21 16:12:40 +04:00
2002-12-18 19:00:25 +03:00
public void disable()
{
throw new NotImplementedException();
}
2003-07-21 16:12:40 +04:00
2002-12-18 19:00:25 +03:00
public void dispose()
{
2004-03-16 20:10:09 +03:00
control.Invoke(new SetVoid(disposeImpl));
}
private void disposeImpl()
{
// HACK we should dispose the control here, but that hangs in an infinite loop...
control.Hide();
2002-12-18 19:00:25 +03:00
}
2003-07-21 16:12:40 +04:00
2002-12-18 19:00:25 +03:00
public void enable()
{
throw new NotImplementedException();
}
2003-07-21 16:12:40 +04:00
2002-12-18 19:00:25 +03:00
public ColorModel getColorModel()
{
throw new NotImplementedException();
}
2003-07-21 16:12:40 +04:00
2002-12-18 19:00:25 +03:00
public java.awt.FontMetrics getFontMetrics(java.awt.Font f)
{
2003-07-21 16:12:40 +04:00
// HACK this is a very heavy weight way to determine DPI, it should be possible
// to do this without creating a Graphics object
using(Graphics g = control.CreateGraphics())
{
return new NetFontMetrics(f, NetGraphics.NetFontFromJavaFont(f, g.DpiY), null, control);
}
2002-12-18 19:00:25 +03:00
}
2003-07-21 16:12:40 +04:00
public virtual java.awt.Graphics getGraphics()
2002-12-18 19:00:25 +03:00
{
2003-07-25 01:01:48 +04:00
return new NetGraphics(control.CreateGraphics(), component.getFont(), control.BackColor, true);
2002-12-18 19:00:25 +03:00
}
2003-07-21 16:12:40 +04:00
2002-12-18 19:00:25 +03:00
public java.awt.Point getLocationOnScreen()
{
throw new NotImplementedException();
}
2003-07-21 16:12:40 +04:00
2002-12-18 19:00:25 +03:00
public java.awt.Dimension getMinimumSize()
{
2003-07-21 16:12:40 +04:00
return minimumSize();
2002-12-18 19:00:25 +03:00
}
public virtual java.awt.Dimension getPreferredSize()
{
2003-07-21 16:12:40 +04:00
return preferredSize();
2002-12-18 19:00:25 +03:00
}
public java.awt.Toolkit getToolkit()
{
return java.awt.Toolkit.getDefaultToolkit();
}
public void handleEvent(java.awt.AWTEvent e)
{
2003-07-21 16:12:40 +04:00
if(e is java.awt.@event.PaintEvent)
{
java.awt.Graphics g = component.getGraphics();
try
{
2005-05-25 17:44:08 +04:00
switch(e.getID())
{
case java.awt.@event.PaintEvent.UPDATE:
component.update(g);
break;
case java.awt.@event.PaintEvent.PAINT:
component.paint(g);
break;
default:
Console.WriteLine("Unknown PaintEvent: {0}", e.getID());
break;
}
2003-07-21 16:12:40 +04:00
}
finally
{
g.dispose();
}
}
2002-12-18 19:00:25 +03:00
}
2003-07-21 16:12:40 +04:00
2002-12-18 19:00:25 +03:00
public void hide()
{
throw new NotImplementedException();
}
2003-07-21 16:12:40 +04:00
2002-12-18 19:00:25 +03:00
public bool isFocusTraversable()
{
throw new NotImplementedException();
}
2003-07-21 16:12:40 +04:00
2002-12-18 19:00:25 +03:00
public java.awt.Dimension minimumSize()
{
2003-07-21 16:12:40 +04:00
return component.getSize();
2002-12-18 19:00:25 +03:00
}
public java.awt.Dimension preferredSize()
{
2003-07-21 16:12:40 +04:00
return minimumSize();
2002-12-18 19:00:25 +03:00
}
public void paint(java.awt.Graphics graphics)
{
2004-03-16 20:10:09 +03:00
//throw new NotImplementedException();
2002-12-18 19:00:25 +03:00
}
2003-07-21 16:12:40 +04:00
2002-12-18 19:00:25 +03:00
public bool prepareImage(java.awt.Image img, int width, int height, ImageObserver ob)
{
2003-07-23 16:50:11 +04:00
return getToolkit().prepareImage(img, width, height, ob);
2002-12-18 19:00:25 +03:00
}
2003-07-21 16:12:40 +04:00
2002-12-18 19:00:25 +03:00
public void print(java.awt.Graphics graphics)
{
throw new NotImplementedException();
}
2003-07-21 16:12:40 +04:00
2002-12-18 19:00:25 +03:00
public void repaint(long tm, int x, int y, int width, int height)
{
2003-07-21 16:12:40 +04:00
// TODO do something with the tm parameter
Rectangle rect = new Rectangle(x, y, width, height);
rect.Offset(offsetX, offsetY);
control.Invoke(new SetRectangle(control.Invalidate), new object[] { rect });
2002-12-18 19:00:25 +03:00
}
2003-07-21 16:12:40 +04:00
2002-12-18 19:00:25 +03:00
public void requestFocus()
{
2003-07-21 16:12:40 +04:00
control.Invoke(new SetVoid(requestFocusImpl), null);
2002-12-18 19:00:25 +03:00
}
2003-07-21 16:12:40 +04:00
private void requestFocusImpl()
{
control.Focus();
}
2003-03-17 17:02:46 +03:00
public bool requestFocus(java.awt.Component source, bool bool1, bool bool2, long x)
{
throw new NotImplementedException();
}
2003-07-21 16:12:40 +04:00
2002-12-18 19:00:25 +03:00
public void reshape(int x, int y, int width, int height)
{
throw new NotImplementedException();
}
2003-07-21 16:12:40 +04:00
2002-12-18 19:00:25 +03:00
public void setBackground(java.awt.Color color)
{
2003-07-21 16:12:40 +04:00
control.Invoke(new SetColor(SetBackColorImpl), new object[] { Color.FromArgb(color.getRGB()) });
}
private void SetBackColorImpl(Color c)
{
control.BackColor = c;
2002-12-18 19:00:25 +03:00
}
private void setBoundsImpl(int x, int y, int width, int height)
{
control.SetBounds(x, y, width, height);
}
public void setBounds(int x, int y, int width, int height)
{
2003-07-21 16:12:40 +04:00
control.Invoke(new SetXYWH(setBoundsImpl), new object[] { x + offsetX, y + offsetY, width, height });
2002-12-18 19:00:25 +03:00
}
public void setCursor(java.awt.Cursor cursor)
{
2003-07-21 16:12:40 +04:00
switch(cursor.getType())
{
case java.awt.Cursor.WAIT_CURSOR:
control.Cursor = Cursors.WaitCursor;
break;
case java.awt.Cursor.DEFAULT_CURSOR:
control.Cursor = Cursors.Default;
break;
2005-05-25 17:44:08 +04:00
case java.awt.Cursor.HAND_CURSOR:
control.Cursor = Cursors.Hand;
break;
case java.awt.Cursor.CROSSHAIR_CURSOR:
control.Cursor = Cursors.Cross;
break;
case java.awt.Cursor.E_RESIZE_CURSOR:
control.Cursor = Cursors.SizeWE;
break;
case java.awt.Cursor.MOVE_CURSOR:
control.Cursor = Cursors.SizeAll;
break;
case java.awt.Cursor.N_RESIZE_CURSOR:
case java.awt.Cursor.S_RESIZE_CURSOR:
control.Cursor = Cursors.SizeNS;
break;
case java.awt.Cursor.NE_RESIZE_CURSOR:
case java.awt.Cursor.SW_RESIZE_CURSOR:
control.Cursor = Cursors.SizeNESW;
break;
case java.awt.Cursor.NW_RESIZE_CURSOR:
case java.awt.Cursor.SE_RESIZE_CURSOR:
control.Cursor = Cursors.SizeNWSE;
break;
case java.awt.Cursor.TEXT_CURSOR:
control.Cursor = Cursors.IBeam;
break;
2003-07-21 16:12:40 +04:00
default:
Console.WriteLine("setCursor not implement for: " + cursor);
break;
}
2002-12-18 19:00:25 +03:00
}
private void setEnabledImpl(bool enabled)
{
control.Enabled = enabled;
}
public void setEnabled(bool enabled)
{
control.Invoke(new SetBool(setEnabledImpl), new object[] { enabled });
}
public void setFont(java.awt.Font font)
{
2003-07-21 16:12:40 +04:00
// TODO use control.Invoke
control.Font = NetGraphics.NetFontFromJavaFont(font, component.getToolkit().getScreenResolution());
2002-12-18 19:00:25 +03:00
}
2003-07-21 16:12:40 +04:00
2002-12-18 19:00:25 +03:00
public void setForeground(java.awt.Color color)
{
2003-07-21 16:12:40 +04:00
control.Invoke(new SetColor(SetForeColorImpl), new object[] { Color.FromArgb(color.getRGB()) });
}
private void SetForeColorImpl(Color c)
{
control.ForeColor = c;
2002-12-18 19:00:25 +03:00
}
private void setVisibleImpl(bool visible)
{
control.Visible = visible;
2003-07-23 16:50:11 +04:00
postEvent(new java.awt.@event.ComponentEvent(component,
visible ? java.awt.@event.ComponentEvent.COMPONENT_SHOWN : java.awt.@event.ComponentEvent.COMPONENT_HIDDEN));
2002-12-18 19:00:25 +03:00
}
public void setVisible(bool visible)
{
control.Invoke(new SetBool(setVisibleImpl), new object[] { visible });
}
public void show()
{
throw new NotImplementedException();
}
2003-07-21 16:12:40 +04:00
2002-12-18 19:00:25 +03:00
public java.awt.GraphicsConfiguration getGraphicsConfiguration()
{
2003-07-21 16:12:40 +04:00
return new NetGraphicsConfiguration();
2002-12-18 19:00:25 +03:00
}
public void setEventMask (long mask)
{
2005-05-25 17:44:08 +04:00
//Console.WriteLine("NOTE: NetComponentPeer.setEventMask not implemented");
2002-12-18 19:00:25 +03:00
}
2003-03-17 17:02:46 +03:00
public bool isObscured()
{
throw new NotImplementedException();
}
public bool canDetermineObscurity()
{
throw new NotImplementedException();
}
public void coalescePaintEvent(java.awt.@event.PaintEvent e)
{
throw new NotImplementedException();
}
public void updateCursorImmediately()
{
throw new NotImplementedException();
}
2004-09-27 14:17:34 +04:00
public java.awt.image.VolatileImage createVolatileImage(int width, int height)
2003-03-17 17:02:46 +03:00
{
throw new NotImplementedException();
}
public bool handlesWheelScrolling()
{
throw new NotImplementedException();
}
public void createBuffers(int x, java.awt.BufferCapabilities capabilities)
{
throw new NotImplementedException();
}
public java.awt.Image getBackBuffer()
{
throw new NotImplementedException();
}
public void flip(java.awt.BufferCapabilities.FlipContents contents)
{
throw new NotImplementedException();
}
public void destroyBuffers()
{
throw new NotImplementedException();
}
public bool isFocusable()
{
// TODO
return true;
}
2002-12-18 19:00:25 +03:00
}
2003-07-21 16:12:40 +04:00
// HACK Classpath should have a working BufferedImage, but currently it doesn't, until then, we
// provide a hacked up version
class NetBufferedImage : java.awt.image.BufferedImage
{
2003-07-23 16:50:11 +04:00
internal Bitmap bitmap;
2003-07-21 16:12:40 +04:00
internal NetBufferedImage(Bitmap bitmap)
: base(bitmap.Width, bitmap.Height, java.awt.image.BufferedImage.TYPE_INT_RGB)
{
this.bitmap = bitmap;
}
internal NetBufferedImage(int width, int height)
: base(width, height, java.awt.image.BufferedImage.TYPE_INT_RGB)
{
bitmap = new Bitmap(width, height);
using(Graphics g = Graphics.FromImage(bitmap))
{
g.Clear(Color.White);
}
}
public override java.awt.Graphics2D createGraphics()
{
Graphics g = Graphics.FromImage(bitmap);
// HACK for off-screen images we don't want ClearType or anti-aliasing
// TODO I'm sure Java 2D has a way to control text rendering quality, we should honor that
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
2003-07-25 01:01:48 +04:00
return new NetGraphics(g, null, Color.White, true);
2003-07-21 16:12:40 +04:00
}
public override java.awt.image.ImageProducer getSource()
{
int[] pix = new int[bitmap.Width * bitmap.Height];
for(int y = 0; y < bitmap.Height; y++)
{
for(int x = 0; x < bitmap.Width; x++)
{
pix[x + y * bitmap.Width] = bitmap.GetPixel(x, y).ToArgb();
}
}
return new java.awt.image.MemoryImageSource(bitmap.Width, bitmap.Height, pix, 0, bitmap.Width);
}
}
2004-09-27 14:17:34 +04:00
class NetProducerImage : java.awt.Image, java.awt.image.ImageConsumer
{
private java.awt.image.ImageProducer source;
internal NetProducerImage(java.awt.image.ImageProducer source)
{
this.source = source;
}
public override void flush()
{
}
public override java.awt.Graphics getGraphics()
{
return null;
}
public override int getHeight(ImageObserver param)
{
return 0;
}
public override int getWidth(ImageObserver param)
{
return 0;
}
public override object getProperty(string param, ImageObserver obs)
{
return null;
}
public override ImageProducer getSource()
{
return null;
}
public void setHints(int hintflags)
{
Console.WriteLine("NetBufferedImage: setHints");
}
2005-02-02 18:11:26 +03:00
public void setPixels(int x, int y, int w, int h, ColorModel model, byte[] pixels, int off, int scansize)
2004-09-27 14:17:34 +04:00
{
Console.WriteLine("NetBufferedImage: setPixels1");
}
void java.awt.image.ImageConsumer.setPixels(int x, int y, int w, int h, ColorModel model, int[] pixels, int off, int scansize)
{
Console.WriteLine("NetBufferedImage: setPixels2");
}
public void setDimensions(int width, int height)
{
Console.WriteLine("NetBufferedImage: setDimensions");
}
public void imageComplete(int status)
{
Console.WriteLine("NetBufferedImage: imageComplete");
}
public void setColorModel(ColorModel model)
{
Console.WriteLine("NetBufferedImage: setColorModel");
}
public void setProperties(Hashtable props)
{
Console.WriteLine("NetBufferedImage: setProperties");
}
}
2003-07-21 16:12:40 +04:00
class NetGraphicsConfiguration : java.awt.GraphicsConfiguration
{
public override java.awt.image.BufferedImage createCompatibleImage(int param1, int param2, int param3)
{
throw new NotImplementedException();
}
public override java.awt.image.BufferedImage createCompatibleImage(int width, int height)
{
return new NetBufferedImage(width, height);
}
public override java.awt.image.VolatileImage createCompatibleVolatileImage(int param1, int param2, java.awt.ImageCapabilities param3)
{
throw new NotImplementedException();
}
public override java.awt.image.VolatileImage createCompatibleVolatileImage(int param1, int param2)
{
throw new NotImplementedException();
}
public override java.awt.Rectangle getBounds()
{
throw new NotImplementedException();
}
public override java.awt.BufferCapabilities getBufferCapabilities()
{
throw new NotImplementedException();
}
public override java.awt.image.ColorModel getColorModel(int param)
{
throw new NotImplementedException();
}
public override java.awt.image.ColorModel getColorModel()
{
throw new NotImplementedException();
}
public override java.awt.geom.AffineTransform getDefaultTransform()
{
throw new NotImplementedException();
}
public override java.awt.GraphicsDevice getDevice()
{
throw new NotImplementedException();
}
public override java.awt.ImageCapabilities getImageCapabilities()
{
throw new NotImplementedException();
}
public override java.awt.geom.AffineTransform getNormalizingTransform()
{
throw new NotImplementedException();
}
}
2002-12-18 19:00:25 +03:00
class NetButtonPeer : NetComponentPeer, ButtonPeer
{
public NetButtonPeer(java.awt.Button awtbutton, Button button)
: base(awtbutton, button)
{
2003-07-21 16:12:40 +04:00
if(!awtbutton.isBackgroundSet())
{
awtbutton.setBackground(java.awt.SystemColor.control);
}
button.BackColor = Color.FromArgb(awtbutton.getBackground().getRGB());
2002-12-18 19:00:25 +03:00
setLabel(awtbutton.getLabel());
control.Invoke(new SetVoid(Setup));
}
private void Setup()
{
((Button)control).Click += new EventHandler(OnClick);
}
private void OnClick(object sender, EventArgs e)
{
// TODO set all these properties correctly
string cmd = "";
long when = 0;
int modifiers = 0;
postEvent(new java.awt.@event.ActionEvent(component, java.awt.@event.ActionEvent.ACTION_PERFORMED, cmd, when, modifiers));
}
private void setLabelImpl(string label)
{
control.Text = label;
}
public void setLabel(string label)
{
control.Invoke(new SetString(setLabelImpl), new object[] { label });
}
public override java.awt.Dimension getPreferredSize()
{
2003-07-21 16:12:40 +04:00
using(Graphics g = control.CreateGraphics())
{
// TODO get these fudge factors from somewhere
return new java.awt.Dimension((int)Math.Round(12 + g.MeasureString(control.Text, control.Font).Width) * 8 / 7, 6 + control.Font.Height * 8 / 7);
}
2002-12-18 19:00:25 +03:00
}
}
class NetTextComponentPeer : NetComponentPeer, TextComponentPeer
{
public NetTextComponentPeer(java.awt.TextComponent textComponent, TextBox textBox)
: base(textComponent, textBox)
{
2003-07-21 16:12:40 +04:00
control.Invoke(new SetVoid(Setup));
}
private void Setup()
{
if(!component.isBackgroundSet())
{
component.setBackground(java.awt.SystemColor.window);
}
TextBox textBox = (TextBox)control;
setBackground(component.getBackground());
textBox.AutoSize = false;
textBox.Text = ((java.awt.TextComponent)component).getText();
2002-12-18 19:00:25 +03:00
}
protected override void OnKeyPress(object sender, KeyPressEventArgs e)
{
base.OnKeyPress(sender, e);
// TODO for TextAreas this probably isn't the right behaviour
if(e.KeyChar == '\r')
{
// TODO set all these properties correctly
string cmd = "";
long when = 0;
int modifiers = 0;
postEvent(new java.awt.@event.ActionEvent(component, java.awt.@event.ActionEvent.ACTION_PERFORMED, cmd, when, modifiers));
}
}
public int getSelectionEnd()
{
throw new NotImplementedException();
}
public int getSelectionStart()
{
throw new NotImplementedException();
}
private string getTextImpl()
{
return control.Text;
}
public string getText()
{
return (string)control.Invoke(new GetString(getTextImpl));
}
private void setTextImpl(string text)
{
control.Text = text;
}
public void setText(string text)
{
control.Invoke(new SetString(setTextImpl), new object[] { text });
}
public void select(int start_pos, int end_pos)
{
throw new NotImplementedException();
}
public void setEditable(bool editable)
{
throw new NotImplementedException();
}
public int getCaretPosition()
{
throw new NotImplementedException();
}
2004-09-27 14:17:34 +04:00
private void setCaretPositionImpl(int pos)
{
((TextBox)control).SelectionStart = pos;
((TextBox)control).SelectionLength = 0;
}
2002-12-18 19:00:25 +03:00
public void setCaretPosition(int pos)
{
2004-09-27 14:17:34 +04:00
control.Invoke(new SetInt(setCaretPositionImpl), new object[] { pos });
2002-12-18 19:00:25 +03:00
}
2003-03-17 17:02:46 +03:00
public long filterEvents(long filter)
{
throw new NotImplementedException();
}
public int getIndexAtPoint(int x, int y)
{
throw new NotImplementedException();
}
public java.awt.Rectangle getCharacterBounds(int pos)
{
throw new NotImplementedException();
}
2002-12-18 19:00:25 +03:00
}
2005-05-25 17:44:08 +04:00
class NetChoicePeer : NetComponentPeer, ChoicePeer
{
public NetChoicePeer(java.awt.Choice target, ComboBox combobox)
: base(target, combobox)
{
}
public void add(string str, int i)
{
// TODO: Add NetChoicePeer.add implementation
}
public void addItem(string str, int i)
{
// TODO: Add NetChoicePeer.addItem implementation
}
public void select(int i)
{
// TODO: Add NetChoicePeer.select implementation
}
public void removeAll()
{
// TODO: Add NetChoicePeer.removeAll implementation
}
public void remove(int i)
{
// TODO: Add NetChoicePeer.remove implementation
}
}
class NetCheckboxPeer : NetComponentPeer, CheckboxPeer
{
public NetCheckboxPeer(java.awt.Checkbox target, CheckBox checkbox)
: base(target, checkbox)
{
}
public void setCheckboxGroup(java.awt.CheckboxGroup cg)
{
// TODO: Add NetCheckboxPeer.setCheckboxGroup implementation
}
public void setState(bool b)
{
// TODO: Add NetCheckboxPeer.setState implementation
}
public void setLabel(string str)
{
// TODO: Add NetCheckboxPeer.setLabel implementation
}
}
2003-07-21 16:12:40 +04:00
class NetLabelPeer : NetComponentPeer, LabelPeer
{
public NetLabelPeer(java.awt.Label jlabel, Label label)
: base(jlabel, label)
{
label.Text = jlabel.getText();
setAlignment(jlabel.getAlignment());
}
public void setAlignment(int align)
{
switch(align)
{
case java.awt.Label.LEFT:
control.Invoke(new SetInt(setAlignImpl), new object[] { ContentAlignment.TopLeft });
break;
case java.awt.Label.CENTER:
control.Invoke(new SetInt(setAlignImpl), new object[] { ContentAlignment.TopCenter });
break;
case java.awt.Label.RIGHT:
control.Invoke(new SetInt(setAlignImpl), new object[] { ContentAlignment.TopRight });
break;
}
}
private void setAlignImpl(int align)
{
((Label)control).TextAlign = (ContentAlignment)align;
}
public void setText(string s)
{
control.Invoke(new SetString(setTextImpl), new Object[] { s });
}
private void setTextImpl(string s)
{
control.Text = s;
}
public override java.awt.Dimension getPreferredSize()
{
return (java.awt.Dimension)control.Invoke(new GetDimension(getPreferredSizeImpl), null);
}
private java.awt.Dimension getPreferredSizeImpl()
{
Label lab = (Label)control;
// HACK get these fudge factors from somewhere
return new java.awt.Dimension(lab.PreferredWidth, 2 + lab.PreferredHeight);
}
}
2002-12-18 19:00:25 +03:00
class NetTextFieldPeer : NetTextComponentPeer, TextFieldPeer
{
public NetTextFieldPeer(java.awt.TextField textField, TextBox textBox)
: base(textField, textBox)
{
2005-05-25 17:44:08 +04:00
setEchoCharacter(textField.getEchoChar());
2002-12-18 19:00:25 +03:00
}
public java.awt.Dimension minimumSize(int len)
{
throw new NotImplementedException();
}
2004-03-16 20:10:09 +03:00
2002-12-18 19:00:25 +03:00
public java.awt.Dimension preferredSize(int len)
{
throw new NotImplementedException();
}
2004-03-16 20:10:09 +03:00
2002-12-18 19:00:25 +03:00
public java.awt.Dimension getMinimumSize(int len)
{
2004-03-16 20:10:09 +03:00
return getPreferredSize(len);
2002-12-18 19:00:25 +03:00
}
public java.awt.Dimension getPreferredSize(int len)
{
// TODO use control.Invoke
2003-07-21 16:12:40 +04:00
using(Graphics g = control.CreateGraphics())
{
2003-07-23 16:50:11 +04:00
return new java.awt.Dimension((int)Math.Round((g.MeasureString("abcdefghijklm", control.Font).Width * len) / 13), ((TextBox)control).PreferredHeight);
2003-07-21 16:12:40 +04:00
}
2002-12-18 19:00:25 +03:00
}
public void setEchoChar(char echo_char)
{
2005-05-25 17:44:08 +04:00
setEchoCharacter(echo_char);
2002-12-18 19:00:25 +03:00
}
2004-03-16 20:10:09 +03:00
2002-12-18 19:00:25 +03:00
public void setEchoCharacter(char echo_char)
{
2005-05-25 17:44:08 +04:00
// TODO use control.Invoke
((TextBox)control).PasswordChar = echo_char;
2002-12-18 19:00:25 +03:00
}
}
class NetTextAreaPeer : NetTextComponentPeer, TextAreaPeer
{
public NetTextAreaPeer(java.awt.TextArea textArea, TextBox textBox)
: base(textArea, textBox)
{
control.Invoke(new SetVoid(Setup));
}
private void Setup()
{
2003-07-21 16:12:40 +04:00
TextBox textBox = (TextBox)control;
textBox.ReadOnly = !((java.awt.TextArea)component).isEditable();
textBox.WordWrap = false;
textBox.ScrollBars = ScrollBars.Both;
textBox.Multiline = true;
2002-12-18 19:00:25 +03:00
}
private void insertImpl(string text, int pos)
{
2003-07-21 16:12:40 +04:00
control.Text = control.Text.Insert(pos, text);
2002-12-18 19:00:25 +03:00
}
public void insert(string text, int pos)
{
control.Invoke(new SetStringInt(insertImpl), new Object[] { text, pos });
}
public void insertText(string text, int pos)
{
throw new NotImplementedException();
}
public java.awt.Dimension minimumSize(int rows, int cols)
{
2005-05-25 17:44:08 +04:00
return getMinimumSize(rows, cols);
2002-12-18 19:00:25 +03:00
}
public java.awt.Dimension getMinimumSize(int rows, int cols)
{
2005-05-25 17:44:08 +04:00
return new java.awt.Dimension(0, 0);
2002-12-18 19:00:25 +03:00
}
public java.awt.Dimension preferredSize(int rows, int cols)
{
throw new NotImplementedException();
}
public java.awt.Dimension getPreferredSize(int rows, int cols)
{
Console.WriteLine("NOTE: NetTextAreaPeer.getPreferredSize not implemented");
return new java.awt.Dimension(10 * cols, 15 * rows);
}
public void replaceRange(string text, int start_pos, int end_pos)
{
throw new NotImplementedException();
}
public void replaceText(string text, int start_pos, int end_pos)
{
throw new NotImplementedException();
}
}
class NetContainerPeer : NetComponentPeer, ContainerPeer
{
2005-05-25 17:44:08 +04:00
private java.awt.Insets _insets = new java.awt.Insets(0, 0, 0, 0);
2002-12-18 19:00:25 +03:00
public NetContainerPeer(java.awt.Container awtcontainer, ContainerControl container)
: base(awtcontainer, container)
{
}
public java.awt.Insets insets()
{
2005-05-25 17:44:08 +04:00
return getInsets();
2002-12-18 19:00:25 +03:00
}
public virtual java.awt.Insets getInsets()
{
2005-05-25 17:44:08 +04:00
return _insets;
2002-12-18 19:00:25 +03:00
}
public void beginValidate()
{
}
public void endValidate()
{
}
2003-03-17 17:02:46 +03:00
public void beginLayout()
{
throw new NotImplementedException();
}
public void endLayout()
{
throw new NotImplementedException();
}
public bool isPaintPending()
{
throw new NotImplementedException();
}
2002-12-18 19:00:25 +03:00
}
class NetPanelPeer : NetContainerPeer, PanelPeer
{
public NetPanelPeer(java.awt.Panel panel, ContainerControl container)
: base(panel, container)
{
}
}
2003-07-21 16:12:40 +04:00
class NewCanvasPeer : NetComponentPeer, CanvasPeer
{
public NewCanvasPeer(java.awt.Canvas canvas, Control control)
: base(canvas, control)
{
}
}
2002-12-18 19:00:25 +03:00
class NetWindowPeer : NetContainerPeer, WindowPeer
{
public NetWindowPeer(java.awt.Window window, Form form)
: base(window, form)
{
2003-07-21 16:12:40 +04:00
if(!window.isFontSet())
{
window.setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12));
}
if(!window.isForegroundSet())
{
window.setForeground(java.awt.SystemColor.windowText);
}
if(!window.isBackgroundSet())
{
window.setBackground(java.awt.SystemColor.window);
}
setFont(window.getFont());
setForeground(window.getForeground());
setBackground(window.getBackground());
form.SetBounds(window.getX(), window.getY(), window.getWidth(), window.getHeight());
2002-12-18 19:00:25 +03:00
}
public void toBack()
{
2003-07-21 16:12:40 +04:00
((Form)control).SendToBack();
2002-12-18 19:00:25 +03:00
}
public void toFront()
{
2003-07-21 16:12:40 +04:00
((Form)control).Activate();
2002-12-18 19:00:25 +03:00
}
}
class NetFramePeer : NetWindowPeer, FramePeer
{
public NetFramePeer(java.awt.Frame frame, Form form)
: base(frame, form)
{
setTitle(frame.getTitle());
control.Invoke(new SetVoid(Setup));
}
private void Setup()
{
Form form = (Form)control;
form.Resize += new EventHandler(Resize);
form.Closing += new CancelEventHandler(Closing);
}
private void Closing(object sender, CancelEventArgs e)
{
e.Cancel = true;
postEvent(new java.awt.@event.WindowEvent((java.awt.Window)component, java.awt.@event.WindowEvent.WINDOW_CLOSING));
}
private void Resize(object sender, EventArgs e)
{
// TODO I have no clue what I should do here...
Rectangle r = control.Bounds;
component.setBounds(r.X, r.Y, r.Width, r.Height);
component.invalidate();
component.validate();
postEvent(new java.awt.@event.ComponentEvent(component, java.awt.@event.ComponentEvent.COMPONENT_RESIZED));
}
2003-07-21 16:12:40 +04:00
public override java.awt.Graphics getGraphics()
{
2003-07-25 01:01:48 +04:00
NetGraphics g = new NetGraphics(control.CreateGraphics(), component.getFont(), control.BackColor, true);
2003-07-21 16:12:40 +04:00
java.awt.Insets insets = ((java.awt.Frame)component).getInsets();
g.translate(-insets.left, -insets.top);
g.setClip(insets.left, insets.top, control.ClientRectangle.Width, control.ClientRectangle.Height);
return g;
}
2002-12-18 19:00:25 +03:00
public void setIconImage(java.awt.Image image)
{
throw new NotImplementedException();
}
public void setMenuBar(java.awt.MenuBar mb)
{
throw new NotImplementedException();
}
public void setResizable(bool resizable)
{
throw new NotImplementedException();
}
private void setTitleImpl(string title)
{
control.Text = title;
}
public void setTitle(string title)
{
control.Invoke(new SetString(setTitleImpl), new object[] { title });
}
public override java.awt.Insets getInsets()
{
// TODO use control.Invoke
2003-07-21 16:12:40 +04:00
Form f = (Form)control;
Rectangle client = f.ClientRectangle;
Rectangle r = f.RectangleToScreen(client);
int x = r.Location.X - f.Location.X;
int y = r.Location.Y - f.Location.Y;
return new java.awt.Insets(y, x, control.Height - client.Height - y, control.Width - client.Width - x);
2002-12-18 19:00:25 +03:00
}
2003-07-21 16:12:40 +04:00
2003-03-17 17:02:46 +03:00
public int getState()
{
throw new NotImplementedException();
}
public void setState(int state)
{
throw new NotImplementedException();
}
public void setMaximizedBounds(java.awt.Rectangle r)
{
throw new NotImplementedException();
}
2002-12-18 19:00:25 +03:00
}
2003-08-12 17:09:31 +04:00
2004-09-27 14:17:34 +04:00
class NetDialogPeer : NetWindowPeer, DialogPeer
{
internal NetDialogPeer(java.awt.Dialog target, Form form)
: base(target, form)
{
}
private void setTitleImpl(string title)
{
control.Text = title;
}
public void setTitle(string title)
{
control.Invoke(new SetString(setTitleImpl), new object[] { title });
}
public void setResizable(bool resizable)
{
throw new NotImplementedException();
}
}
2003-08-12 17:09:31 +04:00
class NetListPeer : NetComponentPeer, ListPeer
{
internal NetListPeer(java.awt.List target, ListBox listbox)
: base(target, listbox)
{
}
public void add(String item, int index)
{
throw new NotImplementedException();
}
public void addItem(String item, int index)
{
throw new NotImplementedException();
}
public void clear()
{
throw new NotImplementedException();
}
public void delItems(int start_index, int end_index)
{
throw new NotImplementedException();
}
public void deselect(int index)
{
throw new NotImplementedException();
}
public int[] getSelectedIndexes()
{
throw new NotImplementedException();
}
public void makeVisible(int index)
{
throw new NotImplementedException();
}
public java.awt.Dimension minimumSize(int s)
{
throw new NotImplementedException();
}
public java.awt.Dimension preferredSize(int s)
{
throw new NotImplementedException();
}
public void removeAll()
{
throw new NotImplementedException();
}
public void select(int index)
{
throw new NotImplementedException();
}
public void setMultipleMode(bool multi)
{
throw new NotImplementedException();
}
public void setMultipleSelections(bool multi)
{
throw new NotImplementedException();
}
public java.awt.Dimension getPreferredSize(int s)
{
throw new NotImplementedException();
}
public java.awt.Dimension getMinimumSize(int s)
{
throw new NotImplementedException();
}
}
2002-12-18 19:00:25 +03:00
}