//-----------------------------------------------------------------------------
// wx.NET - ReflectCnofig.cs
//
// Some static methods to check compatibility of defines and availability of
// conditional code.
//
// (C) 2007 Harald Meyer auf'm Hofe
// Licensed under the wxWidgets license, see LICENSE.txt for details.
//
// $Id: ReflectConfig.cs,v 1.6 2007/11/18 19:33:48 harald_meyer Exp $
//-----------------------------------------------------------------------------
using System;
using System.Text;
using System.Runtime.InteropServices;
using System.Reflection;
/** \page page_ReflectConfig Runtime queries on the available configuration.
* \c wx.NET as well as the underlying \e wxWidgets library are highly configurable.
* The current configuration of the \e wxWidgets is specified by the used \c config.XX
* file in the \c build subdirectory. Additionally, \c wx.NET uses some defines to turn
* off certain wrappers. Usually, these defines have to be compatible with the configuration
* of the used compilation of the \e wxWidgets library.
*
* Class ReflectConfig provides some static methods for queries on the defines that have
* been used on compilation. These methods may be of some use in systems that load and unload
* assemblies dynamically. Additionally, this class provides method ReflectConfig.CheckCompatibility() to test
* whether \c wx.NET and \c wx-c.dll are compatible or not. An instance of this class is
* also added as an attribute of the assembly. so, users of \c wx.NET may analyse the
* assembly before use.
*
* Please note, that preprocessor symbols as defined for \c wx.NET have to fit those in \e wxWidgets.
* For instance, \c wxUSE_TAB_DIALOG shall rarely be used in \c wx.NET since this is an unrecommended
* setting in \e wxWidgets.
* */
namespace wx{
/** Class providing some methods to check availability of conditional code and compatiblity of \c wx.NET.dll and \c wx-c.dll.
*
* This class provides some static methods but is also an attribute of the assembly.
* So, laoders of this assembly may analyse this before use.
* */
[AttributeUsage(AttributeTargets.Assembly)]
public class ReflectConfig : Attribute
{
#region CAPI
[DllImport("wx-c")][return: MarshalAs(UnmanagedType.U1)]
static extern bool ReflectConfig_CheckWxMSW();
[DllImport("wx-c")][return: MarshalAs(UnmanagedType.U1)]
static extern bool ReflectConfig_CheckUseTabDialog();
[DllImport("wx-c")][return: MarshalAs(UnmanagedType.U1)]
static extern bool ReflectConfig_CheckUseUnicode();
[DllImport("wx-c")][return: MarshalAs(UnmanagedType.U1)]
static extern bool ReflectConfig_CheckWxMAC();
[DllImport("wx-c")][return: MarshalAs(UnmanagedType.U1)] static extern bool ReflectConfig_CheckWxGTK();
[DllImport("wx-c")][return: MarshalAs(UnmanagedType.U1)]
static extern bool ReflectConfig_CheckWxWinCompatibility26();
[DllImport("wx-c")][return: MarshalAs(UnmanagedType.U1)]
static extern bool ReflectConfig_CheckWxWinCompatibility24();
[DllImport("wx-c")][return: MarshalAs(UnmanagedType.U1)]
static extern bool ReflectConfig_CheckWxWinVersion28();
#endregion
//---------------------------------------------------------------------
#region CTor
/** This generates an attribute where the provided text is followed by a description of the conditional compilation.
* */
public ReflectConfig()
{
}
#endregion
#region Public Properties
/** \name These are the properties that one can read from the attribute.
* Instances of this class provide possibles attributes of this assembly.
* These properties define the information rovided by this attribute.
* Additionally, we have a ToString() method here that returns the
* ConfigurationString().
* */
//@{
//! Returns CheckWxWinCompatibility26().
public bool Compatibility26 { get { return CheckWxWinCompatibility26(); } }
//! Returns CheckWxWinCompatibility24().
public bool Compatibility24 { get { return CheckWxWinCompatibility24(); } }
//! Returns CheckWxWinVersion28().
public bool Version28 { get { return CheckWxWinVersion28(); } }
//! Returns CheckWxGTK().
public bool WxGTK { get { return CheckWxGTK(); } }
//! Returns CheckWxMSW().
public bool WxMSW { get { return CheckWxMSW(); } }
//! Returns CheckWxMAC().
public bool WxMAC { get { return CheckWxMAC(); } }
//! Returns CheckUseUnicode().
/*! This is true iff this is linked with a \e wxWidgets library with Unicode support.
*/
public bool UseUnicode { get { return CheckUseUnicode(); } }
//! Returns CheckUseTabDialog().
public bool UseTabCtrl { get { return CheckUseTabDialog(); } }
//! CheckWxNetDisplay().
public bool UseDisplay { get { return CheckWxNetDisplay(); } }
//! CheckStyledTextCtrl().
public bool UseStyledTextCtrl { get { return CheckStyledTextCtrl(); } }
public override string ToString()
{
return ConfigurationString();
}
//@}
#endregion
#region Static Public Methods
/** These static methods provide the information on the used configuration.
* These methods return information on the configuration of this assembly
* concerning conditional code. Several methods here will also query \c wx-c.dll.
* */
//@{
/** Test configuration according to \c WXWIN_COMPATIBILITY_2_6.
* This tests whether compatiblity features are provided by this assembly
* as well as the \c wx-c.dll.
**/
public static bool CheckWxWinCompatibility26()
{
#if WXWIN_COMPATIBILITY_2_6
return ReflectConfig_CheckWxWinCompatibility26();
#else
return false;
#endif
}
/** Test configuration according to \c WXWIN_COMPATIBILITY_2_4.
* This tests whether compatiblity features are provided by this assembly
* as well as the \c wx-c.dll.
**/
public static bool CheckWxWinCompatibility24()
{
#if WXWIN_COMPATIBILITY_2_4
return ReflectConfig_CheckWxWinCompatibility24();
#else
return false;
#endif
}
/** Tests whether the features introduced with \e wxWidgets 2.8.0 are available.
* */
public static bool CheckWxWinVersion28()
{
#if WXWIN_VERSION_2_8
return ReflectConfig_CheckWxWinVersion28();
#else
return false;
#endif
}
/** Test for availability of code particular for \c __WXGTK__.
* */
public static bool CheckWxGTK()
{
#if __WXGTK__
return ReflectConfig_CheckWxGTK();
#else
return false;
#endif
}
/** Test for availability of code particular for \c __WXMSW__.
* */
public static bool CheckWxMSW()
{
#if __WXMSW__
return ReflectConfig_CheckWxMSW();
#else
return false;
#endif
}
/** Test for availability of code particular for \c __WXMAC__.
* This is in fact rather a query whether code shall be avoided that cannot be provided
* for Apple Macintosh computers.
* */
public static bool CheckWxMAC()
{
#if __WXMAC__
return ReflectConfig_CheckWxMAC();
#else
return false;
#endif
}
/** Test for availability of \c WXNET_DISPLAY code.
* */
public static bool CheckWxNetDisplay()
{
#if WXNET_DISPLAY
return true;
#else
return false;
#endif
}
/** This tests for the availability of STC ( define \c WXNET_STYLEDTEXTCTRL ).
* */
public static bool CheckStyledTextCtrl()
{
#if WXNET_STYLEDTEXTCTRL
return true;
#else
return false;
#endif
}
/** This is \c true iff \e wx.NET implements the namespace \c wx.DataAccess.
* This feature is currently not directly supported by \c Portable.NET (cscc).
*/
public static bool CheckDbGrid()
{
#if __WXMSW__ || WXNET_DBGRID
return true;
#else
return false;
#endif
}
/** Checks for the availability of the TabCtrl class.
* This class is currently only available with CheckWxMSW().
* */
public static bool CheckUseTabDialog()
{
#if __WXMSW__ && wxUSE_TAB_DIALOG
return ReflectConfig_CheckUseTabDialog();
#else
return false;
#endif
}
/** Checks for the availability of Unicode support in the linked \e wxWidgets library.
* Currently, native Unicode support in \c wxString will not be used for conditional
* compilation but might be interest for if-then conditions in some code.
* */
public static bool CheckUseUnicode()
{
return ReflectConfig_CheckUseUnicode();
}
/** Runtime-check: Tests whether \c wx.NET does not require more features than \c wx-c.dll provides.
* Please note that unfortunately this cannot be tested for defines of \c wx.NET that do not have
* an equivalent in \c wxWidgets. These defines have the prefix \c WXNET_ .
*
* <em> If this is \c false then several classes cannot be used since they
* require functions in the \c wx-c.dll according to the \c wx.NET configuration
* that have not been compiled due to the configuration of the used \e wxWidgets
* system.</em>
* */
public static bool CheckCompatibility()
{
#if WXWIN_VERSION_2_8
if (!ReflectConfig_CheckWxWinVersion28()) return false;
#endif
#if WXWIN_COMPATIBILITY_2_4
if (!ReflectConfig_CheckWxWinCompatibility24()) return false;
#endif
#if WXWIN_COMPATIBILITY_2_6
if (!ReflectConfig_CheckWxWinCompatibility26()) return false;
#endif
return true;
}
/** This is \c true iff the \e wx.NET is configured for internal use of UTF 8 strings.
* This option is for instance relevant to the PNET implementation of the .NET framework.
*/
public static bool CheckInternalUseUTF8()
{
#if WXNET_INTERNAL_USE_UTF8
return true;
#else
return false;
#endif
}
/** Returns an english string describing the configuration.
* */
public static string ConfigurationString()
{
StringBuilder sb = new StringBuilder();
if (CheckWxWinVersion28())
sb.Append("Using version 2.8.X of the wxWidgets library.\n");
else
sb.Append("Using version 2.6.X of the wxWidgets library.\n");
if (CheckWxWinCompatibility26())
sb.Append("Includes compatibility pack for wxWidgets version 2.6.\n");
if (CheckWxWinCompatibility24())
sb.Append("Includes compatibility pack for wxWidgets version 2.4.\n");
if (CheckWxGTK())
sb.Append("Compiled for using GTK.\n");
if (CheckWxMSW())
sb.Append("Compiled for Windows TM systems.\n");
if (CheckWxMAC())
sb.Append("Compiled for using Apple MACs.\n");
if (CheckUseUnicode())
sb.Append("Full Unicode support.\n");
else
sb.Append("Supporting ANSI characters only.");
if (CheckInternalUseUTF8())
{
sb.Append("Expecting the .NET framework to use UTF 8 internally.");
}
if (CheckWxNetDisplay() || CheckStyledTextCtrl() || CheckUseTabDialog())
{
sb.Append("Extras: ");
bool separator = false;
if (CheckStyledTextCtrl())
{
if (separator) sb.Append(", ");
sb.Append("styled text control");
separator = true;
}
if (CheckWxNetDisplay())
{
if (separator) sb.Append(", ");
sb.Append("managament of multiple displays");
separator = true;
}
if (CheckUseTabDialog())
{
if (separator) sb.Append(", ");
sb.Append("tabbed control");
separator = true;
}
}
return sb.ToString();
}
//@}
#endregion
}
}
|