Server/Display.cs
changeset 104 189aac7dd3d6
parent 57 544132d07c3b
child 105 4196b0ca97d9
     1.1 --- a/Server/Display.cs	Wed Feb 04 15:48:08 2015 +0100
     1.2 +++ b/Server/Display.cs	Wed Feb 04 17:44:25 2015 +0100
     1.3 @@ -10,11 +10,33 @@
     1.4  namespace SharpDisplayManager
     1.5  {
     1.6  
     1.7 +
     1.8      /// <summary>
     1.9      /// Provide access to our display hardware through MiniDisplay API.
    1.10      /// </summary>
    1.11      public class Display
    1.12      {
    1.13 +		public delegate void OnOpenedHandler(Display aDisplay);
    1.14 +		public event OnOpenedHandler OnOpened;
    1.15 +
    1.16 +		public delegate void OnClosedHandler(Display aDisplay);
    1.17 +		public event OnClosedHandler OnClosed;
    1.18 +
    1.19 +		//Our display device handle
    1.20 +		IntPtr iDevice;
    1.21 +
    1.22 +		//static functions
    1.23 +		public static int TypeCount()
    1.24 +		{
    1.25 +			return MiniDisplayTypeCount();
    1.26 +		}
    1.27 +
    1.28 +		public static string TypeName(TMiniDisplayType aType)
    1.29 +		{
    1.30 +			IntPtr ptr = MiniDisplayTypeName(aType);
    1.31 +			string str = Marshal.PtrToStringUni(ptr);
    1.32 +			return str;
    1.33 +		}
    1.34  
    1.35          //Constructor
    1.36          public Display()
    1.37 @@ -25,17 +47,36 @@
    1.38          //
    1.39          public bool Open(TMiniDisplayType aType)
    1.40          {
    1.41 -            if (iDevice == IntPtr.Zero)
    1.42 -            {
    1.43 -                iDevice = MiniDisplayOpen(aType);
    1.44 -            }
    1.45 -            return iDevice != IntPtr.Zero;
    1.46 +			if (IsOpen())
    1.47 +			{
    1.48 +				//Already open return an error
    1.49 +				return false;
    1.50 +			}
    1.51 +
    1.52 +            iDevice = MiniDisplayOpen(aType);
    1.53 +
    1.54 +            bool success = iDevice != IntPtr.Zero;
    1.55 +			if (success)
    1.56 +			{
    1.57 +				//Broadcast opened event
    1.58 +				OnOpened(this);
    1.59 +			}
    1.60 +
    1.61 +			return success;
    1.62          }
    1.63  
    1.64          public void Close()
    1.65          {
    1.66 +			if (!IsOpen())
    1.67 +			{
    1.68 +				//Pointless
    1.69 +				return;
    1.70 +			}
    1.71 +
    1.72              MiniDisplayClose(iDevice);
    1.73              iDevice = IntPtr.Zero;
    1.74 +			//Broadcast closed event
    1.75 +			OnClosed(this);
    1.76          }
    1.77  
    1.78          public bool IsOpen()
    1.79 @@ -192,10 +233,6 @@
    1.80              return str;
    1.81          }
    1.82  
    1.83 -        //Our display device handle
    1.84 -        IntPtr iDevice;
    1.85 -
    1.86 -
    1.87          //[Serializable]
    1.88          public enum TMiniDisplayType
    1.89          {
    1.90 @@ -221,6 +258,12 @@
    1.91          [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
    1.92          public static extern void MiniDisplayClose(IntPtr aDevice);
    1.93  
    1.94 +		[DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
    1.95 +		public static extern int MiniDisplayTypeCount();
    1.96 +
    1.97 +		[DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
    1.98 +		public static extern IntPtr MiniDisplayTypeName(TMiniDisplayType aType);
    1.99 +
   1.100          [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   1.101          public static extern void MiniDisplayClear(IntPtr aDevice);
   1.102