FontMisc.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 » FontMisc.cs
//-----------------------------------------------------------------------------
// wx.NET - FontMapper.cs
//
// The wxFontMapper wrapper class.
//
// Written by Alexander Olk (xenomorph2@onlinehome.de)
// (C) 2003 Alexander Olk
// Licensed under the wxWidgets license, see LICENSE.txt for details.
//
// $Id: FontMisc.cs,v 1.13 2007/12/25 19:30:23 harald_meyer Exp $
//-----------------------------------------------------------------------------

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

namespace wx{
  public class FontMapper : Object
  {
    [DllImport("wx-c")] static extern IntPtr wxFontMapper_ctor();
    [DllImport("wx-c")] static extern void   wxFontMapper_dtor(IntPtr self);
    
    [DllImport("wx-c")] static extern IntPtr wxFontMapper_Get();
    [DllImport("wx-c")] static extern IntPtr wxFontMapper_Set(IntPtr mapper);
    [DllImport("wx-c")] static extern int    wxFontMapper_GetSupportedEncodingsCount();
    [DllImport("wx-c")] static extern int    wxFontMapper_GetEncoding(int n);
    [DllImport("wx-c")] static extern IntPtr wxFontMapper_GetEncodingName(int encoding);
    [DllImport("wx-c")] static extern IntPtr wxFontMapper_GetEncodingDescription(int encoding);
    [DllImport("wx-c")] static extern int    wxFontMapper_GetEncodingFromName(IntPtr name);
    
    [DllImport("wx-c")] static extern int    wxFontMapper_CharsetToEncoding(IntPtr self, IntPtr charset, bool interactive);
    [DllImport("wx-c")][return:MarshalAs(UnmanagedType.U1)] static extern bool   wxFontMapper_IsEncodingAvailable(IntPtr self, int encoding, IntPtr facename);
        [DllImport("wx-c")]
        [return: MarshalAs(UnmanagedType.U1)]
        static extern bool wxFontMapper_GetAltForEncoding(IntPtr self, int encoding, out int alt_encoding, IntPtr facename, bool interactive);
    
    [DllImport("wx-c")] static extern void   wxFontMapper_SetDialogParent(IntPtr self, IntPtr parent);
    [DllImport("wx-c")] static extern void   wxFontMapper_SetDialogTitle(IntPtr self, IntPtr title);
    
    //---------------------------------------------------------------------
    
    private static FontMapper staticFontMapper = new FontMapper(wxFontMapper_Get(), false);
    
    //---------------------------------------------------------------------
    
    public FontMapper(IntPtr wxObject)
      : base(wxObject) 
    {
      this.wxObject = wxObject;
    }
      
    internal FontMapper(IntPtr wxObject, bool memOwn)
      : base(wxObject)
    { 
      this.memOwn = memOwn;
      this.wxObject = wxObject;
    }
      
    public FontMapper()
      : this(wxFontMapper_ctor(), true) {}
      
    //---------------------------------------------------------------------
        
    public override void Dispose()
    {
      if (!disposed)
      {
                if (wxObject != IntPtr.Zero)
        {
          if (memOwn)
          {
            wxFontMapper_dtor(wxObject);
            memOwn = false;
          }
        }
        RemoveObject(wxObject);
        wxObject = IntPtr.Zero;
                --validInstancesCount;
                disposed = true;
      }
      
      base.Dispose();
      GC.SuppressFinalize(this);
    }
    
    //---------------------------------------------------------------------
    
    ~FontMapper() 
    {
      Dispose();
    }
      
    //---------------------------------------------------------------------
    
    public static FontMapper Get
    {
      get { return staticFontMapper; }
    }
    
    //---------------------------------------------------------------------
    
    public static FontMapper Set(FontMapper mapper)
    {
      return new FontMapper(wxFontMapper_Set(Object.SafePtr(mapper)));
    }
    
    //---------------------------------------------------------------------
    
