// Constructor.
	public Form()
			{
				visible = false;
				autoScale = true;
				topLevel = true;
				loaded=false;
				borderStyle = FormBorderStyle.Sizable;
				mdiChildren = new Form [0];
				ownedForms = new Form [0];
				opacity = 1.0;
				windowFlags = ToolkitWindowFlags.Default;
				formStartPosition = FormStartPosition.WindowsDefaultLocation;
				windowState = FormWindowState.Normal;
			}
	// Set the current state of a window decoration flag.
	private void SetWindowFlag(ToolkitWindowFlags flag, bool value)
			{
				// Alter the flag setting.
				if(value)
				{
					windowFlags |= flag;
				}
				else
				{
					windowFlags &= ~flag;
				}

				// Pass the flags to the window manager.
				if(toolkitWindow != null)
				{
					SetWindowFlags(toolkitWindow);
				}
			}
	// Get the current state of a window decoration flag.
	private bool GetWindowFlag(ToolkitWindowFlags flag)
			{
				return ((windowFlags & flag) == flag);
			}
	// Change the set of supported window decorations and functions.
	void IToolkitTopLevelWindow.SetWindowFlags(ToolkitWindowFlags flags)
			{
				// Set the default hint flags.
				MotifDecorations decorations = 0;
				MotifFunctions functions = 0;
				MotifInputType inputType = MotifInputType.Normal;
				OtherHints otherHints = OtherHints.None;

				// Alter decorations according to the window flags.
				if((flags & ToolkitWindowFlags.Close) != 0)
				{
					functions |= MotifFunctions.Close;
				}
				if((flags & ToolkitWindowFlags.Minimize) != 0)
				{
					decorations |= MotifDecorations.Minimize;
					functions |= MotifFunctions.Minimize;
				}
				if((flags & ToolkitWindowFlags.Caption) != 0)
				{
					decorations |= MotifDecorations.Title;
				}
				if((flags & ToolkitWindowFlags.Border) != 0)
				{
					decorations |= MotifDecorations.Border;
				}
				if((flags & ToolkitWindowFlags.ResizeHandles) != 0)
				{
					decorations |= MotifDecorations.ResizeHandles;
				}
				if((flags & ToolkitWindowFlags.Menu) != 0)
				{
					decorations |= MotifDecorations.Menu;
				}
				if((flags & ToolkitWindowFlags.Resize) != 0)
				{
					decorations |= MotifDecorations.Maximize |
								   MotifDecorations.ResizeHandles;
					functions |= MotifFunctions.Maximize |
								 MotifFunctions.Resize;
				}
				if((flags & ToolkitWindowFlags.Move) != 0)
				{
					functions |= MotifFunctions.Move;
				}
				if((flags & ToolkitWindowFlags.Modal) != 0)
				{
					inputType = MotifInputType.ApplicationModal;
				}
				if((flags & ToolkitWindowFlags.ToolWindow) != 0)
				{
					otherHints |= OtherHints.ToolWindow;
				}
				else if((flags & ToolkitWindowFlags.Dialog) != 0)
				{
					otherHints |= OtherHints.Dialog;
				}
				if((flags & ToolkitWindowFlags.ShowInTaskbar) == 0)
				{
					otherHints |= OtherHints.HideFromTaskBar;
				}
				if((flags & ToolkitWindowFlags.Help) != 0)
				{
					otherHints |= OtherHints.HelpButton;
				}
				if((flags & ToolkitWindowFlags.TopMost) != 0)
				{
					otherHints |= OtherHints.TopMost;
				}

				// Remove the "transient for" hint if we are changing a
				// modal form back into a regular form.
				if(InputType == MotifInputType.ApplicationModal &&
				   inputType == MotifInputType.Normal)
				{
					RemoveTransientFor();
				}

				// Send the Motif flags to the window manager.
				Decorations = decorations;
				Functions = functions;
				InputType = inputType;
				OtherHints = otherHints;
			}
	// Change the set of supported window decorations and functions.
	void IToolkitTopLevelWindow.SetWindowFlags(ToolkitWindowFlags flags)
	{
		if (hwnd == IntPtr.Zero)
			throw new ApplicationException("DrawingTopLevelWindow.SetWindowsFlags ERROR: Cant SetWindowsFlags. Hwnd not created yet");
	
		Win32.Api.WindowStyle style;
		Win32.Api.WindowsExtendedStyle extendedStyle;
			
		toolkit.GetWin32StylesFromFlags( flags, out style, out extendedStyle);
		//Now set the style
		
		Win32.Api.SetLastError(0);
		
		if (Win32.Api.SetWindowLongA(hwnd, Win32.Api.SetWindowLongType.GWL_STYLE,style) == 0
			&& Win32.Api.GetLastError() != 0)
			throw new InvalidOperationException("Unable to change the window style");
			
		Win32.Api.SetLastError(0);
		
		if (Win32.Api.SetWindowLongA(hwnd, Win32.Api.SetWindowLongType.GWL_EXSTYLE,extendedStyle) == 0
			&& Win32.Api.GetLastError() != 0)
			throw new InvalidOperationException("Unable to change the extended window style");
			
		// Redraw the entire window including the non client portion
		Win32.Api.RedrawWindow( hwnd, IntPtr.Zero, IntPtr.Zero, Win32.Api.RedrawWindowFlags.RDW_INVALIDATE | Win32.Api.RedrawWindowFlags.RDW_FRAME );
		//Console.WriteLine( "DrawingTopLevelWindow.SetWindowFlags, " + sink );
			

	}
	// Get the adjustment values for a top-level window, to convert
	// between window bounds and client bounds.  Each value should
	// be >= 0 and indicate the number of pixels to subtract from the
	// windows bounds to get the client bounds.
	public void GetWindowAdjust(out int leftAdjust, out int topAdjust,
						        out int rightAdjust, out int bottomAdjust,
								ToolkitWindowFlags flags)
			{
				// X adds borders separately in the window manager.
				// They are not counted in the size of the app window.
				// There is no portable way to get the window borders before
				// a window is created. These are representive values.
				leftAdjust = 2;
				topAdjust = 19 + 2;
				rightAdjust = 2;
				bottomAdjust = 2;
			}
	// Get the adjustment values for a top-level window, to convert
	// between window bounds and client bounds.  Each value should
	// be >= 0 and indicate the number of pixels to subtract from the
	// windows bounds to get the client bounds.
	public virtual void GetWindowAdjust
				(out int leftAdjust, out int topAdjust,
				 out int rightAdjust, out int bottomAdjust,
				 ToolkitWindowFlags flags)
			{
				leftAdjust = 0;
				topAdjust = 0;
				rightAdjust = 0;
				bottomAdjust = 0;
			}
	internal void GetWin32StylesFromFlags( ToolkitWindowFlags flags, out Win32.Api.WindowStyle style, out Win32.Api.WindowsExtendedStyle extendedStyle)
	{
		style = Win32.Api.WindowStyle.WS_POPUP | Win32.Api.WindowStyle.WS_CLIPCHILDREN;
		extendedStyle = 0;
	
		//to remove the popup style
		Win32.Api.WindowStyle overlapped = ~Win32.Api.WindowStyle.WS_POPUP;
			
		if((flags & ToolkitWindowFlags.Close) > 0)
			style |= Win32.Api.WindowStyle.WS_SYSMENU;

		if((flags & ToolkitWindowFlags.Minimize) > 0)
			style = style & overlapped | Win32.Api.WindowStyle.WS_MINIMIZEBOX;

		if((flags & ToolkitWindowFlags.Maximize) > 0)
			style = style & overlapped | Win32.Api.WindowStyle.WS_MAXIMIZEBOX;

		if((flags & ToolkitWindowFlags.Caption) > 0)
			style |= Win32.Api.WindowStyle.WS_CAPTION;

		if((flags & ToolkitWindowFlags.Border) > 0)
			style |= Win32.Api.WindowStyle.WS_BORDER;

		if((flags & ToolkitWindowFlags.ResizeHandles) > 0)
			style |= Win32.Api.WindowStyle.WS_THICKFRAME;

		if((flags & ToolkitWindowFlags.Menu) > 0)
			style = style | Win32.Api.WindowStyle.WS_SYSMENU;

		if((flags & ToolkitWindowFlags.Resize) > 0)
			style |= Win32.Api.WindowStyle.WS_THICKFRAME;

		//We dont handle the Move flag in Win32

		//TODO: NOT SURE HERE
		if((flags & ToolkitWindowFlags.Modal) > 0)
			style |= Win32.Api.WindowStyle.WS_POPUP | Win32.Api.WindowStyle.WS_DLGFRAME;

		//TODO: Need a hidden window
		//if((flags & ToolkitWindowFlags.ShowInTaskBar)>0)
	
		if((flags & ToolkitWindowFlags.TopMost)>0)
			extendedStyle |= Win32.Api.WindowsExtendedStyle.WS_EX_TOPMOST;

		if((flags & ToolkitWindowFlags.ToolWindow) > 0)
			extendedStyle |= Win32.Api.WindowsExtendedStyle.WS_EX_TOOLWINDOW;		

	}
	// Get the adjustment values for a top-level window, to convert
	// between window bounds and client bounds.  Each value should
	// be >= 0 and indicate the number of pixels to subtract from the
	// windows bounds to get the client bounds.
	public void GetWindowAdjust(out int leftAdjust, out int topAdjust,
		out int rightAdjust, out int bottomAdjust,
		ToolkitWindowFlags flags)
	{
		Win32.Api.WindowStyle style;
		Win32.Api.WindowsExtendedStyle extendedStyle;
		GetWin32StylesFromFlags( flags, out style, out extendedStyle);
		Win32.Api.RECT rect = new System.Drawing.Win32.Api.RECT(0,0,0,0);
		Win32.Api.AdjustWindowRectEx( ref rect, style, false, extendedStyle );

		leftAdjust = -rect.left;
		topAdjust = -rect.top;
		rightAdjust = rect.right;
		bottomAdjust = rect.bottom;
	}