1
0

ClearFill.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #include <windows.h>
  2. #include <tchar.h>
  3. #import "VGCoreAuto.tlb" \
  4. rename("GetCommandLine", "VGGetCommandLine") \
  5. rename("CopyFile", "VGCore") \
  6. rename("FindWindow", "VGFindWindow")
  7. #ifdef _MANAGED
  8. #pragma managed(push, off)
  9. #endif
  10. BOOL APIENTRY DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved )
  11. {
  12. switch (fdwReason)
  13. {
  14. case DLL_PROCESS_ATTACH:
  15. case DLL_THREAD_ATTACH:
  16. case DLL_THREAD_DETACH:
  17. case DLL_PROCESS_DETACH:
  18. break;
  19. }
  20. return TRUE;
  21. }
  22. #ifdef _MANAGED
  23. #pragma managed(pop)
  24. #endif
  25. class CVGAppPlugin : public VGCore::IVGAppPlugin
  26. {
  27. private:
  28. VGCore::IVGApplication *m_pApp;
  29. ULONG m_ulRefCount;
  30. long m_lCookie;
  31. bool m_bEnabled;
  32. bool CheckSelection();
  33. void OnClearFill();
  34. public:
  35. CVGAppPlugin();
  36. // IUnknown
  37. public:
  38. STDMETHOD(QueryInterface)(REFIID riid, void **ppvObject);
  39. STDMETHOD_(ULONG, AddRef)(void) { return ++m_ulRefCount; }
  40. STDMETHOD_(ULONG, Release)(void)
  41. {
  42. ULONG ulCount = --m_ulRefCount;
  43. if(ulCount == 0)
  44. {
  45. delete this;
  46. }
  47. return ulCount;
  48. }
  49. // IDispatch
  50. public:
  51. STDMETHOD(GetTypeInfoCount)(UINT *pctinfo) { return E_NOTIMPL; }
  52. STDMETHOD(GetTypeInfo)(UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo) { return E_NOTIMPL; }
  53. STDMETHOD(GetIDsOfNames)(REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId) { return E_NOTIMPL; }
  54. STDMETHOD(Invoke)(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr);
  55. // IVGAppPlugin
  56. public:
  57. STDMETHOD(raw_OnLoad)(VGCore::IVGApplication *Application);
  58. STDMETHOD(raw_StartSession)();
  59. STDMETHOD(raw_StopSession)();
  60. STDMETHOD(raw_OnUnload)();
  61. };
  62. bool CVGAppPlugin::CheckSelection()
  63. {
  64. bool bRet = false;
  65. if(m_pApp->Documents->Count > 0)
  66. {
  67. bRet = (m_pApp->ActiveSelection->Shapes->Count > 0);
  68. }
  69. return bRet;
  70. }
  71. void CVGAppPlugin::OnClearFill()
  72. {
  73. if(CheckSelection())
  74. {
  75. m_pApp->ActiveSelection->Fill->ApplyNoFill();
  76. }
  77. }
  78. CVGAppPlugin::CVGAppPlugin() :
  79. m_pApp(NULL),
  80. m_lCookie(0),
  81. m_ulRefCount(1),
  82. m_bEnabled(false)
  83. {
  84. }
  85. STDMETHODIMP CVGAppPlugin::QueryInterface(REFIID riid, void **ppvObject)
  86. {
  87. HRESULT hr = S_OK;
  88. m_ulRefCount++;
  89. if(riid == IID_IUnknown)
  90. {
  91. *ppvObject = (IUnknown *)this;
  92. }
  93. else if(riid == IID_IDispatch)
  94. {
  95. *ppvObject = (IDispatch *)this;
  96. }
  97. else if(riid == __uuidof(VGCore::IVGAppPlugin))
  98. {
  99. *ppvObject = (VGCore::IVGAppPlugin *)this;
  100. }
  101. else
  102. {
  103. m_ulRefCount--;
  104. hr = E_NOINTERFACE;
  105. }
  106. return hr;
  107. }
  108. STDMETHODIMP CVGAppPlugin::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
  109. {
  110. switch(dispIdMember)
  111. {
  112. case 0x0011: //DISPID_APP_SELCHANGE
  113. m_bEnabled = CheckSelection();
  114. break;
  115. case 0x0014: // DISPID_APP_ONPLUGINCMD
  116. if(pDispParams != NULL && pDispParams->cArgs == 1)
  117. {
  118. _bstr_t strCmd(pDispParams->rgvarg[0].bstrVal);
  119. if(strCmd == _bstr_t("ClearFill"))
  120. {
  121. OnClearFill();
  122. }
  123. }
  124. break;
  125. case 0x0015: // DISPID_APP_ONPLUGINCMDSTATE
  126. if(pDispParams != NULL && pDispParams->cArgs == 3)
  127. {
  128. _bstr_t strCmd(pDispParams->rgvarg[2].bstrVal);
  129. if(strCmd == _bstr_t("ClearFill"))
  130. {
  131. *pDispParams->rgvarg[1].pboolVal = m_bEnabled ? VARIANT_TRUE : VARIANT_FALSE;
  132. }
  133. }
  134. break;
  135. }
  136. return S_OK;
  137. }
  138. STDMETHODIMP CVGAppPlugin::raw_OnLoad(VGCore::IVGApplication *Application)
  139. {
  140. m_pApp = Application;
  141. if(m_pApp)
  142. {
  143. m_pApp->AddRef();
  144. }
  145. return S_OK;
  146. }
  147. STDMETHODIMP CVGAppPlugin::raw_StartSession()
  148. {
  149. try
  150. {
  151. m_pApp->AddPluginCommand(_bstr_t("ClearFill"), _bstr_t("Clear Fill"), _bstr_t("Clears fill from selected objects"));
  152. // CorelDRAW X6 使用 VGCore::CommandBarControlPtr ctl
  153. // CorelDRAW 2020 SDK 使用 VGCore::ICUIControlPtr ctl
  154. // https://github.com/fersatgit/SmartDepart/issues/1 // 感谢 fersatgit 修复CorelDRAW 2020 使用错误
  155. VGCore::ICUIControlPtr ctl = m_pApp->CommandBars->Item[_bstr_t("Standard")]->Controls->AddCustomButton(VGCore::cdrCmdCategoryPlugins, _bstr_t("ClearFill"), 1, VARIANT_FALSE);
  156. // _bstr_t bstrPath(m_pApp->Path + _bstr_t("Plugins64\\ClearFill.bmp"));
  157. ctl->SetIcon2(_bstr_t("guid://d2fdc0d9-09f8-4948-944c-4297395c05b7"));
  158. m_lCookie = m_pApp->AdviseEvents(this);
  159. }
  160. catch(_com_error &e)
  161. {
  162. MessageBox(NULL, e.Description(), _T("Error"), MB_ICONSTOP);
  163. }
  164. return S_OK;
  165. }
  166. STDMETHODIMP CVGAppPlugin::raw_StopSession()
  167. {
  168. try
  169. {
  170. m_pApp->UnadviseEvents(m_lCookie);
  171. m_pApp->RemovePluginCommand(_bstr_t("ClearFill"));
  172. }
  173. catch(_com_error &e)
  174. {
  175. MessageBox(NULL, e.Description(), _T("Error"), MB_ICONSTOP);
  176. }
  177. return S_OK;
  178. }
  179. STDMETHODIMP CVGAppPlugin::raw_OnUnload()
  180. {
  181. if(m_pApp)
  182. {
  183. m_pApp->Release();
  184. m_pApp = NULL;
  185. }
  186. return S_OK;
  187. }
  188. extern "C" __declspec(dllexport) DWORD APIENTRY AttachPlugin(VGCore::IVGAppPlugin **ppIPlugin)
  189. {
  190. *ppIPlugin = new CVGAppPlugin;
  191. return 0x100;
  192. }