initial commit

Signed-off-by: Peter Siegmund <mars3142@noreply.mars3142.dev>
This commit is contained in:
2025-10-31 23:37:30 +01:00
commit bf6b52fd94
9654 changed files with 4035664 additions and 0 deletions

View File

@@ -0,0 +1,112 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/msw/darkmode.h
// Purpose: Documentation for MSW-specific dark mode functionality.
// Author: Vadim Zeitlin
// Created: 2023-02-19
// Copyright: (c) 2023 Vadim Zeitlin
// Licence: wxWindows Licence
/////////////////////////////////////////////////////////////////////////////
/**
Constants used with wxDarkModeSettings::GetMenuColour().
@since 3.3.0
*/
enum class wxMenuColour
{
/// Text colour used for the normal items in dark mode.
StandardFg,
/// Standard menu background colour.
StandardBg,
/// Foreground colour for the disabled items.
DisabledFg,
/// Background colour used for the item over which mouse is hovering.
HotBg
};
/**
Allows to customize some of the settings used in MSW dark mode.
An object of this class may be passed to wxApp::MSWEnableDarkMode() to
customize some aspects of the dark mode when it is used under MSW systems.
For example, to customize the background colour to use a reddish black
instead of normal black used by default, you could do the following:
@code
class MySettings : public wxDarkModeSettings
{
public:
wxColour GetColour(wxSystemColour index) override
{
switch ( index )
{
case wxSYS_COLOUR_ACTIVECAPTION:
case wxSYS_COLOUR_APPWORKSPACE:
case wxSYS_COLOUR_INFOBK:
case wxSYS_COLOUR_LISTBOX:
case wxSYS_COLOUR_WINDOW:
case wxSYS_COLOUR_BTNFACE:
// Default colour used here is 0x202020.
return wxColour(0x402020);
default:
return wxDarkModeSettings::GetColour(index);
}
}
};
wxTheApp->MSWEnableDarkMode(wxApp::DarkMode_Always, new MySettings());
@endcode
@since 3.3.0
*/
class wxDarkModeSettings
{
public:
/**
Default constructor does nothing.
*/
wxDarkModeSettings() = default;
/**
Get the colour to use for the given system colour when dark mode is on.
The base class version of this function returns the colours commonly
used in dark mode. As the rest of dark mode support, their exact values
are not documented and are subject to change in the future Windows or
wxWidgets versions.
@see GetMenuColour()
*/
virtual wxColour GetColour(wxSystemColour index);
/**
Get the colour to use for the menu bar in the given state.
Currently the colours used by the menus in the menu bar in dark mode
don't correspond to any of wxSystemColour values and this separate
function is used for customizing them instead of GetColour().
Note that the colours returned by this function only affect the top
level menus, the colours of the menu items inside them can be
customized in the usual way using wxOwnerDrawn::SetTextColour().
The returned colour must be valid.
*/
virtual wxColour GetMenuColour(wxMenuColour which);
/**
Get the pen to use for drawing wxStaticBox border in dark mode.
Returning an invalid pen indicates that the default border drawn by the
system should be used, which doesn't look very well in dark mode but
shouldn't result in any problems worse than cosmetic ones.
The base class version returns a grey pen, which looks better than the
default white one.
*/
virtual wxPen GetBorderPen();
};

View File

