📄 previewdialog.cpp
字号:
/* * * previewdialog.cpp * Copyright (C) 2006 Michael H. Overlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Contact at poster_printer@yahoo.com * */#include "previewdialog.h"#include "prbitmapdatafile.h"#include "previewdialog_switches.h"#include "prposterdatafile.h"#include "prlistviewdialog.h"#include "prpreviewutils.h"#include "resource.h"#include "viewableprintpageslist.h"#include "..\lib\buffer.h"#include "..\lib\devmode.h"#include "..\lib\gdiutils.h"#include "..\lib\mathutils.h"#include "..\lib\prcommandline.h"#include "..\lib\prdatasource.h"#include "..\lib\printResizerCommon.h"#include "..\lib\progressdialog.h"#include "..\lib\prspoolerdatafile.h"#include "..\lib\prutils.h"#include "..\lib\spoolutils.h"#include "..\lib\renderpages.h"#include "..\lib\tabdialogsctrl.h"//#include <winspool.h>#include <commctrl.h>#include <commdlg.h>#include <vector>#include <tchar.h>#include <strsafe.h>#include <stdlib.h>class ChildEnabler : private EnumWindows {public: ChildEnabler(HWND hwndParent, BOOL bEnable) : m_hwndParent(hwndParent), m_bEnable(bEnable) {} void DoEnable(void) { EnumChildWindows(m_hwndParent); } virtual BOOL EnumProc(HWND hwndEnum) { ::EnableWindow(hwndEnum, m_bEnable); return TRUE; }private: HWND m_hwndParent; BOOL m_bEnable;};// ****// **** MODULE PRIVATE ROUTINES PROTOTYPES// ****// DEBUGVOID DrawTestImage(OUT HDC hdc) ;//void GetEnhMetafileFrame_Inches(OUT RECTD& rd, IN HENHMETAFILE hMeta) ;void GetMinimumPageMargins(OUT RECTD& rdMargins, IN const PageSpec& ps) ;//6/4//void GetPageSpec(OUT ::PageSpec &ps, IN ::PCDEVMODE pdm) ;// ***************************************************************************************************// ** class PreviewDialog **************************************************************************// ***************************************************************************************************PreviewDialog::PreviewDialog(IN HINSTANCE hinst, IN WORD wTemplateID, IN LPCTSTR lptstrCommandLine) : DialogWindow(hinst, wTemplateID){ m_hMetaForPage = NULL; m_hMetaDraftForPage = NULL; //m_ppds = ::PrintPreviewDataSources::eUnspecified; m_pdwWaitingForSpoolerData = NULL; // DEBUG - FIX m_hIcon = ::LoadIcon(hinst, MAKEINTRESOURCE(IDI_ICON_PREVIEWAPP)); //m_pDataSource = new PRSpoolerDataFile; m_pDataSource = NULL; m_tstrCommandLine = lptstrCommandLine; m_pdmKeeper = new DevModeKeeper(); m_prdp = new ::PR_RulerDrawerProvider(); // FIX - TEMPORARY m_szdMinSelectionBox.cx = MIN_SELECTIONBOX_SIZE; m_szdMinSelectionBox.cy = MIN_SELECTIONBOX_SIZE; m_msResized.dCutGuideMargin_Inches = CUTGUIDE_MARGIN_INCHES; m_msResized.dOverlapMargin_Inches = OVERLAPPED_MARGIN_INCHES; m_msResized.rdEdgeMargins_Inches.left = PAGE_MARGIN_LEFT; m_msResized.rdEdgeMargins_Inches.top = PAGE_MARGIN_TOP; m_msResized.rdEdgeMargins_Inches.right = PAGE_MARGIN_RIGHT; m_msResized.rdEdgeMargins_Inches.bottom = PAGE_MARGIN_BOTTOM; m_msOriginal.dCutGuideMargin_Inches = 0; m_msOriginal.dOverlapMargin_Inches = 0; m_msOriginal.rdEdgeMargins_Inches.left = 0; m_msOriginal.rdEdgeMargins_Inches.top = 0; m_msOriginal.rdEdgeMargins_Inches.right = 0; m_msOriginal.rdEdgeMargins_Inches.bottom = 0; // m_tstrLastPrinterSelected IS ALREADY EMPTY, ITS DEFAULT STATE}PreviewDialog::~PreviewDialog() { // 7/8 IN SOME CASES SAW THIS HANG IN THE DESTRUCTOR // (AFTER ENDDIALOG) WAITING ON THE PROGRESS DIALOGS THREAD HANDLE // WHILE THE THREAD ITSELF SEEMED TO BE STUCK IN CENTERING ITSELF ABOVE ITS PARENT // IT MAY BE THAT SOMEHOW THE PROCESS WAS BEING TERMINATED ABNORMALLY, SUCH AS IN THE // UI-DLL ... IN ANY CASE, THIS DOESNT SEEM REALLY NECESSARY, CURRENTLY THIS CODE IS ONLY // HIT WHEN THE ENTIRE PROCESS IS BEING TERMINATED //if (m_pdwWaitingForSpoolerData != NULL) { // m_pdwWaitingForSpoolerData->EndDialog(0); // delete m_pdwWaitingForSpoolerData; //} // LISTS ARE ALREADY DELETED AT THIS POINT //this->CloseViewableLists(); delete m_pDataSource; delete m_pdmKeeper; delete m_prdp; this->DeletePageMetaFiles();}BOOL PreviewDialog::InitMsg(WPARAM wParam, LPARAM lParam) { DialogWindow::InitMsg(wParam, lParam); this->SendMessage(WM_SETICON, ICON_BIG, (LPARAM) m_hIcon); this->SendMessage(WM_SETICON, ICON_SMALL, (LPARAM) m_hIcon); this->CenterWindowAboveParent(); this->SetDialogTitle(TEXT("")); // DEFAULT UI STATE //this->FillPageList(0); this->WriteAutoRotate(TRUE); this->WriteNoCutGuidelines(FALSE); this->WriteZoom(1.0); this->WriteOriginalAll(TRUE);#if 0 this->WriteResizedAll(TRUE);#endif this->WriteEvenMargins(TRUE); // SET UP THE TAB DIALOG CONTROL HWND hwndTab = this->GetDlgItem(IDC_TABDIALOG); this->m_pTabDialogs = (TabDialogsCtrl *) Window::TheirGetObjPtr(hwndTab); std::vector<TabDialogsCtrl::TabSpec> vts(2); vts[0].pdw = new ::PRListViewDialog(this->hinst(), IDD_DIALOG_PRLISTVIEW); vts[0].tstrTab = TEXT("Poster"); vts[1].pdw = new ::PRListViewDialog(this->hinst(), IDD_DIALOG_PRLISTVIEW); vts[1].tstrTab = TEXT("Original"); m_pTabDialogs->SetDialogs(vts); // REGISTER AS NOTIFICATION TARGET { PRListViewDialog *pprlvdOriginal = this->GetOriginalSourceDialog(); m_hwndOriginalListView = pprlvdOriginal->AddListViewNotifyTarget(this->hdlg()); PRListViewDialog *pprlvdResized = this->GetResizedDialog(); m_hwndResizedListView = pprlvdResized->AddListViewNotifyTarget(this->hdlg()); } ::FillComboWithInstalledPrinters(this->GetDlgItem(IDC_COMBO_PRINTERS), TRUE); LPTSTR lptstrTemp = ::ChooseTargetPrinterNameWithoutUserInput(); if (lptstrTemp != NULL) { this->WriteSelectedPrinter(lptstrTemp); free(lptstrTemp); } this->CloseDataSource(); ::PrintPreviewDataSource ppdsNew; tstring tstrDataFileName; if (::ParseCommandLine(m_tstrCommandLine.c_str(), tstrDataFileName, ppdsNew)) { switch(ppdsNew) { case ::PrintPreviewDataSources::eBitmap: this->OnOpenFile(tstrDataFileName, new ::PRBitmapDataFile()/*, ::PrintPreviewDataSources::eBitmap*/); // ITS NOT USED AFTER THIS m_tstrCommandLine.erase(); break; case ::PrintPreviewDataSources::ePosterDataFile: this->OnOpenFile(tstrDataFileName, new ::PRPosterDataFile()/*, ::PrintPreviewDataSources::ePosterDataFile*/); // ITS NOT USED AFTER THIS m_tstrCommandLine.erase(); break; case ::PrintPreviewDataSources::ePrintSpoolerDataFile: { // NOW WE USE COMMAND LINE TO HOLD THE TEMP SPOOL DATA FILE NAME tstring tstrDialogTitle; this->ComposeDialogTitle(tstrDialogTitle, TEXT("Print in progress")); m_tstrCommandLine = tstrDataFileName; m_pdwWaitingForSpoolerData = new ::ProgressDialogWindow( this->hinst(), tstrDialogTitle.c_str(), TEXT("Waiting for data from spooler"), TRUE); m_pdwWaitingForSpoolerData->SetStatusString(TEXT("Spooler writing data")); m_pdwWaitingForSpoolerData->DoNewThreadModalDialog(this->hdlg()); } break; default: // ITS NOT USED AFTER THIS m_tstrCommandLine.erase(); break; } } return TRUE;}BOOL PreviewDialog::CommandMsg(WPARAM wParam, LPARAM lParam) { WORD wID = LOWORD(wParam); switch(wID) { // THERE IS NO "OK" BUTTON, THIS CASE JUST HANDLES A RETURN KEY PRESS FROM THE EDIT BOX case IDOK: { HWND hwndZoomEditBox = this->GetDlgItem(IDC_EDIT_ZOOM); HWND hwndFocus = ::GetFocus(); if (hwndFocus == hwndZoomEditBox) { this->OnZoomEditBoxEntry(); } //7/14 HWND hwndCtrl = this->GetDlgItem(IDC_EDIT_ZOOM); ::PostMessage(hwndCtrl, EM_SETSEL, 0, (LPARAM) -1); } break; case ID_FILE_EXIT: // FALL THRU case IDC_BUTTON_EXIT: { BOOL bExit = this->CloseDataSourceCofirmationMessage(TEXT("Exit")); if (bExit) { this->DestroyWindow(); } } break; case IDC_BUTTON_CONFIGURE: { BOOL bUnspecifiedError = FALSE; tstring tstrPrinter; if (this->ReadSelectedPrinter(tstrPrinter)) { PDEVMODE pdm = this->m_pdmKeeper->GetDevMode(tstrPrinter); if (pdm != NULL) { PDEVMODE pdmTemp = DM_Duplicate(pdm); LONG lresult = ::DoDocumentProperties(this->hdlg(), tstrPrinter.c_str(), pdmTemp, DM_IN_BUFFER | DM_OUT_BUFFER | DM_PROMPT); if (lresult == IDOK) { if (this->UpdateResizedPageSpec(pdmTemp)) { ::DM_Copy(pdmTemp, (LPBYTE) pdm); this->MakeZoomSettingsConsistent(); this->WriteZoom(m_rsResized.dZoom); this->ResetResizedViewableList(); } else { this->ErrorMessage(TEXT("The configured page size could not be used.\nPrinter changes have been reverted.")); } } else if (lresult < -1) { bUnspecifiedError = TRUE; } if (pdmTemp != NULL) { free(pdmTemp); } } else { bUnspecifiedError = TRUE; } } else { this->ErrorMessage(TEXT("Cannot configure printer: No printer is selected.")); } if (bUnspecifiedError) { this->ErrorMessage(TEXT("Cannot configure printer: An error occurred.")); } } break; case IDC_CHECK_EVENMARGINS: if (this->UpdateResizedPageSpec()) { this->MakeZoomSettingsConsistent(); this->WriteZoom(m_rsResized.dZoom); this->ResetResizedViewableList(); } else { this->ErrorMessage(TEXT("Unable to enact margin change")); this->WriteEvenMargins(! this->ReadEvenMargins() ); } break; case IDC_CHECK_LANDSCAPE: { // 7/4 DONT ASSUME WE ARE MAKING A CHANGE, EXCL. OR TO CHECK FIRST ; AND ASSERT ASSERT(m_psResized.rotDir != ::LandscapeRot::eNone); BOOL bNewLandscape = this->ReadLandscape(); BOOL bOldLandscape = m_psResized.bLandscape; //if (bNewLandscape ^ bOldLandscape) { if (lxor(bNewLandscape, bOldLandscape)) { ::LandscapeRotatePageSpec(m_psResized); // 7/8 BOOL bTemp = this->ReadAutoRotate(); this->WriteAutoRotate(FALSE); this->MakeZoomSettingsConsistent(); this->WriteAutoRotate(bTemp); this->WriteZoom(m_rsResized.dZoom); this->ResetResizedViewableList(); } } break; case IDC_BUTTON_PRINT: this->OnPrintCommand(); break; case IDC_CHECK_NOGUIDELINES: { BOOL bNoCutGuidelines = this->ReadNoCutGuidelines(); if (lxor(bNoCutGuidelines, ! m_rsResized.bCutGuides)) { m_rsResized.bCutGuides = ! bNoCutGuidelines; this->MakeZoomSettingsConsistent(); this->WriteZoom(m_rsResized.dZoom); this->ResetResizedViewableList(); } } break; case IDC_COMBO_PRINTERS: { WORD wCode = HIWORD(wParam); switch(wCode) { case CBN_SELCHANGE: if (this->UpdateResizedPageSpec()) { this->MakeZoomSettingsConsistent(); this->WriteZoom(m_rsResized.dZoom); this->ResetResizedViewableList(); } else { this->ErrorMessage(TEXT("Error on selecting printer")); tstring tstrTemp = this->m_tstrLastPrinterSelected; this->WriteSelectedPrinter(tstrTemp.c_str()); } break; default: break; } } break; case ID_FILE_OPEN: { BOOL bConfirm = this->CloseDataSourceCofirmationMessage(TEXT("Open poster")); if (bConfirm) { tstring tstrFileName; if (this->GetPosterOpenFileName(tstrFileName)) { if ( ! tstrFileName.empty() ) { ::PRDataSource *pprdsNew = new ::PRPosterDataFile(); this->OnOpenFile(tstrFileName, pprdsNew/*, ::PrintPreviewDataSources::ePosterDataFile*/); } } else { this->ErrorMessage(TEXT("Error initializing open")); } } } break; case ID_FILE_OPEN_BITMAP: { BOOL bConfirm = this->CloseDataSourceCofirmationMessage(TEXT("Open bitmap")); if (bConfirm) { tstring tstrFileName; if (this->GetBitmapOpenFilename(tstrFileName)) { if ( ! tstrFileName.empty()) { ::PRDataSource* pprdsNew = new ::PRBitmapDataFile(); this->OnOpenFile(tstrFileName, pprdsNew/*, ::PrintPreviewDataSources::eBitmap*/); } } else { this->ErrorMessage(TEXT("Error initializing open")); } } } break; case ID_FILE_SAVEPOSTER: this->OnSavePosterCommand(); break; case ID_FILE_SAVEORIGINALPAGESASBITMAPS: this->OnSaveOriginalAsBitmapCommand(); break; case ID_HELP_ABOUT: this->OnHelpAbout(); break; case ID_HELP_DOCUMENTATION: this->OnHelpDocumentation(); break; case IDC_LIST_PAGES: { WORD wCode = HIWORD(wParam); switch(wCode) { case LBN_SELCHANGE: uint uiPage; if (this->ReadSelectedPage(uiPage)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -