00001
00002
00003
00004
00005
00006
00008
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00044
00045
00046 #include "stdafx.h"
00047
00048 #include "MgaUtil.h"
00049 #include "ComponentConfig.h"
00050
00051 #include "GMECOM.h"
00052
00053 #include "ComponentDll.h"
00054 #include "ComponentObj.h"
00055
00056 #define _OLESTR(x) OLESTR(x)
00057 extern const char* g_COCLASS_PROGIDA = COCLASS_PROGID;
00058 extern const wchar_t* g_COCLASS_PROGIDW = _OLESTR(COCLASS_PROGID);
00059 extern const char* g_COMPONENT_NAMEA = COMPONENT_NAME;
00060 extern const wchar_t* g_COMPONENT_NAMEW = _OLESTR(COMPONENT_NAME);
00061 #ifdef UNICODE
00062 extern const TCHAR* g_COMPONENT_NAME = g_COMPONENT_NAMEW;
00063 #else
00064 extern const TCHAR* g_COMPONENT_NAME = g_COMPONENT_NAMEA;
00065 #endif
00066 #ifdef REGISTER_SYSTEMWIDE
00067 extern const bool g_REGISTER_SYSTEMWIDE = true;
00068 #else
00069 extern const bool g_REGISTER_SYSTEMWIDE = false;
00070 #endif
00071 #ifdef GME_ADDON
00072 extern const bool g_GME_ADDON = true;
00073 #else
00074 extern const bool g_GME_ADDON = false;
00075 #endif
00076 #ifdef TEST_META_CONFORMANCE_INSIDE_BON
00077 extern const bool g_TEST_META_CONFORMANCE_INSIDE_BON = true;
00078 #else
00079 extern const bool g_TEST_META_CONFORMANCE_INSIDE_BON = false;
00080 #endif
00081
00082 #include "Core_i.c"
00083 #include "Mga_i.c"
00084 #include "ComponentLib_i.c"
00085
00086 #ifdef BUILDER_OBJECT_NETWORK
00087 #include "Mga.h"
00088 #include <BONComponent.h>
00089 #include "Builder.h"
00090 #endif
00091
00092 #include "ComHelp.h"
00093
00094 #include "ComponentLib.h"
00095
00096 #include "Console.h"
00097
00098
00099 #include "Gme.h"
00100
00101
00102
00103 #ifdef _DEBUG
00104 #define new DEBUG_NEW
00105 #undef THIS_FILE
00106 static char THIS_FILE[] = __FILE__;
00107 #endif // _DEBUG
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 #define WCHAR_L() L
00120 #define WCHAR(PAR) WCHAR_L()PAR
00121
00122 #ifdef PARADIGM_INDEPENDENT
00123 #define EXCETYPE (componenttype_enum)(CETYPE|COMPONENTTYPE_PARADIGM_INDEPENDENT)
00124 #undef PARADIGMS
00125 #define PARADIGMS "*"
00126 #else // PARADIGM_INDEPENDENT
00127 #define EXCETYPE CETYPE
00128 #endif // PARADIGM_INDEPENDENT
00129
00130
00131 #ifdef GME_ADDON
00132 #define CETYPE COMPONENTTYPE_ADDON
00133 #else
00134 #ifdef GME_INTERPRETER
00135 #define CETYPE COMPONENTTYPE_INTERPRETER
00136 #else
00137 #error No GME Componenttype (one of GME_ADDON or GME_INTERPRETER) is defined
00138 #endif
00139 #endif
00140 #ifdef GME_ADDON
00141
00142
00143
00144 IMPLEMENT_DYNCREATE(CEventSink, CCmdTarget)
00145
00146 CEventSink::CEventSink()
00147 {
00148 EnableAutomation();
00149
00150
00151
00152
00153 AfxOleLockApp();
00154 }
00155
00156 CEventSink::~CEventSink()
00157 {
00158
00159
00160
00161 AfxOleUnlockApp();
00162 }
00163
00164 BEGIN_MESSAGE_MAP(CEventSink, CCmdTarget)
00165
00166
00167
00168 END_MESSAGE_MAP()
00169
00170 BEGIN_DISPATCH_MAP(CEventSink, CCmdTarget)
00171
00172
00173
00174 END_DISPATCH_MAP()
00175
00176 BEGIN_INTERFACE_MAP(CEventSink, CCmdTarget)
00177 INTERFACE_PART(CEventSink, IID_IMgaEventSink, Component)
00178 END_INTERFACE_MAP()
00179
00180 void CEventSink::OnFinalRelease()
00181 {
00182
00183
00184
00185
00186
00187 CCmdTarget::OnFinalRelease();
00188 }
00189
00190 #define COMCLASS CEventSink::XComponent
00191 #define COMPROLOGUE METHOD_PROLOGUE(CEventSink,Component)
00192
00193 STDMETHODIMP COMCLASS::GlobalEvent(globalevent_enum event) {
00194 COMPROLOGUE;
00195 #ifdef BUILDER_OBJECT_NETWORK_V2
00196 try {
00197 pThis->comp->bon2Comp.globalEventPerformed( event );
00198 }
00199 catch ( Util::Exception& ex ) {
00200 pThis->comp->HandleError( &ex );
00201 }
00202 catch ( ... ) {
00203 AfxMessageBox( _T("Unhandled and unknown exception was thrown in BON2Component GlobalEvent!") );
00204 }
00205 return S_OK;
00206 #else
00207 return pThis->comp->rawcomp.GlobalEvent(event);
00208 #endif // BUILDER_OBJECT_NETWORK_V2
00209 }
00210
00211 STDMETHODIMP COMCLASS::ObjectEvent(IMgaObject * obj, unsigned long eventmask, VARIANT v) {
00212 COMPROLOGUE;
00213 #ifdef BUILDER_OBJECT_NETWORK_V2
00214 try {
00215 BON::Object object = BON::Object::attach( obj );
00216 for ( MON::ObjectEventType eEvent = MON::OET_ObjectCreated ; eEvent != MON::OET_All ; eEvent++ ) {
00217 if ( eventmask & eEvent ) {
00218 BON::Event event( eEvent, object );
00219 object->eventPerformedI( event );
00220 if ( eEvent & ADDON_EVENTMASK ) {
00221 object->getProject()->performEvent( event );
00222 object->performEvent( event );
00223 }
00224 }
00225 }
00226 pThis->comp->bon2Comp.objectEventPerformed( object, eventmask, v );
00227 }
00228 catch ( Util::Exception& ex ) {
00229 pThis->comp->HandleError( &ex );
00230 }
00231 catch ( ... ) {
00232 AfxMessageBox( _T("Unhandled and unknown exception was thrown in BON2Component ObjectEvent!") );
00233 }
00234 return S_OK;
00235 #else
00236 return pThis->comp->rawcomp.ObjectEvent(obj, eventmask, v);
00237 #endif // BUILDER_OBJECT_NETWORK_V2
00238 }
00239
00240 STDMETHODIMP_(ULONG) COMCLASS::AddRef()
00241 {
00242 COMPROLOGUE;
00243 return pThis->ExternalAddRef();
00244 }
00245
00246 STDMETHODIMP_(ULONG) COMCLASS::Release()
00247 {
00248 COMPROLOGUE;
00249 return pThis->ExternalRelease();
00250 }
00251
00252 STDMETHODIMP COMCLASS::QueryInterface(REFIID riid, void** ppv)
00253 {
00254 COMPROLOGUE;
00255 return pThis->ExternalQueryInterface(&riid, ppv);
00256 }
00257
00258 #undef COMCLASS
00259 #undef COMPROLOGUE
00260
00261 #endif // GME_ADDON
00262
00263
00264
00266
00267
00268 IMPLEMENT_DYNCREATE(CComponentObj, CCmdTarget)
00269
00270 CComponentObj::CComponentObj()
00271 {
00272 EnableAutomation();
00273
00274
00275
00276
00277 AfxOleLockApp();
00278
00279 registeractiveobjectret = 0;
00280 interactive = true;
00281 #ifdef RAWCOMPONENT_H
00282 rawcomp.interactive = interactive;
00283 #endif // RAWCOMPONENT_H
00284 #ifdef BUILDER_OBJECT_NETWORK_V2
00285 bon2Comp.m_bIsInteractive = interactive;
00286 #endif // BUILDER_OBJECT_NETWORK_V2
00287 }
00288
00289 void CComponentObj::RegisterActiveObject()
00290 {
00291 ASSERT( registeractiveobjectret == 0 );
00292
00293 COMVERIFY( ::RegisterActiveObject(GetInterface(), CLSID_MgaComponent,
00294 ACTIVEOBJECT_STRONG, ®isteractiveobjectret) );
00295
00296 ASSERT( registeractiveobjectret );
00297 }
00298
00299 CComponentObj::~CComponentObj()
00300 {
00301
00302
00303
00304 ASSERT( registeractiveobjectret == 0 );
00305 GMEConsole::Console::gmeoleapp.Release();
00306
00307 AfxOleUnlockApp();
00308 }
00309
00310 void CComponentObj::UnregisterActiveObject()
00311 {
00312 ASSERT( registeractiveobjectret );
00313 COMVERIFY( ::RevokeActiveObject(registeractiveobjectret, NULL) );
00314 registeractiveobjectret = 0;
00315 }
00316
00317 void CComponentObj::OnFinalRelease()
00318 {
00319
00320
00321
00322
00323
00324 CCmdTarget::OnFinalRelease();
00325 }
00326
00327
00328 BEGIN_MESSAGE_MAP(CComponentObj, CCmdTarget)
00329
00330
00331
00332 END_MESSAGE_MAP()
00333
00334 BEGIN_DISPATCH_MAP(CComponentObj, CCmdTarget)
00335
00336
00337
00338 END_DISPATCH_MAP()
00339
00340
00341
00342
00343 BEGIN_INTERFACE_MAP(CComponentObj, CCmdTarget)
00344 #ifndef IMPLEMENT_OLD_INTERFACE_ONLY
00345 INTERFACE_PART(CComponentObj, IID_IMgaComponentEx, Component)
00346 #endif
00347 INTERFACE_PART(CComponentObj, IID_IMgaComponent, Component)
00348 INTERFACE_PART(CComponentObj, IID_IGMEVersionInfo, VersionInfo)
00349 END_INTERFACE_MAP()
00350
00351
00352
00353
00354 #ifndef GME_COMPONENT_COM_THREAD
00355 #define GME_COMPONENT_COM_THREAD afxRegApartmentThreading
00356 #endif
00357 IMPLEMENT_OLECREATE_FLAGS(CComponentObj, COCLASS_PROGID, GME_COMPONENT_COM_THREAD,
00358 COCLASS_UUID_EXPLODED1,
00359 COCLASS_UUID_EXPLODED2,
00360 COCLASS_UUID_EXPLODED3,
00361 COCLASS_UUID_EXPLODED4,
00362 COCLASS_UUID_EXPLODED5,
00363 COCLASS_UUID_EXPLODED6,
00364 COCLASS_UUID_EXPLODED7,
00365 COCLASS_UUID_EXPLODED8,
00366 COCLASS_UUID_EXPLODED9,
00367 COCLASS_UUID_EXPLODED10,
00368 COCLASS_UUID_EXPLODED11)
00369
00370
00371
00372
00373 #define COMCLASS CComponentObj::XComponent
00374 #define COMPROLOGUE METHOD_PROLOGUE(CComponentObj,Component)
00375
00376 STDMETHODIMP_(ULONG) COMCLASS::AddRef()
00377 {
00378 COMPROLOGUE;
00379 return pThis->ExternalAddRef();
00380 }
00381
00382 STDMETHODIMP_(ULONG) COMCLASS::Release()
00383 {
00384 COMPROLOGUE;
00385 return pThis->ExternalRelease();
00386 }
00387
00388 STDMETHODIMP COMCLASS::QueryInterface(REFIID riid, void** ppv)
00389 {
00390 COMPROLOGUE;
00391 return pThis->ExternalQueryInterface(&riid, ppv);
00392 }
00393
00394
00395 #if defined(BUILDER_OBJECT_NETWORK)
00396 STDMETHODIMP COMCLASS::Invoke(IMgaProject *gme, IMgaFCOs *psa, long param)
00397 {
00398 COMPROLOGUE;
00399 CPushRoutingFrame temp(NULL);
00400
00401 ASSERT( gme != NULL );
00402
00403 COMTRY {
00404 long prefs;
00405 COMTHROW(gme->get_Preferences(&prefs));
00406
00407 COMTHROW(gme->put_Preferences(prefs | MGAPREF_RELAXED_RDATTRTYPES | MGAPREF_RELAXED_WRATTRTYPES));
00408 CBuilder builder(gme);
00409
00410 CBuilderObjectList objects;
00411 if(psa) {
00412 MGACOLL_ITERATE(IMgaFCO, psa) {
00413 CBuilderObject* o = CBuilder::theInstance->FindObject(MGACOLL_ITER);
00414 ASSERT( o != NULL );
00415 objects.AddTail(o);
00416 } MGACOLL_ITERATE_END;
00417 }
00418
00419 #ifndef DEPRECATED_BON_INVOKE_IMPLEMENTED
00420 CComponent comp;
00421 CBuilderObject *focus;
00422 POSITION p = objects.GetHeadPosition();
00423 if(p) {
00424 focus = objects.GetAt(p);
00425 objects.RemoveAt(p);
00426 }
00427 comp.InvokeEx(builder, focus, objects, param);
00428 #else
00429 #ifdef BUILDER_OBJECT_NETWORK
00430 CComponent comp;
00431 comp.Invoke(builder, objects, param);
00432 #else
00433 CInterpreter intp;
00434 intp.Interpret(builder, objects, param);
00435 #endif
00436 #endif
00437
00438 COMTHROW(gme->put_Preferences(prefs));
00439 } COMCATCH(;)
00440 return S_OK;
00441 }
00442
00443
00444 STDMETHODIMP COMCLASS::InvokeEx( IMgaProject *project, IMgaFCO *currentobj, IMgaFCOs *selectedobjs, long param) {
00445 COMPROLOGUE;
00446 CPushRoutingFrame temp(NULL);
00447 COMTRY {
00448 #ifdef NEW_BON_INVOKE
00449 ASSERT( project != NULL );
00450
00451 long prefs;
00452 COMTHROW(project->get_Preferences(&prefs));
00453
00454 COMTHROW(project->put_Preferences(prefs | MGAPREF_RELAXED_RDATTRTYPES | MGAPREF_RELAXED_WRATTRTYPES));
00455
00456 CComPtr<IMgaTerritory> terr;
00457 COMTHROW(project->CreateTerritory(NULL, &terr));
00458 COMTHROW(project->BeginTransaction(terr));
00459 {
00460 try {
00461 CBuilder builder(project, &pThis->parmap);
00462 CBuilderObject *focus = NULL;
00463 if (currentobj) {
00464 CComPtr<IMgaFCO> currobj;
00465 COMCHECK2(terr, terr->OpenFCO(currentobj,&currobj));
00466 focus = CBuilder::theInstance->FindObject(currobj);
00467 ASSERT( focus != NULL );
00468 }
00469 CBuilderObjectList objects;
00470 if(selectedobjs) {
00471 CComPtr<IMgaFCOs> fcos;
00472 COMCHECK2(terr, terr->OpenFCOs(selectedobjs,&fcos));
00473 MGACOLL_ITERATE(IMgaFCO, fcos) {
00474 CBuilderObject* o = CBuilder::theInstance->FindObject(MGACOLL_ITER);
00475 ASSERT( o != NULL );
00476 objects.AddTail(o);
00477 } MGACOLL_ITERATE_END;
00478 }
00479
00480 #ifdef BON_CUSTOM_TRANSACTIONS
00481 COMCHECK2(project, project->CommitTransaction());
00482 #endif
00483
00484 CComponent comp;
00485 comp.InvokeEx(builder, focus, objects, param);
00486
00487 #ifndef BON_CUSTOM_TRANSACTIONS
00488 COMCHECK2(project, project->CommitTransaction());
00489 #endif
00490 } catch (Util::Exception e) {
00491 pThis->HandleError(&e);
00492 COMTHROW(project->AbortTransaction());
00493 COMTHROW(E_FAIL);
00494 } catch (HRESULT) {
00495 COMTHROW(project->AbortTransaction());
00496 throw;
00497 } catch(...) {
00498 AfxMessageBox(_T("Unhandled and unknown exception was thrown in BON2Component Invoke!"));
00499 COMTHROW(project->AbortTransaction());
00500 COMTHROW(E_FAIL);
00501 }
00502 }
00503 COMTHROW(project->put_Preferences(prefs));
00504 #else
00505 if(pThis->interactive) {
00506 AfxMessageBox(_T("This interpreter has been upgraded to the new component interface \n")
00507 _T("but the user-provided files (Component.cpp and Component.h) \n")
00508 _T("use the deprecated interface. You can proceed now, but you are adviced to\n")
00509 _T("#define NEW_BON_INVOKE in Component.h, and implement other\n")
00510 _T("modifications as described at the top of the ComponentObj.cpp file"));
00511 }
00512 CComPtr<IMgaTerritory> terr;
00513 COMTHROW(project->CreateTerritory(NULL, &terr));
00514 COMTHROW(project->BeginTransaction(terr));
00515 try {
00516 CComPtr<IMgaFCOs> objs;
00517 if(currentobj) {
00518 COMTHROW(currentobj->CreateCollection(&objs));
00519 }
00520 else objs = selectedobjs;
00521 long param = 0;
00522 COMTHROW(Invoke(project, objs, param));
00523 COMTHROW(project->CommitTransaction());
00524 }
00525 catch(...) {
00526 project->AbortTransaction();
00527 throw;
00528 }
00529 #endif
00530 } COMCATCH(;);
00531 }
00532
00533 STDMETHODIMP COMCLASS::ObjectsInvokeEx( IMgaProject *project, IMgaObject *currentobj, IMgaObjects *selectedobjs, long param) {
00534 COMPROLOGUE;
00535 CPushRoutingFrame temp(NULL);
00536 COMTRY {
00537 #ifdef NEW_BON_INVOKE
00538 ASSERT( project != NULL );
00539
00540 long prefs;
00541 COMTHROW(project->get_Preferences(&prefs));
00542
00543 COMTHROW(project->put_Preferences(prefs | MGAPREF_RELAXED_RDATTRTYPES | MGAPREF_RELAXED_WRATTRTYPES));
00544 CComPtr<IMgaTerritory> terr;
00545 COMTHROW(project->CreateTerritory(NULL, &terr));
00546 COMTHROW(project->BeginTransaction(terr));
00547 try {
00548 {
00549 CBuilder builder(project);
00550
00551 CComponent comp;
00552 const CBuilderFolderList *allfolders = builder.GetFolders();
00553 CBuilderObject *focus = NULL;
00554 CComPtr<IMgaObject> currobj;
00555 COMTHROW(terr->OpenObj(currentobj,&currobj));
00556 CComQIPtr<IMgaFCO> co = currobj;
00557 if (co) {
00558 focus = CBuilder::theInstance->FindObject(co);
00559 ASSERT( focus != NULL );
00560 }
00561 else if(currobj) {
00562 CComQIPtr<IMgaFolder> cf = currentobj;
00563 POSITION p = allfolders->GetHeadPosition();
00564 while(p) {
00565 CBuilderFolder *f = allfolders->GetNext(p);
00566 if(f->GetIFolder() == cf) {
00567 comp.focusfolder = f;
00568 break;
00569 }
00570 }
00571 ASSERT(comp.focusfolder != NULL);
00572 }
00573 CBuilderObjectList objects;
00574 if(selectedobjs) {
00575 MGACOLL_ITERATE(IMgaObject, selectedobjs) {
00576 CComPtr<IMgaObject> currobj;
00577 COMTHROW(terr->OpenObj(MGACOLL_ITER,&currobj));
00578 CComQIPtr<IMgaFCO> co = currobj;
00579 if (co) {
00580 CBuilderObject* o = CBuilder::theInstance->FindObject(co);
00581 ASSERT( o != NULL );
00582 objects.AddTail(o);
00583 }
00584 else if(currobj) {
00585 CComQIPtr<IMgaFolder> cf = currentobj;
00586 CBuilderFolder *sf = NULL;
00587 POSITION p = allfolders->GetHeadPosition();
00588 while(p) {
00589 CBuilderFolder *f = allfolders->GetNext(p);
00590 if(f->GetIFolder() == cf) {
00591 sf = f;
00592 break;
00593 }
00594 }
00595 ASSERT( sf != NULL );
00596 comp.selectedfolders.AddTail(sf);
00597 }
00598 } MGACOLL_ITERATE_END;
00599 }
00600
00601 comp.InvokeEx(builder, focus, objects, param);
00602 }
00603 COMTHROW(project->CommitTransaction());
00604 } catch(...) { project->AbortTransaction(); throw; }
00605 COMTHROW(project->put_Preferences(prefs));
00606 #else
00607 if(pThis->interactive) {
00608 AfxMessageBox(_T"This interpreter has been upgraded to the new component interface \n")
00609 _T("but the user-provided files (Component.cpp and Component.h) \n")
00610 _T("use the deprecated interface.\n")
00611 _T("#define NEW_BON_INVOKE in Component.h, and implement other\n")
00612 _T("modifications as described at the top of the ComComponent.cpp file"));
00613 }
00614 return E_MGA_NOT_IMPLEMENTED;
00615 #endif
00616 } COMCATCH(;);
00617 }
00618
00619
00620
00621
00622
00623 STDMETHODIMP COMCLASS::Initialize(struct IMgaProject *p) {
00624 COMTRY {
00625 GMEConsole::Console::SetupConsole(p);
00626 } COMCATCH(;);
00627 };
00628
00629 STDMETHODIMP COMCLASS::Enable(VARIANT_BOOL newVal) {
00630 return S_OK;
00631 };
00632 STDMETHODIMP COMCLASS::get_InteractiveMode(VARIANT_BOOL *enabled) {
00633 COMPROLOGUE;
00634 if(enabled) *enabled = pThis->interactive ? VARIANT_TRUE : VARIANT_FALSE;
00635 return S_OK;
00636 };
00637
00638 STDMETHODIMP COMCLASS::put_InteractiveMode(VARIANT_BOOL enabled) {
00639 COMPROLOGUE;
00640 pThis->interactive = (enabled == VARIANT_TRUE);
00641 return S_OK;
00642 };
00643
00644 STDMETHODIMP COMCLASS::get_ComponentParameter(BSTR name, VARIANT *pVal) {
00645 COMPROLOGUE;
00646 CComVariant vv;
00647 CString bb;
00648 if (pThis->parmap.Lookup(CString(name), bb)) {
00649 vv = CComBSTR(bb);
00650 vv.Detach(pVal);
00651 }
00652
00653 return S_OK;
00654 }
00655 STDMETHODIMP COMCLASS::put_ComponentParameter(BSTR name, VARIANT newVal) {
00656 COMPROLOGUE;
00657 CComVariant dest;
00658 HRESULT hr = ::VariantChangeType(&dest, &newVal, VARIANT_NOVALUEPROP, VT_BSTR);
00659 if (hr == S_OK) pThis->parmap.SetAt(CString(name), CString(dest.bstrVal));
00660 return hr;
00661 }
00662
00663
00664 #else // BUILDER_OBJECT_NETWORK
00665
00666 #ifdef BUILDER_OBJECT_NETWORK_V2
00667
00668
00669 STDMETHODIMP COMCLASS::Invoke( IMgaProject *gme, IMgaFCOs *psa, long param )
00670 {
00671 COMPROLOGUE;
00672 CPushRoutingFrame temp( NULL );
00673
00674 try {
00675 ASSERT( gme != NULL );
00676 BON::Project project = BON::Project::attach( gme );
00677
00678 std::set<BON::FCO> setFCOs;
00679 if ( psa ) {
00680 MGACOLL_ITERATE( IMgaFCO, psa ) {
00681 setFCOs.insert( BON::FCO::attach( MGACOLL_ITER ) );
00682 } MGACOLL_ITERATE_END;
00683 }
00684
00685 pThis->bon2Comp.invoke( project, setFCOs, param );
00686 }
00687 catch ( Util::Exception& ex ) {
00688 pThis->HandleError( &ex );
00689 }
00690 catch ( ... ) {
00691 AfxMessageBox( _T("Unhandled and unknown exception was thrown in BON2Component Invoke!") );
00692 }
00693
00694 return S_OK;
00695 }
00696
00697 STDMETHODIMP COMCLASS::InvokeEx( IMgaProject *gme, IMgaFCO *currentobj, IMgaFCOs *selectedobjs, long param)
00698 {
00699 COMPROLOGUE;
00700 CPushRoutingFrame temp( NULL );
00701
00702 COMTRY {
00703 ASSERT( gme != NULL );
00704
00705 long prefs;
00706 COMTHROW( gme->get_Preferences( &prefs ) );
00707 COMTHROW( gme->put_Preferences( prefs | MGAPREF_RELAXED_RDATTRTYPES | MGAPREF_RELAXED_WRATTRTYPES ) );
00708
00709 CComPtr<IMgaTerritory> spTerritory;
00710 COMTHROW( gme->CreateTerritory( NULL, &spTerritory ) );
00711 COMTHROW( gme->BeginTransaction( spTerritory ) );
00712
00713 try {
00714 BON::Project project = BON::Project::attach( gme );
00715 project->assignTerritory(spTerritory);
00716
00717 CComPtr<IMgaFCO> spFCO;
00718 if ( currentobj )
00719 COMTHROW( spTerritory->OpenFCO( currentobj, &spFCO ) );
00720 BON::FCO fco = BON::FCO::attach( spFCO );
00721
00722 std::set<BON::FCO> setFCOs;
00723 if ( selectedobjs ) {
00724 CComPtr<IMgaFCOs> spFCOs;
00725 COMTHROW( spTerritory->OpenFCOs( selectedobjs, &spFCOs ) );
00726 MGACOLL_ITERATE( IMgaFCO, spFCOs ) {
00727 setFCOs.insert( BON::FCO::attach( MGACOLL_ITER ) );
00728 } MGACOLL_ITERATE_END;
00729 }
00730
00731 #ifdef BON_CUSTOM_TRANSACTIONS
00732 COMTHROW( gme->CommitTransaction() );
00733 #endif
00734
00735 pThis->bon2Comp.invokeEx( project, fco, setFCOs, param );
00736
00737 #ifndef BON_CUSTOM_TRANSACTIONS
00738 COMTHROW( gme->CommitTransaction() );
00739 #endif
00740 }
00741 catch ( Util::Exception& ex ) {
00742 pThis->HandleError( &ex );
00743 #ifndef BON_CUSTOM_TRANSACTIONS
00744 COMTHROW( gme->AbortTransaction() );
00745 #endif
00746 }
00747 catch ( ... ) {
00748 AfxMessageBox( _T("Unhandled and unknown exception was thrown in BON2Component InvokeEx!") );
00749 #ifndef BON_CUSTOM_TRANSACTIONS
00750 COMTHROW( gme->AbortTransaction() );
00751 #endif
00752 }
00753 } COMCATCH(;)
00754 }
00755
00756 STDMETHODIMP COMCLASS::ObjectsInvokeEx( IMgaProject *gme, IMgaObject *currentobj, IMgaObjects *selectedobjs, long param)
00757 {
00758 COMPROLOGUE;
00759 CPushRoutingFrame temp( NULL );
00760
00761 ASSERT( gme != NULL );
00762
00763 COMTRY {
00764 long prefs;
00765 COMTHROW( gme->get_Preferences( &prefs ) );
00766 COMTHROW( gme->put_Preferences( prefs | MGAPREF_RELAXED_RDATTRTYPES | MGAPREF_RELAXED_WRATTRTYPES ) );
00767
00768 CComPtr<IMgaTerritory> spTerritory;
00769 COMTHROW( gme->CreateTerritory( NULL, &spTerritory ) );
00770 COMTHROW( gme->BeginTransaction( spTerritory ) );
00771
00772 BON::Project project = BON::Project::attach( gme );
00773 project->assignTerritory(spTerritory);
00774
00775 CComPtr<IMgaObject> spObject;
00776 if ( currentobj )
00777 COMTHROW( spTerritory->OpenObj( currentobj, &spObject ) );
00778 BON::Object object = BON::Object::attach( spObject );
00779
00780 std::set<BON::Object> setObjects;
00781 if ( selectedobjs ) {
00782 MGACOLL_ITERATE( IMgaObject, selectedobjs ) {
00783 CComPtr<IMgaObject> spObject;
00784 COMTHROW( spTerritory->OpenObj( MGACOLL_ITER, &spObject ) );
00785 setObjects.insert( BON::Object::attach( spObject ) );
00786 } MGACOLL_ITERATE_END;
00787 }
00788
00789 try {
00790 pThis->bon2Comp.objectInvokeEx( project, object, setObjects, param );
00791 COMTHROW( gme->CommitTransaction() );
00792 }
00793 catch ( Util::Exception& ex ) {
00794 pThis->HandleError( &ex );
00795 COMTHROW( gme->AbortTransaction() );
00796 }
00797 catch ( ... ) {
00798 AfxMessageBox( _T("Unhandled and unknown exception was thrown in BON2Component ObjectInvokeEx!") );
00799 COMTHROW( gme->AbortTransaction() );
00800 }
00801 } COMCATCH(;)
00802
00803 return S_OK;
00804 }
00805
00806 STDMETHODIMP COMCLASS::Initialize( struct IMgaProject *p )
00807 {
00808 COMTRY {
00809 COMPROLOGUE;
00810
00811 #ifdef GME_ADDON
00812 CEventSink *es = new CEventSink;
00813 pThis->e_sink = &es->m_xComponent;
00814 es->comp = pThis;
00815
00816 pThis->addon = NULL;
00817 COMTHROW( p->CreateAddOn( pThis->e_sink, &( pThis->addon ) ) );
00818 COMTHROW( pThis->addon->put_EventMask( ADDON_EVENTMASK ) );
00819 #endif
00820
00821 GMEConsole::Console::SetupConsole(p);
00822
00823 CComPtr<IMgaTerritory> spTerritory;
00824 COMTHROW( p->CreateTerritory( NULL, &spTerritory ) );
00825 COMTHROW( p->BeginTransaction( spTerritory ) );
00826
00827 BON::Project project = BON::Project::attach( p );
00828 pThis->bon2Comp.m_project = project;
00829 try {
00830 pThis->bon2Comp.initialize( project );
00831 }
00832 catch ( Util::Exception& ex ) {
00833 pThis->HandleError( &ex );
00834 }
00835 catch ( ... ) {
00836 AfxMessageBox( _T("Unhandled and unknown exception was thrown in BON2Component Initialization!") );
00837 }
00838
00839 COMTHROW( p->CommitTransaction() );
00840
00841 return S_OK;
00842 } COMCATCH(;);
00843 }
00844
00845 STDMETHODIMP COMCLASS::Enable( VARIANT_BOOL newVal )
00846 {
00847 return S_OK;
00848 }
00849
00850 STDMETHODIMP COMCLASS::get_InteractiveMode( VARIANT_BOOL *enabled )
00851 {
00852 COMPROLOGUE;
00853 if( enabled )
00854 *enabled = pThis->interactive ? VARIANT_TRUE : VARIANT_FALSE;
00855 return S_OK;
00856 }
00857
00858 STDMETHODIMP COMCLASS::put_InteractiveMode( VARIANT_BOOL enabled )
00859 {
00860 COMPROLOGUE;
00861 pThis->interactive = enabled == VARIANT_TRUE;
00862 pThis->bon2Comp.m_bIsInteractive = pThis->interactive;
00863 return S_OK;
00864 }
00865
00866 STDMETHODIMP COMCLASS::get_ComponentParameter( BSTR name, VARIANT *pVal )
00867 {
00868 COMPROLOGUE;
00869 std::string strValue = pThis->bon2Comp.getParameter( Util::Copy( CComBSTR( name ) ) );
00870 CComVariant vv = Util::Copy( strValue );
00871 vv.Detach( pVal );
00872 return S_OK;
00873 }
00874
00875 STDMETHODIMP COMCLASS::put_ComponentParameter( BSTR name, VARIANT newVal )
00876 {
00877 COMPROLOGUE;
00878 CComVariant dest;
00879 HRESULT hr = ::VariantChangeType( &dest, &newVal, VARIANT_NOVALUEPROP, VT_BSTR );
00880 if( hr == S_OK )
00881 pThis->bon2Comp.setParameter( Util::Copy( CComBSTR( name ) ), Util::Copy( CComBSTR( dest.bstrVal ) ) );
00882 return hr;
00883 }
00884
00885 #else
00886
00887
00888
00889 #ifndef RAWCOMPONENT_H
00890 #error This part should be visible only in the RAW Component case
00891 #endif
00892
00893 STDMETHODIMP COMCLASS::Invoke(IMgaProject *gme, IMgaFCOs *psa, long param)
00894 {
00895 COMPROLOGUE;
00896 CPushRoutingFrame temp(NULL);
00897
00898 ASSERT( gme != NULL );
00899
00900
00901 return pThis->rawcomp.Invoke(gme, psa, param);
00902 }
00903
00904
00905 STDMETHODIMP COMCLASS::InvokeEx( IMgaProject *gme, IMgaFCO *currentobj, IMgaFCOs *selectedobjs, long param) {
00906 COMPROLOGUE;
00907 CPushRoutingFrame temp(NULL);
00908
00909 ASSERT( gme != NULL );
00910
00911
00912 return pThis->rawcomp.InvokeEx(gme, currentobj, selectedobjs, param);
00913 }
00914
00915 STDMETHODIMP COMCLASS::ObjectsInvokeEx( IMgaProject *gme, IMgaObject *currentobj, IMgaObjects *selectedobjs, long param) {
00916 COMPROLOGUE;
00917 CPushRoutingFrame temp(NULL);
00918
00919 ASSERT( gme != NULL );
00920
00921
00922 return pThis->rawcomp.ObjectsInvokeEx(gme, currentobj, selectedobjs, param);
00923 }
00924
00925
00926
00927 STDMETHODIMP COMCLASS::Initialize(struct IMgaProject *p) {
00928 COMTRY {
00929 COMPROLOGUE;
00930 #ifdef GME_ADDON
00931
00932 CEventSink *es = new CEventSink;
00933 pThis->e_sink = &es->m_xComponent;
00934 es->comp = pThis;
00935
00936 pThis->rawcomp.addon = NULL;
00937 COMTHROW(p->CreateAddOn(pThis->e_sink, &(pThis->rawcomp.addon)) );
00938 COMTHROW(pThis->rawcomp.addon->put_EventMask(ADDON_EVENTMASK));
00939
00940 #endif
00941
00942 GMEConsole::Console::SetupConsole(p);
00943 return pThis->rawcomp.Initialize(p);
00944 } COMCATCH(;);
00945 };
00946
00947 STDMETHODIMP COMCLASS::Enable(VARIANT_BOOL newVal) {
00948 return S_OK;
00949 };
00950 STDMETHODIMP COMCLASS::get_InteractiveMode(VARIANT_BOOL *enabled) {
00951 COMPROLOGUE;
00952 if(enabled) *enabled = pThis->interactive ? VARIANT_TRUE : VARIANT_FALSE;
00953 return S_OK;
00954 };
00955
00956 STDMETHODIMP COMCLASS::put_InteractiveMode(VARIANT_BOOL enabled) {
00957 COMPROLOGUE;
00958 pThis->interactive = (enabled == VARIANT_TRUE);
00959 #ifdef RAWCOMPONENT_H
00960 pThis->rawcomp.interactive = pThis->interactive;
00961 #endif
00962 return S_OK;
00963 };
00964
00965 STDMETHODIMP COMCLASS::get_ComponentParameter( BSTR name, VARIANT *pVal )
00966 {
00967 COMPROLOGUE;
00968 pThis->rawcomp.get_ComponentParameter(name, pVal);
00969 return S_OK;
00970 }
00971
00972 STDMETHODIMP COMCLASS::put_ComponentParameter( BSTR name, VARIANT newVal )
00973 {
00974 COMPROLOGUE;
00975 return pThis->rawcomp.put_ComponentParameter(name, newVal);
00976 return S_OK;
00977 }
00978
00979 #endif // BUILDER_OBJECT_NETWORK_V2
00980
00981 #endif // BUILDER_OBJECT_NETWORK
00982
00983 void CComponentObj::HandleError( Util::Exception* pEx )
00984 {
00985 std::string strOut = "Exception kind : " + pEx->getKind() + "\n";
00986 strOut += "Exception message : " + pEx->getErrorMessage();
00987 if ( pEx->getKind() == "MON::Exception" ) {
00988 char chBuffer[ 100 ];
00989 sprintf_s( chBuffer, "%x", ( (MON::Exception*) pEx)->getHResult() );
00990 strOut += "\nException hresult : " + std::string( chBuffer );
00991 }
00992 else if ( pEx->getKind() == "BON::Exception" ) {
00993 char chBuffer[ 100 ];
00994 sprintf_s( chBuffer, "%x", ( (BON::Exception*) pEx)->getHResult() );
00995 strOut += "\nException hresult : " + std::string( chBuffer );
00996 }
00997 AfxMessageBox( CString(strOut.c_str()) );
00998 }
00999
01000
01001 STDMETHODIMP COMCLASS::get_ComponentType( componenttype_enum *t)
01002 {
01003 COMPROLOGUE;
01004 *t = EXCETYPE;
01005 return S_OK;
01006 }
01007
01008 #undef COMCLASS
01009 #undef COMPROLOGUE
01010
01012
01013
01014 #define COMCLASS CComponentObj::XVersionInfo
01015 #define COMPROLOGUE METHOD_PROLOGUE(CComponentObj,VersionInfo)
01016
01017 STDMETHODIMP_(ULONG) COMCLASS::AddRef()
01018 {
01019 COMPROLOGUE;
01020 return pThis->ExternalAddRef();
01021 }
01022
01023 STDMETHODIMP_(ULONG) COMCLASS::Release()
01024 {
01025 COMPROLOGUE;
01026 return pThis->ExternalRelease();
01027 }
01028
01029 STDMETHODIMP COMCLASS::QueryInterface(REFIID riid, void** ppv)
01030 {
01031 COMPROLOGUE;
01032 return pThis->ExternalQueryInterface(&riid, ppv);
01033 }
01034
01035 STDMETHODIMP COMCLASS::get_version(enum GMEInterfaceVersion *pVal)
01036 {
01037 COMPROLOGUE;
01038
01039 if( pVal == NULL )
01040 return E_POINTER;
01041
01042 *pVal = GMEInterfaceVersion_Current;
01043 return S_OK;
01044 }
01045
01046 #undef COMCLASS
01047 #undef COMPROLOGUE
01048
01049
01050
01051 CComponentReg::CComponentReg()
01052 {
01053 CString pars = PARADIGMS;
01054 #ifndef PARADIGM_INDEPENDENT
01055 while( !pars.IsEmpty() )
01056 {
01057 CString trash = pars.SpanIncluding(_T(" ,;"));
01058 pars = pars.Mid(trash.GetLength());
01059 if( pars.IsEmpty() )
01060 break;
01061 CString par = pars.SpanExcluding(_T(" ,;"));
01062 pars = pars.Mid(par.GetLength());
01063 ASSERT(!par.IsEmpty());
01064 paradigms.AddTail(par);
01065 }
01066 #endif // PARADIGM_INDEPENDENT
01067 }
01068
01069
01070 #define COMRETURN(hr) { HRESULT res; if((res = (hr)) != S_OK) { ASSERT(false); return res; } }
01071
01072
01073 HRESULT CComponentReg::UnregisterParadigms(regaccessmode_enum loc) {
01074 CComPtr<IMgaRegistrar> registrar;
01075 COMRETURN(registrar.CoCreateInstance(OLESTR("Mga.MgaRegistrar")));
01076 COMRETURN(registrar->UnregisterComponent(CComBSTR(COCLASS_PROGID), loc));
01077 return S_OK;
01078 }
01079
01080 HRESULT CComponentReg::RegisterParadigms(regaccessmode_enum loc) {
01081 CComPtr<IMgaRegistrar> registrar;
01082 COMRETURN(registrar.CoCreateInstance(OLESTR("Mga.MgaRegistrar")));
01083 COMRETURN(registrar->RegisterComponent(CComBSTR(COCLASS_PROGID),EXCETYPE, CComBSTR(COMPONENT_NAME), loc));
01084 #ifdef BON_ICON_SUPPORT
01085 COMRETURN(registrar->put_ComponentExtraInfo(loc, CComBSTR(COCLASS_PROGID), CComBSTR("Icon"), CComBSTR(",IDI_COMPICON")));
01086 #endif
01087 COMRETURN(registrar->put_ComponentExtraInfo(loc, CComBSTR(COCLASS_PROGID), CComBSTR("Tooltip"), CComBSTR(TOOLTIP_TEXT)));
01088
01089 POSITION pos = paradigms.GetHeadPosition();
01090 while(pos)
01091 {
01092 CString paradigm = paradigms.GetNext(pos);
01093 COMRETURN(registrar->Associate(CComBSTR(COCLASS_PROGID), CComBSTR(paradigm), loc));
01094 }
01095 return S_OK;
01096 }