ActionSetDefaultGrid Class Reference

When executed, this sets up an action to redo/undo a default grid resize. More...

#include <optsgrid.h>

Inheritance diagram for ActionSetDefaultGrid:

Action ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 ActionSetDefaultGrid ()
 ActionSetDefaultGrid constructor.
 ~ActionSetDefaultGrid ()
 ActionSetDefaultGrid destructor.
virtual ActionCode Execute ()
 Executes the ActionSetDefaultGrid to go and set up a new default grid in the specified spread and generates another ActionSetDefaultGrid to undo this change. Forces a redraw of the parent document of the specified spread.

Static Public Member Functions

static ActionCode Init (Operation *const pOp, ActionList *pActionList, UINT32 ActionSize, Spread *pSpread, double GridDivisions, UINT32 GridSubDivisions, UnitType GridUnits, GridType TypeOfGrid, MILLIPOINT OriginX, MILLIPOINT OriginY, Action **NewAction)
 To check that there is sufficient room for the action in the operation history, and if there is, then to add the action to the operations action list.

Private Attributes

Spread * pSpread
double GridDivisions
UINT32 GridSubDivisions
UnitType GridUnits
GridType TypeOfGrid
MILLIPOINT OriginX
MILLIPOINT OriginY

Detailed Description

When executed, this sets up an action to redo/undo a default grid resize.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/10/95
See also:
OpSetDefaultGrid

Definition at line 254 of file optsgrid.h.


Constructor & Destructor Documentation

ActionSetDefaultGrid::ActionSetDefaultGrid (   ) 
 

ActionSetDefaultGrid constructor.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/2/95

Definition at line 1106 of file optsgrid.cpp.

01107 {
01108 }

ActionSetDefaultGrid::~ActionSetDefaultGrid (   ) 
 

ActionSetDefaultGrid destructor.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/2/95

Definition at line 1122 of file optsgrid.cpp.

01123 {
01124 }


Member Function Documentation

ActionCode ActionSetDefaultGrid::Execute (   )  [virtual]
 

Executes the ActionSetDefaultGrid to go and set up a new default grid in the specified spread and generates another ActionSetDefaultGrid to undo this change. Forces a redraw of the parent document of the specified spread.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/2/95
Parameters:
- [INPUTS]
ActionCode indicating if the action was successfully executed or not [OUTPUTS]
Returns:
-

Reimplemented from Action.

Definition at line 1143 of file optsgrid.cpp.

01144 {
01145     ActionSetDefaultGrid SetDefaultGridAct;
01146     ActionCode ActCode = AC_OK;
01147 
01148     // Get the details on the present default grid layout so that we can use this to undo
01149     // what we are about to try and do
01150         
01151     double PresentGridDivisions = 0;
01152     UINT32 PresentGridSubDivisions = 0;
01153     UnitType PresentGridUnits = NOTYPE;
01154     GridType PresentGridType = RECTANGULAR;
01155     NodeGrid* pGrid = NULL; 
01156     MILLIPOINT  PresentOriginX = 0;
01157     MILLIPOINT  PresentOriginY = 0;
01158 
01159     if (pSpread != NULL)
01160     {
01161             pGrid = pSpread->FindFirstDefaultGridInSpread();
01162             ERROR3IF(pGrid == NULL,"ActionSetDefaultGrid::Execute() no current default grid");
01163 
01164             PresentGridDivisions = pGrid->GetDivisions();                
01165             PresentGridSubDivisions = pGrid->GetSubdivisions();
01166             PresentGridUnits = pGrid->GetUnits();
01167             PresentGridType = pGrid->GetGridType();
01168 
01169             // Grid origin should be made relative to bottom left hand corner of page union
01170             DocRect PagesRect;
01171             /*BOOL ok =*/ pSpread->GetPagesRect(&PagesRect);
01172             pGrid->GetOrigin(&PresentOriginX, &PresentOriginY);
01173             // Make relative to bottom left hand corner of page union
01174             PresentOriginX = PresentOriginX - PagesRect.lo.x;
01175             PresentOriginY = PresentOriginY - PagesRect.lo.y;
01176 TRACEUSER( "Neville", _T("ActionSetDefaultGrid::Execute starting grid origin at %d, %d\n"), PresentOriginX, PresentOriginY);
01177     }
01178 
01179      // Create an action to restore the changes we are about to make
01180     if ((ActCode = ActionSetDefaultGrid::Init(pOperation,
01181                                             pOppositeActLst,
01182                                             sizeof(ActionSetDefaultGrid),
01183                                             pSpread,
01184                                             PresentGridDivisions,
01185                                             PresentGridSubDivisions,
01186                                             PresentGridUnits,
01187                                             PresentGridType,
01188                                             PresentOriginX,
01189                                             PresentOriginY,
01190                                             ( Action**)(&SetDefaultGridAct))) != AC_FAIL)
01191     {
01192         // Need to do something here
01193         if ((pSpread != NULL) && (pGrid != NULL)) 
01194         {
01195             // Check if we must change grid types
01196             if (PresentGridType != TypeOfGrid)
01197             {
01198                 NodeGrid* pNewGrid = NULL;
01199 
01200                 // Work out the size required for the new grid
01201                 DocRect Rect = pSpread->GetPasteboardRect(FALSE);
01202                 pSpread->DocCoordToSpreadCoord(&Rect);
01203 
01204                 // Create a grid of the new type
01205                 switch (TypeOfGrid)
01206                 {
01207                     case RECTANGULAR    : ALLOC_WITH_FAIL(pNewGrid,(new NodeGridRect()),pOperation); break;
01208                     case ISOMETRIC      : ALLOC_WITH_FAIL(pNewGrid,(new NodeGridIso()), pOperation); break;
01209                     case INVALID_GRID_TYPE: ERROR3("Use of invalid grid type"); break;
01210                 }
01211 
01212                 if (pNewGrid != NULL)
01213                 {
01214                     // Attach the new grid as the last child of the specified spread
01215                     pNewGrid->AttachNode(pSpread, LASTCHILD); 
01216                     pNewGrid->SetDefault(TRUE);         // Its a default grid
01217                     pNewGrid->SetBoundingRect(Rect);    // Tell the NodeGrid of the new bounds
01218 
01219                     // Now delete the old grid
01220                     pGrid->CascadeDelete();
01221 
01222                     // Make the present grid the new one so that we can set the new parameters  
01223                     pGrid = pNewGrid;
01224                 }
01225                 else
01226                 {
01227                     // We failed to create the new grid so return that failure
01228                     ActCode = AC_FAIL;
01229                 }
01230             }
01231 
01232 
01233             // Set up those new grid parameters
01234             if (ActCode != AC_FAIL)
01235             {
01236                 // Grid system works in divisions, which are the number of units between the
01237                 // main grid points.
01238                 pGrid->SetGridParams(GridDivisions, GridSubDivisions, GridUnits);
01239                 
01240                 // Must set the origin of the grid to the bottom left corner of the
01241                 // union rectangle of all pages on the spread as this is where the x,y
01242                 // measurements are made from.
01243                 DocRect PagesRect;
01244                 BOOL ok = pSpread->GetPagesRect(&PagesRect);
01245                 if (ok)
01246                    pGrid->SetOrigin(PagesRect.lo.x + OriginX, PagesRect.lo.y + OriginY);
01247 
01248                 // Force all views onto the document to be updated 
01249                 // Also, tell the options dialog box that something has changed
01250                 // Assume spread is in the selected document
01251                 Document *pParentDoc = (Document *)pSpread->FindOwnerDoc();
01252                 if (pParentDoc != NULL)
01253                 {
01254                     pParentDoc->ForceRedraw();
01255                     BROADCAST_TO_ALL( OptionsChangingMsg(pParentDoc,OptionsChangingMsg::NEWDEFAULTGRID) );
01256                 }
01257             }
01258         }
01259     }
01260 
01261     return (ActCode);
01262 }

