dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/System.Windows.Forms AmbientProperti


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/System.Windows.Forms AmbientProperties.cs,NONE,1.1 BaseCollection.cs,NONE,1.1 FeatureSupport.cs,NONE,1.1 OSFeature.cs,NONE,1.1 Screen.cs,NONE,1.1 Application.cs,1.2,1.3 ApplicationContext.cs,1.1,1.2 IFeatureSupport.cs,1.1,1.2
Date: Fri, 13 Jun 2003 08:30:33 -0400

Update of /cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms
In directory subversions:/tmp/cvs-serv3275/System.Windows.Forms

Modified Files:
        Application.cs ApplicationContext.cs IFeatureSupport.cs 
Added Files:
        AmbientProperties.cs BaseCollection.cs FeatureSupport.cs 
        OSFeature.cs Screen.cs 
Log Message:


Implement some housekeeping classes within the Forms API.


--- NEW FILE ---
/*
 * AmbientProperties.cs - Implementation of the
 *                      "System.Windows.Forms.AmbientProperties" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Windows.Forms
{

using System.Drawing;

public sealed class AmbientProperties
{
        // Internal state.
        private Color backColor;
        private Cursor cursor;
        private Font font;
        private Color foreColor;

        // Constructor.
        public AmbientProperties() {}

        // Get or set this object's properties.
        public Color BackColor
                        {
                                get
                                {
                                        return backColor;
                                }
                                set
                                {
                                        backColor = value;
                                }
                        }
        public Cursor Cursor
                        {
                                get
                                {
                                        return cursor;
                                }
                                set
                                {
                                        cursor = value;
                                }
                        }
        public Font Font
                        {
                                get
                                {
                                        return font;
                                }
                                set
                                {
                                        font = value;
                                }
                        }
        public Color ForeColor
                        {
                                get
                                {
                                        return foreColor;
                                }
                                set
                                {
                                        foreColor = value;
                                }
                        }

}; // class AmbientProperties

}; // namespace System.Windows.Forms

--- NEW FILE ---
/*
 * BaseCollection.cs - Implementation of the
 *                      "System.Windows.Forms.BaseCollection" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Windows.Forms
{

using System.Collections;

public class BaseCollection : MarshalByRefObject, ICollection, IEnumerable
{
        // Constructor.
        public BaseCollection() {}

        // Implement the ICollection interface.
        public void CopyTo(Array array, int index)
                        {
                                List.CopyTo(array, index);
                        }
        public virtual int Count
                        {
                                get
                                {
                                        return List.Count;
                                }
                        }
        public bool IsSynchronized
                        {
                                get
                                {
                                        return false;
                                }
                        }
        public Object SyncRoot
                        {
                                get
                                {
                                        return this;
                                }
                        }

        // Implement the IEnumerable interface.
        public IEnumerator GetEnumerator()
                        {
                                return List.GetEnumerator();
                        }

        // Determine if the collection is read-only.
        public bool IsReadOnly
                        {
                                get
                                {
                                        return false;
                                }
                        }

        // Get the array list that underlies this collection
        protected virtual ArrayList List
                        {
                                get
                                {
                                        return null;
                                }
                        }

}; // class BaseCollection

}; // namespace System.Windows.Forms

--- NEW FILE ---
/*
 * FeatureSupport.cs - Implementation of the
 *                      "System.Windows.Forms.FeatureSupport" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Windows.Forms
{

#if !CONFIG_COMPACT_FORMS

using System.Reflection;

public abstract class FeatureSupport : IFeatureSupport
{
        // Constructor.
        protected FeatureSupport() {}

        // Get a feature support object.
        private static IFeatureSupport GetFeatureSupport(String 
featureClassName)
                        {
                        #if CONFIG_REFLECTION
                                Type type = Type.GetType(featureClassName);
                                if(type != null &&
                                   
typeof(IFeatureSupport).IsAssignableFrom(type))
                                {
                                        ConstructorInfo ctor =
                                                
type.GetConstructor(Type.EmptyTypes);
                                        if(ctor != null)
                                        {
                                                return (ctor.Invoke(new Object 
[0]) as
                                                                                
IFeatureSupport);
                                        }
                                }
                        #endif
                                return null;
                        }

        // Get the version of a specific feature which is present.
        public abstract Version GetVersionPresent(Object feature);
        public static Version GetVersionPresent
                                (String featureClassName, String 
featureConstName)
                        {
                                IFeatureSupport feature;
                                feature = GetFeatureSupport(featureClassName);
                                if(feature != null)
                                {
                                        return 
feature.GetVersionPresent(featureConstName);
                                }
                                else
                                {
                                        return null;
                                }
                        }

        // Determine if a feature is present.
        public virtual bool IsPresent(Object feature)
                        {
                                Version version = GetVersionPresent(feature);
                                return (version != null);
                        }
        public virtual bool IsPresent(Object feature, Version minimumVersion)
                        {
                                Version version = GetVersionPresent(feature);
                                if(minimumVersion != null)
                                {
                                        return (version != null && version >= 
minimumVersion);
                                }
                                else
                                {
                                        return (version != null);
                                }
                        }
        public static bool IsPresent
                                (String featureClassName, String 
featureConstName)
                        {
                                IFeatureSupport feature;
                                feature = GetFeatureSupport(featureClassName);
                                if(feature != null)
                                {
                                        return 
feature.IsPresent(featureConstName);
                                }
                                else
                                {
                                        return false;
                                }
                        }
        public static bool IsPresent
                                (String featureClassName, String 
featureConstName,
                                 Version minimumVersion)
                        {
                                IFeatureSupport feature;
                                feature = GetFeatureSupport(featureClassName);
                                if(feature != null)
                                {
                                        return feature.IsPresent
                                                (featureConstName, 
minimumVersion);
                                }
                                else
                                {
                                        return false;
                                }
                        }

}; // class FeatureSupport

#endif // !CONFIG_COMPACT_FORMS

}; // namespace System.Windows.Forms

--- NEW FILE ---
/*
 * OSFeature.cs - Implementation of the
 *                      "System.Windows.Forms.OSFeature" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Windows.Forms
{

#if !CONFIG_COMPACT_FORMS

public class OSFeature : FeatureSupport
{
        // Internal state.
        private static OSFeature feature = new OSFeature();

        // Standard feature names.
        public static readonly Object LayeredWindows = new Object();
        public static readonly Object Themes = new Object();

        // Constructor.
        private OSFeature () {}

        // Get the version of a specific feature which is present.
        public override Version GetVersionPresent(Object feature)
                        {
                                // We don't support any special features yet.
                                return null;
                        }

        // Get the main OS feature object.
        public static OSFeature Feature
                        {
                                get
                                {
                                        return feature;
                                }
                        }

}; // class OSFeature

#endif // !CONFIG_COMPACT_FORMS

}; // namespace System.Windows.Forms

--- NEW FILE ---
/*
 * Screen.cs - Implementation of the
 *                      "System.Windows.Forms.Screen" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Windows.Forms
{

#if !CONFIG_COMPACT_FORMS

using System.Drawing;
using System.Drawing.Toolkit;

public class Screen
{
        // Internal state.  We only have one (virtual) screen.
        private static Screen[] allScreens = {new Screen()};

        // Constructor.
        private Screen() {}

        // Get an array of all screens on the system.
        public static Screen[] AllScreens
                        {
                                get
                                {
                                        return allScreens;
                                }
                        }

        // Get the bounds for this screen.
        public Rectangle Bounds
                        {
                                get
                                {
                                        return new Rectangle
                                                (new Point(0, 0),
                                                 
ToolkitManager.Toolkit.GetScreenSize());
                                }
                        }

        // Get the device name for this screen.
        public String DeviceName
                        {
                                get
                                {
                                        // We use the name of the toolkit as 
the device name.
                                        return 
ToolkitManager.Toolkit.GetType().ToString();
                                }
                        }

        // Determine if this is the primary screen.
        public bool Primary
                        {
                                get
                                {
                                        // We only have one screen in this 
implementation.
                                        return true;
                                }
                        }

        // Get the primary screen.
        public static Screen PrimaryScreen
                        {
                                get
                                {
                                        return allScreens[0];
                                }
                        }

        // Get the working area for the screen.
        public Rectangle WorkingArea
                        {
                                get
                                {
                                        return 
ToolkitManager.Toolkit.GetWorkingArea();
                                }
                        }

        // Determine if two objects are equal.
        public override bool Equals(Object obj)
                        {
                                // We only have one screen, so the test is easy.
                                return (obj == this);
                        }

        // Get the screen that contains a particular control.
        public static Screen FromControl(Control control)
                        {
                                return PrimaryScreen;
                        }

        // Get the screen that contains a particular window.
        public static Screen FromHandle(IntPtr hwnd)
                        {
                                return PrimaryScreen;
                        }

        // Get the screen that contains a particular point.
        public static Screen FromPoint(Point point)
                        {
                                return PrimaryScreen;
                        }

        // Get the screen that contains a particular rectangle.
        public static Screen FromRectangle(Rectangle rect)
                        {
                                return PrimaryScreen;
                        }

        // Get a hash code for this object.
        public override int GetHashCode()
                        {
                                return base.GetHashCode();
                        }

        // Get the working area for the screen containing a control.
        public static Rectangle GetWorkingArea(Control control)
                        {
                                return FromControl(control).WorkingArea;
                        }

        // Get the working area for the screen containing a point.
        public static Rectangle GetWorkingArea(Point pt)
                        {
                                return FromPoint(pt).WorkingArea;
                        }

        // Get the working area for the screen containing a rectangle.
        public static Rectangle GetWorkingArea(Rectangle rect)
                        {
                                return FromRectangle(rect).WorkingArea;
                        }

        // Convert this object into a string.
        public override String ToString()
                        {
                                return String.Format
                                        ("Screen [Bounds={0} WorkingArea={1} " +
                                         "Primary={2} DeviceName={3}]",
                                         Bounds, WorkingArea, Primary, 
DeviceName);
                        }

}; // class Screen

#endif // !CONFIG_COMPACT_FORMS

}; // namespace System.Windows.Forms

Index: Application.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms/Application.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** Application.cs      12 Jun 2003 05:50:29 -0000      1.2
--- Application.cs      13 Jun 2003 12:30:31 -0000      1.3
***************
*** 305,312 ****
                        }
  
        // Inner version of "Run".  In this implementation we only allow a
        // message loop to be running on one of the threads.
!       private static void RunMessageLoop()
                        {
                                // Make sure that we are the only message loop.
                                lock(typeof(Application))
--- 305,336 ----
                        }
  
+       // Exit from the current thread when the main form closes.
+       private static void ContextExit(Object sender, EventArgs e)
+                       {
+                       #if !CONFIG_COMPACT_FORMS
+                               ExitThread();
+                       #else
+                               Exit();
+                       #endif
+                       }
+ 
        // Inner version of "Run".  In this implementation we only allow a
        // message loop to be running on one of the threads.
!       private static void RunMessageLoop(ApplicationContext context)
                        {
+                               Form mainForm = context.MainForm;
+                               EventHandler handler;
+ 
+                               // Connect the context's ThreadExit event to 
our "ExitThread".
+                               handler = new EventHandler(ContextExit);
+                               context.ThreadExit += handler;
+ 
+                               // Show the main form on-screen.
+                               if(mainForm != null)
+                               {
+                                       mainForm.Show();
+                                       Form.activeForm = mainForm;
+                               }
+ 
                                // Make sure that we are the only message loop.
                                lock(typeof(Application))
***************
*** 355,358 ****
--- 379,386 ----
                                }
  
+                               // Disconnect from the context's "ThreadExit" 
event.
+                               context.ThreadExit -= handler;
+                               Form.activeForm = null;
+ 
                        #if !CONFIG_COMPACT_FORMS
  
***************
*** 374,387 ****
        // Make the specified form visible and run the main loop.
        // The loop will exit when "Exit" is called.
-       [TODO]
        public static void Run(Form mainForm)
                        {
!                               // TODO
!                               if(mainForm != null)
!                               {
!                                       mainForm.Show();
!                                       Form.activeForm = mainForm;
!                               }
!                               RunMessageLoop();
                        }
  
--- 402,408 ----
        // Make the specified form visible and run the main loop.
        // The loop will exit when "Exit" is called.
        public static void Run(Form mainForm)
                        {
!                               RunMessageLoop(new 
ApplicationContext(mainForm));
                        }
  
***************
*** 391,403 ****
        public static void Run()
                        {
!                               RunMessageLoop();
                        }
  
        // Run the main message loop for an application context.
-       [TODO]
        public static void Run(ApplicationContext context)
                        {
!                               // TODO
!                               RunMessageLoop();
                        }
  
--- 412,426 ----
        public static void Run()
                        {
!                               RunMessageLoop(new ApplicationContext());
                        }
  
        // Run the main message loop for an application context.
        public static void Run(ApplicationContext context)
                        {
!                               if(context == null)
!                               {
!                                       context = new ApplicationContext();
!                               }
!                               RunMessageLoop(context);
                        }
  

Index: ApplicationContext.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms/ApplicationContext.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** ApplicationContext.cs       11 Jun 2003 07:07:19 -0000      1.1
--- ApplicationContext.cs       13 Jun 2003 12:30:31 -0000      1.2
***************
*** 23,30 ****
  {
  
! [TODO]
! public sealed class ApplicationContext
  {
!       // TODO
  
  }; // class ApplicationContext
--- 23,119 ----
  {
  
! #if !CONFIG_COMPACT_FORMS
! public
! #else
! internal
! #endif
! class ApplicationContext
  {
!       // Internal state.
!       private Form mainForm;
! 
!       // Constructors.
!       public ApplicationContext() {}
!       public ApplicationContext(Form mainForm)
!                       {
!                               MainForm = mainForm;
!                       }
! 
!       // Destructor.
!       ~ApplicationContext()
!                       {
!                               Dispose(false);
!                       }
! 
!       // Event handler for the main form's handle destroy event.
!       private void MainFormDestroyed(Object sender, EventArgs e)
!                       {
!                               Form form = (sender as Form);
!                               if(form != null && !form.RecreatingHandle)
!                               {
!                                       form.HandleDestroyed -=
!                                               new 
EventHandler(MainFormDestroyed);
!                                       OnMainFormClosed(sender, e);
!                               }
!                       }
! 
!       // Get or set the main form for this context.
!       public Form MainForm
!                       {
!                               get
!                               {
!                                       return mainForm;
!                               }
!                               set
!                               {
!                                       if(mainForm != value)
!                                       {
!                                               EventHandler handler =
!                                                       new 
EventHandler(MainFormDestroyed);
!                                               if(mainForm != null)
!                                               {
!                                                       
mainForm.HandleDestroyed -= handler;
!                                               }
!                                               mainForm = value;
!                                               if(mainForm != null)
!                                               {
!                                                       
mainForm.HandleDestroyed += handler;
!                                               }
!                                       }
!                               }
!                       }
! 
!       // Dispose of this object.
!       public void Dispose()
!                       {
!                               Dispose(true);
!                               GC.SuppressFinalize(this);
!                       }
!       protected virtual void Dispose(bool disposing)
!                       {
!                               MainForm = null;
!                       }
! 
!       // Exit the current thread's message loop.
!       public void ExitThread()
!                       {
!                               ExitThreadCore();
!                       }
!       protected virtual void ExitThreadCore()
!                       {
!                               if(ThreadExit != null)
!                               {
!                                       ThreadExit(this, EventArgs.Empty);
!                               }
!                       }
! 
!       // Event that is raised when the thread message loop should exit.
!       public event EventHandler ThreadExit;
! 
!       // Method that is called when the main form is closed.
!       protected virtual void OnMainFormClosed(Object sender, EventArgs e)
!                       {
!                               ExitThreadCore();
!                       }
  
  }; // class ApplicationContext

Index: IFeatureSupport.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms/IFeatureSupport.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** IFeatureSupport.cs  13 Jun 2003 10:22:58 -0000      1.1
--- IFeatureSupport.cs  13 Jun 2003 12:30:31 -0000      1.2
***************
*** 23,26 ****
--- 23,28 ----
  {
  
+ #if !CONFIG_COMPACT_FORMS
+ 
  public interface IFeatureSupport
  {
***************
*** 33,36 ****
--- 35,40 ----
  
  }; // interface IFeatureSupport
+ 
+ #endif // !CONFIG_COMPACT_FORMS
  
  }; // namespace System.Windows.Forms





reply via email to

[Prev in Thread] Current Thread [Next in Thread]