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 7228269764
9653 changed files with 4034514 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/msw/ole/access.h
// Purpose: declaration of the wxAccessible class
// Author: Julian Smart
// Created: 2003-02-12
// Copyright: (c) 2003 Julian Smart
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_ACCESS_H_
#define _WX_ACCESS_H_
#if wxUSE_ACCESSIBILITY
// ----------------------------------------------------------------------------
// forward declarations
// ----------------------------------------------------------------------------
struct IAccessible;
class wxIAccessible;
class WXDLLIMPEXP_FWD_CORE wxWindow;
// ----------------------------------------------------------------------------
// macros
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// wxAccessible implements accessibility behaviour.
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxAccessible : public wxAccessibleBase
{
public:
wxAccessible(wxWindow *win = nullptr);
virtual ~wxAccessible();
// Overridables
// Accessors
// Returns the wxIAccessible pointer
wxIAccessible* GetIAccessible() { return m_pIAccessible; }
// Returns the IAccessible standard interface pointer
IAccessible* GetIAccessibleStd();
// Operations
// Sends an event when something changes in an accessible object.
static void NotifyEvent(int eventType, wxWindow* window, wxAccObject objectType,
int objectId);
protected:
void Init();
private:
wxIAccessible * m_pIAccessible; // the pointer to COM interface
IAccessible* m_pIAccessibleStd; // the pointer to the standard COM interface,
// for default processing
wxDECLARE_NO_COPY_CLASS(wxAccessible);
};
#endif //wxUSE_ACCESSIBILITY
#endif //_WX_ACCESS_H_

View File

@@ -0,0 +1,254 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/msw/ole/activex.h
// Purpose: wxActiveXContainer class
// Author: Ryan Norton <wxprojects@comcast.net>
// Created: 8/18/05
// Copyright: (c) Ryan Norton
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
// ============================================================================
// Definitions
// ============================================================================
#ifndef _WX_MSW_OLE_ACTIVEXCONTAINER_H_
#define _WX_MSW_OLE_ACTIVEXCONTAINER_H_
#if wxUSE_ACTIVEX
//---------------------------------------------------------------------------
// wx includes
//---------------------------------------------------------------------------
#include "wx/msw/ole/oleutils.h" // wxBasicString &c
#include "wx/msw/ole/uuid.h"
#include "wx/window.h"
#include "wx/variant.h"
class FrameSite;
//---------------------------------------------------------------------------
// MSW COM includes
//---------------------------------------------------------------------------
#include <oleidl.h>
#include <olectl.h>
#include <exdisp.h>
#include <docobj.h>
#ifndef STDMETHOD
#define STDMETHOD(funcname) virtual HRESULT wxSTDCALL funcname
#endif
//
// These defines are from another ole header - but its not in the
// latest sdk. Also the ifndef DISPID_READYSTATE is here because at
// least on my machine with the latest sdk olectl.h defines these 3
//
#ifndef DISPID_READYSTATE
#define DISPID_READYSTATE (-525)
#define DISPID_READYSTATECHANGE (-609)
#define DISPID_AMBIENT_TRANSFERPRIORITY (-728)
#endif
#define DISPID_AMBIENT_OFFLINEIFNOTCONNECTED (-5501)
#define DISPID_AMBIENT_SILENT (-5502)
#ifndef DISPID_AMBIENT_CODEPAGE
#define DISPID_AMBIENT_CODEPAGE (-725)
#define DISPID_AMBIENT_CHARSET (-727)
#endif
//---------------------------------------------------------------------------
//
// wxActiveXContainer
//
//---------------------------------------------------------------------------
template<typename I>
class wxAutoOleInterface
{
public:
typedef I Interface;
explicit wxAutoOleInterface(I *pInterface = nullptr) : m_interface(pInterface)
{}
wxAutoOleInterface(REFIID riid, IUnknown *pUnk) : m_interface(nullptr)
{ QueryInterface(riid, pUnk); }
wxAutoOleInterface(REFIID riid, IDispatch *pDispatch) : m_interface(nullptr)
{ QueryInterface(riid, pDispatch); }
wxAutoOleInterface(REFCLSID clsid, REFIID riid) : m_interface(nullptr)
{ CreateInstance(clsid, riid); }
wxAutoOleInterface(const wxAutoOleInterface& ti) : m_interface(nullptr)
{ operator=(ti); }
wxAutoOleInterface& operator=(const wxAutoOleInterface& ti)
{
if ( ti.m_interface )
ti.m_interface->AddRef();
Free();
m_interface = ti.m_interface;
return *this;
}
wxAutoOleInterface& operator=(I*& ti)
{
Free();
m_interface = ti;
return *this;
}
~wxAutoOleInterface() { Free(); }
void Free()
{
if ( m_interface )
m_interface->Release();
m_interface = nullptr;
}
HRESULT QueryInterface(REFIID riid, IUnknown *pUnk)
{
Free();
wxASSERT(pUnk != nullptr);
return pUnk->QueryInterface(riid, (void **)&m_interface);
}
HRESULT CreateInstance(REFCLSID clsid, REFIID riid)
{
Free();
return CoCreateInstance
(
clsid,
nullptr,
CLSCTX_ALL,
riid,
(void **)&m_interface
);
}
operator I*() const {return m_interface; }
I* operator->() {return m_interface; }
I** GetRef() {return &m_interface; }
bool Ok() const { return IsOk(); }
bool IsOk() const { return m_interface != nullptr; }
protected:
I *m_interface;
};
typedef wxAutoOleInterface<IDispatch> wxAutoIDispatch;
typedef wxAutoOleInterface<IOleClientSite> wxAutoIOleClientSite;
typedef wxAutoOleInterface<IUnknown> wxAutoIUnknown;
typedef wxAutoOleInterface<IOleObject> wxAutoIOleObject;
typedef wxAutoOleInterface<IOleInPlaceObject> wxAutoIOleInPlaceObject;
typedef wxAutoOleInterface<IOleInPlaceActiveObject> wxAutoIOleInPlaceActiveObject;
typedef wxAutoOleInterface<IOleDocumentView> wxAutoIOleDocumentView;
typedef wxAutoOleInterface<IViewObject> wxAutoIViewObject;
class WXDLLIMPEXP_CORE wxActiveXContainer : public wxWindow
{
public:
wxActiveXContainer(wxWindow * parent, REFIID iid, IUnknown* pUnk);
virtual ~wxActiveXContainer();
void OnSize(wxSizeEvent&);
void OnPaint(wxPaintEvent&);
void OnSetFocus(wxFocusEvent&);
void OnKillFocus(wxFocusEvent&);
virtual bool MSWTranslateMessage(WXMSG* pMsg) override;
virtual bool QueryClientSiteInterface(REFIID iid, void **_interface, const char *&desc);
protected:
friend class FrameSite;
friend class wxActiveXEvents;
FrameSite *m_frameSite;
wxAutoIDispatch m_Dispatch;
wxAutoIOleClientSite m_clientSite;
wxAutoIUnknown m_ActiveX;
wxAutoIOleObject m_oleObject;
wxAutoIOleInPlaceObject m_oleInPlaceObject;
wxAutoIOleInPlaceActiveObject m_oleInPlaceActiveObject;
wxAutoIOleDocumentView m_docView;
wxAutoIViewObject m_viewObject;
HWND m_oleObjectHWND;
bool m_bAmbientUserMode;
DWORD m_docAdviseCookie;
wxWindow* m_realparent;
void CreateActiveX(REFIID, IUnknown*);
};
///\brief Store native event parameters.
///\detail Store OLE 'Invoke' parameters for event handlers that need to access them.
/// These are the exact values for the event as they are passed to the wxActiveXContainer.
struct wxActiveXEventNativeMSW
{
DISPID dispIdMember;
REFIID riid;
LCID lcid;
WORD wFlags;
DISPPARAMS *pDispParams;
VARIANT *pVarResult;
EXCEPINFO *pExcepInfo;
unsigned int *puArgErr;
wxActiveXEventNativeMSW
(DISPID a_dispIdMember, REFIID a_riid, LCID a_lcid, WORD a_wFlags, DISPPARAMS *a_pDispParams,
VARIANT *a_pVarResult, EXCEPINFO *a_pExcepInfo, unsigned int *a_puArgErr)
:dispIdMember(a_dispIdMember), riid(a_riid), lcid(a_lcid), wFlags(a_wFlags), pDispParams(a_pDispParams),
pVarResult(a_pVarResult), pExcepInfo(a_pExcepInfo), puArgErr(a_puArgErr)
{ }
};
// Events
class WXDLLIMPEXP_CORE wxActiveXEvent : public wxCommandEvent
{
private:
friend class wxActiveXEvents;
wxVariant m_params;
DISPID m_dispid;
public:
wxNODISCARD virtual wxEvent *Clone() const override
{ return new wxActiveXEvent(*this); }
size_t ParamCount() const;
wxString ParamType(size_t idx) const
{
wxASSERT(idx < ParamCount());
return m_params[idx].GetType();
}
wxString ParamName(size_t idx) const
{
wxASSERT(idx < ParamCount());
return m_params[idx].GetName();
}
wxVariant& operator[] (size_t idx);
DISPID GetDispatchId() const
{ return m_dispid; }
wxActiveXEventNativeMSW *GetNativeParameters() const
{ return (wxActiveXEventNativeMSW*)GetClientData(); }
};
// #define wxACTIVEX_ID 14001
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_ACTIVEX, wxActiveXEvent );
typedef void (wxEvtHandler::*wxActiveXEventFunction)(wxActiveXEvent&);
#define wxActiveXEventHandler(func) \
wxEVENT_HANDLER_CAST( wxActiveXEventFunction, func )
#define EVT_ACTIVEX(id, fn) wxDECLARE_EVENT_TABLE_ENTRY(wxEVT_ACTIVEX, id, -1, wxActiveXEventHandler( fn ), nullptr ),
#endif // wxUSE_ACTIVEX
#endif // _WX_MSW_OLE_ACTIVEXCONTAINER_H_

