Display.cs :  » GUI » wx-NET » wx » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GUI » wx NET 
wx NET » wx » Display.cs
//------------------------------------------------------------------------
// wx.NET - Display.cs
// 
// Michael S. Muegel mike _at_ muegel dot org
//
// Licensed under the wxWidgets license, see LICENSE.txt for details.
//
// TODO:
//    + Memory management review
//
// wxWidgets-based quirks of note:
//    + Display resolution did not change on my Fedora1 test system
//      under both wxWidgets display sample and my port.
//    + IsPrimary is wrong, at least on WIN32: assumes display #0
//      is primary, which may not be the case. For example, I have
//      three horizontally aligned displays. wxWidgets numbers them
//      0, 1, 2. But it's #1 is actually the primary, not 0. Note also
//      that the numbering scheme differs from how windows numbers
//      them, which has more to do with the display adapter used. This
//      is not an issue really, but something to be aware of should
//      you be expecting them to match.
//------------------------------------------------------------------------

#if WXNET_DISPLAY

using System;
using System.Drawing;
using System.Runtime.InteropServices;

namespace wx{
    /** Use static method GetDisplay() to generate instances.
     * Please note, that this method will generate at most on instance for each display.
     * */
  public class Display : Object
  {
    [DllImport("wx-c")] static extern IntPtr wxDisplay_ctor(int index);
        [DllImport("wx-c")] static extern void wxDisplay_RegisterOnDispose(IntPtr self, Virtual_Dispose virtualDisposeMethod);
    [DllImport("wx-c")] static extern int wxDisplay_GetCount();
    [DllImport("wx-c")] static extern int wxDisplay_GetFromPoint(ref Point pt);
    [DllImport("wx-c")] static extern int wxDisplay_GetFromWindow(IntPtr window);
    [DllImport("wx-c")] static extern void wxDisplay_GetGeometry(IntPtr self, out Rectangle rect);
    [DllImport("wx-c")] static extern IntPtr wxDisplay_GetName(IntPtr self);
    [DllImport("wx-c")] static extern bool wxDisplay_IsPrimary(IntPtr self);
    [DllImport("wx-c")] static extern void wxDisplay_GetCurrentMode(IntPtr self, out VideoMode mode);
    [DllImport("wx-c")] static extern bool wxDisplay_ChangeMode(IntPtr self, VideoMode mode);


    [DllImport("wx-c")] static extern int wxDisplay_GetNumModes(IntPtr self, VideoMode mode);
    [DllImport("wx-c")] static extern void wxDisplay_GetModes(IntPtr self, VideoMode mode, [In, Out] VideoMode[] modes);

    
    [DllImport("wx-c")] static extern void wxDisplay_ResetMode(IntPtr self);
    [DllImport("wx-c")] static extern void wxDisplay_dtor(IntPtr self);

    //------------------------------------------------------------------------

    /** Symbolic constant used by all Find()-like functions returning positive
      * integer on success as failure indicator. While this is global in
      * wxWidgets it makes more sense to be in each class that uses it??? 
      * Or maybe move it to Window.cs.
         * */
    public const int wxNOT_FOUND = -1;
    
    //------------------------------------------------------------------------
    
    public Display(IntPtr wxObject)
      : base(wxObject)
    { 
      this.wxObject = wxObject;
            this.virtual_Dispose = new Virtual_Dispose(this.VirtualDispose);
            wxDisplay_RegisterOnDispose(this.wxObject, this.virtual_Dispose);
    }
      
    internal Display(IntPtr wxObject, bool memOwn)
      : base(wxObject)
    { 
      this.memOwn = memOwn;
      this.wxObject = wxObject;
            this.virtual_Dispose = new Virtual_Dispose(this.VirtualDispose);
            wxDisplay_RegisterOnDispose(this.wxObject, this.virtual_Dispose);
        }

    //------------------------------------------------------------------------

        internal Display(int index)
      : this(wxDisplay_ctor(index), true)
        {
        }

    //------------------------------------------------------------------------
    
    ~Display() 
    {
      Dispose();
    }

    //------------------------------------------------------------------------
    public static int Count
    {
      get { return wxDisplay_GetCount(); }
    }

        static Display[] s_displays=null;

    /** The array of all Displays indexed by display number.
         * These are all instance of this class that should ever live.
         */
    public static Display[] GetDisplays()
    {
            if (s_displays == null)
            {
                s_displays = new Display[Count];
                for (int i = 0; i < Count; i++)
                {
                    // currently, destruction of display instances crashes the system
                    // "access violation". i cannot imagine why.
                    s_displays[i] = new Display(i);
                    s_displays[i].memOwn = false;
                }
            }
            return s_displays;
    }

        /** Returns the representation of the desired display.
         * \return null iff the index is too large.
         */
        public static Display GetDisplay(int index)
        {
            if (s_displays == null) GetDisplays();
            if (index < 0 || index >= s_displays.Length)
            {
                return null;
            }
            return s_displays[index];
        }

        //------------------------------------------------------------------------
    // An array of available VideoModes for this display.
    virtual public VideoMode[] GetModes()
    {
      return GetModes(new VideoMode(0,0,0,0));
    }

    // An array of the VideoModes that match mode. A match occurs when
    // the resolution and depth matches and the refresh frequency in 
    // equal to or greater than mode.RefreshFrequency.
    virtual public VideoMode[] GetModes(VideoMode mode)
    {
      int num_modes = wxDisplay_GetNumModes(wxObject, mode);
      VideoMode[] modes = new VideoMode[num_modes];
      wxDisplay_GetModes(wxObject, mode, modes);
      return modes;
    }


    //------------------------------------------------------------------------

    public static int GetFromPoint(Point pt)
    {
      return wxDisplay_GetFromPoint(ref pt);
    }

    //------------------------------------------------------------------------

    virtual public int GetFromWindow(Window window)
    {
      #if __WXMSW__
        return wxDisplay_GetFromWindow(Object.SafePtr(window));
      #else
        throw new ApplicationException("Display.GetFromWindow is only available on WIN32");
      #endif
    }

    //------------------------------------------------------------------------

    virtual public Rectangle Geometry
    {
      get 
      {
        Rectangle rect = new Rectangle();
        wxDisplay_GetGeometry(wxObject, out rect);
        return rect;
      }
    }

    //------------------------------------------------------------------------

    virtual public string Name
    {
      get 
      {
        return new wxString(wxDisplay_GetName(wxObject), true);
      }
    }

    //------------------------------------------------------------------------

    virtual public bool IsPrimary
    {
      get 
      { 
        return wxDisplay_IsPrimary(wxObject);
      }
    }

    //------------------------------------------------------------------------


    virtual public VideoMode CurrentMode
    {
      get
      {
        VideoMode mode;
        wxDisplay_GetCurrentMode(wxObject, out mode);
        return mode;
      }
    }

    //------------------------------------------------------------------------

    virtual public bool ChangeMode(VideoMode mode)
    {
      return wxDisplay_ChangeMode(wxObject, mode);
    }

    //------------------------------------------------------------------------

    virtual public void ResetMode()
    {
      wxDisplay_ResetMode(wxObject);
    }

    //------------------------------------------------------------------------

  }

}

#endif
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.