Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / extensions / test / ole / MfcControl / MfcControlCtl.cpp
blobe64ed65705c9d1df0b1df39e6751dcd8183e76e8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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.
21 #include "stdafx.h"
22 #include "MfcControl.h"
23 #include "MfcControlCtl.h"
24 #include "MfcControlPpg.h"
27 #ifdef _DEBUG
28 #define new DEBUG_NEW
29 #undef THIS_FILE
30 static char THIS_FILE[] = __FILE__;
31 #endif
34 IMPLEMENT_DYNCREATE(CMfcControlCtrl, COleControl)
38 // Message map
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 !
44 //}}AFX_MSG_MAP
45 ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
46 END_MESSAGE_MAP()
50 // Dispatch map
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)
68 //}}AFX_DISPATCH_MAP
69 END_DISPATCH_MAP()
73 // Event map
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 !
79 //}}AFX_EVENT_MAP
80 END_EVENT_MAP()
84 // Property pages
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)
106 // Interface IDs
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 |
120 OLEMISC_INSIDEOUT |
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.
139 if (bRegister)
140 return AfxOleRegisterControlClass(
141 AfxGetInstanceHandle(),
142 m_clsid,
143 m_lpszProgID,
144 IDS_MFCCONTROL,
145 IDB_MFCCONTROL,
146 afxRegApartmentThreading,
147 _dwMfcControlOleMisc,
148 _tlid,
149 _wVerMajor,
150 _wVerMinor);
151 else
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)
218 char buf[256];
219 sprintf( buf, "inByte: value= %d", val);
220 ::MessageBoxA( NULL, buf, "MFCCONTROL.MfcControl", MB_OK);
221 return val+1;
224 long CMfcControlCtrl::inLong(long val)
226 char buf[256];
227 sprintf( buf, "inLong: value= %d", val);
228 ::MessageBoxA( NULL, buf, "MFCCONTROL.MfcControl", MB_OK);
229 return val+1;
232 BSTR CMfcControlCtrl::inString(BSTR* val)
234 CString strResult;
235 strResult= *val;
236 char buf[256];
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)
245 char buf[256];
246 sprintf( buf, "inFloat: value= %f", val);
247 ::MessageBoxA( NULL, buf, "MFCCONTROL.MfcControl", MB_OK);
248 return val+1;
251 double CMfcControlCtrl::inDouble(double val)
253 char buf[256];
254 sprintf( buf, "inDouble: value= %g", val);
255 ::MessageBoxA( NULL, buf, "MFCCONTROL.MfcControl", MB_OK);
256 return val+1;
259 VARIANT CMfcControlCtrl::inVariant(const VARIANT& val)
261 VARIANT vaResult;
262 VariantInit(&vaResult);
263 VariantCopyInd( &vaResult, const_cast<VARIANT*>(&val));
264 if( vaResult.vt == VT_BSTR)
266 char buf[256];
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)
276 char buf[256];
277 _bstr_t bstr;
278 HRESULT hr= S_OK;
279 COleVariant var;
280 DISPID id;
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, &params, &var,0,0);
289 if( var.vt== VT_BSTR)
290 bstr= var.bstrVal;
291 sprintf( buf, "inObject: value= %S", (wchar_t*)bstr);
292 ::MessageBoxA( NULL, buf, "MFCCONTROL.MfcControl", MB_OK);
294 return NULL;
298 void CMfcControlCtrl::outShort(short* val)
300 *val= 123;
303 void CMfcControlCtrl::outLong(long* val)
305 *val= 1234;
308 void CMfcControlCtrl::outString(BSTR* val)
310 *val= SysAllocString(L"A string from CMfcControlCtrl::outString ");
313 void CMfcControlCtrl::outFloat(float* val)
315 *val= 3.14f;
318 void CMfcControlCtrl::outDouble(double* val)
320 *val= 3.145;
323 void CMfcControlCtrl::outVariant(VARIANT* val)
325 VariantInit( val);
326 val->vt= VT_BSTR;
327 val->bstrVal= SysAllocString( L"a string in a VARIANT");
330 void CMfcControlCtrl::outObject(LPDISPATCH* val)
332 //{BFE10EBE-8584-11D4-005004526AB4}
333 HRESULT hr= S_OK;
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)
342 COleVariant var;
343 DISPID id;
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;
349 DISPPARAMS params;
350 params.cArgs= 1;
351 params.cNamedArgs= 1;
352 params.rgdispidNamedArgs= &dispidPut;
353 params.rgvarg= &vaParam1;
355 hr= pDisp->Invoke( id, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUT, &params, &var,0,0);
356 *val= pDisp;
362 // VT_I1
364 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */