printprg.cpp

Go to the documentation of this file.
00001 // $Id: printprg.cpp 1593 2006-07-29 11:22:30Z 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 //
00099 // PrintProgressDlg - implements the print progress dialog displayed during printing
00100 
00101 /*
00102 */
00103 
00104 #include "camtypes.h"
00105 
00106 //  WEBSTER-ranbirr-12/11/96
00107 #ifndef WEBSTER
00108 
00109 #include "printprg.h"
00110 //#include "printdlg.h"
00111 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00112 //#include "custmsg.h"
00113 //#include "markn.h"
00114 //#include "simon.h"
00115 //#include "andy.h"
00116 //#include "fixst256.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00117 #include "camelot.h"
00118 //#include "justin2.h"
00119 #include "prncamvw.h"
00120 
00121 DECLARE_SOURCE("$Revision: 1593 $");
00122 
00123 CC_IMPLEMENT_DYNCREATE(PrintProgressDlg, DialogOp)
00124 
00125 #define new CAM_DEBUG_NEW
00126 
00127 const CDlgMode PrintProgressDlg::Mode = MODELESS ;// Mode of the dialog
00128 const UINT32 PrintProgressDlg::IDD = _R(IDD_PRINTPROGRESS);
00129 BOOL PrintProgressDlg::Aborted = FALSE;
00130 PrintProgressDlg* PrintProgressDlg::pPrintProgressDlg = NULL;
00131 
00132 const INT32 SLIDER_MAX = 0x08000000;
00133 
00134 /********************************************************************************************
00135 
00136 >   PrintProgressDlg::PrintProgressDlg()
00137 
00138     Author:     Alex Bligh <alex@alex.org.uk>
00139     Created:    14/06/2006
00140     Inputs:     -
00141     Returns:    -
00142     Purpose:    Constructs the dlg.
00143     SeeAlso:    -
00144 
00145 ********************************************************************************************/
00146 
00147 
00148 PrintProgressDlg::PrintProgressDlg(): DialogOp(PrintProgressDlg::IDD, PrintProgressDlg::Mode)
00149 {
00150     if (pPrintProgressDlg)
00151     {
00152         pPrintProgressDlg->Done();
00153         pPrintProgressDlg = NULL;
00154     }
00155 
00156     SliderMax = SLIDER_MAX;
00157     SliderCurPercent = -1;
00158     SliderSubRangeMax = SLIDER_MAX;
00159     SliderSubRangeBase = 0;
00160     SliderSubRangeStep = 1;
00161 
00162     pPrintProgressDlg = this;
00163     pDisabler = NULL;
00164 
00165     Printing = FALSE;
00166     IgnoreUpdates = FALSE;
00167     Aborted = FALSE;
00168 
00169     UpdateTime.Sample();
00170 }
00171 
00172 
00173 /********************************************************************************************
00174 
00175 >   BOOL PrintProgressDlg::Do(OpDescriptor*)
00176 
00177     Author:     Alex Bligh <alex@alex.org.uk>
00178     Created:    14/06/2006
00179     Inputs:     -
00180     Returns:    TRUE if OK, FALSE otherwise
00181     Purpose:    Inits the dialog's controls, and calls the base classes OnInitDialog() function
00182     SeeAlso:    -
00183 
00184 ********************************************************************************************/
00185 
00186 void PrintProgressDlg::Do(OpDescriptor*)
00187 {
00188     Create();
00189     Open();
00190 }
00191 
00192 /********************************************************************************************
00193 
00194 >   BOOL PrintProgressDlg::GetState(String_256*, OpDescriptor*)
00195 
00196     Author:     Alex Bligh <alex@alex.org.uk>
00197     Created:    14/06/2006
00198     Inputs:     -
00199     Returns:    TRUE if OK, FALSE otherwise
00200     Purpose:    Inits the dialog's controls, and calls the base classes OnInitDialog() function
00201     SeeAlso:    -
00202 
00203 ********************************************************************************************/
00204 
00205 OpState PrintProgressDlg::GetState(String_256*, OpDescriptor*)
00206 {
00207     OpState OpSt;
00208     return(OpSt);
00209 }
00210 
00211 /********************************************************************************************
00212 
00213 >   BOOL PrintProgressDlg::PrintProgressDlg::Init()
00214 
00215     Author:     Alex Bligh <alex@alex.org.uk>
00216     Created:    14/06/2006
00217     Inputs:     -
00218     Returns:    TRUE if OK, FALSE otherwise
00219     Purpose:    Inits the dialog's controls, and calls the base classes OnInitDialog() function
00220     SeeAlso:    -
00221 
00222 ********************************************************************************************/
00223 
00224 BOOL PrintProgressDlg::Init()
00225 {
00226     return (RegisterOpDescriptor(
00227                                     0,
00228                                     _R(IDD_PRINTPROGRESS),
00229                                     CC_RUNTIME_CLASS(PrintProgressDlg),
00230                                     OPTOKEN_PRINT_PROGRESS,
00231                                     PrintProgressDlg::GetState,
00232                                     0,  /* help ID */
00233                                     0,  /* bubble help*/
00234                                     0   /* bitmap ID */
00235                                     ));
00236 }
00237 
00238 /********************************************************************************************
00239 
00240 >   MsgResult PrintProgressDlg::Message( Msg* Message)
00241 
00242     Author:     Alex Bligh <alex@alex.org.uk>
00243     Created:    14/06/2006
00244     Inputs:     -
00245     Returns:    -
00246     Purpose:    Overrides the default OnOK() func so that we can check the values set by the user.
00247                 If dodgy values have been put in, the user is warned.
00248     SeeAlso:    -
00249 
00250 ********************************************************************************************/
00251 
00252 MsgResult PrintProgressDlg::Message( Msg* Message)
00253 {
00254     if (IS_OUR_DIALOG_MSG(Message))
00255     {
00256         DialogMsg* Msg = (DialogMsg*)Message;
00257         // Handle ok button
00258         if (Msg->DlgMsg == DIM_CREATE)
00259         {
00260             SetSliderMax(SLIDER_MAX);
00261             SetSliderPos(0);
00262             IgnoreUpdates = FALSE;
00263             UpdateTime.Sample();
00264 
00265             if (pDisabler)
00266                 delete pDisabler;
00267             pDisabler = new wxWindowDisabler(WindowID);
00268             ::wxYield(); // flush anything out the system
00269         }
00270         else if (Msg->DlgMsg == DIM_CANCEL)
00271         {
00272             if (CCamApp::IsDisabled())
00273                 return OK;
00274 
00275             INT32 b = InformWarning(_R(IDS_PRINT_SUSPEND),_R(IDS_ABORT),_R(IDS_CONTINUE));
00276     
00277             if (b == 1)
00278             {
00279                 Aborted = TRUE;
00280             }
00281             return OK; // Do not pass to the base class as this will destroy the dialog - we do that elsewhere
00282         }
00283     }
00284     return DialogOp::Message(Message);
00285 }
00286 
00287 
00288 
00289 
00290 
00291 //--------------------------------------------
00292 
00293 void PrintProgressDlg::SetSliderMax(INT32 max)
00294 {
00295     SliderMax        = max;
00296     SliderCurPercent = -1;
00297 
00298     SetGadgetRange(_R(IDC_PRINTPROGSLIDER), 0, max);
00299 }
00300 
00301 //--------------------------------------------
00302 
00303 void PrintProgressDlg::SetSliderPos(INT32 pos)
00304 {
00305     if (pos == -1)
00306         pos = SliderMax;
00307 
00308     if (pos < 0) pos = 0;
00309     if (pos > SliderMax) pos = SliderMax;
00310 
00311     INT32 p;
00312     double ratio = double(SliderMax) / 100.0;
00313     if (ratio != 0.0)
00314         p = INT32 ((double(pos) / ratio)+0.5);
00315     else
00316         p = 0;
00317 
00318     if (p != SliderCurPercent)
00319     {
00320         SliderCurPercent = p;
00321 
00322         SetLongGadgetValue(_R(IDC_PRINTPROGSLIDER), (INT32)pos);
00323     
00324         String_32 Percent;
00325         Percent.MakeMsg(_R(IDS_PRINT_PROG_PERCENT), (INT32) p);
00326         SetStringGadgetValue(_R(IDC_CURRENTPERCENTAGE), Percent);
00327         PaintGadgetNow(_R(IDC_CURRENTPERCENTAGE));
00328         PaintGadgetNow(_R(IDC_PRINTPROGSLIDER));
00329     }
00330 }
00331 
00332 //--------------------------------------------
00333 
00334 void PrintProgressDlg::SetSliderSubRangeMax(INT32 max)
00335 {
00336     if (max < 1) max = 1;
00337     SliderSubRangeMax = max;
00338 }
00339 
00340 //--------------------------------------------
00341 
00342 void PrintProgressDlg::SetSliderSubRangePos(INT32 pos)
00343 {
00344     if (pos > SliderSubRangeMax) pos = SliderSubRangeMax;
00345     if (pos < 0)                 pos = 0;
00346 
00347     double ratio = double(pos)/double(SliderSubRangeMax);
00348 
00349     SetSliderPos(SliderSubRangeBase+INT32(double(SliderSubRangeStep)*ratio));
00350 }
00351 
00352 //--------------------------------------------
00353 
00354 void PrintProgressDlg::SetDocName(LPCTSTR pDocName)
00355 {
00356     if (pDocName != NULL)
00357     {
00358         SetStringGadgetValue(_R(IDC_DOCNAME), String_256(pDocName));
00359         PaintGadgetNow(_R(IDC_DOCNAME));
00360     }
00361 }
00362 
00363 //--------------------------------------------
00364 
00365 void PrintProgressDlg::SetPrinterName(LPCTSTR pPrinterName)
00366 {
00367     if (pPrinterName != NULL)
00368     {
00369         SetStringGadgetValue(_R(IDC_PRINTERNAME), String_256(pPrinterName));
00370         PaintGadgetNow(_R(IDC_PRINTERNAME));
00371     }
00372 }
00373 
00374 //--------------------------------------------
00375 
00376 void PrintProgressDlg::SetPortName(LPCTSTR pPortName)
00377 {
00378 // Phil has decided that the port name is a bit too tecchie and not
00379 // really very useful info, so we've removed it to simplify the dialog
00380 //
00381 //  if (pPortName != NULL)
00382 //  {
00383 //      SetStringGadgetValue(_R(IDC_PORTNAME), String_256(pPortName));
00384 //      PaintGadgetNow(_R(IDC_PORTNAME));
00385 //  }
00386 
00387 }
00388 
00389 //--------------------------------------------
00390 
00391 /********************************************************************************************
00392 
00393 >   void PrintProgressDlg::SetPageNumber(INT32 PageNumber,  INT32 MaxPageNumber,
00394                                      INT32 PlateNumber, INT32 MaxPlateNumber, LPCTSTR pPlateName,
00395                                      INT32 TileNumber,  INT32 MaxTileNumber)
00396 
00397     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>/Jason
00398     Created:    ? (93 or 94 ish)
00399     Inputs:     PageNumber      - The page being printed in the range 1..MaxPageNumber
00400                 MaxPageNumber   - Total number of pages being printed (minimum of 1)
00401                 PlateNumber     - If separating, the current plate number in range 1..MaxPlateNumber
00402                                     else ignored
00403                 MaxPlateNumber  - If separating, the number of plates being printed (minimum of 1)
00404                                   If not separating, this MUST be set to 0.
00405                 pPlateName      - If separating, the name of the plate,
00406                                     else NULL
00407                 TileNumber      - The current tile in the range 1..MaxTileNumber
00408                 MaxTileNumber   - The number of tiles being printed (minimum of 1)
00409     Returns:    -
00410     Purpose:    Dumps the last error returned by GetLastError() using the FormatMessage() command
00411     SeeAlso:    CPrintDialog::DoModal
00412 
00413 ********************************************************************************************/
00414 
00415 void PrintProgressDlg::SetPageNumber(INT32 PageNumber,  INT32 MaxPageNumber,
00416                                      INT32 PlateNumber, INT32 MaxPlateNumber, LPCTSTR pPlateName,
00417                                      INT32 TileNumber,  INT32 MaxTileNumber)
00418 {
00419     // If the dlg is tem,porarily locked to stop screen updates, just return immediately.
00420     if (IgnoreUpdates)
00421         return;
00422 
00423     String_256 Str;
00424 
00425     // Set the page info
00426     Str.MakeMsg(_R(IDS_PRINT_PROG_PAGE), PageNumber, MaxPageNumber);
00427     SetStringGadgetValue(_R(IDC_PAGENUMBER), Str);
00428     PaintGadgetNow(_R(IDC_PORTNAME));
00429 
00430     // Set the plate info
00431     if (MaxPlateNumber > 0 && pPlateName != NULL)
00432         Str.MakeMsg(_R(IDS_PRINT_PROG_PLATE), PlateNumber, MaxPlateNumber, pPlateName);
00433     else
00434         Str.MakeMsg(_R(IDS_PRINT_PROG_COMPOSITE));
00435 
00436     SetStringGadgetValue(_R(IDC_PLATENUMBER), Str);
00437     PaintGadgetNow(_R(IDC_PLATENUMBER));
00438 
00439     // Set the tile info
00440     if (MaxTileNumber > 1)
00441     {
00442         Str.MakeMsg(_R(IDS_PRINT_PROG_TILE), TileNumber, MaxTileNumber);
00443         SetStringGadgetValue(_R(IDC_TILENUMBER), Str);
00444     }
00445 
00446     HideGadget(_R(IDC_TILETITLE), (MaxTileNumber <= 1));
00447     HideGadget(_R(IDC_TILENUMBER), (MaxTileNumber <= 1));
00448     PaintGadgetNow(_R(IDC_TILETITLE));
00449     PaintGadgetNow(_R(IDC_TILENUMBER));
00450 
00451     // Make sure we don't get a div by zero or a nasty negative in the calculations below
00452     if (MaxPageNumber < 1)      MaxPageNumber = 1;
00453     if (PageNumber < 1)         PageNumber = 1;
00454     if (MaxPlateNumber < 1)     MaxPlateNumber = 1;
00455     if (PlateNumber < 1)        PlateNumber = 1;
00456     if (MaxTileNumber < 1)      MaxTileNumber = 1;
00457     if (TileNumber < 1)         TileNumber = 1;
00458 
00459     // And set the slider position accordingly - divide the 100% up into ranges for each page,
00460     // subdivided into ranges for each plate, subdivided into ranges for each tile.
00461     INT32 SliderPerPage  = SliderMax / MaxPageNumber;
00462     INT32 SliderPerPlate = SliderPerPage / MaxPlateNumber;
00463     INT32 SliderPerTile  = SliderPerPlate / MaxTileNumber;
00464 
00465     SliderSubRangeBase = (SliderPerPage  * (PageNumber-1))  +
00466                          (SliderPerPlate * (PlateNumber-1)) +
00467                          (SliderPerTile  * (TileNumber-1));
00468     SliderSubRangeStep = SliderPerTile;
00469 
00470     SetSliderPos(SliderSubRangeBase);
00471 }
00472 
00473 
00474 //--------------------------------------------
00475 //--------------------------------------------
00476 
00477 BOOL PrintProgressDlg::AbortProc()
00478 {
00479     if (CCamApp::IsDisabled() || !pPrintProgressDlg)
00480         // Ignore
00481         return TRUE;
00482 
00483     // Note this only paints the gadget if it is invalidated
00484     pPrintProgressDlg->PaintGadgetNow(0);
00485 
00486     // Only sample if 750ms of printing has elapsed as the yield can take a while
00487     if (!PrintMonitor::IsYieldDisabled() && (pPrintProgressDlg->UpdateTime.Elapsed(750)))
00488     {
00489         // Save current doc view etc. around yield as paint can destroy them.
00490         View * pCurrentView = View::GetCurrent();
00491         Document * pCurrentDocument = Document::GetCurrent();
00492         AfxGetApp().Yield(TRUE);
00493         pCurrentDocument->SetCurrent();
00494         pCurrentView->SetCurrent();
00495 
00496         // resample after the yield
00497         pPrintProgressDlg->UpdateTime.Sample();
00498     }
00499 
00500     return Aborted;
00501 }
00502 
00503 
00504 #endif //webster

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