View File

@@ -0,0 +1,139 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/msw/ole/automtn.h
// Purpose: OLE automation utilities
// Author: Julian Smart
// Created: 11/6/98
// Copyright: (c) 1998, Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_AUTOMTN_H_
#define _WX_AUTOMTN_H_
#include "wx/defs.h"
#if wxUSE_OLE_AUTOMATION
#include "wx/object.h"
#include "wx/variant.h"
typedef void WXIDISPATCH;
typedef unsigned short* WXBSTR;
typedef unsigned long WXLCID;
#ifdef GetObject
#undef GetObject
#endif
// Flags used with wxAutomationObject::GetInstance()
enum wxAutomationInstanceFlags
{
// Only use the existing instance, never create a new one.
wxAutomationInstance_UseExistingOnly = 0,
// Create a new instance if there are no existing ones.
wxAutomationInstance_CreateIfNeeded = 1,
// Do not log errors if we failed to get the existing instance because none
// is available.
wxAutomationInstance_SilentIfNone = 2
};
/*
* wxAutomationObject
* Wraps up an IDispatch pointer and invocation; does variant conversion.
*/
class WXDLLIMPEXP_CORE wxAutomationObject: public wxObject
{
public:
wxAutomationObject(WXIDISPATCH* dispatchPtr = nullptr);
virtual ~wxAutomationObject();
// Set/get dispatch pointer
void SetDispatchPtr(WXIDISPATCH* dispatchPtr) { m_dispatchPtr = dispatchPtr; }
WXIDISPATCH* GetDispatchPtr() const { return m_dispatchPtr; }
bool IsOk() const { return m_dispatchPtr != nullptr; }
// Get a dispatch pointer from the current object associated
// with a ProgID, such as "Excel.Application"
bool GetInstance(const wxString& progId,
int flags = wxAutomationInstance_CreateIfNeeded) const;
// Get a dispatch pointer from a new instance of the class
bool CreateInstance(const wxString& progId) const;
// Low-level invocation function. Pass either an array of variants,
// or an array of pointers to variants.
bool Invoke(const wxString& member, int action,
wxVariant& retValue, int noArgs, wxVariant args[], const wxVariant* ptrArgs[] = nullptr) const;
// Invoke a member function
wxVariant CallMethod(const wxString& method, int noArgs, wxVariant args[]);
wxVariant CallMethodArray(const wxString& method, int noArgs, const wxVariant **args);
// Convenience function
wxVariant CallMethod(const wxString& method,
const wxVariant& arg1 = wxNullVariant, const wxVariant& arg2 = wxNullVariant,
const wxVariant& arg3 = wxNullVariant, const wxVariant& arg4 = wxNullVariant,
const wxVariant& arg5 = wxNullVariant, const wxVariant& arg6 = wxNullVariant);
// Get/Put property
wxVariant GetProperty(const wxString& property, int noArgs = 0, wxVariant args[] = nullptr) const;
wxVariant GetPropertyArray(const wxString& property, int noArgs, const wxVariant **args) const;
wxVariant GetProperty(const wxString& property,
const wxVariant& arg1, const wxVariant& arg2 = wxNullVariant,
const wxVariant& arg3 = wxNullVariant, const wxVariant& arg4 = wxNullVariant,
const wxVariant& arg5 = wxNullVariant, const wxVariant& arg6 = wxNullVariant);
bool PutPropertyArray(const wxString& property, int noArgs, const wxVariant **args);
bool PutProperty(const wxString& property, int noArgs, wxVariant args[]) ;
bool PutProperty(const wxString& property,
const wxVariant& arg1, const wxVariant& arg2 = wxNullVariant,
const wxVariant& arg3 = wxNullVariant, const wxVariant& arg4 = wxNullVariant,
const wxVariant& arg5 = wxNullVariant, const wxVariant& arg6 = wxNullVariant);
// Uses DISPATCH_PROPERTYGET
// and returns a dispatch pointer. The calling code should call Release
// on the pointer, though this could be implicit by constructing a wxAutomationObject
// with it and letting the destructor call Release.
WXIDISPATCH* GetDispatchProperty(const wxString& property, int noArgs, wxVariant args[]) const;
WXIDISPATCH* GetDispatchProperty(const wxString& property, int noArgs, const wxVariant **args) const;
// A way of initialising another wxAutomationObject with a dispatch object,
// without having to deal with nasty IDispatch pointers.
bool GetObject(wxAutomationObject& obj, const wxString& property, int noArgs = 0, wxVariant args[] = nullptr) const;
bool GetObject(wxAutomationObject& obj, const wxString& property, int noArgs, const wxVariant **args) const;
// Returns the locale identifier used in automation calls. The default is
// LOCALE_SYSTEM_DEFAULT. Objects obtained by GetObject() inherit the
// locale identifier from the one that created them.
WXLCID GetLCID() const;
// Sets the locale identifier to be used in automation calls performed by
// this object. The default is LOCALE_SYSTEM_DEFAULT.
void SetLCID(WXLCID lcid);
// Returns the flags used for conversions between wxVariant and OLE
// VARIANT, see wxOleConvertVariantFlags. The default value is
// wxOleConvertVariant_Default but all the objects obtained by GetObject()
// inherit the flags from the one that created them.
long GetConvertVariantFlags() const;
// Sets the flags used for conversions between wxVariant and OLE VARIANT,
// see wxOleConvertVariantFlags (default is wxOleConvertVariant_Default.
void SetConvertVariantFlags(long flags);
public: // public for compatibility only, don't use m_dispatchPtr directly.
WXIDISPATCH* m_dispatchPtr;
private:
WXLCID m_lcid;
long m_convertVariantFlags;
wxDECLARE_NO_COPY_CLASS(wxAutomationObject);
};
#endif // wxUSE_OLE_AUTOMATION
#endif // _WX_AUTOMTN_H_