@@ -0,0 +1,313 @@
/////////////////////////////////////////////////////////////////////////////
// Name: msw/ole/activex.h
// Purpose: interface of wxActiveXEvent
// Author: wxWidgets team
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
/**
@class wxActiveXEvent
An event class for handling ActiveX events passed from wxActiveXContainer.
ActiveX events are basically a function call with the parameters passed
through an array of wxVariants along with a return value that is a wxVariant
itself. What type the parameters or return value are depends on the context
(i.e. what the .idl specifies).
@beginEventTable{wxActiveXEvent}
@event{EVT_ACTIVEX(func)}
Sent when the ActiveX control hosted by wxActiveXContainer receives an
ActiveX event.
@endEventTable
ActiveX event parameters can get extremely complex and may be beyond the
abilities of wxVariant. If 'operator[]' fails, prints an error messages or
crashes the application, event handlers should use GetNativeParameters()
instead to obtain the original event information.
Calls to operator[] and GetNativeParmeters() can be mixed. It is valid
to handle some parameters of an event with operator[] and others directly
through GetNativeParameters(). It is \b not valid however to manipulate
the same parameter using both approaches at the same time.
@onlyfor{wxmsw}
@library{wxcore}
@category{events}
*/
class wxActiveXEvent : public wxCommandEvent
{
public:
/**
Returns the dispatch id of this ActiveX event.
This is the numeric value from the .idl file specified by the id().
*/
DISPID GetDispatchId(int idx) const;
/**
Obtains the number of parameters passed through the ActiveX event.
*/
size_t ParamCount() const;
/**
Obtains the param name of the param number idx specifies as a string.
*/
wxString ParamName(size_t idx) const;
/**
Obtains the param type of the param number idx specifies as a string.
*/
wxString ParamType(size_t idx) const;
/**
Obtains the actual parameter value specified by idx.
*/
wxVariant operator[](size_t idx);
/**
Obtain the original MSW parameters for the event.
Event handlers can use this information to handle complex event parameters
that are beyond the scope of wxVariant.
The information returned here is the information passed to the original
'Invoke' method call.
\return a pointer to a struct containing the original MSW event parameters
*/
wxActiveXEventNativeMSW *GetNativeParameters() const;
};
/**
@class wxActiveXContainer
wxActiveXContainer is a host for an ActiveX control on Windows (and as such
is a platform-specific class).
Note that the HWND that the class contains is the actual HWND of the ActiveX
control so using dynamic events and connecting to @c wxEVT_SIZE, for example,
will receive the actual size message sent to the control.
It is somewhat similar to the ATL class CAxWindow in operation.
The size of the ActiveX control's content is generally guaranteed to be that
of the client size of the parent of this wxActiveXContainer.
You can also process ActiveX events through wxActiveXEvent.
@section activexcontainer_example Example
This is an example of how to use the Adobe Acrobat Reader ActiveX control to
read PDF files (requires Acrobat Reader 4 and up).
Controls like this are typically found and dumped from OLEVIEW.exe that is
distributed with Microsoft Visual C++.
This example also demonstrates how to create a backend for wxMediaCtrl.
@code
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// wxPDFMediaBackend
//
// http://partners.adobe.com/public/developer/en/acrobat/sdk/pdf/iac/IACOverview.pdf
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include "wx/mediactrl.h" // wxMediaBackendCommonBase
#include "wx/msw/ole/activex.h" // wxActiveXContainer
#include "wx/msw/ole/automtn.h" // wxAutomationObject
const IID DIID__DPdf = {0xCA8A9781,0x280D,0x11CF,{0xA2,0x4D,0x44,0x45,0x53,0x54,0x00,0x00}};
const IID DIID__DPdfEvents = {0xCA8A9782,0x280D,0x11CF,{0xA2,0x4D,0x44,0x45,0x53,0x54,0x00,0x00}};
const CLSID CLSID_Pdf = {0xCA8A9780,0x280D,0x11CF,{0xA2,0x4D,0x44,0x45,0x53,0x54,0x00,0x00}};
class WXDLLIMPEXP_MEDIA wxPDFMediaBackend : public wxMediaBackendCommonBase
{
public:
wxPDFMediaBackend() : m_pAX(nullptr) {}
virtual ~wxPDFMediaBackend()
{
if(m_pAX)
{
m_pAX->DissociateHandle();
delete m_pAX;
}
}
virtual bool CreateControl(wxControl* ctrl, wxWindow* parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxValidator& validator,
const wxString& name)
{
IDispatch* pDispatch;
if( ::CoCreateInstance(CLSID_Pdf, nullptr,
CLSCTX_INPROC_SERVER,
DIID__DPdf, (void**)&pDispatch) != 0 )
return false;
m_PDF.SetDispatchPtr(pDispatch); // wxAutomationObject will release itself
if ( !ctrl->wxControl::Create(parent, id, pos, size,
(style & ~wxBORDER_MASK) | wxBORDER_NONE,
validator, name) )
return false;
m_ctrl = wxStaticCast(ctrl, wxMediaCtrl);
m_pAX = new wxActiveXContainer(ctrl,
DIID__DPdf,
pDispatch);
wxPDFMediaBackend::ShowPlayerControls(wxMEDIACTRLPLAYERCONTROLS_NONE);
return true;
}
virtual bool Play()
{
return true;
}
virtual bool Pause()
{
return true;
}
virtual bool Stop()
{
return true;
}
virtual bool Load(const wxString& fileName)
{
if(m_PDF.CallMethod("LoadFile", fileName).GetBool())
{
m_PDF.CallMethod("setCurrentPage", wxVariant((long)0));
NotifyMovieLoaded(); // initial refresh
wxSizeEvent event;
m_pAX->OnSize(event);
return true;
}
return false;
}
virtual bool Load(const wxURI& location)
{
return m_PDF.CallMethod("LoadFile", location.BuildUnescapedURI()).GetBool();
}
virtual bool Load(const wxURI& WXUNUSED(location),
const wxURI& WXUNUSED(proxy))
{
return false;
}
virtual wxMediaState GetState()
{
return wxMEDIASTATE_STOPPED;
}
virtual bool SetPosition(wxLongLong where)
{
m_PDF.CallMethod("setCurrentPage", wxVariant((long)where.GetValue()));
return true;
}
virtual wxLongLong GetPosition()
{
return 0;
}
virtual wxLongLong GetDuration()
{
return 0;
}
virtual void Move(int WXUNUSED(x), int WXUNUSED(y),
int WXUNUSED(w), int WXUNUSED(h))
{
}
wxSize GetVideoSize() const
{
return wxDefaultSize;
}
virtual double GetPlaybackRate()
{
return 0;
}
virtual bool SetPlaybackRate(double)
{
return false;
}
virtual double GetVolume()
{
return 0;
}
virtual bool SetVolume(double)
{
return false;
}
virtual bool ShowPlayerControls(wxMediaCtrlPlayerControls flags)
{
if(flags)
{
m_PDF.CallMethod("setShowToolbar", true);
m_PDF.CallMethod("setShowScrollbars", true);
}
else
{
m_PDF.CallMethod("setShowToolbar", false);
m_PDF.CallMethod("setShowScrollbars", false);
}
return true;
}
wxActiveXContainer* m_pAX;
wxAutomationObject m_PDF;
wxDECLARE_DYNAMIC_CLASS(wxPDFMediaBackend);
};
wxIMPLEMENT_DYNAMIC_CLASS(wxPDFMediaBackend, wxMediaBackend);
// Put this in one of your existing source files and then create a wxMediaCtrl with
wxMediaCtrl* mymediactrl = new wxMediaCtrl(this, "myfile.pdf", wxID_ANY,
wxDefaultPosition, wxSize(300,300),
0, "wxPDFMediaBackend");
// [this] is the parent window, "myfile.pdf" is the PDF file to open
@endcode
@onlyfor{wxmsw}
@library{wxcore}
@category{ctrl,ipc}
@see wxActiveXEvent
*/
class wxActiveXContainer : public wxControl
{
public:
/**
Creates this ActiveX container.
@param parent
parent of this control. Must not be @NULL.
@param iid
COM IID of pUnk to query. Must be a valid interface to an ActiveX control.
@param pUnk
Interface of ActiveX control.
*/
wxActiveXContainer(wxWindow* parent, REFIID iid, IUnknown* pUnk);
/**
Queries host's site for interface.
@param iid
The iid of the required interface.
@param _interface
Double pointer to outgoing interface. Supply your own interface if desired.
@param desc
The description of the outgoing interface.
@return bool
Return true if interface supplied else return false.
*/
virtual bool QueryClientSiteInterface(REFIID iid, void **_interface, const char *&desc);
};

View File