    public static int SupportedEncodingsCount
    {
      get { return wxFontMapper_GetSupportedEncodingsCount(); }
    }
    
    //---------------------------------------------------------------------
    
    public static FontEncoding GetEncoding(int n)
    {
      return (FontEncoding)wxFontMapper_GetEncoding(n);
    }
    
    //---------------------------------------------------------------------
    
    public static string GetEncodingName(FontEncoding encoding)
    {
      return new wxString(wxFontMapper_GetEncodingName((int)encoding), true);
    }
    
    //---------------------------------------------------------------------
    
    public static FontEncoding GetEncodingFromName(string name)
    {
            wxString wxName = wxString.SafeNew(name);
      return (FontEncoding)wxFontMapper_GetEncodingFromName(Object.SafePtr(wxName));
    }
    
    //---------------------------------------------------------------------
    
    public FontEncoding CharsetToEncoding(string charset)
    {
      return CharsetToEncoding(charset, true);
    }
    
    public FontEncoding CharsetToEncoding(string charset, bool interactive)
    {
            return CharsetToEncoding(wxString.SafeNew(charset), interactive);
        }
    public FontEncoding CharsetToEncoding(wxString charset, bool interactive)
    {
      return (FontEncoding)wxFontMapper_CharsetToEncoding(wxObject, Object.SafePtr(charset), interactive);
    }
    
    //---------------------------------------------------------------------
    
    public bool IsEncodingAvailable(FontEncoding encoding)
    {
      return IsEncodingAvailable(encoding, "");
    }

        public bool IsEncodingAvailable(FontEncoding encoding, string facename)
        {
            return IsEncodingAvailable(encoding, wxString.SafeNew(facename));
        }
    public bool IsEncodingAvailable(FontEncoding encoding, wxString facename)
    {
      return wxFontMapper_IsEncodingAvailable(wxObject, (int)encoding, Object.SafePtr(facename));
    }
    
    //---------------------------------------------------------------------
    
    public bool GetAltForEncoding(FontEncoding encoding, out FontEncoding alt_encoding)
    {
      return GetAltForEncoding(encoding, out alt_encoding, "", true);
    }
    
    public bool GetAltForEncoding(FontEncoding encoding, out FontEncoding alt_encoding, string facename)
    {
      return GetAltForEncoding(encoding, out alt_encoding, facename, true);
    }

        public bool GetAltForEncoding(FontEncoding encoding, out FontEncoding alt_encoding, string facename, bool interactive)
        {
            return GetAltForEncoding(encoding, out alt_encoding, wxString.SafeNew(facename), interactive);
        }
    public bool GetAltForEncoding(FontEncoding encoding, out FontEncoding alt_encoding, wxString facename, bool interactive)
    {
      int alt_tmp;
      bool result = wxFontMapper_GetAltForEncoding(wxObject, (int)encoding, out alt_tmp, Object.SafePtr(facename), interactive);
      alt_encoding = (FontEncoding)alt_tmp;
      return result;
    }
    
    //---------------------------------------------------------------------
    
    public static string GetEncodingDescription(FontEncoding encoding)
    {
      return new wxString(wxFontMapper_GetEncodingDescription((int)encoding), true);
    }
    
    //---------------------------------------------------------------------
    
    public void SetDialogParent(Window parent)
    {
      wxFontMapper_SetDialogParent(wxObject, Object.SafePtr(parent));
    }
    
    //---------------------------------------------------------------------
    
    public void SetDialogTitle(string title)
    {
            wxString wxTitle = wxString.SafeNew(title);
      wxFontMapper_SetDialogTitle(wxObject, Object.SafePtr(wxTitle));
    }
  }
  
  //---------------------------------------------------------------------
  
  public class EncodingConverter : Object
  {
    enum CONVERT
    {
       wxCONVERT_STRICT,
       wxCONVERT_SUBSTITUTE
    }
    
