optspage.cpp

Go to the documentation of this file.
00001 // $Id: optspage.cpp 1282 2006-06-09 09:46:49Z 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 // Implementation of the Page tab of the options dialog box
00099 
00100 /*
00101 
00102 */
00103 
00104 #include "camtypes.h"
00105 #include "appprefs.h"
00106 //#include "prefsdlg.h" // dialog/gadget ids
00107 //#include "optsres.h"  // error strings
00108 #include "optspage.h"
00109 #include "optsmsgs.h"
00110 //#include "app.h"      // Camelot object - in camtypes.h [AUTOMATICALLY REMOVED]
00111 //#include "document.h" // document object - in camtypes.h [AUTOMATICALLY REMOVED]
00112 //#include "spread.h"       // spread object - in camtypes.h [AUTOMATICALLY REMOVED]
00113 #include "page.h"       // page object
00114 //#include "units.h"        // units - in camtypes.h [AUTOMATICALLY REMOVED]
00115 #include "pagesize.h"   // Page sizes available e.g. A4
00116 //#include "trans2d.h"  // 2d translation matrix - in camtypes.h [AUTOMATICALLY REMOVED]
00117 #include "layer.h"
00118 #include "progress.h"   // Begin/EndSlowJob
00119 
00120 CC_IMPLEMENT_DYNAMIC(PageTab, OptionsTabs)   
00121 
00122 CC_IMPLEMENT_DYNCREATE(OpPageResize, UndoableOperation)   
00123 CC_IMPLEMENT_DYNCREATE(ActionPageResize, Action)
00124 
00125 // This is not compulsory, but you may as well put it in so that the correct version
00126 // of your file can be registered in the .exe
00127 DECLARE_SOURCE("$Revision: 1282 $");
00128 
00129 // Set some limit to the allowed page dimensions so that cannot have stupid values
00130 // better to do this than fall over or stop rendering.
00131 // The maximum at present which we can cope with is about 2.75M.
00132 // This was determined by trial and error, and is the maximum page size that allows an
00133 // object to be placed in the Top-Right corner, without our Render Matrix overflowing
00134 // at maximum zoom (and hence the object not rendering).
00135 // Future versions of Xara, should probably dynamically limit the Zoom factor to stop this.
00136 // but limiting the Page size is easiest for now.
00137 
00138 //const MILLIPOINT MaxPageDimension = 12 * 72000 * 12;  // maximum = 12ft
00139 const MILLIPOINT MaxPageDimension = 9 * 72000 * 12;     // maximum = 108in = 9 ft = 275cm
00140 const MILLIPOINT MinPageDimension = 72000/2;            // minimum = 0.5inch
00141 
00142 /********************************************************************************************
00143 
00144 >   PageTab::PageTab() 
00145 
00146 
00147     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00148     Created:    7/12/94
00149     Inputs:     -
00150     Outputs:    -
00151     Returns:    -
00152     Purpose:    PageTab constructor. Creates a non-undoable operation
00153     Errors:     -
00154     SeeAlso:    -
00155 
00156 ********************************************************************************************/
00157 
00158 PageTab::PageTab()
00159 {   
00160     // Do nothing for now
00161     InitedPageSizeList = FALSE;
00162 }        
00163 
00164 /********************************************************************************************
00165 
00166 >   PageTab::~PageTab()
00167 
00168 
00169     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00170     Created:    7/12/94
00171     Inputs:     -
00172     Outputs:    -
00173     Returns:    -
00174     Purpose:    PageTab destructor
00175     Errors:     -
00176     SeeAlso:    -
00177 
00178 ********************************************************************************************/
00179                                                                                 
00180 PageTab::~PageTab()
00181 {   
00182 }        
00183 
00184 /********************************************************************************************
00185 
00186 >   BOOL PageTab::Init()
00187 
00188 
00189     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00190     Created:    7/12/94
00191     Inputs:     -
00192     Outputs:    -
00193     Returns:    True if initialised ok, False if failed.
00194     Purpose:    PageTab initialisation routine
00195     Errors:     -
00196     SeeAlso:    -
00197 
00198 ********************************************************************************************/
00199                                                                                 
00200 BOOL PageTab::Init()
00201 {   
00202     // Init (register) all our undoable operations
00203     if (!OpPageResize::Init())
00204         return(FALSE);
00205 
00206     return TRUE;
00207 }        
00208 
00209 
00210 /******************************************************************************************
00211 
00212 >   CDlgResID PageTab::GetPageID()()
00213 
00214     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00215     Created:    7/12/94
00216     Inputs:     -
00217     Outputs:    -
00218     Returns:    The dialog ID of this tab section.    
00219     Purpose:    Allows the options dialog code to determine the dialog ID of this section.
00220     Errors:     -
00221     SeeAlso:    -
00222 
00223 ******************************************************************************************/
00224 
00225 CDlgResID PageTab::GetPageID()
00226 {
00227     return _R(IDD_OPTSTAB_PAGE);
00228 }
00229 
00230 /******************************************************************************************
00231 
00232 >   BOOL PageTab::IsDocumentOption()
00233 
00234     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00235     Created:    14/12/94
00236     Inputs:     -
00237     Outputs:    -
00238     Returns:    Returns True if this tab is a document option.    
00239     Purpose:    Allows the document options dialog code to determine if this tab belongs
00240                 to the group of document options.
00241     Errors:     -
00242     SeeAlso:    IsProgramOption();
00243 
00244 ******************************************************************************************/
00245 
00246 BOOL PageTab::IsDocumentOption()
00247 {
00248     return TRUE;    // This tab is not a document option 
00249 }
00250 
00251 /******************************************************************************************
00252 
00253 >   BOOL PageTab::IsProgramOption()
00254 
00255     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00256     Created:    14/12/94
00257     Inputs:     -
00258     Outputs:    -
00259     Returns:    Returns True if this tab is a program option.     
00260     Purpose:    Allows the program options dialog code to determine if this tab belongs
00261                 to the group of program options.
00262     Errors:     -
00263     SeeAlso:    IsProgramOption();
00264 
00265 ******************************************************************************************/
00266 
00267 BOOL PageTab::IsProgramOption()
00268 {
00269     return TRUE;    // This tab is a program option 
00270 }
00271 
00272 
00273 /******************************************************************************************
00274 
00275 >   BOOL AppPrefsDlg::CommitSection()
00276 
00277     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00278     Created:    7/12/94
00279     Inputs:     -
00280     Outputs:    -
00281     Returns:    True if values in dialog box ok, False otherwise.     
00282     Purpose:    Takes the values in the Page section tab of the options dialog box and
00283                 sets the associated preference values accordingly
00284                 Called when ok is pressed on the dialog box.
00285     Errors:     -
00286     SeeAlso:    -
00287 
00288 ******************************************************************************************/
00289 
00290 BOOL PageTab::CommitSection()
00291 {
00292 TRACEUSER( "Neville", _T("commit page section\n"));
00293     ERROR2IF(pPrefsDlg == NULL,FALSE,"PageTab::CommitSection called with no dialog pointer");
00294 
00295     BOOL ok = pPrefsDlg->TalkToPage(_R(IDD_OPTSTAB_PAGE));  // The Page page identifier
00296     if (!ok)
00297         return TRUE;    // Talk to page failed to return now
00298 
00299     // All units work off the selected document and so we must do nothing if there is no
00300     // selected document. Check our clas variable to see if this is true or not.
00301     // Units should have been set up by the caller.
00302     if (pDocument == NULL)
00303         return (TRUE);
00304 
00305     // Ok has been pressed so take the values from this section of the dialog box
00306     BOOL Valid=0;       // Flag for validity of value
00307 //  BOOL State=0;       // Flag for state of button/switch
00308 //  BOOL SetOk=0;       // Preference value set ok
00309 
00310 
00311 
00312     // Section = Page
00313 
00314 // WEBSTER Neville 13/8/97
00315 #ifdef WEBSTER
00316     // Webster has a limited set of controls. So use the present settings on the page and just
00317     // allow the user to alter the few parameters that they can.
00318 
00319     // Find out the details on the presently selected page/spread
00320     MILLIPOINT  Width       = 0;
00321     MILLIPOINT  Height      = 0;
00322     MILLIPOINT  Margin      = 0;
00323     MILLIPOINT  Bleed       = 0;
00324     BOOL        Portrait    = TRUE;
00325     BOOL        Dps         = FALSE;
00326     BOOL        DropShadow  = FALSE;
00327 
00328     INT32 PageSizeId =0; 
00329     
00330     ok = GetSizeOfPage(&Width, &Height, &Margin, &Bleed, &Portrait, &Dps, &DropShadow);
00331     if (!ok)
00332         return FALSE;
00333 TRACEUSER( "Neville", _T("Currently Width =%d Height =%d Margin=%d Bleed=%d\n"), Width, Height, Margin, Bleed);
00334 
00335 #else
00336     // In Camelot mode, the user can change everything
00337 
00338     // First, get the current state of Portrait button
00339     BOOL Portrait = FALSE;
00340     Portrait = pPrefsDlg->GetLongGadgetValue(_R(IDC_OPTS_PORTRAIT), 0, 1, 0, &Valid);
00341 
00342     // Next, get the current values for the page width and height.
00343     // If custom use the editable fields otherwise use the actual page size from
00344     // the definition otherwise may encounter conversion errors.
00345     MILLIPOINT Width = 0;
00346     MILLIPOINT Height = 0;
00347 
00348     INT32 PageSizeSelected = CUSTOM;
00349     PageSizeSelected = pPrefsDlg->GetSelectedValueIndex(_R(IDC_OPTS_SIZELIST));
00350 
00351     if (PageSizeSelected == CUSTOM)
00352 #endif //webster
00353     {
00354         // Portrait and landscape radio buttons should have been taken care of by the switch
00355         // changing the editable fields which we are just about to read. 
00356         Height = pPrefsDlg->GetUnitGadgetValue(_R(IDC_OPTS_HEIGHT), CurrentPageUnits,
00357                                                   MinPageDimension, MaxPageDimension,
00358                                                   _R(IDE_OPTS_INVALIDHEIGHT), &Valid);
00359         if (!Valid)
00360             return FALSE;           // height incorrect, user has been warned already
00361 
00362         Width  = pPrefsDlg->GetUnitGadgetValue(_R(IDC_OPTS_WIDTH), CurrentPageUnits,
00363                                                   MinPageDimension, MaxPageDimension,
00364                                                   _R(IDE_OPTS_INVALIDWIDTH), &Valid);
00365         if (!Valid)
00366             return FALSE;           // width incorrect, user has been warned already
00367     }
00368 // WEBSTER-ranbirr-13/11/96
00369 #ifndef WEBSTER
00370     else
00371     {
00372         if (AppPrefsDlg::pPageSizesList != NULL && InitedPageSizeList)
00373         {
00374             // We will need to take account of the Portrait and landscape radio buttons and
00375             // hence swapping of the width and height fields as we are reading the values
00376             // directly from the sizes list.
00377             PageId PageChosen = (PageId)PageSizeSelected;
00378             AppPrefsDlg::pPageSizesList->GetSizeFromPageId(PageChosen, &Width, &Height);
00379 TRACEUSER( "Neville", _T("PageTab::CommitSection width %d height %d in MP\n"),Width,Height);
00380             
00381             // Now we have the width/height, check if landscape is selected and if so
00382             // swap the height and width over.
00383             if (!Portrait)
00384             {
00385                 // Swap the height and width fields over.
00386                 MILLIPOINT Temp = Width;
00387                 Width = Height;
00388                 Height = Temp;
00389             }
00390         }
00391         else
00392         {
00393             ERROR2IF(TRUE,FALSE,"Bad page sizes list in PageTab::CommitSection"); 
00394         }
00395     }
00396 
00397     // Now the page margin size
00398     // Limit the page margin to much less than the page size as things like zoom to 
00399     // spread/drawing assume that part of the spread is visible in the view so that
00400     // this can then be used to pick up the desired spread. 
00401     MILLIPOINT Margin = 0; // MinPageDimension;
00402     MILLIPOINT MaxPageMargin = MaxPageDimension;
00403     Margin = pPrefsDlg->GetUnitGadgetValue(_R(IDC_OPTS_MARGIN), CurrentPageUnits,
00404                                              MinPageDimension, MaxPageMargin,
00405                                              0, &Valid);
00406     if (Margin < 0 || Margin >= MaxPageDimension) // ignore valid as it will be false
00407     {
00408         InformError(_R(IDE_OPTS_INVALIDMARGIN));
00409         return FALSE;           // margin incorrect, user has been warned already
00410     }
00411 
00412     // Now the page bleed size
00413     MILLIPOINT Bleed = 0;
00414     BOOL BleedEnabled;
00415     BleedEnabled = pPrefsDlg->GetLongGadgetValue(_R(IDC_OPTS_BLEEDSWITCH), 0, 1, 0, &Valid);
00416     if (BleedEnabled)
00417     {
00418         const MILLIPOINT MaxBleed = (MILLIPOINT)(3 * 72000);    // maximum in inches
00419         Bleed = pPrefsDlg->GetUnitGadgetValue(_R(IDC_OPTS_BLEED), CurrentPageUnits,
00420                                                  0, MaxBleed, _R(IDE_OPTS_INVALIDBLEED), &Valid);
00421         if (!Valid)
00422             return FALSE;           // bleed incorrect, user has been warned already
00423     }
00424     else
00425         Bleed = 0;
00426 
00427     // Get current state of the double page spread button
00428     BOOL Dps = FALSE;
00429     Dps = pPrefsDlg->GetLongGadgetValue(_R(IDC_OPTS_DPS), 0, 1, 0, &Valid);
00430 
00431     // Get the current state of the drop shadow switch
00432     BOOL DropShadow = FALSE;
00433     DropShadow = pPrefsDlg->GetLongGadgetValue(_R(IDC_OPTS_SHADOW), 0, 1, 0, &Valid);
00434 #endif //webster
00435 
00436     // Check pasteboard dimensions
00437 
00438     // Possibly should get the resize operation to check this and pass back a result, as
00439     // loading dodgy documents might be possibly another way to create completely large pages.
00440 
00441     // Check if the overall size of the pasteboard will break our maximum dimensions
00442     MILLIPOINT PagesWidth = Width;
00443     if (Dps)
00444         PagesWidth += Width;    // If double page spread then make two page wide
00445     MILLIPOINT PasteBoardWidth = Margin + PagesWidth + Margin;
00446     MILLIPOINT PasteBoardHeight = Margin + Height + Margin;
00447     if (PasteBoardWidth > MaxPageDimension || PasteBoardHeight > MaxPageDimension)
00448     {
00449         // There is a problem so warn the user that the value is incorrect
00450         InformWarning(_R(IDE_OPTS_OVERALLSPREADSIZE));
00451         return FALSE;
00452     }
00453 
00454 
00455 
00456     // Go and make those requested changes
00457 
00458     // Now that we have the required information, now go and do it
00459     // Set up the parameters which we require to do the page resizing operation 
00460     // This is undoable and redoable
00461     PageResizeInfo Param;
00462 
00463     // Set up the new page parameters that we want
00464     Param.Height         = Height;
00465     Param.Width          = Width;
00466     Param.Margin         = Margin;
00467     Param.Bleed          = Bleed;
00468     Param.Portrait       = Portrait;
00469     Param.Dps            = Dps;
00470     Param.ShowDropShadow = DropShadow;
00471 
00472     InvokeResize(&Param);
00473 
00474     return ok;
00475 }
00476 
00477 /******************************************************************************************
00478 
00479 >   BOOL PageTab::NewUnitsInSection()
00480 
00481     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00482     Created:    5/1/95
00483     Inputs:     -
00484     Outputs:    -
00485     Returns:    True if values in dialog box ok, False otherwise.     
00486     Purpose:    Function called when new default units come into operation. We must convert
00487                 all units fields to display in the newly specified units.
00488     Errors:     -
00489     SeeAlso:    -
00490 
00491 ******************************************************************************************/
00492 
00493 BOOL PageTab::NewUnitsInSection()
00494 {
00495 TRACEUSER( "Neville", _T("New units in page section\n"));
00496     ERROR2IF(pPrefsDlg == NULL,FALSE,"PageTab::NewUnitsInSection called with no dialog pointer");
00497 
00498     BOOL ok = pPrefsDlg->TalkToPage(_R(IDD_OPTSTAB_PAGE));  // The page tab identifier
00499     if (!ok)
00500         return TRUE;    // Talk to page failed to return now
00501 
00502 
00503     // All units work off the selected document and so we must do nothing if there is no
00504     // selected document. Check our clas variable to see if this is true or not.
00505     // Units should have been set up by the caller.
00506     if (pDocument == NULL)
00507     {
00508         // the dialog box is greyed.
00509         GreySection();
00510         return (TRUE);
00511     }
00512 
00513     // Do the same things as the normal init section code
00514     InitPageSection();
00515 
00516     return TRUE;
00517 }
00518 
00519 
00520 /********************************************************************************************
00521 
00522 >   BOOL PageTab::GreySection()
00523 
00524     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00525     Created:    3/2/95
00526     Inputs:     -
00527     Outputs:    -
00528     Returns:    -
00529     Purpose:    Called when the user has closed all documents 
00530     Errors:     -
00531     SeeAlso:    PageTab::UngreySection;
00532 
00533 ********************************************************************************************/
00534 
00535 BOOL PageTab::GreySection()
00536 {
00537 TRACEUSER( "Neville", _T("GreySection in page section\n"));
00538     ERROR2IF(pPrefsDlg == NULL,FALSE,"PageTab::GreySection called with no dialog pointer");
00539 
00540     BOOL ok = pPrefsDlg->TalkToPage(_R(IDD_OPTSTAB_PAGE));  // The page tab identifier
00541     if (!ok)
00542         return TRUE;    // Talk to page failed to return now
00543 
00544     // Make sure the information field displaying the name of the current document
00545     // is correct.
00546     String_256  DocumentName(_R(IDT_OPTS_PAGE_INFO)); 
00547     DocumentName += *GetDocumentName();
00548     pPrefsDlg->SetStringGadgetValue(_R(IDC_OPTS_INFO), DocumentName);
00549 
00550     // Only update if we are not already grey 
00551     if (GreyStatus == TRUE)
00552         return TRUE;
00553 
00554     // Call our central greying/ungreying function
00555     ok = ChangeControlStatus(FALSE);
00556     
00557     GreyStatus = TRUE;
00558 
00559     return ok;
00560 } 
00561 
00562 /********************************************************************************************
00563 
00564 >   BOOL PageTab::UngreySection()
00565 
00566     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00567     Created:    3/2/95
00568     Inputs:     -
00569     Outputs:    -
00570     Returns:    -
00571     Purpose:    Called when the user has selected a new document 
00572     Errors:     -
00573     SeeAlso:    PageTab::UngreySection;
00574 
00575 ********************************************************************************************/
00576 
00577 BOOL PageTab::UngreySection()
00578 {
00579 TRACEUSER( "Neville", _T("UngreySection in page section\n"));
00580     ERROR2IF(pPrefsDlg == NULL,FALSE,"PageTab::UngreySection called with no dialog pointer");
00581 
00582     BOOL ok = pPrefsDlg->TalkToPage(_R(IDD_OPTSTAB_PAGE));  // The page tab identifier
00583     if (!ok)
00584         return TRUE;    // Talk to page failed to return now
00585 
00586     // Make sure the information field displaying the name of the current document
00587     // is correct.
00588     String_256  DocumentName(_R(IDT_OPTS_PAGE_INFO)); 
00589     DocumentName += *GetDocumentName();
00590     pPrefsDlg->SetStringGadgetValue(_R(IDC_OPTS_INFO), DocumentName);
00591 
00592     // Only update if we are not already ungrey 
00593     if (GreyStatus == FALSE)
00594         return TRUE;
00595 
00596     // Call our central greying/ungreying function
00597     ok = ChangeControlStatus(TRUE);
00598     
00599     GreyStatus = FALSE;
00600 
00601     return ok;
00602 }
00603 
00604 /********************************************************************************************
00605 
00606 >   BOOL PageTab::ChangeControlStatus(const BOOL Status)
00607 
00608     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00609     Created:    3/2/95
00610     Inputs:     -
00611     Outputs:    -
00612     Returns:    -
00613     Purpose:    Called to grey/ungrey all controls on this tab. 
00614     Errors:     -
00615     SeeAlso:    PageTab::GreySection;   PageTab::UngreySection;
00616 
00617 ********************************************************************************************/
00618 
00619 BOOL PageTab::ChangeControlStatus(const BOOL Status)
00620 {
00621     // Grey/Ungrey the controls
00622     pPrefsDlg->EnableGadget(_R(IDC_OPTS_INFO), Status);
00623 
00624     pPrefsDlg->EnableGadget(_R(IDC_OPTS_PAGEGROUP), Status);
00625     pPrefsDlg->EnableGadget(_R(IDC_OPTS_SIZENAME), Status);
00626     pPrefsDlg->EnableGadget(_R(IDN_PAGESIZE_CUSTOM), Status);
00627 // WEBSTER-ranbirr-13/11/96
00628 #ifndef WEBSTER
00629     pPrefsDlg->EnableGadget(_R(IDC_OPTS_SIZELIST), Status);
00630 #endif //webster
00631     pPrefsDlg->EnableGadget(_R(IDC_OPTS_HEIGHTTXT), Status);
00632     pPrefsDlg->EnableGadget(_R(IDC_OPTS_HEIGHT), Status);
00633     pPrefsDlg->EnableGadget(_R(IDC_OPTS_WIDTHTXT), Status);
00634     pPrefsDlg->EnableGadget(_R(IDC_OPTS_WIDTH), Status);
00635     pPrefsDlg->EnableGadget(_R(IDC_OPTS_ORIENTGROUP), Status);
00636 
00637 // WEBSTER-ranbirr-13/11/96
00638 #ifndef WEBSTER
00639     pPrefsDlg->EnableGadget(_R(IDC_OPTS_PORTRAIT), Status);
00640     pPrefsDlg->EnableGadget(_R(IDC_OPTS_LANDSCAPE), Status);
00641 
00642     pPrefsDlg->EnableGadget(_R(IDC_OPTS_SPREADGROUP), Status);
00643     pPrefsDlg->EnableGadget(_R(IDC_OPTS_MARGINTXT), Status);
00644     pPrefsDlg->EnableGadget(_R(IDC_OPTS_MARGIN), Status);
00645     pPrefsDlg->EnableGadget(_R(IDC_OPTS_BLEEDSWITCH), Status);
00646     pPrefsDlg->EnableGadget(_R(IDC_OPTS_BLEED), Status);
00647     pPrefsDlg->EnableGadget(_R(IDC_OPTS_BLEEDTXT), Status);
00648     pPrefsDlg->EnableGadget(_R(IDC_OPTS_DPS), Status);
00649     pPrefsDlg->EnableGadget(_R(IDC_OPTS_SHADOW), Status);
00650 #endif //webster
00651     return TRUE;
00652 }           
00653 
00654 /********************************************************************************************
00655 
00656 >   BOOL PageTab::UpdateSection(String_256 *DocumentName)
00657 
00658     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00659     Created:    3/2/95
00660     Inputs:     Name of document
00661     Outputs:    -
00662     Returns:    -
00663     Purpose:    Called when we have switched to a new document and need to update all the 
00664                 controls on this tab. Should only init the tab if the page is present.  
00665                 The document name allows the info field on the tab to be filled in correctly.
00666     Errors:     -
00667     SeeAlso:    PageTab::GreySection; PageTab::UngreySection; PageTab::InitSection;
00668 
00669 ********************************************************************************************/
00670 
00671 BOOL PageTab::UpdateSection(String_256 *DocumentName)
00672 {
00673 TRACEUSER( "Neville", _T("PageTab::UpdateSection\n"));
00674     ERROR2IF(pPrefsDlg == NULL,FALSE,"PageTab::UpdateSection called with no dialog pointer");
00675 
00676     BOOL ok = pPrefsDlg->TalkToPage(_R(IDD_OPTSTAB_PAGE));  // The Page page identifier
00677     if (!ok)
00678         return TRUE;        // page not present
00679 
00680     // Do everything the same as the InitSection but do not init the page size list as this
00681     // causes a huge redraw.
00682     
00683     // Make sure the information field displaying the name of the current document
00684     // is correct.
00685     String_256  DocName(_R(IDT_OPTS_PAGE_INFO)); 
00686     DocName +=  *DocumentName;
00687     pPrefsDlg->SetStringGadgetValue(_R(IDC_OPTS_INFO), DocName);
00688 
00689 
00690     // All units work off the selected document and so we must do nothing if there is no
00691     // selected document. Check our clas variable to see if this is true or not.
00692     // Units should have been set up by the caller.
00693     if (pDocument == NULL)
00694     {
00695         // If returns False then we are in an invalid situation and so should make sure that
00696         // the dialog box is greyed.
00697         GreySection();
00698         return TRUE;
00699     }
00700 
00701     // Check if we have an uninitialised page sizes list
00702     if (!InitedPageSizeList)
00703     {
00704         // Set up the list of available page size options, starting with the default.
00705         // Handle everything that we do not know as a CUSTOM setting.
00706         SetUpPageSizeList();
00707     }
00708 
00709     // Do the same things as the normal init section code
00710     InitPageSection();
00711 
00712     return TRUE;
00713 }
00714 
00715 /********************************************************************************************
00716 
00717 >   BOOL PageTab::UpdatePageSection()
00718 
00719     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00720     Created:    3/3/95
00721     Inputs:     -
00722     Outputs:    -
00723     Returns:    -
00724     Purpose:    Called when we have undone a page resize operation and hence need to update the 
00725                 page's details on the page section of this tab.
00726                 Should only init the tab if the page is present.  
00727     Errors:     -
00728     SeeAlso:    PageTab::GreySection; PageTab::UngreySection; PageTab::InitSection;
00729 
00730 ********************************************************************************************/
00731 
00732 BOOL PageTab::UpdatePageSection()
00733 {
00734 TRACEUSER( "Neville", _T("PageTab::UpdatePageSection\n"));
00735     ERROR2IF(pPrefsDlg == NULL,FALSE,"PageTab::UpdatePageSection called with no dialog pointer");
00736 
00737     BOOL ok = pPrefsDlg->TalkToPage(_R(IDD_OPTSTAB_PAGE));  // The Page page identifier
00738     if (!ok)
00739         return TRUE;        // page not present
00740 
00741     // Do everything the same as the InitSection but do not init the page size list as this
00742     // causes a huge redraw.
00743 
00744     // All units work off the selected document and so we must do nothing if there is no
00745     // selected document. Check our clas variable to see if this is true or not.
00746     // Units should have been set up by the caller.
00747     if (pDocument == NULL)
00748     {
00749         // If returns False then we are in an invalid situation and so should make sure that
00750         // the dialog box is greyed.
00751         GreySection();
00752         return (TRUE);
00753     }
00754     
00755     // Check if we have an uninitialised page sizes list
00756     if (!InitedPageSizeList)
00757     {
00758         // Remove any lists that we have created.
00759         //pPrefsDlg->DeleteAllValues(_R(IDC_OPTS_SIZELIST));
00760         //InitedPageSizeList = FALSE;
00761 
00762         // Set up the list of available page size options, starting with the default.
00763         // Handle everything that we do not know as a CUSTOM setting.
00764         SetUpPageSizeList();
00765     }
00766 
00767     // Call the normal init section code for the page parts
00768     return InitPageSection();
00769 }
00770 
00771 
00772 /********************************************************************************************
00773 
00774 >   BOOL PageTab::HandleMsg(DialogMsg* Msg)
00775 
00776     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00777     Created:    7/12/94
00778     Inputs:     -
00779     Outputs:    -
00780     Returns:    -
00781     Purpose:    Handles all the Page options tabs messages 
00782     Errors:     -
00783     SeeAlso:    -
00784 
00785 ********************************************************************************************/
00786 
00787 BOOL PageTab::HandleMsg(DialogMsg* Msg)
00788 {
00789 TRACEUSER( "Neville", _T("HandlePageMsg\n"));
00790     ERROR2IF(Msg == NULL,FALSE,"PageTab::Message null message received");
00791     ERROR2IF(pPrefsDlg == NULL,FALSE,"PageTab::HandleMsg called with no dialog pointer");
00792 
00793     BOOL ok = pPrefsDlg->TalkToPage(_R(IDD_OPTSTAB_PAGE));  // The Page page identifier
00794     if (!ok)
00795         return TRUE;        // page not present
00796 
00797     switch(Msg->DlgMsg)
00798     {
00799         case DIM_CREATE:    // Initialise controls
00800             GreyStatus = FALSE; // we are ungreyed by default
00801             ok = InitSection();
00802             if (!ok)
00803                 InformError();
00804             break;
00805         case DIM_SELECTION_CHANGED:
00806             OptionsTabs::SetApplyNowState(TRUE);
00807     // WEBSTER-ranbirr-13/11/96
00808     #ifndef WEBSTER
00809             if (Msg->GadgetID == _R(IDC_OPTS_SIZELIST))
00810             {
00811                 // Get the currently selected item and set up the other fields accordingly 
00812                 INT32 PageSizeSelected;
00813                 PageSizeSelected = pPrefsDlg->GetSelectedValueIndex(_R(IDC_OPTS_SIZELIST));
00814                 // Get whether we are in Portrait or Landscape mode
00815                 BOOL Portrait;
00816                 BOOL Valid;
00817                 Portrait = pPrefsDlg->GetLongGadgetValue(_R(IDC_OPTS_PORTRAIT), 0, 1, 0, &Valid);
00818                 HandlePageList(PageSizeSelected, Portrait);
00819                 break;
00820             }
00821         case DIM_LFT_BN_CLICKED:
00822             OptionsTabs::SetApplyNowState(TRUE);
00823             if (FALSE) {}
00824             // WEBSTER-ranbirr-13/11/96
00825             #ifndef WEBSTER
00826             else if ((Msg->GadgetID == _R(IDC_OPTS_PORTRAIT)) || (Msg->GadgetID == _R(IDC_OPTS_LANDSCAPE)))
00827                 // Portrait landscape buttons toggle the width/height fields
00828                 HandlePortraitLandscape();
00829             #endif // Webster
00830             else if (Msg->GadgetID == _R(IDC_OPTS_BLEEDSWITCH))
00831             {
00832                 // Bleed switch enables or disables the bleed size field 
00833                 BOOL BleedEnabled;
00834                 BOOL Valid;
00835                 BleedEnabled = pPrefsDlg->GetLongGadgetValue(_R(IDC_OPTS_BLEEDSWITCH), 0, 1, 0, &Valid);
00836                 if (BleedEnabled)
00837                 {
00838                     pPrefsDlg->EnableGadget(_R(IDC_OPTS_BLEED), TRUE);
00839                     pPrefsDlg->EnableGadget(_R(IDC_OPTS_BLEEDTXT), TRUE);
00840                 }
00841                 else
00842                 {
00843                     pPrefsDlg->EnableGadget(_R(IDC_OPTS_BLEED), FALSE);
00844                     pPrefsDlg->EnableGadget(_R(IDC_OPTS_BLEEDTXT), FALSE);
00845                 }                                                   
00846             }
00847     #endif //webster    
00848         case DIM_TEXT_CHANGED:
00849             OptionsTabs::SetApplyNowState(TRUE);
00850             break;
00851         default:
00852             break;
00853     }
00854     
00855     return TRUE;
00856 }  
00857 
00858 
00859 /******************************************************************************************
00860 
00861 >   BOOL PageTab::InitSection()
00862 
00863     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00864     Created:    6/12/94
00865     Inputs:     -
00866     Outputs:    -
00867     Returns:    TRUE if successful, else FALSE
00868     Purpose:    Sets initial values for the Page section of the options dialog box.
00869                 This section includes the:-
00870     Errors:     -
00871     SeeAlso:    AppPrefsDlg; OptionsTabs; UpdateSection;
00872 
00873 ******************************************************************************************/
00874 
00875 BOOL PageTab::InitSection()
00876 {
00877 TRACEUSER( "Neville", _T("InitPageSection\n"));
00878     ERROR2IF(pPrefsDlg == NULL,FALSE,"PageTab::InitSection called with no dialog pointer");
00879     ERROR2IF(AppPrefsDlg::pPageSizesList == NULL,FALSE,"PageTab::InitSection called with list of page sizes");
00880 
00881 //  BOOL ok = TRUE;         // Flag for whether value set up ok 
00882 
00883     // We have an uninitialised page sizes list, so flag that before we have a chance to exit
00884     pPrefsDlg->DeleteAllValues(_R(IDC_OPTS_SIZELIST));
00885     InitedPageSizeList = FALSE;
00886 
00887     // Do everything the same as the UpdateSection but init the page size list for this
00888     // once and only time to stop redraws.
00889 
00890     // Make sure the information field displaying the name of the current document
00891     // is correct.
00892     String_256  DocumentName(_R(IDT_OPTS_PAGE_INFO)); 
00893     DocumentName += *GetDocumentName();
00894     pPrefsDlg->SetStringGadgetValue(_R(IDC_OPTS_INFO), DocumentName);
00895 
00896 
00897     // All units work off the selected document and so we must do nothing if there is no
00898     // selected document. Check our clas variable to see if this is true or not.
00899     // Units should have been set up by the caller.
00900     if (pDocument == NULL)
00901     {
00902         // If returns False then we are in an invalid situation and so should make sure that
00903         // the dialog box is greyed.
00904         GreySection();
00905         return (TRUE);
00906     }
00907 
00908     // Set up the list of available page size options, starting with the default.
00909     // Handle everything that we do not know as a CUSTOM setting.
00910     SetUpPageSizeList();
00911 
00912     InitPageSection();
00913 
00914     return TRUE;
00915 }
00916 
00917 /******************************************************************************************
00918 
00919 >   BOOL PageTab::SetUpPageSizeList()
00920 
00921     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00922     Created:    30/3/95
00923     Outputs:    -
00924     Returns:    TRUE if successful, else FALSE
00925     Purpose:    Sets up the pages sizes list in the Page tab on the options dialog box.
00926                 Done separately to InitPageSection so that code is modular and should only
00927                 be used once when the page is set up and not on updates otherwise you get
00928                 the drop list causing a huge redraw problem. 
00929     Errors:     -
00930     SeeAlso:    InitSection; InitPageSection; AppPrefsDlg; OptionsTabs;
00931 
00932 ******************************************************************************************/
00933 
00934 BOOL PageTab::SetUpPageSizeList()
00935 {
00936     // already set this up so don't do it again
00937     if (InitedPageSizeList)
00938         return TRUE;
00939 
00940     // Set up the list of available page size options, starting with the default.
00941     // Handle everything that we do not know as a CUSTOM setting.
00942 // WEBSTER-ranbirr-13/11/96
00943 #ifndef WEBSTER
00944     pPrefsDlg->SetStringGadgetValue(_R(IDC_OPTS_SIZELIST), String_32(_R(IDN_PAGESIZE_CUSTOM)));
00945 #endif //webster
00946 
00947     // Now go through the defined list
00948     PageSize* pPageSize = (PageSize*) AppPrefsDlg::pPageSizesList->GetFirstPageSize();
00949 
00950     while (pPageSize != NULL)
00951     {
00952         // Get the name of the current page size item
00953         String_32 *pPageName = pPageSize->GetPageName();
00954 // WEBSTER-ranbirr-13/11/96
00955 #ifndef WEBSTER
00956         pPrefsDlg->SetStringGadgetValue(_R(IDC_OPTS_SIZELIST), *pPageName);
00957 #endif //webster
00958         // skip to the next item, if there is one
00959         pPageSize = (PageSize*) AppPrefsDlg::pPageSizesList->GetNextPageSize(pPageSize);
00960     }
00961 // WEBSTER-ranbirr-13/11/96
00962 #ifndef WEBSTER
00963     pPrefsDlg->SetComboListLength(_R(IDC_OPTS_SIZELIST));
00964 #endif //webster
00965     // It is now set up and correct
00966     InitedPageSizeList = TRUE;
00967 
00968     return TRUE;
00969 }   
00970 
00971 /******************************************************************************************
00972 
00973 >   BOOL PageTab::InitPageSection()
00974 
00975     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00976     Created:    3/3/95
00977     Outputs:    -
00978     Returns:    TRUE if successful, else FALSE
00979     Purpose:    Sets initial values for the page details section of the Page tab on the
00980                 options dialog box.
00981     Errors:     -
00982     SeeAlso:    InitSection; AppPrefsDlg; OptionsTabs;
00983 
00984 ******************************************************************************************/
00985 
00986 BOOL PageTab::InitPageSection()
00987 {
00988     BOOL ok = TRUE;
00989 
00990     // Section = Page
00991 
00992     // List size done elsewhere so that only ever done once and not on updates as well.
00993 
00994     // Find out the details on the presently selected page/spread
00995     MILLIPOINT Width = 0;
00996     MILLIPOINT Height = 0;
00997     MILLIPOINT Margin = 0;
00998     MILLIPOINT Bleed = 0;
00999     PortraitSelected = TRUE;
01000     BOOL Dps = FALSE;
01001 // WEBSTER-ranbirr-13/11/96
01002 #ifndef WEBSTER
01003     BOOL PageShadow = TRUE;
01004 #else
01005     BOOL PageShadow = FALSE;
01006 #endif //webster
01007 
01008     INT32 PageSizeId =0; 
01009     
01010     ok = GetSizeOfPage(&Width, &Height, &Margin, &Bleed, &PortraitSelected, &Dps, &PageShadow);
01011     if (!ok)
01012         return FALSE;
01013 TRACEUSER( "Neville", _T("Width =%d Height =%d Margin=%d Bleed=%d\n"), Width, Height, Margin, Bleed);
01014 
01015     PageSizeId = GetPageSizeItem(Width, Height);
01016 TRACEUSER( "Neville", _T("PageSize =%d \n"), PageSizeId);
01017     // Set up the default option displayed
01018 // WEBSTER-ranbirr-13/11/96
01019 #ifndef WEBSTER
01020     ok = pPrefsDlg->SetSelectedValueIndex(_R(IDC_OPTS_SIZELIST),PageSizeId);
01021 
01022     // Get the current portrait/landscape state orientation
01023     if ( PortraitSelected != FALSE )
01024     {
01025         pPrefsDlg->SetLongGadgetValue(_R(IDC_OPTS_PORTRAIT), TRUE);
01026         pPrefsDlg->SetLongGadgetValue(_R(IDC_OPTS_LANDSCAPE), FALSE);
01027     }
01028     else
01029     {
01030         pPrefsDlg->SetLongGadgetValue(_R(IDC_OPTS_PORTRAIT), FALSE);
01031         pPrefsDlg->SetLongGadgetValue(_R(IDC_OPTS_LANDSCAPE), TRUE);
01032     }
01033 #endif //webster
01034     // Now set up and enable/disable the height and width fields accordingly
01035     // If not Portrait i.e. Landscape then swap the width and the height fields over 
01036     if (PortraitSelected == FALSE)
01037     {
01038         // Swap width for height
01039         MILLIPOINT Temp = Width;
01040         Width = Height;
01041         Height = Temp;
01042     }   
01043     // Now set up the height and width fields accordingly
01044     ok = pPrefsDlg->SetUnitGadgetValue(_R(IDC_OPTS_HEIGHT), CurrentPageUnits, Height, FALSE, -1);
01045     ok = pPrefsDlg->SetUnitGadgetValue(_R(IDC_OPTS_WIDTH), CurrentPageUnits, Width, FALSE, -1);
01046     BOOL Enable;
01047 // WEBSTER-ranbirr-13/11/96
01048 #ifndef WEBSTER
01049     if (PageSizeId == CUSTOM)
01050         Enable = TRUE;
01051     else
01052         Enable = FALSE; 
01053 #endif //webster
01054     // Enable should be True if the custom page size has been selected.
01055     pPrefsDlg->EnableGadget(_R(IDC_OPTS_HEIGHT), Enable);
01056     pPrefsDlg->EnableGadget(_R(IDC_OPTS_WIDTH), Enable);
01057 // WEBSTER-ranbirr-13/11/96
01058 #ifndef WEBSTER
01059     // Now show the current page Margin
01060     ok = pPrefsDlg->SetUnitGadgetValue(_R(IDC_OPTS_MARGIN), CurrentPageUnits, Margin, FALSE, -1);
01061 #endif //webster
01062     // Now show the current page bleed, setting or unsetting the switch accordingly
01063     // and greying/ungreying the size field accordingly.
01064     BOOL BleedEnabled;
01065     if (Bleed == 0)
01066     {
01067         // No bleed
01068         BleedEnabled = FALSE;
01069     }
01070     else
01071     {
01072         // Bleed present
01073         BleedEnabled = TRUE;
01074     }
01075 // WEBSTER-ranbirr-13/11/96
01076 #ifndef WEBSTER
01077     pPrefsDlg->SetLongGadgetValue(_R(IDC_OPTS_BLEEDSWITCH), BleedEnabled);
01078     pPrefsDlg->EnableGadget(_R(IDC_OPTS_BLEED), BleedEnabled);
01079     pPrefsDlg->EnableGadget(_R(IDC_OPTS_BLEEDTXT), BleedEnabled);
01080 #endif //webster
01081     // If the bleed is zero and disabled then fill in a default value of 3mm
01082     if ((Bleed == 0) && (!BleedEnabled))
01083     {
01084 // WEBSTER-ranbirr-13/11/96
01085 #ifndef WEBSTER
01086         Bleed = (MILLIPOINT)(3 * MM_MP_VAL);    // 3mm in millipoints
01087 #else
01088         Bleed = 0;
01089 #endif //webster
01090     }
01091 
01092     // Now show the current value
01093     // WEBSTER-ranbirr-13/11/96
01094 #ifndef WEBSTER
01095     ok = pPrefsDlg->SetUnitGadgetValue(_R(IDC_OPTS_BLEED), CurrentPageUnits, Bleed, FALSE, -1);
01096     // Now for the double page spread button
01097     pPrefsDlg->SetLongGadgetValue(_R(IDC_OPTS_DPS), Dps);
01098     // Now for the show page shadow
01099     pPrefsDlg->SetLongGadgetValue(_R(IDC_OPTS_SHADOW), PageShadow);
01100 #endif //webster
01101 
01102     return TRUE;
01103 }
01104 
01105 /******************************************************************************************
01106 
01107 >   INT32   PageTab::GetPageSizeItem(const MILLIPOINT Width, const MILLIPOINT Height)
01108 
01109     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01110     Created:    9/12/94
01111     Inputs:     Width   width of current page in millipoints
01112                 Height  height of current page in millipoints
01113     Outputs:    Type of page found according to position on list
01114     Returns:    -
01115     Purpose:    Translates a width or height into a number which specifies whether it
01116                 is A0, A1 ... or custom which corresponds to the list offered to the
01117                 user. 
01118     Errors:     -
01119     SeeAlso:    -
01120 
01121 ******************************************************************************************/
01122 
01123 INT32   PageTab::GetPageSizeItem(const MILLIPOINT Width, const MILLIPOINT Height)
01124 {    
01125     PageId ItemInList = CUSTOM;     // set useful default of CUSTOM
01126 
01127     if (AppPrefsDlg::pPageSizesList != NULL)
01128     {
01129         // Use the PageSize and PageSizesList classes to work out if this is a known page
01130         // size or if it is regarded as a custom one.
01131         ItemInList = AppPrefsDlg::pPageSizesList->GetPageIdFromSize(Width, Height);
01132 TRACEUSER( "Neville", _T("PageTab::GetPageSizeItem width %d height %d give item = %d\n"),Width,Height,ItemInList);
01133     }
01134 
01135     return (INT32) ItemInList;  
01136 }
01137 
01138 /******************************************************************************************
01139 
01140 >   BOOL    PageTab::HandlePageList(INT32 ItemClicked, BOOL Portrait)
01141 
01142     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01143     Created:    9/12/94
01144     Inputs:     ItemClicked     number of item clicked in list
01145                 Portrait        True if Portrait, False if Landscape.
01146     Outputs:    -
01147     Returns:    -
01148     Purpose:    Sets up the height and width fields according to the item selected in the
01149                 list.
01150     Errors:     -
01151     SeeAlso:    -
01152 
01153 ******************************************************************************************/
01154 
01155 BOOL    PageTab::HandlePageList(INT32 ItemClicked, BOOL Portrait)
01156 {    
01157     ERROR2IF(pPrefsDlg == NULL,FALSE,"PageTab::HandlePageList called with no dialog pointer");
01158 
01159     // Now enable or disable and fill in the height and width fields dependent
01160     // on what size has been selected in the list of available pages. 
01161     BOOL Enable;
01162     BOOL ok;
01163     MILLIPOINT Width = 0;
01164     MILLIPOINT Height = 0;
01165 
01166     if ( ItemClicked == CUSTOM)
01167     {
01168         // If custom then just ungrey the present width/height editable fields
01169         Enable = TRUE;
01170     }
01171     else
01172     {
01173         Enable = FALSE;
01174         PageId PageChosen = (PageId)ItemClicked;
01175         if (AppPrefsDlg::pPageSizesList != NULL)
01176         {
01177             AppPrefsDlg::pPageSizesList->GetSizeFromPageId(PageChosen, &Width, &Height);
01178 TRACEUSER( "Neville", _T("PageTab::HandlePageList width %d height %d in MP\n"),Width,Height);
01179         }
01180 
01181         // If not Portrait i.e. Landscape then swap the width and the height fields over 
01182         if (Portrait == FALSE)
01183         {
01184             // Swap width for height
01185             MILLIPOINT Temp = Width;
01186             Width = Height;
01187             Height = Temp;
01188         }   
01189         // Now set up the height and width fields accordingly
01190         ok = pPrefsDlg->SetUnitGadgetValue(_R(IDC_OPTS_HEIGHT), CurrentPageUnits,
01191                                              Height, FALSE, -1);
01192         ok = pPrefsDlg->SetUnitGadgetValue(_R(IDC_OPTS_WIDTH), CurrentPageUnits,
01193                                              Width, FALSE, -1);
01194     }   
01195     
01196     // Enable should be True if the custom page size has been selected.
01197     pPrefsDlg->EnableGadget(_R(IDC_OPTS_HEIGHT), Enable);
01198     pPrefsDlg->EnableGadget(_R(IDC_OPTS_WIDTH), Enable);
01199 
01200     return TRUE;
01201 }
01202 
01203 /******************************************************************************************
01204 
01205 >   BOOL    PageTab::HandlePortraitLandscape()
01206 
01207     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01208     Created:    9/12/94
01209     Purpose:    Checks to see if Portrait or Landscape has been selected. If a change has
01210                 been made then swaps the height and width fields over.
01211     Errors:     -
01212     SeeAlso:    -
01213 
01214 ******************************************************************************************/
01215 
01216 // WEBSTER-ranbirr-13/11/96
01217 #ifndef WEBSTER
01218 BOOL    PageTab::HandlePortraitLandscape()
01219 {
01220     ERROR2IF(pPrefsDlg == NULL,FALSE,"PageTab::HandlePortraitLandscape called with no dialog pointer");
01221 
01222     // Get current state of Portrait button
01223     BOOL Portrait;
01224     BOOL Valid;
01225     Portrait = pPrefsDlg->GetLongGadgetValue(_R(IDC_OPTS_PORTRAIT), 0, 1, 0, &Valid);
01226 
01227     // Check for change of state, if none then exit now
01228     if (Portrait == PortraitSelected)
01229         return TRUE;
01230 
01231 TRACEUSER( "Neville", _T("PageTab::HandlePortraitLandscape() change state\n"));
01232     // We have changed so swap the height and the width fields over
01233     // First, get the current values from the editable fields
01234     MILLIPOINT Width = 0;
01235     MILLIPOINT Height = 0;
01236     BOOL ok;
01237     Height = pPrefsDlg->GetUnitGadgetValue(_R(IDC_OPTS_HEIGHT), CurrentPageUnits,
01238                                               0, INT_MAX, _R(IDE_OPTS_INVALIDHEIGHT), &Valid);
01239     if (!Valid)
01240     {
01241         // failed to read correct value so return switch to known position and exit
01242         pPrefsDlg->SetLongGadgetValue(_R(IDC_OPTS_PORTRAIT), PortraitSelected);
01243         pPrefsDlg->SetLongGadgetValue(_R(IDC_OPTS_LANDSCAPE), !PortraitSelected);
01244         return FALSE;           
01245     }
01246     Width  = pPrefsDlg->GetUnitGadgetValue(_R(IDC_OPTS_WIDTH), CurrentPageUnits,
01247                                               0, INT_MAX, _R(IDE_OPTS_INVALIDWIDTH), &Valid);
01248     if (!Valid)
01249     {
01250         // failed to read correct value so return switch to known position and exit
01251         pPrefsDlg->SetLongGadgetValue(_R(IDC_OPTS_PORTRAIT), PortraitSelected);
01252         pPrefsDlg->SetLongGadgetValue(_R(IDC_OPTS_LANDSCAPE), !PortraitSelected);
01253         return FALSE;           
01254     }
01255 
01256     // Now set up the height and width fields reversly
01257     ok = pPrefsDlg->SetUnitGadgetValue(_R(IDC_OPTS_HEIGHT), CurrentPageUnits,
01258                                           Width, FALSE, -1);
01259     ok = pPrefsDlg->SetUnitGadgetValue(_R(IDC_OPTS_WIDTH), CurrentPageUnits,
01260                                           Height, FALSE, -1);
01261     
01262     // Now update the stored present state to the new state 
01263     PortraitSelected = Portrait;
01264 
01265     return TRUE;
01266 }    
01267 #endif //webster
01268 
01269 /******************************************************************************************
01270 
01271 >   BOOL    PageTab::GetSizeOfPage(MILLIPOINT *Width, MILLIPOINT *Height, MILLIPOINT *Bleed,
01272                                    BOOL *Portrait, BOOL *Dps, BOOL *ShowDropShadow)
01273 
01274     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01275     Created:    9/12/94
01276     Outputs:    Width           found page width in millipoints
01277                 Height          found page height in millipoints
01278                 Margin          found page margin in millipoints
01279                 Bleed           found page bleed in millipoints
01280                 Portrait        set TRUE if found Width smaller than height
01281                 Dps             set TRUE if double page spread present
01282                 ShowDropShadow  set TRUE if currently displaying a drop shadow
01283     Returns:    True if found the details ok.
01284     Purpose:    Checks to see what the size of the first page in the first spread in
01285                 the document is and returns the width and height of it.
01286                 Assumes at present a fairly simple document structure.
01287                 Assumes the class variables pDocument, pSpread have been set up.
01288     Errors:     -
01289     SeeAlso:    AppPrefsDlg::SetCurrentSpread;
01290 
01291 ******************************************************************************************/
01292 
01293 BOOL PageTab::GetSizeOfPage(MILLIPOINT *Width, MILLIPOINT *Height, MILLIPOINT *Margin,
01294                             MILLIPOINT *Bleed, BOOL *Portrait, BOOL *Dps, BOOL *ShowDropShadow)
01295 {
01296     // Set up defaults in case of dodgy exit
01297     *Width  = 0;
01298     *Height = 0;
01299     *Margin  = 0;
01300     *Bleed  = 0;
01301     *Portrait = TRUE;
01302     *Dps = FALSE;
01303     //   WEBSTER-ranbirr-13/11/96
01304 #ifndef WEBSTER
01305     *ShowDropShadow = TRUE;
01306 #else   //webster has no page shadow.       
01307     *ShowDropShadow = FALSE;
01308 #endif  //webster
01309 
01310     // The dialog handler should have already set up the class variables pDocument and pSpread.
01311     // We will check that they are not null.
01312     // For now, get details on 1st page of spread 1
01313     ERROR2IF(pDocument == NULL,FALSE,"PageTab::GetSizeOfPage no selected document");
01314     ERROR2IF(pSpread == NULL,FALSE,"PageTab::GetSizeOfPage no spread to work on");
01315 
01316     // Set up some interim variables
01317     MILLIPOINT PageWidth = *Width;
01318     MILLIPOINT PageHeight = *Height;
01319     MILLIPOINT PageMargin = *Margin;
01320     MILLIPOINT PageBleed = *Bleed;
01321     BOOL Pages = *Dps;
01322     BOOL DropShadow = *ShowDropShadow;
01323         
01324     if (pSpread != NULL)
01325     {
01326         BOOL ok = pSpread->GetPageSize(&PageWidth, &PageHeight, &PageMargin, &PageBleed,
01327                                        &Pages, &DropShadow);
01328         if (ok)
01329         {
01330             // page values read ok so set return parameters
01331             *Width  = PageWidth;
01332             *Height = PageHeight;
01333             *Margin  = PageMargin;
01334             *Bleed  = PageBleed;
01335             *Dps = Pages;
01336             *ShowDropShadow = DropShadow;
01337         }
01338         else
01339             return FALSE;
01340     }
01341 
01342 
01343     // Now check if landscape or portrait
01344     if (PageWidth < PageHeight)
01345     {
01346         *Portrait = TRUE;
01347         *Width = PageWidth;
01348         *Height = PageHeight;
01349     }
01350     else
01351     {
01352         *Portrait = FALSE;
01353         *Width = PageHeight;
01354         *Height = PageWidth;
01355     }
01356     
01357     // Remember the states found
01358     OldPageWidth = PageWidth;           // entry page width
01359     OldPageHeight = PageHeight;         // entry page height
01360     OldDpsState = Pages;                // entry state of dps
01361     OldDropShadowState = DropShadow;    // entry drop shadow state 
01362     OldMarginSize  = PageMargin;        // entry page margin size
01363     OldBleedSize  = PageBleed;          // entry page bleed size
01364     OldPortraitState = *Portrait;       // entry portrait/landscape state
01365 
01366     return TRUE;
01367 }
01368 
01369 /******************************************************************************************
01370 
01371 >   BOOL    PageTab::SetNewSizeOfPage(MILLIPOINT Width, MILLIPOINT Height, MILLIPOINT Margin,
01372                                       MILLIPOINT Bleed, BOOL Portrait, BOOL Dps, BOOL ShowDropShadow)
01373 
01374     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01375     Created:    9/12/94
01376     Inputs:     Width       new page width in millipoints
01377                 Height      new page height in millipoints
01378                 Margin      new page margin in millipoints
01379                 Bleed       new page bleed in millipoints
01380                 Portrait    set to TRUE if want Width smaller than height
01381                 Dps         set to TRUE if double page spread required
01382     Returns:    True if found the details ok.
01383     Purpose:    Checks to see what the size of the first page in the first spread in
01384                 the document is and returns the width and height of it.
01385                 Assumes at present a fairly simple document structure.
01386                 This function should not no be used, should be using the undoable operation
01387                 instead.
01388                 Assumes the class variables pDocument, pSpread have been set up.
01389     Errors:     -
01390     SeeAlso:    AppPrefsDlg::SetCurrentSpread; InvokeResize;
01391 
01392 ******************************************************************************************/
01393 
01394 //BOOL PageTab::SetNewSizeOfPage(MILLIPOINT Width, MILLIPOINT Height, MILLIPOINT Margin,
01395 //                             MILLIPOINT Bleed, BOOL Portrait, BOOL Dps, BOOL ShowDropShadow)
01396 //{
01397 //  BOOL ok = FALSE;
01398 //
01399 //  // The dialog handler should have already set up the class variables pDocument and pSpread.
01400 //  // We will check that they are not null.
01401 //  // For now, get details on 1st page of spread 1
01402 //  ERROR2IF(pDocument == NULL,FALSE,"PageTab::SetNewSizeOfPage no selected document")
01403 //  ERROR2IF(pSpread == NULL,FALSE,"PageTab::SetNewSizeOfPage no spread to work on")
01404 //
01405 //  // Only change the page size/layout if something has changed 
01406 //  // If the user has changed anything then warn them that nothing will happen
01407 //  MILLIPOINT bodge = 5;       // extra leeway on comparison required
01408 //  if ( (OldPageWidth <= (Width - bodge)) || (OldPageWidth >= (Width + bodge)) ||
01409 //       (OldPageHeight  <= (Height - bodge)) || (OldPageHeight  >= (Height + bodge)) || 
01410 //      OldDpsState != Dps ||
01411 //      OldPortraitState != Portrait ||
01412 //      OldDropShadowState != ShowDropShadow ||
01413 //      OldMarginSize != Margin ||
01414 //      OldBleedSize != Bleed)
01415 //  {
01416 //      // Changes made so resize all pages in the spread.
01417 //      pSpread->SetPageSize(Width, Height, Margin, Bleed, Dps, ShowDropShadow);
01418 //      
01419 //      // Force all views onto the document to be updated 
01420 //      pDocument->ForceRedraw();
01421 //      
01422 //      // And make these the new defaults
01423 //      OldPageWidth = Width;
01424 //      OldPageHeight = Height;
01425 //      OldDpsState = Dps;
01426 //      OldPortraitState = Portrait;
01427 //      OldDropShadowState = ShowDropShadow;
01428 //      OldMarginSize = Margin;
01429 //      OldBleedSize = Bleed;       
01430 //  }
01431 //
01432 //  return TRUE;
01433 //}
01434 
01435 
01436 /******************************************************************************************
01437 
01438 >   BOOL    PageTab::InvokeResize(PageResizeInfo *Param)
01439 
01440     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01441     Created:    17/2/95
01442     Inputs: 
01443     Returns:    True if managed to change the page/spread  details ok.
01444     Purpose:    Sets the new details of the page size and of the default grid.
01445                 The default grid should always be resident in the spread.
01446                 Assumes the class variables pDocument, pSpread have been set up.
01447                 This function should be used instead of SetNewSizeOfPage
01448                 as it is undoable and they aren't.
01449     Errors:     -
01450     SeeAlso:    AppPrefsDlg::SetCurrentSpread; SetNewSizeOfPage;
01451 
01452 ******************************************************************************************/
01453 
01454 BOOL PageTab::InvokeResize(PageResizeInfo *pParam)
01455 {
01456     ERROR2IF(pParam==NULL,FALSE,"PageTab::InvokeResize() no pParam supplied");
01457     // For now, get details on 1st page of spread 1
01458 
01459     // The dialog handler should have already set up the class variables pDocument and pSpread.
01460     // We will check that they are not null.
01461     ERROR2IF(pDocument==NULL,FALSE,"PageTab::InvokeResize() no selected document");
01462     ERROR2IF(  pSpread==NULL,FALSE,"PageTab::InvokeResize() no spread to work on");
01463 
01464     // Only change the page size/layout if something has changed 
01465     // If the user has changed anything then warn them that nothing will happen
01466     MILLIPOINT bodge = 5;       // extra leeway on comparison required
01467 
01468     BOOL ChangeRequired = FALSE;
01469     if ( (OldPageWidth >= (pParam->Width - bodge)) && (OldPageWidth <= (pParam->Width + bodge)) &&
01470          (OldPageHeight  >= (pParam->Height - bodge)) && (OldPageHeight  <= (pParam->Height + bodge)) && 
01471         OldDpsState == pParam->Dps &&
01472         OldDropShadowState == pParam->ShowDropShadow &&
01473         (OldMarginSize >= (pParam->Margin - bodge)) && (OldMarginSize <= (pParam->Margin + bodge)) &&
01474         (OldBleedSize >= (pParam->Bleed - bodge)) && (OldBleedSize <= (pParam->Bleed + bodge)))
01475     {
01476             // Set the page parameters so that we do not resize
01477             pParam->Height = 0;
01478             pParam->Width = 0;
01479             pParam->Margin = 0;
01480             pParam->Bleed = 0;
01481             pParam->Dps = FALSE;
01482     }
01483     else
01484     {
01485         // Flag we need to make a change
01486         ChangeRequired = TRUE;
01487 
01488         // Make these the new defaults
01489         OldPageWidth = pParam->Width;
01490         OldPageHeight = pParam->Height;
01491         OldDpsState = pParam->Dps;
01492         OldPortraitState = pParam->Portrait;
01493         OldDropShadowState = pParam->ShowDropShadow;
01494         OldMarginSize = pParam->Margin;
01495         OldBleedSize = pParam->Bleed;       
01496     }
01497 
01498     if (ChangeRequired)
01499     {
01500         // Set the flag to say that we are doing a move and resize operation
01501         // rather than a centre and resize used by batching
01502         pParam->ResizeAndCentre = FALSE;
01503 
01504         // Invoke the Page resizing operation so that we get Undo.
01505         OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(CC_RUNTIME_CLASS(OpPageResize));
01506 
01507         if (pOpDesc != NULL)
01508         {
01509             // Set up the parameters which we require to do the page resizing operation 
01510             pParam->pSpread = pSpread;
01511 
01512             // Go for it!
01513             pOpDesc->Invoke((OpParam *) pParam);
01514         }
01515     }
01516 
01517     return TRUE;
01518 }   
01519 
01520 /******************************************************************************************
01521 
01522 >   BOOL    PageTab::InvokeResizeAndCentre(PageResizeInfo *Param)
01523 
01524     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01525     Created:    8/7/95
01526     Inputs: 
01527     Returns:    True if managed to change the page/spread  details ok.
01528     Purpose:    Sets the new details of the page size and of the default grid.
01529                 The default grid should always be resident in the spread.
01530                 Assumes the class variables pDocument, pSpread have been set up.
01531                 This function should be used instead of SetNewSizeOfPage
01532                 as it is undoable and they aren't.
01533                 This does the same as resize but centres the objects on the page.
01534                 Used by the batching code.
01535     Errors:     -
01536     SeeAlso:    AppPrefsDlg::SetCurrentSpread; SetNewSizeOfPage;
01537 
01538 ******************************************************************************************/
01539 
01540 BOOL PageTab::InvokeResizeAndCentre(PageResizeInfo *pParam)
01541 {
01542     ERROR2IF(pParam==NULL,FALSE,"PageTab::InvokeResizeAndCentre() no pParam supplied");
01543 
01544     // The dialog handler should have already set up the class variables pDocument and pSpread.
01545     // We will check that they are not null.
01546     ERROR2IF(pDocument==NULL,FALSE,"PageTab::InvokeResizeAndCentre() no selected document");
01547     ERROR2IF(  pSpread==NULL,FALSE,"PageTab::InvokeResizeAndCentre() no spread to work on");
01548 
01549     // Flag we need to make a change
01550 //  BOOL ChangeRequired = TRUE;
01551 
01552     // Make these the new defaults
01553     OldPageWidth = pParam->Width;
01554     OldPageHeight = pParam->Height;
01555     OldDpsState = pParam->Dps;
01556     OldPortraitState = pParam->Portrait;
01557     OldDropShadowState = pParam->ShowDropShadow;
01558     OldMarginSize = pParam->Margin;
01559     OldBleedSize = pParam->Bleed;       
01560 
01561     // Set the flag to say that we are doing a centre and resize operation
01562     pParam->ResizeAndCentre = TRUE;
01563 
01564     // Invoke the Page resizing operation so that we get Undo.
01565     OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(CC_RUNTIME_CLASS(OpPageResize));
01566 
01567     if (pOpDesc != NULL)
01568     {
01569         // Set up the parameters which we require to do the page resizing operation 
01570         pParam->pSpread = pSpread;
01571 
01572         // Go for it!
01573         pOpDesc->Invoke((OpParam *) pParam);
01574     }
01575 
01576     return TRUE;
01577 }   
01578 
01579 
01580 
01582 
01583 /******************************************************************************************
01584 >   OpPageResize::OpPageResize() : UndoableOperation()
01585 
01586     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01587     Created:    13/2/95
01588     Inputs:     -
01589     Outputs:    -
01590     Returns:    -
01591     Purpose:    OpPageResize constructor (Creates an undoable operation)
01592     SeeAlso:    PageTab;
01593 
01594 ******************************************************************************************/
01595 
01596 OpPageResize::OpPageResize() : TransOperation() //UndoableOperation() 
01597 {
01598 }       
01599 
01600 /********************************************************************************************
01601 
01602 >   OpPageResize::~OpPageResize() 
01603 
01604     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01605     Created:    13/2/95
01606     Inputs:     -
01607     Outputs:    -
01608     Returns:    -
01609     Purpose:    OpPageResize destructor
01610     Errors:     -
01611     SeeAlso:    -
01612 
01613 ********************************************************************************************/
01614 
01615 OpPageResize::~OpPageResize()
01616 {
01617 }
01618 
01619 /******************************************************************************************
01620 >   BOOL OpAlign::Init()
01621 
01622     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01623     Created:    13/2/95
01624     Returns:    FALSE if it fails (due to lack of memory)
01625     Purpose:    Creates an OpDescriptor for a Page Resize operation
01626     SeeAlso:    PageTab;
01627 
01628 ******************************************************************************************/
01629 
01630 BOOL OpPageResize::Init()
01631 {  
01632     return RegisterOpDescriptor(
01633         0,                              // Tool ID
01634         _R(IDS_OPPAGERESIZE),               // String resource ID
01635         CC_RUNTIME_CLASS(OpPageResize), // Runtime class
01636         OPTOKEN_OPPAGERESIZE,           // Token string
01637         OpPageResize::GetState,         // GetState function
01638         0,                              // Help ID
01639         0,                              // Bubble ID
01640         0,                              // Resource ID
01641         0                               // Control ID
01642 //  needs   'GREY_WHEN_NO_CURRENT_DOC'
01643     );
01644 }   
01645 
01646 /******************************************************************************************
01647 >   OpState OpPageResize::GetState(String_256* pString, OpDescriptor* pOpDesc)
01648 
01649     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01650     Created:    13/2/95
01651     Purpose:    Returns the OpState of the OpPageResize dialogue operation.
01652     SeeAlso:    PageTab;
01653 
01654 ******************************************************************************************/
01655 
01656 OpState OpPageResize::GetState(String_256* pString, OpDescriptor* pOpDesc)
01657 {
01658     OpState OpSt;
01659 
01660     return(OpSt);
01661 }
01662 
01663 /********************************************************************************************
01664 
01665 >   void OpPageResize::Do(OpDescriptor*)
01666 
01667     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01668     Created:    13/2/95
01669     Inputs:     OpPageResize (unused)
01670     Outputs:    -
01671     Returns:    -
01672     Purpose:    (Performs the page resizing operation)
01673                 OpPageResize has a special overloaded Do operator which takes
01674                 parameters describing what is to be done - that version of Do must
01675                 be used
01676     Errors:     Always generates an ENSURE failure because this Do doesn't.
01677     SeeAlso:    -
01678 
01679 ********************************************************************************************/
01680             
01681 void OpPageResize::Do(OpDescriptor *NotUsed)
01682 {
01683     ENSURE(FALSE, "OpPageResize does not provide a Do() function - Use DoWithParam");
01684     End();
01685 }
01686 
01687 /******************************************************************************************
01688 >   void OpPageResize::DoWithParam(OpDescriptor* pOp, OpParam* pAlignParam)
01689 
01690     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01691     Created:    13/2/95
01692     Inputs:     pOp - OpDescriptor as for all Do() functions
01693                 Param - points to a Page resize structure with parameters:
01694                     pSpread - The spread to be changed
01695     Outputs:    -
01696     Returns:    -
01697     Purpose:    Performs the page/spread resize operation, which resizes the pages in the
01698                 specified spread (with undo) to the new size.
01699                 Forces a redraw of the parent document for the specified spread.
01700 
01701     SeeAlso:    PageTab::SetNewSizeOfPage;
01702 
01703 ******************************************************************************************/
01704 
01705 void OpPageResize::DoWithParam(OpDescriptor* pOp, OpParam* pResizeParam)
01706 {
01707     PageResizeInfo *pInfo = (PageResizeInfo *) pResizeParam;
01708 
01709     ERROR3IF(pInfo == NULL,"OpPageResize called with NULL info pointer");
01710     ERROR3IF((pInfo == NULL) && (pInfo->pSpread == NULL),"OpPageResize called with NULL spread pointer");
01711 
01712     // Fail if the input parameters are incorrect
01713     if ((pInfo == NULL) || (pInfo->pSpread == NULL))
01714     {
01715         FailAndExecute();
01716         End();
01717         return;
01718     }
01719 
01720     Spread * pTheSpread = pInfo->pSpread;
01721 
01722     // As we are derived off TransOperation then we MUST call DoStartTransOp otherwise
01723     // it seems to fall over in a very nasty way!
01724     
01725     // Find the spreads first layer
01726     Layer* pCurrentLayer = pTheSpread->FindFirstLayer();
01727     ERROR3IF(pCurrentLayer == NULL,"OpPageResize specified spread has no layers");
01728     // Fail if the input parameters are incorrect
01729     if (pCurrentLayer == NULL)
01730     {
01731         FailAndExecute();
01732         End();
01733         return;
01734     }
01735 
01736     // Find all objects on this spread, selected or unselected and move them.
01737     // Range Control parameters are:-
01738     // Include selected nodes - we want TRUE.
01739     // Include Unselected nodes - we want TRUE.
01740     // Cross layers - we want TRUE
01741     // Ignore locked layers - we want FALSE so that we include locked layers.
01742     // IsRenderable if set then calls NeedsToRender - we want TRUE
01743     // Ignore invisible layers - we want TRUE so that we include invisible layers.
01744     
01745     // DMc - included the promote to parents flag
01746     Range  SearchRange(pCurrentLayer, NULL, RangeControl(TRUE, TRUE, TRUE, FALSE, TRUE, TRUE,
01747         FALSE)); 
01748 
01749     // Must call this so that the Translation operation is set up ok.
01750     // NOTE! A FALSE return may simply mean there are no objects on the page!
01751     BOOL StartTransOpOk = DoStartTransOp(FALSE, NULL, &SearchRange);
01752 
01753     // See if we must do some resizing of the page(s).
01754     // If no change is required then both the height and width passed in will be zero
01755     if ((pInfo->Width != 0) && (pInfo->Height != 0))
01756     {
01757         // Get the details on the present page layout so that we can use this to undo what we
01758         // are about to try and do
01759         MILLIPOINT PageWidth = 0;
01760         MILLIPOINT PageHeight = 0;
01761         MILLIPOINT PageMargin = 0;
01762         MILLIPOINT PageBleed = 0;
01763         BOOL PresentDps = 0;
01764         BOOL PresentDropShadow = 0;
01765             
01766         pTheSpread->GetPageSize(&PageWidth, &PageHeight, &PageMargin, &PageBleed,
01767                                 &PresentDps, &PresentDropShadow);
01768 
01769         // Create an action to Undo the resizing operation
01770         ActionPageResize *APR;
01771 
01772         ActionCode PageResizeAction = ActionPageResize::Init(
01773                                                             this,
01774                                                             &UndoActions,
01775                                                             sizeof(ActionPageResize),
01776                                                             pInfo->pSpread,
01777                                                             PageWidth,
01778                                                             PageHeight,
01779                                                             PageMargin,
01780                                                             PageBleed,
01781                                                             PresentDps,
01782                                                             PresentDropShadow,
01783                                                             (Action**)(&APR)
01784                                                             );
01785 
01786         // If the init happened ok then go and do the first operation
01787         if (PageResizeAction != AC_FAIL) 
01788         {
01789             // If the DoStartTransOp happened ok then move the objects on the page
01790             if (StartTransOpOk)
01791             {
01792                 // Reposition the objects on the page correctly.
01793                 // Do this first as if going from large to small the old position of the objects
01794                 // might limit the size of the paste rectangle whereas the new positions wont. 
01795                 if (
01796                     !MoveObjectsOnPage(pTheSpread,
01797                                        pInfo->Width, pInfo->Height, pInfo->Margin, pInfo->Dps,
01798                                        PageWidth, PageHeight, PageMargin, PresentDps,
01799                                        &SearchRange,
01800                                        pInfo->ResizeAndCentre
01801                                        )
01802                    )
01803                 {
01804                     FailAndExecute();
01805                     End();
01806                     return;
01807                 }
01808             }
01809 
01810             // Apply the initial 'Do' operation - resize that page
01811 
01812             // Save away the current spreads pasteboard rectangle as the specified margin
01813             // may be overridden if the bounding rectangle of the objects on the page would
01814             // not fit into a rectangle encompassing the new page structure and having a
01815             // margin gap around all 4 sides. 
01816             PasteboardRect = pTheSpread->GetPasteboardRect();
01817 
01818             pTheSpread->SetPageSize(pInfo->Width, pInfo->Height, pInfo->Margin, pInfo->Bleed,
01819                                     pInfo->Dps, pInfo->ShowDropShadow);
01820         }
01821         else
01822         {
01823             FailAndExecute();
01824             End();
01825             return;
01826         }
01827     }
01828 
01829 
01830 //      NodeGrid* pGrid = NULL;
01831 // 
01832 //      pGrid = pTheSpread->FindFirstDefaultGridInSpread();
01833 //      ERROR3IF(pGrid == NULL,"ActionSetDefaultGrid::Execute() no current default grid")
01834 //
01835 //      // Must set the origin of the grid to the bottom left corner of the
01836 //      // union rectangle of all pages on the spread as this is where the x,y
01837 //      // measurements are made from.
01838 //      DocRect PagesRect;
01839 //      BOOL ok = pTheSpread->GetPagesRect(&PagesRect);
01840 //      if (ok)
01841 //      {
01842 //         pGrid->SetOrigin(PagesRect.lo.x,PagesRect.lo.y);
01843 //TRACEUSER( "Neville", _T("OpPageResize Grid origin at %d, %d\n"),PagesRect.lo.x,PagesRect.lo.y);
01844 //      }
01845     
01846     // We must have been called to change either the page size OR the grid so always
01847     // force a redraw 
01848     // If everything has gone swimmingly then last thing is to redraw the document
01849     // JustinF says: only do this if the document isn't hidden, ie. it's one of the user's.
01850     // Don't do this if it's a hidden doc, such as the clipboard.
01851     Document *pParentDoc = (Document *)pTheSpread->FindOwnerDoc();
01852     if (pParentDoc != NULL && !pParentDoc->IsAHiddenDoc())
01853     {
01854         // Broadcast the special NEWPAGESIZE message which does not try and update the
01855         // page tab.
01856         pParentDoc->ForceRedraw();
01857         BROADCAST_TO_ALL(OptionsChangingMsg(pParentDoc,
01858                                             OptionsChangingMsg::PAGESIZEHASCHANGED));
01859     }
01860 
01861     // If we reached here then everything has happened ok and we can just end the
01862     // operation and exit 
01863     End();
01864 
01865     return;
01866 }
01867 
01868 /******************************************************************************************
01869 >   BOOL OpPageResize::MoveObjectsOnPage(Spread *pSpread,
01870                                          MILLIPOINT Width, MILLIPOINT Height,
01871                                          MILLIPOINT Margin, BOOL Dps,
01872                                          MILLIPOINT OldWidth, MILLIPOINT OldHeight,
01873                                          MILLIPOINT OldMargin, BOOL OldDps,
01874                                          Range  *pSearchRange,
01875                                          BOOL ResizeAndCentre)
01876 
01877     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01878     Created:    20/4/95
01879     Inputs:     pSpread     - pointer to the spread whose objects areto be moved
01880                 Width       - new page width
01881                 Height      - new page height
01882                 Margin      - new page margin
01883                 Dps         - single (FALSE) or double (TRUE) page spread flag
01884                 Width       - old page width
01885                 Height      - old page height
01886                 Margin      - old page margin
01887                 Dps         - old single (FALSE) or double (TRUE) page spread flag
01888                 pSearchRange- the range to be trasnformed 
01889                 ResizeAndCentre - Set True if want a centre and resize operation 
01890                                 - False if want the resize and move operation
01891     Outputs:    -
01892     Returns:    -
01893     Purpose:    As part of the page/spread resize operation, which resizes the pages in the
01894                 specified spread (with undo) to the new size, we must translate the objects
01895                 on the page to a better position.
01896 
01897     SeeAlso:    OpPageResize::DoWithParam; ActionPageResize; PageTab::SetNewSizeOfPage;
01898 
01899 ******************************************************************************************/
01900 
01901 BOOL OpPageResize::MoveObjectsOnPage(Spread *pSpread,
01902                                      MILLIPOINT Width, MILLIPOINT Height,
01903                                      MILLIPOINT Margin, BOOL Dps,
01904                                      MILLIPOINT OldWidth, MILLIPOINT OldHeight,
01905                                      MILLIPOINT OldMargin, BOOL OldDps,
01906                                      Range  *pSearchRange,
01907                                      BOOL ResizeAndCentre)
01908 {
01909     ERROR2IF(pSpread == NULL, FALSE,"OpPageResize::MoveObjectsOnPage specified spread is null");
01910     ERROR2IF(pSearchRange == NULL, FALSE,"OpPageResize::MoveObjectsOnPage specified range is null");
01911 
01912     // Found no nodes on the page according to this spec so nothing to move
01913     if (pSearchRange->FindFirst() == NULL)
01914         return TRUE;
01915 
01916     // Work out the rectangle encompassing the old page structure
01917     MILLIPOINT OldWidthOfPages = 0;
01918     if (OldDps)
01919         OldWidthOfPages = OldMargin + 2 * OldWidth;
01920     else
01921         OldWidthOfPages = OldWidth;
01922     DocRect OldPagesRect(OldMargin,
01923                          OldMargin,
01924                          OldMargin + OldWidthOfPages + OldMargin,
01925                          OldMargin + OldHeight + OldMargin);
01926 
01927     // Work out the rectangle encompassing the new page structure
01928     MILLIPOINT WidthOfPages = 0;
01929     if (Dps)
01930         WidthOfPages = Margin + 2 * Width;
01931     else
01932         WidthOfPages = Width;
01933         
01934     DocRect NewPagesRect(Margin,
01935                          Margin,
01936                          Margin + WidthOfPages + Margin,
01937                          Margin + Height + Margin);
01938 
01939     MILLIPOINT dx = 0;
01940     MILLIPOINT dy = 0;
01941     if (ResizeAndCentre)
01942     { 
01943         /* Centre items on page... */
01944         DocRect OurItemRect(pSearchRange->GetBoundingRect());
01945         DocCoord ItemCentre((OurItemRect.Width()/2) + OurItemRect.lo.x,
01946                             (OurItemRect.Height()/2) + OurItemRect.lo.y);
01947         DocCoord PageCentre(Width / 2, Height / 2);
01948         dx = PageCentre.x - ItemCentre.x;
01949         dy = PageCentre.y - ItemCentre.y;
01950         dx += Margin;
01951         dy += Margin;
01952     }
01953     else
01954     {
01955         // Work out the difference between the centre points of the page structures
01956 //      MILLIPOINT dx = NewPagesRect.lo.x + NewPagesRect.Width()/2
01957 //                      - (OldPagesRect.lo.x + OldPagesRect.Width()/2);
01958 //      MILLIPOINT dy = NewPagesRect.lo.y + NewPagesRect.Height()/2
01959 //                      - (OldPagesRect.lo.y + OldPagesRect.Height()/2);
01960         dx = NewPagesRect.lo.x - OldPagesRect.lo.x;
01961         dy = NewPagesRect.lo.y - OldPagesRect.lo.y;
01962 TRACEUSER( "Neville", _T("Old spread low x,y %d, %d\n"), OldPagesRect.lo.x, OldPagesRect.lo.y);
01963 TRACEUSER( "Neville", _T("New spread low x,y %d, %d\n"), NewPagesRect.lo.x, NewPagesRect.lo.y);
01964 TRACEUSER( "Neville", _T("Distance to move is %d, %d\n"), dx, dy);
01965     }
01966     
01967     // If the movement required is small then forget it
01968     const MILLIPOINT bodge = 100;
01969     if (
01970         (dx >= -bodge) && (dx <= bodge) &&
01971         (dy >= -bodge) && (dy <= bodge)
01972        )
01973         return TRUE;
01974 
01975     // Construct the translation matrix that we want to apply to the objects
01976     Trans2DMatrix* pMatrix = new Trans2DMatrix(dx, dy);
01977 
01978     // Move all those nodes by the required amount (if it is a Renderable Ink Node)
01979     DoTransformNodes(*pSearchRange, pMatrix);
01980 
01981     // Update the selection cache
01982     GetApplication()->UpdateSelection();
01983 
01984     return TRUE;
01985 }   
01986 
01987 
01988 
01989 
01990 /********************************************************************************************
01991 
01992 >   ActionPageResize::ActionPageResize()
01993 
01994     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01995     Created:    15/2/95
01996     Purpose:    ActionPageResize constructor
01997 
01998 ********************************************************************************************/
01999     
02000 ActionPageResize::ActionPageResize()
02001 {
02002 }
02003 
02004 
02005 
02006 /********************************************************************************************
02007 
02008 >   ActionPageResize::~ActionPageResize() 
02009 
02010     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
02011     Created:    15/2/95
02012     Purpose:    ActionPageResize destructor
02013 
02014 ********************************************************************************************/
02015 
02016 ActionPageResize::~ActionPageResize()
02017 {
02018 }
02019 
02020 
02021 
02022 /********************************************************************************************
02023 
02024 >   virtual ActionCode ActionPageResize::Execute()
02025 
02026     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
02027     Created:    15/2/95
02028     Inputs:     -
02029     Outputs:    ActionCode indicating if the action was successfully executed or not
02030     Returns:    -
02031     Purpose:    Executes the ActionPageResize to go and resize the current spread/page
02032                 and generates another ActionPageResize to undo this change.
02033                 Forces a redraw of the parent document for the specified spread.
02034 
02035 ********************************************************************************************/
02036 
02037 ActionCode ActionPageResize::Execute()
02038 {
02039     ActionPageResize PageResizeAct;
02040     ActionCode ActCode = AC_FAIL;
02041 
02042 
02043     // Get the details on the present page layout so that we can use this to undo what we
02044     // are about to try and do
02045     MILLIPOINT PageWidth = 0;
02046     MILLIPOINT PageHeight = 0;
02047     MILLIPOINT PageMargin = 0;
02048     MILLIPOINT PageBleed = 0;
02049     BOOL PresentDps = 0;
02050     BOOL PresentDropShadow = 0;
02051         
02052     if (pSpread != NULL)
02053     {
02054         pSpread->GetPageSize(&PageWidth, &PageHeight, &PageMargin, &PageBleed,
02055                                        &PresentDps, &PresentDropShadow);
02056     }
02057 
02058      // Create an action to restore the changes we are about to make
02059     if ((ActCode = ActionPageResize::Init(pOperation,
02060                                             pOppositeActLst,
02061                                             sizeof(ActionPageResize),
02062                                             pSpread,
02063                                             PageWidth,
02064                                             PageHeight,
02065                                             PageMargin,
02066                                             PageBleed,
02067                                             PresentDps,
02068                                             PresentDropShadow,
02069                                             ( Action**)(&PageResizeAct))) != AC_FAIL)
02070     {
02071         // Need to do something here
02072         if (pSpread != NULL)
02073         {
02074             // Save away the current spreads pasteboard rectangle as the specified margin
02075             // may be overridden if the bounding rectangle of the objects on the page would
02076             // not fit into a rectangle encompassing the new page structure and having a
02077             // margin gap around all 4 sides. 
02078             PasteboardRect = pSpread->GetPasteboardRect();
02079 
02080             pSpread->SetPageSize(Width, Height, Margin, Bleed, Dps, ShowDropShadow);
02081 
02082 
02083             // Force all views onto the document to be updated 
02084             Document *pParentDoc = (Document *)pSpread->FindOwnerDoc();
02085             if (pParentDoc != NULL)
02086             {
02087                 pParentDoc->ForceRedraw();
02088 
02089                 BROADCAST_TO_ALL(OptionsChangingMsg(
02090                                                  pParentDoc,
02091                                                  OptionsChangingMsg::NEWPAGESIZE
02092                                                    )
02093                                 );
02094             }
02095         }
02096     }
02097 
02098     return (ActCode);
02099 }
02100 
02101 
02102 
02103 /********************************************************************************************
02104 
02105 >   ActionCode ActionPageResize::Init(Operation* const pOp, 
02106                                         ActionList* pActionList,    
02107                                         UINT32 ActionSize,
02108                                         Spread *pSpread,
02109                                         Page *pPage,
02110                                         Action** NewAction)
02111     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
02112     Created:    15/2/95
02113 
02114     Inputs:     pOp: The operation to which the action should be added
02115                 pActionList: The action list in the operation object
02116                 ActionSize:  The size of the action in bytes. This should be the total  
02117                              size of the action (including any objects pointed to by the
02118                              action).
02119                 pSpread:     The target spread which will be changed when we are executed
02120                 Height       The new page height required.
02121                 Width        The new page width required.
02122                 Margin       The new page margin required.
02123                 Bleed        The new page bleed required.
02124                 Dps          The new single/double page spread required.
02125                 ShowPageShadow  The new page shadow display state required.
02126 
02127 
02128     Outputs:    NewAction:   A pointer to the action if it could be allocated. 
02129 
02130     Returns:    AC_FAIL:     There was not enough room in the operation history for the
02131                              action and the user did not wish to continue. Usually
02132                              End() should be called in this situation.
02133 
02134                 AC_NORECORD: There was not enough room in the operation history for
02135                              the action, but the user requested that he wished to 
02136                              continue without undo. 
02137 
02138                 AC_OK      : The action was successfully initialised and added to the 
02139                              operation. 
02140                          
02141                            
02142     Purpose:    To check that there is sufficient room for the action in the operation
02143                 history, and if there is, then to add the action to the operations 
02144                 action list. 
02145                 
02146                 The function calls the Action::Init function passing the runtime class 
02147                 of an ActionPageResize.
02148     Errors:     -
02149     SeeAlso:    Action::Init; OpPageResize; PageTab::SetNewSizeOfPage; 
02150 
02151 ********************************************************************************************/
02152    
02153 ActionCode ActionPageResize::Init(Operation* const pOp, 
02154                                     ActionList* pActionList,    
02155                                     UINT32 ActionSize,
02156                                     Spread *pTheSpread,
02157                                     MILLIPOINT NewWidth,
02158                                     MILLIPOINT NewHeight,
02159                                     MILLIPOINT NewMargin,
02160                                     MILLIPOINT NewBleed,
02161                                     BOOL NewDps,
02162                                     BOOL NewShowDropShadow,
02163                                     Action** NewAction)
02164 {
02165     ActionCode Ac = (Action::Init(pOp,
02166                                     pActionList,
02167                                     ActionSize,
02168                                     CC_RUNTIME_CLASS(ActionPageResize), 
02169                                     NewAction));
02170     if (*NewAction != NULL)
02171     {
02172         ActionPageResize *ACC = (ActionPageResize*) (*NewAction);
02173         ACC->pSpread  = pTheSpread;
02174         ACC->Width = NewWidth;
02175         ACC->Height = NewHeight;
02176         ACC->Margin = NewMargin;
02177         ACC->Bleed = NewBleed;
02178         ACC->Dps = NewDps;
02179         ACC->ShowDropShadow = NewShowDropShadow;
02180     }
02181 
02182     return (Ac);
02183 }
02184 
02185 

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