@@ -0,0 +1,326 @@
/////////////////////////////////////////////////////////////////////////////
// Name: msw/ole/automtn.h
// Purpose: interface of wxAutomationObject
// Author: wxWidgets team
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
/**
Automation object creation flags.
These flags can be used with wxAutomationObject::GetInstance().
@since 2.9.2
*/
enum wxAutomationInstanceFlags
{
/**
Only use the existing instance, never create a new one.
This flag can be used to forbid the creation of a new instance if none
is currently running.
*/
wxAutomationInstance_UseExistingOnly = 0,
/**
Create a new instance if there are no existing ones.
This flag corresponds to the default behaviour of
wxAutomationObject::GetInstance() and means that if getting an existing
instance failed, we should call wxAutomationObject::CreateInstance() to
create a new one.
*/
wxAutomationInstance_CreateIfNeeded = 1,
/**
Do not show an error message if no existing instance is currently
running.
All other errors will still be reported as usual.
*/
wxAutomationInstance_SilentIfNone = 2
};
/**
@class wxAutomationObject
The @b wxAutomationObject class represents an OLE automation object containing
a single data member,
an @c IDispatch pointer. It contains a number of functions that make it easy to
perform
automation operations, and set and get properties. The class makes heavy use of
the wxVariant class.
The usage of these classes is quite close to OLE automation usage in Visual
Basic. The API is
high-level, and the application can specify multiple properties in a single
string. The following example
gets the current Microsoft Excel instance, and if it exists, makes the active cell bold.
@code
wxAutomationObject excelObject;
if ( excelObject.GetInstance("Excel.Application") )
excelObject.PutProperty("ActiveCell.Font.Bold", true);
@endcode
Note that this class obviously works under Windows only.
@onlyfor{wxmsw}
@library{wxcore}
@category{data}
@see wxVariant, wxVariantDataCurrency, wxVariantDataErrorCode, wxVariantDataSafeArray
*/
class wxAutomationObject : public wxObject
{
public:
/**
Constructor, taking an optional @c IDispatch pointer which will be released when
the
object is deleted.
*/
wxAutomationObject(WXIDISPATCH* dispatchPtr = nullptr);
/**
Destructor. If the internal @c IDispatch pointer is non-null, it will be released.
*/
~wxAutomationObject();
//@{
/**
Calls an automation method for this object. The first form takes a method name,
number of
arguments, and an array of variants. The second form takes a method name and
zero to six
constant references to variants. Since the variant class has constructors for
the basic
data types, and C++ provides temporary objects automatically, both of the
following lines
are syntactically valid:
@code
wxVariant res = obj.CallMethod("Sum", wxVariant(1.2), wxVariant(3.4));
wxVariant res = obj.CallMethod("Sum", 1.2, 3.4);
@endcode
Note that @a method can contain dot-separated property names, to save the
application
needing to call GetProperty() several times using several temporary objects. For
example:
@code
object.CallMethod("ActiveWorkbook.ActiveSheet.Protect", "MyPassword");
@endcode
*/
wxVariant CallMethod(const wxString& method, int noArgs,
wxVariant args[]) const;
wxVariant CallMethod(const wxString& method, ... ) const;
//@}
/**
Creates a new object based on the @a progID, returning @true if the object was
successfully created,
or @false if not.
@see GetInstance()
*/
bool CreateInstance(const wxString& progId) const;
/**
Checks if the object is in a valid state.
Returns @true if the object was successfully initialized or @false if
it has no valid @c IDispatch pointer.
@see GetDispatchPtr()
*/
bool IsOk() const;
/**
Gets the @c IDispatch pointer.
Notice that the return value of this function is an untyped pointer but
it can be safely cast to @c IDispatch.
*/
WXIDISPATCH* GetDispatchPtr() const;
/**
Retrieves the current object associated with the specified ProgID, and
attaches the @c IDispatch pointer to this object.
If attaching to an existing object failed and @a flags includes
::wxAutomationInstance_CreateIfNeeded flag, a new object will be created.
Otherwise this function will normally log an error message which may be
undesirable if the object may or may not exist. The
::wxAutomationInstance_SilentIfNone flag can be used to prevent the error
from being logged in this case.
Returns @true if a pointer was successfully retrieved, @false
otherwise.
Note that this cannot cope with two instances of a given OLE object being
active simultaneously,
such as two copies of Microsoft Excel running. Which object is referenced cannot
currently be specified.
@param progId COM ProgID, e.g. "Excel.Application"
@param flags The creation flags (this parameters was added in wxWidgets
2.9.2)
@see CreateInstance()
*/
bool GetInstance(const wxString& progId,
int flags = wxAutomationInstance_CreateIfNeeded) const;
/**
Retrieves a property from this object, assumed to be a dispatch pointer, and
initialises @a obj with it.
To avoid having to deal with @c IDispatch pointers directly, use this function in
preference
to GetProperty() when retrieving objects
from other objects.
Note that an @c IDispatch pointer is stored as a @c void* pointer in wxVariant
objects.
@see GetProperty()
*/
bool GetObject(wxAutomationObject& obj, const wxString& property,
int noArgs = 0,
wxVariant args[] = nullptr) const;
//@{
/**
Gets a property value from this object. The first form takes a property name,
number of
arguments, and an array of variants. The second form takes a property name and
zero to six
constant references to variants. Since the variant class has constructors for
the basic
data types, and C++ provides temporary objects automatically, both of the
following lines
are syntactically valid:
@code
wxVariant res = obj.GetProperty("Range", wxVariant("A1"));
wxVariant res = obj.GetProperty("Range", "A1");
@endcode
Note that @a property can contain dot-separated property names, to save the
application
needing to call GetProperty several times using several temporary objects.
@see GetObject(), PutProperty()
*/
wxVariant GetProperty(const wxString& property, int noArgs,
wxVariant args[]) const;
wxVariant GetProperty(const wxString& property, ... ) const;
//@}
/**
This function is a low-level implementation that allows access to the @c IDispatch
Invoke function.
It is not meant to be called directly by the application, but is used by other
convenience functions.
@param member
The member function or property name.
@param action
Bitlist: may contain @c DISPATCH_PROPERTYPUT, @c DISPATCH_PROPERTYPUTREF,
@c DISPATCH_PROPERTYGET, @c DISPATCH_METHOD.
@param retValue
Return value (ignored if there is no return value)
@param noArgs
Number of arguments in args or ptrArgs.
@param args
If non-null, contains an array of variants.
@param ptrArgs
If non-null, contains an array of constant pointers to variants.
@return @true if the operation was successful, @false otherwise.
@remarks Two types of argument array are provided, so that when possible
pointers are used for efficiency.
*/
bool Invoke(const wxString& member, int action,
wxVariant& retValue, int noArgs,
wxVariant args[],
const wxVariant* ptrArgs[] = 0) const;
//@{
/**
Puts a property value into this object. The first form takes a property name,
number of
arguments, and an array of variants. The second form takes a property name and
zero to six
constant references to variants. Since the variant class has constructors for
the basic
data types, and C++ provides temporary objects automatically, both of the
following lines
are syntactically valid:
@code
obj.PutProperty("Value", wxVariant(23));
obj.PutProperty("Value", 23);
@endcode
Note that @a property can contain dot-separated property names, to save the
application
needing to call GetProperty() several times using several temporary objects.
*/
bool PutProperty(const wxString& property, int noArgs,
wxVariant args[]);
bool PutProperty(const wxString& property, ... );
//@}
/**
Sets the @c IDispatch pointer, does not check if there is already one.
You may need to cast from @c IDispatch* to @c WXIDISPATCH* when calling this function.
*/
void SetDispatchPtr(WXIDISPATCH* dispatchPtr);
/**
Returns the locale identifier used in automation calls.
The default is @c LOCALE_SYSTEM_DEFAULT but the objects obtained by
GetObject() inherit the locale identifier from the one that created
them.
@since 2.9.5
*/
WXLCID GetLCID() const;
/**
Sets the locale identifier to be used in automation calls performed by
this object.
The default value is @c LOCALE_SYSTEM_DEFAULT.
Notice that any automation objects created by this one inherit the same
@c LCID.
@since 2.9.5
*/
void SetLCID(WXLCID lcid);
/**
Returns the flags used for conversions between wxVariant and OLE
@c VARIANT, see #wxOleConvertVariantFlags.
The default value is ::wxOleConvertVariant_Default for compatibility but
it can be changed using SetConvertVariantFlags().
Notice that objects obtained by GetObject() inherit the flags from the
one that created them.
@since 3.0
*/
long GetConvertVariantFlags() const;
/**
Sets the flags used for conversions between wxVariant and OLE @c VARIANT,
see #wxOleConvertVariantFlags.
The default value is ::wxOleConvertVariant_Default.
@since 3.0
*/
void SetConvertVariantFlags(long flags);
};

