00001 // $Id: optsgrid.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 // 00099 // Implementation of the Grid and Rulers tab of the options dialog box 00100 00101 /* 00102 00103 */ 00104 00105 #include "camtypes.h" 00106 #include "appprefs.h" 00107 //#include "prefsdlg.h" // dialog/gadget ids 00108 //#include "optsres.h" // error strings 00109 #include "optsmsgs.h" 00110 #include "optsgrid.h" 00111 //#include "app.h" // Camelot object - in camtypes.h [AUTOMATICALLY REMOVED] 00112 //#include "document.h" // document object - in camtypes.h [AUTOMATICALLY REMOVED] 00113 //#include "spread.h" // spread object - in camtypes.h [AUTOMATICALLY REMOVED] 00114 #include "page.h" // page object 00115 //#include "units.h" // units - in camtypes.h [AUTOMATICALLY REMOVED] 00116 //#include "trans2d.h" // 2d translation matrix - in camtypes.h [AUTOMATICALLY REMOVED] 00117 #include "layer.h" 00118 #include "progress.h" // Begin/EndSlowJob 00119 #include "ophist.h" 00120 00121 CC_IMPLEMENT_DYNCREATE(OpGridResize, UndoableOperation) 00122 CC_IMPLEMENT_DYNCREATE(ActionSetDefaultGrid, Action) 00123 00124 // This is not compulsory, but you may as well put it in so that the correct version 00125 // of your file can be registered in the .exe 00126 DECLARE_SOURCE("$Revision: 1282 $"); 00127 00128 // Set some limit to the allowed page dimensions so that cannot have stupid values 00129 // better to do this than fall over or stop rendering. 00130 // The maximum at present which we can cope with is about 2.75M. 00131 // This was determined by trial and error, and is the maximum page size that allows an 00132 // object to be placed in the Top-Right corner, without our Render Matrix overflowing 00133 // at maximum zoom (and hence the object not rendering). 00134 // Future versions of Xara, should probably dynamically limit the Zoom factor to stop this. 00135 // but limiting the Page size is easiest for now. 00136 00137 //const MILLIPOINT MaxPageDimension = 12 * 72000 * 12; // maximum = 12ft 00138 const MILLIPOINT MaxPageDimension = 9 * 72000 * 12; // maximum = 108in = 9 ft = 275cm 00139 const MILLIPOINT MinPageDimension = 72000/2; // minimum = 0.5inch 00140 00141 00142 CC_IMPLEMENT_DYNAMIC(GridTab, OptionsTabs) 00143 00144 /******************************************************************************************** 00145 00146 > GridTab::GridTab() 00147 00148 00149 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00150 Created: 5/10/95 00151 Inputs: - 00152 Outputs: - 00153 Returns: - 00154 Purpose: GridTab constructor. Creates a non-undoable operation 00155 Errors: - 00156 SeeAlso: - 00157 00158 ********************************************************************************************/ 00159 00160 GridTab::GridTab() 00161 { 00162 // Do nothing for now 00163 } 00164 00165 /******************************************************************************************** 00166 00167 > GridTab::~GridTab() 00168 00169 00170 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00171 Created: 5/10/95 00172 Inputs: - 00173 Outputs: - 00174 Returns: - 00175 Purpose: GridTab destructor 00176 Errors: - 00177 SeeAlso: - 00178 00179 ********************************************************************************************/ 00180 00181 GridTab::~GridTab() 00182 { 00183 } 00184 00185 /******************************************************************************************** 00186 00187 > BOOL GridTab::Init() 00188 00189 00190 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00191 Created: 5/10/95 00192 Inputs: - 00193 Outputs: - 00194 Returns: True if initialised ok, False if failed. 00195 Purpose: GridTab initialisation routine 00196 Errors: - 00197 SeeAlso: - 00198 00199 ********************************************************************************************/ 00200 00201 BOOL GridTab::Init() 00202 { 00203 // Init (register) all our undoable operations 00204 if (!OpGridResize::Init()) 00205 return(FALSE); 00206 00207 return TRUE; 00208 } 00209 00210 00211 /****************************************************************************************** 00212 00213 > CDlgResID GridTab::GetPageID()() 00214 00215 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00216 Created: 5/10/95 00217 Inputs: - 00218 Outputs: - 00219 Returns: The dialog ID of this tab section. 00220 Purpose: Allows the options dialog code to determine the dialog ID of this section. 00221 Errors: - 00222 SeeAlso: - 00223 00224 ******************************************************************************************/ 00225 00226 CDlgResID GridTab::GetPageID() 00227 { 00228 return _R(IDD_OPTSTAB_GRID); 00229 } 00230 00231 /****************************************************************************************** 00232 00233 > BOOL GridTab::IsDocumentOption() 00234 00235 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00236 Created: 5/10/95 00237 Inputs: - 00238 Outputs: - 00239 Returns: Returns True if this tab is a document option. 00240 Purpose: Allows the document options dialog code to determine if this tab belongs 00241 to the group of document options. 00242 Errors: - 00243 SeeAlso: IsProgramOption(); 00244 00245 ******************************************************************************************/ 00246 00247 BOOL GridTab::IsDocumentOption() 00248 { 00249 return TRUE; // This tab is not a document option 00250 } 00251 00252 /****************************************************************************************** 00253 00254 > BOOL GridTab::IsProgramOption() 00255 00256 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00257 Created: 5/10/95 00258 Inputs: - 00259 Outputs: - 00260 Returns: Returns True if this tab is a program option. 00261 Purpose: Allows the program options dialog code to determine if this tab belongs 00262 to the group of program options. 00263 Errors: - 00264 SeeAlso: IsProgramOption(); 00265 00266 ******************************************************************************************/ 00267 00268 BOOL GridTab::IsProgramOption() 00269 { 00270 return TRUE; // This tab is a program option 00271 } 00272 00273 00274 /****************************************************************************************** 00275 00276 > BOOL AppPrefsDlg::CommitSection() 00277 00278 Author: Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com> 00279 Created: 18/10/95 00280 Returns: TRUE if worked, FALSE if fails 00281 Purpose: Reads the gadgets on the Grid and Ruler Options Tab and sets the appropriate 00282 values in the grid in the spread dictated by the OptionsTab class, currently 00283 kept up to date with the first spread in the selected document 00284 00285 If False is returned then **MUST** have reported error to the user otherwise 00286 the dialog box will refuse to close and the user will not know why. 00287 Also, individual controls must report their individual errors and not go 00288 through some crazy system and then ***NOT*** report the errors 00289 00290 ******************************************************************************************/ 00291 00292 BOOL GridTab::CommitSection() 00293 { 00294 ERROR2IF(pPrefsDlg==NULL,FALSE,"GridTab::CommitSection() - pPrefsDlg==NULL"); 00295 00296 if (pDocument==NULL || pPrefsDlg->TalkToPage(_R(IDD_OPTSTAB_GRID))==FALSE) 00297 return TRUE; // just return with no error 00298 00299 // create storage for required values and init to arbitary but legal values 00300 UnitType GridUnits = NOTYPE; 00301 double GridSpacing = 72000.0; 00302 double GridDivs = 1.0; 00303 UINT32 GridSubDivs = 8; 00304 GridType TypeOfGrid = RECTANGULAR; 00305 00306 // Determine the current grid units and grid divisions (ie grid step in terms of units) 00307 // First the grid spacing 00308 BOOL ok = pPrefsDlg->GetDoubleAndUnitGadgetValue(&GridSpacing, &GridDivs, &GridUnits, _R(IDC_OPTS_GRIDSPACING), pSpread); 00309 if (!ok) 00310 { 00311 // We have had an error so inform the user that something is wrong 00312 InformWarning(_R(IDE_OPTS_INVALIDGRIDSPACE)); 00313 return FALSE; 00314 } 00315 // ensure sensible grid spacing 00316 if (GridSpacing <= 0 || GridSpacing >= MaxPageDimension) 00317 { 00318 InformWarning(_R(IDE_OPTS_INVALIDGRIDSPACE)); 00319 return FALSE; 00320 } 00321 00322 00323 // determine grid sub-divisions 00324 GridSubDivs = pPrefsDlg->GetLongGadgetValue(_R(IDC_OPTS_GRIDDIVISIONS), 0,100, _R(IDE_OPTS_INVALIDGRIDDIV), &ok); 00325 if (!ok) 00326 { 00327 // We have had an error, informed the user so get out now before any more errors are reported 00328 return FALSE; 00329 } 00330 00331 // Make sure we have a sensible number of sub divisions 00332 if (GridSubDivs < 1) 00333 GridSubDivs = 1; 00334 00335 // then grid type 00336 //WEBSTER-ranbirr-13/11/96 00337 #ifndef WEBSTER 00338 TypeOfGrid = pPrefsDlg->GetLongGadgetValue(_R(IDC_OPTS_RECTANGULAR), 0,1,0,&ok) ? RECTANGULAR : ISOMETRIC; 00339 #endif //webster 00340 // determine the origin 00341 DocCoord PageRelativeOrigin(0,0); 00342 //WEBSTER-ranbirr-13/11/96 00343 #ifndef WEBSTER 00344 PageRelativeOrigin.x = pPrefsDlg->GetDimensionGadgetValue(_R(IDC_OPTS_ORIGINX), pSpread, &ok); 00345 if (ok) PageRelativeOrigin.y = pPrefsDlg->GetDimensionGadgetValue(_R(IDC_OPTS_ORIGINY), pSpread, &ok); 00346 if (!ok) 00347 { 00348 // We have had an error so inform the user that something is wrong 00349 InformWarning(_R(IDE_OPTS_INVALIDORIGIN)); 00350 return FALSE; 00351 } 00352 00353 DocCoord Origin(0,0); 00354 ok = pSpread->PagesCoordToSpreadCoord(&Origin,PageRelativeOrigin); 00355 if (!ok) 00356 { 00357 // We have had an error so inform the user that something is wrong 00358 InformWarning(_R(IDE_OPTS_INVALIDORIGIN)); 00359 return FALSE; 00360 } 00361 00362 // Ensure the origin falls within the spread's pasteboard 00363 DocRect SpreadRect = pSpread->GetPasteboardRect(FALSE); 00364 pSpread->DocCoordToSpreadCoord(&SpreadRect); 00365 00366 if (!SpreadRect.ContainsCoord(Origin)) 00367 { 00368 InformWarning(_R(IDE_OPTS_INVALIDORIGIN)); 00369 return FALSE; 00370 } 00371 #endif //webster 00372 // Set up param block with new grid info and invoke the resize op 00373 GridResizeInfo Param; 00374 Param.GridSpacing = GridSpacing; 00375 Param.GridSubDivisions = GridSubDivs; 00376 Param.GridDivisions = GridDivs; 00377 Param.GridUnits = GridUnits; 00378 Param.TypeOfGrid = TypeOfGrid; 00379 Param.OriginX = PageRelativeOrigin.x; 00380 Param.OriginY = PageRelativeOrigin.y; 00381 InvokeResize(&Param); 00382 00383 return TRUE; 00384 } 00385 00386 /****************************************************************************************** 00387 00388 > BOOL GridTab::NewUnitsInSection() 00389 00390 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00391 Created: 5/10/95 00392 Inputs: - 00393 Outputs: - 00394 Returns: True if values in dialog box ok, False otherwise. 00395 Purpose: Function called when new default units come into operation. We must convert 00396 all units fields to display in the newly specified units. 00397 Errors: - 00398 SeeAlso: - 00399 00400 ******************************************************************************************/ 00401 00402 BOOL GridTab::NewUnitsInSection() 00403 { 00404 TRACEUSER( "Neville", _T("New units in page section\n")); 00405 ERROR2IF(pPrefsDlg == NULL,FALSE,"GridTab::NewUnitsInSection called with no dialog pointer"); 00406 00407 BOOL ok = pPrefsDlg->TalkToPage(_R(IDD_OPTSTAB_GRID)); // The page tab identifier 00408 if (!ok) 00409 return TRUE; // Talk to page failed to return now 00410 00411 00412 // All units work off the selected document and so we must do nothing if there is no 00413 // selected document. Check our clas variable to see if this is true or not. 00414 // Units should have been set up by the caller. 00415 if (pDocument == NULL) 00416 { 00417 // the dialog box is greyed. 00418 GreySection(); 00419 return (TRUE); 00420 } 00421 00422 // Do the same things as the normal init section code 00423 InitGridSection(); 00424 00425 return TRUE; 00426 } 00427 00428 /******************************************************************************************** 00429 00430 > BOOL GridTab::GreySection() 00431 00432 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00433 Created: 5/10/95 00434 Inputs: - 00435 Outputs: - 00436 Returns: - 00437 Purpose: Called when the user has closed all documents 00438 Errors: - 00439 SeeAlso: GridTab::UngreySection; 00440 00441 ********************************************************************************************/ 00442 00443 BOOL GridTab::GreySection() 00444 { 00445 TRACEUSER( "Neville", _T("GreySection in page section\n")); 00446 ERROR2IF(pPrefsDlg == NULL,FALSE,"GridTab::GreySection called with no dialog pointer"); 00447 00448 BOOL ok = pPrefsDlg->TalkToPage(_R(IDD_OPTSTAB_GRID)); // The grid tab identifier 00449 if (!ok) 00450 return TRUE; // Talk to page failed to return now 00451 00452 // Make sure the information field displaying the name of the current document 00453 // is correct. 00454 String_256 DocumentName(_R(IDT_OPTS_GRID_INFO)); 00455 DocumentName += *GetDocumentName(); 00456 pPrefsDlg->SetStringGadgetValue(_R(IDC_OPTS_INFO), DocumentName); 00457 00458 // Only update if we are not already grey 00459 if (GreyStatus == TRUE) 00460 return TRUE; 00461 00462 // Call our central greying/ungreying function 00463 ok = ChangeControlStatus(FALSE); 00464 00465 GreyStatus = TRUE; 00466 00467 return ok; 00468 } 00469 00470 /******************************************************************************************** 00471 00472 > BOOL GridTab::UngreySection() 00473 00474 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00475 Created: 5/10/95 00476 Inputs: - 00477 Outputs: - 00478 Returns: - 00479 Purpose: Called when the user has selected a new document 00480 Errors: - 00481 SeeAlso: GridTab::UngreySection; 00482 00483 ********************************************************************************************/ 00484 00485 BOOL GridTab::UngreySection() 00486 { 00487 TRACEUSER( "Neville", _T("UngreySection in page section\n")); 00488 ERROR2IF(pPrefsDlg == NULL,FALSE,"GridTab::UngreySection called with no dialog pointer"); 00489 00490 BOOL ok = pPrefsDlg->TalkToPage(_R(IDD_OPTSTAB_GRID)); // The grid tab identifier 00491 if (!ok) 00492 return TRUE; // Talk to page failed to return now 00493 00494 // Make sure the information field displaying the name of the current document 00495 // is correct. 00496 String_256 DocumentName(_R(IDT_OPTS_GRID_INFO)); 00497 DocumentName += *GetDocumentName(); 00498 pPrefsDlg->SetStringGadgetValue(_R(IDC_OPTS_INFO), DocumentName); 00499 00500 // Only update if we are not already ungrey 00501 if (GreyStatus == FALSE) 00502 return TRUE; 00503 00504 // Call our central greying/ungreying function 00505 ok = ChangeControlStatus(TRUE); 00506 00507 GreyStatus = FALSE; 00508 00509 return ok; 00510 } 00511 00512 /******************************************************************************************** 00513 00514 > BOOL GridTab::ChangeControlStatus(const BOOL Status) 00515 00516 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00517 Created: 5/10/95 00518 Inputs: - 00519 Outputs: - 00520 Returns: - 00521 Purpose: Called to grey/ungrey all controls on this tab. 00522 Errors: - 00523 SeeAlso: GridTab::GreySection; GridTab::UngreySection; 00524 00525 ********************************************************************************************/ 00526 00527 BOOL GridTab::ChangeControlStatus(const BOOL Status) 00528 { 00529 // Grey/Ungrey the controls 00530 pPrefsDlg->EnableGadget(_R(IDC_OPTS_INFO), Status); 00531 00532 pPrefsDlg->EnableGadget(_R(IDC_OPTS_ORIGINGROUP), Status); 00533 //WEBSTER-ranbirr-13/11/96 00534 #ifndef WEBSTER 00535 pPrefsDlg->EnableGadget(_R(IDC_OPTS_ORIGINXTXT), Status); 00536 #endif //webster 00537 pPrefsDlg->EnableGadget(_R(IDC_OPTS_ORIGINYTXT), Status); 00538 //WEBSTER-ranbirr-13/11/96 00539 #ifndef WEBSTER 00540 pPrefsDlg->EnableGadget(_R(IDC_OPTS_ORIGINX), Status); 00541 pPrefsDlg->EnableGadget(_R(IDC_OPTS_ORIGINY), Status); 00542 pPrefsDlg->EnableGadget(_R(IDC_OPTS_GRIDGROUP), Status); 00543 #endif //webster 00544 pPrefsDlg->EnableGadget(_R(IDC_OPTS_GRIDSPACETXT), Status); 00545 pPrefsDlg->EnableGadget(_R(IDC_OPTS_GRIDSPACING), Status); 00546 //WEBSTER-ranbirr-13/11/96 00547 #ifndef WEBSTER 00548 pPrefsDlg->EnableGadget(_R(IDC_OPTS_GRIDDIVTXT), Status); 00549 #endif //webster 00550 pPrefsDlg->EnableGadget(_R(IDC_OPTS_GRIDDIVISIONS), Status); 00551 pPrefsDlg->EnableGadget(_R(IDC_OPTS_GRIDTYPE), Status); 00552 //WEBSTER-ranbirr-13/11/96 00553 #ifndef WEBSTER 00554 pPrefsDlg->EnableGadget(_R(IDC_OPTS_ISOMETRIC), Status); 00555 pPrefsDlg->EnableGadget(_R(IDC_OPTS_RECTANGULAR), Status); 00556 #endif //webster 00557 return TRUE; 00558 } 00559 00560 /******************************************************************************************** 00561 00562 > BOOL GridTab::UpdateSection(String_256 *DocumentName) 00563 00564 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00565 Created: 5/10/95 00566 Inputs: Name of document 00567 Outputs: - 00568 Returns: - 00569 Purpose: Called when we have switched to a new document and need to update all the 00570 controls on this tab. Should only init the tab if the page is present. 00571 The document name allows the info field on the tab to be filled in correctly. 00572 Errors: - 00573 SeeAlso: GridTab::GreySection; GridTab::UngreySection; GridTab::InitSection; 00574 00575 ********************************************************************************************/ 00576 00577 BOOL GridTab::UpdateSection(String_256 *DocumentName) 00578 { 00579 TRACEUSER( "Neville", _T("GridTab::UpdateSection\n")); 00580 ERROR2IF(pPrefsDlg == NULL,FALSE,"GridTab::UpdateSection called with no dialog pointer"); 00581 00582 BOOL ok = pPrefsDlg->TalkToPage(_R(IDD_OPTSTAB_GRID)); // The Page page identifier 00583 if (!ok) 00584 return TRUE; // page not present 00585 00586 // Make sure the information field displaying the name of the current document is correct. 00587 String_256 DocName(_R(IDT_OPTS_GRID_INFO)); 00588 DocName += *DocumentName; 00589 pPrefsDlg->SetStringGadgetValue(_R(IDC_OPTS_INFO), DocName); 00590 00591 // All units work off the selected document and so we must do nothing if there is no 00592 // selected document. Check our clas variable to see if this is true or not. 00593 // Units should have been set up by the caller. 00594 if (pDocument == NULL) 00595 { 00596 GreySection(); 00597 return TRUE; 00598 } 00599 00600 // Do the same things as the normal init section code 00601 InitGridSection(); 00602 00603 return TRUE; 00604 } 00605 00606 00607 /******************************************************************************************** 00608 00609 > BOOL GridTab::UpdateGridSection() 00610 00611 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00612 Created: 5/10/95 00613 Inputs: - 00614 Outputs: - 00615 Returns: - 00616 Purpose: Called when we have undone a default grid resize operation and hence need to 00617 update the default grid's details on the page section of this tab. 00618 Should only init the tab if the page is present. 00619 Errors: - 00620 SeeAlso: GridTab::GreySection; GridTab::UngreySection; GridTab::InitSection; 00621 00622 ********************************************************************************************/ 00623 00624 BOOL GridTab::UpdateGridSection() 00625 { 00626 TRACEUSER( "Neville", _T("GridTab::UpdateGridSection\n")); 00627 ERROR2IF(pPrefsDlg == NULL,FALSE,"GridTab::UpdateGridSection called with no dialog pointer"); 00628 00629 BOOL ok = pPrefsDlg->TalkToPage(_R(IDD_OPTSTAB_GRID)); // The Page page identifier 00630 if (!ok) 00631 return TRUE; // page not present 00632 00633 // All units work off the selected document and so we must do nothing if there is no 00634 // selected document. Check our clas variable to see if this is true or not. 00635 // Units should have been set up by the caller. 00636 if (pDocument == NULL) 00637 { 00638 GreySection(); 00639 return (TRUE); 00640 } 00641 00642 // Call the normal init section code for the page parts 00643 return InitGridSection(); 00644 } 00645 00646 /******************************************************************************************** 00647 00648 > BOOL GridTab::HandleMsg(DialogMsg* Msg) 00649 00650 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00651 Created: 5/10/95 00652 Inputs: - 00653 Outputs: - 00654 Returns: - 00655 Purpose: Handles all the Page options tabs messages 00656 Errors: - 00657 SeeAlso: - 00658 00659 ********************************************************************************************/ 00660 00661 BOOL GridTab::HandleMsg(DialogMsg* Msg) 00662 { 00663 TRACEUSER( "Neville", _T("HandlePageMsg\n")); 00664 ERROR2IF(Msg == NULL,FALSE,"GridTab::Message null message received"); 00665 ERROR2IF(pPrefsDlg == NULL,FALSE,"GridTab::HandleMsg called with no dialog pointer"); 00666 00667 BOOL ok = pPrefsDlg->TalkToPage(_R(IDD_OPTSTAB_GRID)); // The Page page identifier 00668 if (!ok) 00669 return TRUE; // page not present 00670 00671 switch(Msg->DlgMsg) 00672 { 00673 case DIM_CREATE: // Initialise controls 00674 GreyStatus = FALSE; // we are ungreyed by default 00675 ok = InitSection(); 00676 if (!ok) 00677 InformError(); 00678 break; 00679 case DIM_LFT_BN_CLICKED: 00680 case DIM_SELECTION_CHANGED: 00681 case DIM_TEXT_CHANGED: 00682 OptionsTabs::SetApplyNowState(TRUE); 00683 break; 00684 default: 00685 break; 00686 } 00687 00688 return TRUE; 00689 } 00690 00691 00692 /****************************************************************************************** 00693 00694 > BOOL GridTab::InitSection() 00695 00696 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00697 Created: 5/10/95 00698 Inputs: - 00699 Outputs: - 00700 Returns: TRUE if successful, else FALSE 00701 Purpose: Sets initial values for the Page section of the options dialog box. 00702 This section includes the:- 00703 Errors: - 00704 SeeAlso: AppPrefsDlg; OptionsTabs; UpdateSection; 00705 00706 ******************************************************************************************/ 00707 00708 BOOL GridTab::InitSection() 00709 { 00710 TRACEUSER( "Neville", _T("InitPageSection\n")); 00711 ERROR2IF(pPrefsDlg == NULL,FALSE,"GridTab::InitSection called with no dialog pointer"); 00712 00713 // BOOL ok = TRUE; // Flag for whether value set up ok 00714 00715 // Make sure the information field displaying the name of the current document 00716 // is correct. 00717 String_256 DocumentName(_R(IDT_OPTS_GRID_INFO)); 00718 DocumentName += *GetDocumentName(); 00719 pPrefsDlg->SetStringGadgetValue(_R(IDC_OPTS_INFO), DocumentName); 00720 00721 // All units work off the selected document and so we must do nothing if there is no 00722 // selected document. Check our clas variable to see if this is true or not. 00723 // Units should have been set up by the caller. 00724 if (pDocument == NULL) 00725 { 00726 GreySection(); 00727 return (TRUE); 00728 } 00729 00730 // Set up our tab information 00731 InitGridSection(); 00732 00733 return TRUE; 00734 } 00735 00736 00737 /****************************************************************************************** 00738 00739 > BOOL GridTab::InitGridSection() 00740 00741 Author: Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com> 00742 Created: 14/9/95 00743 Returns: TRUE if everything went ok, FALSE if fails 00744 Purpose: Reflects the state of the default grid in the grid tab of the options dialog 00745 00746 ******************************************************************************************/ 00747 00748 BOOL GridTab::InitGridSection() 00749 { 00750 // validate spread/doc pointers associated with the options tab 00751 ERROR2IF(pDocument==NULL,FALSE,"GridTab::GetDefaultGridDetails() - pDocument==NULL"); 00752 ERROR2IF( pSpread==NULL,FALSE,"GridTab::GetDefaultGridDetails() - pSpread==|NULL"); 00753 00754 // get a pointer to the default grid 00755 NodeGrid* pDefaultGrid = pSpread->FindFirstDefaultGridInSpread(); 00756 ERROR2IF(pDefaultGrid==NULL,FALSE,"GridTab::GetDefaultGridDetails() - pDefaultGrid==NULL"); 00757 00758 // read current grid settings 00759 double GridSpacing = pDefaultGrid->GetMainStep(); // seems to be equivalent 00760 UINT32 GridSubDivisions = pDefaultGrid->GetSubdivisions(); 00761 UnitType GridUnits = pDefaultGrid->GetUnits(); 00762 GridType TypeOfGrid = pDefaultGrid->GetGridType(); 00763 ERROR2IF(GridUnits==NOTYPE,FALSE,"GridTab::GetDefaultGridDetails() - grid units should never be NOTYPE!"); 00764 DocCoord GridOrigin(0,0); 00765 pDefaultGrid->GetOrigin(&GridOrigin.x, &GridOrigin.y); 00766 BOOL ok = pSpread->SpreadCoordToPagesCoord(&GridOrigin,GridOrigin); // make origin page relative 00767 00768 // reflect these in the gadgets 00769 //WEBSTER-ranbirr-13/11/96 00770 #ifndef WEBSTER 00771 ok = ok && pPrefsDlg->SetLongGadgetValue(_R(IDC_OPTS_RECTANGULAR), TypeOfGrid==RECTANGULAR); 00772 ok = ok && pPrefsDlg->SetLongGadgetValue(_R(IDC_OPTS_ISOMETRIC), TypeOfGrid==ISOMETRIC); 00773 #endif //webster 00774 ok = ok && pPrefsDlg->SetLongGadgetValue(_R(IDC_OPTS_GRIDDIVISIONS), GridSubDivisions); 00775 ok = ok && pPrefsDlg->SetDimensionUnitGadgetValue(_R(IDC_OPTS_GRIDSPACING), GridUnits, GridSpacing, pDefaultGrid); 00776 //WEBSTER-ranbirr-13/11/96 00777 #ifndef WEBSTER 00778 ok = ok && pPrefsDlg->SetDimensionGadgetValue(_R(IDC_OPTS_ORIGINX), GridOrigin.x, pSpread); 00779 ok = ok && pPrefsDlg->SetDimensionGadgetValue(_R(IDC_OPTS_ORIGINY), GridOrigin.y, pSpread); 00780 #endif //webster 00781 // Note the states of the gadgets 00782 OldGridSpacing = GridSpacing; 00783 OldGridSubDivisions = GridSubDivisions; 00784 OldGridUnits = GridUnits; 00785 OldTypeOfGrid = TypeOfGrid; 00786 OldOriginX = GridOrigin.x; 00787 OldOriginY = GridOrigin.y; 00788 00789 return ok; 00790 } 00791 00792 00793 /****************************************************************************************** 00794 00795 > BOOL GridTab::InvokeResize(GridResizeInfo *Param) 00796 00797 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00798 Created: 17/2/95 00799 Inputs: 00800 Returns: True if managed to change the page/spread details ok. 00801 Purpose: Sets the new details of the page size and of the default grid. 00802 The default grid should always be resident in the spread. 00803 Assumes the class variables pDocument, pSpread have been set up. 00804 This function should be used instead of SetNewSizeOfPage and 00805 SetDefaultPageGrid as it is undoable and they aren't. 00806 Errors: - 00807 SeeAlso: AppPrefsDlg::SetCurrentSpread; SetDefaultPageGrid; 00808 00809 ******************************************************************************************/ 00810 00811 BOOL GridTab::InvokeResize(GridResizeInfo *pParam) 00812 { 00813 // For now, get details on 1st page of spread 1 00814 00815 // The dialog handler should have already set up the class variables pDocument and pSpread. 00816 // We will check that they are not null. 00817 ERROR2IF(pDocument==NULL,FALSE,"GridTab::InvokeResize() no selected document"); 00818 ERROR2IF( pSpread==NULL,FALSE,"GridTab::InvokeResize() no spread to work on"); 00819 00820 // Only change the page size/layout if something has changed 00821 // If the user has changed anything then warn them that nothing will happen 00822 // if no grid params have changed, flag this in the param block, else use them as the new defaults 00823 MILLIPOINT bodge = 5; // extra leeway on comparison required 00824 BOOL ChangeRequired = FALSE; 00825 if ( 00826 OldGridSpacing == pParam->GridSpacing && 00827 OldGridSubDivisions == pParam->GridSubDivisions && 00828 OldGridUnits == pParam->GridUnits && 00829 OldTypeOfGrid == pParam->TypeOfGrid && 00830 (OldOriginX >= (pParam->OriginX - bodge)) && (OldOriginX <= (pParam->OriginX + bodge)) && 00831 (OldOriginY >= (pParam->OriginY - bodge)) && (OldOriginY <= (pParam->OriginY + bodge)) 00832 ) 00833 { 00834 pParam->GridSpacing = 0; 00835 pParam->GridDivisions = 0; 00836 pParam->GridSubDivisions = 0; 00837 pParam->GridUnits = NOTYPE; 00838 } 00839 else 00840 { 00841 ChangeRequired = TRUE; 00842 OldGridSpacing = pParam->GridSpacing; 00843 OldGridSubDivisions = pParam->GridSubDivisions; 00844 OldGridUnits = pParam->GridUnits; 00845 OldTypeOfGrid = pParam->TypeOfGrid; 00846 OldOriginX = pParam->OriginX; 00847 OldOriginY = pParam->OriginY; 00848 } 00849 00850 if (ChangeRequired) 00851 { 00852 // Invoke the Page resizing operation so that we get Undo. 00853 OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(CC_RUNTIME_CLASS(OpGridResize)); 00854 00855 if (pOpDesc != NULL) 00856 { 00857 // Set up the parameters which we require to do the page resizing operation 00858 pParam->pSpread = pSpread; 00859 00860 // Go for it! 00861 pOpDesc->Invoke((OpParam *) pParam); 00862 } 00863 } 00864 00865 return TRUE; 00866 } 00867 00868 00869 00871 00872 /****************************************************************************************** 00873 > OpGridResize::OpGridResize() : UndoableOperation() 00874 00875 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00876 Created: 5/10/95 00877 Inputs: - 00878 Outputs: - 00879 Returns: - 00880 Purpose: OpGridResize constructor (Creates an undoable operation) 00881 SeeAlso: GridTab; 00882 00883 ******************************************************************************************/ 00884 00885 OpGridResize::OpGridResize() : UndoableOperation() 00886 { 00887 } 00888 00889 /******************************************************************************************** 00890 00891 > OpGridResize::~OpGridResize() 00892 00893 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00894 Created: 5/10/95 00895 Inputs: - 00896 Outputs: - 00897 Returns: - 00898 Purpose: OpGridResize destructor 00899 Errors: - 00900 SeeAlso: - 00901 00902 ********************************************************************************************/ 00903 00904 OpGridResize::~OpGridResize() 00905 { 00906 } 00907 00908 /****************************************************************************************** 00909 > BOOL OpAlign::Init() 00910 00911 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00912 Created: 5/10/95 00913 Returns: FALSE if it fails (due to lack of memory) 00914 Purpose: Creates an OpDescriptor for a Page Resize operation 00915 SeeAlso: GridTab; 00916 00917 ******************************************************************************************/ 00918 00919 BOOL OpGridResize::Init() 00920 { 00921 return RegisterOpDescriptor( 00922 0, // Tool ID 00923 _R(IDS_OPSETDEFAULTGRID), // String resource ID 00924 CC_RUNTIME_CLASS(OpGridResize), // Runtime class 00925 OPTOKEN_OPGRIDRESIZE, // Token string 00926 OpGridResize::GetState, // GetState function 00927 0, // Help ID 00928 0, // Bubble ID 00929 0, // Resource ID 00930 0 // Control ID 00931 // needs 'GREY_WHEN_NO_CURRENT_DOC' 00932 ); 00933 } 00934 00935 /****************************************************************************************** 00936 00937 > OpState OpGridResize::GetState(String_256* pString, OpDescriptor* pOpDesc) 00938 00939 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00940 Created: 5/10/95 00941 Purpose: Returns the OpState of the OpGridResize dialogue operation. 00942 SeeAlso: GridTab; 00943 00944 ******************************************************************************************/ 00945 00946 OpState OpGridResize::GetState(String_256* pString, OpDescriptor* pOpDesc) 00947 { 00948 OpState OpSt; 00949 00950 return(OpSt); 00951 } 00952 00953 /******************************************************************************************** 00954 00955 > void OpGridResize::Do(OpDescriptor*) 00956 00957 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00958 Created: 5/10/95 00959 Inputs: OpGridResize (unused) 00960 Outputs: - 00961 Returns: - 00962 Purpose: (Performs the page resizing operation) 00963 OpGridResize has a special overloaded Do operator which takes 00964 parameters describing what is to be done - that version of Do must 00965 be used 00966 Errors: Always generates an ENSURE failure because this Do doesn't. 00967 SeeAlso: - 00968 00969 ********************************************************************************************/ 00970 00971 void OpGridResize::Do(OpDescriptor *NotUsed) 00972 { 00973 ENSURE(FALSE, "OpGridResize does not provide a Do() function - Use DoWithParam"); 00974 End(); 00975 } 00976 00977 /****************************************************************************************** 00978 00979 > void OpGridResize::DoWithParam(OpDescriptor* pOpDesc, OpParam* pResizeInfo) 00980 00981 Author: Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com> 00982 Created: 10/10/95 00983 Inputs: pOpDesc - unused 00984 pResizeInfo - points to a Page resize structure with parameters: 00985 Purpose: Performs the grid resize operation via DoResizeGrid() 00986 00987 ******************************************************************************************/ 00988 00989 void OpGridResize::DoWithParam(OpDescriptor* pOp, OpParam* pResizeInfo) 00990 { 00991 if (DoResizeGrid((GridResizeInfo*)pResizeInfo)==FALSE) 00992 FailAndExecute(); 00993 End(); 00994 } 00995 00996 00997 /****************************************************************************************** 00998 00999 > BOOL OpGridResize::DoResizeGrid(GridResizeInfo* pResizeInfo) 01000 01001 Author: Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com> 01002 Created: 10/10/95 01003 Inputs: pResizeInfo - info describing how to change grid 01004 note origin is page relative and specified as 2 ordinates - why! 01005 Returns: FALSE if fails 01006 Purpose: Undoably performs the grid resize operation 01007 Forces a redraw of the parent document for the specified spread. 01008 01009 ******************************************************************************************/ 01010 01011 BOOL OpGridResize::DoResizeGrid(GridResizeInfo* pInfo) 01012 { 01013 ERROR2IF( pInfo==NULL,FALSE,"OpGridResize::DoResizeGrid() - pInfo==NULL"); 01014 Spread* pSpread = pInfo->pSpread; 01015 ERROR2IF(pSpread==NULL,FALSE,"OpGridResize::DoResizeGrid() - pSpread==NULL"); 01016 01017 // If the grid is the same as last time then we want to do nothing 01018 // This apparently is signalled by the GridDivisions and GridSubDivisions being 0! 01019 if (pInfo->GridDivisions==0 || pInfo->GridSubDivisions==0) 01020 return TRUE; 01021 01022 // find the present default grid and read it's settings for the undo action 01023 NodeGrid* pDefaultGrid = pSpread->FindFirstDefaultGridInSpread(); 01024 ERROR2IF(pDefaultGrid==NULL,FALSE,"OpGridResize::DoResizeGrid() - pDefaultGrid==NULL"); 01025 01026 double PresentGridDivisions = pDefaultGrid->GetDivisions(); 01027 UINT32 PresentGridSubDivisions = pDefaultGrid->GetSubdivisions(); 01028 UnitType PresentGridUnits = pDefaultGrid->GetUnits(); 01029 GridType PresentGridType = pDefaultGrid->GetGridType(); 01030 01031 DocCoord PresentOrigin(0,0); 01032 pDefaultGrid->GetOrigin(&PresentOrigin.x, &PresentOrigin.y); 01033 BOOL ok=pSpread->SpreadCoordToPagesCoord(&PresentOrigin,PresentOrigin); // make page relative 01034 if (!ok) return FALSE; 01035 01036 // Create an action to Undo the resizing operation 01037 ActionSetDefaultGrid *ASDG; 01038 ActionCode SetDefaultGridAction= ActionSetDefaultGrid::Init(this, 01039 &UndoActions, 01040 sizeof(ActionSetDefaultGrid), 01041 pSpread, 01042 PresentGridDivisions, 01043 PresentGridSubDivisions, 01044 PresentGridUnits, 01045 PresentGridType, 01046 PresentOrigin.x, 01047 PresentOrigin.y, 01048 (Action**)(&ASDG) 01049 ); 01050 ERROR2IF(SetDefaultGridAction==AC_FAIL,FALSE,"OpGridResize::DoResizeGrid() - ActionSetDefaultGrid::Init() failed"); 01051 01052 // Check if we must change grid types, if so, replace it with the correct type 01053 if (PresentGridType!=pInfo->TypeOfGrid) 01054 { 01055 // Create a grid of the new type 01056 NodeGrid* pNewGrid = NULL; 01057 switch (pInfo->TypeOfGrid) 01058 { 01059 case RECTANGULAR : ALLOC_WITH_FAIL(pNewGrid,(new NodeGridRect()),this); break; 01060 case ISOMETRIC : ALLOC_WITH_FAIL(pNewGrid,(new NodeGridIso()), this); break; 01061 case INVALID_GRID_TYPE: ERROR3("Use of invalid grid type"); break; 01062 } 01063 ERROR2IF(pNewGrid==NULL,FALSE,"OpGridResize::DoResizeGrid() - failed to create new grid"); 01064 01065 // The grid will cover the entire spread pasteboard area 01066 DocRect GridRect = pSpread->GetPasteboardRect(FALSE); 01067 pSpread->DocCoordToSpreadCoord(&GridRect); 01068 01069 // Attach the new grid as the last child of the specified spread 01070 pNewGrid->AttachNode(pSpread, LASTCHILD); 01071 pNewGrid->SetDefault(TRUE); // Its a default grid 01072 pNewGrid->SetBoundingRect(GridRect); 01073 01074 // Now replace the old grid with the new one 01075 pDefaultGrid->CascadeDelete(); 01076 pDefaultGrid = pNewGrid; 01077 } 01078 01079 // the grid may have been replaced with a new one so must set up all remaining values 01080 DocCoord Origin(pInfo->OriginX, pInfo->OriginY); 01081 ok = pSpread->PagesCoordToSpreadCoord(&Origin,Origin); // convert from page relaive to absolute 01082 if (ok) pDefaultGrid->SetOrigin(Origin.x,Origin.y); 01083 if (ok) ok = pDefaultGrid->SetGridParams(pInfo->GridDivisions, pInfo->GridSubDivisions, pInfo->GridUnits); 01084 if (!ok) return FALSE; 01085 01086 // since grid changed sucessfully, force redraw doc and broadcast message (eg for rulers) 01087 Document* pParentDoc = (Document*)pSpread->FindOwnerDoc(); 01088 ERROR2IF(pParentDoc==NULL,FALSE,"OpGridResize::DoResizeGrid() - pParentDoc==NULL"); 01089 pParentDoc->ForceRedraw(); 01090 BROADCAST_TO_ALL( OptionsChangingMsg(pParentDoc,OptionsChangingMsg::NEWDEFAULTGRID) ); 01091 01092 return TRUE; 01093 } 01094 01095 01096 /******************************************************************************************** 01097 01098 > ActionSetDefaultGrid::ActionSetDefaultGrid() 01099 01100 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 01101 Created: 17/2/95 01102 Purpose: ActionSetDefaultGrid constructor 01103 01104 ********************************************************************************************/ 01105 01106 ActionSetDefaultGrid::ActionSetDefaultGrid() 01107 { 01108 } 01109 01110 01111 01112 /******************************************************************************************** 01113 01114 > ActionSetDefaultGrid::~ActionSetDefaultGrid() 01115 01116 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 01117 Created: 17/2/95 01118 Purpose: ActionSetDefaultGrid destructor 01119 01120 ********************************************************************************************/ 01121 01122 ActionSetDefaultGrid::~ActionSetDefaultGrid() 01123 { 01124 } 01125 01126 01127 01128 /******************************************************************************************** 01129 01130 > virtual ActionCode ActionSetDefaultGrid::Execute() 01131 01132 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 01133 Created: 15/2/95 01134 Inputs: - 01135 Outputs: ActionCode indicating if the action was successfully executed or not 01136 Returns: - 01137 Purpose: Executes the ActionSetDefaultGrid to go and set up a new default grid in the 01138 specified spread and generates another ActionSetDefaultGrid to undo this change. 01139 Forces a redraw of the parent document of the specified spread. 01140 01141 ********************************************************************************************/ 01142 01143 ActionCode ActionSetDefaultGrid::Execute() 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 } 01263 01264 01265 01266 /******************************************************************************************** 01267 01268 > ActionCode ActionSetDefaultGrid::Init(Operation* const pOp, 01269 ActionList* pActionList, 01270 UINT32 ActionSize, 01271 Spread *pSpread, 01272 double NewGridDivisions, 01273 UINT32 NewGridSubDivisions, 01274 UnitType NewGridUnits, 01275 GridType NewGridType, 01276 MILLIPOINT NewOriginX, 01277 MILLIPOINT NewOriginY, 01278 Action** NewAction) 01279 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 01280 Created: 15/2/95 01281 01282 Inputs: pOp: The operation to which the action should be added 01283 pActionList: The action list in the operation object 01284 ActionSize: The size of the action in bytes. This should be the total 01285 size of the action (including any objects pointed to by the 01286 action). 01287 pSpread: The target spread which will be changed when we are executed 01288 NewGridDivisions: The new number of grid divisions 01289 NewGridSubDivisions: The new number of grid subdivisions 01290 NewGridUnits: The new grid units 01291 NewGridType: The new type of grid required, either Isometric or Rectangular 01292 NewOriginX: The new origin x coordinate to use 01293 NewOriginY: The new origin y coordinate to use 01294 01295 Outputs: NewAction: A pointer to the action if it could be allocated. 01296 01297 Returns: AC_FAIL: There was not enough room in the operation history for the 01298 action and the user did not wish to continue. Usually 01299 End() should be called in this situation. 01300 01301 AC_NORECORD: There was not enough room in the operation history for 01302 the action, but the user requested that he wished to 01303 continue without undo. 01304 01305 AC_OK : The action was successfully initialised and added to the 01306 operation. 01307 01308 01309 Purpose: To check that there is sufficient room for the action in the operation 01310 history, and if there is, then to add the action to the operations 01311 action list. 01312 01313 The function calls the Action::Init function passing the runtime class 01314 of an ActionSetDefaultGrid. 01315 Errors: - 01316 SeeAlso: Action::Init; OpSetDefaultGrid; GridTab::SetNewSizeOfPage; 01317 01318 ********************************************************************************************/ 01319 01320 ActionCode ActionSetDefaultGrid::Init(Operation* const pOp, 01321 ActionList* pActionList, 01322 UINT32 ActionSize, 01323 Spread *pTheSpread, 01324 double NewGridDivisions, 01325 UINT32 NewGridSubDivisions, 01326 UnitType NewGridUnits, 01327 GridType NewGridType, 01328 MILLIPOINT NewOriginX, 01329 MILLIPOINT NewOriginY, 01330 Action** NewAction) 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 }