00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef __CCPDFEXCELADDINOBJ_H_
00028 #define __CCPDFEXCELADDINOBJ_H_
00029
00030 #include "resource.h"
00031
00032 #import "DESIGNER\MSADDNDR.TLB" raw_interfaces_only, raw_native_types, no_namespace, named_guids
00033
00034 #import "EXCEL9.olb" rename("DialogBox","MyDialogBox"),rename("RGB","MyRGB"),named_guids, rename_namespace("MSExcel")
00035 using namespace MSExcel;
00036
00037 #include "CCTChar.h"
00038
00040
00044 class ATL_NO_VTABLE CCCPDFExcelAddinObj :
00045 public CComObjectRootEx<CComSingleThreadModel>,
00046 public ISupportErrorInfo,
00047 #ifdef CC_PDF_CONVERTER
00048 public CComCoClass<CCCPDFExcelAddinObj, &CLSID_CCPDFExcelAddinObj>,
00049 public IDispatchImpl<ICCPDFExcelAddinObj, &IID_ICCPDFExcelAddinObj, &LIBID_CCPDFEXCELADDINLib>,
00050 #elif EXCEL_TO_PDF
00051 public CComCoClass<CCCPDFExcelAddinObj, &CLSID_XL2PDFExcelAddinObj>,
00052 public IDispatchImpl<IXL2PDFExcelAddinObj, &IID_IXL2PDFExcelAddinObj, &LIBID_XL2PDFEXCELADDINLib>,
00053 #else
00054 #error "Please define one of the printer types"
00055 #endif
00056 public IDispatchImpl<_IDTExtensibility2, &IID__IDTExtensibility2, &LIBID_AddInDesignerObjects>,
00057 public IDispEventSimpleImpl<1, CCCPDFExcelAddinObj, &__uuidof(MSExcel::AppEvents)>,
00058 public IDispEventSimpleImpl<2, CCCPDFExcelAddinObj, &__uuidof(Office2000::_CommandBarButtonEvents)>
00059 {
00060 public:
00064 CCCPDFExcelAddinObj() : m_hDialog(NULL)
00065 {
00066 }
00067
00068 DECLARE_REGISTRY_RESOURCEID(IDR_CCPDFEXCELADDINOBJ)
00069
00070 DECLARE_PROTECT_FINAL_CONSTRUCT()
00071
00072 BEGIN_COM_MAP(CCCPDFExcelAddinObj)
00073 #ifdef CC_PDF_CONVERTER
00074 COM_INTERFACE_ENTRY(ICCPDFExcelAddinObj)
00075 COM_INTERFACE_ENTRY2(IDispatch, ICCPDFExcelAddinObj)
00076 #elif EXCEL_TO_PDF
00077 COM_INTERFACE_ENTRY(IXL2PDFExcelAddinObj)
00078 COM_INTERFACE_ENTRY2(IDispatch, IXL2PDFExcelAddinObj)
00079 #else
00080 #error "Please define one of the printer types"
00081 #endif
00082 COM_INTERFACE_ENTRY(ISupportErrorInfo)
00083 COM_INTERFACE_ENTRY(_IDTExtensibility2)
00084 END_COM_MAP()
00085
00086 BEGIN_SINK_MAP(CCCPDFExcelAddinObj)
00087 SINK_ENTRY_INFO(1, __uuidof(MSExcel::AppEvents), 0x620, OnWorkbookActivate, &DocumentOpenInfo)
00088 SINK_ENTRY_INFO(1, __uuidof(MSExcel::AppEvents), 0x622, OnWorkbookBeforeClose, &DocumentBeforeCloseInfo)
00089 SINK_ENTRY_INFO(1, __uuidof(MSExcel::AppEvents), 0x61d, OnNewWorkbook, &DocumentNew)
00090 SINK_ENTRY_INFO(2, __uuidof(Office2000::_CommandBarButtonEvents), 0x01, OnButtonClick, &OnClickButtonInfo)
00091 END_SINK_MAP()
00092
00093
00094
00096 STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
00097
00098
00099 public:
00100
00102 STDMETHOD(OnConnection)(IDispatch * Application, ext_ConnectMode ConnectMode, IDispatch * AddInInst, SAFEARRAY * * custom);
00104 STDMETHOD(OnDisconnection)(ext_DisconnectMode RemoveMode, SAFEARRAY * * custom);
00109 STDMETHOD(OnAddInsUpdate)(SAFEARRAY * * custom)
00110 {
00111 return E_NOTIMPL;
00112 }
00117 STDMETHOD(OnStartupComplete)(SAFEARRAY * * custom)
00118 {
00119 return E_NOTIMPL;
00120 }
00125 STDMETHOD(OnBeginShutdown)(SAFEARRAY * * custom)
00126 {
00127 return E_NOTIMPL;
00128 }
00129
00130
00132 void __stdcall OnNewWorkbook(IDispatch * workbook);
00134 void __stdcall OnWorkbookActivate(IDispatch * workbook);
00136 void __stdcall OnWorkbookBeforeClose(IDispatch * workbook, VARIANT_BOOL * CancelDefault);
00138 void __stdcall OnButtonClick(IDispatch * button, VARIANT_BOOL * CancelDefault);
00139
00140 protected:
00142 CComPtr<Office2000::_CommandBarButton> m_buttonToolbar;
00144 CComPtr<Office2000::_CommandBarButton> m_buttonMenu;
00146 CComPtr<MSExcel::_Application> m_spApp;
00148 HWND m_hDialog;
00149
00151 bool EnableButtons(bool bEnable);
00153 void DoPrint(HANDLE hPrinter, const std::tstring& sPrinter);
00155 void SetPrinterAndBreaks(const std::tstring& sPrinter);
00157 bool CalculatePrintData(const struct PrintPageData& pageHorz, const PrintPageData& pageVert, struct PrintCalcData& dataHorz, PrintCalcData& dataVert, class CCPrintData& data, HANDLE hPrinter, const std::tstring& sPrinter, CComPtr<MSExcel::PageSetup>& page, CComQIPtr<MSExcel::_Worksheet>& worksheet);
00161 void CleanupDialog() {if (m_hDialog != NULL) DestroyWindow(m_hDialog); m_hDialog = NULL;};
00165 void EnsureDialogVisible() {if (m_hDialog == NULL) return; ::BringWindowToTop(m_hDialog); UpdateWindow(m_hDialog);};
00166
00168 static _ATL_FUNC_INFO OnClickButtonInfo;
00170 static _ATL_FUNC_INFO DocumentOpenInfo;
00172 static _ATL_FUNC_INFO DocumentNew;
00174 static _ATL_FUNC_INFO DocumentBeforeCloseInfo;
00175 };
00176
00177 #endif //__CCPDFEXCELADDINOBJ_H_