    [DllImport("wx-c")] static extern IntPtr wxEncodingConverter_ctor();
    [DllImport("wx-c")][return:MarshalAs(UnmanagedType.U1)] static extern bool wxEncodingConverter_Init(IntPtr self, int input_enc, int output_enc, int method);
    [DllImport("wx-c")] static extern IntPtr wxEncodingConverter_Convert(IntPtr self, IntPtr input);
    
    //---------------------------------------------------------------------
    
    public EncodingConverter(IntPtr wxObject)
      : base(wxObject) {}
      
    public EncodingConverter()
      : base(wxEncodingConverter_ctor()) {}
      
    //---------------------------------------------------------------------
    
    public bool Init(FontEncoding input_enc, FontEncoding output_enc)
    {
      return Init(input_enc, output_enc, (int)CONVERT.wxCONVERT_STRICT);
    }
    
    public bool Init(FontEncoding input_enc, FontEncoding output_enc, int method)
    {
      return wxEncodingConverter_Init(wxObject, (int)input_enc, (int)output_enc, method);
    }
    
    //---------------------------------------------------------------------

        public string Convert(string input)
        {
            return Convert(wxString.SafeNew(input));
        }
    public string Convert(wxString input)
    {
      return new wxString(wxEncodingConverter_Convert(wxObject, Object.SafePtr(input)), true);
    }
  }
  
  //---------------------------------------------------------------------
  
  public class FontEnumerator : Object
  {
    private delegate bool Virtual_EnumerateFacenames(int encoding, bool fixedWidthOnly);
    private delegate bool Virtual_EnumerateEncodings(IntPtr facename);
    private delegate bool Virtual_OnFacename(IntPtr facename);
    private delegate bool Virtual_OnFontEncoding(IntPtr facename, IntPtr encoding);

    private Virtual_EnumerateFacenames virtual_EnumerateFacenames;
    private Virtual_EnumerateEncodings virtual_EnumerateEncodings;
    private Virtual_OnFacename virtual_OnFacename;
    private Virtual_OnFontEncoding virtual_OnFontEncoding;
    
    [DllImport("wx-c")] static extern IntPtr wxFontEnumerator_ctor();
    [DllImport("wx-c")] static extern void wxFontEnumerator_dtor(IntPtr self);
    [DllImport("wx-c")] static extern void wxFontEnumerator_RegisterVirtual(IntPtr self, Virtual_Dispose onDispose, Virtual_EnumerateFacenames enumerateFacenames, Virtual_EnumerateEncodings enumerateEncodings, Virtual_OnFacename onFacename, Virtual_OnFontEncoding onFontEncoding);
    [DllImport("wx-c")] static extern IntPtr wxFontEnumerator_GetFacenames(IntPtr self);
    [DllImport("wx-c")] static extern IntPtr wxFontEnumerator_GetEncodings(IntPtr self);
    [DllImport("wx-c")] static extern bool wxFontEnumerator_OnFacename(IntPtr self, IntPtr facename);
    [DllImport("wx.c")] static extern bool wxFontEnumerator_OnFontEncoding(IntPtr self, IntPtr facename, IntPtr encoding);
    [DllImport("wx-c")] static extern bool wxFontEnumerator_EnumerateFacenames(IntPtr self, int encoding, bool fixedWidthOnly);
    [DllImport("wx-c")] static extern bool wxFontEnumerator_EnumerateEncodings(IntPtr self, IntPtr facename);
    
    //---------------------------------------------------------------------
    
    public FontEnumerator()
      : this(wxFontEnumerator_ctor(), true) 
    {
            virtual_Dispose = new Virtual_Dispose(this.VirtualDispose);
      virtual_EnumerateFacenames = new Virtual_EnumerateFacenames(DoEnumerateFacenames);
      virtual_EnumerateEncodings = new Virtual_EnumerateEncodings(DoEnumerateEncodings);
      virtual_OnFacename = new Virtual_OnFacename(DoOnFacename);
      virtual_OnFontEncoding = new Virtual_OnFontEncoding(DoOnFontEncoding);

      wxFontEnumerator_RegisterVirtual(wxObject,
                virtual_Dispose,
        virtual_EnumerateFacenames,
        virtual_EnumerateEncodings,
        virtual_OnFacename,
        virtual_OnFontEncoding);      
    }
    
