1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 // MfcControlCtl.cpp : Implementation of the CMfcControlCtrl ActiveX Control class.
22 #include "MfcControl.h"
23 #include "MfcControlCtl.h"
24 #include "MfcControlPpg.h"
30 static char THIS_FILE
[] = __FILE__
;
34 IMPLEMENT_DYNCREATE(CMfcControlCtrl
, COleControl
)
40 BEGIN_MESSAGE_MAP(CMfcControlCtrl
, COleControl
)
41 //{{AFX_MSG_MAP(CMfcControlCtrl)
42 // NOTE - ClassWizard will add and remove message map entries
43 // DO NOT EDIT what you see in these blocks of generated code !
45 ON_OLEVERB(AFX_IDS_VERB_PROPERTIES
, OnProperties
)
52 BEGIN_DISPATCH_MAP(CMfcControlCtrl
, COleControl
)
53 //{{AFX_DISPATCH_MAP(CMfcControlCtrl)
54 DISP_FUNCTION(CMfcControlCtrl
, "inShort", inShort
, VT_I2
, VTS_I2
)
55 DISP_FUNCTION(CMfcControlCtrl
, "inLong", inLong
, VT_I4
, VTS_I4
)
56 DISP_FUNCTION(CMfcControlCtrl
, "inString", inString
, VT_BSTR
, VTS_PBSTR
)
57 DISP_FUNCTION(CMfcControlCtrl
, "inFloat", inFloat
, VT_R4
, VTS_R4
)
58 DISP_FUNCTION(CMfcControlCtrl
, "inDouble", inDouble
, VT_R8
, VTS_R8
)
59 DISP_FUNCTION(CMfcControlCtrl
, "inVariant", inVariant
, VT_VARIANT
, VTS_VARIANT
)
60 DISP_FUNCTION(CMfcControlCtrl
, "inObject", inObject
, VT_DISPATCH
, VTS_DISPATCH
)
61 DISP_FUNCTION(CMfcControlCtrl
, "outShort", outShort
, VT_EMPTY
, VTS_PI2
)
62 DISP_FUNCTION(CMfcControlCtrl
, "outLong", outLong
, VT_EMPTY
, VTS_PI4
)
63 DISP_FUNCTION(CMfcControlCtrl
, "outString", outString
, VT_EMPTY
, VTS_PBSTR
)
64 DISP_FUNCTION(CMfcControlCtrl
, "outFloat", outFloat
, VT_EMPTY
, VTS_PR4
)
65 DISP_FUNCTION(CMfcControlCtrl
, "outDouble", outDouble
, VT_EMPTY
, VTS_PR8
)
66 DISP_FUNCTION(CMfcControlCtrl
, "outVariant", outVariant
, VT_EMPTY
, VTS_PVARIANT
)
67 DISP_FUNCTION(CMfcControlCtrl
, "outObject", outObject
, VT_EMPTY
, VTS_PDISPATCH
)
75 BEGIN_EVENT_MAP(CMfcControlCtrl
, COleControl
)
76 //{{AFX_EVENT_MAP(CMfcControlCtrl)
77 // NOTE - ClassWizard will add and remove event map entries
78 // DO NOT EDIT what you see in these blocks of generated code !
86 // TODO: Add more property pages as needed. Remember to increase the count!
87 BEGIN_PROPPAGEIDS(CMfcControlCtrl
, 1)
88 PROPPAGEID(CMfcControlPropPage::guid
)
89 END_PROPPAGEIDS(CMfcControlCtrl
)
93 // Initialize class factory and guid
95 IMPLEMENT_OLECREATE_EX(CMfcControlCtrl
, "MFCCONTROL.MfcControlCtrl.1",
96 0xac221fb6, 0xa0d8, 0x11d4, 0x83, 0x3b, 0, 0x50, 0x4, 0x52, 0x6a, 0xb4)
100 // Type library ID and version
102 IMPLEMENT_OLETYPELIB(CMfcControlCtrl
, _tlid
, _wVerMajor
, _wVerMinor
)
108 const IID BASED_CODE IID_DMfcControl
=
109 { 0xac221fb4, 0xa0d8, 0x11d4, { 0x83, 0x3b, 0, 0x50, 0x4, 0x52, 0x6a, 0xb4 } };
110 const IID BASED_CODE IID_DMfcControlEvents
=
111 { 0xac221fb5, 0xa0d8, 0x11d4, { 0x83, 0x3b, 0, 0x50, 0x4, 0x52, 0x6a, 0xb4 } };
115 // Control type information
117 static const DWORD BASED_CODE _dwMfcControlOleMisc
=
118 OLEMISC_ACTIVATEWHENVISIBLE
|
119 OLEMISC_SETCLIENTSITEFIRST
|
121 OLEMISC_CANTLINKINSIDE
|
122 OLEMISC_RECOMPOSEONRESIZE
;
124 IMPLEMENT_OLECTLTYPE(CMfcControlCtrl
, IDS_MFCCONTROL
, _dwMfcControlOleMisc
)
128 // CMfcControlCtrl::CMfcControlCtrlFactory::UpdateRegistry -
129 // Adds or removes system registry entries for CMfcControlCtrl
131 BOOL
CMfcControlCtrl::CMfcControlCtrlFactory::UpdateRegistry(BOOL bRegister
)
133 // TODO: Verify that your control follows apartment-model threading rules.
134 // Refer to MFC TechNote 64 for more information.
135 // If your control does not conform to the apartment-model rules, then
136 // you must modify the code below, changing the 6th parameter from
137 // afxRegApartmentThreading to 0.
140 return AfxOleRegisterControlClass(
141 AfxGetInstanceHandle(),
146 afxRegApartmentThreading
,
147 _dwMfcControlOleMisc
,
152 return AfxOleUnregisterClass(m_clsid
, m_lpszProgID
);
157 // CMfcControlCtrl::CMfcControlCtrl - Constructor
159 CMfcControlCtrl::CMfcControlCtrl()
161 InitializeIIDs(&IID_DMfcControl
, &IID_DMfcControlEvents
);
163 // TODO: Initialize your control's instance data here.
168 // CMfcControlCtrl::~CMfcControlCtrl - Destructor
170 CMfcControlCtrl::~CMfcControlCtrl()
172 // TODO: Cleanup your control's instance data here.
177 // CMfcControlCtrl::OnDraw - Drawing function
179 void CMfcControlCtrl::OnDraw(
180 CDC
* pdc
, const CRect
& rcBounds
, const CRect
& rcInvalid
)
182 // TODO: Replace the following code with your own drawing code.
183 pdc
->FillRect(rcBounds
, CBrush::FromHandle((HBRUSH
)GetStockObject(WHITE_BRUSH
)));
184 pdc
->Ellipse(rcBounds
);
189 // CMfcControlCtrl::DoPropExchange - Persistence support
191 void CMfcControlCtrl::DoPropExchange(CPropExchange
* pPX
)
193 ExchangeVersion(pPX
, MAKELONG(_wVerMinor
, _wVerMajor
));
194 COleControl::DoPropExchange(pPX
);
196 // TODO: Call PX_ functions for each persistent custom property.
202 // CMfcControlCtrl::OnResetState - Reset control to default state
204 void CMfcControlCtrl::OnResetState()
206 COleControl::OnResetState(); // Resets defaults found in DoPropExchange
208 // TODO: Reset any other control state here.
213 // CMfcControlCtrl message handlers
216 short CMfcControlCtrl::inShort(short val
)
219 sprintf( buf
, "inByte: value= %d", val
);
220 ::MessageBoxA( NULL
, buf
, "MFCCONTROL.MfcControl", MB_OK
);
224 long CMfcControlCtrl::inLong(long val
)
227 sprintf( buf
, "inLong: value= %d", val
);
228 ::MessageBoxA( NULL
, buf
, "MFCCONTROL.MfcControl", MB_OK
);
232 BSTR
CMfcControlCtrl::inString(BSTR
* val
)
237 sprintf( buf
, "inString: value= %S", *val
);
238 ::MessageBoxA( NULL
, buf
, "MFCCONTROL.MfcControl", MB_OK
);
239 strResult
+= L
" an appended string";
240 return strResult
.AllocSysString();
243 float CMfcControlCtrl::inFloat(float val
)
246 sprintf( buf
, "inFloat: value= %f", val
);
247 ::MessageBoxA( NULL
, buf
, "MFCCONTROL.MfcControl", MB_OK
);
251 double CMfcControlCtrl::inDouble(double val
)
254 sprintf( buf
, "inDouble: value= %g", val
);
255 ::MessageBoxA( NULL
, buf
, "MFCCONTROL.MfcControl", MB_OK
);
259 VARIANT
CMfcControlCtrl::inVariant(const VARIANT FAR
& val
)
262 VariantInit(&vaResult
);
263 VariantCopyInd( &vaResult
, const_cast<VARIANT
*>(&val
));
264 if( vaResult
.vt
== VT_BSTR
)
267 sprintf( buf
, "inVariant: value= %S", vaResult
.bstrVal
);
268 ::MessageBoxA( NULL
, buf
, "MFCCONTROL.MfcControl", MB_OK
);
271 return _variant_t( L
" a string from CMfcControlCtrl::inVariant");
274 LPDISPATCH
CMfcControlCtrl::inObject(LPDISPATCH val
)
281 OLECHAR
* name
=L
"prpString";
282 if( SUCCEEDED(hr
= val
->GetIDsOfNames( IID_NULL
, &name
, 1, LOCALE_USER_DEFAULT
, &id
)))
284 DISPPARAMS params
={0,0,0,0};
285 hr
= val
->Invoke( id
, IID_NULL
, LOCALE_USER_DEFAULT
, DISPATCH_PROPERTYGET
, ¶ms
, &var
,0,0);
289 if( var
.vt
== VT_BSTR
)
291 sprintf( buf
, "inObject: value= %S", (wchar_t*)bstr
);
292 ::MessageBoxA( NULL
, buf
, "MFCCONTROL.MfcControl", MB_OK
);
298 void CMfcControlCtrl::outShort(short* val
)
303 void CMfcControlCtrl::outLong(long* val
)
308 void CMfcControlCtrl::outString(BSTR FAR
* val
)
310 *val
= SysAllocString(L
"A string from CMfcControlCtrl::outString ");
313 void CMfcControlCtrl::outFloat(float* val
)
318 void CMfcControlCtrl::outDouble(double* val
)
323 void CMfcControlCtrl::outVariant(VARIANT FAR
* val
)
327 val
->bstrVal
= SysAllocString( L
"a string in a VARIANT");
330 void CMfcControlCtrl::outObject(LPDISPATCH FAR
* val
)
332 //{BFE10EBE-8584-11D4-005004526AB4}
334 CLSID clsTestControl
;
335 hr
= CLSIDFromProgID( L
"AxTestComponents.Basic", &clsTestControl
);
337 IDispatch
* pDisp
= NULL
;
338 hr
= CoCreateInstance( clsTestControl
, NULL
, CLSCTX_ALL
, __uuidof(IDispatch
), (void**)&pDisp
);
340 if( SUCCEEDED( hr
) && val
)
344 OLECHAR
* name
=L
"prpString";
345 if( SUCCEEDED(hr
= pDisp
->GetIDsOfNames( IID_NULL
, &name
, 1, LOCALE_USER_DEFAULT
, &id
)))
347 COleVariant
vaParam1(_T("this is property prpString of AxTestComponents.Basic"));
348 DISPID dispidPut
= DISPID_PROPERTYPUT
;
351 params
.cNamedArgs
= 1;
352 params
.rgdispidNamedArgs
= &dispidPut
;
353 params
.rgvarg
= &vaParam1
;
355 hr
= pDisp
->Invoke( id
, IID_NULL
, LOCALE_USER_DEFAULT
, DISPATCH_PROPERTYPUT
, ¶ms
, &var
,0,0);
364 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */