summaryrefslogtreecommitdiffstats
path: root/extensions/test/ole/MfcControl/MfcControlCtl.cpp
blob: 201a27204e764bd20f2ff5c3a4d5e83a039bffa6 (plain)
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */
// MfcControlCtl.cpp : Implementation of the CMfcControlCtrl ActiveX Control class.

#include "stdafx.h"
#include "MfcControl.h"
#include "MfcControlCtl.h"
#include "MfcControlPpg.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


IMPLEMENT_DYNCREATE(CMfcControlCtrl, COleControl)


/////////////////////////////////////////////////////////////////////////////
// Message map

BEGIN_MESSAGE_MAP(CMfcControlCtrl, COleControl)
    //{{AFX_MSG_MAP(CMfcControlCtrl)
    // NOTE - ClassWizard will add and remove message map entries
    //    DO NOT EDIT what you see in these blocks of generated code !
    //}}AFX_MSG_MAP
    ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// Dispatch map

BEGIN_DISPATCH_MAP(CMfcControlCtrl, COleControl)
    //{{AFX_DISPATCH_MAP(CMfcControlCtrl)
    DISP_FUNCTION(CMfcControlCtrl, "inShort", inShort, VT_I2, VTS_I2)
    DISP_FUNCTION(CMfcControlCtrl, "inLong", inLong, VT_I4, VTS_I4)
    DISP_FUNCTION(CMfcControlCtrl, "inString", inString, VT_BSTR, VTS_PBSTR)
    DISP_FUNCTION(CMfcControlCtrl, "inFloat", inFloat, VT_R4, VTS_R4)
    DISP_FUNCTION(CMfcControlCtrl, "inDouble", inDouble, VT_R8, VTS_R8)
    DISP_FUNCTION(CMfcControlCtrl, "inVariant", inVariant, VT_VARIANT, VTS_VARIANT)
    DISP_FUNCTION(CMfcControlCtrl, "inObject", inObject, VT_DISPATCH, VTS_DISPATCH)
    DISP_FUNCTION(CMfcControlCtrl, "outShort", outShort, VT_EMPTY, VTS_PI2)
    DISP_FUNCTION(CMfcControlCtrl, "outLong", outLong, VT_EMPTY, VTS_PI4)
    DISP_FUNCTION(CMfcControlCtrl, "outString", outString, VT_EMPTY, VTS_PBSTR)
    DISP_FUNCTION(CMfcControlCtrl, "outFloat", outFloat, VT_EMPTY, VTS_PR4)
    DISP_FUNCTION(CMfcControlCtrl, "outDouble", outDouble, VT_EMPTY, VTS_PR8)
    DISP_FUNCTION(CMfcControlCtrl, "outVariant", outVariant, VT_EMPTY, VTS_PVARIANT)
    DISP_FUNCTION(CMfcControlCtrl, "outObject", outObject, VT_EMPTY, VTS_PDISPATCH)
    //}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()


/////////////////////////////////////////////////////////////////////////////
// Event map

BEGIN_EVENT_MAP(CMfcControlCtrl, COleControl)
    //{{AFX_EVENT_MAP(CMfcControlCtrl)
    // NOTE - ClassWizard will add and remove event map entries
    //    DO NOT EDIT what you see in these blocks of generated code !
    //}}AFX_EVENT_MAP
END_EVENT_MAP()


/////////////////////////////////////////////////////////////////////////////
// Property pages

// TODO: Add more property pages as needed.  Remember to increase the count!
BEGIN_PROPPAGEIDS(CMfcControlCtrl, 1)
    PROPPAGEID(CMfcControlPropPage::guid)
END_PROPPAGEIDS(CMfcControlCtrl)


/////////////////////////////////////////////////////////////////////////////
// Initialize class factory and guid

IMPLEMENT_OLECREATE_EX(CMfcControlCtrl, "MFCCONTROL.MfcControlCtrl.1",
    0xac221fb6, 0xa0d8, 0x11d4, 0x83, 0x3b, 0, 0x50, 0x4, 0x52, 0x6a, 0xb4)


/////////////////////////////////////////////////////////////////////////////
// Type library ID and version

IMPLEMENT_OLETYPELIB(CMfcControlCtrl, _tlid, _wVerMajor, _wVerMinor)


