merged tag ooo/OOO330_m14
[LibreOffice.git] / extensions / test / ole / MfcControl / MfcControlCtl.cpp
blob52f6a0f4e8b52c8a760d7b43cb01aff4796701e4
1 // MfcControlCtl.cpp : Implementation of the CMfcControlCtrl ActiveX Control class.
3 #include "stdafx.h"
4 #include "MfcControl.h"
5 #include "MfcControlCtl.h"
6 #include "MfcControlPpg.h"
9 #ifdef _DEBUG
10 #define new DEBUG_NEW
11 #undef THIS_FILE
12 static char THIS_FILE[] = __FILE__;
13 #endif
16 IMPLEMENT_DYNCREATE(CMfcControlCtrl, COleControl)
19 /////////////////////////////////////////////////////////////////////////////
20 // Message map
22 BEGIN_MESSAGE_MAP(CMfcControlCtrl, COleControl)
23 //{{AFX_MSG_MAP(CMfcControlCtrl)
24 // NOTE - ClassWizard will add and remove message map entries
25 // DO NOT EDIT what you see in these blocks of generated code !
26 //}}AFX_MSG_MAP
27 ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
28 END_MESSAGE_MAP()
31 /////////////////////////////////////////////////////////////////////////////
32 // Dispatch map
34 BEGIN_DISPATCH_MAP(CMfcControlCtrl, COleControl)
35 //{{AFX_DISPATCH_MAP(CMfcControlCtrl)
36 DISP_FUNCTION(CMfcControlCtrl, "inShort", inShort, VT_I2, VTS_I2)
37 DISP_FUNCTION(CMfcControlCtrl, "inLong", inLong, VT_I4, VTS_I4)
38 DISP_FUNCTION(CMfcControlCtrl, "inString", inString, VT_BSTR, VTS_PBSTR)
39 DISP_FUNCTION(CMfcControlCtrl, "inFloat", inFloat, VT_R4, VTS_R4)
40 DISP_FUNCTION(CMfcControlCtrl, "inDouble", inDouble, VT_R8, VTS_R8)
41 DISP_FUNCTION(CMfcControlCtrl, "inVariant", inVariant, VT_VARIANT, VTS_VARIANT)
42 DISP_FUNCTION(CMfcControlCtrl, "inObject", inObject, VT_DISPATCH, VTS_DISPATCH)
43 DISP_FUNCTION(CMfcControlCtrl, "outShort", outShort, VT_EMPTY, VTS_PI2)
44 DISP_FUNCTION(CMfcControlCtrl, "outLong", outLong, VT_EMPTY, VTS_PI4)
45 DISP_FUNCTION(CMfcControlCtrl, "outString", outString, VT_EMPTY, VTS_PBSTR)
46 DISP_FUNCTION(CMfcControlCtrl, "outFloat", outFloat, VT_EMPTY, VTS_PR4)
47 DISP_FUNCTION(CMfcControlCtrl, "outDouble", outDouble, VT_EMPTY, VTS_PR8)
48 DISP_FUNCTION(CMfcControlCtrl, "outVariant", outVariant, VT_EMPTY, VTS_PVARIANT)
49 DISP_FUNCTION(CMfcControlCtrl, "outObject", outObject, VT_EMPTY, VTS_PDISPATCH)
50 //}}AFX_DISPATCH_MAP
51 END_DISPATCH_MAP()
54 /////////////////////////////////////////////////////////////////////////////
55 // Event map
57 BEGIN_EVENT_MAP(CMfcControlCtrl, COleControl)
58 //{{AFX_EVENT_MAP(CMfcControlCtrl)
59 // NOTE - ClassWizard will add and remove event map entries
60 // DO NOT EDIT what you see in these blocks of generated code !
61 //}}AFX_EVENT_MAP
62 END_EVENT_MAP()
65 /////////////////////////////////////////////////////////////////////////////
66 // Property pages
68 // TODO: Add more property pages as needed. Remember to increase the count!
69 BEGIN_PROPPAGEIDS(CMfcControlCtrl, 1)
70 PROPPAGEID(CMfcControlPropPage::guid)
71 END_PROPPAGEIDS(CMfcControlCtrl)
74 /////////////////////////////////////////////////////////////////////////////
75 // Initialize class factory and guid
77 IMPLEMENT_OLECREATE_EX(CMfcControlCtrl, "MFCCONTROL.MfcControlCtrl.1",
78 0xac221fb6, 0xa0d8, 0x11d4, 0x83, 0x3b, 0, 0x50, 0x4, 0x52, 0x6a, 0xb4)
81 /////////////////////////////////////////////////////////////////////////////
82 // Type library ID and version
84 IMPLEMENT_OLETYPELIB(CMfcControlCtrl, _tlid, _wVerMajor, _wVerMinor)
87 /////////////////////////////////////////////////////////////////////////////
88 // Interface IDs
90 const IID BASED_CODE IID_DMfcControl =
91 { 0xac221fb4, 0xa0d8, 0x11d4, { 0x83, 0x3b, 0, 0x50, 0x4, 0x52, 0x6a, 0xb4 } };
92 const IID BASED_CODE IID_DMfcControlEvents =
93 { 0xac221fb5, 0xa0d8, 0x11d4, { 0x83, 0x3b, 0, 0x50, 0x4, 0x52, 0x6a, 0xb4 } };
96 /////////////////////////////////////////////////////////////////////////////
97 // Control type information
99 static const DWORD BASED_CODE _dwMfcControlOleMisc =
100 OLEMISC_ACTIVATEWHENVISIBLE |
101 OLEMISC_SETCLIENTSITEFIRST |
102 OLEMISC_INSIDEOUT |
103 OLEMISC_CANTLINKINSIDE |
104 OLEMISC_RECOMPOSEONRESIZE;
106 IMPLEMENT_OLECTLTYPE(CMfcControlCtrl, IDS_MFCCONTROL, _dwMfcControlOleMisc)
109 /////////////////////////////////////////////////////////////////////////////
110 // CMfcControlCtrl::CMfcControlCtrlFactory::UpdateRegistry -
111 // Adds or removes system registry entries for CMfcControlCtrl
113 BOOL CMfcControlCtrl::CMfcControlCtrlFactory::UpdateRegistry(BOOL bRegister)
115 // TODO: Verify that your control follows apartment-model threading rules.
116 // Refer to MFC TechNote 64 for more information.
117 // If your control does not conform to the apartment-model rules, then
118 // you must modify the code below, changing the 6th parameter from
119 // afxRegApartmentThreading to 0.
121 if (bRegister)
122 return AfxOleRegisterControlClass(
123 AfxGetInstanceHandle(),
124 m_clsid,
125 m_lpszProgID,
126 IDS_MFCCONTROL,
127 IDB_MFCCONTROL,
128 afxRegApartmentThreading,
129 _dwMfcControlOleMisc,
130 _tlid,
131 _wVerMajor,
132 _wVerMinor);
133 else
134 return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
138 /////////////////////////////////////////////////////////////////////////////
139 // CMfcControlCtrl::CMfcControlCtrl - Constructor
141 CMfcControlCtrl::CMfcControlCtrl()
143 InitializeIIDs(&IID_DMfcControl, &IID_DMfcControlEvents);
145 // TODO: Initialize your control's instance data here.
149 /////////////////////////////////////////////////////////////////////////////
150 // CMfcControlCtrl::~CMfcControlCtrl - Destructor
152 CMfcControlCtrl::~CMfcControlCtrl()
154 // TODO: Cleanup your control's instance data here.
158 /////////////////////////////////////////////////////////////////////////////
159 // CMfcControlCtrl::OnDraw - Drawing function
161 void CMfcControlCtrl::OnDraw(
162 CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
164 // TODO: Replace the following code with your own drawing code.
165 pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
166 pdc->Ellipse(rcBounds);
170 /////////////////////////////////////////////////////////////////////////////
171 // CMfcControlCtrl::DoPropExchange - Persistence support
173 void CMfcControlCtrl::DoPropExchange(CPropExchange* pPX)
175 ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
176 COleControl::DoPropExchange(pPX);
178 // TODO: Call PX_ functions for each persistent custom property.
183 /////////////////////////////////////////////////////////////////////////////
184 // CMfcControlCtrl::OnResetState - Reset control to default state
186 void CMfcControlCtrl::OnResetState()
188 COleControl::OnResetState(); // Resets defaults found in DoPropExchange
190 // TODO: Reset any other control state here.
194 /////////////////////////////////////////////////////////////////////////////
195 // CMfcControlCtrl message handlers
198 short CMfcControlCtrl::inShort(short val)
200 char buf[256];
201 sprintf( buf, "inByte: value= %d", val);
202 ::MessageBoxA( NULL, buf, "MFCCONTROL.MfcControl", MB_OK);
203 return val+1;
206 long CMfcControlCtrl::inLong(long val)
208 char buf[256];
209 sprintf( buf, "inLong: value= %d", val);
210 ::MessageBoxA( NULL, buf, "MFCCONTROL.MfcControl", MB_OK);
211 return val+1;
214 BSTR CMfcControlCtrl::inString(BSTR* val)
216 CString strResult;
217 strResult= *val;
218 char buf[256];
219 sprintf( buf, "inString: value= %S", *val);
220 ::MessageBoxA( NULL, buf, "MFCCONTROL.MfcControl", MB_OK);
221 strResult += L" an appended string";
222 return strResult.AllocSysString();
225 float CMfcControlCtrl::inFloat(float val)
227 char buf[256];
228 sprintf( buf, "inFloat: value= %f", val);
229 ::MessageBoxA( NULL, buf, "MFCCONTROL.MfcControl", MB_OK);
230 return val+1;
233 double CMfcControlCtrl::inDouble(double val)
235 char buf[256];
236 sprintf( buf, "inDouble: value= %g", val);
237 ::MessageBoxA( NULL, buf, "MFCCONTROL.MfcControl", MB_OK);
238 return val+1;
241 VARIANT CMfcControlCtrl::inVariant(const VARIANT FAR& val)
243 VARIANT vaResult;
244 VariantInit(&vaResult);
245 VariantCopyInd( &vaResult, const_cast<VARIANT*>(&val));
246 if( vaResult.vt == VT_BSTR)
248 char buf[256];
249 sprintf( buf, "inVariant: value= %S", vaResult.bstrVal);
250 ::MessageBoxA( NULL, buf, "MFCCONTROL.MfcControl", MB_OK);
253 return _variant_t( L" a string from CMfcControlCtrl::inVariant");
256 LPDISPATCH CMfcControlCtrl::inObject(LPDISPATCH val)
258 char buf[256];
259 _bstr_t bstr;
260 HRESULT hr= S_OK;
261 COleVariant var;
262 DISPID id;
263 OLECHAR* name=L"prpString";
264 if( SUCCEEDED(hr= val->GetIDsOfNames( IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &id)))
266 DISPPARAMS params={0,0,0,0};
267 hr= val->Invoke( id, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET, &params, &var,0,0);
271 if( var.vt== VT_BSTR)
272 bstr= var.bstrVal;
273 sprintf( buf, "inObject: value= %S", (wchar_t*)bstr);
274 ::MessageBoxA( NULL, buf, "MFCCONTROL.MfcControl", MB_OK);
276 return NULL;
280 void CMfcControlCtrl::outShort(short* val)
282 *val= 123;
285 void CMfcControlCtrl::outLong(long* val)
287 *val= 1234;
290 void CMfcControlCtrl::outString(BSTR FAR* val)
292 *val= SysAllocString(L"A string from CMfcControlCtrl::outString ");
295 void CMfcControlCtrl::outFloat(float* val)
297 *val= 3.14f;
300 void CMfcControlCtrl::outDouble(double* val)
302 *val= 3.145;
305 void CMfcControlCtrl::outVariant(VARIANT FAR* val)
307 VariantInit( val);
308 val->vt= VT_BSTR;
309 val->bstrVal= SysAllocString( L"a string in a VARIANT");
312 void CMfcControlCtrl::outObject(LPDISPATCH FAR* val)
314 //{BFE10EBE-8584-11D4-005004526AB4}
315 HRESULT hr= S_OK;
316 CLSID clsTestControl;
317 hr= CLSIDFromProgID( L"AxTestComponents.Basic", &clsTestControl);
319 IDispatch* pDisp= NULL;
320 hr= CoCreateInstance( clsTestControl, NULL, CLSCTX_ALL, __uuidof(IDispatch), (void**)&pDisp);
322 if( SUCCEEDED( hr) && val)
324 COleVariant var;
325 DISPID id;
326 OLECHAR* name=L"prpString";
327 if( SUCCEEDED(hr= pDisp->GetIDsOfNames( IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &id)))
329 COleVariant vaParam1(_T("this is property prpString of AxTestComponents.Basic"));
330 DISPID dispidPut= DISPID_PROPERTYPUT;
331 DISPPARAMS params;
332 params.cArgs= 1;
333 params.cNamedArgs= 1;
334 params.rgdispidNamedArgs= &dispidPut;
335 params.rgvarg= &vaParam1;
337 hr= pDisp->Invoke( id, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUT, &params, &var,0,0);
338 *val= pDisp;
344 // VT_I1