00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "stdafx.h"
00028 #ifdef CC_PDF_CONVERTER
00029 #include "CCPDFExcelAddin.h"
00030 #elif EXCEL_TO_PDF
00031 #include "XL2PDFExcelAddin.h"
00032 #else
00033 #error "Please define one of the printer types"
00034 #endif
00035 #include "CCPDFExcelAddinObj.h"
00036
00037 #include "CCPrintData.h"
00038 #include "CCRegistry.h"
00039
00041
00042
00043 #ifdef CC_PDF_CONVERTER
00045 #define PRODUCT_NAME _T("CC PDF Converter")
00047 #define PRINTER_NAME _T("CC PDF Printer")
00049 #define REGISTRY_DATA_PATH _T("Software\\Cogniview\\CC PDF Converter\\Excel Addin")
00051 #define PRINTER_DRIVER_NAME _T("CC PDF Virtual Printer")
00053 #define BUTTON_TAG _T("CCPDF Save PDF")
00054 #elif EXCEL_TO_PDF
00056 #define PRODUCT_NAME _T("Excel to PDF")
00058 #define PRINTER_NAME _T("Excel to PDF Printer")
00060 #define REGISTRY_DATA_PATH _T("Software\\Cogniview\\Excel to PDF Converter\\Excel Addin")
00062 #define PRINTER_DRIVER_NAME _T("Excel to PDF Virtual Printer")
00064 #define BUTTON_TAG _T("XL2PDF Save PDF")
00065 #else
00066 #error "Please define one of the printer types"
00067 #endif
00068
00070 #define FIND_PRINTER_ERROR_MSG _T("Cannot access the ") PRINTER_NAME
00072 #define PRINTER_ERROR_TITLE PRODUCT_NAME
00074 #define ACCESS_PRINTER_ERROR_MSG _T("Error when accessing the ") PRINTER_NAME
00076 #define WORKING_PRINTER_ERROR_MSG _T("Error when working with the ") PRINTER_NAME
00077
00079 typedef IDispEventSimpleImpl< 2, CCCPDFExcelAddinObj, &__uuidof(Office2000::_CommandBarButtonEvents)> CommandButtonEvents;
00081 _ATL_FUNC_INFO CCCPDFExcelAddinObj::DocumentOpenInfo = {CC_STDCALL,VT_EMPTY, 1, {VT_DISPATCH|VT_BYREF}};
00083 _ATL_FUNC_INFO CCCPDFExcelAddinObj::DocumentNew = {CC_STDCALL,VT_EMPTY, 1, {VT_DISPATCH|VT_BYREF}};
00085 _ATL_FUNC_INFO CCCPDFExcelAddinObj::DocumentBeforeCloseInfo = {CC_STDCALL,VT_EMPTY, 2, {VT_DISPATCH|VT_BYREF, VT_BYREF|VT_BOOL}};
00087 _ATL_FUNC_INFO CCCPDFExcelAddinObj::OnClickButtonInfo ={CC_STDCALL,VT_EMPTY,2,{VT_DISPATCH,VT_BYREF | VT_BOOL}};
00088
00093 STDMETHODIMP CCCPDFExcelAddinObj::InterfaceSupportsErrorInfo(REFIID riid)
00094 {
00095
00096 static const IID* arr[] =
00097 {
00098 #ifdef CC_PDF_CONVERTER
00099 &IID_ICCPDFExcelAddinObj
00100 #elif EXCEL_TO_PDF
00101 &IID_IXL2PDFExcelAddinObj
00102 #else
00103 #error "Please define one of the printer types"
00104 #endif
00105 };
00106
00107
00108 for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
00109 {
00110 if (IsEqualGUID(*arr[i],riid))
00111
00112 return S_OK;
00113 }
00114
00115 return S_FALSE;
00116 }
00117
00125 STDMETHODIMP CCCPDFExcelAddinObj::OnConnection(IDispatch * Application, ext_ConnectMode ConnectMode, IDispatch * AddInInst, SAFEARRAY * * custom)
00126 {
00127 HRESULT hr;
00128
00129
00130 CComQIPtr<MSExcel::_Application> spApp(Application);
00131 ATLASSERT(spApp);
00132 m_spApp = spApp;
00133
00134
00135 CComPtr <_CommandBars> pCmdBars = m_spApp->GetCommandBars();
00136 CComPtr <CommandBar> pStandardBar = NULL;
00137 int nBefore;
00138
00139
00140 hr = pCmdBars->get_Item(_variant_t(_T("Standard")), &pStandardBar);
00141 if (!FAILED(hr) && (pStandardBar != NULL))
00142 {
00143
00144 CComPtr <CommandBarControls> pBarControls = pStandardBar->GetControls();
00145
00146 bool bFound = false;
00147
00148
00149 int nCount = pBarControls->GetCount();
00150 nBefore = nCount;
00151 for (int i=nCount; i>=1; i--)
00152 {
00153 CComPtr<CommandBarControl> pControl = pBarControls->GetItem(_variant_t((long)i));
00154
00155 CComQIPtr<Office2000::_CommandBarButton> pButton(pControl);
00156 if (pButton == NULL)
00157
00158 continue;
00159
00160
00161 _bstr_t tag = pButton->GetTag();
00162 if (pButton->GetId() == 3)
00163 {
00164
00165 nBefore = i + 1;
00166 }
00167
00168 if (_tcscmp(BUTTON_TAG, (LPCTSTR)tag) == 0)
00169 {
00170
00171 m_buttonToolbar = pButton;
00172 bFound = true;
00173 break;
00174 }
00175 }
00176
00177 if (!bFound)
00178 {
00179
00180 CComVariant vToolBarType(Office2000::msoControlButton);
00181 CComVariant vEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);
00182 CComVariant vBefore(nBefore);
00183
00184
00185 CComPtr<CommandBarControl> pControl = pBarControls->Add(vToolBarType, vEmpty, vEmpty, vBefore, vEmpty);
00186 ATLASSERT(pControl);
00187
00188
00189 CComQIPtr<_CommandBarButton> pButton(pControl);
00190 ATLASSERT(pButton);
00191
00192
00193 HBITMAP hBitmap = (HBITMAP)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDB_BUTTON), IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS);
00194 if (hBitmap != NULL)
00195 {
00196 ::OpenClipboard(NULL);
00197 ::EmptyClipboard();
00198 ::SetClipboardData(CF_BITMAP, (HANDLE)hBitmap);
00199 ::CloseClipboard();
00200 ::DeleteObject(hBitmap);
00201 pButton->PutStyle(Office2000::msoButtonIcon);
00202 hr = pButton->PasteFace();
00203 if (FAILED(hr))
00204 return hr;
00205 }
00206 else
00207 {
00208
00209 pButton->PutStyle(Office2000::msoButtonCaption);
00210 }
00211
00212
00213 pButton->PutCaption(_T("Save As PDF File..."));
00214 pButton->PutTooltipText(_T("Save the current sheet as a PDF file"));
00215 pButton->PutEnabled(VARIANT_TRUE);
00216 pButton->PutVisible(VARIANT_TRUE);
00217
00218
00219 pButton->PutTag(BUTTON_TAG);
00220
00221 m_buttonToolbar = pButton;
00222 }
00223
00224
00225 hr = CommandButtonEvents::DispEventAdvise((IDispatch*)m_buttonToolbar);
00226 if (FAILED(hr))
00227 return hr;
00228
00229
00230 m_buttonToolbar->PutEnabled(VARIANT_TRUE);
00231 }
00232
00233
00234 CComPtr <CommandBar> pMenuBar = NULL;
00235 hr = pCmdBars->get_Item(_variant_t(_T("Worksheet Menu Bar")), &pMenuBar);
00236 if (!FAILED(hr) && (pMenuBar != NULL))
00237 {
00238
00239 CComVariant vToolBarType(Office2000::msoControlButton);
00240 CComVariant vEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);
00241
00242 CComPtr <CommandBarControls> pBarControls = pMenuBar->GetControls();
00243 CComPtr<CommandBarControl> pControl = pBarControls->GetItem(_T("File"));
00244 if (pControl != NULL)
00245 {
00246 CComQIPtr<Office2000::CommandBarPopup> pPopup(pControl);
00247 if (pPopup != NULL)
00248 {
00249
00250 CComPtr <CommandBarControls> pMenuControls = pPopup->GetControls();
00251 long lBefore = 1;
00252 long i;
00253 for (i = 1; i <= pMenuControls->GetCount(); i++)
00254 {
00255
00256 CComPtr<CommandBarControl> pControl = pMenuControls->GetItem(i);
00257 CComQIPtr<Office2000::_CommandBarButton> pButton(pControl);
00258 if (pButton == NULL)
00259
00260 continue;
00261
00262 if (pButton->GetId() == 3823)
00263 {
00264
00265 lBefore = i;
00266 continue;
00267 }
00268
00269
00270 _bstr_t tag = pButton->GetTag();
00271 if (_tcscmp(BUTTON_TAG, (LPCTSTR)tag) == 0)
00272 {
00273
00274 m_buttonMenu = pButton;
00275 break;
00276 }
00277 }
00278
00279
00280 if (i > pMenuControls->GetCount())
00281 {
00282
00283 CComVariant vToolBarType(Office2000::msoControlButton);
00284 CComVariant vEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);
00285 CComVariant vBefore(lBefore + 1);
00286
00287
00288 CComPtr<CommandBarControl> pControl = pMenuControls->Add(vToolBarType, vEmpty, vEmpty, vBefore, vEmpty);
00289 ATLASSERT(pControl);
00290
00291
00292 CComQIPtr<_CommandBarButton> pButton(pControl);
00293 ATLASSERT(pButton);
00294
00295
00296 HBITMAP hBitmap = (HBITMAP)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDB_BUTTON), IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS);
00297 if (hBitmap != NULL)
00298 {
00299 ::OpenClipboard(NULL);
00300 ::EmptyClipboard();
00301 ::SetClipboardData(CF_BITMAP, (HANDLE)hBitmap);
00302 ::CloseClipboard();
00303 ::DeleteObject(hBitmap);
00304 pButton->PutStyle(Office2000::msoButtonIconAndCaption);
00305 hr = pButton->PasteFace();
00306 }
00307 else
00308
00309 pButton->PutStyle(Office2000::msoButtonCaption);
00310
00311
00312 pButton->PutCaption(_T("Save As PDF &File..."));
00313 pButton->PutTooltipText(_T("Save the current sheet as a PDF file"));
00314 pButton->PutEnabled(VARIANT_TRUE);
00315 pButton->PutVisible(VARIANT_TRUE);
00316
00317
00318 pButton->PutTag(BUTTON_TAG);
00319
00320 m_buttonMenu = pButton;
00321 }
00322 }
00323 }
00324
00325 m_buttonMenu->PutEnabled(VARIANT_TRUE);
00326 }
00327
00328
00329 hr = IDispEventSimpleImpl<1, CCCPDFExcelAddinObj, &__uuidof(MSExcel::AppEvents)>::DispEventAdvise(m_spApp);
00330 if (FAILED(hr))
00331 return hr;
00332
00333 return S_OK;
00334 }
00335
00341 STDMETHODIMP CCCPDFExcelAddinObj::OnDisconnection(ext_DisconnectMode RemoveMode, SAFEARRAY * * custom)
00342 {
00343
00344 HRESULT hr = CommandButtonEvents::DispEventUnadvise((IDispatch*)m_buttonToolbar);
00345 if (FAILED(hr))
00346 return hr;
00347
00348
00349 hr = IDispEventSimpleImpl<1, CCCPDFExcelAddinObj, &__uuidof(MSExcel::AppEvents)>::DispEventUnadvise(m_spApp);
00350 if (FAILED(hr))
00351 return hr;
00352
00353
00354 if (RemoveMode == ext_dm_UserClosed)
00355 {
00356
00357 m_buttonToolbar->Delete(VARIANT_FALSE);
00358 m_buttonMenu->Delete(VARIANT_FALSE);
00359 }
00360
00361 m_spApp = NULL;
00362 return hr;
00363 }
00364
00368 void __stdcall CCCPDFExcelAddinObj::OnWorkbookActivate(IDispatch * workbook)
00369 {
00370
00371 EnableButtons(true);
00372 }
00373
00377 void __stdcall CCCPDFExcelAddinObj::OnNewWorkbook(IDispatch * workbook)
00378 {
00379
00380 EnableButtons(true);
00381 }
00382
00387 void __stdcall CCCPDFExcelAddinObj::OnWorkbookBeforeClose(IDispatch * workbook, VARIANT_BOOL * CancelDefault)
00388 {
00389
00390 CComPtr <MSExcel::Workbooks> books = m_spApp->GetWorkbooks();
00391 long lCount = books->GetCount();
00392 EnableButtons(lCount > 1);
00393 }
00394
00398 void CCCPDFExcelAddinObj::SetPrinterAndBreaks(const std::tstring& sPrinter)
00399 {
00400
00401 m_spApp->PutActivePrinter(0, sPrinter.c_str());
00402
00403
00404 CComPtr <MSExcel::Window> window = m_spApp->GetActiveWindow();
00405 window->PutView(MSExcel::xlPageBreakPreview);
00406 window->PutView(MSExcel::xlNormalView);
00407 }
00408
00413 void __stdcall CCCPDFExcelAddinObj::OnButtonClick(IDispatch * button, VARIANT_BOOL * CancelDefault)
00414 {
00415
00416 std::tstring sPrinter, sPrinterName, sOldPrinter;
00417 DWORD dwSize, dwCount;
00418
00419 EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &dwSize, &dwCount);
00420 if (dwSize > 0)
00421 {
00422
00423 PRINTER_INFO_2* pInfo = (PRINTER_INFO_2*)new char[dwSize];
00424
00425 if (EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pInfo, dwSize, &dwSize, &dwCount) > 0)
00426 {
00427 DWORD i;
00428 for (i=0;i<dwCount;i++)
00429 {
00430
00431 if (_tcscmp(pInfo[i].pDriverName, PRINTER_DRIVER_NAME) == 0)
00432 break;
00433 }
00434 if (i < dwCount)
00435
00436 sPrinterName = pInfo[i].pPrinterName;
00437 }
00438 delete [] pInfo;
00439 }
00440
00441
00442 if (sPrinterName.empty())
00443 {
00444
00445 MessageBox(NULL, FIND_PRINTER_ERROR_MSG, PRINTER_ERROR_TITLE, MB_OK|MB_ICONERROR);
00446 return;
00447 }
00448
00449 bool bSuccess;
00450 std::tstring sPort = CCRegistry::GetString(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows NT\\CurrentVersion\\Devices"), sPrinterName.c_str(), &bSuccess);
00451 if (!bSuccess || sPort.empty())
00452 {
00453 MessageBox(NULL, FIND_PRINTER_ERROR_MSG, PRINTER_ERROR_TITLE, MB_OK|MB_ICONERROR);
00454 return;
00455 }
00456 std::tstring::size_type pos = sPort.find_first_of(',');
00457 if (pos == std::tstring::npos)
00458 {
00459 MessageBox(NULL, FIND_PRINTER_ERROR_MSG, PRINTER_ERROR_TITLE, MB_OK|MB_ICONERROR);
00460 return;
00461 }
00462 sPrinter = sPrinterName + _T(" on ") + sPort.substr(pos + 1);
00463
00464
00465 sOldPrinter = m_spApp->GetActivePrinter();
00466 if (sPrinter != sOldPrinter)
00467 SetPrinterAndBreaks(sPrinter);
00468
00469
00470 HANDLE hPrinter = NULL;
00471 PRINTER_DEFAULTS defs;
00472 defs.pDatatype = NULL;
00473 defs.pDevMode = NULL;
00474 defs.DesiredAccess = PRINTER_ACCESS_ADMINISTER;
00475 if (!OpenPrinter((LPTSTR)sPrinterName.c_str(), &hPrinter, &defs))
00476 {
00477
00478 MessageBox(NULL, FIND_PRINTER_ERROR_MSG, PRINTER_ERROR_TITLE, MB_OK|MB_ICONERROR);
00479 if (sPrinter != sOldPrinter)
00480 SetPrinterAndBreaks(sOldPrinter);
00481 return;
00482 }
00483
00484
00485 m_hDialog = NULL;
00486 try
00487 {
00488 DoPrint(hPrinter, sPrinter);
00489 }
00490 catch( _com_error e )
00491 {
00492
00493 CleanupDialog();
00494 MessageBox(NULL, e.ErrorMessage(), PRINTER_ERROR_TITLE, MB_OK|MB_ICONERROR);
00495 }
00496 catch(...)
00497 {
00498
00499 CleanupDialog();
00500 MessageBox(NULL, _T("Unspecified error"), PRINTER_ERROR_TITLE, MB_OK|MB_ICONERROR);
00501 }
00502
00503
00504 CCPrintData data;
00505 data.CleanSaved(hPrinter);
00506 ::ClosePrinter(hPrinter);
00507
00508
00509 if (sPrinter != sOldPrinter)
00510 SetPrinterAndBreaks(sOldPrinter);
00511 }
00512
00519 bool EnableButtons(CComPtr<CommandBarControls>& pControls, bool bEnable)
00520 {
00521
00522 for (long i=1;i<pControls->GetCount();i++)
00523 {
00524
00525 CComPtr<CommandBarControl> pControl = pControls->GetItem(i);
00526 switch (pControl->GetType())
00527 {
00528 case Office2000::msoControlButton:
00529 {
00530
00531 CComQIPtr<Office2000::_CommandBarButton> pButton(pControl);
00532
00533 _bstr_t tag = pButton->GetTag();
00534 if (_tcscmp(BUTTON_TAG, (LPCTSTR)tag) == 0)
00535 pButton->PutEnabled(bEnable ? VARIANT_TRUE : VARIANT_FALSE);
00536 }
00537 break;
00538 default:
00539 {
00540
00541 CComQIPtr<Office2000::CommandBarPopup> pPopup(pControl);
00542 if (pPopup != NULL)
00543 {
00544
00545 CComPtr <CommandBarControls> pInnerControls = pPopup->GetControls();
00546
00547 if (!EnableButtons(pInnerControls, bEnable))
00548 return false;
00549 }
00550 }
00551 break;
00552 }
00553 }
00554 return true;
00555 }
00556
00561 bool CCCPDFExcelAddinObj::EnableButtons(bool bEnable)
00562 {
00563
00564 CComPtr <_CommandBars> pCmdBars = m_spApp->GetCommandBars();
00565
00566
00567 for (long i=1;i<pCmdBars->GetCount();i++)
00568 {
00569 CComPtr <CommandBar> pCommandBar = NULL;
00570 HRESULT hr = pCmdBars->get_Item((variant_t)i, &pCommandBar);
00571 if (!FAILED(hr) && (pCommandBar != NULL))
00572 {
00573
00574 CComPtr <CommandBarControls> pControls = pCommandBar->GetControls();
00575
00576 if (!::EnableButtons(pControls, bEnable))
00577 return false;
00578 }
00579 }
00580 return true;
00581 }
00582
00586 struct CellInfo
00587 {
00588 public:
00592 CellInfo() : nPage(0), dPos(0.0), dEnd(0.0) {};
00599 CellInfo(int n, double d, double dS) : nPage(n), dPos(d), dEnd(d + dS) {};
00604 CellInfo(const CellInfo& other) : nPage(other.nPage), dPos(other.dPos), dEnd(other.dEnd) {};
00605
00607 int nPage;
00609 double dPos;
00611 double dEnd;
00612
00619 void Set(int n, double d, double dS) {nPage = n; dPos = d; dEnd = d + dS;};
00620 };
00621
00628 std::tstring CellName(long nRow, long nColumn)
00629 {
00630 std::tstring sColumn;
00631
00632
00633 do
00634 {
00635 nColumn--;
00636 int nLetter = nColumn % 26;
00637
00638 TCHAR cLetter = _T('A') + nLetter;
00639 sColumn = cLetter + sColumn;
00640
00641 nColumn /= 26;
00642 } while (nColumn > 0);
00643
00644
00645 TCHAR cRet[1024];
00646 _stprintf(cRet, _T("%.768s%d"), sColumn.c_str(), nRow);
00647 return cRet;
00648 }
00649
00653 struct PrintPageData
00654 {
00660 PrintPageData(long lFont, bstr_t& sFont) : dDPI(0.0), dStartMargin(0.0), dEndMargin(0.0), bCenter(false), lFontSize(lFont), sFontName(sFont) {};
00662 double dDPI;
00664 double dStartMargin;
00666 double dEndMargin;
00668 bool bCenter;
00670 long lFontSize;
00672 std::tstring sFontName;
00673
00675 std::tstring CreateName() const;
00676 };
00677
00681 std::tstring PrintPageData::CreateName() const
00682 {
00683 TCHAR c[128];
00684 _stprintf(c, _T("%d%0.2f%0.2f%d%d%s"), (long)dDPI, dStartMargin, dEndMargin, bCenter ? 1 : 0, lFontSize, sFontName.c_str());
00685 return c;
00686 }
00687
00691 struct PrintCalcData
00692 {
00696 PrintCalcData() : dFactor(0.0), lOffset(0), lFullSize(0), bCenter(false), bForceDPI(false) {};
00698 double dFactor;
00700 long lOffset;
00702 long lFullSize;
00704 bool bCenter;
00706 bool bForceDPI;
00707
00709 bool WriteToRegistry(const PrintPageData& orig, LPCTSTR lpPrefix);
00711 bool ReadFromRegistry(const PrintPageData& orig, LPCTSTR lpPrefix);
00712
00714 void FromData(const PrintPageData& orig, int nEnd, int nStart, double dEnd, double dStart, long lFull);
00716 long FixLocation(double dPos, double dFullPage);
00717 };
00718
00724 bool PrintCalcData::ReadFromRegistry(const PrintPageData& orig, LPCTSTR lpPrefix)
00725 {
00726
00727 std::tstring sName = REGISTRY_DATA_PATH _T("\\PD_");
00728 sName += lpPrefix + orig.CreateName();
00729
00730
00731 int nSize = sizeof(dFactor);
00732 unsigned char* pFactor;
00733 if (!CCRegistry::GetBinary(HKEY_CURRENT_USER, sName.c_str(), _T("Factor"), pFactor, nSize))
00734 return false;
00735 dFactor = *((double*)pFactor);
00736 delete [] pFactor;
00737 bool bSuccess;
00738 DWORD dw = CCRegistry::GetNumber(HKEY_CURRENT_USER, sName.c_str(), _T("Offset"), &bSuccess);
00739 if (!bSuccess)
00740 return false;
00741 lOffset = (long)dw;
00742 dw = CCRegistry::GetNumber(HKEY_CURRENT_USER, sName.c_str(), _T("FullSize"), &bSuccess);
00743 if (!bSuccess)
00744 return false;
00745 lFullSize = (long)dw;
00746 dw = CCRegistry::GetNumber(HKEY_CURRENT_USER, sName.c_str(), _T("ForceDPI"), &bSuccess);
00747 if (bSuccess)
00748 bForceDPI = (dw == 1);
00749
00750
00751 bCenter = orig.bCenter;
00752 return true;
00753 }
00754
00760 bool PrintCalcData::WriteToRegistry(const PrintPageData& orig, LPCTSTR lpPrefix)
00761 {
00762
00763 std::tstring sName = REGISTRY_DATA_PATH _T("\\PD_");
00764 sName += lpPrefix + orig.CreateName();
00765
00766
00767 if (!CCRegistry::SetBinary(HKEY_CURRENT_USER, sName.c_str(), _T("Factor"), (unsigned char*)&dFactor, sizeof(dFactor)))
00768 return false;
00769 if (!CCRegistry::SetNumber(HKEY_CURRENT_USER, sName.c_str(), _T("Offset"), (DWORD)lOffset))
00770 return false;
00771 if (!CCRegistry::SetNumber(HKEY_CURRENT_USER, sName.c_str(), _T("FullSize"), (DWORD)lFullSize))
00772 return false;
00773 if (!CCRegistry::SetNumber(HKEY_CURRENT_USER, sName.c_str(), _T("ForceDPI"), bForceDPI ? 1 : 0))
00774 return false;
00775
00776 return true;
00777 }
00778
00787 void PrintCalcData::FromData(const PrintPageData& orig, int nEnd, int nStart, double dEnd, double dStart, long lFull)
00788 {
00789
00790 bCenter = orig.bCenter;
00791 lFullSize = lFull;
00792
00793 dFactor = (nEnd - nStart) / (dEnd - dStart);
00794
00795 lOffset = bCenter ? (nStart + nEnd) / 2 : nStart;
00796 }
00797
00803 long PrintCalcData::FixLocation(double dPos, double dFullPage)
00804 {
00805
00806 long lRet = lOffset;
00807 if (bCenter)
00808
00809 dPos -= (dFullPage / 2);
00810
00811 return lRet + (dPos * dFactor);
00812 }
00813
00821 INT_PTR CALLBACK ProcessingDlgFunc(HWND hwndDialog, UINT uMsg, WPARAM wParam, LPARAM lParam)
00822 {
00823
00824 return FALSE;
00825 }
00826
00831 void CenterWindow(HWND hWnd)
00832 {
00833
00834 RECT rcDlg;
00835 ::GetWindowRect(hWnd, &rcDlg);
00836 RECT rcCenter, rcArea;
00837
00838 ::SystemParametersInfo(SPI_GETWORKAREA, NULL, &rcArea, NULL);
00839 rcCenter = rcArea;
00840
00841 int DlgWidth = rcDlg.right - rcDlg.left;
00842 int DlgHeight = rcDlg.bottom - rcDlg.top;
00843
00844
00845 int xLeft = (rcCenter.left + rcCenter.right) / 2 - DlgWidth / 2;
00846 int yTop = (rcCenter.top + rcCenter.bottom) / 2 - DlgHeight / 2;
00847
00848
00849 if (xLeft < rcArea.left)
00850 xLeft = rcArea.left;
00851 else if(xLeft + DlgWidth > rcArea.right)
00852 xLeft = rcArea.right - DlgWidth;
00853
00854 if(yTop < rcArea.top)
00855 yTop = rcArea.top;
00856 else if(yTop + DlgHeight > rcArea.bottom)
00857 yTop = rcArea.bottom - DlgHeight;
00858
00859
00860 ::SetWindowPos(hWnd, NULL, xLeft, yTop, -1, -1, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
00861 }
00862
00867 void CCCPDFExcelAddinObj::DoPrint(HANDLE hPrinter, const std::tstring& sPrinter)
00868 {
00869
00870 CCPrintData data;
00871 CComPtr <MSExcel::_Workbook> workbook = m_spApp->GetActiveWorkbook();
00872 if (workbook == NULL)
00873 {
00874 MessageBox(NULL, _T("Cannot access the active worksheet"), PRINTER_ERROR_TITLE, MB_OK|MB_ICONERROR);
00875 return;
00876 }
00877
00878
00879 CComPtr<MSExcel::Styles> styles = workbook->GetStyles();
00880 CComPtr<MSExcel::Style> style = styles->GetItem(_T("Normal"));
00881 if (style == NULL)
00882 {
00883 MessageBox(NULL, _T("Cannot access the active worksheet's styles"), PRINTER_ERROR_TITLE, MB_OK|MB_ICONERROR);
00884 return;
00885 }
00886 CComPtr<MSExcel::Font> font = style->GetFont();
00887 long lFontSize = font->GetSize();
00888 bstr_t sFontName = (bstr_t) font->GetName();
00889 CComQIPtr<MSExcel::_Worksheet> worksheet = workbook->GetActiveSheet();
00890 if (worksheet == NULL)
00891 {
00892 MessageBox(NULL, _T("Cannot access the active worksheet"), PRINTER_ERROR_TITLE, MB_OK|MB_ICONERROR);
00893 return;
00894 }
00895
00896
00897 CComPtr<MSExcel::Range> range = worksheet->GetUsedRange();
00898 int nColumns = range->GetColumns()->GetCount() + range->GetColumn(), nRows = range->GetRows()->GetCount() + range->GetRow();
00899 if ((nColumns < 1) || (nRows < 1))
00900 {
00901
00902 CleanupDialog();
00903 MessageBox(NULL, _T("No data in the active sheet"), PRINTER_ERROR_TITLE, MB_OK|MB_ICONERROR);
00904 return;
00905 }
00906
00907
00908 CComPtr<MSExcel::PageSetup> page = worksheet->GetPageSetup();
00909 variant_t vZoom = page->GetZoom();
00910 bool bFitToPage = ((vZoom.vt == VT_BOOL) && (vZoom.boolVal == FALSE));
00911 if (bFitToPage)
00912 {
00913
00914 MessageBox(NULL, PRODUCT_NAME _T(" cannot make a PDF from a sheet which is set to 'fit-to'.\nPlease change the setting in Excel's Page Setup"), PRINTER_ERROR_TITLE, MB_OK|MB_ICONERROR);
00915 return;
00916 }
00917
00918
00919 m_hDialog = CreateDialog(_Module.m_hInstResource, MAKEINTRESOURCE(IDD_PROCESSING), NULL, ProcessingDlgFunc);
00920 CenterWindow(m_hDialog);
00921
00922
00923 PrintPageData pageHorz(lFontSize, sFontName), pageVert(lFontSize, sFontName);
00924 PrintCalcData dataHorz, dataVert;
00925
00926 pageHorz.dStartMargin = page->GetLeftMargin();
00927 pageHorz.dEndMargin = page->GetRightMargin();
00928 pageHorz.dDPI = page->GetPrintQuality((long)1);
00929 pageHorz.bCenter = ((BOOL)page->GetCenterHorizontally()) ? true : false;
00930
00931 pageVert.dStartMargin = page->GetTopMargin();
00932 pageVert.dEndMargin = page->GetBottomMargin();
00933 pageVert.dDPI = page->GetPrintQuality((long)2);
00934 pageVert.bCenter = ((BOOL)page->GetCenterVertically()) ? true : false;
00935
00936
00937 m_spApp->PutScreenUpdating(0, VARIANT_FALSE);
00938
00939 if (!CalculatePrintData(pageHorz, pageVert, dataHorz, dataVert, data, hPrinter, sPrinter, page, worksheet))
00940 {
00941 m_spApp->PutScreenUpdating(0, VARIANT_TRUE);
00942 return;
00943 }
00944
00945
00946 if (dataHorz.bForceDPI)
00947 page->PutPrintQuality((long)1, 300.0);
00948 if (dataVert.bForceDPI)
00949 page->PutPrintQuality((long)2, 300.0);
00950
00951
00952 m_spApp->PutScreenUpdating(0, VARIANT_TRUE);
00953
00954 EnsureDialogVisible();
00955
00956
00957 bool bDownfirst = (page->GetOrder() == MSExcel::xlDownThenOver);
00958
00959
00960
00961
00962 std::vector<CellInfo> arColumns, arRows;
00963 std::vector<double> arPageWidth, arPageHeight;
00964 arColumns.resize(nColumns+1);
00965 arRows.resize(nRows+1);
00966 double dSize = 0.0, dPageStart = 0.0;
00967 int nPage = 1;
00968 arPageWidth.push_back(0.0);
00969 CComPtr<MSExcel::Range> columns = worksheet->GetColumns();
00970 CComPtr<MSExcel::Range> rows = worksheet->GetRows();
00971 CComQIPtr<MSExcel::Range> temp;
00972
00973 long i;
00974 for (i=1;i<=nColumns+1;i++)
00975 {
00976
00977 temp = columns->GetItem(i);
00978
00979 dSize = temp->GetWidth().dblVal;
00980 if (temp->GetPageBreak() != MSExcel::xlPageBreakNone)
00981 {
00982
00983 dPageStart = temp->GetLeft();
00984 nPage++;
00985
00986 arPageWidth.push_back(0.0);
00987 }
00988
00989 arColumns[i-1].Set(nPage, temp->GetLeft().dblVal - dPageStart, dSize);
00990
00991 arPageWidth[nPage - 1] += temp->GetWidth().dblVal;
00992 }
00993
00994 arPageWidth[nPage - 1] -= temp->GetWidth().dblVal;
00995
00996
00997 dSize = 0.0;
00998 dPageStart = 0.0;
00999 nPage = 1;
01000 arPageHeight.push_back(0.0);
01001 for (i=1;i<=nRows+1;i++)
01002 {
01003
01004 temp = rows->GetItem(i);
01005
01006 dSize = temp->GetHeight().dblVal;
01007 if (temp->GetPageBreak() != MSExcel::xlPageBreakNone)
01008 {
01009
01010 dPageStart = temp->GetTop();
01011 nPage++;
01012
01013 arPageHeight.push_back(0.0);
01014 }
01015
01016 arRows[i-1].Set(nPage, temp->GetTop().dblVal - dPageStart, dSize);
01017
01018 arPageHeight[nPage - 1] += temp->GetHeight().dblVal;
01019 }
01020
01021 arPageHeight[nPage - 1] -= temp->GetHeight().dblVal;
01022
01023
01024 std::tstring sSheetName;
01025 LPCTSTR lpName = worksheet->GetName();
01026 if (lpName != NULL)
01027 sSheetName = worksheet->GetName();
01028
01029
01030 CComPtr<MSExcel::Hyperlinks> links = worksheet->GetHyperlinks();
01031 CComPtr<MSExcel::Names> names = workbook->GetNames();
01032 RECTL rect;
01033
01034
01035 for (i=1;i<=links->GetCount();i++)
01036 {
01037
01038 CComPtr<MSExcel::Hyperlink> link = links->GetItem(i);
01039 try
01040 {
01041
01042 temp = link->GetRange();
01043 }
01044 catch (_com_error e)
01045 {
01046
01047 continue;
01048 }
01049
01050
01051 const CellInfo& row = arRows[temp->GetRow() - 1], column = arColumns[temp->GetColumn() - 1];
01052
01053
01054 rect.top = dataVert.FixLocation(row.dPos, arPageHeight[row.nPage - 1]);
01055 rect.left = dataHorz.FixLocation(column.dPos, arPageWidth[column.nPage - 1]);
01056 rect.bottom = dataVert.FixLocation(row.dEnd, arPageHeight[row.nPage - 1]);
01057 rect.right = dataHorz.FixLocation(column.dEnd, arPageWidth[column.nPage - 1]);
01058
01059
01060 nPage = bDownfirst ? (arRows.back().nPage * (column.nPage - 1)) + row.nPage : (arColumns.back().nPage * (row.nPage - 1)) + column.nPage;
01061
01062
01063 std::tstring sAddress, sSubAddress;
01064 LPCTSTR lpAddress = link->GetAddress();
01065 LPCTSTR lpSubAddress = link->GetSubAddress();
01066 if (lpAddress != NULL)
01067 sAddress = link->GetAddress();
01068 if (lpSubAddress != NULL)
01069 sSubAddress = link->GetSubAddress();
01070
01071 if (!sAddress.empty())
01072 {
01073
01074 if (!sSubAddress.empty())
01075 sAddress += _T("#") + sSubAddress;
01076
01077
01078 data.AddLink(sAddress, rect, nPage, (LPCTSTR)link->GetScreenTip());
01079 continue;
01080 }
01081
01082
01083 if (sSubAddress.empty() || sSheetName.empty())
01084 continue;
01085
01086 try
01087 {
01088
01089 CComPtr<MSExcel::Name> name = names->Item(sSubAddress.c_str());
01090 if (name != NULL)
01091 {
01092
01093 variant_t var = name->GetRefersToLocal();
01094 sSubAddress = (_bstr_t)var;
01095 if (!sSubAddress.empty())
01096 {
01097 if (sSubAddress[0] == '=')
01098 sSubAddress.erase(0, 1);
01099 else
01100 sSubAddress = _T("");
01101 }
01102 }
01103 }
01104 catch (...)
01105 {
01106
01107 }
01108 if (sSubAddress.empty())
01109
01110 continue;
01111
01112
01113
01114
01115 std::tstring::size_type nBreak = sSubAddress.find_last_of('!');
01116 if (nBreak != std::tstring::npos)
01117 {
01118
01119 std::tstring sSheet = sSubAddress.substr(0, nBreak);
01120 if (sSheet != sSheetName)
01121 continue;
01122
01123 sSubAddress.erase(0, nBreak + 1);
01124 }
01125
01126 nBreak = sSubAddress.find_first_of(_T("0123456789"));
01127 if (nBreak == std::tstring::npos)
01128 continue;
01129 std::tstring sColumn = sSubAddress.substr(0, nBreak);
01130 sSubAddress.erase(0, nBreak);
01131 if (sColumn.empty() || sSubAddress.empty())
01132 continue;
01133 if (sColumn[0] == '$')
01134 sColumn.erase(0, 1);
01135 if (sColumn.empty())
01136 continue;
01137 if (sColumn.at(sColumn.size() - 1) == '$')
01138 sColumn.erase(sColumn.size() - 1, 1);
01139 int nColumn = 0;
01140 while (!sColumn.empty())
01141 {
01142 nColumn = nColumn * 26 + (((unsigned char)sColumn[0]) - 'A');
01143 sColumn.erase(0, 1);
01144 }
01145 nColumn++;
01146 int nRow = _ttoi(sSubAddress.c_str());
01147 if (nRow < 1)
01148 continue;
01149
01150
01151 const CellInfo& linkRow = nRow <= arRows.size() ? arRows[nRow - 1] : arRows.back();
01152 const CellInfo& linkColumn = nColumn <= arColumns.size() ? arColumns[nColumn - 1] : arColumns.back();
01153 int nDestPage = bDownfirst ? (arRows.back().nPage * (linkColumn.nPage - 1)) + linkRow.nPage : (arColumns.back().nPage * (linkRow.nPage - 1)) + linkColumn.nPage;
01154
01155
01156
01157
01158
01159 double dX = dataHorz.FixLocation(linkColumn.dPos, arPageWidth[linkColumn.nPage - 1]);
01160 dX = dX * 72.0 / pageHorz.dDPI;
01161 double dY = dataVert.FixLocation(linkRow.dPos, arPageHeight[linkRow.nPage - 1]);
01162 dY = (dataVert.lFullSize - dY) * 72 / pageVert.dDPI;
01163
01164 data.AddLink(rect, nPage, nDestPage, dX - 5.0, dY + 5.0, (LPCTSTR)link->GetScreenTip());
01165 }
01166
01167
01168 if (data.HasData())
01169 {
01170 if (!data.SaveProcessData(hPrinter))
01171 {
01172 CleanupDialog();
01173 MessageBox(NULL, ACCESS_PRINTER_ERROR_MSG, PRINTER_ERROR_TITLE, MB_OK|MB_ICONERROR);
01174 return;
01175 }
01176 }
01177 else
01178 data.CleanSaved(hPrinter);
01179
01180
01181 ::Sleep(2000);
01182
01183
01184 CleanupDialog();
01185 CComVariant vEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);
01186 worksheet->PrintOut(vEmpty, vEmpty, (variant_t)(long)1, VARIANT_FALSE, vEmpty, VARIANT_FALSE, VARIANT_FALSE);
01187 }
01188
01207 bool CCCPDFExcelAddinObj::CalculatePrintData(const PrintPageData& pageHorz, const PrintPageData& pageVert, PrintCalcData& dataHorz, PrintCalcData& dataVert, CCPrintData& data, HANDLE hPrinter, const std::tstring& sPrinter, CComPtr<MSExcel::PageSetup>& page, CComQIPtr<MSExcel::_Worksheet>& worksheet)
01208 {
01209
01210 variant_t vZoom = page->GetZoom();
01211 bool bFitToPage = ((vZoom.vt == VT_BOOL) && (vZoom.boolVal == FALSE));
01212
01213 if (!bFitToPage)
01214 {
01215 if (dataHorz.ReadFromRegistry(pageHorz, _T("Horz")) && dataVert.ReadFromRegistry(pageVert, _T("Vert")))
01216
01217 return true;
01218 }
01219
01220
01221 double dTopLeftX, dTopLeftY, dBottomRightX, dBottomRightY;
01222 CComPtr<MSExcel::Workbooks> workbooks = m_spApp->GetWorkbooks();
01223 CComPtr<MSExcel::_Workbook> workbookTemp = workbooks->Add();
01224 try
01225 {
01226
01227 workbookTemp->Activate();
01228 EnsureDialogVisible();
01229 CComQIPtr<MSExcel::_Worksheet> worksheetTemp = workbookTemp->GetActiveSheet();
01230 EnsureDialogVisible();
01231 m_spApp->PutActivePrinter(0, sPrinter.c_str());
01232 CComPtr<MSExcel::PageSetup> pageTemp = worksheetTemp->GetPageSetup();
01233 pageTemp->PutCenterHorizontally(pageHorz.bCenter ? VARIANT_TRUE : VARIANT_FALSE);
01234 pageTemp->PutCenterVertically(pageVert.bCenter ? VARIANT_TRUE : VARIANT_FALSE);
01235 pageTemp->PutDraft(page->GetDraft());
01236 pageTemp->PutFooterMargin(page->GetFooterMargin());
01237 pageTemp->PutHeaderMargin(page->GetHeaderMargin());
01238 pageTemp->PutLeftMargin(pageHorz.dStartMargin);
01239 pageTemp->PutRightMargin(pageHorz.dEndMargin);
01240 pageTemp->PutOrientation(page->GetOrientation());
01241 pageTemp->PutPaperSize(page->GetPaperSize());
01242 pageTemp->PutPrintGridlines(VARIANT_FALSE);
01243 pageTemp->PutPrintHeadings(page->GetPrintHeadings());
01244 pageTemp->PutPrintTitleColumns(page->GetPrintTitleColumns());
01245 pageTemp->PutPrintTitleRows(page->GetPrintTitleRows());
01246 pageTemp->PutTopMargin(pageVert.dStartMargin);
01247 pageTemp->PutBottomMargin(pageVert.dEndMargin);
01248
01249
01250 if (bFitToPage)
01251 pageTemp->PutZoom((variant_t)(long)100);
01252 else
01253 pageTemp->PutZoom(vZoom);
01254 try
01255 {
01256
01257 pageTemp->PutPrintQuality((long)1, pageHorz.dDPI);
01258 }
01259 catch (...)
01260 {
01261
01262 dataHorz.bForceDPI = true;
01263 pageTemp->PutPrintQuality((long)1, 300.0);
01264 }
01265 try
01266 {
01267
01268 pageTemp->PutPrintQuality((long)2, pageVert.dDPI);
01269 }
01270 catch (...)
01271 {
01272
01273 dataVert.bForceDPI = true;
01274 pageTemp->PutPrintQuality((long)2, 300.0);
01275 }
01276
01277
01278 CComPtr<MSExcel::Styles> stylesTemp = workbookTemp->GetStyles();
01279 CComPtr<MSExcel::Style> styleTemp = stylesTemp->GetItem(_T("Normal"));
01280 CComPtr<MSExcel::Font> fontTemp = styleTemp->GetFont();
01281 fontTemp->PutSize(pageHorz.lFontSize);
01282 fontTemp->PutName(pageHorz.sFontName.c_str());
01283
01284
01285 CComPtr<MSExcel::Hyperlinks> links = worksheetTemp->GetHyperlinks();
01286 CComPtr<MSExcel::Range> range = worksheetTemp->GetRange((variant_t)_T("A1"));
01287 dTopLeftX = range->GetLeft();
01288 dTopLeftY = range->GetTop();
01289 CComVariant vEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);
01290 CComPtr<MSExcel::Range> columns = worksheetTemp->GetColumns();
01291 CComPtr<MSExcel::Range> rows = worksheetTemp->GetRows();
01292 CComQIPtr<MSExcel::Range> temp;
01293
01294
01295 links->Add(range, _T("http://topleft.com"), vEmpty, vEmpty, _T("a"));
01296 range->PutVerticalAlignment((long)MSExcel::xlTop);
01297 range->PutHorizontalAlignment((long)MSExcel::xlLeft);
01298 data.AddLink(_T("http://topleft.com"), _T("a"), 1);
01299
01300
01301 long lRow = 2, lCol = 2;
01302 do
01303 {
01304
01305 range = worksheetTemp->GetRange((variant_t)CellName(1, lCol).c_str());
01306 range->PutFormula(_T("c"));
01307 temp = columns->GetItem(lCol);
01308 if (temp->GetPageBreak() != MSExcel::xlPageBreakNone)
01309 break;
01310
01311 range->ClearContents();
01312 lCol++;
01313 } while (true);
01314 range->ClearContents();
01315 lCol--;
01316
01317 do
01318 {
01319
01320 range = worksheetTemp->GetRange((variant_t)CellName(lRow, 1).c_str());
01321 range->PutFormula(_T("c"));
01322 temp = rows->GetItem(lRow);
01323 if (temp->GetPageBreak() != MSExcel::xlPageBreakNone)
01324 break;
01325
01326 range->ClearContents();
01327 lRow++;
01328 } while (true);
01329 range->ClearContents();
01330 lRow--;
01331
01332
01333 range = worksheetTemp->GetRange((variant_t)CellName(lRow, lCol).c_str());
01334 dBottomRightX = (double)range->GetLeft() + (double)range->GetWidth();
01335 dBottomRightY = (double)range->GetTop() + (double)range->GetHeight();
01336 links->Add(range, _T("http://bottomright.com"), vEmpty, vEmpty, _T("b"));
01337
01338 range->PutHorizontalAlignment((long)MSExcel::xlRight);
01339 range->PutVerticalAlignment((long)MSExcel::xlBottom);
01340 data.AddLink(_T("http://bottomright.com"), _T("b"), 1);
01341
01342 data.SetTestPage();
01343
01344
01345 if (bFitToPage)
01346 {
01347
01348 range = worksheet->GetUsedRange();
01349 long lColumns = range->GetColumns()->GetCount() + range->GetColumn(), lRows = range->GetRows()->GetCount() + range->GetRow();
01350 range = worksheet->GetRange((variant_t)CellName(lRows, lColumns).c_str());
01351 double dEndX = range->GetLeft().dblVal + range->GetWidth().dblVal, dEndY = range->GetTop().dblVal + range->GetWidth().dblVal;
01352
01353 CComPtr<MSExcel::Range> columns = worksheetTemp->GetColumns();
01354 CComPtr<MSExcel::Range> rows = worksheetTemp->GetRows();
01355 lColumns = 1;
01356 CComQIPtr<MSExcel::Range> temp;
01357 while (true)
01358 {
01359 temp = columns->GetItem(lColumns);
01360 if (temp->GetLeft().dblVal + temp->GetWidth().dblVal >= dEndX)
01361 break;
01362 lColumns++;
01363 }
01364 lRows = 1;
01365 while (true)
01366 {
01367 temp = rows->GetItem(lRows);
01368 if (temp->GetTop().dblVal + temp->GetHeight().dblVal >= dEndY)
01369 break;
01370 lRows++;
01371 }
01372 range = worksheetTemp->GetRange((variant_t)CellName(lRows, lColumns).c_str());
01373 range->PutFormula(_T("xyz"));
01374 pageTemp->PutFitToPagesTall(page->GetFitToPagesTall());
01375 pageTemp->PutFitToPagesWide(page->GetFitToPagesWide());
01376 }
01377
01378
01379 if (!data.SaveProcessData(hPrinter))
01380 {
01381 CleanupDialog();
01382 MessageBox(NULL, ACCESS_PRINTER_ERROR_MSG, PRINTER_ERROR_TITLE, MB_OK|MB_ICONERROR);
01383 return false;
01384 }
01385 try
01386 {
01387 worksheetTemp->PrintOut((variant_t)(long)1, (variant_t)(long)1, (variant_t)(long)1, VARIANT_FALSE, vEmpty, VARIANT_FALSE, VARIANT_FALSE);
01388 }
01389 catch (...)
01390 {
01391 }
01392 }
01393 catch (...)
01394 {
01395
01396 try
01397 {
01398 workbookTemp->Close(VARIANT_FALSE);
01399 }
01400 catch(...)
01401 {
01402 }
01403 throw;
01404 }
01405
01406 workbookTemp->Close(VARIANT_FALSE);
01407
01408
01409 if (!data.ReloadProcessData(hPrinter) || (data.GetPageCount() != 1) || (data.GetPageData(1).size() != 2))
01410 {
01411
01412 CleanupDialog();
01413 MessageBox(NULL, WORKING_PRINTER_ERROR_MSG, PRINTER_ERROR_TITLE, MB_OK|MB_ICONERROR);
01414 return false;
01415 }
01416
01417
01418 int nTopLeftX, nTopLeftY, nBottomRightX, nBottomRightY;
01419 if (data.GetPageCount() != 1)
01420 {
01421
01422 CleanupDialog();
01423 MessageBox(NULL, WORKING_PRINTER_ERROR_MSG, PRINTER_ERROR_TITLE, MB_OK|MB_ICONERROR);
01424 return false;
01425 }
01426
01427
01428 const CCPrintData::PageData& pageData = data.GetPageData(1);
01429 for (CCPrintData::PageData::const_iterator iData = pageData.begin(); iData != pageData.end(); iData++)
01430 {
01431 const CCPrintData::LinkData& link = (*iData);
01432
01433 if (link.sURL == _T("http://topleft.com"))
01434 {
01435
01436 nTopLeftX = link.rectLocation.left;
01437 nTopLeftY = link.rectLocation.top;
01438 }
01439
01440 else if (link.sURL == _T("http://bottomright.com"))
01441 {
01442
01443 nBottomRightX = link.rectLocation.right;
01444 nBottomRightY = link.rectLocation.bottom;
01445 }
01446 else
01447 {
01448
01449 CleanupDialog();
01450 MessageBox(NULL, WORKING_PRINTER_ERROR_MSG, PRINTER_ERROR_TITLE, MB_OK|MB_ICONERROR);
01451 return false;
01452 }
01453 }
01454
01455
01456 dataHorz.FromData(pageHorz, nBottomRightX, nTopLeftX, dBottomRightX, dTopLeftX, pageData.szPage.cx);
01457 dataVert.FromData(pageVert, nBottomRightY, nTopLeftY, dBottomRightY, dTopLeftY, pageData.szPage.cy);
01458
01459 if (!bFitToPage)
01460 {
01461 dataHorz.WriteToRegistry(pageHorz, _T("Horz"));
01462 dataVert.WriteToRegistry(pageVert, _T("Vert"));
01463 }
01464
01465
01466 data.CleanThis();
01467 return true;
01468 }