prdlgctl.cpp

Go to the documentation of this file.
00001 // $Id: prdlgctl.cpp 1742 2006-09-05 17:25:58Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 // Custom Print Dialog
00099 
00100 /*
00101 */
00102 
00103 #include "camtypes.h"
00104 
00105 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00106 #include "prdlgctl.h"
00107 //#include "printdlg.h"
00108 #include "printprg.h"
00109 #include "princomp.h"
00110 #include "optsprin.h"
00111 //#include "fixmem.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00112 #include "printmsg.h"
00113 #include "prnprefs.h"   // PrintPrefsDlg;;InvokeDialog
00114 #include "helpuser.h"
00115 #include "camelot.h"
00116 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00117 #include "ccdc.h"
00118 #include "ctrlhelp.h"
00119 //#include "richard2.h"
00120 #include "progress.h"
00121 //#include "markn.h"
00122 #include "unicdman.h"
00123 //#include "fonts.h"
00124 #include "printctl.h"
00125 #include "prnmks.h"
00126 #include "psdc.h"
00127 //#include "jason.h"        // Error messages
00128 //#include "resource.h" // _R(IDS_OK)/CANCEL
00129 //#include "simon.h"        // _R(IDS_HELP)
00130 
00131 #ifdef _DEBUG
00132 #include "optsprin.h"
00133 #include "keypress.h"
00134 #endif
00135 
00136 #define Swap(a,b)       { (a)^=(b), (b)^=(a), (a)^=(b); }
00137 
00138 PORTNOTE("printing", "Disabled message map stuff")
00139 #ifndef EXCLUDE_FROM_XARALX
00140 //---------------------------------
00141 
00142 //  WEBSTER-ranbirr-12/11/96
00143 #ifndef WEBSTER
00144 BEGIN_MESSAGE_MAP(CCPrintDialog, CPrintDialog)
00145     //{{AFX_MSG_MAP(CPrintDialog)
00146     ON_COMMAND_EX(_R(IDC_ALLOBJECTS),       OnCommand)
00147     ON_COMMAND_EX(_R(IDC_SELECTEDOBJECTS),  OnCommand)
00148     ON_COMMAND_EX(_R(IDC_DPSBOTH),          OnCommand)
00149     ON_COMMAND_EX(_R(IDC_DPSLEFTPAGES),     OnCommand)
00150     ON_COMMAND_EX(_R(IDC_DPSRIGHTPAGES),    OnCommand)
00151     ON_COMMAND_EX(_R(IDC_PRINTOPTIONS),     OnCommand)
00152     ON_COMMAND_EX(_R(IDC_PRINTHELP),        OnCommand)
00153     ON_COMMAND(psh1, OnPrintSetup) // print setup button when print is displayed
00154     //}}AFX_MSG_MAP
00155 END_MESSAGE_MAP()
00156 
00157 //---------------------------------
00158 
00159 #endif //webster
00160 #endif
00161 
00162 IMPLEMENT_DYNAMIC_CLASS(CCPrintDialog, wxPrintDialog)
00163 CC_IMPLEMENT_DYNAMIC(PrintMsg,Msg)
00164 
00165 
00166 //---------------------------------
00167 // This is the new Win95-compatible DOCINFO structure that has two extra fields, lpszDatatype & fwType.
00168 // We don't have the new header files yet, so we need to implement this struct ourselves.
00169 // This new struct is utilised by the func CCPrintInfo::SetUpDocInfo(DOCINFO* pDocInfo)
00170 
00171 typedef struct _NEW_DOCINFOA {
00172     INT32     cbSize;
00173     LPCSTR   lpszDocName;
00174     LPCSTR   lpszOutput;
00175     LPCSTR   lpszDatetype;
00176     DWORD    fwType;
00177 } NEW_DOCINFOA;
00178 typedef struct _NEW_DOCINFOW {
00179     INT32     cbSize;
00180     LPCWSTR  lpszDocName;
00181     LPCWSTR  lpszOutput;
00182     LPCWSTR  lpszDatetype;
00183     DWORD    fwType;
00184 } NEW_DOCINFOW;
00185 #ifdef UNICODE
00186 typedef NEW_DOCINFOW NEW_DOCINFO;
00187 #else
00188 typedef NEW_DOCINFOA NEW_DOCINFO;
00189 #endif // UNICODE
00190 
00191 #ifndef DI_APPBANDING
00192 #define DI_APPBANDING   0x0001
00193 #endif
00194 
00195 //---------------------------------
00196 
00197 // CCPrintDialog static vars
00198 //CCPrintDialog* CCPrintDialog::pInfoPrintDlg = NULL;       // Used to get settings for the default printer
00199 //  WEBSTER-ranbirr-12/11/96
00200 #ifndef WEBSTER
00201 
00202 BOOL    CCPrintDialog::GotPrinterSettings   = FALSE;
00203 wxSize  CCPrintDialog::PrPaperSize;
00204 BOOL    CCPrintDialog::PrPortrait           = TRUE;
00205 INT32   CCPrintDialog::PrScale              = 100;
00206 BOOL    CCPrintDialog::PrMultiCopies        = FALSE;
00207 
00208 INT32   CCPrintDialog::PrResolution         = 300;
00209 INT32   CCPrintDialog::PrResolutionX        = 300;
00210 INT32   CCPrintDialog::PrResolutionY        = 300;
00211 
00212 INT32   CCPrintDialog::PrLeftMargin         = 0;    //0x32a0;
00213 INT32   CCPrintDialog::PrTopMargin          = 0;    //0x2ee0;
00214 INT32   CCPrintDialog::PrRightMargin        = 0;    //0x3750;
00215 INT32   CCPrintDialog::PrBottomMargin       = 0;    //0x2ee0;
00216 
00217 BOOL    CCPrintDialog::PrPostscript         = FALSE;
00218 
00219 BOOL    CCPrintDialog::ReopenMainDlg        = FALSE;
00220 BOOL    CCPrintDialog::InformPrinterReset   = FALSE;
00221 BOOL    CCPrintDialog::IgnorePrntData       = FALSE;
00222 
00223 wxPrintDialogData CCPrintInfo::m_DefaultDialogData;
00224 BOOL CCPrintInfo::m_HaveSavedDefaultDialogData = FALSE;
00225 
00226 
00227 CCPrintInfo*   CCPrintInfo::pCurrent            = NULL; // Ptr to the last constructed CCPrintInfo
00228 #endif //webster
00229 
00230 #ifndef EXCLUDE_FROM_XARALX
00231 TCHAR   CCPrintToFileDialog::FileName[FILENAMEBUFSIZE]  = {_T('\0')};
00232 //  WEBSTER-ranbirr-12/11/96
00233 #ifndef WEBSTER
00234 CCPrintDialog* CCPrintDialog::pCurrentCCPrintDialog = NULL;
00235 wxPrintDialog*  CCPrintDialog::pDlgSetup                = NULL;
00236 #endif //webster
00237 #endif
00238 
00239 //---------------------------------
00240 
00241 // Paper selections
00242 // This data is taken from wingdi.h and defines the sizes of all the default paper size values
00243 // that appear in the dmPaperSize member of DEVMODE
00244 //
00245 // If dmPaperSize is zero, dmPaperLength and dmPaperWidth define the paper size (in tenths of a millimetre)
00246 //
00247 // NOTE: The code must be tested on a dot matrix printer because the dmPaperLength can be arbitrary.
00248 //
00249 // NOTE: I have not found an automatic way of finding out the dimensions of a particular paper size.
00250 // The closest I got was to use OpenPrinter() to get a handle of a printer, then use GetForm() to retrieve
00251 // the dimensions of a paper size given the name of the paper (e.g. "A4").  However MSDN says that neither of
00252 // these functions are supported under Win32s.
00253 
00254 #define IN_TO_MP(n) (MILLIPOINT((double(IN_MP_VAL)*n)+0.5))
00255 #define MM_TO_MP(n) (MILLIPOINT((double(MM_MP_VAL)*n)+0.5))
00256 
00257 //#define wxPAPER_LISTEND (wxPAPER_LAST+1)
00258 #define wxPAPER_LISTEND ((UINT32)(-1))
00259 
00260 struct PaperSizesType
00261 {
00262     UINT32      ID;
00263     MILLIPOINT  Width;
00264     MILLIPOINT  Height;
00265 } pPaperSizes[] = 
00266 {
00267     { wxPAPER_LETTER,       IN_TO_MP(8.5),      IN_TO_MP(11)    },  // Letter 8 1/2 x 11 in               
00268     { wxPAPER_LETTERSMALL,  IN_TO_MP(8.5),      IN_TO_MP(11)    },  // Letter Small 8 1/2 x 11 in         
00269     { wxPAPER_TABLOID,      IN_TO_MP(11),       IN_TO_MP(17)    },  // Tabloid 11 x 17 in                 
00270     { wxPAPER_LEDGER,       IN_TO_MP(17),       IN_TO_MP(11)    },  // Ledger 17 x 11 in                  
00271     { wxPAPER_LEGAL,        IN_TO_MP(8.5),      IN_TO_MP(14)    },  // Legal 8 1/2 x 14 in                
00272     { wxPAPER_STATEMENT,    IN_TO_MP(5.5),      IN_TO_MP(8.5)   },  // Statement 5 1/2 x 8 1/2 in         
00273     { wxPAPER_EXECUTIVE,    IN_TO_MP(7.25),     IN_TO_MP(10.5)  },  // Executive 7 1/4 x 10 1/2 in        
00274 
00275     { wxPAPER_A3,           MM_TO_MP(297),      MM_TO_MP(420)   },  // A3 297 x 420 mm                    
00276     { wxPAPER_A4,           MM_TO_MP(210),      MM_TO_MP(297)   },  // A4 210 x 297 mm                    
00277     { wxPAPER_A4SMALL,      MM_TO_MP(210),      MM_TO_MP(297)   },  // A4 Small 210 x 297 mm              
00278     { wxPAPER_A5,           MM_TO_MP(148),      MM_TO_MP(210)   },  // A5 148 x 210 mm                    
00279     { wxPAPER_B4,           MM_TO_MP(250),      MM_TO_MP(354)   },  // B4 250 x 354                       
00280     { wxPAPER_B5,           MM_TO_MP(182),      MM_TO_MP(257)   },  // B5 182 x 257 mm                    
00281 
00282     { wxPAPER_FOLIO,        IN_TO_MP(8.5),      IN_TO_MP(13)    },  // Folio 8 1/2 x 13 in                
00283     { wxPAPER_QUARTO,       MM_TO_MP(215),      MM_TO_MP(275)   },  // Quarto 215 x 275 mm                
00284     { wxPAPER_10X14,        IN_TO_MP(10),       IN_TO_MP(14)    },  // 10x14 in                           
00285     { wxPAPER_11X17,        IN_TO_MP(11),       IN_TO_MP(17)    },  // 11x17 in                           
00286     { wxPAPER_NOTE,         IN_TO_MP(8.5),      IN_TO_MP(11)    },  // Note 8 1/2 x 11 in                 
00287 
00288     { wxPAPER_ENV_9,        IN_TO_MP(3.875),    IN_TO_MP(8.875) },  // Envelope #9 3 7/8 x 8 7/8 in
00289     { wxPAPER_ENV_10,       IN_TO_MP(4.125),    IN_TO_MP(9.5)   },  // Envelope #10 4 1/8 x 9 1/2 in        
00290     { wxPAPER_ENV_11,       IN_TO_MP(4.5),      IN_TO_MP(10.375)},  // Envelope #11 4 1/2 x 10 3/8 in       
00291     { wxPAPER_ENV_12,       IN_TO_MP(4.75),     IN_TO_MP(11)    },  // Envelope #12 4 3/4 x 11 in          
00292     { wxPAPER_ENV_14,       IN_TO_MP(5),        IN_TO_MP(11.5)  },  // Envelope #14 5 x 11 1/2 in           
00293 
00294     { wxPAPER_CSHEET,       IN_TO_MP(17),       IN_TO_MP(22)    },  // C size sheet 17 x 22 in
00295     { wxPAPER_DSHEET,       IN_TO_MP(22),       IN_TO_MP(34)    },  // D size sheet 22 x 34 in
00296     { wxPAPER_ESHEET,       IN_TO_MP(34),       IN_TO_MP(44)    },  // E size sheet 34 x 44 in
00297 
00298     { wxPAPER_ENV_DL,       MM_TO_MP(110),      MM_TO_MP(220)   },  // Envelope DL 110 x 220mm            
00299     { wxPAPER_ENV_C5,       MM_TO_MP(162),      MM_TO_MP(229)   },  // Envelope C5 162 x 229 mm           
00300     { wxPAPER_ENV_C3,       MM_TO_MP(324),      MM_TO_MP(458)   },  // Envelope C3  324 x 458 mm          
00301     { wxPAPER_ENV_C4,       MM_TO_MP(229),      MM_TO_MP(324)   },  // Envelope C4  229 x 324 mm          
00302     { wxPAPER_ENV_C6,       MM_TO_MP(114),      MM_TO_MP(162)   },  // Envelope C6  114 x 162 mm          
00303     { wxPAPER_ENV_C65,      MM_TO_MP(114),      MM_TO_MP(229)   },  // Envelope C65 114 x 229 mm          
00304 
00305     { wxPAPER_ENV_B4,       MM_TO_MP(250),      MM_TO_MP(353)   },  // Envelope B4  250 x 353 mm          
00306     { wxPAPER_ENV_B5,       MM_TO_MP(176),      MM_TO_MP(250)   },  // Envelope B5  176 x 250 mm          
00307     { wxPAPER_ENV_B6,       MM_TO_MP(176),      MM_TO_MP(125)   },  // Envelope B6  176 x 125 mm          
00308     { wxPAPER_ENV_ITALY,    MM_TO_MP(110),      MM_TO_MP(230)   },  // Envelope 110 x 230 mm              
00309 
00310     { wxPAPER_ENV_MONARCH,  IN_TO_MP(3.875),    IN_TO_MP(7.5)   },  // Envelope Monarch 3.875 x 7.5 in    
00311     { wxPAPER_ENV_PERSONAL, IN_TO_MP(3.625),    IN_TO_MP(6.5)   },  // 6 3/4 Envelope 3 5/8 x 6 1/2 in    
00312 
00313     { wxPAPER_FANFOLD_US,           IN_TO_MP(14.875),   IN_TO_MP(11)    },  // US Std Fanfold 14 7/8 x 11 in      
00314     { wxPAPER_FANFOLD_STD_GERMAN,   IN_TO_MP(8.5),      IN_TO_MP(12)    },  // German Std Fanfold 8 1/2 x 12 in   
00315     { wxPAPER_FANFOLD_LGL_GERMAN,   IN_TO_MP(8.5),      IN_TO_MP(13)    },  // German Legal Fanfold 8 1/2 x 13 in 
00316 
00317 #if(WINVER >= 0x0400)
00318     { wxPAPER_ISO_B4,               MM_TO_MP(250),      MM_TO_MP(353)   },  // B4 (ISO) 250 x 353 mm
00319     { wxPAPER_JAPANESE_POSTCARD,    MM_TO_MP(100),      MM_TO_MP(148)   },  // Japanese Postcard 100 x 148 mm     
00320     { wxPAPER_9X11,                 IN_TO_MP(9),        IN_TO_MP(11)    },  // 9 x 11 in                          
00321     { wxPAPER_10X11,                IN_TO_MP(10),       IN_TO_MP(11)    },  // 10 x 11 in                         
00322     { wxPAPER_15X11,                IN_TO_MP(15),       IN_TO_MP(11)    },  // 15 x 11 in                         
00323     { wxPAPER_ENV_INVITE,           MM_TO_MP(220),      MM_TO_MP(220)   },  // Envelope Invite 220 x 220 mm       
00324 //  { wxPAPER_RESERVED_48,          MM_TO_MP(250),      MM_TO_MP(353)   },  // RESERVED--DO NOT USE               
00325 //  { wxPAPER_RESERVED_49,          MM_TO_MP(250),      MM_TO_MP(353)   },  // RESERVED--DO NOT USE               
00326     { wxPAPER_LETTER_EXTRA,         IN_TO_MP(9.5),      IN_TO_MP(12)    },  // Letter Extra 9 \275 x 12 in        
00327     { wxPAPER_LEGAL_EXTRA,          IN_TO_MP(9.5),      IN_TO_MP(15)    },  // Legal Extra 9 \275 x 15 in         
00328     { wxPAPER_TABLOID_EXTRA,        IN_TO_MP(11.69),    IN_TO_MP(18)    },  // Tabloid Extra 11.69 x 18 in        
00329     { wxPAPER_A4_EXTRA,             IN_TO_MP(9.27),     IN_TO_MP(12.69) },  // A4 Extra 9.27 x 12.69 in           
00330     { wxPAPER_LETTER_TRANSVERSE,    IN_TO_MP(8.5),      IN_TO_MP(11)    },  // Letter Transverse 8 \275 x 11 in   
00331     { wxPAPER_A4_TRANSVERSE,        MM_TO_MP(210),      MM_TO_MP(297)   },  // A4 Transverse 210 x 297 mm         
00332     { wxPAPER_LETTER_EXTRA_TRANSVERSE,IN_TO_MP(9.5),    IN_TO_MP(12)    },  // Letter Extra Transverse 9\275 x 12 in 
00333     { wxPAPER_A_PLUS,               MM_TO_MP(227),      MM_TO_MP(356)   },  // SuperA/SuperA/A4 227 x 356 mm      
00334     { wxPAPER_B_PLUS,               MM_TO_MP(305),      MM_TO_MP(487)   },  // SuperB/SuperB/A3 305 x 487 mm      
00335     { wxPAPER_LETTER_PLUS,          IN_TO_MP(8.5),      IN_TO_MP(12.69) },  // Letter Plus 8.5 x 12.69 in         
00336     { wxPAPER_A4_PLUS,              MM_TO_MP(210),      MM_TO_MP(330)   },  // A4 Plus 210 x 330 mm               
00337     { wxPAPER_A5_TRANSVERSE,        MM_TO_MP(148),      MM_TO_MP(210)   },  // A5 Transverse 148 x 210 mm         
00338     { wxPAPER_B5_TRANSVERSE,        MM_TO_MP(182),      MM_TO_MP(257)   },  // B5 (JIS) Transverse 182 x 257 mm   
00339     { wxPAPER_A3_EXTRA,             MM_TO_MP(322),      MM_TO_MP(445)   },  // A3 Extra 322 x 445 mm              
00340     { wxPAPER_A5_EXTRA,             MM_TO_MP(174),      MM_TO_MP(235)   },  // A5 Extra 174 x 235 mm              
00341     { wxPAPER_B5_EXTRA,             MM_TO_MP(201),      MM_TO_MP(276)   },  // B5 (ISO) Extra 201 x 276 mm        
00342     { wxPAPER_A2,                   MM_TO_MP(420),      MM_TO_MP(594)   },  // A2 420 x 594 mm                    
00343     { wxPAPER_A3_TRANSVERSE,        MM_TO_MP(297),      MM_TO_MP(420)   },  // A3 Transverse 297 x 420 mm         
00344     { wxPAPER_A3_EXTRA_TRANSVERSE,  MM_TO_MP(322),      MM_TO_MP(445)   },  // A3 Extra Transverse 322 x 445 mm   
00345 #endif 
00346 
00347     { wxPAPER_LISTEND,0,0 }
00348 };
00349 
00350 //---------------------------------
00351 void Beep();
00352 //---------------------------------
00353 
00354 //  WEBSTER-ranbirr-12/11/96
00355 #ifndef WEBSTER
00356 
00357 
00358 /********************************************************************************************
00359 
00360 >   CCPrintDialog::CCPrintDialog(Document* pDoc,BOOL PrintSetUpOnly = FALSE)
00361 
00362     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00363     Created:    29/3/95
00364     Inputs:     pDoc           = ptr to the document this print dialog is associated with
00365                 PrintSetUpOnly = TRUE if you only want the print setup dialog only
00366     Purpose:    Creates a camelot print dialog, based on CPrintDialog
00367     SeeAlso:    CCPrintInfo
00368 
00369 ********************************************************************************************/
00370 
00371 CCPrintDialog::CCPrintDialog(CCPrintInfo * pDialogData, Document* pDoc,BOOL PrintSetUpOnly) : wxPrintDialog(NULL, pDialogData)
00372 {
00373     pDocument = pDoc;
00374     PrintPrefsOpen      = FALSE;
00375     PrintPrefsChanged   = FALSE;
00376 }
00377 
00378 
00379 /********************************************************************************************
00380 
00381 >   CCPrintDialog::~CCPrintDialog()
00382 
00383     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00384     Created:    29/3/95
00385     Inputs:     -
00386     Purpose:    Default destructor
00387                 This deletes the member DC using ::DeleteDC() as instructed by the help on 
00388                 CPrintDialog::GetPrinterDC() (only if the DC is not NULL of course)
00389 
00390                 Why CPrintDialog doesn't have a destructor to do this is a mystery.  I think it relies
00391                 on you using CPrintInfo who's destructor DOES delete the DC if need be.
00392 
00393     SeeAlso:    CCPrintInfo
00394 
00395 ********************************************************************************************/
00396 
00397 CCPrintDialog::~CCPrintDialog()
00398 {
00399 }
00400 
00401 /********************************************************************************************
00402 
00403 >   PrintControl* CCPrintDialog::GetPrintControl()
00404 
00405     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00406     Created:    5/4/95
00407     Inputs:     -
00408     Returns:    Ptr to the print control
00409     Purpose:    Returns the ptr to the print control attached to the doc associated with this dialog
00410     SeeAlso:    CCPrintInfo
00411 
00412 ********************************************************************************************/
00413 
00414 PrintControl* CCPrintDialog::GetPrintControl()
00415 {
00416     PrintControl* pPrCtrl = NULL;
00417 
00418     if (pDocument != NULL)
00419     {
00420         PrintComponent* pComp = (PrintComponent*)pDocument->GetDocComponent(CC_RUNTIME_CLASS(PrintComponent));
00421 
00422         if (pComp != NULL)
00423             pPrCtrl = pComp->GetPrintControl();
00424     }
00425 
00426     ERROR3IF(pPrCtrl == NULL,"Unable to find the print control object");
00427 
00428     return pPrCtrl;
00429 }
00430 
00431 // Here's how we might one-day run help
00432 
00433 // Yes, run the help system and don't process this message any more.  As we don't
00434 // have any C++ object associated with the Print Problems page we must use the
00435 // bodgey raw help function here.
00436 // _HelpUser(TEXT("PrintProblems"));
00437 // _HelpUser(TEXT("CCPrintSetupDialog"));
00438 
00439 #ifndef EXCLUDE_FROM_XARALX
00440 
00441 /********************************************************************************************
00442 
00443 >   INT32 CCPrintDialog::DoModal()
00444 
00445     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00446     Created:    30/3/95
00447     Inputs:     -
00448     Returns:    See CPrintDialog::DoModal() for return values
00449     Purpose:    This calls CPrintDialog::DoModal() and returns the value that it returns
00450 
00451                 This func allows us to detect when the print dialog has been displayed, and which
00452                 button the user clicked on to close it (i.e. OK or Cancel)
00453 
00454     SeeAlso:    CPrintDialog::DoModal
00455 
00456 ********************************************************************************************/
00457 
00458 INT32 CCPrintDialog::DoModal()
00459 {
00460     ERROR2IF(pDocument == NULL,IDCANCEL,"NULL doc ptr");
00461 
00462     ERROR3IF(pCurrentCCPrintDialog != NULL,"pCurrentCCPrintDialog is not NULL");
00463     pCurrentCCPrintDialog = this;
00464 
00465     // Get a copy of the print control in the associated document
00466     PrintControl* pPrCtrl = GetPrintControl();
00467     ERROR2IF(pPrCtrl == NULL,IDCANCEL,"Unable to find the print control");
00468     LocalPrintControl = *pPrCtrl;
00469 
00470     // Inform the user if we have switched to using the default printer on the system
00471     InformResetToDefaultPrinter(FALSE);
00472 
00473     // Initialise the custom dlg template
00474     ERROR2IF(!InitCustomDlg(),IDCANCEL,"Unable to init the print dlg with our custom template");
00475 
00476     // Update our details about this printer
00477     UpdatePrinterSettings(FALSE);
00478 
00479     // Set the print control to print the selected spread
00480     // Do this after UpdatePrinterSettings() to make sure it uses the right values!
00481     LocalPrintControl.SetUp(Document::GetSelectedSpread());
00482 
00483     // Display the dlg to the user, and return the result
00484     BOOL ok = FALSE;
00485     BOOL Reopen = FALSE;
00486     do
00487     {
00488         // If we are reopening the main print dlg, update the printer settings first
00489         // (NB: This should only happen in Win3.1 after the print setup dlg has been used. 
00490         //  See CCPrintDialog::OnPrintSetup())
00491         if (Reopen)
00492             UpdatePrinterSettings();
00493 
00494         // Keep Control Helper system informed
00495         ControlHelper::InformModalDialogOpened();
00496 
00497         // Open the main print dlg (uses ::PrintDlg() in the depths of MFC)
00498         ok = CPrintDialog::DoModal();
00499         FixFPControlRegister();
00500 
00501         // Keep Control Helper system informed
00502         ControlHelper::InformModalDialogClosed();
00503 
00504         Reopen = ReopenMainDlg;     // Do we need to reopen the main print dlg?
00505         ReopenMainDlg = FALSE;      // Make sure this flag is cleared, or we'll be here all day
00506 
00507     } while (Reopen);
00508 
00509     // If we are to ignore the printer data (because the selected printer has been deleted, renamed, etc)
00510     // then we must reset the global memory handles that hold the data, as the settings they contain
00511     // no longer refer to a printer known by the host system
00512     if (IgnorePrintData())
00513     {
00514         FreeGlobalHandle(&m_pd.hDevMode);
00515         FreeGlobalHandle(&m_pd.hDevNames);
00516         ResetIgnorePrintData();
00517     }
00518 
00519     ERROR3IF(pCurrentCCPrintDialog == NULL,"pCurrentCCPrintDialog is NULL");
00520     pCurrentCCPrintDialog = NULL;
00521 
00522     return ok;
00523 }
00524 #endif
00525 
00526 //-------------------
00527 
00528 /********************************************************************************************
00529 
00530 >   static BOOL CCPrintDialog::GetPrinterSettings(BOOL RedrawPrintBorders = TRUE)
00531 
00532     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00533     Created:    5/4/95
00534     Inputs:     RedrawPrintBorders if a force redraw should be issued (Defaults to TRUE)
00535     Returns:    TRUE if OK, FALSE otherwise
00536     Purpose:    This function ensures that we have a valid set of printer settings.
00537 
00538                 If this is the first time this function has been called, it uses a CCPrintDialog
00539                 to get the default settings from the printer driver.
00540 
00541                 If we already have a set of valid settings, this func does nothing
00542 
00543     SeeAlso:    -
00544 
00545 ********************************************************************************************/
00546 
00547 BOOL CCPrintDialog::GetPrinterSettings(BOOL RedrawPrintBorders)
00548 {
00549     if (!GotPrinterSettings)
00550     {
00551         Progress Hourglass(_R(IDS_UPDATE_PRINTER_SETTINGS),-1,FALSE);
00552         Hourglass.Update();
00553 
00554         CCPrintInfo * pPrintInfo = CCPrintInfo::GetCurrent();
00555         BOOL Local=FALSE;
00556         if (!pPrintInfo)
00557         {
00558             pPrintInfo = new CCPrintInfo(Document::GetSelected(), NULL);
00559             ERROR2IF(!pPrintInfo, FALSE, "Cannot get print info");
00560             Local = TRUE;
00561         }
00562         
00563         //CCPrintDialog PrintDlg(pPrintInfo);       // Use CCPrintDialog to get hold of printer's DEVMODE settings
00564 
00565         pPrintInfo->UpdatePrinterSettings(RedrawPrintBorders);
00566 
00567         if (Local)
00568             delete pPrintInfo;
00569 
00570     }
00571 
00572     return (GotPrinterSettings);
00573 }
00574 
00575 /********************************************************************************************
00576 
00577 >   static void CCPrintDialog::ResetToDefaultPrinter()
00578 
00579     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00580     Created:    8/2/96
00581     Inputs:     -
00582     Returns:    -
00583     Purpose:    Use this function to tell the printing system that the printer data has been reset
00584                 so that it will use the default printer next time you print.
00585 
00586                 If there are any print-related dialogs open, they will be closed.
00587 
00588                 If a dialog is closed, the function will display a warning to the user.
00589 
00590                 If a dialog is not closed, a flag is set so that the warning will be displayed when 
00591                 the user next tries to print something.
00592 
00593     SeeAlso:    CCamApp::ResetToDefaultPrinter()
00594 
00595 ********************************************************************************************/
00596 
00597 void CCPrintDialog::ResetToDefaultPrinter()
00598 {
00599     if (GotPrinterSettings)
00600     {
00601         GotPrinterSettings = FALSE;         // We need new printer settings
00602         InformPrinterReset = TRUE;          // We need to inform the use about what's happening
00603 
00604         // Close any print dlgs that may be open
00605         ClosePrintDialogs();
00606 
00607         // Get the default printer settings
00608         GetPrinterSettings();
00609     }
00610 }
00611 
00612 /********************************************************************************************
00613 
00614 >   static void CCPrintDialog::ClosePrintDialogs()
00615 
00616     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00617     Created:    8/2/96
00618     Inputs:     -
00619     Returns:    -
00620     Purpose:    Closes any print-related dlgs that may be open.
00621                 If any dlgs are closed, and it is due to resetting to the default printer,
00622                 a warning will be issued to the user informing them of this fact.
00623 
00624     SeeAlso:    static BOOL ResetToDefaultPrinter()
00625 
00626 ********************************************************************************************/
00627 
00628 void CCPrintDialog::ClosePrintDialogs()
00629 {
00630     // Close the print prefs tabbed dlg
00631     PrintPrefsDlg::CloseCurrentDlg();
00632 
00633 #ifndef EXCLUDE_FROM_XARALX
00634     // Close the print setup dlg that's opened from the main print dlg
00635     if (pDlgSetup != NULL)
00636     {
00637         IgnorePrntData = TRUE;  // We are forcing the closure of the print dlgs
00638         // Inform the user if we have switched to using the default printer on the system
00639         // before closing dialog
00640         InformResetToDefaultPrinter(TRUE);
00641         delete pDlgSetup;
00642         pDlgSetup = NULL;
00643     }
00644 
00645     // Close the main print dlg
00646     if (pCurrentCCPrintDialog != NULL)
00647     {
00648         IgnorePrntData = TRUE;  // We are forcing the closure of the print dlgs
00649         // Inform the user if we have switched to using the default printer on the system
00650         // before closing dialog
00651         InformResetToDefaultPrinter(TRUE);
00652         delete pCurrentCCPrintDialog;
00653         pCurrentCCPrintDialog = NULL;
00654     }
00655 #endif
00656 
00657 }
00658 
00659 #endif
00660 
00661 /********************************************************************************************
00662 
00663 >   static void CCPrintDialog::InformResetToDefaultPrinter(BOOL ClosingDlgs)
00664 
00665     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00666     Created:    8/2/96
00667     Inputs:     ClosingDlgs - TRUE if the caller will also close any print dlgs too.
00668     Returns:    -
00669     Purpose:    Displays a warning to the user saying that we have switched to the default printer.
00670 
00671                 It only does this if the flag InformPrinterReset is TRUE.
00672                 
00673                 After displaying the warning, InformPrinterReset is set to FALSE, so you can call this
00674                 func as often as you like - it will only get displayed once until the next time we
00675                 switch to the default printer.
00676 
00677                 If this is called just before closing any print dlgs, call with ClosingDlgs=TRUE.
00678                 This will display a slightly different warning explaining the dlgs will be closed.
00679 
00680     SeeAlso:    static BOOL ResetToDefaultPrinter()
00681 
00682 ********************************************************************************************/
00683 
00684 void CCPrintDialog::InformResetToDefaultPrinter(BOOL ClosingDlgs)
00685 {
00686     if (InformPrinterReset)
00687     {
00688         if (ClosingDlgs)
00689             InformWarning(_R(IDS_RESET_PRINTER_REOPEN));
00690         else
00691             InformWarning(_R(IDS_RESET_PRINTER));
00692 
00693         InformPrinterReset = FALSE;
00694     }
00695 }
00696 
00697 #ifndef EXCLUDE_FROM_XARALX
00698 
00699 /********************************************************************************************
00700 
00701 >   static void CCPrintDialog::GetSelectedPrinterName(LPTSTR pName,INT32 BufferSize)
00702 
00703     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00704     Created:    15/2/96
00705     Inputs:     pName = ptr to buffer to place name in
00706                 BufferSize = size of buffer pointed to by BufferSize
00707     Returns:    -
00708     Purpose:    This will return what is considered to be the name of the app's selected printer
00709 
00710                 If the main print dlg or the print setup dlg (opened via the File menu) are open,
00711                 the name is taken from them.
00712 
00713                 Otherwise, the app's cached printer data is used, and this is gained vai CCamApp::GetDevNames()
00714 
00715                 If no printer is found, pName == "" (i.e. pName[0] == 0).
00716 
00717     SeeAlso:    static BOOL ResetToDefaultPrinter()
00718 
00719 ********************************************************************************************/
00720 
00721 void CCPrintDialog::GetSelectedPrinterName(LPTSTR pName,INT32 BufferSize)
00722 {
00723     // Enough of these silly values
00724     ERROR3IF(pName == NULL || BufferSize < 1,"How about some senisble input params eh?");
00725     if (pName == NULL || BufferSize < 1)
00726         return;
00727 
00728     CCamApp *pCamApp = (CCamApp *)AfxGetApp();
00729     
00730     // Default to the app's DEVMODE structure
00731     HGLOBAL hDevNames = NULL;
00732     if(pCamApp != NULL)
00733         hDevNames = pCamApp->GetDevNames();
00734 
00735     // If we have a main print dlg up, look at the selected printer within the dlg
00736     if (pCurrentCCPrintDialog != NULL)
00737         hDevNames = pCurrentCCPrintDialog->m_pd.hDevNames;
00738 
00739     // If we have the print setup dlg open from the file menu, look at the selected printer within it
00740     if (pCamApp != NULL && pCamApp->GetFilePrintSetupDlg() != NULL)
00741         hDevNames = pCamApp->GetFilePrintSetupDlg()->m_pd.hDevNames;
00742 
00743     // NULL terminate now, just in case things go wrong
00744     pName[0] = 0;
00745 
00746     if (hDevNames != NULL)
00747     {
00748         // Get a ptr to the memory block defined by hDevNames
00749         DEVNAMES* pDevNames = (DEVNAMES*)::GlobalLock(hDevNames);
00750         if (pDevNames != NULL)
00751         {
00752             // Copy the name from the DEVNAMES field into the buffer provided
00753             camStrncpy(pName,LPTSTR(pDevNames) + pDevNames->wDeviceOffset,BufferSize);
00754             ::GlobalUnlock(hDevNames);
00755         }
00756     }
00757 }
00758 
00759 #endif
00760 
00761 /********************************************************************************************
00762 
00763 >   BOOL CCPrintInfo::UpdatePrinterSettings(BOOL RedrawPrintBorders = TRUE)
00764 
00765     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00766     Created:    14/4/95
00767     Inputs:     RedrawPrintBorders = TRUE if you want any visible print borders redrawing
00768     Returns:    TRUE if ok, FALSE otherwise
00769     Purpose:    Updates the static members that represent the current printer settings Camelot
00770                 is interested in, such a paper size, orientation, etc.
00771                 It uses the DEVMODE structure returned by GetDevMode(), plus member funcs for
00772                 driver, device and port names.
00773 
00774                 This sets the static member GotPrinterSettings to TRUE if successful
00775 
00776     SeeAlso:    static BOOL UpdatePrinterSettings()
00777 
00778 ********************************************************************************************/
00779 
00780 BOOL CCPrintInfo::UpdatePrinterSettings(BOOL RedrawPrintBorders)
00781 {
00782     wxDC * dc = MakeDCFromPrintData(&GetPrintData());
00783     BOOL ret=CCPrintDialog::UpdatePrinterSettings(m_pNativePrintData,dc,pDocument,RedrawPrintBorders);
00784     delete dc;
00785     return ret;
00786 }
00787 
00788 /********************************************************************************************
00789 
00790 >   static BOOL CCPrintDialog::UpdatePrinterSettings(wxPrintData * pPrintData, wxDC * pDC, Document* pDocument, BOOL RedrawPrintBorders)
00791 
00792     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00793     Created:    5/4/95
00794     Inputs:     pDevMode = ptr to a DEVMODE used to extract printer settings from
00795                 hdc      = printer device context (can be NULL)
00796                 pDocument= ptr to associated doc (NULL means use current doc)
00797                 RedrawPrintBorders = TRUE if you want any visible print borders redrawing
00798     Returns:    TRUE if ok, FALSE otherwise
00799     Purpose:    Updates the static members that represent the current printer settings Camelot
00800                 is interested in, such a paper size, orientation, etc.
00801 
00802                 This sets the static member GotPrinterSettings to TRUE if successful
00803 
00804                 It will also redraw all views in the given doc that are showing print borders
00805 
00806     SeeAlso:    -
00807 
00808 ********************************************************************************************/
00809 
00810 BOOL CCPrintDialog::UpdatePrinterSettings(wxPrintData * pPrintData, wxDC * pDC, Document* pDocument, BOOL RedrawPrintBorders)
00811 {
00812     if (pPrintData == NULL)
00813     {
00814         TRACE( _T("CCPrintDialog::UpdatePrinterSettings() - pPrintData is NULL"));
00815         GotPrinterSettings = FALSE;
00816         return FALSE;
00817     }
00818 
00819     BOOL InitPaperSize = FALSE;
00820 
00821     // First, look-up the paper size if we can, as this is more accurate than using the DC to get the
00822     // physical width & height plus X & Y dpi
00823     if (!InitPaperSize)
00824     {
00825         // The dmPaperSize field has been initialised, so look up the paper dimensions
00826         // if this value is not 0
00827         // Note: I discovered a page in MSDN on 7/2/96 that states that a paper size value
00828         // of wxPAPER_USER means "get size from dmPaperWidth & dmPaperLength"
00829         if (pPrintData->GetPaperId() != wxPAPER_NONE)
00830             InitPaperSize = LookUpPaperSize(pPrintData->GetPaperId(),&PrPaperSize);
00831     }
00832 
00833     // Use the DC to find out the paper size
00834     if (!InitPaperSize && pDC)
00835     {
00836         double xdpi = pDC->GetPPI().GetWidth();     // Get X & Y dots (pixels) per inch
00837         double ydpi = pDC->GetPPI().GetHeight();
00838 
00839         ERROR3IF(xdpi == 0,"(papersize) xdpi == 0");
00840         ERROR3IF(ydpi == 0,"(papersize) ydpi == 0");
00841 
00842         // Find the width and height in inches
00843         double width  =double(pDC->GetSize().GetWidth())  / xdpi; // 2479.0 
00844         double height =double(pDC->GetSize().GetHeight()) / ydpi; // 3504.0 
00845 
00846         PrPaperSize = wxSize(IN_TO_MP(width), IN_TO_MP(height));
00847         InitPaperSize = TRUE;
00848     }
00849 
00850     if (!InitPaperSize)
00851     {
00852         // If we still haven't managed to get the paper size, then error in debug builds
00853         // and set the paper size to a sensible default
00854         ERROR3("Unable to extract paper size");
00855         LookUpPaperSize(wxPAPER_A4,&PrPaperSize);
00856     }
00857 
00858     // ---------------------------------
00859     // Extract paper orientation
00860     //
00861 
00862     // Has the orientation field been initialised?
00863     PrPortrait = (pPrintData->GetOrientation() == wxPORTRAIT);
00864     
00865     // ---------------------------------
00866     // Extract print quality (i.e. resolution in dots per inch)
00867     //
00868     // It turns out that the printer quality setting isn't always set in the DEVMODE structure. If this is the
00869     // case, the hdc param is used to extract the device x & y resolution
00870 
00871     // Set PrResolution to a value that means "yet to find printer resolution"
00872     PrResolution = -1;
00873 
00874     // Use the DC to find the resolution, in preference to using the DEVMODE structure
00875     // (Overall DPI is the smallest between the X and Y resolution of the device)
00876     if (PrResolution <= 0 && pDC)
00877     {
00878         PrResolutionX = pDC->GetPPI().GetWidth();
00879         PrResolutionY = pDC->GetPPI().GetHeight();
00880 
00881         PrResolution = min(PrResolutionX,PrResolutionY);
00882     }
00883 
00884     // If we failed to get the printer resolution using the DC, try the DEVMODE structure
00885     if (PrResolution <= 0)
00886     {
00887         PrResolution = pPrintData->GetQuality();
00888         PrResolutionX = PrResolutionY = PrResolution;   // The X & Y res are the same
00889     }
00890 
00891     // If all else fails, fall back on a default value
00892     if (PrResolution <= 0)
00893     {
00894         ERROR3IF(pDC == NULL,"hdc is NULL. Try supplying one in order to get printer resolution.");
00895         ERROR3("Unable to find the printer resolution");
00896         PrResolution = 300;
00897         PrResolutionX = PrResolutionY = PrResolution;   // The X & Y res are the same
00898     }
00899 
00900     // ---------------------------------
00901     // Extract the margins of the printable area on the paper
00902     // (we can only do this via the DC)
00903 
00904 #ifndef EXCLUDE_FROM_XARALX
00905     if (hdc != NULL)
00906     {
00907         // Find out the various printer bits and bobs, all measured in pixels
00908         double left,top,width,height;
00909 
00910         if (IsWindows31()) //IsWin32s() && !IsWin32c())
00911         {
00912             POINT offsets,size;
00913             ::Escape(hdc,GETPRINTINGOFFSET,NULL,NULL,&offsets);
00914             ::Escape(hdc,GETPHYSPAGESIZE,NULL,NULL,&size);
00915 
00916             left    = double(offsets.x); // 54.0
00917             top     = double(offsets.y); // 50.0
00918             width   = double(size.x);    // 2479.0
00919             height  = double(size.y);    // 3504.0
00920 
00921             //TRACE( _T("GETPRINTINGOFFSET.x = %ld\n"),offsets.x);
00922             //TRACE( _T("GETPRINTINGOFFSET.y = %ld\n"),offsets.y);
00923             //TRACE( _T("GETPHYSPAGESIZE.x   = %ld\n"),size.x);
00924             //TRACE( _T("GETPHYSPAGESIZE.y   = %ld\n"),size.y);
00925             //TRACE( _T("\n"));
00926         }
00927         else
00928         {
00929             left    = double(::GetDeviceCaps(hdc,PHYSICALOFFSETX)); // left margin      // 54.0  
00930             top     = double(::GetDeviceCaps(hdc,PHYSICALOFFSETY)); // top margin       // 50.0  
00931             width   = double(::GetDeviceCaps(hdc,PHYSICALWIDTH));   // width of paper   // 2479.0
00932             height  = double(::GetDeviceCaps(hdc,PHYSICALHEIGHT));  // height of paper  // 3504.0
00933 
00934             //TRACE( _T("PHYSICALOFFSETX = %ld\n"),INT32(left));
00935             //TRACE( _T("PHYSICALOFFSETY = %ld\n"),INT32(top)); 
00936             //TRACE( _T("PHYSICALWIDTH   = %ld\n"),INT32(width));   
00937             //TRACE( _T("PHYSICALHEIGHT  = %ld\n"),INT32(height));
00938         }
00939 
00940         double hres = double(::GetDeviceCaps(hdc,HORZRES));         // width of printable area              2366.0
00941         double yres = double(::GetDeviceCaps(hdc,VERTRES));         // height of printable area             3404.0
00942         double xdpi = double(::GetDeviceCaps(hdc,LOGPIXELSX));      // Get X & Y dots (pixels) per inch     300.0
00943         double ydpi = double(::GetDeviceCaps(hdc,LOGPIXELSY));      //                                      300.0
00944 
00945         ERROR3IF(xdpi == 0,"xdpi == 0");
00946         ERROR3IF(ydpi == 0,"ydpi == 0");
00947 
00948         //TRACE( _T("HORZRES         = %ld\n"),INT32(hres));            
00949         //TRACE( _T("VERTRES         = %ld\n"),INT32(yres));            
00950         //TRACE( _T("LOGPIXELSX      = %ld\n"),INT32(xdpi));
00951         //TRACE( _T("LOGPIXELSY      = %ld\n"),INT32(ydpi));
00952 
00953         PrLeftMargin    = IN_TO_MP(left / xdpi);
00954         PrTopMargin     = IN_TO_MP(top  / ydpi);
00955         PrRightMargin   = IN_TO_MP((width-hres-left) / xdpi);
00956         PrBottomMargin  = IN_TO_MP((height-yres-top) / ydpi);
00957     }
00958     else
00959 #endif
00960     {
00961         PrLeftMargin    = 0;
00962         PrTopMargin     = 0;
00963         PrRightMargin   = 0;
00964         PrBottomMargin  = 0;
00965     }
00966 
00967     // ---------------------------------
00968     // Is printer a Postscript printer?
00969     //
00970     PrPostscript = pDC->IsKindOf(CLASSINFO(wxPostScriptDC));
00971 
00972 #ifndef EXCLUDE_FROM_XARALX
00973     // ---------------------------------
00974     // Extract the scale factor
00975     //
00976     if (Fields & DM_SCALE)
00977     {
00978         PrScale = pDevMode->dmScale;
00979 
00980         // is the value sensible?
00981         if (PrScale <= 0)
00982         {
00983             ERROR3_PF(("Bad printer scale factor (%d)",PrScale));
00984             PrScale = 100;
00985         }
00986     }
00987     else
00988 #endif
00989     {
00990         // We haven't managed to get the print scale, so error in debug builds
00991         // and set the scale to a sensible default
00992         //ERROR3("Unable to extract print scale from given DEVMODE");
00993         PrScale = 100;
00994     }
00995 
00996     // ---------------------------------
00997     // Extract the printer's ability to do multiple copies.
00998     //
00999     PrMultiCopies = 1; // ((Fields & DM_COPIES) != 0);
01000 
01001     // ---------------------------------
01002     // Final processing on extracted data 
01003     //
01004 
01005     if (!PrPortrait)
01006     {
01007         // If landscape printing, swap the width and height of the paper to which we will print to
01008         PrPaperSize=wxSize(PrPaperSize.GetHeight(),PrPaperSize.GetWidth());
01009     }
01010 
01011     if (PrScale != 100)
01012     {
01013         // If the printer driver is applying a scale factor, scale the real paper size to the apparent 
01014         // size of the paper after scaling
01015 
01016         double w = PrPaperSize.GetWidth();          // w = width of paper
01017         double h = PrPaperSize.GetHeight();         // h = height of paper
01018         double f = 100/double(PrScale);     // f = scale factor applied by printer driver
01019 
01020         PrPaperSize = wxSize(MILLIPOINT((w*f)+0.5), MILLIPOINT((h*f)+0.5));
01021     }
01022 
01023     GotPrinterSettings = TRUE;  // Note that we have a set of valid printer settings now
01024 
01025     // Tell everyone that the print settings have changed
01026     BROADCAST_TO_ALL(PrintMsg(PrintMsg::SETTINGSCHANGED));
01027 
01028     // Update the document's print control to make sure it recalculates scale factors etc, and
01029     // redraw any views that are showing their print borders
01030     if (pDocument == NULL)
01031         pDocument = Document::GetSelected();
01032 
01033     if (pDocument != NULL)
01034     {
01035         PrintControl* pPrCtrl = NULL;
01036         PrintComponent* pComp = (PrintComponent*)pDocument->GetDocComponent(CC_RUNTIME_CLASS(PrintComponent));
01037         if (pComp != NULL)
01038             pPrCtrl = pComp->GetPrintControl();
01039 
01040         if (pPrCtrl != NULL)
01041             pPrCtrl->SetUp(pDocument->GetSelectedSpread());
01042 
01043         if (RedrawPrintBorders)
01044         {
01045             CBitmapCache* pBC = Camelot.GetBitmapCache();
01046             pBC->DeInitialise();                            // Brute force cache clear
01047 
01048             // Redraw all views that are showing their print borders
01049             FRDocViewFunc pFunc = PrintControl::RedrawPrintableArea;
01050             pDocument->ForceRedraw(pFunc);
01051         }
01052     }
01053 
01054     return (TRUE);
01055 }
01056 
01057 
01058 
01059 /********************************************************************************************
01060 
01061 >   static BOOL CCPrintDialog::IsPostscript()
01062 
01063     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01064     Created:    15/6/95
01065     Inputs:     -
01066     Returns:    TRUE means the printer is a Postscript printer, FALSE otherwise
01067     Purpose:    Use this to find out if the printer is a Postscript one or not.
01068     SeeAlso:    -
01069 
01070 ********************************************************************************************/
01071 
01072 BOOL CCPrintDialog::IsPostscript()
01073 {
01074 PORTNOTE("printing", "Make printer always appear to be postscript")
01075 #ifndef EXCLUDE_FROM_XARALX
01076     GetPrinterSettings();
01077     return PrPostscript;
01078 #else
01079     return TRUE;
01080 #endif
01081 }
01082 
01083 
01084 /********************************************************************************************
01085 
01086 >   static BOOL CCPrintDialog::LookUpPaperSize(UINT32 PaperSizeID,wxSize* pPaperSize)
01087 
01088     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01089     Created:    6/4/95
01090     Inputs:     PaperSizeID = ID of the paper, i.e. wxPAPER_?
01091                 pPaperSize  = ptr to place to put dimensions in (defined in MILLIPOINTS)
01092     Returns:    TRUE means found, FALSE otherwise
01093     Purpose:    This looks up the paper size in our table of standard paper sizes, and puts the dimensions
01094                 in pPaperSize.
01095 
01096                 If PaperSizeID > 0, and it's not found, then we're in trouble!
01097 
01098     SeeAlso:    -
01099 
01100 ********************************************************************************************/
01101 
01102 BOOL CCPrintDialog::LookUpPaperSize(UINT32 PaperSizeID,wxSize* pPaperSize)
01103 {
01104     ERROR2IF(pPaperSize == NULL,FALSE,"pPaperSize is NULL");
01105 
01106     for(INT32 i=0;pPaperSizes[i].ID != wxPAPER_LISTEND;i++)
01107     {
01108         if (pPaperSizes[i].ID == PaperSizeID)
01109         {
01110             *pPaperSize = wxSize(pPaperSizes[i].Width, pPaperSizes[i].Height);
01111             return TRUE;
01112         }
01113     }
01114 
01115     ERROR3_PF(("Couldn't find paper size for paper ID %d",PaperSizeID));
01116 
01117     return FALSE;
01118 }
01119 
01120 /********************************************************************************************
01121 
01122 >   static BOOL CCPrintDialog::GetPaperSize(wxSize* pPaperSize, BOOL RedrawPrintBorders = TRUE)
01123 
01124     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01125     Created:    5/4/95
01126     Inputs:     pPaperSize = ptr to a wxSize struct to place the size of the paper into
01127                 RedrawPrintBorders  - True (Default) to force a redraw of docs
01128     Returns:    TRUE means OK, FALSE otherwise
01129     Purpose:    Retrieves the physical size of the printer's paper, in MILLIPOINTS
01130 
01131                 This size takes into account any processing that is done by the printer driver
01132                 independantly of the application.  This processing is in the form of scaling and 
01133                 rotation (for landscape printing).
01134 
01135                 E.g. Say the physical paper is A4 (210mm x 297mm), and the user has set Landscape
01136                 with a scale factor of 50% via the Print Setup... dlg.
01137 
01138                 The resultant paper size will be 594mm x 420mm, i.e. because of the setup of the printer
01139                 it is as if we are printing on a landscape piece of paper twice the size of a landscape
01140                 piece of A4.
01141 
01142     SeeAlso:    -
01143 
01144 ********************************************************************************************/
01145 
01146 BOOL CCPrintDialog::GetPaperSize(wxSize* pPaperSize, BOOL RedrawPrintBorders)
01147 {
01148     ERROR2IF(pPaperSize == NULL,FALSE,"NULL paper size param");
01149 
01150     if (GetPrinterSettings(RedrawPrintBorders))
01151     {
01152         *pPaperSize = PrPaperSize;
01153         return TRUE;
01154     }
01155 
01156     return FALSE;
01157 }
01158 
01159 
01160 /********************************************************************************************
01161 
01162 >   static BOOL CCPrintDialog::GetResolution(INT32* pDPI,INT32* pXDPI = NULL,INT32* pYDPI = NULL)
01163 
01164     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01165     Created:    7/4/95
01166     Inputs:     pDPI  = ptr to where to place overall printer resolution
01167                 pXDPI = ptr to X resolution (can be NULL)
01168                 pYDPI = ptr to Y resolution (can be NULL)
01169     Returns:    TRUE means OK, FALSE otherwise
01170     Purpose:    Retrieves the printer resolution
01171 
01172                 If +ve, *pDPI contains the printer resolution in dots per inch (DPI)
01173 
01174                 If -ve, *pDPI specifies a device-independent print quality setting that can be one of the
01175                 following values:
01176 
01177                         DMRES_HIGH
01178                         DMRES_MEDIUM
01179                         DMRES_LOW
01180                         DMRES_DRAFT
01181 
01182                 *pDPI contains the minimum of the X & Y DPI if these values are deferent.  To find the
01183                 actual X & Y dpi, suppy ptrs in the last two params of this function.
01184     SeeAlso:    -
01185 
01186 ********************************************************************************************/
01187 
01188 BOOL CCPrintDialog::GetResolution(INT32* pDPI,INT32* pXDPI,INT32* pYDPI)
01189 {
01190     ERROR2IF(pDPI == NULL,FALSE,"NULL pDPI given");
01191 
01192     if (GetPrinterSettings())
01193     {
01194         *pDPI = PrResolution;
01195         if (pXDPI != NULL) *pXDPI = PrResolutionX;
01196         if (pYDPI != NULL) *pYDPI = PrResolutionY;
01197         return TRUE;
01198     }
01199 
01200     return FALSE;
01201 }
01202 
01203 /********************************************************************************************
01204 
01205 >   static BOOL CCPrintDialog::GetScale(INT32* pScale)
01206 
01207     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01208     Created:    7/4/95
01209     Inputs:     pScale = ptr to where to place printer scale factor percentage
01210     Returns:    TRUE means OK, FALSE otherwise
01211     Purpose:    Retrieves the printer scale factor percentage
01212 
01213                 E.g. 100 means 100% (no scaling)
01214                       50 means 50%
01215                       etc
01216     SeeAlso:    -
01217 
01218 ********************************************************************************************/
01219 
01220 BOOL CCPrintDialog::GetScale(INT32* pScale)
01221 {
01222     ERROR2IF(pScale == NULL,FALSE,"NULL pScale param");
01223 
01224     if (GetPrinterSettings())
01225     {
01226         *pScale = PrScale;
01227         return TRUE;
01228     }
01229 
01230     return FALSE;
01231 }
01232 
01233 /********************************************************************************************
01234 
01235 >   static BOOL CCPrintDialog::GetPrintableArea(DocRect* pPrintableArea)
01236 
01237     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01238     Created:    1/5/95
01239     Inputs:     pPrintableArea = ptr to the printable area rect
01240     Returns:    TRUE means OK, FALSE otherwise
01241     Purpose:    Retrieves the printable area rect
01242 
01243                 This printable area is relative to a piece of paper that has it's origin (0,0)
01244                 at the bottom left.
01245 
01246     SeeAlso:    -
01247 
01248 ********************************************************************************************/
01249 
01250 BOOL CCPrintDialog::GetPrintableArea(DocRect* pPrintableArea)
01251 {
01252     ERROR2IF(pPrintableArea== NULL,FALSE,"NULL pPrintableArea param");
01253 
01254     if (GetPrinterSettings())
01255     {
01256         pPrintableArea->lo.x = PrLeftMargin;
01257         pPrintableArea->hi.x = PrPaperSize.GetWidth() - PrRightMargin;
01258 
01259         pPrintableArea->lo.y = PrBottomMargin;
01260         pPrintableArea->hi.y = PrPaperSize.GetHeight() - PrTopMargin;
01261 
01262         return TRUE;
01263     }
01264 
01265     return FALSE;
01266 }
01267 
01268 /********************************************************************************************
01269 
01270 >   static BOOL CCPrintDialog::GetPrintMargins(INT32* pLeft = NULL,INT32* pTop = NULL,INT32* pRight = NULL,INT32* pBottom = NULL)
01271 
01272     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01273     Created:    1/5/95
01274     Inputs:     pLeft   = ptr to left margin value
01275                 pTop    = ptr to top margin value
01276                 pRight  = ptr to right margin value
01277                 pBottom = ptr to bottom margin value
01278     Returns:    TRUE means OK, FALSE otherwise
01279     Purpose:    Retrieves the print margins
01280 
01281                 Any of the params can be NULL, to allow selective use.
01282 
01283     SeeAlso:    -
01284 
01285 ********************************************************************************************/
01286 
01287 BOOL CCPrintDialog::GetPrintMargins(INT32* pLeft,INT32* pTop,INT32* pRight,INT32* pBottom)
01288 {
01289     if (GetPrinterSettings())
01290     {
01291         if (pLeft   != NULL) *pLeft     = PrLeftMargin;
01292         if (pTop    != NULL) *pTop      = PrTopMargin;
01293         if (pRight  != NULL) *pRight    = PrRightMargin;
01294         if (pBottom != NULL) *pBottom   = PrBottomMargin;
01295         return TRUE;
01296     }
01297 
01298     return FALSE;
01299 }
01300 
01301 /********************************************************************************************
01302 
01303 >   static BOOL CCPrintDialog::CanMultiCopy(BOOL* pState)
01304 
01305     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01306     Created:    7/4/95
01307     Inputs:     pState = ptr to where to place flag
01308     Returns:    TRUE means OK, FALSE otherwise
01309     Purpose:    Retrieves the printer's capability for printing multiple copies
01310 
01311                 If TRUE is returned, we should only need to print a page once and get the printer to
01312                 do multiple copies, otherwise we'll have to do each copy ourselves.
01313     SeeAlso:    -
01314 
01315 ********************************************************************************************/
01316 
01317 BOOL CCPrintDialog::CanMultiCopy(BOOL* pState)
01318 {
01319     ERROR2IF(pState == NULL,FALSE,"NULL pState param");
01320 
01321     if (GetPrinterSettings())
01322     {
01323         *pState = PrMultiCopies;
01324         return TRUE;
01325     }
01326 
01327     return FALSE;
01328 }
01329 
01330 #ifndef EXCLUDE_FROM_XARALX
01331 
01332 /********************************************************************************************
01333 
01334 >   void CCPrintDialog::GetDetails(PrintControl *TargetPC)
01335 
01336     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01337     Created:    7/8/95
01338     Outputs:    TargetPC will be updated with the current settings from the dialogue
01339 
01340     Purpose:    Gets the settings from the various gadgets in the dlg and puts them in 
01341                 LocalPrintControl.
01342     SeeAlso:    -
01343 
01344 ********************************************************************************************/
01345 
01346 void CCPrintDialog::GetDetails(PrintControl *TargetPC)
01347 {
01348     // The print range controls
01349     if (IsDlgButtonChecked(_R(IDC_ALLOBJECTS)))         TargetPC->SetObjPrintRange(PRINTRANGEOBJ_ALL);
01350     if (IsDlgButtonChecked(_R(IDC_SELECTEDOBJECTS)))    TargetPC->SetObjPrintRange(PRINTRANGEOBJ_SELECTED);
01351 
01352     // The print pages controls (to do with double page spreads)
01353     if (IsDlgButtonChecked(_R(IDC_DPSBOTH)))            TargetPC->SetDPSPrintRange(PRINTRANGEDPS_BOTH);
01354     if (IsDlgButtonChecked(_R(IDC_DPSLEFTPAGES)))       TargetPC->SetDPSPrintRange(PRINTRANGEDPS_LEFTPAGES);
01355     if (IsDlgButtonChecked(_R(IDC_DPSRIGHTPAGES)))      TargetPC->SetDPSPrintRange(PRINTRANGEDPS_RIGHTPAGES);
01356 
01357     // Print to file check box
01358     TargetPC->SetPrintToFile(IsDlgButtonChecked(chx1));
01359 
01360     // Num copies ed field
01361     BOOL TranslatedOK;
01362     UINT32 NumCopies = GetDlgItemInt(edt3,&TranslatedOK,FALSE);
01363     if (!TranslatedOK || NumCopies == 0)
01364         NumCopies = 1;
01365 
01366     TargetPC->SetNumCopies(INT32(NumCopies));
01367 
01368     // Collated check box
01369     TargetPC->SetCollated(IsDlgButtonChecked(chx2));
01370 }
01371 
01372 
01373 
01374 /********************************************************************************************
01375 
01376 >   void CCPrintDialog::OnOK()
01377 
01378     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01379     Created:    7/4/95
01380     Inputs:     -
01381     Returns:    -
01382     Purpose:    This takes the values specified in the dlg, and places them in the local
01383                 print control object.
01384 
01385                 Then it copies this complete local print control into the doc's print control
01386                 object.
01387 
01388                 This is called when the user clicks OK on the main print dialog
01389     SeeAlso:    -
01390 
01391 ********************************************************************************************/
01392 
01393 void CCPrintDialog::OnOK()
01394 {
01395     if (PrintPrefsOpen)
01396     {
01397         Beep();
01398         return;
01399     }
01400 
01401     // Get ptr to document's print control
01402     PrintControl* pPrCtrl = GetPrintControl();
01403     ERROR3IF(pPrCtrl == NULL,"Unable to find the print control");
01404 
01405     // Get the details from the dlg controls
01406     if (pPrCtrl != NULL)
01407     {
01408         // Update the document settings to reflect those just committed in the dialogue
01409         GetDetails(pPrCtrl);
01410 
01411         // And refresh our local print control from the document one we've just updated
01412         // just to make sure that we're in step with all the document options
01413         LocalPrintControl = *pPrCtrl;
01414     }
01415 
01416     #ifdef _DEBUG
01417     if (KeyPress::IsConstrainPressed())
01418     {
01419         PrintLayoutTab::TestPrinting(pPrCtrl);
01420         return;
01421     }
01422     #endif
01423 
01424     // Before we allow the print to proceed, let's just check for total stupidity...
01425     TypesetInfo *TInfo = pPrCtrl->GetTypesetInfo();
01426     if (TInfo->AreSeparating())
01427     {
01428         // Are they trying to print colour seps in Bitmap mode? This is fruitless!
01429         if (pPrCtrl->GetPrintMethod() != PRINTMETHOD_NORMAL)
01430         {
01431             if (InformError(_R(IDE_PRINTSEPSASBMP), _R(IDS_PLATEPROCEED), _R(IDS_CANCEL)) != 1)
01432                 return;
01433         }
01434 
01435         // Are they trying to print a silly number of plates?
01436         DWORD NumPlates = TInfo->GetNumPrintPlates();
01437         if (NumPlates < 1)
01438         {
01439             // No plates to print - don't allow them to print at all
01440             InformError(_R(IDE_NOPLATESTOPRINT), _R(IDS_OK));
01441             return;
01442         }
01443 
01444         if (NumPlates > 6)
01445         {
01446             // There are more than 6 plates set to print - this could be a mistake,
01447             // and it could be a very costly mistake! Check if the user really
01448             // meant to do this.
01449             if (InformError(_R(IDE_MANYPLATESTOPRINT), _R(IDS_PLATEPROCEED), _R(IDS_CANCEL)) != 1)
01450                 return;
01451         }
01452     }
01453 
01454     // Finally, call base class function
01455     CPrintDialog::OnOK();
01456 }
01457 
01458 /********************************************************************************************
01459 
01460 >   void CCPrintDialog::OnCancel()
01461 
01462     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01463     Created:    24/4/95
01464     Inputs:     -
01465     Returns:    -
01466     Purpose:    It copies the original print control into the doc's print control
01467                 object.
01468 
01469                 This is called when the user clicks Cancel on the main print dialog
01470     SeeAlso:    -
01471 
01472 ********************************************************************************************/
01473 
01474 void CCPrintDialog::OnCancel()
01475 {
01476     if (PrintPrefsOpen)
01477     {
01478         Beep();
01479         return;
01480     }
01481 
01482     CPrintDialog::OnCancel();
01483 }   
01484 
01485 /********************************************************************************************
01486 
01487 >   BOOL CCPrintDialog::OnInitDialog()
01488 
01489     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01490     Created:    31/3/95
01491     Inputs:     -
01492     Returns:    TRUE if all ok, FALSE if an error occurs
01493     Purpose:    Called just before the print dlg is displayed.
01494 
01495                 This calls the base class version, then ShowDetails() to reflect the local print
01496                 control in the dialog.
01497 
01498     SeeAlso:    ShowDetails()
01499 
01500 ********************************************************************************************/
01501 
01502 BOOL CCPrintDialog::OnInitDialog()
01503 {
01504     // Call the base class version first
01505     CPrintDialog::OnInitDialog();
01506 
01507     // Set the font in the dialog
01508     if (UnicodeManager::IsDBCSOS())
01509         FontFactory::ApplyFontToWindow(m_hWnd, STOCKFONT_DIALOG);
01510 
01511     return ShowDetails();
01512 }
01513 
01514 /********************************************************************************************
01515 
01516 >   BOOL CCPrintDialog::ShowDetails()
01517 
01518     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01519     Created:    7/4/95
01520     Inputs:     -
01521     Returns:    TRUE if all ok, FALSE if an error occurs
01522     Purpose:    This sets up all the print dlg controls to reflect the current state of printing
01523                 for the associated document.
01524 
01525     SeeAlso:    OnInitDialog(); OnPrintSetup()
01526 
01527 ********************************************************************************************/
01528 
01529 BOOL CCPrintDialog::ShowDetails()
01530 {
01531     // Set the name of the device in the control
01532     String_256 Str = GetDeviceName();
01533     String_256 Ps  = _R(IDS_PRDLGCTL_CAP_POSTSCRIPT); //"Postscript";
01534     String_256 ps  = _R(IDS_PRDLGCTL_SML_POSTSCRIPT); //"postscript";
01535     if (IsPostscript() && (Str.Sub(Ps) == -1) && (Str.Sub(ps) == -1))
01536         Str += String_32(_R(IDS_PRDLGCTL_BRACKET_POSTSCRIPT)); //" (Postscript)";
01537     SetDlgItemText(_R(IDC_PRINTERNAME),Str);
01538 
01539     // The print range controls
01540     PrintRangeObj ObjRange = LocalPrintControl.GetObjPrintRange();
01541     CheckDlgButton(_R(IDC_ALLOBJECTS),      ObjRange == PRINTRANGEOBJ_ALL);
01542     CheckDlgButton(_R(IDC_SELECTEDOBJECTS), ObjRange == PRINTRANGEOBJ_SELECTED);
01543 
01544     SelRange* pSelRange = GetApplication()->FindSelection();
01545     BOOL SelectionPresent= (pSelRange->FindFirst() != NULL);
01546     Enable(grp1,                SelectionPresent);
01547     Enable(_R(IDC_ALLOBJECTS),      SelectionPresent);
01548     Enable(_R(IDC_SELECTEDOBJECTS), SelectionPresent);
01549 
01550     // The print pages controls (to do with double page spreads)
01551     BOOL DPS         = LocalPrintControl.IsDoublePageSpread();
01552     BOOL WholeSpread = LocalPrintControl.IsWholeSpread();
01553     Enable(_R(IDC_GROUP_PRINTPAGES),DPS && !WholeSpread);
01554     Enable(_R(IDC_DPSBOTH),         DPS && !WholeSpread);
01555     Enable(_R(IDC_DPSLEFTPAGES),    DPS && !WholeSpread);
01556     Enable(_R(IDC_DPSRIGHTPAGES),   DPS && !WholeSpread);
01557 
01558     PrintRangeDPS DPSRange = LocalPrintControl.GetDPSPrintRange();
01559     CheckDlgButton(_R(IDC_DPSBOTH),      DPSRange == PRINTRANGEDPS_BOTH);
01560     CheckDlgButton(_R(IDC_DPSLEFTPAGES), DPSRange == PRINTRANGEDPS_LEFTPAGES);
01561     CheckDlgButton(_R(IDC_DPSRIGHTPAGES),DPSRange == PRINTRANGEDPS_RIGHTPAGES);
01562 
01563     // Print to file check box
01564     CheckDlgButton(chx1,LocalPrintControl.GetPrintToFile());
01565 
01566     // Num copies ed field
01567     SetDlgItemInt(edt3,LocalPrintControl.GetNumCopies());
01568     Enable(edt3,TRUE);
01569 
01570     // Collated check box
01571     CheckDlgButton(chx2,LocalPrintControl.IsCollated());
01572     INT32 NumPages = LocalPrintControl.GetNumPrintablePages();
01573     Enable(chx2,NumPages > 1);
01574 
01575     // The print info text
01576     Str = LocalPrintControl.BuildPrintInfoStr();
01577     SetDlgItemText(_R(IDC_PRINTLAYOUTINFO),Str);
01578 
01579 // Code to comment out non-functional aspects of the print dlg (18/4/95)
01580 /*
01581 Enable(chx1,                FALSE);
01582 Enable(_R(IDC_ALLOBJECTS),      FALSE);
01583 Enable(_R(IDC_SELECTEDOBJECTS), FALSE);
01584 Enable(_R(IDC_GROUP_PRINTPAGES),FALSE);
01585 Enable(_R(IDC_DPSBOTH),         FALSE);
01586 Enable(_R(IDC_DPSLEFTPAGES),    FALSE);
01587 Enable(_R(IDC_DPSRIGHTPAGES),   FALSE);
01588 Enable(chx2,                FALSE);
01589 Enable(grp1,                FALSE);
01590 */
01591     return TRUE;
01592 }
01593 
01594 /********************************************************************************************
01595 
01596 >   void CCPrintDialog::Enable(UINT32 GadgetID, BOOL State)
01597 
01598     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01599     Created:    31/3/95
01600     Inputs:     GadgetID = ID of the dlg item
01601                 State    = TRUE = enable, FALSE = disable
01602     Returns:    -
01603     Purpose:    Enables (ungreys) or disables (greys) contols within the print dlg
01604 
01605     SeeAlso:    -
01606 
01607 ********************************************************************************************/
01608 
01609 void CCPrintDialog::Enable(UINT32 GadgetID,BOOL State)
01610 {
01611     CWnd* pGadget =  GetDlgItem(GadgetID);
01612     if (pGadget != NULL)
01613         pGadget->EnableWindow(State);
01614 }
01615 
01616 /********************************************************************************************
01617 
01618 >   BOOL CCPrintDialog::OnCommand()
01619 
01620     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01621     Created:    31/3/95
01622     Inputs:     -
01623     Returns:    TRUE if all ok, FALSE if an error occurs
01624     Purpose:    Called when something happends to one of our controls
01625 
01626                 It processes the UI change, and reflects this change in LocalPrintControl
01627 
01628     SeeAlso:    -
01629 
01630 ********************************************************************************************/
01631 
01632 BOOL CCPrintDialog::OnCommand(UINT32 GadgetID)
01633 {
01634     switch (GadgetID)
01635     {
01636         // Print range radio buttons
01637         case _R(IDC_ALLOBJECTS):        LocalPrintControl.SetObjPrintRange(PRINTRANGEOBJ_ALL);      break;
01638         case _R(IDC_SELECTEDOBJECTS):   LocalPrintControl.SetObjPrintRange(PRINTRANGEOBJ_SELECTED); break;
01639 
01640         // Print pages radio buttons
01641         case _R(IDC_DPSBOTH):       LocalPrintControl.SetDPSPrintRange(PRINTRANGEDPS_BOTH);         break;
01642         case _R(IDC_DPSLEFTPAGES):  LocalPrintControl.SetDPSPrintRange(PRINTRANGEDPS_LEFTPAGES);    break;
01643         case _R(IDC_DPSRIGHTPAGES): LocalPrintControl.SetDPSPrintRange(PRINTRANGEDPS_RIGHTPAGES);   break;
01644 
01645         case _R(IDC_PRINTOPTIONS):
01646         {
01647             if (PrintPrefsOpen)
01648                 break;
01649 
01650             // Get ptr to document's print control
01651             PrintControl* pPrCtrl = GetPrintControl();
01652             ERROR3IF(pPrCtrl == NULL,"Unable to find the print control");
01653 
01654             if (pPrCtrl != NULL)
01655             {
01656                 // Get the dlg settings
01657                 // We have to commit the settings to the document now, or else they won't be copied through to
01658                 // the options dialogue. Thus, the Options button effectively soft-commits the values.
01659                 GetDetails(pPrCtrl);
01660 
01661                 PrintPrefsOpen = TRUE;
01662 
01663                 ControlHelper::InformModalDialogOpened();
01664 
01665                 // Open print prefs dlg
01666                 if (PrintPrefsDlg::InvokeDialog())
01667                     PrintPrefsChanged = TRUE;
01668 
01669                 ControlHelper::InformModalDialogClosed();
01670 
01671                 PrintPrefsOpen = FALSE;
01672                 SetFocus();
01673             }
01674 
01675             // Now copy the document options (which may have been changed by the options dialogue)
01676             // back into our local print control, and make sure we update the dialogue as well.
01677             // Just to be really safe, I find the print control from scratch
01678             pPrCtrl = GetPrintControl();
01679             ERROR3IF(pPrCtrl == NULL,"Unable to find the print control");
01680             if (pPrCtrl != NULL)
01681                 LocalPrintControl = *pPrCtrl;
01682             ShowDetails();
01683             break;
01684         }
01685 
01686         case _R(IDC_PRINTHELP):
01687         {
01688             // Get the dlg settings
01689 //          GetDetails();
01690 
01691             // We need help!
01692             HelpUser(*this);
01693             break;
01694         }
01695 
01696         default:
01697             ERROR3("Unknown custom print dialog command");
01698             break;
01699     }
01700 
01701     // If a gadget that could effect the appearence of print borders has been clicked,
01702     // better redraw the print borders
01703     if ((GadgetID == _R(IDC_DPSBOTH)) || (GadgetID == _R(IDC_DPSLEFTPAGES)) || (GadgetID == _R(IDC_DPSRIGHTPAGES)))
01704     {
01705         PrintControl* pPrCtrl = GetPrintControl();
01706         if (pPrCtrl != NULL)
01707         {
01708             pPrCtrl->SetDPSPrintRange(LocalPrintControl.GetDPSPrintRange());
01709             
01710             Document* pDoc = pDocument;
01711             // Redraw all views that are showing their print borders
01712             if (pDoc == NULL)
01713                 pDoc = Document::GetSelected();
01714             if (pDoc != NULL)
01715             {
01716                 FRDocViewFunc pFunc = PrintControl::RedrawPrintableArea;
01717                 pDoc->ForceRedraw(pFunc);
01718             }
01719         }
01720     }
01721 
01722     // Update the dlg controls in case something has changed.
01723     ShowDetails();
01724 
01725     return TRUE;
01726 }
01727 
01728 /********************************************************************************************
01729 
01730 >   void CCPrintDialog::OnPrintSetup()
01731 
01732     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01733     Created:    7/4/95
01734     Inputs:     -
01735     Returns:    -
01736     Purpose:    This is called when the user clicks on Print setup...
01737 
01738                 It calls the base class OnPrintSetup(), and when it returns, updates the
01739                 printer settings static members.
01740 
01741                 It also calls ShowDetails() to keep the dlg up to date.
01742     SeeAlso:    -
01743 
01744 ********************************************************************************************/
01745 
01746 void CCPrintDialog::OnPrintSetup()
01747 {
01748     // Get the dlg control settings
01749     PrintControl* pPrCtrl = GetPrintControl();
01750     ERROR3IF(pPrCtrl == NULL,"Unable to find the print control");
01751 
01752     if (pPrCtrl != NULL)
01753     {
01754         GetDetails(pPrCtrl);            // Commit all the current settings into the document
01755         LocalPrintControl = *pPrCtrl;   // And re-synchronise our local printcontrol with the doc settings
01756     }
01757 
01758     // Bring up the print setup dlg
01759 //  CPrintDialog::OnPrintSetup();
01760     {
01761         ASSERT_VALID(this);
01762 
01763         ERROR3IF(pDlgSetup != NULL,"Er, why is pDlgSetup not NULL?");
01764 
01765         pDlgSetup = AttachOnSetup();
01766 
01767         ERROR3IF(pDlgSetup == NULL,"AttachOnSetup() returned NULL");
01768         
01769         if (pDlgSetup != NULL)
01770         {
01771             AfxHookWindowCreate(pDlgSetup);
01772             Default();
01773             AfxUnhookWindowCreate();
01774 
01775             delete pDlgSetup;
01776             pDlgSetup = NULL;
01777         }
01778     }
01779 
01780 
01781     FixFPControlRegister();
01782 
01783     // In Win3.1 after the print setup dlg has been used, we have to close the main print dlg in order 
01784     // to get the up-to-date hDevNames and hDevMode handles in the m_pd structure (these are up-to-date 
01785     // at point which ::PrintDlg() returns).
01786     //
01787     // This means we must flag that we have prematurely closed the print dlg, so that it can
01788     // be reopened again (this is handled in CCPrintDialog::DoModal()).
01789 
01790     ReopenMainDlg = IsWindows31(); //(IsWin32s() && !IsWin32c());
01791 
01792     if (ReopenMainDlg)
01793         PostMessage(WM_CLOSE);
01794     else
01795     {
01796         if (!IgnorePrintData())
01797         {
01798             UpdatePrinterSettings();
01799 
01800             // Set up print control again so that it takes the new print setup on board.
01801             if (pPrCtrl != NULL)
01802                 LocalPrintControl = *pPrCtrl;   // Re-synchronise our local printcontrol with the doc settings
01803 
01804             LocalPrintControl.SetUp(Document::GetSelectedSpread());
01805 
01806             // Update the dlg controls in case something has changed.
01807             ShowDetails();
01808         }
01809     }
01810 }
01811 
01812 
01813 //-----------------------------------------------------------------------------------------
01814 
01815 /*************************************************************
01816 // This code will retrieve the system-wide DEVMODE settings of printer driver
01817 // It is not too useful to us, as we want the application-wide settings that override the
01818 // system-wide settings, and hence can be different
01819 *********************************************/
01820 
01821 typedef INT32 (FAR WINAPI *EXTDEVICEMODEPROC)(HWND,HANDLE,LPDEVMODE,LPSTR,LPSTR,LPDEVMODE,LPSTR,WORD);
01822 
01823 /********************************************************************************************
01824 
01825 >   DEVMODE* CCPrintDialog::GetSystemDevMode(HWND hWnd,LPCTSTR pDriverName,LPCTSTR pDeviceName,LPCTSTR pPortName)
01826 
01827     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01828     Created:    7/4/95
01829     Inputs:     hWnd = window handle
01830                 pDriverName = ptr to driver name (e.g. "winspool")
01831                 pDeviceName = ptr to device name (e.g. "\\DEEPTHOUGHT\Hobbes")
01832                 pPortName   = ptr to port name (e.g. "Ne00:")
01833     Returns:    ptr to DEVMODE defining system-wide print settings for the currenly selected printer
01834     Purpose:    ******* COMMENTS ***********
01835     SeeAlso:    -
01836 
01837 ********************************************************************************************/
01838 
01839 DEVMODE* CCPrintDialog::GetSystemDevMode(HWND hWnd,LPCTSTR pDriverName,LPCTSTR pDeviceName,LPCTSTR pPortName)
01840 {
01841     if (pDriverName == NULL || pDeviceName == NULL || pPortName == NULL)
01842     {
01843         ERROR3("Given NULL entry params");
01844         return NULL;
01845     }
01846 
01847     DEVMODE* pDevMode = NULL;
01848 
01849     CString DriverName = pDriverName;   // GetDriverName()
01850     DriverName += ".drv";
01851 
01852     HMODULE hMod = GetModuleHandle(DriverName);
01853     if (hMod != NULL)
01854     {
01855         EXTDEVICEMODEPROC ExtDeviceMode;
01856 
01857         ExtDeviceMode = (EXTDEVICEMODEPROC) GetProcAddress(hMod,"ExtDeviceMode");
01858         if (ExtDeviceMode != NULL)
01859         {
01860             LPSTR pDevice = (LPSTR)CCMalloc(100);
01861             LPSTR pPort   = (LPSTR)CCMalloc(100);
01862 
01863             if (pDeviceName != NULL && pPortName != NULL)
01864             {
01865                 camStrncpy(pDevice,pDeviceName,98);
01866                 camStrncpy(pPort,pPortName,98);
01867                 pDevice[99] = 0;
01868                 pPort[99] = 0;
01869 
01870                 //camStrncpy(pDeviceName,PrDlg.GetDeviceName(),200);
01871                 //camStrncpy(pPortName,PrDlg.GetPortName(),200);
01872 
01873                 INT32 size = ExtDeviceMode(hWnd,hMod,NULL, pDevice,pPort, 0, 0, 0);
01874                 if (size > 0)
01875                 {
01876                     pDevMode = (DEVMODE*)CCMalloc(size);
01877 
01878                     if (pDevMode != NULL)
01879                     {
01880                         pDevMode->dmFields = 0xffffffff;
01881 
01882                         INT32 r = ExtDeviceMode(hWnd,hMod,pDevMode, pDevice,pPort, 0,0, DM_COPY);
01883                         if (r != IDOK)
01884                         {
01885                             CCFree(pDevMode);
01886                             pDevMode = NULL;
01887                         }
01888                     }                   
01889                 }
01890             }
01891             if (pDevice != NULL) CCFree(pDevice);
01892             if (pPort != NULL) CCFree(pPort);
01893         }
01894     }           
01895 
01896     return pDevMode;
01897 }
01898 
01899 #endif
01900 
01901 //-----------------------------------------------------------------------------------------
01902 
01903 /********************************************************************************************
01904 
01905 >   CCPrintInfo::CCPrintInfo()
01906 
01907     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01908     Created:    31/3/95
01909     Inputs:     -
01910     Returns:    -
01911     Purpose:    Default constructor
01912     SeeAlso:    CCPrintInfo::CCPrintInfo(Document* pDoc)
01913 
01914 ********************************************************************************************/
01915 
01916 CCPrintInfo::CCPrintInfo()
01917 {
01918     ERROR3("Default constructor called.  Use other constructor");
01919     pOurPD      = NULL;
01920     pOriginalPD = NULL;
01921     Initialised = FALSE;
01922     pDocument   = NULL;
01923     pCCDC = NULL;
01924     m_bContinuePrinting = TRUE;
01925     m_pNativePrintData = NULL;
01926 
01927     if (m_HaveSavedDefaultDialogData)
01928         *((wxPrintDialogData *)this) = m_DefaultDialogData;
01929 }
01930 
01931 
01932 /********************************************************************************************
01933 
01934 >   CCPrintInfo::CCPrintInfo(Document* pDoc,CCamView* pCCamVw)
01935 
01936     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01937     Created:    31/3/95
01938     Inputs:     pDoc    = ptr to doc associated with the print operation
01939                 pCCamVw = ptr to the cam view that's doing the print job
01940     Returns:    -
01941     Purpose:    Main constructor
01942 
01943                 This replaces the m_pPD ptr created by the base CPrintInfo class with a ptr to
01944                 a CCPrintDialog
01945 
01946     SeeAlso:    -
01947 
01948 ********************************************************************************************/
01949 
01950 CCPrintInfo::CCPrintInfo(Document* pDoc,CCamView* pCCamVw)
01951 {
01952     CAM_USE(pCCamVw); // Unused parameter in wxOil - used in WinOil
01953 
01954     pOurPD      = NULL;
01955     pOriginalPD = NULL;
01956     Initialised = FALSE;
01957     Printing    = FALSE;
01958     pDocument   = pDoc;
01959     pPrCtrl     = NULL;
01960     pPrgDlg     = NULL;
01961     pCCDC       = NULL;
01962     m_bContinuePrinting = TRUE;
01963     m_pNativePrintData = NULL;
01964 
01965     if (m_HaveSavedDefaultDialogData)
01966         *((wxPrintDialogData *)this) = m_DefaultDialogData;
01967 
01968     EnableHelp(TRUE);
01969     EnablePageNumbers(FALSE); // Make this TRUE to enable multiple pages
01970     EnablePrintToFile(TRUE);
01971     EnableSelection(TRUE); // we should test here whether or not there is a selection
01972 
01973 PORTNOTE("printing", "Disabled creation of a print dialog inside a CCPrintInfo structure")
01974 #ifndef EXCLUDE_FROM_XARALX
01975     if (pDocument != NULL)
01976     {
01977         pOurPD = new CCPrintDialog(pDocument);
01978 
01979         if (pOurPD != NULL)
01980         {
01981             pOriginalPD = m_pPD;
01982             m_pPD = pOurPD;
01983             Initialised = TRUE;
01984         }
01985         else
01986         {   ERROR3("Unable to create a CCPrintDialog object"); }
01987     }
01988 #else
01989     Initialised = TRUE;
01990 #endif
01991 
01992     ERROR3IF(pDocument == NULL,"CCPrintInfo has NULL document ptr");
01993     
01994     ERROR3IF(CCPrintInfo::pCurrent != NULL,"Constructing a new CCPrintInfo before destructing the old one");
01995     CCPrintInfo::pCurrent = this;
01996 }
01997 
01998 /********************************************************************************************
01999 
02000 >   CCPrintInfo::~CCPrintInfo()
02001 
02002     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02003     Created:    31/3/95
02004     Inputs:     -
02005     Returns:    -
02006     Purpose:    Default destructor
02007 
02008                 This tidies up by restoring the m_pPD member back to how the base class constructed it
02009                 and destroys the CCPrintDialog it made on initialisation
02010 
02011     SeeAlso:    -
02012 
02013 ********************************************************************************************/
02014 
02015 CCPrintInfo::~CCPrintInfo()
02016 {
02017     ERROR3IF(!Initialised,"CCPrintInfo being destructed without successful construction");
02018 
02019     if (Initialised)
02020     {
02021 PORTNOTE("printing", "Disabled deletion of a print dialog inside printinfo structure")
02022 #ifndef EXCLUDE_FROM_XARALX
02023         // restore base classes original CPrintDialog ptr
02024         m_pPD = pOriginalPD;
02025 #endif
02026 
02027         // Delete our CCPrintDialog
02028         if (pOurPD != NULL)
02029             delete pOurPD;
02030 
02031         // Delete our print progress dialog
02032         if (pPrgDlg != NULL)
02033             pPrgDlg->Done(); // this deletes it
02034     }
02035 
02036     if (pCCDC)
02037     {
02038         delete pCCDC;
02039         pCCDC=NULL;
02040     }
02041 
02042     if (m_pNativePrintData)
02043         delete m_pNativePrintData;
02044 
02045     CCPrintInfo::pCurrent = NULL;
02046 }
02047 
02048 
02049 /********************************************************************************************
02050 
02051 >   CNativeDC * CCPrintInfo::GetDC() const
02052 
02053     Author:     Alex Bligh <alex@alex.org.uk>
02054     Created:    22/6/2006
02055     Inputs:     -
02056     Returns:    The CNativeDC
02057     Purpose:    Utility function to get to the underlying DC
02058 
02059     SeeAlso:    -
02060 
02061 ********************************************************************************************/
02062 
02063 CNativeDC * CCPrintInfo::GetDC() const
02064 {
02065     return pCCDC?pCCDC->GetDC():NULL;
02066 }
02067 
02068 /********************************************************************************************
02069 
02070 >   BOOL CCPrintInfo::OnPreparePrinting(BOOL bPrintSetupOnly)
02071 
02072     Author:     Alex Bligh <alex@alex.org.uk>
02073     Created:    22/6/2006
02074     Inputs:     bPrintSetupOnly - true to just bring up the print setup dialog
02075     Returns:    TRUE to print, FALSE to not print
02076     Purpose:    Brings up a print dialog
02077 
02078     SeeAlso:    -
02079 
02080 ********************************************************************************************/
02081 
02082 BOOL CCPrintInfo::OnPreparePrinting(BOOL bPrintSetupOnly /*=FALSE*/)
02083 {
02084     wxPostScriptDC::SetResolution(600); // temporary bodge
02085 
02086     // Zap any existing print dialog
02087     if (pOurPD)
02088     {
02089         delete pOurPD;
02090         pOurPD = NULL;
02091     }
02092 
02093     EnablePrintToFile(true);
02094     EnableSelection(true);
02095     EnablePageNumbers(false);
02096     pOurPD = new CCPrintDialog(this, pDocument);
02097     if (!pOurPD)
02098     {
02099         return FALSE;
02100     }
02101     
02102     // Get rid of any existing CCDC
02103     if (!pCCDC)
02104         delete pCCDC;
02105 
02106     pCCDC = NULL;
02107 
02108     // Bring up a native print setup dialog if possible
02109     wxPrintFactory* factory = wxPrintFactory::GetFactory();
02110 
02111     // Use the print dialog if we can
02112     if (bPrintSetupOnly && factory->HasPrintSetupDialog())
02113     {
02114         // The print setup dialog should change the
02115         // print data in-place if not cancelled.
02116 
02117         wxDialog *dialog = factory->CreatePrintSetupDialog( NULL, &(pOurPD->GetPrintDialogData().GetPrintData()) );
02118         if (dialog->ShowModal() == wxID_OK)
02119         {
02120             *((wxPrintDialogData *)this)=pOurPD->GetPrintDialogData();
02121             SavePrintDialogData();
02122             UpdatePrinterSettings(TRUE);
02123         }
02124 
02125         // If we are to ignore the printer data (because the selected printer has been deleted, renamed, etc)
02126         // then we must reset the global memory handles that hold the data, as the settings they contain
02127         // no longer refer to a printer known by the host system
02128         if (CCPrintDialog::IgnorePrintData())
02129         {
02130 PORTNOTE("printing", "don't do FreeGlobalHandle")
02131 #ifndef EXCLUDE_FROM_XARALX
02132             CCPrintDialog::FreeGlobalHandle(&m_hDevMode);
02133             CCPrintDialog::FreeGlobalHandle(&m_hDevNames);
02134 #endif
02135             CCPrintDialog::ResetIgnorePrintData();
02136         }
02137 
02138         dialog->Destroy();
02139 
02140         delete pOurPD;
02141         pOurPD = NULL;
02142         return FALSE;
02143     }
02144 
02145     ResourceID ret = pOurPD->ShowModal();
02146     if ( (ret == wxID_CANCEL) || !pOurPD->GetPrintDialogData().Ok())
02147     {
02148         delete pOurPD;
02149         pOurPD = NULL;
02150         return FALSE;
02151     }
02152 
02153     // They pressed print
02154     wxDC * dc = pOurPD->GetPrintDC(); // we now own the DC.
02155     if (dc) delete dc; // ignore your nasty dc, which may be a non-wxPostScript DC  
02156 
02157     // Overwrite our own settings
02158     *((wxPrintDialogData *)this)=pOurPD->GetPrintDialogData();
02159     SavePrintDialogData();
02160     UpdatePrinterSettings(TRUE);
02161 
02162     pCCDC = NULL;
02163 
02164     dc = MakeDCFromPrintData(&(pOurPD->GetPrintDialogData().GetPrintData()));
02165 
02166     if (!dc)
02167     {
02168         delete pOurPD;
02169         pOurPD = NULL;
02170         ERROR2(FALSE, "CCPrintInfo::OnPreparePrinting() could not get a wxPostScriptDC");
02171     }
02172 
02173     pCCDC = new PSPrintDC(dc);
02174     if (!pCCDC)
02175     {
02176         delete dc;
02177         delete pOurPD;
02178         pOurPD = NULL;
02179         return FALSE;
02180     }
02181 
02182     pCCDC->SetDC(dc, TRUE); // now deleting the CCDC will delete the DC too
02183 
02184     return TRUE;
02185 }
02186 
02187 /********************************************************************************************
02188 
02189 >   CCPrintInfo::MakeDCFromPrintData( wxPrintData * pPrintData )
02190 
02191     Author:     Alex Bligh <alex@alex.org.uk>
02192     Created:    22/6/2006
02193     Inputs:     pPrintData - pointer to the dialog's print data
02194     Returns:    A DC suitable for printing to
02195     Purpose:    Generates a wxPostscriptDC even though the print dialog may not have
02196                 wanted to give us one. Also fills in m_pNativePrintData with the necessary
02197                 print data.
02198 
02199     SeeAlso:    -
02200 
02201 ********************************************************************************************/
02202 
02203 wxDC * CCPrintInfo::MakeDCFromPrintData( wxPrintData * pPrintData )
02204 {
02205     // Make a new wxPostscriptDC based on the print data
02206 
02207     if (m_pNativePrintData)
02208     {
02209         delete m_pNativePrintData;
02210         m_pNativePrintData = NULL;
02211     }
02212 
02213     // We don't use the copy constructor to copy things over here because this copies
02214     // wxPrintNativeData etc. which is print factory specific. We also have to switch
02215     // print factories around so we get a new print factory with the correct private
02216     // data in (what a bore).
02217 
02218 #if wxUSE_LIBGNOMEPRINT
02219     wxPrintFactory::SetPrintFactory(new wxNativePrintFactory);
02220 #endif
02221 
02222     wxPrintData * pNewData = new wxPrintData;
02223     if (!pNewData)
02224     {
02225 #if wxUSE_LIBGNOMEPRINT
02226         // restore the print factory
02227         wxPrintFactory::SetPrintFactory(new wxGnomePrintFactory);
02228 #endif
02229         ERROR2(NULL, "CCPrintInfo::OnPreparePrinting() could not get new print data");
02230     }
02231 
02232     // Now copy through the bits we care about
02233     pNewData->SetPrinterName(pPrintData->GetPrinterName());
02234     pNewData->SetNoCopies(pPrintData->GetNoCopies());
02235     pNewData->SetCollate(pPrintData->GetCollate());
02236     pNewData->SetOrientation(pPrintData->GetOrientation());
02237     pNewData->SetColour(pPrintData->GetColour());
02238     pNewData->SetDuplex(pPrintData->GetDuplex());
02239     pNewData->SetPaperId(pPrintData->GetPaperId());
02240     pNewData->SetPaperSize(pPrintData->GetPaperSize());
02241     pNewData->SetQuality(pPrintData->GetQuality());
02242     pNewData->SetBin(pPrintData->GetBin());
02243     pNewData->SetPrintMode(pPrintData->GetPrintMode());
02244     pNewData->SetFilename(pPrintData->GetFilename());
02245 
02246     wxDC * dc=new wxPostScriptDC(*pNewData);
02247 
02248     // this has been copied, so it can safely be deleted
02249     m_pNativePrintData =  pNewData;
02250 
02251 #if wxUSE_LIBGNOMEPRINT
02252     // restore the print factory
02253     wxPrintFactory::SetPrintFactory(new wxGnomePrintFactory);
02254 #endif
02255 
02256     if (!(dc->IsKindOf(CLASSINFO(wxPostScriptDC))))
02257     {
02258         delete dc;
02259         ERROR2(NULL, "Something is obstinately refusing to give us a wxPostScriptDC");
02260     }
02261 
02262     return dc;
02263 
02264 }
02265 
02266 /********************************************************************************************
02267 
02268 >   BOOL CCPrintInfo::HasPrintSetup()
02269 
02270     Author:     Alex Bligh <alex@alex.org.uk>
02271     Created:    22/6/2006
02272     Inputs:     -
02273     Returns:    TRUE if a print setup dialog can be brought up
02274     Purpose:    
02275 
02276     SeeAlso:    -
02277 
02278 ********************************************************************************************/
02279 
02280 BOOL CCPrintInfo::HasPrintSetup()
02281 {
02282     wxPrintFactory* factory = wxPrintFactory::GetFactory();
02283     return (factory->HasPrintSetupDialog());
02284 }
02285 
02286 /********************************************************************************************
02287 
02288 >   BOOL CCPrintInfo::LockProgressUpdate(BOOL Locked)
02289 
02290     Author:     Alex Bligh <alex@alex.org.uk>
02291     Created:    22/6/2006
02292     Inputs:     Locked - to lock the progress update
02293     Returns:    
02294     Purpose:    Locks/Unlocks the print progress dialogue (if any) to make sure it doesn't
02295                 update the progress slider etc during some critical operation.
02296 
02297     SeeAlso:    -
02298 
02299 ********************************************************************************************/
02300 
02301 void CCPrintInfo::LockProgressUpdate(BOOL Locked)
02302 {
02303      if (pPrgDlg != NULL)
02304         pPrgDlg->LockProgressUpdate(Locked);
02305 }
02306 
02307 /********************************************************************************************
02308 
02309 >   BOOL CCPrintInfo::StartPrinting()
02310 
02311     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02312     Created:    25/4/95
02313     Inputs:     -
02314     Returns:    TRUE if all OK, FALSE otherwise
02315     Purpose:    This informs the print info object that you are about to do some printing.
02316 
02317                 It also creates and displays the print progress dialog.
02318 
02319                 This is purely to set up the print layout mechanism.  It will work out how many 
02320                 pieces of paper will be printed to, and how many times the page will be printed
02321                 on each piece of of paper (for multiple fit printing).
02322 
02323                 CCPrintInfo just provides easy access to the functions provided by the PrintControl class.
02324                 It means you don't have to worry about getting hold of the right PrintControl object from
02325                 the right document - this is all taken care of for you.
02326 
02327                 The mechanism works like this:
02328 
02329                 if (StartPrinting())
02330                 {
02331                     while (GetNextPaper())
02332                     {
02333                         while (GetNextPatch())
02334                         {
02335                             Use access funcs to get hold of data set up by GetNextPath(), e.g. scale, translation, etc
02336                         
02337                             if (SelectedOnly)
02338                                 print all selected objects that lie within the ClipRect area in the spread
02339                             else
02340                                 print all objects that lie within the ClipRect area in the spread
02341                         }
02342                     }
02343 
02344                     EndPrinting()
02345                 }
02346 
02347     SeeAlso:    GetNextPaper(), GetNextPath()
02348 
02349 ********************************************************************************************/
02350 
02351 BOOL CCPrintInfo::StartPrinting()
02352 {
02353     ERROR2IF(Printing,FALSE,"StartPrinting() called before EndPrinting()");
02354     Printing = TRUE;
02355 
02356     // If not initialised properly, don't start printing
02357     ERROR2IF(!Initialised,FALSE,"Not initialised");
02358     ERROR2IF(pOurPD == NULL,FALSE,"NULL CCPrintDialog ptr");
02359     ERROR2IF(pDocument == NULL,FALSE,"Document ptr is NULL");
02360 
02361     // Get ptr to the PrintControl object
02362     pPrCtrl = pOurPD->GetPrintControl();
02363     ERROR2IF(pPrCtrl == NULL,FALSE,"The print dialog can't find attached print control object");
02364     if (!pPrCtrl->StartPrinting())
02365     {
02366         pPrCtrl = NULL;
02367         return FALSE;
02368     }
02369 
02370     // Start up the print marks manager too
02371     PrintMarksMan* pMarksMan = GetApplication()->GetMarksManager();
02372     if (pMarksMan)
02373         pMarksMan->StartPrinting();
02374 
02375     ERROR3IF(pPrgDlg != NULL,"StartPrinting() called with non-NULL pPrgDlg. Did you call EndPrinting() last time?");
02376 
02377 
02378     OpDescriptor* pOpDesc = (OpDescriptor*)OpDescriptor::FindOpDescriptor( OPTOKEN_PRINT_PROGRESS );
02379     if ( pOpDesc )
02380         pOpDesc->Invoke();
02381     // Create and initialise the print progress dialog
02382     pPrgDlg = PrintProgressDlg::Get();
02383     if (pPrgDlg == NULL)
02384     {
02385         pPrCtrl->EndPrinting();
02386         pPrCtrl = NULL;
02387         return FALSE;
02388     }
02389 
02390     //pPrgDlg->SetDocName(pDocument->GetTitle());
02391     pPrgDlg->SetPrinterName(GetPrintData().GetPrinterName());
02392 //  pPrgDlg->SetPortName(GetPrintData().GetPrinterCommand());
02393     pPrgDlg->SetSliderPos(0);
02394 
02395     return TRUE;
02396 }
02397 
02398 /********************************************************************************************
02399 
02400 >   BOOL CCPrintInfo::EndPrinting()
02401 
02402     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02403     Created:    26/4/95
02404     Inputs:     -
02405     Returns:    TRUE if all OK, FALSE otherwise
02406     Purpose:    This informs the print info object that you have finished printing.
02407                 It also closes the print progress dialog (if there is one)
02408     SeeAlso:    StartPrinting();
02409 
02410 ********************************************************************************************/
02411 
02412 BOOL CCPrintInfo::EndPrinting()
02413 {
02414     ERROR2IF(!Printing,FALSE,"EndPrinting() called before StartPrinting()");
02415     Printing = FALSE;
02416 
02417     // End the print control structure
02418     ERROR2IF(pPrCtrl == NULL,FALSE,"Called with NULL PrintControl ptr.  Have you called StartPrinting()?");
02419     BOOL ok = pPrCtrl->EndPrinting();
02420     pPrCtrl = NULL;
02421 
02422     // End the print marks manager too
02423     PrintMarksMan* pMarksMan = GetApplication()->GetMarksManager();
02424     if (pMarksMan)
02425         pMarksMan->EndPrinting();
02426 
02427     // now destroy the print dialogue
02428     if (pPrgDlg != NULL)
02429     {
02430         pPrgDlg->Done();
02431         pPrgDlg = NULL;
02432     }       
02433 
02434     return (ok);
02435 }
02436 
02437 /********************************************************************************************
02438 
02439 >   BOOL CCPrintInfo::GetNextPaper()
02440 
02441     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02442     Created:    26/4/95
02443     Inputs:     -
02444     Returns:    TRUE if you should print on another piece of paper
02445                 FALSE if the print job should end
02446     Purpose:    Call this for each piece of paper to be printed to.
02447                 NB: You must call StartPrinting() before calling this func as part of your print loop
02448     SeeAlso:    StartPrinting();
02449 
02450 ********************************************************************************************/
02451 
02452 BOOL CCPrintInfo::GetNextPaper()
02453 {
02454     ERROR2IF(!Printing,FALSE,"GetNextPaper() called before StartPrinting()");
02455     ERROR2IF(pPrCtrl == NULL,FALSE,"Called with NULL PrintControl ptr.  Have you called StartPrinting()?");
02456     return (pPrCtrl->GetNextPaper());
02457 }
02458 
02459 
02460 /********************************************************************************************
02461 
02462 >   BOOL CCPrintInfo::MorePaper() const
02463 
02464     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
02465     Created:    11/6/96
02466     Inputs:     -
02467     Returns:    TRUE if there is another piece of paper to come
02468                 FALSE if the print job should end
02469     Purpose:    Call this to determin when to finish the print run of paper
02470                 NB: You must call StartPrinting() before calling this func as part of your print loop
02471     SeeAlso:    StartPrinting();
02472 
02473 ********************************************************************************************/
02474 
02475 BOOL CCPrintInfo::MorePaper() const
02476 {
02477     ERROR2IF(!Printing,FALSE,"MorePaper() called before StartPrinting()");
02478     ERROR2IF(pPrCtrl == NULL,FALSE,"Called with NULL PrintControl ptr.  Have you called StartPrinting()?");
02479     return (pPrCtrl->MorePaper());
02480 }
02481 
02482 
02483 /********************************************************************************************
02484 
02485 >   BOOL CCPrintInfo::ReprintPaper()
02486 
02487     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02488     Created:    26/4/95
02489     Inputs:     -
02490     Returns:    TRUE if all OK, FALSE otherwise
02491     Purpose:    This allows you to print on the same piece of paper again.
02492 
02493                 If you call this func after a call to GetNextPaper(), then the next time you
02494                 call GetNextPaper() you will actually be starting the print on the same piece of
02495                 paper.
02496 
02497     SeeAlso:    GetNextPaper()
02498 
02499 ********************************************************************************************/
02500 
02501 BOOL CCPrintInfo::ReprintPaper()
02502 {
02503     ERROR2IF(!Printing,FALSE,"ReprintPaper() called before StartPrinting()");
02504     ERROR2IF(pPrCtrl == NULL,FALSE,"Called with NULL PrintControl ptr.  Have you called StartPrinting()?");
02505     return (pPrCtrl->ReprintPaper());
02506 }
02507 
02508 
02509 /********************************************************************************************
02510 
02511 >   BOOL CCPrintInfo::GetNextPatch(PrintPatchInfo* pPatchInfo)
02512 
02513     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02514     Created:    26/4/95
02515     Inputs:     pPatchInfo = ptr to object to store patch info in
02516     Outputs:    -
02517     Returns:    TRUE if you should print another page on the paper
02518                 FALSE if the piece of paper printed to is finished.
02519 
02520     Purpose:    If this call returns TRUE, then the given PrintPatchInfo has been set up with
02521                 all the data needed to print the given patch.
02522 
02523                 NB: You must call GetNextPaper() before calling this func as part of your print loop
02524 
02525                 It automatically updates any relevent fields within the print progress dialog, if there
02526                 is one.
02527 
02528     SeeAlso:    StartPrinting(), GetNextPaper()
02529 
02530 ********************************************************************************************/
02531 
02532 BOOL CCPrintInfo::GetNextPatch(PrintPatchInfo* pPatchInfo)
02533 {
02534     ERROR2IF(!Printing,FALSE,"GetNextPatch() called before StartPrinting()");
02535     ERROR2IF(pPrCtrl == NULL,FALSE,"Called with NULL PrintControl ptr.  Have you called StartPrinting()?");
02536 
02537     BOOL ok = pPrCtrl->GetNextPatch(pPatchInfo);
02538 
02539     if (ok && pPrgDlg != NULL)
02540     {
02541         // Determine how many printing plates we're doing, and which one we're up to...
02542         INT32 MaxPlates = 0;        // If doing a composite print, we pass in 0
02543         INT32 CurrentPlate = 1;
02544         String_128 PlateName(TEXT("-"));
02545 
02546         if (GetPrintControl() != NULL)
02547         {
02548             TypesetInfo *TSInfo = GetPrintControl()->GetTypesetInfo();
02549             if (TSInfo != NULL && TSInfo->AreSeparating())
02550             {
02551                 MaxPlates = (INT32) TSInfo->GetNumPrintPlates();
02552                 CurrentPlate = MaxPlates - TSInfo->NumPrintPlatesRemaining();
02553 
02554                 ColourPlate *ThisPlate = TSInfo->GetCurrentPrintPlate();
02555                 if (ThisPlate != NULL)
02556                     ThisPlate->GetDescription((StringBase *) &PlateName);
02557             }
02558         }
02559 
02560         // And set the page, plate, and tile numbers
02561         pPrgDlg->SetPageNumber( pPatchInfo->PaperNumber, pPatchInfo->MaxPaperNumber,
02562                                 CurrentPlate, MaxPlates, (TCHAR *) PlateName,
02563                                 pPatchInfo->PatchNumber, pPatchInfo->MaxPatchNumber);
02564 
02565     }
02566 
02567     return ok;
02568 }
02569 
02570 /********************************************************************************************
02571 
02572 >   BOOL CCPrintInfo::StartPlatePrinting(PrintView *pPrintView, UINT32 *const pErrID)
02573     BOOL CCPrintInfo::SetNextPlate(PrintView *pPrintView)
02574     BOOL CCPrintInfo::MorePlates()
02575     void CCPrintInfo::EndPlatePrinting(PrintView *pPrintView)
02576 
02577     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
02578     Created:    11/6/96
02579     Inputs:     -
02580     Returns:    -
02581     Purpose:    Fast error checking connection functions to the PrintControl associated
02582                 class functions. See the headers for these functions for details.
02583 
02584 ********************************************************************************************/
02585 
02586 BOOL CCPrintInfo::StartPlatePrinting(PrintView *pPrintView, UINT32 *const pErrID)
02587 {
02588     ERROR2IF(!Printing,FALSE,"StartPlatePrinting() called before StartPrinting()");
02589     ERROR2IF(pPrCtrl == NULL,FALSE,"Called with NULL PrintControl ptr.  Have you called StartPrinting()?");
02590     return (pPrCtrl->StartPlatePrinting(pPrintView, pErrID));
02591 }
02592 
02593 BOOL CCPrintInfo::MorePlates()
02594 {
02595     ERROR2IF(!Printing,FALSE,"MorePlates() called before StartPrinting()");
02596     ERROR2IF(pPrCtrl == NULL,FALSE,"Called with NULL PrintControl ptr.  Have you called StartPrinting()?");
02597     return (pPrCtrl->MorePlates());
02598 }
02599 
02600 BOOL CCPrintInfo::SetNextPlate(PrintView *pPrintView)
02601 {
02602     ERROR2IF(!Printing,FALSE,"SetNextPlate() called before StartPrinting()");
02603     ERROR2IF(pPrCtrl == NULL,FALSE,"Called with NULL PrintControl ptr.  Have you called StartPrinting()?");
02604     return (pPrCtrl->SetNextPlate(pPrintView));
02605 }
02606 
02607 void CCPrintInfo::EndPlatePrinting(PrintView *pPrintView)
02608 {
02609     ERROR3IF(!Printing,"EndPlatePrinting() called before StartPrinting()");
02610     ERROR3IF(pPrCtrl == NULL,"Called with NULL PrintControl ptr.  Have you called StartPrinting()?");
02611     pPrCtrl->EndPlatePrinting(pPrintView);
02612 }
02613 
02614 
02615 
02616 
02617 /********************************************************************************************
02618 
02619 >   void CCPrintInfo::SetSliderSubRangeMax(INT32 Max)
02620 
02621     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02622     Created:    28/4/95
02623     Inputs:     Max = The maximum value the sub-range will reach
02624     Outputs:    -
02625     Returns:    -
02626     Purpose:    Defines the maximum value you will call SetSliderSubRange() with.
02627                 The slider is split up into sub-ranges, each range represents a patch (or tile) that
02628                 will be printed.  The slider is automatically set to the start of a sub-range when
02629                 GetNextPatch() is called.  
02630                 
02631                 After GetNextPatch() is called, call this func to define the range of values for 
02632                 the slider sub-range to represent.  Then call SetSliderSubRanngePos() each time the 
02633                 progress of the patch changes.
02634 
02635                 This will only have an effect if StartPrinting() has been successfully called.
02636                 If there isn't a progress bar (for what ever reason) this function does nothing (not
02637                 even error).
02638 
02639     SeeAlso:    StartPrinting(), SetSliderSubRangePos()
02640 
02641 ********************************************************************************************/
02642 
02643 void CCPrintInfo::SetSliderSubRangeMax(INT32 Max)
02644 {
02645     if (pPrgDlg != NULL)
02646         pPrgDlg->SetSliderSubRangeMax(Max);
02647 }
02648 
02649 /********************************************************************************************
02650 
02651 >   void CCPrintInfo::SetSliderSubRangePos(INT32 Pos)
02652 
02653     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02654     Created:    28/4/95
02655     Inputs:     Pos = value for the current sub-range
02656     Outputs:    -
02657     Returns:    -
02658     Purpose:    Sets the slider so that it represents this value within the current sub-range.
02659                 Before Pos is used, it is brought into range such that 0 <= Pos <= MaxSubRange
02660                 ('MaxSubRange' is set via SetSliderSubRangeMax())
02661 
02662                 This will only have an effect if StartPrinting() has been successfully called.
02663                 If there isn't a progress bar (for what ever reason) this function does nothing (not
02664                 even error).
02665 
02666     SeeAlso:    StartPrinting(), SetSliderSubRangeMax()
02667 
02668 ********************************************************************************************/
02669 
02670 void CCPrintInfo::SetSliderSubRangePos(INT32 Pos)
02671 {
02672     if (pPrgDlg != NULL)
02673         pPrgDlg->SetSliderSubRangePos(Pos);
02674 }
02675 
02676 /********************************************************************************************
02677 
02678 >   void CCPrintInfo::SetAnalysing()
02679 
02680     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02681     Created:    31/5/95
02682     Inputs:     -
02683     Outputs:    -
02684     Returns:    -
02685     Purpose:    This tells the associated print progress dlg that we are not yet printing the doc,
02686                 we are currently running some analysis on it.  This will display "Analysing <doc name>"
02687                 instead of "Printing <doc name>"
02688 
02689     SeeAlso:    -
02690 
02691 ********************************************************************************************/
02692 
02693 void CCPrintInfo::SetAnalysing()
02694 {
02695     if (pPrgDlg != NULL)
02696     {
02697         pPrgDlg->SetAnalysing();
02698         if (pDocument != NULL)
02699             pPrgDlg->SetDocName(pDocument->GetTitle());
02700     }
02701 }
02702 
02703 /********************************************************************************************
02704 
02705 >   void CCPrintInfo::SetPrinting()
02706 
02707     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02708     Created:    31/5/95
02709     Inputs:     -
02710     Outputs:    -
02711     Returns:    -
02712     Purpose:    This tells the associated print progress dlg that we have started printing the doc.  
02713                 This will display "Printing <doc name>" instead of "Analysing <doc name>"
02714 
02715     SeeAlso:    -
02716 
02717 ********************************************************************************************/
02718 
02719 void CCPrintInfo::SetPrinting()
02720 {
02721     if (pPrgDlg != NULL)
02722     {
02723         pPrgDlg->SetPrinting();
02724         if (pDocument != NULL)
02725             pPrgDlg->SetDocName(pDocument->GetTitle());
02726     }
02727 }
02728 
02729 /********************************************************************************************
02730 
02731 >   INT32 CCPrintInfo::SetAbortProc(CDC* pCDC)
02732 
02733     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02734     Created:    28/4/95
02735     Inputs:     pCDC = ptr to CDC used for printing
02736     Outputs:    -
02737     Returns:    0 means OK, non-zero means ERROR
02738     Purpose:    Calls pCDC->SetAbortProc() with the appropriate abort proc
02739     SeeAlso:    CDC::SetAbortProc()
02740 
02741 ********************************************************************************************/
02742 
02743 INT32 CCPrintInfo::SetAbortProc(CDC* pCDC)
02744 {
02745 PORTNOTE("printing", "Disabled SetAbortProc bits")
02746 #ifndef EXCLUDE_FROM_XARALX
02747     ERROR2IF(pCDC == NULL,SP_ERROR,"Given NULL CDC ptr");
02748 
02749     return (pCDC->SetAbortProc(PrintProgressDlg::AbortProc));
02750 #else
02751     return 0;
02752 #endif
02753 }
02754 
02755 /********************************************************************************************
02756 
02757 >   BOOL CCPrintInfo::Abort()
02758 
02759     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02760     Created:    28/4/95
02761     Inputs:     -
02762     Outputs:    -
02763     Returns:    TRUE if the user has aborted the print job, FALSE otherwise
02764 
02765     Purpose:    Calls the print progress dlg's abort proc to see if the user has aborted the print job
02766         
02767                 NB: The return value is the reverse of the origin logic used in the first working
02768                 print code
02769     SeeAlso:    -
02770 
02771 ********************************************************************************************/
02772 
02773 BOOL CCPrintInfo::Abort()
02774 {
02775     return PrintProgressDlg::AbortProc();
02776 }
02777 
02778 /********************************************************************************************
02779 
02780 >   BOOL CCPrintInfo::SetUpDocInfo(DOCINFO* pDocInfo)
02781 
02782     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02783     Created:    2/5/95
02784     Inputs:     ppDocInfo = ptr to place to put a ptr to a DOCINFO structure
02785     Outputs:    ppDocInfo = contains ptr to an initialised DOCINFO struct.
02786     Returns:    TRUE if ok, FALSE otherwise
02787 
02788     Purpose:    Creates and sets up a DOCINFO structure, ready for a call to StartDoc().
02789                 If printing to file, this func will ensure that the lpszOutput member points to
02790                 a valid file name.
02791 
02792                 pDocInfo contains the ptr to the DOCINFO on exit.  It is up to the caller to delete
02793                 this object when no longer needed
02794 
02795     SeeAlso:    -
02796 
02797 ********************************************************************************************/
02798 
02799 BOOL CCPrintInfo::SetUpDocInfo(DOCINFO** ppDocInfo)
02800 {
02801     ERROR2IF(ppDocInfo == NULL,FALSE,"ppDocInfo param is NULL");
02802     ERROR2IF(pDocument == NULL,FALSE,"pDocument is NULL");
02803 
02804     // Create a new DOCINFO struct so that we are compatible across all OSs
02805     NEW_DOCINFO* pNewDocInfo = new NEW_DOCINFO;
02806 
02807     BOOL ok = (pNewDocInfo != NULL);
02808 
02809     if (ok)
02810     {
02811         // Zero all struct members
02812         memset(pNewDocInfo,0,sizeof(NEW_DOCINFO));
02813         pNewDocInfo->cbSize = sizeof(NEW_DOCINFO);
02814 
02815         // set up document title
02816         DocTitle = pDocument->GetTitle();
02817 
02818         pNewDocInfo->lpszDocName = DocTitle;
02819         pNewDocInfo->lpszOutput = NULL;
02820 
02821         ERROR2IF(pOurPD == NULL,FALSE,"NULL CCPrintDialog ptr");
02822 
02823         // Get ptr to the PrintControl object
02824         if (pPrCtrl == NULL)
02825             pPrCtrl = pOurPD->GetPrintControl();
02826 
02827         ERROR3IF(pPrCtrl == NULL,"Unable to get ptr to the PrintControl object");
02828 
02829 PORTNOTE("printing", "Disabled print to file")
02830 #ifndef EXCLUDE_FROM_XARALX
02831         if (pPrCtrl != NULL && pPrCtrl->GetPrintToFile())
02832         {
02833             // Keep Control Helper system informed
02834             ControlHelper::InformModalDialogOpened();
02835 
02836             String_256 Filt(_R(IDS_PRDLGCTL_PRINT_FILES_FILT_DLG));
02837 
02838             CCPrintToFileDialog PrintToFileDlg("prn", (TCHAR *)Filt);
02839             if (PrintToFileDlg.DoModal() == IDOK)
02840                 pNewDocInfo->lpszOutput = PrintToFileDlg.GetFullPathNamePtr();
02841             else
02842                 ok = FALSE;     // Abort printing if Cancel is clicked
02843 
02844             // Keep Control Helper system informed
02845             ControlHelper::InformModalDialogClosed();
02846         }
02847 #endif
02848     }
02849 
02850     if (!ok && pNewDocInfo != NULL)
02851     {
02852         delete pNewDocInfo;
02853         pNewDocInfo = NULL;
02854     }
02855 
02856     ERROR2IF(ok && pNewDocInfo == NULL,FALSE,"Returning TRUE but we have a NULL DOCINFO ptr");
02857 
02858     *ppDocInfo = (DOCINFO*)pNewDocInfo;
02859 
02860     return ok;
02861 }
02862 
02863 //-----------------------------------------------------------------------------------------
02864 
02865 
02866 PORTNOTE("printing", "Disabled CCPrintToFileDialog")
02867 #ifndef EXCLUDE_FROM_XARALX
02868 
02869 /********************************************************************************************
02870 
02871 >   CCPrintToFileDialog::CCPrintToFileDialog(TCHAR *DefExt, TCHAR *FilterString)
02872 
02873     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02874     Created:    11/5/95
02875     Inputs:     DefExt          - Default filter extension
02876                 FilterString    - String to pass to the CFileDialog constructor dictating
02877                                                                     the filters for the dialog
02878     Outputs:    -
02879     Returns:    -
02880     Purpose:    Default constructor for the PrintToFile dialog
02881     SeeAlso:    -
02882 
02883 ********************************************************************************************/
02884 
02885 #if 0
02886 CCPrintToFileDialog::CCPrintToFileDialog() : CFileDialog(   FALSE,
02887                                                             "prn",
02888                                                             FileName,
02889                                                             OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
02890                                                             "Print files (*.prn) | *.prn | All files (*.*) | *.* ||",
02891                                                             NULL)
02892 {
02893     m_ofn.lpstrTitle = (TCHAR *)(String_64(_R(IDS_PRDLGCTL_PRINT_TO_FILE))); //"Print To File";
02894 }
02895 #endif
02896 
02897 CCPrintToFileDialog::CCPrintToFileDialog(TCHAR *DefExt, TCHAR *FilterString) :
02898      CFileDialog(FALSE, DefExt, FileName, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, FilterString, NULL)
02899 {
02900 //  String_256 Filt(_R(IDS_PRDLGCTL_PRINT_FILES_FILT_DLG)); // "Print files (*.prn) | *.prn | All files (*.*) | *.* ||"
02901 //  CFileDialog::CFileDialog(FALSE, "prn", FileName,    OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, (TCHAR *)Filt, NULL)
02902     
02903     Title = String_64(_R(IDS_PRDLGCTL_PRINT_TO_FILE));
02904     m_ofn.lpstrTitle = (TCHAR *)(Title);
02905 
02906     // Translate filter into commdlg format (lots of \0)
02907 //  m_strFilter = (TCHAR *)Filt;
02908 //  TCHAR *pch = (TCHAR *)Filt; // modify the buffer in place
02909 
02910     // MFC delimits with '|' not '\0'
02911 //  while ((pch = camStrchr(pch, '|')) != NULL)
02912 //      *pch++ = '\0';
02913 
02914 //  m_ofn.lpstrFilter = m_strFilter;
02915 
02916 }
02917 
02918 /********************************************************************************************
02919 
02920 >   CCPrintToFileDialog::~CCPrintToFileDialog()
02921 
02922     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02923     Created:    11/5/95
02924     Inputs:     -
02925     Outputs:    -
02926     Returns:    -
02927     Purpose:    Default destructor for the PrintToFile dialog
02928     SeeAlso:    -
02929 
02930 ********************************************************************************************/
02931 
02932 CCPrintToFileDialog::~CCPrintToFileDialog()
02933 {
02934 }
02935 
02936 
02937 /********************************************************************************************
02938 
02939 >   INT32 CCPrintToFileDialog::DoModal()
02940 
02941     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02942     Created:    11/5/95
02943     Inputs:     -
02944     Outputs:    -
02945     Returns:    IDOK or IDCANCEL
02946     Purpose:    Displays the PrintToFile dlg modally, and returns the user's result
02947     SeeAlso:    -
02948 
02949 ********************************************************************************************/
02950 
02951 INT32 CCPrintToFileDialog::DoModal()
02952 {
02953     INT32 Result = CFileDialog::DoModal();
02954 
02955     if (Result == IDOK)
02956     {
02957         camStrncpy(FileName,GetPathName(),FILENAMEBUFSIZE);
02958         FileName[FILENAMEBUFSIZE-1] = '\0';
02959     }
02960 
02961     return Result;
02962 }
02963 
02964 /********************************************************************************************
02965 
02966 >   LPSTR CCPrintToFileDialog::GetFullPathNamePtr()
02967 
02968     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02969     Created:    11/5/95
02970     Inputs:     -
02971     Outputs:    -
02972     Returns:    Ptr to the full path name entered by the user
02973     Purpose:    Access to the static buffer that contains the full path name for the file to print to
02974     SeeAlso:    -
02975 
02976 ********************************************************************************************/
02977 
02978 LPSTR CCPrintToFileDialog::GetFullPathNamePtr()
02979 {
02980     return FileName;
02981 }
02982 
02983 #endif

Generated on Sat Nov 10 03:48:48 2007 for Camelot by  doxygen 1.4.4