File: activex.h

package info (click to toggle)
wxpython3.0 3.0.2.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 482,760 kB
  • ctags: 518,293
  • sloc: cpp: 2,127,226; python: 294,045; makefile: 51,942; ansic: 19,033; sh: 3,013; xml: 1,629; perl: 17
file content (263 lines) | stat: -rw-r--r-- 8,165 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
///////////////////////////////////////////////////////////////////////////////
// Name:        wx/msw/ole/activex.h
// Purpose:     wxActiveXContainer class
// Author:      Ryan Norton <wxprojects@comcast.net>
// Modified by:
// 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>

#if !defined(__WXWINCE__) || defined(__WINCE_STANDARDSDK__)
#include <exdisp.h>
#endif

#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 = NULL) : m_interface(pInterface)
        {}
    wxAutoOleInterface(REFIID riid, IUnknown *pUnk) : m_interface(NULL)
        { QueryInterface(riid, pUnk); }
    wxAutoOleInterface(REFIID riid, IDispatch *pDispatch) : m_interface(NULL)
        { QueryInterface(riid, pDispatch); }
    wxAutoOleInterface(REFCLSID clsid, REFIID riid) : m_interface(NULL)
        { CreateInstance(clsid, riid); }
    wxAutoOleInterface(const wxAutoOleInterface& ti) : m_interface(NULL)
        { 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 = NULL;
    }

    HRESULT QueryInterface(REFIID riid, IUnknown *pUnk)
    {
        Free();
        wxASSERT(pUnk != NULL);
        return pUnk->QueryInterface(riid, (void **)&m_interface);
    }

    HRESULT CreateInstance(REFCLSID clsid, REFIID riid)
    {
        Free();
        return CoCreateInstance
               (
                   clsid,
                   NULL,
                   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 != NULL; }

protected:
    I *m_interface;
};

#if WXWIN_COMPATIBILITY_2_8
// this macro is kept for compatibility with older wx versions
#define WX_DECLARE_AUTOOLE(wxAutoOleInterfaceType, I) \
    typedef wxAutoOleInterface<I> wxAutoOleInterfaceType;
#endif // WXWIN_COMPATIBILITY_2_8

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);
    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:
    virtual wxEvent *Clone() const
    { 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 ), NULL ),

#endif // wxUSE_ACTIVEX

#endif // _WX_MSW_OLE_ACTIVEXCONTAINER_H_