View File

@@ -0,0 +1,374 @@
/////////////////////////////////////////////////////////////////////////////
// Name: msw/ole/oleutils.h
// Purpose: interface of OLE helpers
// Author: wxWidgets team
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
/**
Flags used for conversions between wxVariant and OLE @c VARIANT.
These flags are used by wxAutomationObject for its wxConvertOleToVariant()
calls. They can be obtained by wxAutomationObject::GetConvertVariantFlags()
and set by wxAutomationObject::SetConvertVariantFlags().
@since 3.0
@see wxVariantDataSafeArray
*/
enum wxOleConvertVariantFlags
{
/**
Default value.
*/
wxOleConvertVariant_Default = 0,
/**
If this flag is used, SAFEARRAYs contained in OLE @c VARIANTs will be
returned as wxVariants with wxVariantDataSafeArray type instead of
wxVariants with the list type containing the (flattened) SAFEARRAY's
elements.
*/
wxOleConvertVariant_ReturnSafeArrays = 1
};
/**
@class wxVariantDataCurrency
This class represents a thin wrapper for Microsoft Windows @c CURRENCY type.
It is used for converting between wxVariant and OLE @c VARIANT
with type set to @c VT_CURRENCY. When wxVariant stores
wxVariantDataCurrency, it returns "currency" as its type.
An example of setting and getting @c CURRENCY value to and from wxVariant:
@code
CURRENCY cy;
wxVariant variant;
// set wxVariant to currency type
if ( SUCCEEDED(VarCyFromR8(123.45, &cy)) ) // set cy to 123.45
{
variant.SetData(new wxVariantDataCurrency(cy));
// or instead of the line above you could write:
// wxVariantDataCurrency wxCy;
// wxCy.SetValue(cy);
// variant.SetData(wxCy.Clone());
}
// get CURRENCY value from wxVariant
if ( variant.GetType() == "currency" )
{
wxVariantDataCurrency*
wxCy = wxDynamicCastVariantData(variant.GetData(), wxVariantDataCurrency);
cy = wxCy->GetValue();
}
@endcode
@onlyfor{wxmsw}
@since 2.9.5
@library{wxcore}
@category{data}
@see wxAutomationObject, wxVariant, wxVariantData, wxVariantDataErrorCode
*/
class wxVariantDataCurrency : public wxVariantData
{
public:
/**
Default constructor initializes the object to 0.0.
*/
wxVariantDataCurrency();
/**
Constructor from CURRENCY.
*/
wxVariantDataCurrency(CURRENCY value);
/**
Returns the stored CURRENCY value.
*/
CURRENCY GetValue() const;
/**
Sets the stored value to @a value.
*/
void SetValue(CURRENCY value);
/**
Returns @true if @a data is of wxVariantDataCurency type
and contains the same CURRENCY value.
*/
virtual bool Eq(wxVariantData& data) const;
/**
Fills the provided string with the textual representation of this
object.
The implementation of this method uses @c VarBstrFromCy() Windows API
function with @c LOCALE_USER_DEFAULT.
*/
virtual bool Write(wxString& str) const;
/**
Returns a copy of itself.
*/
wxVariantData* Clone() const;
/**
Returns "currency".
*/
virtual wxString GetType() const;
/**
Converts the value of this object to wxAny.
*/
virtual bool GetAsAny(wxAny* any) const;
};
/**
@class wxVariantDataErrorCode
This class represents a thin wrapper for Microsoft Windows @c SCODE type
(which is the same as @c HRESULT).
It is used for converting between a wxVariant and OLE @c VARIANT with type set
to @c VT_ERROR. When wxVariant stores wxVariantDataErrorCode, it returns
"errorcode" as its type. This class can be used for returning error codes
of automation calls or exchanging values with other applications: e.g.
Microsoft Excel returns VARIANTs with @c VT_ERROR type for cell values with
errors (one of XlCVError constants, displayed as e.g. "#DIV/0!" or "#REF!"
there) etc. See wxVariantDataCurrency for an example of how to exchange
values between wxVariant and a native type not directly supported by it.
@onlyfor{wxmsw}
@since 2.9.5
@library{wxcore}
@category{data}
@see wxAutomationObject, wxVariant, wxVariantData, wxVariantDataCurrency
*/
class wxVariantDataErrorCode : public wxVariantData
{
public:
/**
Constructor initializes the object to @a value or @c S_OK if no value was
passed.
*/
wxVariantDataErrorCode(SCODE value = S_OK);
/**
Returns the stored @c SCODE value.
*/
SCODE GetValue() const;
/**
Set the stored value to @a value.
*/
void SetValue(SCODE value);
/**
Returns @true if @a data is of wxVariantDataErrorCode type
and contains the same @c SCODE value.
*/
virtual bool Eq(wxVariantData& data) const;
/**
Fills the provided string with the textual representation of this
object.
The error code is just a number, so it's output as such.
*/
virtual bool Write(wxString& str) const;
/**
Returns a copy of itself.
*/
wxVariantData* Clone() const;
/**
Returns "errorcode".
*/
virtual wxString GetType() const { return wxS("errorcode"); }
/**
Converts the value of this object to wxAny.
*/
virtual bool GetAsAny(wxAny* any) const;
};
/**
@class wxVariantDataSafeArray
This class stores @c SAFEARRAY in a wxVariant. It can be used
to pass arrays having more than one dimension with wxAutomationObject methods.
When wxVariant stores wxVariantDataSafeArray, it returns "safearray" as its type.
wxVariantDataSafeArray does NOT manage the @c SAFEARRAY it points to.
If you want to pass it to a wxAutomationObject as a parameter:
-# Create and fill a @c SAFEARRAY.
-# Assign the @c SAFEARRAY pointer to it and store it in a wxVariant.
-# Call a wxAutomationObject method (such as CallMethod() or PutProperty()) with the wxVariant as a parameter.
-# wxAutomationObject will destroy the array after the automation call.
An example of creating a two-dimensional @c SAFEARRAY containing <tt>VARIANT</tt>s
and storing it in a wxVariant, using a utility class wxSafeArray<varType>.
@code
const size_t dimensions = 2;
const long rowCount = 1000;
const long columnCount = 20;
SAFEARRAYBOUND bounds[dimensions];
wxSafeArray<VT_VARIANT> safeArray;
bounds[0].lLbound = 0; // elements start at 0
bounds[0].cElements = rowCount;
bounds[1].lLbound = 0; // elements start at 0
bounds[1].cElements = columnCount;
if ( !safeArray.Create(bounds, dimensions) )
return false;
long indices[dimensions];
for ( long row = 0; row < rowCount; ++row )
{
indices[0] = row;
for ( long column = 0; column < columnCount; ++column )
{
indices[1] = column;
if ( !safeArray.SetElement(indices, wxString::Format("R%u C%u", row, column)) )
return false;
}
}
range.PutProperty("Value", wxVariant(new wxVariantDataSafeArray(safeArray.Detach())));
@endcode
If you want to receive a @c SAFEARRAY in a wxVariant as a result of a wxAutomationObject
call:
-# Call wxAutomationObject::SetConvertVariantFlags() with parameter
::wxOleConvertVariant_ReturnSafeArrays (otherwise the data would be
sent as a flattened one-dimensional list).
-# Call a wxAutomationObject method (such as CallMethod() or GetProperty()).
-# Retrieve the @c SAFEARRAY from the returned wxVariant.
-# Process the data in the @c SAFEARRAY.
-# Destroy the @c SAFEARRAY when you no longer need it.
The following example shows how to process a two-dimensional @c SAFEARRAY
with @c VT_VARIANT type received from a wxAutomationObject call,
using a utility class wxSafeArray<varType>.
@code
const size_t dimensions = 2;
wxVariant result;
range.SetConvertVariantFlags(wxOleConvertVariant_ReturnSafeArrays);
result = range.GetProperty("Value");
if ( !result.IsType("safearray") )
return false;
wxSafeArray<VT_VARIANT> safeArray;
wxVariantDataSafeArray* const
sa = wxStaticCastVariantData(result.GetData(), wxVariantDataSafeArray);
if ( !safeArray.Attach(sa->GetValue()) )
{
if ( !safeArray.HasArray() )
::SafeArrayDestroy(sa->GetValue()); // we have to dispose the SAFEARRAY ourselves
return false;
}
if ( safeArray.GetDim() != dimensions ) // we are expecting 2 dimensions
return false; // SAFEARRAY will be disposed by safeArray's dtor
long rowStart, columnStart;
long rowCount, columnCount;
long indices[dimensions];
wxVariant value;
// get start indices and item counts for rows and columns
safeArray.GetLBound(1, rowStart);
safeArray.GetLBound(2, columnStart);
safeArray.GetUBound(1, rowCount);
safeArray.GetUBound(2, columnCount);
for ( long row = rowStart; row <= rowCount; ++row )
{
indices[0] = row;
for ( long column = columnStart; column <= columnCount; ++column )
{
indices[1] = column;
if ( !safeArray.GetElement(indices, value) )
return false;
// do something with value
}
}
// SAFEARRAY will be disposed by safeArray's dtor
@endcode
@onlyfor{wxmsw}
@since 2.9.5
@library{wxcore}
@category{data}
@see wxAutomationObject, wxSafeArray<varType>, wxVariant, wxVariantData
*/
class wxVariantDataSafeArray : public wxVariantData
{
public:
/**
Constructor initializes the object to @a value.
*/
explicit wxVariantDataSafeArray(SAFEARRAY* value = nullptr);
/**
Returns the stored array.
*/
SAFEARRAY* GetValue() const;
/**
Set the stored array.
*/
void SetValue(SAFEARRAY* value);
/**
Returns @true if @a data is of wxVariantDataSafeArray type
and contains the same SAFEARRAY* value.
*/
virtual bool Eq(wxVariantData& data) const;
/**
Fills the provided string with the textual representation of this
object.
Only the address of @c SAFEARRAY pointer is output.
*/
virtual bool Write(wxString& str) const;
/**
Returns a copy of itself.
*/
wxVariantData* Clone() const;
/**
Returns "safearray".
*/
virtual wxString GetType() const;
/**
Converts the value of this object to wxAny.
*/
virtual bool GetAsAny(wxAny* any) const;
};