ActionCode ActionSetDefaultGrid::Init (  Operation *const   pOp,
ActionList *  pActionList,
UINT32  ActionSize,
Spread *  pTheSpread,
double  NewGridDivisions,
UINT32  NewGridSubDivisions,
UnitType  NewGridUnits,
GridType  NewGridType,
MILLIPOINT  NewOriginX,
MILLIPOINT  NewOriginY,
Action **  NewAction
)  [static]
 

To check that there is sufficient room for the action in the operation history, and if there is, then to add the action to the operations action list.

Parameters:
pOp,: The operation to which the action should be added [INPUTS] pActionList: The action list in the operation object ActionSize: The size of the action in bytes. This should be the total size of the action (including any objects pointed to by the action). pSpread: The target spread which will be changed when we are executed NewGridDivisions: The new number of grid divisions NewGridSubDivisions: The new number of grid subdivisions NewGridUnits: The new grid units NewGridType: The new type of grid required, either Isometric or Rectangular NewOriginX: The new origin x coordinate to use NewOriginY: The new origin y coordinate to use
NewAction,: A pointer to the action if it could be allocated. [OUTPUTS]
Returns:
AC_FAIL: There was not enough room in the operation history for the action and the user did not wish to continue. Usually End() should be called in this situation.
AC_NORECORD: There was not enough room in the operation history for the action, but the user requested that he wished to continue without undo.

AC_OK : The action was successfully initialised and added to the operation.

The function calls the Action::Init function passing the runtime class of an ActionSetDefaultGrid.

Returns:
Errors: -
See also:
Action::Init; OpSetDefaultGrid; GridTab::SetNewSizeOfPage;

Definition at line 1320 of file optsgrid.cpp.

01331 {
01332     ActionCode Ac = (Action::Init(pOp,
01333                                     pActionList,
01334                                     ActionSize,
01335                                     CC_RUNTIME_CLASS(ActionSetDefaultGrid), 
01336                                     NewAction));
01337     if (*NewAction != NULL)
01338     {
01339         ActionSetDefaultGrid *ACC = (ActionSetDefaultGrid*) (*NewAction);
01340         ACC->pSpread  = pTheSpread;
01341         ACC->GridDivisions = NewGridDivisions;
01342         ACC->GridSubDivisions = NewGridSubDivisions;
01343         ACC->GridUnits = NewGridUnits;
01344         ACC->TypeOfGrid = NewGridType;
01345         ACC->OriginX = NewOriginX;
01346         ACC->OriginY = NewOriginY;
01347     }
01348 
01349     return (Ac);
01350 }


Member Data Documentation

double ActionSetDefaultGrid::GridDivisions [private]
 

Definition at line 278 of file optsgrid.h.

UINT32 ActionSetDefaultGrid::GridSubDivisions [private]
 

Definition at line 279 of file optsgrid.h.

UnitType ActionSetDefaultGrid::GridUnits [private]
 

Definition at line 280 of file optsgrid.h.

MILLIPOINT ActionSetDefaultGrid::OriginX [private]
 

Definition at line 283 of file optsgrid.h.

MILLIPOINT ActionSetDefaultGrid::OriginY [private]
 

Definition at line 284 of file optsgrid.h.

Spread* ActionSetDefaultGrid::pSpread [private]
 

Definition at line 277 of file optsgrid.h.

GridType ActionSetDefaultGrid::TypeOfGrid [private]
 

Definition at line 281 of file optsgrid.h.


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