OpPageResize Class Reference

#include <optspage.h>

Inheritance diagram for OpPageResize:

TransOperation UndoableOperation Operation MessageHandler ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 OpPageResize ()
 OpPageResize constructor (Creates an undoable operation).
 ~OpPageResize ()
 OpPageResize destructor.
void Do (OpDescriptor *)
 (Performs the page resizing operation) OpPageResize has a special overloaded Do operator which takes parameters describing what is to be done - that version of Do must be used
void DoWithParam (OpDescriptor *pOp, OpParam *pResizeParam)
 Performs the page/spread resize operation, which resizes the pages in the specified spread (with undo) to the new size. Forces a redraw of the parent document for the specified spread.

Static Public Member Functions

static BOOL Init ()
 Creates an OpDescriptor for a Page Resize operation.
static OpState GetState (String_256 *, OpDescriptor *)
 Returns the OpState of the OpPageResize dialogue operation.

Private Member Functions

BOOL MoveObjectsOnPage (Spread *pSpread, MILLIPOINT Width, MILLIPOINT Height, MILLIPOINT Margin, BOOL Dps, MILLIPOINT OldWidth, MILLIPOINT OldHeight, MILLIPOINT OldMargin, BOOL OldDps, Range *pSearchRange, BOOL ResizeAndCentre)
 As part of the page/spread resize operation, which resizes the pages in the specified spread (with undo) to the new size, we must translate the objects on the page to a better position.

Private Attributes

DocRect PasteboardRect

Detailed Description

Definition at line 245 of file optspage.h.


Constructor & Destructor Documentation

OpPageResize::OpPageResize  ) 
 

OpPageResize constructor (Creates an undoable operation).

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/2/95
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-
See also:
PageTab;

Definition at line 1596 of file optspage.cpp.

01596                            : TransOperation() //UndoableOperation() 
01597 {
01598 }       

OpPageResize::~OpPageResize  ) 
 

OpPageResize destructor.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/2/95
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 1615 of file optspage.cpp.

01616 {
01617 }


Member Function Documentation

void OpPageResize::Do OpDescriptor NotUsed  )  [virtual]
 

(Performs the page resizing operation) OpPageResize has a special overloaded Do operator which takes parameters describing what is to be done - that version of Do must be used

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/2/95
Parameters:
OpPageResize (unused) [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: Always generates an ENSURE failure because this Do doesn't.

See also:
-

Reimplemented from Operation.

Definition at line 1681 of file optspage.cpp.

01682 {
01683     ENSURE(FALSE, "OpPageResize does not provide a Do() function - Use DoWithParam");
01684     End();
01685 }

void OpPageResize::DoWithParam OpDescriptor pOp,
OpParam pResizeParam
[virtual]
 

Performs the page/spread resize operation, which resizes the pages in the specified spread (with undo) to the new size. Forces a redraw of the parent document for the specified spread.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/2/95
Parameters:
pOp - OpDescriptor as for all Do() functions [INPUTS] Param - points to a Page resize structure with parameters: pSpread - The spread to be changed
- [OUTPUTS]
Returns:
-
See also:
PageTab::SetNewSizeOfPage;

Reimplemented from TransOperation.

Definition at line 1705 of file optspage.cpp.

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 }

OpState OpPageResize::GetState String_256 pString,
OpDescriptor pOpDesc
[static]
 

Returns the OpState of the OpPageResize dialogue operation.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/2/95
See also:
PageTab;

Reimplemented from TransOperation.

Definition at line 1656 of file optspage.cpp.

01657 {
01658     OpState OpSt;
01659 
01660     return(OpSt);
01661 }

BOOL OpPageResize::Init void   )  [static]
 

Creates an OpDescriptor for a Page Resize operation.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/2/95
Returns:
FALSE if it fails (due to lack of memory)
See also:
PageTab;

Reimplemented from SimpleCCObject.

Definition at line 1630 of file optspage.cpp.

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 }   

BOOL OpPageResize::MoveObjectsOnPage Spread pSpread,
MILLIPOINT  Width,
MILLIPOINT  Height,
MILLIPOINT  Margin,
BOOL  Dps,
MILLIPOINT  OldWidth,
MILLIPOINT  OldHeight,
MILLIPOINT  OldMargin,
BOOL  OldDps,
Range pSearchRange,
BOOL  ResizeAndCentre
[private]
 

As part of the page/spread resize operation, which resizes the pages in the specified spread (with undo) to the new size, we must translate the objects on the page to a better position.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/4/95
Parameters:
pSpread - pointer to the spread whose objects areto be moved [INPUTS] Width - new page width Height - new page height Margin - new page margin Dps - single (FALSE) or double (TRUE) page spread flag Width - old page width Height - old page height Margin - old page margin Dps - old single (FALSE) or double (TRUE) page spread flag pSearchRange- the range to be trasnformed ResizeAndCentre - Set True if want a centre and resize operation
  • False if want the resize and move operation
- [OUTPUTS]
Returns:
-
See also:
OpPageResize::DoWithParam; ActionPageResize; PageTab::SetNewSizeOfPage;

Definition at line 1901 of file optspage.cpp.

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 }   


Member Data Documentation

DocRect OpPageResize::PasteboardRect [private]
 

Definition at line 272 of file optspage.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:58:34 2007 for Camelot by  doxygen 1.4.4