View File

@@ -0,0 +1,184 @@
/////////////////////////////////////////////////////////////////////////////
// Name: msw/ole/automtn.h
// Purpose: interface of wxSafeArray
// Author: wxWidgets team
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
/**
@class wxSafeArray<varType>
wxSafeArray<varType> is wxWidgets wrapper for working with MS Windows @c
SAFEARRAY used in Component Object Model (COM) and OLE Automation APIs.
It also has convenience functions for converting between @c SAFEARRAY and
wxVariant with list type or wxArrayString.
wxSafeArray is a template class which must be created with an appropriate
type matching the underlying @c VARIANT type (such as @c VT_VARIANT or @c
VT_BSTR).
See wxVariantDataSafeArray documentation for examples of using it.
@onlyfor{wxmsw}
@since 3.0
@library{wxcore}
@category{data}
@see wxAutomationObject, wxVariantDataSafeArray, wxVariant
*/
template <VARTYPE varType>
class wxSafeArray<varType>
{
public:
/**
The default constructor.
*/
wxSafeArray();
/**
The destructor unlocks and destroys the owned @c SAFEARRAY.
*/
~wxSafeArray();
/**
Creates and locks a zero-based one-dimensional @c SAFEARRAY with the
given number of elements.
*/
bool Create(size_t count);
/**
Creates and locks a @c SAFEARRAY.
See @c SafeArrayCreate() in MSDN documentation for more information.
*/
bool Create(SAFEARRAYBOUND* bound, size_t dimensions);
/**
Creates a zero-based one-dimensional @c SAFEARRAY from wxVariant
with the list type.
Can be called only for wxSafeArray<@c VT_VARIANT>.
*/
bool CreateFromListVariant(const wxVariant& variant);
/**
Creates a zero-based one-dimensional @c SAFEARRAY from wxArrayString.
Can be called only for wxSafeArray<@c VT_BSTR>.
*/
bool CreateFromArrayString(const wxArrayString& strings);
/**
Attaches and locks an existing @c SAFEARRAY.
The array must have the same @c VARTYPE as this wxSafeArray was
instantiated with.
*/
bool Attach(SAFEARRAY* array);
/**
Unlocks the owned @c SAFEARRAY, returns it and gives up its ownership.
*/
SAFEARRAY* Detach();
/**
Unlocks and destroys the owned @c SAFEARRAY.
*/
void Destroy();
/**
Returns @true if it has a valid @c SAFEARRAY.
*/
bool HasArray() const { return m_array != nullptr; }
/**
Returns the number of dimensions.
*/
size_t GetDim() const;
/**
Returns lower bound for dimension @a dim in @a bound.
Dimensions start at @c 1.
*/
bool GetLBound(size_t dim, long& bound) const;
/**
Returns upper bound for dimension @a dim in @a bound.
Dimensions start at @c 1.
*/
bool GetUBound(size_t dim, long& bound) const;
/**
Returns element count for dimension @a dim. Dimensions start at @c 1.
*/
size_t GetCount(size_t dim) const;
/**
Change the value of the specified element.
@a indices have the same row-column order as @c rgIndices i
@c SafeArrayPutElement(), i.e., the right-most dimension is
<tt>rgIndices[0]</tt> and the left-most dimension is stored at
<tt>rgIndices[</tt>GetDim()<tt> 1]</tt>.
@a element must be of type matching @c varType this wxSafeArray was
created with. For example, wxString for wxSafeArray<@c VT_BSTR>,
wxVariant for wxSafeArray<@c VT_VARIANT>, or @c double for
wxSafeArray<@c VT_R8>.
*/
bool SetElement(long* indices, const externT& element);
/**
Retrieve the value of the specified element.
@a indices have the same row-column order as @c rgIndices in
@c SafeArrayGetElement(), i.e., the right-most dimension is
<tt>rgIndices[0]</tt> and the left-most dimension is stored at
<tt>rgIndices[</tt>GetDim()<tt> 1]</tt>.
@a element must be of type matching @c varType this wxSafeArray was
created with. For example, wxString for wxSafeArray<@c VT_BSTR>,
wxVariant for wxSafeArray<@c VT_VARIANT>, or @c double for
wxSafeArray<@c VT_R8>.
*/
bool GetElement(long* indices, externT& element) const;
/**
Converts the array to a wxVariant with the list type, regardless of the
underlying @c SAFEARRAY type.
If the array is multidimensional, it is flattened using the algorithm
originally employed in wxConvertOleToVariant().
*/
bool ConvertToVariant(wxVariant& variant) const;
/**
Converts an array to wxArrayString.
Can be called only for wxSafeArray<@c VT_BSTR>. If the array is
multidimensional, it is flattened using the algorithm originally
employed in wxConvertOleToVariant().
*/
bool ConvertToArrayString(wxArrayString& strings) const;
/**
Converts @a psa to wxVariant.
@see wxSafeArray<varType>::ConvertToVariant(wxVariant&) const
*/
static bool ConvertToVariant(SAFEARRAY* psa, wxVariant& variant);
/**
Converts @a psa to wxArrayString.
@see wxSafeArray<varType>::ConvertToArrayString(wxArrayString&) const
*/
static bool ConvertToArrayString(SAFEARRAY* psa, wxArrayString& strings);
};