/////////////////////////////////////////////////////////////////////////////
// Interface IDs

const IID BASED_CODE IID_DMfcControl =
        { 0xac221fb4, 0xa0d8, 0x11d4, { 0x83, 0x3b, 0, 0x50, 0x4, 0x52, 0x6a, 0xb4 } };
const IID BASED_CODE IID_DMfcControlEvents =
        { 0xac221fb5, 0xa0d8, 0x11d4, { 0x83, 0x3b, 0, 0x50, 0x4, 0x52, 0x6a, 0xb4 } };


/////////////////////////////////////////////////////////////////////////////
// Control type information

static const DWORD BASED_CODE _dwMfcControlOleMisc =
    OLEMISC_ACTIVATEWHENVISIBLE |
    OLEMISC_SETCLIENTSITEFIRST |
    OLEMISC_INSIDEOUT |
    OLEMISC_CANTLINKINSIDE |
    OLEMISC_RECOMPOSEONRESIZE;

IMPLEMENT_OLECTLTYPE(CMfcControlCtrl, IDS_MFCCONTROL, _dwMfcControlOleMisc)


/////////////////////////////////////////////////////////////////////////////
// CMfcControlCtrl::CMfcControlCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CMfcControlCtrl

BOOL CMfcControlCtrl::CMfcControlCtrlFactory::UpdateRegistry(BOOL bRegister)
{
    // TODO: Verify that your control follows apartment-model threading rules.
    // Refer to MFC TechNote 64 for more information.
    // If your control does not conform to the apartment-model rules, then
    // you must modify the code below, changing the 6th parameter from
    // afxRegApartmentThreading to 0.

    if (bRegister)
        return AfxOleRegisterControlClass(
            AfxGetInstanceHandle(),
            m_clsid,
            m_lpszProgID,
            IDS_MFCCONTROL,
            IDB_MFCCONTROL,
            afxRegApartmentThreading,
            _dwMfcControlOleMisc,
            _tlid,
            _wVerMajor,
            _wVerMinor);
    else
        return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}


/////////////////////////////////////////////////////////////////////////////
// CMfcControlCtrl::CMfcControlCtrl - Constructor

CMfcControlCtrl::CMfcControlCtrl()
{
    InitializeIIDs(&IID_DMfcControl, &IID_DMfcControlEvents);

    // TODO: Initialize your control's instance data here.
}


/////////////////////////////////////////////////////////////////////////////
// CMfcControlCtrl::~CMfcControlCtrl - Destructor

CMfcControlCtrl::~CMfcControlCtrl()
{
    // TODO: Cleanup your control's instance data here.
}


/////////////////////////////////////////////////////////////////////////////
// CMfcControlCtrl::OnDraw - Drawing function

void CMfcControlCtrl::OnDraw(
            CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
    // TODO: Replace the following code with your own drawing code.
    pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
    pdc->Ellipse(rcBounds);
}


/////////////////////////////////////////////////////////////////////////////
// CMfcControlCtrl::DoPropExchange - Persistence support

void CMfcControlCtrl::DoPropExchange(CPropExchange* pPX)
{
    ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
    COleControl::DoPropExchange(pPX);

    // TODO: Call PX_ functions for each persistent custom property.

}


/////////////////////////////////////////////////////////////////////////////
// CMfcControlCtrl::OnResetState - Reset control to default state

void CMfcControlCtrl::OnResetState()
{
    COleControl::OnResetState();  // Resets defaults found in DoPropExchange

    // TODO: Reset any other control state here.
}


/////////////////////////////////////////////////////////////////////////////
// CMfcControlCtrl message handlers


short CMfcControlCtrl::inShort(short val)
{
    char buf[256];
    sprintf( buf, "inByte: value= %d", val);
    ::MessageBoxA( NULL, buf, "MFCCONTROL.MfcControl", MB_OK);
    return val+1;
}

long CMfcControlCtrl::inLong(long val)
{
    char buf[256];
    sprintf( buf, "inLong: value= %d", val);
    ::MessageBoxA( NULL, buf, "MFCCONTROL.MfcControl", MB_OK);
    return val+1;
}