View File

@@ -0,0 +1,171 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/msw/ole/comimpl.h
// Purpose: COM helper routines, COM debugging support &c
// Author: Vadim Zeitlin
// Created: 19.02.1998
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef WX_COMIMPL_H
#define WX_COMIMPL_H
// DO NOT USE THIS HEADER.
//
// This header is only preserved for compatibility and the helpers defined here
// are obsolete and shouldn't be used in any new code and don't work correctly
// with classes inheriting from IUnknown more than once.
#include "wx/defs.h"
#include "wx/msw/wrapwin.h"
// get IUnknown, REFIID &c
#include <objbase.h>
// ============================================================================
// General purpose functions and macros
// ============================================================================
// release the interface pointer (if non-null)
inline void ReleaseInterface(IUnknown *pIUnk)
{
if ( pIUnk != nullptr )
pIUnk->Release();
}
// release the interface pointer (if non-null) and set it to nullptr
#define RELEASE_AND_NULL(p) if ( (p) != nullptr ) { p->Release(); p = nullptr; };
// return true if the iid is in the array
extern WXDLLIMPEXP_CORE bool IsIidFromList(REFIID riid, const IID *aIids[], size_t nCount);
// ============================================================================
// IUnknown implementation helpers
// ============================================================================
/*
WARNING: This does NOT work with multiple inheritance, so multiple
interfaces can only be supported when they inherit from each other.
The most dumb implementation of IUnknown methods. We don't support
aggregation nor containment, but for 99% of cases this simple
implementation is quite enough.
Usage is trivial: here is all you should have
1) DECLARE_IUNKNOWN_METHODS in your (IUnknown derived!) class declaration
2) BEGIN/END_IID_TABLE with ADD_IID in between for all interfaces you
support (at least all for which you intent to return 'this' from QI,
i.e. you should derive from IFoo if you have ADD_IID(Foo)) somewhere else
3) IMPLEMENT_IUNKNOWN_METHODS somewhere also
These macros are quite simple: AddRef and Release are trivial and QI does
lookup in a static member array of IIDs and returns 'this' if it founds
the requested interface in it or E_NOINTERFACE if not.
*/
/*
wxAutoULong: this class is used for automatically initialising m_cRef to 0
*/
class wxAutoULong
{
public:
wxAutoULong(ULONG value = 0) : m_Value(value) { }
operator ULONG&() { return m_Value; }
ULONG& operator=(ULONG value) { m_Value = value; return m_Value; }
wxAutoULong& operator++() { ++m_Value; return *this; }
const wxAutoULong operator++( int ) { wxAutoULong temp = *this; ++m_Value; return temp; }
wxAutoULong& operator--() { --m_Value; return *this; }
const wxAutoULong operator--( int ) { wxAutoULong temp = *this; --m_Value; return temp; }
private:
ULONG m_Value;
};
// declare the methods and the member variable containing reference count
// you must also define the ms_aIids array somewhere with BEGIN_IID_TABLE
// and friends (see below)
#define DECLARE_IUNKNOWN_METHODS \
public: \
STDMETHODIMP QueryInterface(REFIID, void **) override; \
STDMETHODIMP_(ULONG) AddRef() override; \
STDMETHODIMP_(ULONG) Release() override; \
private: \
static const IID *ms_aIids[]; \
wxAutoULong m_cRef
// macros for declaring supported interfaces
// NB: ADD_IID prepends IID_I whereas ADD_RAW_IID does not
#define BEGIN_IID_TABLE(cname) const IID *cname::ms_aIids[] = {
#define ADD_IID(iid) &IID_I##iid,
#define ADD_RAW_IID(iid) &iid,
#define END_IID_TABLE }
// implementation is as straightforward as possible
// Parameter: classname - the name of the class
#define IMPLEMENT_IUNKNOWN_METHODS(classname) \
STDMETHODIMP classname::QueryInterface(REFIID riid, void **ppv) \
{ \
wxLogQueryInterface(wxT(#classname), riid); \
\
if ( IsIidFromList(riid, ms_aIids, WXSIZEOF(ms_aIids)) ) { \
*ppv = this; \
AddRef(); \
\
return S_OK; \
} \
else { \
*ppv = nullptr; \
\
return (HRESULT) E_NOINTERFACE; \
} \
} \
\
STDMETHODIMP_(ULONG) classname::AddRef() \
{ \
wxLogAddRef(wxT(#classname), m_cRef); \
\
return ++m_cRef; \
} \
\
STDMETHODIMP_(ULONG) classname::Release() \
{ \
wxLogRelease(wxT(#classname), m_cRef); \
\
if ( --m_cRef == wxAutoULong(0) ) { \
delete this; \
return 0; \
} \
else \
return m_cRef; \
}
// ============================================================================
// Debugging support
// ============================================================================
// VZ: I don't know it's not done for compilers other than VC++ but I leave it
// as is. Please note, though, that tracing COM interface calls may be
// incredibly useful when debugging COM programs.
#if defined(__WXDEBUG__) && defined(__VISUALC__)
// ----------------------------------------------------------------------------
// All COM specific log functions have DebugTrace level (as LogTrace)
// ----------------------------------------------------------------------------
// tries to translate riid into a symbolic name, if possible
WXDLLIMPEXP_CORE void wxLogQueryInterface(const wxChar *szInterface, REFIID riid);
// these functions print out the new value of reference counter
WXDLLIMPEXP_CORE void wxLogAddRef (const wxChar *szInterface, ULONG cRef);
WXDLLIMPEXP_CORE void wxLogRelease(const wxChar *szInterface, ULONG cRef);
#else //!__WXDEBUG__
#define wxLogQueryInterface(szInterface, riid)
#define wxLogAddRef(szInterface, cRef)
#define wxLogRelease(szInterface, cRef)
#endif //__WXDEBUG__
#endif // WX_COMIMPL_H

View File

@@ -0,0 +1,71 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/msw/ole/dataform.h
// Purpose: declaration of the wxDataFormat class
// Author: Vadim Zeitlin
// Created: 19.10.99 (extracted from msw/ole/dataobj.h)
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_MSW_OLE_DATAFORM_H
#define _WX_MSW_OLE_DATAFORM_H
// ----------------------------------------------------------------------------
// wxDataFormat identifies the single format of data
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxDataFormat
{
public:
// the clipboard formats under Win32 are WORD's
typedef unsigned short NativeFormat;
wxDataFormat(NativeFormat format = wxDF_INVALID) { m_format = format; }
// we need constructors from all string types as implicit conversions to
// wxString don't apply when we already rely on implicit conversion of a,
// for example, "char *" string to wxDataFormat, and existing code does it
wxDataFormat(const wxString& format) { SetId(format); }
#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING
wxDataFormat(const char *format) { SetId(format); }
#endif // wxNO_IMPLICIT_WXSTRING_ENCODING
wxDataFormat(const wchar_t *format) { SetId(format); }
wxDataFormat(const wxCStrData& format) { SetId(format); }
wxDataFormat& operator=(NativeFormat format)
{ m_format = format; return *this; }
// default copy ctor/assignment operators ok
// comparison (must have both versions)
bool operator==(wxDataFormatId format) const;
bool operator!=(wxDataFormatId format) const;
bool operator==(const wxDataFormat& format) const;
bool operator!=(const wxDataFormat& format) const;
bool operator==(NativeFormat format) const;
bool operator!=(NativeFormat format) const;
// explicit and implicit conversions to NativeFormat which is one of
// standard data types (implicit conversion is useful for preserving the
// compatibility with old code)
NativeFormat GetFormatId() const { return m_format; }
operator NativeFormat() const { return m_format; }
// this works with standard as well as custom ids
void SetType(NativeFormat format) { m_format = format; }
NativeFormat GetType() const { return m_format; }
// string ids are used for custom types - this SetId() must be used for
// application-specific formats
wxString GetId() const;
void SetId(const wxString& format);
// returns true if the format is one of those defined in wxDataFormatId
bool IsStandard() const { return m_format > 0 && m_format < wxDF_PRIVATE; }
private:
NativeFormat m_format;
};
#endif // _WX_MSW_OLE_DATAFORM_H

View File

@@ -0,0 +1,77 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/msw/ole/dataobj.h
// Purpose: declaration of the wxDataObject class
// Author: Vadim Zeitlin
// Created: 10.05.98
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_MSW_OLE_DATAOBJ_H
#define _WX_MSW_OLE_DATAOBJ_H
// ----------------------------------------------------------------------------
// forward declarations
// ----------------------------------------------------------------------------
struct IDataObject;
// ----------------------------------------------------------------------------
// wxDataObject is a "smart" and polymorphic piece of data.
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxDataObject : public wxDataObjectBase
{
public:
// ctor & dtor
wxDataObject();
virtual ~wxDataObject();
// retrieve IDataObject interface (for other OLE related classes)
IDataObject *GetInterface() const { return m_pIDataObject; }
// tell the object that it should be now owned by IDataObject - i.e. when
// it is deleted, it should delete us as well
void SetAutoDelete();
// return true if we support this format in "Get" direction
bool IsSupportedFormat(const wxDataFormat& format) const
{ return wxDataObjectBase::IsSupported(format, Get); }
// if this method returns false, this wxDataObject will be copied to
// the clipboard with its size prepended to it, which is compatible with
// older wx versions
//
// if returns true, then this wxDataObject will be copied to the clipboard
// without any additional information and ::HeapSize() function will be used
// to get the size of that data
virtual bool NeedsVerbatimData(const wxDataFormat& WXUNUSED(format)) const
{
// return false from here only for compatibility with earlier wx versions
return true;
}
// function to return symbolic name of clipboard format (for debug messages)
#ifdef __WXDEBUG__
static const wxChar *GetFormatName(wxDataFormat format);
#define wxGetFormatName(format) wxDataObject::GetFormatName(format)
#else // !Debug
#define wxGetFormatName(format) wxT("")
#endif // Debug/!Debug
// they need to be accessed from wxIDataObject, so made them public,
// or wxIDataObject friend
public:
virtual const void* GetSizeFromBuffer( const void* buffer, size_t* size,
const wxDataFormat& format );
virtual void* SetSizeInBuffer( void* buffer, size_t size,
const wxDataFormat& format );
virtual size_t GetBufferOffset( const wxDataFormat& format );
private:
IDataObject *m_pIDataObject; // pointer to the COM interface
wxDECLARE_NO_COPY_CLASS(wxDataObject);
};
#endif //_WX_MSW_OLE_DATAOBJ_H

View File

@@ -0,0 +1,144 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/msw/ole/dataobj2.h
// Purpose: second part of platform specific wxDataObject header -
// declarations of predefined wxDataObjectSimple-derived classes
// Author: Vadim Zeitlin
// Created: 21.10.99
// Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_MSW_OLE_DATAOBJ2_H
#define _WX_MSW_OLE_DATAOBJ2_H
// ----------------------------------------------------------------------------
// wxBitmapDataObject is a specialization of wxDataObject for bitmap data
//
// NB: in fact, under MSW we support CF_DIB (and not CF_BITMAP) clipboard
// format and we also provide wxBitmapDataObject2 for CF_BITMAP (which is
// rarely used). This is ugly, but I haven't found a solution for it yet.
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxBitmapDataObject : public wxBitmapDataObjectBase
{
public:
// ctors
wxBitmapDataObject(const wxBitmap& bitmap = wxNullBitmap)
: wxBitmapDataObjectBase(bitmap)
{
SetFormat(wxDF_DIB);
m_data = nullptr;
}
// implement base class pure virtuals
virtual size_t GetDataSize() const override;
virtual bool GetDataHere(void *buf) const override;
virtual bool SetData(size_t len, const void *buf) override;
virtual size_t GetDataSize(const wxDataFormat& WXUNUSED(format)) const override
{ return GetDataSize(); }
virtual bool GetDataHere(const wxDataFormat& WXUNUSED(format),
void *buf) const override
{ return GetDataHere(buf); }
virtual bool SetData(const wxDataFormat& WXUNUSED(format),
size_t len, const void *buf) override
{ return SetData(len, buf); }
private:
// the DIB data
void /* BITMAPINFO */ *m_data;
wxDECLARE_NO_COPY_CLASS(wxBitmapDataObject);
};
// ----------------------------------------------------------------------------
// wxBitmapDataObject2 - a data object for CF_BITMAP
//
// FIXME did I already mention it was ugly?
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxBitmapDataObject2 : public wxBitmapDataObjectBase
{
public:
// ctors
wxBitmapDataObject2(const wxBitmap& bitmap = wxNullBitmap)
: wxBitmapDataObjectBase(bitmap)
{
}
// implement base class pure virtuals
virtual size_t GetDataSize() const override;
virtual bool GetDataHere(void *buf) const override;
virtual bool SetData(size_t len, const void *buf) override;
virtual size_t GetDataSize(const wxDataFormat& WXUNUSED(format)) const override
{ return GetDataSize(); }
virtual bool GetDataHere(const wxDataFormat& WXUNUSED(format),
void *buf) const override
{ return GetDataHere(buf); }
virtual bool SetData(const wxDataFormat& WXUNUSED(format),
size_t len, const void *buf) override
{ return SetData(len, buf); }
private:
wxDECLARE_NO_COPY_CLASS(wxBitmapDataObject2);
};
// ----------------------------------------------------------------------------
// wxFileDataObject - data object for CF_HDROP
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxFileDataObject : public wxFileDataObjectBase
{
public:
wxFileDataObject() = default;
// implement base class pure virtuals
virtual bool SetData(size_t len, const void *buf) override;
virtual size_t GetDataSize() const override;
virtual bool GetDataHere(void *pData) const override;
virtual void AddFile(const wxString& file);
virtual size_t GetDataSize(const wxDataFormat& WXUNUSED(format)) const override
{ return GetDataSize(); }
virtual bool GetDataHere(const wxDataFormat& WXUNUSED(format),
void *buf) const override
{ return GetDataHere(buf); }
virtual bool SetData(const wxDataFormat& WXUNUSED(format),
size_t len, const void *buf) override
{ return SetData(len, buf); }
private:
wxDECLARE_NO_COPY_CLASS(wxFileDataObject);
};
// ----------------------------------------------------------------------------
// wxURLDataObject: data object for URLs
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxURLDataObject : public wxDataObjectComposite
{
public:
// initialize with URL in ctor or use SetURL later
wxURLDataObject(const wxString& url = wxEmptyString);
// return the URL as string
wxString GetURL() const;
// Set a string as the URL in the data object
void SetURL(const wxString& url);
// override to set m_textFormat
virtual bool SetData(const wxDataFormat& format,
size_t len,
const void *buf) override;
private:
// last data object we got data in
wxDataObjectSimple *m_dataObjectLast;
wxDECLARE_NO_COPY_CLASS(wxURLDataObject);
};
#endif // _WX_MSW_OLE_DATAOBJ2_H

View File

@@ -0,0 +1,84 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/msw/ole/dropsrc.h
// Purpose: declaration of the wxDropSource class
// Author: Vadim Zeitlin
// Created: 06.03.98
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_OLEDROPSRC_H
#define _WX_OLEDROPSRC_H
#if wxUSE_DRAG_AND_DROP
// ----------------------------------------------------------------------------
// forward declarations
// ----------------------------------------------------------------------------
class wxIDropSource;
class WXDLLIMPEXP_FWD_CORE wxDataObject;
class WXDLLIMPEXP_FWD_CORE wxWindow;
// ----------------------------------------------------------------------------
// macros
// ----------------------------------------------------------------------------
// this macro may be used instead for wxDropSource ctor arguments: it will use
// the cursor 'name' from the resources under MSW, but will expand to
// something else under GTK. If you don't use it, you will have to use #ifdef
// in the application code.
#define wxDROP_ICON(name) wxCursor(wxT(#name))
// ----------------------------------------------------------------------------
// wxDropSource is used to start the drag-&-drop operation on associated
// wxDataObject object. It's responsible for giving UI feedback while dragging.
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxDropSource : public wxDropSourceBase
{
public:
// ctors: if you use default ctor you must call SetData() later!
//
// NB: the "wxWindow *win" parameter is unused and is here only for wxGTK
// compatibility, as well as both icon parameters
wxDropSource(wxWindow *win = nullptr,
const wxCursorBundle& cursorCopy = {},
const wxCursorBundle& cursorMove = {},
const wxCursorBundle& cursorStop = {});
wxDropSource(wxDataObject& data,
wxWindow *win = nullptr,
const wxCursorBundle& cursorCopy = {},
const wxCursorBundle& cursorMove = {},
const wxCursorBundle& cursorStop = {});
virtual ~wxDropSource();
// do it (call this in response to a mouse button press, for example)
// params: if bAllowMove is false, data can be only copied
virtual wxDragResult DoDragDrop(int flags = wxDrag_CopyOnly) override;
// overridable: you may give some custom UI feedback during d&d operation
// in this function (it's called on each mouse move, so it shouldn't be
// too slow). Just return false if you want default feedback.
virtual bool GiveFeedback(wxDragResult effect) override;
protected:
void Init();
private:
// The window passed to the ctor.
wxWindow* const m_win;
wxIDropSource *m_pIDropSource; // the pointer to COM interface
// Last cursor used in GiveFeedback(): we need to keep it alive to ensure
// its HCURSOR remains valid.
wxCursor m_feedbackCursor;
wxDECLARE_NO_COPY_CLASS(wxDropSource);
};
#endif //wxUSE_DRAG_AND_DROP
#endif //_WX_OLEDROPSRC_H

View File

@@ -0,0 +1,88 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/msw/ole/droptgt.h
// Purpose: declaration of the wxDropTarget class
// Author: Vadim Zeitlin
// Created: 06.03.98
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_OLEDROPTGT_H
#define _WX_OLEDROPTGT_H
#if wxUSE_DRAG_AND_DROP
// ----------------------------------------------------------------------------
// forward declarations
// ----------------------------------------------------------------------------
class wxIDropTarget;
struct wxIDropTargetHelper;
struct IDataObject;
// ----------------------------------------------------------------------------
// An instance of the class wxDropTarget may be associated with any wxWindow
// derived object via SetDropTarget() function. If this is done, the virtual
// methods of wxDropTarget are called when something is dropped on the window.
//
// Note that wxDropTarget is an abstract base class (ABC) and you should derive
// your own class from it implementing pure virtual function in order to use it
// (all of them, including protected ones which are called by the class itself)
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxDropTarget : public wxDropTargetBase
{
public:
// ctor & dtor
wxDropTarget(wxDataObject *dataObject = nullptr);
virtual ~wxDropTarget();
// normally called by wxWindow on window creation/destruction, but might be
// called `manually' as well. Register() returns true on success.
bool Register(WXHWND hwnd);
void Revoke(WXHWND hwnd);
// provide default implementation for base class pure virtuals
virtual bool OnDrop(wxCoord x, wxCoord y) override;
virtual bool GetData() override;
// Can only be called during OnXXX methods.
wxDataFormat GetMatchingPair();
// implementation only from now on
// -------------------------------
// do we accept this kind of data?
bool MSWIsAcceptedData(IDataObject *pIDataSource) const;
// give us the data source from IDropTarget::Drop() - this is later used by
// GetData() when it's called from inside OnData()
void MSWSetDataSource(IDataObject *pIDataSource);
// These functions take care of all things necessary to support native drag
// images.
//
// {Init,End}DragImageSupport() are called during Register/Revoke,
// UpdateDragImageOnXXX() functions are called on the corresponding drop
// target events.
void MSWInitDragImageSupport();
void MSWEndDragImageSupport();
void MSWUpdateDragImageOnData(wxCoord x, wxCoord y, wxDragResult res);
void MSWUpdateDragImageOnDragOver(wxCoord x, wxCoord y, wxDragResult res);
void MSWUpdateDragImageOnEnter(wxCoord x, wxCoord y, wxDragResult res);
void MSWUpdateDragImageOnLeave();
private:
// helper used by IsAcceptedData() and GetData()
wxDataFormat MSWGetSupportedFormat(IDataObject *pIDataSource) const;
wxIDropTarget *m_pIDropTarget; // the pointer to our COM interface
IDataObject *m_pIDataSource; // the pointer to the source data object
wxIDropTargetHelper *m_dropTargetHelper; // the drop target helper
wxDECLARE_NO_COPY_CLASS(wxDropTarget);
};
#endif //wxUSE_DRAG_AND_DROP
#endif //_WX_OLEDROPTGT_H

View File

@@ -0,0 +1,260 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/msw/ole/oleutils.h
// Purpose: OLE helper routines, OLE debugging support &c
// Author: Vadim Zeitlin
// Created: 19.02.1998
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_OLEUTILS_H
#define _WX_OLEUTILS_H
#include "wx/defs.h"
#if wxUSE_OLE
// ole2.h includes windows.h, so include wrapwin.h first
#include "wx/msw/wrapwin.h"
// get IUnknown, REFIID &c
#include <ole2.h>
#include "wx/intl.h"
#include "wx/log.h"
#include "wx/variant.h"
#include "wx/msw/ole/comimpl.h"
// ============================================================================
// General purpose functions and macros
// ============================================================================
// ----------------------------------------------------------------------------
// initialize/cleanup OLE
// ----------------------------------------------------------------------------
// Simple wrapper for OleInitialize().
//
// Avoid using it directly, use wxOleInitializer instead.
//
// return true if ok, false otherwise
inline bool wxOleInitialize()
{
const HRESULT
hr = ::OleInitialize(nullptr);
// RPC_E_CHANGED_MODE indicates that OLE had been already initialized
// before, albeit with different mode. Don't consider it to be an error as
// we don't actually care ourselves about the mode used so this allows the
// main application to call OleInitialize() on its own before we do if it
// needs non-default mode.
if ( hr != RPC_E_CHANGED_MODE && FAILED(hr) )
{
wxLogError(wxGetTranslation("Cannot initialize OLE"));
return false;
}
return true;
}
inline void wxOleUninitialize()
{
::OleUninitialize();
}
// wrapper around BSTR type (by Vadim Zeitlin)
class WXDLLIMPEXP_CORE wxBasicString
{
public:
// Constructs with the owned BSTR set to nullptr
wxBasicString() : m_bstrBuf(nullptr) {}
// Constructs with the owned BSTR created from a wxString
wxBasicString(const wxString& str)
: m_bstrBuf(SysAllocString(str.wc_str())) {}
// Constructs with the owned BSTR as a copy of the BSTR owned by bstr
wxBasicString(const wxBasicString& bstr) : m_bstrBuf(bstr.Copy()) {}
// Frees the owned BSTR
~wxBasicString() { SysFreeString(m_bstrBuf); }
// Creates the owned BSTR from a wxString
void AssignFromString(const wxString& str);
// Returns the owned BSTR and gives up its ownership,
// the caller is responsible for freeing it
wxNODISCARD BSTR Detach();
// Returns a copy of the owned BSTR,
// the caller is responsible for freeing it
wxNODISCARD BSTR Copy() const { return SysAllocString(m_bstrBuf); }
// Returns the address of the owned BSTR, not to be called
// when wxBasicString already contains a non-null BSTR
BSTR* ByRef();
// Sets its BSTR to a copy of the BSTR owned by bstr
wxBasicString& operator=(const wxBasicString& bstr);
/// Returns the owned BSTR while keeping its ownership
operator BSTR() const { return m_bstrBuf; }
// retrieve a copy of our string - caller must SysFreeString() it later!
wxDEPRECATED_MSG("use Copy() instead")
BSTR Get() const { return Copy(); }
private:
// actual string
BSTR m_bstrBuf;
};
#if wxUSE_VARIANT
// Convert variants
class WXDLLIMPEXP_FWD_BASE wxVariant;
// wrapper for CURRENCY type used in VARIANT (VARIANT.vt == VT_CY)
class WXDLLIMPEXP_CORE wxVariantDataCurrency : public wxVariantData
{
public:
wxVariantDataCurrency() { VarCyFromR8(0.0, &m_value); }
wxVariantDataCurrency(CURRENCY value) { m_value = value; }
CURRENCY GetValue() const { return m_value; }
void SetValue(CURRENCY value) { m_value = value; }
virtual bool Eq(wxVariantData& data) const override;
#if wxUSE_STD_IOSTREAM
virtual bool Write(std::ostream& str) const override;
#endif
virtual bool Write(wxString& str) const override;
wxNODISCARD wxNODISCARD wxVariantData* Clone() const override { return new wxVariantDataCurrency(m_value); }
virtual wxString GetType() const override { return wxS("currency"); }
DECLARE_WXANY_CONVERSION()
private:
CURRENCY m_value;
};
// wrapper for SCODE type used in VARIANT (VARIANT.vt == VT_ERROR)
class WXDLLIMPEXP_CORE wxVariantDataErrorCode : public wxVariantData
{
public:
wxVariantDataErrorCode(SCODE value = S_OK) { m_value = value; }
SCODE GetValue() const { return m_value; }
void SetValue(SCODE value) { m_value = value; }
virtual bool Eq(wxVariantData& data) const override;
#if wxUSE_STD_IOSTREAM
virtual bool Write(std::ostream& str) const override;
#endif
virtual bool Write(wxString& str) const override;
wxNODISCARD wxNODISCARD wxVariantData* Clone() const override { return new wxVariantDataErrorCode(m_value); }
virtual wxString GetType() const override { return wxS("errorcode"); }
DECLARE_WXANY_CONVERSION()
private:
SCODE m_value;
};
// wrapper for SAFEARRAY, used for passing multidimensional arrays in wxVariant
class WXDLLIMPEXP_CORE wxVariantDataSafeArray : public wxVariantData
{
public:
explicit wxVariantDataSafeArray(SAFEARRAY* value = nullptr)
{
m_value = value;
}
SAFEARRAY* GetValue() const { return m_value; }
void SetValue(SAFEARRAY* value) { m_value = value; }
virtual bool Eq(wxVariantData& data) const override;
#if wxUSE_STD_IOSTREAM
virtual bool Write(std::ostream& str) const override;
#endif
virtual bool Write(wxString& str) const override;
wxNODISCARD wxNODISCARD wxVariantData* Clone() const override { return new wxVariantDataSafeArray(m_value); }
virtual wxString GetType() const override { return wxS("safearray"); }
DECLARE_WXANY_CONVERSION()
private:
SAFEARRAY* m_value;
};
// Used by wxAutomationObject for its wxConvertOleToVariant() calls.
enum wxOleConvertVariantFlags
{
wxOleConvertVariant_Default = 0,
// If wxOleConvertVariant_ReturnSafeArrays flag is set, SAFEARRAYs
// contained in OLE 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
};
WXDLLIMPEXP_CORE
bool wxConvertVariantToOle(const wxVariant& variant, VARIANTARG& oleVariant);
WXDLLIMPEXP_CORE
bool wxConvertOleToVariant(const VARIANTARG& oleVariant, wxVariant& variant,
long flags = wxOleConvertVariant_Default);
#endif // wxUSE_VARIANT
// Convert string to Unicode
wxNODISCARD WXDLLIMPEXP_CORE BSTR wxConvertStringToOle(const wxString& str);
// Convert string from BSTR to wxString
WXDLLIMPEXP_CORE wxString wxConvertStringFromOle(BSTR bStr);
#else // !wxUSE_OLE
// ----------------------------------------------------------------------------
// stub functions to avoid #if wxUSE_OLE in the main code
// ----------------------------------------------------------------------------
inline bool wxOleInitialize() { return false; }
inline void wxOleUninitialize() { }
#endif // wxUSE_OLE/!wxUSE_OLE
// RAII class initializing OLE in its ctor and undoing it in its dtor.
class wxOleInitializer
{
public:
wxOleInitializer()
: m_ok(wxOleInitialize())
{
}
bool IsOk() const
{
return m_ok;
}
~wxOleInitializer()
{
if ( m_ok )
wxOleUninitialize();
}
private:
const bool m_ok;
wxDECLARE_NO_COPY_CLASS(wxOleInitializer);
};
#endif //_WX_OLEUTILS_H

View File

@@ -0,0 +1,394 @@
///////////////////////////////////////////////////////////////////////////////
// Name: msw/ole/safearray.h
// Purpose: Helpers for working with OLE SAFEARRAYs.
// Author: PB
// Created: 2012-09-23
// Copyright: (c) 2012 wxWidgets development team
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _MSW_OLE_SAFEARRAY_H_
#define _MSW_OLE_SAFEARRAY_H_
#include "wx/msw/ole/oleutils.h"
#if wxUSE_OLE && wxUSE_VARIANT
/*
wxSafeArray is wxWidgets wrapper for working with MS Windows SAFEARRAYs.
It also has convenience functions for converting between SAFEARRAY
and wxVariant with list type or wxArrayString.
*/
// The base class with type-independent methods. It exists solely in order to
// reduce the template bloat.
class WXDLLIMPEXP_CORE wxSafeArrayBase
{
public:
// If owns a SAFEARRAY, it's unlocked and destroyed.
virtual ~wxSafeArrayBase() { Destroy(); }
// Unlocks and destroys the owned SAFEARRAY.
void Destroy();
// Unlocks the owned SAFEARRAY, returns it and gives up its ownership.
wxNODISCARD SAFEARRAY* Detach();
// Returns true if has a valid SAFEARRAY.
bool HasArray() const { return m_array != nullptr; }
// Returns the number of dimensions.
size_t GetDim() const;
// Returns lower bound for dimension dim in bound. Dimensions start at 1.
bool GetLBound(size_t dim, long& bound) const;
// Returns upper bound for dimension dim in bound. Dimensions start at 1.
bool GetUBound(size_t dim, long& bound) const;
// Returns element count for dimension dim. Dimensions start at 1.
size_t GetCount(size_t dim) const;
protected:
// Default constructor, protected so the class can't be used on its own,
// it's only used as a base class of wxSafeArray<>.
wxSafeArrayBase()
{
m_array = nullptr;
}
bool Lock();
bool Unlock();
SAFEARRAY* m_array;
};
// wxSafeArrayConvertor<> must be specialized for the type in order to allow
// using it with wxSafeArray<>.
//
// We specialize it below for the standard types.
template <VARTYPE varType>
struct wxSafeArrayConvertor {};
/**
Macro for specializing wxSafeArrayConvertor for simple types.
The template parameters are:
- externType: basic C data type, e.g. wxFloat64 or wxInt32
- varType: corresponding VARIANT type constant, e.g. VT_R8 or VT_I4.
*/
#define wxSPECIALIZE_WXSAFEARRAY_CONVERTOR_SIMPLE(externType, varType) \
template <> \
struct wxSafeArrayConvertor<varType> \
{ \
typedef externType externT; \
typedef externT internT; \
static bool ToArray(const externT& from, internT& to) \
{ \
to = from; \
return true; \
} \
static bool FromArray(const internT& from, externT& to) \
{ \
to = from; \
return true; \
} \
}
wxSPECIALIZE_WXSAFEARRAY_CONVERTOR_SIMPLE(wxInt16, VT_I2);
wxSPECIALIZE_WXSAFEARRAY_CONVERTOR_SIMPLE(wxInt32, VT_I4);
wxSPECIALIZE_WXSAFEARRAY_CONVERTOR_SIMPLE(wxFloat32, VT_R4);
wxSPECIALIZE_WXSAFEARRAY_CONVERTOR_SIMPLE(wxFloat64, VT_R8);
// Specialization for VT_BSTR using wxString.
template <>
struct wxSafeArrayConvertor<VT_BSTR>
{
typedef wxString externT;
typedef BSTR internT;
static bool ToArray(const wxString& from, BSTR& to)
{
BSTR bstr = wxConvertStringToOle(from);
if ( !bstr && !from.empty() )
{
// BSTR can be null for empty strings but if the string was
// not empty, it means we failed to allocate memory for it.
return false;
}
to = bstr;
return true;
}
static bool FromArray(const BSTR from, wxString& to)
{
to = wxConvertStringFromOle(from);
return true;
}
};
// Specialization for VT_VARIANT using wxVariant.
template <>
struct wxSafeArrayConvertor<VT_VARIANT>
{
typedef wxVariant externT;
typedef VARIANT internT;
static bool ToArray(const wxVariant& from, VARIANT& to)
{
return wxConvertVariantToOle(from, to);
}
static bool FromArray(const VARIANT& from, wxVariant& to)
{
return wxConvertOleToVariant(from, to);
}
};
template <VARTYPE varType>
class wxSafeArray : public wxSafeArrayBase
{
public:
typedef wxSafeArrayConvertor<varType> Convertor;
typedef typename Convertor::internT internT;
typedef typename Convertor::externT externT;
// Default constructor.
wxSafeArray()
{
m_array = nullptr;
}
// Creates and locks a zero-based one-dimensional SAFEARRAY with the given
// number of elements.
bool Create(size_t count)
{
SAFEARRAYBOUND bound;
bound.lLbound = 0;
bound.cElements = count;
return Create(&bound, 1);
}
// Creates and locks a SAFEARRAY. See SafeArrayCreate() in MSDN
// documentation for more information.
bool Create(SAFEARRAYBOUND* bound, size_t dimensions)
{
wxCHECK_MSG( !m_array, false, wxS("Can't be created twice") );
m_array = SafeArrayCreate(varType, dimensions, bound);
if ( !m_array )
return false;
return Lock();
}
/**
Creates a 0-based one-dimensional SAFEARRAY from wxVariant with the
list type.
Can be called only for wxSafeArray<VT_VARIANT>.
*/
bool CreateFromListVariant(const wxVariant& variant)
{
wxCHECK(varType == VT_VARIANT, false);
wxCHECK(variant.GetType() == wxS("list"), false);
if ( !Create(variant.GetCount()) )
return false;
VARIANT* data = static_cast<VARIANT*>(m_array->pvData);
for ( size_t i = 0; i < variant.GetCount(); i++)
{
if ( !Convertor::ToArray(variant[i], data[i]) )
return false;
}
return true;
}
/**
Creates a 0-based one-dimensional SAFEARRAY from wxArrayString.
Can be called only for wxSafeArray<VT_BSTR>.
*/
bool CreateFromArrayString(const wxArrayString& strings)
{
wxCHECK(varType == VT_BSTR, false);
if ( !Create(strings.size()) )
return false;
BSTR* data = static_cast<BSTR*>(m_array->pvData);
for ( size_t i = 0; i < strings.size(); i++ )
{
if ( !Convertor::ToArray(strings[i], data[i]) )
return false;
}
return true;
}
/**
Attaches and locks an existing SAFEARRAY.
The array must have the same VARTYPE as this wxSafeArray was
instantiated with.
*/
bool Attach(SAFEARRAY* array)
{
wxCHECK_MSG(!m_array && array, false,
wxS("Can only attach a valid array to an uninitialized one") );
VARTYPE vt;
HRESULT hr = SafeArrayGetVartype(array, &vt);
if ( FAILED(hr) )
{
wxLogApiError(wxS("SafeArrayGetVarType()"), hr);
return false;
}
wxCHECK_MSG(vt == varType, false,
wxS("Attaching array of invalid type"));
m_array = array;
return Lock();
}
/**
Indices have the same row-column order as rgIndices in
SafeArrayPutElement(), i.e. they follow BASIC rules, NOT C ones.
*/
bool SetElement(long* indices, const externT& element)
{
wxCHECK_MSG( m_array, false, wxS("Uninitialized array") );
wxCHECK_MSG( indices, false, wxS("Invalid index") );
internT* data;
if ( FAILED( SafeArrayPtrOfIndex(m_array, (LONG *)indices, (void**)&data) ) )
return false;
return Convertor::ToArray(element, *data);
}
/**
Indices have the same row-column order as rgIndices in
SafeArrayPutElement(), i.e. they follow BASIC rules, NOT C ones.
*/
bool GetElement(long* indices, externT& element) const
{
wxCHECK_MSG( m_array, false, wxS("Uninitialized array") );
wxCHECK_MSG( indices, false, wxS("Invalid index") );
internT* data;
if ( FAILED( SafeArrayPtrOfIndex(m_array, (LONG *)indices, (void**)&data) ) )
return false;
return Convertor::FromArray(*data, element);
}
/**
Converts the array to a wxVariant with the list type, regardless of the
underlying SAFEARRAY type.
If the array is multidimensional, it is flattened using the algorithm
originally employed in wxConvertOleToVariant().
*/
bool ConvertToVariant(wxVariant& variant) const
{
wxCHECK_MSG( m_array, false, wxS("Uninitialized array") );
size_t dims = m_array->cDims;
size_t count = 1;
for ( size_t i = 0; i < dims; i++ )
count *= m_array->rgsabound[i].cElements;
const internT* data = static_cast<const internT*>(m_array->pvData);
externT element;
variant.ClearList();
for ( size_t i1 = 0; i1 < count; i1++ )
{
if ( !Convertor::FromArray(data[i1], element) )
{
variant.ClearList();
return false;
}
variant.Append(element);
}
return true;
}
/**
Converts an array to an ArrayString.
Can be called only for wxSafeArray<VT_BSTR>. If the array is
multidimensional, it is flattened using the algorithm originally
employed in wxConvertOleToVariant().
*/
bool ConvertToArrayString(wxArrayString& strings) const
{
wxCHECK_MSG( m_array, false, wxS("Uninitialized array") );
wxCHECK(varType == VT_BSTR, false);
size_t dims = m_array->cDims;
size_t count = 1;
for ( size_t i = 0; i < dims; i++ )
count *= m_array->rgsabound[i].cElements;
const BSTR* data = static_cast<const BSTR*>(m_array->pvData);
wxString element;
strings.clear();
strings.reserve(count);
for ( size_t i1 = 0; i1 < count; i1++ )
{
if ( !Convertor::FromArray(data[i1], element) )
{
strings.clear();
return false;
}
strings.push_back(element);
}
return true;
}
static bool ConvertToVariant(SAFEARRAY* psa, wxVariant& variant)
{
wxSafeArray<varType> sa;
bool result = false;
if ( sa.Attach(psa) )
result = sa.ConvertToVariant(variant);
if ( sa.HasArray() )
wxUnusedVar(sa.Detach()); // we do not own the array, just attached it
return result;
}
static bool ConvertToArrayString(SAFEARRAY* psa, wxArrayString& strings)
{
wxSafeArray<varType> sa;
bool result = false;
if ( sa.Attach(psa) )
result = sa.ConvertToArrayString(strings);
if ( sa.HasArray() )
wxUnusedVar(sa.Detach()); // we do not own the array, just attached it
return result;
}
wxDECLARE_NO_COPY_TEMPLATE_CLASS(wxSafeArray, varType);
};
#endif // wxUSE_OLE && wxUSE_VARIANT
#endif // _MSW_OLE_SAFEARRAY_H_

View File

@@ -0,0 +1,86 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/msw/ole/uuid.h
// Purpose: encapsulates an UUID with some added helper functions
// Author: Vadim Zeitlin
// Created: 11.07.97
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
// Licence: wxWindows licence
//
// Notes: you should link your project with RPCRT4.LIB!
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_OLEUUID_H
#define _WX_OLEUUID_H
#include "wx/chartype.h"
// ------------------------------------------------------------------
// UUID (Universally Unique IDentifier) definition
// ------------------------------------------------------------------
// ----- taken from RPC.H
#ifndef UUID_DEFINED // in some cases RPC.H will be already
typedef struct
{
unsigned long Data1;
unsigned short Data2;
unsigned short Data3;
unsigned char Data4[8];
} UUID; // UUID = GUID = CLSID = LIBID = IID
#endif // UUID_DEFINED
#ifndef GUID_DEFINED
typedef UUID GUID;
#define UUID_DEFINED // prevent redefinition
#endif // GUID_DEFINED
typedef unsigned char uchar;
// ------------------------------------------------------------------
// a class to store UUID and its string representation
// ------------------------------------------------------------------
// uses RPC functions to create/convert Universally Unique Identifiers
class WXDLLIMPEXP_CORE Uuid
{
private:
UUID m_uuid;
wxUChar *m_pszUuid; // this string is alloc'd and freed by RPC
wxChar *m_pszCForm; // this string is allocated in Set/Create
void UuidToCForm();
// function used to set initial state by all ctors
void Init() { m_pszUuid = nullptr; m_pszCForm = nullptr; }
public:
// ctors & dtor
Uuid() { Init(); }
Uuid(const wxChar *pc) { Init(); Set(pc); }
Uuid(const UUID &uuid) { Init(); Set(uuid); }
~Uuid();
// copy ctor and assignment operator needed for this class
Uuid(const Uuid& uuid);
Uuid& operator=(const Uuid& uuid);
// create a brand new UUID
void Create();
// set value of UUID
bool Set(const wxChar *pc); // from a string, returns true if ok
void Set(const UUID& uuid); // from another UUID (never fails)
// comparison operators
bool operator==(const Uuid& uuid) const;
bool operator!=(const Uuid& uuid) const { return !(*this == uuid); }
// accessors
operator const UUID*() const { return &m_uuid; }
operator const wxChar*() const { return (wxChar *)(m_pszUuid); }
// return string representation of the UUID in the C form
// (as in DEFINE_GUID macro)
const wxChar *CForm() const { return m_pszCForm; }
};
#endif //_WX_OLEUUID_H