    public FontEnumerator(IntPtr wxObject)
      : base(wxObject) 
    {
      this.wxObject = wxObject;
    }
    
    internal FontEnumerator(IntPtr wxObject, bool memOwn)
      : base(wxObject)
    { 
      this.memOwn = memOwn;
      this.wxObject = wxObject;
    }
    
    //---------------------------------------------------------------------
        
    public override void Dispose()
    {
      if (!disposed)
      {
        if (wxObject != IntPtr.Zero)
        {
          if (memOwn)
          {
            wxFontEnumerator_dtor(wxObject);
            memOwn = false;
          }
        }
        RemoveObject(wxObject);
        wxObject = IntPtr.Zero;
                --validInstancesCount;
                disposed = true;
      }
      
      base.Dispose();
      GC.SuppressFinalize(this);
    }
    
    //---------------------------------------------------------------------
    
    ~FontEnumerator() 
    {
      Dispose();
    }
      
    //---------------------------------------------------------------------
    
    public string[] Facenames
    {
      get { return new ArrayString(wxFontEnumerator_GetFacenames(wxObject), true); }
    }
    
    //---------------------------------------------------------------------
    
    public string[] Encodings
    {
      get { return new ArrayString(wxFontEnumerator_GetEncodings(wxObject), true); }
    }
    
    //---------------------------------------------------------------------
    
    public virtual bool OnFacename(string facename)
    {
            wxString wxFaceName = wxString.SafeNew(facename);
      return wxFontEnumerator_OnFacename(wxObject, Object.SafePtr(wxFaceName));
    }
    
    private bool DoOnFacename(IntPtr facename)
    {
      return OnFacename(new wxString(facename));
    }
    
    //---------------------------------------------------------------------
    
    public virtual bool OnFontEncoding(string facename, string encoding)
    {
            wxString wxfacename = wxString.SafeNew(facename);
            wxString wxencoding = wxString.SafeNew(encoding);
      return wxFontEnumerator_OnFontEncoding(wxObject, Object.SafePtr(wxfacename), Object.SafePtr(wxencoding));
    }
    
    private bool DoOnFontEncoding(IntPtr facename, IntPtr encoding)
    {
      return OnFontEncoding(new wxString(facename, false), new wxString(encoding, false));
    }
    
    //---------------------------------------------------------------------
    
    public virtual bool EnumerateFacenames()
    {
      return this.EnumerateFacenames(FontEncoding.wxFONTENCODING_SYSTEM, false);
    }
    
    public virtual bool EnumerateFacenames(FontEncoding encoding)
    {
      return this.EnumerateFacenames(encoding, false);
    }
    
    public virtual bool EnumerateFacenames(FontEncoding encoding, bool fixedWidthOnly)
    {
      return wxFontEnumerator_EnumerateFacenames(wxObject, (int)encoding, fixedWidthOnly);
    }
    
    private bool DoEnumerateFacenames(int encoding, bool fixedWidthOnly)
    {
      return EnumerateFacenames((FontEncoding)encoding, fixedWidthOnly);
    }
    
    //---------------------------------------------------------------------
    
    public virtual bool EnumerateEncodings()
    {
      return EnumerateEncodings(null);
    }
    
    public virtual bool EnumerateEncodings(string facename)
    {
            wxString wxfacename = wxString.SafeNew(facename);
      return wxFontEnumerator_EnumerateEncodings(wxObject, Object.SafePtr(wxfacename));
    }
    
    private bool DoEnumerateEncodings(IntPtr facename)
    {
      return EnumerateEncodings(new wxString(facename));
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.