View File

@@ -0,0 +1,38 @@
/////////////////////////////////////////////////////////////////////////////
// Name: regconf.h
// Purpose: interface of wxRegConfig
// Author: wxWidgets team
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
/**
@class wxRegConfig
wxRegConfig implements the wxConfigBase interface for
storing and retrieving configuration information using Windows registry.
This class is used by default for wxConfig on Windows platforms; see wxFileConfig
for an alternative you may want to use (also on Windows).
@library{wxbase}
@category{cfg}
@see wxConfigBase
*/
class wxRegConfig : public wxConfigBase
{
public:
/**
The wxRegConfig constructor. For more info see the docs for the
wxConfigBase::wxConfigBase() constructor.
Note that wxRegConfig's @a style argument defaults to @c wxCONFIG_USE_GLOBAL_FILE,
i.e. to the use of the @c HKLM key (also known as "HKEY_LOCAL_MACHINE").
*/
wxRegConfig(const wxString& appName = wxEmptyString,
const wxString& vendorName = wxEmptyString,
const wxString& localFilename = wxEmptyString,
const wxString& globalFilename = wxEmptyString,
long style = wxCONFIG_USE_GLOBAL_FILE);
};

View File

@@ -0,0 +1,440 @@
/////////////////////////////////////////////////////////////////////////////
// Name: msw/registry.h
// Purpose: interface of wxRegKey
// Author: wxWidgets team
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
/**
@class wxRegKey
wxRegKey is a class representing the Windows registry (it is only available
under Windows) which can be used to create, query, set and delete registry keys.
The Windows registry contains data stored by Windows and the applications.
The data are stored in a tree structure, where a tree node is called a key.
Each key can contain subkeys as well as values. There are several predefined keys
that are used as main entry points to the registry, the most commonly used being:
@li @c HKEY_CLASSES_ROOT (HKCR)
@li @c HKEY_CURRENT_USER (HKCU)
@li @c HKEY_LOCAL_MACHINE (HKLM)
@li @c HKEY_CURRENT_CONFIG (HKCC)
@li @c HKEY_USERS (HKU)
The values can be in these formats:
@li String Value
@li Binary Value
@li DWORD Value
@li Multi String Value
@li Expandable String Value
@onlyfor{wxmsw}
@b Example:
@code
// This assumes that the key already exists, use HasSubKey() to check
// for the key existence if necessary.
wxRegKey key(wxRegKey::HKCU, "Software\\MyKey");
// Create a new value "MyValue" and set it to 12.
key.SetValue("MyValue", 12);
// Read the value back.
long value;
key.QueryValue("MyValue", &value);
wxLogMessage("Registry value: %ld", value);
// Enumerate the subkeys.
wxString keyName;
long index = 0;
for ( bool cont = key.GetFirstKey(keyName, index);
cont;
cont = key.GetNextKey(keyName, index) )
{
wxLogMessage("Subkey name: %s", keyName);
}
@endcode
@library{wxbase}
@category{cfg}
*/
class wxRegKey
{
public:
/**
Default constructor, initializes to @c HKEY_CLASSES_ROOT.
The @a viewMode parameter is new since wxWidgets 2.9.2.
*/
wxRegKey(WOW64ViewMode viewMode = WOW64ViewMode_Default);
/**
The constructor to set the full name of the key.
The @a viewMode parameter is new since wxWidgets 2.9.2.
*/
wxRegKey(const wxString& strKey,
WOW64ViewMode viewMode = WOW64ViewMode_Default);
/**
The constructor to set the full name of the key using one of the
standard keys, that is, HKCR, HKCU, HKLM, HKUSR, HKPD (obsolete),
HKCC or HKDD (obsolete).
The @a viewMode parameter is new since wxWidgets 2.9.2.
*/
wxRegKey(StdKey keyParent, const wxString& strKey,
WOW64ViewMode viewMode = WOW64ViewMode_Default);
/**
The constructor to set the full name of the key under a previously
created parent. The registry view is inherited from the parent.
*/
wxRegKey(const wxRegKey& keyParent, const wxString& strKey);
/**
Access modes for wxRegKey.
*/
enum AccessMode
{
Read, ///< Read-only
Write ///< Read and Write
};
/**
The standard registry key enumerator.
*/
enum StdKey
{
HKCR, ///< HKEY_CLASSES_ROOT
HKCU, ///< HKEY_CURRENT_USER
HKLM, ///< HKEY_LOCAL_MACHINE
HKUSR, ///< HKEY_USERS
HKPD, ///< HKEY_PERFORMANCE_DATA (Obsolete under XP and later)
HKCC, ///< HKEY_CURRENT_CONFIG
HKDD, ///< HKEY_DYN_DATA (Obsolete under XP and later)
HKMAX
};
/**
The value type enumerator.
*/
enum ValueType
{
Type_None, ///< No value type
Type_String, ///< Unicode null-terminated string
Type_Expand_String, ///< Unicode null-terminated string
///< (with environment variable references)
Type_Binary, ///< Free form binary
Type_Dword, ///< 32-bit number
Type_Dword_little_endian, ///< 32-bit number (same as Type_Dword)
Type_Dword_big_endian, ///< 32-bit number
Type_Link, ///< Symbolic Link (Unicode)
Type_Multi_String, ///< Multiple Unicode strings
Type_Resource_list, ///< Resource list in the resource map
Type_Full_resource_descriptor, ///< Resource list in the hardware description
Type_Resource_requirements_list ///<
};
/**
Used to determine how the registry will be viewed, either as
32-bit or 64-bit.
@since 2.9.2
*/
enum WOW64ViewMode
{
/**
Uses 32-bit registry for 32-bit applications and
64-bit registry for 64-bit ones.
*/
WOW64ViewMode_Default,
/**
Can be used in 64-bit apps to access the 32-bit registry,
has no effect (i.e. treated as default) in 32-bit apps.
*/
WOW64ViewMode_32,
/**
Can be used in 32-bit apps to access the 64-bit registry,
has no effect (i.e. treated as default) in 64-bit apps.
*/
WOW64ViewMode_64
};
/**
Closes the key.
*/
void Close();
/**
Copy the entire contents of the key recursively to another location
using the name. Returns @true if successful.
*/
bool Copy(const wxString& szNewName);
/**
Copy the entire contents of the key recursively to another location
using the key. Returns @true if successful.
*/
bool Copy(wxRegKey& keyDst);
/**
Copy the value to another key, possibly changing its name. By default
it will remain the same. Returns @true if successful.
*/
bool CopyValue(const wxString& szValue, wxRegKey& keyDst,
const wxString& szNewName = wxEmptyString);
/**
Creates the key. Will fail if the key already exists and @a bOkIfExists
is @false. Returns @true if successful.
*/
bool Create(bool bOkIfExists = true);
/**
Deletes the subkey with all its subkeys and values recursively.
*/
void DeleteKey(const wxString& szKey);
/**
Deletes this key and all its subkeys and values recursively.
*/
void DeleteSelf();
/**
Deletes the named value or use an empty string argument to remove the
default value of the key.
*/
void DeleteValue(const wxString& szKey);
/**
Returns @true if the key exists.
*/
bool Exists() const;
/**
Write the contents of this key and all its subkeys to the given file.
(The file will not be overwritten; it's an error if it already exists.)
Note that we export the key in REGEDIT4 format, not RegSaveKey() binary
format nor the newer REGEDIT5. Returns @true if successful.
*/
bool Export(const wxString& filename) const;
/**
Write the contents of this key and all its subkeys to the opened stream.
Returns @true if successful.
*/
bool Export(wxOutputStream& ostr) const;
/**
Gets the first key. Returns @true if successful.
*/
bool GetFirstKey(wxString& strKeyName, long& lIndex);
/**
Gets the first value of this key. Returns @true if successful.
*/
bool GetFirstValue(wxString& strValueName, long& lIndex);
/**
Return the associated HKEY handle.
It may be null if the key is not opened.
@since 3.3.1
*/
WXHKEY GetHkey() const;
/**
Gets information about the key. Returns @true if successful.
@param pnSubKeys
The number of subkeys.
@param pnMaxKeyLen
The maximum length of the subkey name.
@param pnValues
The number of values.
@param pnMaxValueLen
The maximum length of a value.
*/
bool GetKeyInfo(size_t* pnSubKeys, size_t* pnMaxKeyLen,
size_t* pnValues, size_t* pnMaxValueLen) const;
/**
Gets the name of the registry key.
*/
wxString GetName(bool bShortPrefix = true) const;
/**
Retrieves the registry view used by this key.
@since 2.9.2
@return The registry view given at the object's construction.
*/
WOW64ViewMode GetView() const { return m_viewMode; }
/**
Gets the next key. Returns @true if successful.
*/
bool GetNextKey(wxString& strKeyName, long& lIndex) const;
/**
Gets the next key value for this key. Returns @true if successful.
*/
bool GetNextValue(wxString& strValueName, long& lIndex) const;
/**
Gets the value type.
*/
ValueType GetValueType(const wxString& szValue) const;
/**
Returns @true if given subkey exists.
*/
bool HasSubKey(const wxString& szKey) const;
/**
Returns @true if any subkeys exist.
*/
bool HasSubkeys() const;
/**
Returns @true if the value exists.
*/
bool HasValue(const wxString& szValue) const;
/**
Returns @true if any values exist.
*/
bool HasValues() const;
/**
Returns @true if this key is empty, nothing under this key.
*/
bool IsEmpty() const;
/**
Returns @true if the value contains a number.
*/
bool IsNumericValue(const wxString& szValue) const;
/**
Returns @true if the key is opened.
*/
bool IsOpened() const;
/**
Explicitly opens the key. This method also allows the key to be opened
in read-only mode by passing wxRegKey::Read instead of default
wxRegKey::Write parameter. Returns @true if successful.
*/
bool Open(AccessMode mode = Write);
/**
Assignment operator to set the default value of the key.
*/
wxRegKey& operator=(const wxString& strValue);
/**
Return the default value of the key.
*/
wxString QueryDefaultValue() const;
/**
Retrieves the raw string value. Returns @true if successful.
An empty @a szValue queries the default/unnamed key value.
*/
bool QueryRawValue(const wxString& szValue, wxString& strValue) const;
/**
Retrieves the raw or expanded string value. Returns @true if successful.
An empty @a szValue queries the default/unnamed key value.
*/
bool QueryValue(const wxString& szValue, wxString& strValue, bool raw) const;
/**
Retrieves the numeric value. Returns @true if successful.
An empty @a szValue queries the default/unnamed key value.
*/
bool QueryValue(const wxString& szValue, long* plValue) const;
/**
Retrieves the 64-bit value. Returns @true if successful.
An empty @a szValue queries the default/unnamed key value.
@since 3.1.5
*/
bool QueryValue64(const wxString& szValue, wxLongLong_t* plValue) const;
/**
Retrieves the binary structure. Returns @true if successful.
An empty @a szValue queries the default/unnamed key value.
*/
bool QueryValue(const wxString& szValue, wxMemoryBuffer& buf) const;
/**
Renames the key. Returns @true if successful.
*/
bool Rename(const wxString& szNewName);
/**
Renames a value. Returns @true if successful.
*/
bool RenameValue(const wxString& szValueOld,
const wxString& szValueNew);
/**
Preallocate some memory for the name. For wxRegConfig usage only.
*/
void ReserveMemoryForName(size_t bytes);
/**
Set or change the HKEY handle.
*/
void SetHkey(WXHKEY hKey);
/**
Set the full key name. The name is absolute. It should start with
HKEY_xxx.
*/
void SetName(const wxString& strKey);
/**
Set the name relative to the parent key
*/
void SetName(StdKey keyParent, const wxString& strKey);
/**
Set the name relative to the parent key
*/
void SetName(const wxRegKey& keyParent, const wxString& strKey);
/**
Sets the given @a szValue which must be numeric. If the value doesn't
exist, it is created. Returns @true if successful.
An empty @a szValue sets the default/unnamed key value.
*/
bool SetValue(const wxString& szValue, long lValue);
/**
Sets a 64-bit value.
This function creates or modifies a field of @c QWORD type in the
registry.
@since 3.1.5
*/
bool SetValue64(const wxString& szValue, wxLongLong_t lValue);
/**
Sets the given @a szValue which must be string. If the value doesn't
exist, it is created. Returns @true if successful.
An empty @a szValue sets the default/unnamed key value.
*/
bool SetValue(const wxString& szValue, const wxString& strValue);
/**
Sets the given @a szValue which must be binary. If the value doesn't
exist, it is created. Returns @true if successful.
An empty @a szValue sets the default/unnamed key value.
*/
bool SetValue(const wxString& szValue, const wxMemoryBuffer& buf);
};