控件系统中的编辑事件管理器,只有一个唯一的全局对象,调用
class McEditor : public McRxEvent;
McEditor.h
例如:mxdrawx.ocx中使用的代码
class CMxDrawEditorReactor : public McEditorReactor { protected: CMxDrawEditorReactor(void); public: static void RemoveReactor(); static void RegistReactor(); virtual ~CMxDrawEditorReactor(void); virtual void gripEditEnded(McDbDatabase* dwg, McDbObjectId id,int iGridIndex); virtual void selectModified(McDbDatabase* dwg,const McDbObjectIdArray& aryId,const McDbObjectIdArray& aryModifyId,bool isAdd); private: static CMxDrawEditorReactor* s_pReactor; }; CMxDrawEditorReactor* CMxDrawEditorReactor::s_pReactor = NULL; CMxDrawEditorReactor::CMxDrawEditorReactor(void) { } CMxDrawEditorReactor::~CMxDrawEditorReactor(void) { } void CMxDrawEditorReactor::RemoveReactor() { if(s_pReactor == NULL) return; Mx::mcedEditor()->removeReactor(s_pReactor); delete s_pReactor; s_pReactor = NULL; } void CMxDrawEditorReactor::RegistReactor() { if(s_pReactor != NULL) return; s_pReactor = new CMxDrawEditorReactor; Mx::mcedEditor()->addReactor(s_pReactor); } void CMxDrawEditorReactor::gripEditEnded(McDbDatabase* dwg, McDbObjectId id,int iGridIndex) { MxDraw::MXDRAWOCXHANDLE hOcx = MxDraw::GetOcxHandleFormDatabase(dwg); if(hOcx == NULL) return; CMxDrawXCtrl* pOcxCrtl = CMxDrawXCtrl::Get_OcxHanleToCtrl(hOcx); if(pOcxCrtl == NULL || !::IsWindow(pOcxCrtl->GetSafeHwnd()) ) { MXASSERT(0); return; } long lId = (long)(id.asOldId()); MrxDbgRbList spParam = Mx::mcutBuildList(RTLONG,lId,RTLONG,iGridIndex,RTNONE); CMxDrawCustomEvent* pCustomEvent = pOcxCrtl->GetCustomEvent(); CString sResult; pCustomEvent->FireEvent(_T("ObjectGripEdit"),spParam.data(),sResult); } void CMxDrawEditorReactor::selectModified(McDbDatabase* dwg,const McDbObjectIdArray& aryId,const McDbObjectIdArray& aryModifyId,bool isAdd) { MxDraw::MXDRAWOCXHANDLE hOcx = MxDraw::GetOcxHandleFormDatabase(dwg); if(hOcx == NULL) return; CMxDrawXCtrl* pOcxCrtl = CMxDrawXCtrl::Get_OcxHanleToCtrl(hOcx); if(pOcxCrtl == NULL || !::IsWindow(pOcxCrtl->GetSafeHwnd()) ) { MXASSERT(0); return; } struct resbuf* pParam = NULL; struct resbuf* pPrv = NULL; for(int i = 0; i < aryId.length();i++) { long lId = (long)(aryId[i].asOldId()); struct resbuf* pNew = Mx::mcutNewRb(RTLONG); pNew->resval.rlong = lId; if(pPrv == NULL) { pParam = pNew; } else { pPrv->rbnext = pNew; } pPrv = pNew; } CMxDrawCustomEvent* pCustomEvent = pOcxCrtl->GetCustomEvent(); CString sResult; pCustomEvent->FireEvent(_T("SelectModified"),pParam,sResult); Mx::mcutRelRb(pParam); } // 在MxDraw::InitMxDraw()函数调用后面注册反应器 BOOL CMxDrawXApp::InitInstance() { BOOL bInit = COleControlModule::InitInstance(); if (bInit) { // TODO: 在此添加您自己的模块初始化代码。 // 初始绘图控件,不使用配制文件,使用默认值 MxDraw::InitMxDraw(false,_T(""), NULL,NULL,NULL,NULL); // CMxDrawEditorReactor::RegistReactor(); } return bInit; } // 在MxDraw::UnInitMxDraw()函数调用前面注销反应器 int CMxDrawXApp::ExitInstance() { CMxDrawEditorReactor::RemoveReactor(); // 释放绘图控件 MxDraw::UnInitMxDraw(); return COleControlModule::ExitInstance(); }