BSTR CMfcControlCtrl::inString(BSTR* val)
{
    CString strResult;
    strResult= *val;
    char buf[256];
    sprintf( buf, "inString: value= %S", *val);
    ::MessageBoxA( NULL, buf, "MFCCONTROL.MfcControl", MB_OK);
    strResult += L" an appended string";
    return strResult.AllocSysString();
}

float CMfcControlCtrl::inFloat(float val)
{
    char buf[256];
    sprintf( buf, "inFloat: value= %f", val);
    ::MessageBoxA( NULL, buf, "MFCCONTROL.MfcControl", MB_OK);
    return val+1;
}

double CMfcControlCtrl::inDouble(double val)
{
    char buf[256];
    sprintf( buf, "inDouble: value= %g", val);
    ::MessageBoxA( NULL, buf, "MFCCONTROL.MfcControl", MB_OK);
    return val+1;
}

VARIANT CMfcControlCtrl::inVariant(const VARIANT FAR& val)
{
    VARIANT vaResult;
    VariantInit(&vaResult);
    VariantCopyInd( &vaResult, const_cast<VARIANT*>(&val));
    if( vaResult.vt == VT_BSTR)
    {
        char buf[256];
        sprintf( buf, "inVariant: value= %S", vaResult.bstrVal);
        ::MessageBoxA( NULL, buf, "MFCCONTROL.MfcControl", MB_OK);

    }
    return _variant_t( L" a string from CMfcControlCtrl::inVariant");
}

LPDISPATCH CMfcControlCtrl::inObject(LPDISPATCH val)
{
    char buf[256];
    _bstr_t bstr;
    HRESULT hr= S_OK;
    COleVariant var;
    DISPID id;
    OLECHAR* name=L"prpString";
    if( SUCCEEDED(hr= val->GetIDsOfNames( IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &id)))
    {
        DISPPARAMS params={0,0,0,0};
        hr= val->Invoke( id, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET, &params, &var,0,0);

    }

    if( var.vt== VT_BSTR)
        bstr= var.bstrVal;
    sprintf( buf, "inObject: value= %S", (wchar_t*)bstr);
    ::MessageBoxA( NULL, buf, "MFCCONTROL.MfcControl", MB_OK);

    return NULL;
}


void CMfcControlCtrl::outShort(short* val)
{
    *val= 123;
}

void CMfcControlCtrl::outLong(long* val)
{
    *val= 1234;
}

void CMfcControlCtrl::outString(BSTR FAR* val)
{
    *val= SysAllocString(L"A string from CMfcControlCtrl::outString ");
}

void CMfcControlCtrl::outFloat(float* val)
{
    *val= 3.14f;
}

void CMfcControlCtrl::outDouble(double* val)
{
    *val= 3.145;
}

void CMfcControlCtrl::outVariant(VARIANT FAR* val)
{
    VariantInit( val);
    val->vt= VT_BSTR;
    val->bstrVal= SysAllocString( L"a string in a VARIANT");
}

void CMfcControlCtrl::outObject(LPDISPATCH FAR* val)
{
    //{BFE10EBE-8584-11D4-005004526AB4}
    HRESULT hr= S_OK;
    CLSID clsTestControl;
    hr= CLSIDFromProgID( L"AxTestComponents.Basic", &clsTestControl);

    IDispatch* pDisp= NULL;
    hr= CoCreateInstance( clsTestControl, NULL, CLSCTX_ALL, __uuidof(IDispatch), (void**)&pDisp);

    if( SUCCEEDED( hr) && val)
    {
        COleVariant var;
        DISPID id;
        OLECHAR* name=L"prpString";
        if( SUCCEEDED(hr= pDisp->GetIDsOfNames( IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &id)))
        {
            COleVariant vaParam1(_T("this is property prpString of AxTestComponents.Basic"));
            DISPID dispidPut= DISPID_PROPERTYPUT;
            DISPPARAMS params;
            params.cArgs= 1;
            params.cNamedArgs= 1;
            params.rgdispidNamedArgs= &dispidPut;
            params.rgvarg= &vaParam1;

            hr= pDisp->Invoke( id, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUT, &params, &var,0,0);
            *val= pDisp;
        }

    }

}
// VT_I1

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */