00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 #include "camtypes.h"
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 #include "csrstack.h"
00114 #include "osrndrgn.h"
00115
00116
00117 #include "paper.h"
00118
00119
00120
00121
00122 #include "chapter.h"
00123
00124 #include "oilfiles.h"
00125 #include "camelot.h"
00126 #include "mainfrm.h"
00127
00128
00129
00130
00131 #include "cutop.h"
00132 #include "progress.h"
00133 #include "bubbleid.h"
00134
00135 #include "gridtool.h"
00136
00137
00138
00139 DECLARE_SOURCE( "$Revision: 1282 $" );
00140
00141 CC_IMPLEMENT_DYNCREATE( OpGrid, UndoableOperation )
00142 CC_IMPLEMENT_DYNCREATE( OpGridNewResize, OpGrid )
00143 CC_IMPLEMENT_DYNCREATE( OpGridSelection, OpGrid )
00144 CC_IMPLEMENT_DYNCREATE( OpGridChange, OpGrid )
00145 CC_IMPLEMENT_DYNCREATE( OpGridDelete, OpGrid )
00146 CC_IMPLEMENT_DYNCREATE( OpGridCut, OpGrid )
00147 CC_IMPLEMENT_DYNCREATE( OpGridCopy, OpGrid )
00148 CC_IMPLEMENT_DYNCREATE( OpGridPaste, OpGrid )
00149 CC_IMPLEMENT_DYNCREATE( OpGridDuplicate, OpGrid )
00150 CC_IMPLEMENT_DYNCREATE( GridInfoBarOp, InformationBarOp )
00151
00152 static OpState NoClipboardOpGetState(String_256*, OpDescriptor*);
00153
00154 #define new CAM_DEBUG_NEW
00155
00156 static struct
00157 {
00158 GridType Type;
00159 UINT32 IDS;
00160 } GridTypeList[NUM_GRID_TYPES] =
00161 {
00162 { RECTANGULAR, _R(IDS_RECTANGULAR) },
00163 { ISOMETRIC, _R(IDS_ISOMETRIC) }
00164 };
00165
00166
00167 char* GridTool::FamilyName = "Grid Tools";
00168 char* GridTool::ToolName = "Grid Tool";
00169 char* GridTool::Purpose = "Grid manipulation";
00170 char* GridTool::Author = "Mark Neves";
00171
00172 Spread* GridTool::SpreadClicked = NULL;
00173 NodeGrid* GridTool::LastGridClicked = NULL;
00174 NodeGrid* GridTool::GridClicked = NULL;
00175 GridBlobType GridTool::GridBlobClicked = NoGridBlob;
00176 DocCoord GridTool::PointClicked;
00177
00178 UINT32 GridTool::LastStatusID = 0;
00179 GridInfoBarOp* GridTool::pGridInfoBarOp = NULL;
00180 Document* GridTool::pDocument = NULL;
00181
00182 BOOL OpGridNewResize::StartADrag = TRUE;
00183 BOOL OpGridNewResize::EndTheDrag = TRUE;
00184
00185 static MILLIPOINT abs(MILLIPOINT n) { if (n<0) return (0-n); else return (n);}
00186 static MILLIPOINT sgn(MILLIPOINT n) { if (n<0) return (-1); else return (1);}
00187
00188 CC_IMPLEMENT_MEMDUMP( GridTool, Tool_v1 )
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202 GridTool::GridTool()
00203 {
00204 pcCurrentCursor = NULL;
00205 }
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217 GridTool::~GridTool()
00218 {
00219
00220
00221
00222
00223 }
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239 BOOL GridTool::Init()
00240 {
00241
00242
00243
00244
00245 BOOL ok = ( OpGridNewResize::Declare() &&
00246 OpGridSelection::Declare() &&
00247 OpGridChange::Declare());
00248
00249
00250
00251
00252
00253 if (ok)
00254 {
00255 CCResTextFile file;
00256 GridInfoBarOpCreate BarCreate;
00257
00258 ok = file.open(_R(IDM_GRID_BAR), _R(IDT_INFO_BAR_RES));
00259 if (ok) ok = DialogBarOp::ReadBarsFromFile(file,BarCreate);
00260 if (ok) file.close();
00261
00262 ENSURE(ok,"Unable to load gridbar.ini from resource\n");
00263
00264 if (ok)
00265 {
00266
00267 String_32 str = String_32(_R(IDS_GRIDTOOL_INFOBARNAME));
00268 DialogBarOp* pDialogBarOp = DialogBarOp::FindDialogBarOp(str);
00269
00270 ok = (pDialogBarOp != NULL);
00271 if (ok) ok = pDialogBarOp->IsKindOf(CC_RUNTIME_CLASS(GridInfoBarOp));
00272 if (ok) pGridInfoBarOp = (GridInfoBarOp*)pDialogBarOp;
00273
00274 ENSURE(ok,"Couldn't find grid tool info bar");
00275 }
00276 }
00277
00278 return (ok);
00279 }
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298 void GridTool::Describe(void *InfoPtr)
00299 {
00300
00301 ToolInfo_v1 *Info = (ToolInfo_v1 *) InfoPtr;
00302
00303 Info -> InfoVersion = 1;
00304
00305 Info -> InterfaceVersion = GetToolInterfaceVersion();
00306
00307
00308 Info -> Version = 1;
00309 Info -> ID = GetID();
00310 Info -> TextID = _R(IDS_GRID_TOOL);
00311
00312 Info -> Family = FamilyName;
00313 Info -> Name = ToolName;
00314 Info -> Purpose = Purpose;
00315 Info -> Author = Author;
00316
00317 Info -> InfoBarDialog = _R(IDD_GRIDTOOL);
00318 Info -> BubbleID = _R(IDBBL_GRID_TOOLBOX);
00319 }
00320
00321 UINT32 GridTool::GetID()
00322 {
00323 return TOOLID_GRID;
00324 }
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347 void GridTool::SelectChange(BOOL isSelected)
00348 {
00349 if (isSelected)
00350 {
00351
00352 GridTool::SetDoc(Document::GetCurrent());
00353
00354 if (!CreateCursors()) return;
00355
00356 CurrentCursorID = CursorStack::GPush(pcNormalGridCursor, FALSE);
00357 pcCurrentCursor = pcNormalGridCursor;
00358
00359
00360 if (DocView::GetSelected() != NULL)
00361 {
00362 if (!DocView::GetSelected()->GetShowGridState())
00363 NodeGrid::ForceRedrawAllGrids();
00364 else
00365 RenderAllGridBlobs();
00366 }
00367
00368 GridTool::FindCurrentSpread();
00369
00370
00371
00372 pGridInfoBarOp->Create();
00373
00374
00375 OpDescriptor* pOpDesc;
00376
00377
00378
00379 pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_DELETE);
00380 if (pOpDesc != NULL) pOpDesc->AliasOperation(CC_RUNTIME_CLASS(OpGridDelete),OpGridDelete::GetState);
00381
00382 pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_CUT);
00383 if (pOpDesc != NULL) pOpDesc->AliasOperation(CC_RUNTIME_CLASS(OpGridCut),NoClipboardOpGetState);
00384
00385 pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_COPY);
00386 if (pOpDesc != NULL) pOpDesc->AliasOperation(CC_RUNTIME_CLASS(OpGridCopy),NoClipboardOpGetState);
00387
00388 pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_PASTE);
00389 if (pOpDesc != NULL) pOpDesc->AliasOperation(CC_RUNTIME_CLASS(OpGridPaste),NoClipboardOpGetState);
00390
00391 pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_DUPLICATE);
00392 if (pOpDesc != NULL) pOpDesc->AliasOperation(CC_RUNTIME_CLASS(OpGridDuplicate),OpGridDuplicate::GetState);
00393 }
00394 else
00395 {
00396
00397 if (pcCurrentCursor != NULL)
00398 {
00399 CursorStack::GPop(CurrentCursorID);
00400 delete pcNormalGridCursor;
00401 delete pcOverGridCursor;
00402 delete pcOverBlobCursorUD;
00403 delete pcOverBlobCursorLR;
00404 delete pcOverBlobCursorTL;
00405 delete pcOverBlobCursorTR;
00406 pcCurrentCursor = NULL;
00407 CurrentCursorID = 0;
00408 }
00409
00410 if (DocView::GetSelected() != NULL)
00411 {
00412 if (!DocView::GetSelected()->GetShowGridState())
00413 NodeGrid::ForceRedrawAllGrids();
00414 else
00415 RenderAllGridBlobs();
00416 }
00417
00418
00419 pGridInfoBarOp->Delete();
00420
00421 SpreadClicked = NULL;
00422 }
00423 }
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445 void GridTool::SetDoc(Document* pThisDoc)
00446 {
00447 if (GridTool::pDocument != pThisDoc)
00448 {
00449 GridTool::pDocument = pThisDoc;
00450 if (GridTool::pDocument != NULL)
00451 NodeGrid::SetDefaultUnits(GridTool::pDocument->GetDocUnitList()->GetPageUnits());
00452 else
00453 NodeGrid::SetDefaultUnits(NOTYPE);
00454
00455 GridTool::FindCurrentSpread();
00456 pGridInfoBarOp->InitControls();
00457 pGridInfoBarOp->DisplayDefaultGridInfo();
00458 }
00459 }
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476 BOOL GridTool::CreateCursors()
00477 {
00478
00479 pcNormalGridCursor = new Cursor(this, _R(IDC_GRIDTOOLCURSOR));
00480 pcOverGridCursor = new Cursor(this, _R(IDC_MOVEBEZIERCURSOR));
00481 pcOverBlobCursorUD = new Cursor(_R(IDC_SIZENS));
00482 pcOverBlobCursorLR = new Cursor(_R(IDC_SIZEWE));
00483 pcOverBlobCursorTL = new Cursor(_R(IDC_SIZENWSE));
00484 pcOverBlobCursorTR = new Cursor(_R(IDC_SIZENESW));
00485
00486 if ( pcNormalGridCursor==NULL || !pcNormalGridCursor->IsValid() ||
00487 pcOverGridCursor==NULL || !pcOverGridCursor->IsValid() ||
00488 pcOverBlobCursorUD==NULL || !pcOverBlobCursorUD->IsValid() ||
00489 pcOverBlobCursorLR==NULL || !pcOverBlobCursorLR->IsValid() ||
00490 pcOverBlobCursorTL==NULL || !pcOverBlobCursorTL->IsValid() ||
00491 pcOverBlobCursorTR==NULL || !pcOverBlobCursorTR->IsValid())
00492 {
00493 if (IsUserName("MarkN")) TRACE( _T("Couldn't create grid tool cursors!\n"));
00494
00495 if (pcNormalGridCursor != NULL) delete pcNormalGridCursor;
00496 if (pcOverGridCursor != NULL) delete pcOverGridCursor;
00497 if (pcOverBlobCursorUD != NULL) delete pcOverBlobCursorUD;
00498 if (pcOverBlobCursorLR != NULL) delete pcOverBlobCursorLR;
00499 if (pcOverBlobCursorTL != NULL) delete pcOverBlobCursorTL;
00500 if (pcOverBlobCursorTR != NULL) delete pcOverBlobCursorTR;
00501 return FALSE;
00502 }
00503 else
00504 return TRUE;
00505 }
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522 void GridTool::FindCurrentSpread()
00523 {
00524 Spread* pSpreadWithSelGrids = NULL;
00525 Spread* pSpreadWithSelObjects = NULL;
00526
00527 if (GridTool::GetDoc() != NULL)
00528 {
00529
00530
00531 Chapter* pChapter = Node::FindFirstChapter(GridTool::GetDoc());
00532 while (pChapter != NULL && pSpreadWithSelGrids == NULL)
00533 {
00534
00535 Node* pNode = pChapter->FindFirstChild();
00536 while (pNode != NULL && pSpreadWithSelGrids == NULL)
00537 {
00538
00539 if (pNode->IsKindOf(CC_RUNTIME_CLASS(Spread)))
00540 {
00541 Spread* pSpread = (Spread*)pNode;
00542 if (HasSpreadSelGrids(pSpread))
00543 pSpreadWithSelGrids = pSpread;
00544 }
00545 pNode = pNode->FindNext();
00546 }
00547 pChapter = pChapter->FindNextChapter();
00548 }
00549
00550 if (pSpreadWithSelGrids == NULL)
00551 {
00552
00553 Range Sel(*(GetApplication()->FindSelection()));
00554
00555
00556 Node* FirstSelected = Sel.FindFirst();
00557
00558
00559
00560 if (FirstSelected != NULL)
00561 pSpreadWithSelObjects = (Spread*)FirstSelected->FindParent(CC_RUNTIME_CLASS(Spread));
00562 }
00563 }
00564
00565 if (pSpreadWithSelGrids != NULL)
00566 SpreadClicked = pSpreadWithSelGrids;
00567 else
00568 SpreadClicked = pSpreadWithSelObjects;
00569 }
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586 BOOL GridTool::HasSpreadSelGrids(Spread* pSpread)
00587 {
00588
00589 Node* pNode = pSpread->FindFirstChild();
00590 while (pNode != NULL)
00591 {
00592 if (pNode->IsKindOf(CC_RUNTIME_CLASS(NodeGrid)))
00593 {
00594
00595 NodeGrid* pGrid = (NodeGrid*)pNode;
00596 if (!pGrid->IsDisabled() && pGrid->IsGridSelected())
00597 return TRUE;
00598 }
00599 pNode = pNode->FindNext();
00600 }
00601 return FALSE;
00602 }
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659 void GridTool::RenderAllGridBlobs()
00660 {
00661 DocView* pDocView = DocView::GetCurrent();
00662 if (pDocView == NULL) return;
00663 if (pDocView->GetDoc() == NULL) return;
00664 Document* pDoc = pDocView->GetDoc();
00665 pDoc->SetCurrent();
00666
00667
00668
00669
00670 Chapter* pChapter = Node::FindFirstChapter(pDoc);
00671 while (pChapter != NULL)
00672 {
00673
00674 Node* pNode = pChapter->FindFirstChild();
00675 while (pNode != NULL)
00676 {
00677
00678 if (pNode->IsKindOf(CC_RUNTIME_CLASS(Spread)))
00679 {
00680 Spread* pSpread = (Spread*)pNode;
00681
00682 DocRect BB = pSpread->GetPasteboardRect();
00683 pSpread->DocCoordToSpreadCoord(&BB);
00684
00685
00686
00687 RenderGridBlobsInSpread(pDocView,pSpread,&BB);
00688 }
00689 pNode = pNode->FindNext();
00690 }
00691 pChapter = pChapter->FindNextChapter();
00692 }
00693 }
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710 void GridTool::RenderGridBlobsInSpread(DocView* pDocView,Spread* pSpread,DocRect* pDocRect)
00711 {
00712
00713
00714 RenderRegion* pRender = pDocView->RenderOnTop(pDocRect,pSpread,UnclippedEOR);
00715
00716 while (pRender != NULL)
00717 {
00718
00719 Node* pNode = pSpread->FindFirstChild();
00720 while (pNode != NULL)
00721 {
00722 if (pNode->IsKindOf(CC_RUNTIME_CLASS(NodeGrid)))
00723 {
00724
00725 NodeGrid* pGrid = (NodeGrid*)pNode;
00726 RenderGridBlobs(pRender,pGrid);
00727
00728 if (pGrid->IsGridSelected() && !pGrid->IsDefault())
00729 RenderGridSelectBlobs(pRender,pGrid);
00730 }
00731 pNode = pNode->FindNext();
00732 }
00733
00734
00735 pRender = pDocView->GetNextOnTop(pDocRect);
00736 }
00737 }
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753 void GridTool::RenderGridBlobs(RenderRegion* pRender,NodeGrid* pGrid)
00754 {
00755 if (!pGrid->IsDefault())
00756 {
00757 DocRect Rect = pGrid->GetBoundingRect();
00758
00759 pRender->SetLineColour(COLOUR_GRID);
00760 pRender->SetFillColour(COLOUR_TRANS);
00761 pRender->DrawRect(&Rect);
00762 }
00763 }
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780 void GridTool::RenderGridBlobs(NodeGrid* pGrid)
00781 {
00782 DocView* pDocView;
00783 Spread* pSpread;
00784 DocRect Rect;
00785
00786
00787 if (!GetGridBlobRenderVars(pGrid,&pDocView,&pSpread,&Rect)) return;
00788
00789
00790
00791
00792 RenderRegion* pRender = pDocView->RenderOnTop(&Rect,pSpread,UnclippedEOR);
00793
00794
00795 while (pRender != NULL)
00796 {
00797 RenderGridBlobs(pRender,pGrid);
00798 pRender = pDocView->GetNextOnTop(&Rect);
00799 }
00800 }
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816 void GridTool::RenderGridSelectBlobs(RenderRegion* pRender,NodeGrid* pGrid)
00817 {
00818 if (!pGrid->IsDefault())
00819 {
00820
00821 pRender->SetLineColour(COLOUR_NONE);
00822 pRender->SetFillColour(COLOUR_UNSELECTEDBLOB);
00823
00824 for(INT32 i = BottomLeft;i < NumGridBlobTypes;i++)
00825 pRender->DrawBlob(pGrid->GetBlobCoord((GridBlobType)i),BT_UNSELECTED);
00826 }
00827 }
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844 void GridTool::RenderGridSelectBlobs(NodeGrid* pGrid)
00845 {
00846 DocView* pDocView;
00847 Spread* pSpread;
00848 DocRect Rect;
00849
00850
00851 if (!GetGridBlobRenderVars(pGrid,&pDocView,&pSpread,&Rect)) return;
00852
00853
00854
00855
00856 RenderRegion* pRender = pDocView->RenderOnTop(&Rect,pSpread,UnclippedEOR);
00857
00858
00859 while (pRender != NULL)
00860 {
00861 RenderGridSelectBlobs(pRender,pGrid);
00862 pRender = pDocView->GetNextOnTop(&Rect);
00863 }
00864 }
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882 void GridTool::RenderAllGridBlobs(NodeGrid* pGrid)
00883 {
00884 RenderGridBlobs(pGrid);
00885 RenderGridSelectBlobs(pGrid);
00886 }
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914 BOOL GridTool::GetGridBlobRenderVars(NodeGrid* pGrid,DocView** ppDocView,Spread** ppSpread,DocRect* pDocRect)
00915 {
00916
00917 *ppDocView = DocView::GetCurrent();
00918 if (*ppDocView == NULL) return (FALSE);
00919
00920
00921 *ppSpread = pGrid->FindParentSpread();
00922 if (*ppSpread == NULL) return (FALSE);
00923
00924
00925 *pDocRect = (*ppSpread)->GetPasteboardRect();
00926 (*ppSpread)->DocCoordToSpreadCoord(pDocRect);
00927
00928 return (TRUE);
00929 }
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949 void GridTool::RenderToolBlobs(Spread* pSpread,DocRect* pDocRect)
00950 {
00951
00952
00953
00954 DocView* pDocView = DocView::GetSelected();
00955 if (pDocView != NULL)
00956 RenderGridBlobsInSpread(pDocView,pSpread,pDocRect);
00957 }
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009 void GridTool::ForceRedraw(Spread* pSpread,DocRect Rect)
01010 {
01011
01012 if (pSpread == NULL) return;
01013
01014
01015 DocView* pDocView = DocView::GetSelected();
01016 if (pDocView == NULL) return;
01017
01018
01019 if (Rect.IsEmpty() || !Rect.IsValid()) return;
01020
01021 DocRect BlobSize;
01022
01023
01024 OSRenderRegion::GetBlobRect(pDocView->GetViewScale(), Rect.HighCorner(),
01025 BT_SELECTEDLARGEST, &BlobSize);
01026 Rect.IncludePoint( BlobSize.HighCorner() );
01027
01028
01029 OSRenderRegion::GetBlobRect(pDocView->GetViewScale(), Rect.LowCorner(),
01030 BT_SELECTEDLARGEST, &BlobSize);
01031 Rect.IncludePoint( BlobSize.LowCorner() );
01032
01033
01034
01035
01036
01037
01038
01039
01040 pDocView->ForceRedraw(pSpread,Rect);
01041 }
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056 void GridTool::ForceRedraw(NodeGrid* pGrid)
01057 {
01058 ForceRedraw(pGrid->FindParentSpread(),pGrid->GetBlobBoundingRect());
01059 }
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079 BOOL GridTool::WhichGridClicked(Spread* pSpread,const DocCoord& PointerPos,NodeGrid** ppGrid)
01080 {
01081
01082 *ppGrid = NULL;
01083
01084
01085 Node* pNode = pSpread->FindLastChild();
01086 while ((pNode != NULL) && (*ppGrid == NULL))
01087 {
01088 if (pNode->IsKindOf(CC_RUNTIME_CLASS(NodeGrid)))
01089 {
01090 NodeGrid* pGrid = (NodeGrid*)pNode;
01091
01092 if (!pGrid->IsDisabled())
01093 {
01094 if (pGrid->GetBoundingRect().ContainsCoord(PointerPos))
01095 *ppGrid = pGrid;
01096 }
01097 }
01098
01099 pNode = pNode->FindPrevious();
01100 }
01101
01102 return (*ppGrid != NULL);
01103 }
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125 BOOL GridTool::WhichGridBlobClicked(Spread* pSpread,const DocCoord& PointerPos,
01126 NodeGrid** ppGrid,GridBlobType* pGridBlob)
01127 {
01128
01129 *ppGrid = NULL;
01130 *pGridBlob = NoGridBlob;
01131
01132 DocView *pDocView = DocView::GetCurrent();
01133 if (pDocView==NULL) return FALSE;
01134
01135
01136 Node* pNode = pSpread->FindLastChild();
01137 while ((pNode != NULL) && (*ppGrid == NULL))
01138 {
01139 if (pNode->IsKindOf(CC_RUNTIME_CLASS(NodeGrid)))
01140 {
01141 NodeGrid* pGrid = (NodeGrid*)pNode;
01142
01143 if (pGrid->IsGridSelected() && !pGrid->IsDisabled())
01144 {
01145 DocRect CornerBlob;
01146 DocCoord BlobCoord;
01147
01148 for (INT32 i=BottomLeft;(i<NumGridBlobTypes) && (*ppGrid == NULL);i++)
01149 {
01150 BlobCoord = pGrid->GetBlobCoord((GridBlobType)i);
01151 OSRenderRegion::GetBlobRect(pDocView->GetViewScale(),BlobCoord,BT_SELECTEDLARGEST,&CornerBlob);
01152
01153
01154 if (CornerBlob.ContainsCoord(PointerPos))
01155 {
01156 *ppGrid = pGrid;
01157 *pGridBlob = (GridBlobType)i;
01158 }
01159 }
01160 }
01161 }
01162
01163 pNode = pNode->FindPrevious();
01164 }
01165
01166 return (*ppGrid != NULL);
01167 }
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184 void GridTool::ClearSelection(Spread* pSpread)
01185 {
01186
01187 if (pSpread == NULL) return;
01188
01189 Node* pNode = pSpread->FindLastChild();
01190 while (pNode != NULL)
01191 {
01192 if (pNode->IsKindOf(CC_RUNTIME_CLASS(NodeGrid)))
01193 {
01194 NodeGrid* pGrid = (NodeGrid*)pNode;
01195
01196 if (pGrid->IsGridSelected())
01197 {
01198 RenderGridSelectBlobs(pGrid);
01199 pGrid->SetGridSelected(FALSE);
01200 }
01201 }
01202 pNode = pNode->FindPrevious();
01203 }
01204 }
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225 void GridTool::OnClick( DocCoord PointerPos, ClickType Click, ClickModifiers ClickMods,
01226 Spread* pSpread )
01227 {
01228 if (ClickMods.Menu) return;
01229
01230 ENSURE(pSpread != NULL,"GridTool::OnClick pSpread == NULL!!!!!");
01231
01232
01233 if ( Click == CLICKTYPE_SINGLE || Click == CLICKTYPE_DOUBLE)
01234 {
01235
01236
01237 if (SpreadClicked != pSpread) ClearSelection(SpreadClicked);
01238
01239 if (SpreadClicked == NULL && pSpread != NULL)
01240 pGridInfoBarOp->EnableGadget(_R(IDC_MAKEGRID),TRUE);
01241
01242
01243 PointClicked = PointerPos;
01244 SpreadClicked = pSpread;
01245
01246
01247
01248
01249
01250
01251 if (!WhichGridBlobClicked(SpreadClicked,PointClicked,&GridClicked,&GridBlobClicked))
01252 WhichGridClicked(SpreadClicked,PointClicked,&GridClicked);
01253
01254
01255
01256
01257 if (GridClicked != NULL)
01258 {
01259
01260 ENSURE(pGridInfoBarOp != NULL,"GridTool::OnClick - pGridInfoBarOp == NULL!");
01261 pGridInfoBarOp->DisplayGridInfo(GridClicked);
01262
01263 if (!GridClicked->IsDefault())
01264 {
01265 if (GridBlobClicked == NoGridBlob)
01266 {
01267 if (GridClicked->IsGridSelected() && !ClickMods.Adjust)
01268 {
01269
01270 }
01271 else
01272 {
01273
01274 if (ClickMods.Adjust)
01275 GridClicked->SetGridSelected(!GridClicked->IsGridSelected());
01276 else
01277 {
01278
01279 ClearSelection(SpreadClicked);
01280 GridClicked->SetGridSelected(TRUE);
01281 }
01282
01283
01284 RenderGridSelectBlobs(GridClicked);
01285 NodeGrid::RecalcNumSelectedGrids(SpreadClicked);
01286 DialogBarOp::SetSystemStateChanged();
01287 }
01288 }
01289 }
01290 else
01291 {
01292 ClearSelection(SpreadClicked);
01293 GridClicked->SetGridSelected(TRUE);
01294 GridBlobClicked = NoGridBlob;
01295 GridClicked = NULL;
01296 NodeGrid::RecalcNumSelectedGrids(SpreadClicked);
01297 DialogBarOp::SetSystemStateChanged();
01298 }
01299 }
01300 else
01301 {
01302
01303 ClearSelection(SpreadClicked);
01304 NodeGrid::RecalcNumSelectedGrids(SpreadClicked);
01305 DialogBarOp::SetSystemStateChanged();
01306 }
01307
01308
01309 OnMouseMove(PointerPos, pSpread, ClickMods);
01310
01311
01312 pGridInfoBarOp->EnableControls();
01313 }
01314
01315 if ( Click == CLICKTYPE_DRAG )
01316 {
01317 if ((GridClicked != NULL) && (GridBlobClicked == NoGridBlob))
01318 {
01319
01320 if (GridClicked->IsGridSelected() && !ClickMods.Adjust)
01321 {
01322
01323 OpGridSelection* pOpGridSelection = new OpGridSelection;
01324 if (pOpGridSelection != NULL)
01325 {
01326
01327 pOpGridSelection->DoDrag(SpreadClicked,PointClicked,GridClicked);
01328 }
01329 }
01330 }
01331 else
01332 {
01333
01334 OpGridNewResize* pOpGridNewResize = new OpGridNewResize;
01335 if (pOpGridNewResize != NULL)
01336 {
01337 if (GridBlobClicked == NoGridBlob)
01338 ClearSelection(SpreadClicked);
01339
01340
01341 OpGridNewResize::StartADrag = TRUE;
01342 OpGridNewResize::EndTheDrag = TRUE;
01343 pOpGridNewResize->DoDrag(SpreadClicked,GridClicked,GridBlobClicked,PointClicked);
01344 }
01345 }
01346 }
01347 }
01348
01349
01350
01351
01352
01353
01354
01355
01356
01357
01358
01359
01360
01361
01362
01363
01364
01365
01366 void GridTool::OnMouseMove(DocCoord PointerPos,Spread* pSpread, ClickModifiers mods)
01367 {
01368
01369
01370 NodeGrid* pGrid;
01371 GridBlobType GridBlob;
01372 Cursor* pCursor=NULL;
01373 UINT32 StatusID = _R(IDS_NOGRID);
01374
01375
01376 if (WhichGridBlobClicked(pSpread,PointerPos,&pGrid,&GridBlob))
01377 {
01378 switch (GridBlob)
01379 {
01380 case BottomLeft : pCursor = pcOverBlobCursorTR;
01381 StatusID = _R(IDS_BOTTOMLEFTHANDLE);
01382 break;
01383 case TopRight : pCursor = pcOverBlobCursorTR;
01384 StatusID = _R(IDS_TOPRIGHTHANDLE);
01385 break;
01386 case TopLeft : pCursor = pcOverBlobCursorTL;
01387 StatusID = _R(IDS_TOPLEFTHANDLE);
01388 break;
01389 case BottomRight : pCursor = pcOverBlobCursorTL;
01390 StatusID = _R(IDS_BOTTOMRIGHTHANDLE);
01391 break;
01392 case LeftMiddle : pCursor = pcOverBlobCursorLR;
01393 StatusID = _R(IDS_LEFTHANDLE);
01394 break;
01395 case RightMiddle : pCursor = pcOverBlobCursorLR;
01396 StatusID = _R(IDS_RIGHTHANDLE);
01397 break;
01398 case TopMiddle : pCursor = pcOverBlobCursorUD;
01399 StatusID = _R(IDS_TOPHANDLE);
01400 break;
01401 case BottomMiddle : pCursor = pcOverBlobCursorUD;
01402 StatusID = _R(IDS_BOTTOMHANDLE);
01403 break;
01404 }
01405 }
01406 else
01407 {
01408
01409 if (WhichGridClicked(pSpread,PointerPos,&pGrid))
01410 {
01411 if (pGrid->IsDefault())
01412 {
01413 pCursor = pcNormalGridCursor;
01414 if (pGrid->IsGridSelected())
01415 StatusID = _R(IDS_SELDEFAULT);
01416 else
01417 StatusID = _R(IDS_UNSELDEFAULT);
01418 }
01419 else
01420 {
01421 pCursor = pcOverGridCursor;
01422 if (pGrid->IsGridSelected())
01423 StatusID = _R(IDS_SELGRID);
01424 else
01425 StatusID = _R(IDS_UNSELGRID);
01426 }
01427 }
01428 else
01429 {
01430 pCursor = pcNormalGridCursor;
01431 StatusID = _R(IDS_NOGRID);
01432 }
01433 }
01434
01435 if (pCursor != pcCurrentCursor)
01436 {
01437
01438 pcCurrentCursor = pCursor;
01439 CursorStack::GSetTop(pcCurrentCursor, CurrentCursorID);
01440 }
01441
01442 GridTool::DisplayStatusBarHelp(StatusID);
01443 }
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454
01455
01456
01457
01458
01459
01460 void GridTool::ToggleDefaultGrid()
01461 {
01462 if (SpreadClicked == NULL) return;
01463
01464
01465 Node* pNode = SpreadClicked->FindFirstChild();
01466 while (pNode != NULL)
01467 {
01468 if (pNode->IsKindOf(CC_RUNTIME_CLASS(NodeGrid)))
01469 {
01470
01471 NodeGrid* pGrid = (NodeGrid*)pNode;
01472 if (pGrid->IsDefault())
01473 {
01474 if (pGrid->IsDisabled())
01475 {
01476 pGrid->SetDisabled(FALSE);
01477 ForceRedraw(pGrid);
01478 ClearSelection(SpreadClicked);
01479 pGrid->SetGridSelected(TRUE);
01480 }
01481 else
01482 {
01483 ForceRedraw(pGrid);
01484 pGrid->SetDisabled(TRUE);
01485 }
01486 }
01487 }
01488 pNode = pNode->FindNext();
01489 }
01490 }
01491
01492
01493
01494
01495
01496
01497
01498
01499
01500
01501
01502
01503
01504
01505
01506 void GridTool::DisplayStatusBarHelp(UINT32 StatusID)
01507 {
01508
01509
01510 String_256 StatusMsg("");
01511 StatusMsg.Load(StatusID);
01512 GetApplication()->UpdateStatusBarText(&StatusMsg);
01513 LastStatusID = StatusID;
01514
01515 }
01516
01517
01518
01519
01520
01521
01522
01523
01524
01525
01526
01527
01528
01529
01530
01531
01532 void GridTool::DisplayGridInfo(NodeGrid* pGrid)
01533 {
01534 pGridInfoBarOp->DisplayGridInfo(pGrid);
01535 }
01536
01537
01538
01539
01540
01541
01542
01543
01544
01545
01546
01547
01548
01549
01550
01551
01552
01553
01554
01555
01556
01557
01558
01559
01560
01561
01562 NodeGrid* OpGrid::DoDuplicateGrid( NodeGrid* pGrid,
01563 AttachNodeDirection AttDir,
01564 Node* pContextNode,
01565 Spread* pSrcSpread,
01566 Spread* pDestSpread,
01567 BOOL FRedraw,
01568 INT32 XDelta,
01569 INT32 YDelta)
01570 {
01571 BOOL ok=FALSE;
01572 NodeGrid* pNewGrid;
01573 DocRect OldRect,NewRect;
01574
01575 OldRect = pGrid->GetBoundingRect();
01576 NewRect = OldRect;
01577 NewRect.Translate(XDelta,YDelta);
01578
01579 switch (pGrid->GetGridType())
01580 {
01581 case RECTANGULAR : ALLOC_WITH_FAIL(pNewGrid,(new NodeGridRect()),this); break;
01582 case ISOMETRIC : ALLOC_WITH_FAIL(pNewGrid,(new NodeGridIso()), this); break;
01583 }
01584
01585 ok = (pNewGrid != NULL);
01586 if (ok) ok = DoInsertNewNode(pNewGrid,pContextNode,AttDir,TRUE);
01587 if (ok) ok = DoInvalidateNodeRegion(pNewGrid, TRUE);
01588 if (ok) ok = DoInvalidateNodeRegion(pGrid, TRUE);
01589
01590 if (ok)
01591 {
01592 pNewGrid->SetGridParams(pGrid->GetDivisions(),pGrid->GetSubdivisions(),pGrid->GetUnits());
01593 pNewGrid->SetGridSelected(pGrid->IsGridSelected());
01594 NodeGrid::RecalcNumSelectedGrids(pDestSpread);
01595
01596 if (FRedraw)
01597 {
01598 GridTool::ForceRedraw(pSrcSpread, OldRect);
01599 GridTool::ForceRedraw(pDestSpread,NewRect);
01600 }
01601
01602 if (!FRedraw) GridTool::RenderAllGridBlobs(pNewGrid);
01603 pNewGrid->SetBoundingRect(NewRect);
01604 if (!FRedraw) GridTool::RenderAllGridBlobs(pNewGrid);
01605 }
01606
01607 if (!ok)
01608 return (NULL);
01609 else
01610 return (pNewGrid);
01611 }
01612
01617
01619
01620
01621
01622
01623
01624
01625
01626
01627
01628
01629
01630
01631
01632
01633
01634
01635 OpGridNewResize::OpGridNewResize()
01636 {
01637 }
01638
01639
01640
01641
01642
01643
01644
01645
01646
01647
01648
01649 OpGridNewResize::~OpGridNewResize()
01650 {
01651 }
01652
01653
01654
01655
01656
01657
01658
01659
01660
01661
01662
01663
01664
01665
01666
01667
01668
01669
01670
01671 void OpGridNewResize::DoDrag( Spread* pSpread,NodeGrid* pGrid,GridBlobType Blob,
01672 DocCoord PointClicked)
01673 {
01674 DocView::SnapCurrent(pSpread,&PointClicked);
01675
01676
01677 PreOpDisplayedGrid = NULL;
01678 PostOpDisplayedGrid = NULL;
01679
01680 SpreadClicked = pSpread;
01681 GridClicked = pGrid;
01682 GridBlobClicked = Blob;
01683
01684 if (GridBlobClicked == NoGridBlob)
01685
01686 DragPoint = AnchorPoint = PointClicked;
01687 else
01688 {
01689
01690 ENSURE(GridClicked != NULL,"Oops! GridClicked == NULL && GridBlobClicked != NoGridBlob");
01691
01692
01693
01694
01695 GridBlobType DragBlob = (GridBlobType) ((INT32)GridBlobClicked % 4);
01696 GridBlobType AnchorBlob = (GridBlobType) (((INT32)DragBlob+2) % 4);
01697
01698
01699 AnchorPoint = GridClicked->GetBlobCoord(AnchorBlob);
01700
01701 if (GridBlobClicked < LeftMiddle)
01702
01703 DragPoint = PointClicked;
01704 else
01705 {
01706
01707
01708 DragPoint = GridClicked->GetBlobCoord(DragBlob);
01709
01710 if (((INT32)GridBlobClicked % 2) == 0)
01711 DragPoint.x = PointClicked.x;
01712 else
01713 DragPoint.y = PointClicked.y;
01714 }
01715 RenderMyDragBlobs();
01716 }
01717
01718
01719 if (OpGridNewResize::StartADrag) StartDrag( DRAGTYPE_AUTOSCROLL );
01720 }
01721
01722
01723
01724
01725
01726
01727
01728
01729
01730
01731
01732
01733
01734
01735
01736
01737
01738
01739
01740 void OpGridNewResize::DragPointerMove( DocCoord PointerPos, ClickModifiers ClickMods,
01741 Spread* pSpread, BOOL bSolidDrag)
01742 {
01743
01744
01745
01746 RenderMyDragBlobs();
01747
01748
01749 if (pSpread != SpreadClicked)
01750 PointerPos = MakeRelativeToSpread(SpreadClicked, pSpread, PointerPos);
01751
01752 DocView::SnapCurrent(pSpread,&PointerPos);
01753
01754 if (GridBlobClicked < LeftMiddle)
01755
01756 DragPoint = PointerPos;
01757 else
01758 {
01759
01760 if (((INT32)GridBlobClicked % 2) == 0)
01761 DragPoint.x = PointerPos.x;
01762 else
01763 DragPoint.y = PointerPos.y;
01764 }
01765
01766
01767 RenderMyDragBlobs();
01768 }
01769
01770
01771
01772
01773
01774
01775
01776
01777
01778
01779
01780
01781
01782
01783
01784
01785
01786
01787
01788
01789
01790
01791
01792 void OpGridNewResize::DragFinished( DocCoord PointerPos, ClickModifiers ClickMods,
01793 Spread* pSpread, BOOL Success, BOOL bSolidDrag)
01794 {
01795 BOOL ok = Success;
01796
01797
01798 BeginSlowJob();
01799
01800 if (ok) DocView::SnapCurrent(pSpread,&PointerPos);
01801
01802
01803
01804 if (!OpGridNewResize::EndTheDrag) DragPoint = PointerPos;
01805
01806
01807 RenderMyDragBlobs();
01808
01809
01810 DocView* pDocView = DocView::GetSelected();
01811 if (ok) ok = (pDocView != NULL);
01812
01813 UINT32 IDS = 0;
01814
01815
01816 if (ok) ok = (DragPoint != AnchorPoint);
01817
01818 NodeGrid* pNewGrid = NULL;
01819 NodeGrid* pOldGrid = NULL;
01820
01821 if (ok)
01822 {
01823
01824 BOOL FRedraw = TRUE;
01825
01826 DocRect ScaledBlob;
01827 OSRenderRegion::GetBlobRect(pDocView->GetViewScale(), DocCoord(0,0), BT_SELECTEDLARGEST, &ScaledBlob);
01828
01829
01830 MILLIPOINT dx = AnchorPoint.x - DragPoint.x;
01831 MILLIPOINT dy = AnchorPoint.y - DragPoint.y;
01832 if (abs(dx) < ScaledBlob.Width()) DragPoint.x = AnchorPoint.x + (ScaledBlob.Width() *sgn(dx));
01833 if (abs(dy) < ScaledBlob.Height()) DragPoint.y = AnchorPoint.y + (ScaledBlob.Height()*sgn(dy));
01834
01835
01836
01837 DocRect Rect( min(AnchorPoint.x, DragPoint.x),min(AnchorPoint.y, DragPoint.y),
01838 max(AnchorPoint.x, DragPoint.x),max(AnchorPoint.y, DragPoint.y) );
01839
01840
01841 DocRect OldRect = DocRect(0,0,0,0);
01842
01843 GridType CreateGridType;
01844 Node* ContextNode;
01845 AttachNodeDirection AttachDir;
01846
01847 if (GridBlobClicked == NoGridBlob)
01848 {
01849 CreateGridType = NodeGrid::GetDefaultGridType();
01850 ContextNode = SpreadClicked;
01851 AttachDir = LASTCHILD;
01852 OpType = NEW;
01853 }
01854 else
01855 {
01856 pOldGrid = GridClicked;
01857 OldRect = pOldGrid->GetBoundingRect();
01858 GridTool::RenderAllGridBlobs(pOldGrid);
01859
01860 CreateGridType = pOldGrid->GetGridType();
01861 ContextNode = pOldGrid;
01862 AttachDir = NEXT;
01863 OpType = RESIZE;
01864 }
01865
01866 switch (CreateGridType)
01867 {
01868 case RECTANGULAR : ALLOC_WITH_FAIL(pNewGrid,(new NodeGridRect()),this); break;
01869 case ISOMETRIC : ALLOC_WITH_FAIL(pNewGrid,(new NodeGridIso()), this); break;
01870 }
01871
01872 ok = (pNewGrid != NULL);
01873 if (ok) ok = DoInsertNewNode(pNewGrid,ContextNode,AttachDir,TRUE);
01874 if (ok) ok = DoInvalidateNodeRegion(pNewGrid,TRUE);
01875 if (ok && (pOldGrid != NULL)) ok = DoInvalidateNodeRegion(pOldGrid,TRUE);
01876 if (ok && (pOldGrid != NULL)) ok = DoHideNode(pOldGrid,TRUE);
01877
01878 if (ok)
01879 {
01880
01881 if (pOldGrid == NULL)
01882 {
01883 pNewGrid->SetGridParams(NodeGrid::GetDefaultDivisions(),NodeGrid::GetDefaultSubdivisions(),NodeGrid::GetDefaultUnits());
01884
01885 pNewGrid->SetDefault(FALSE);
01886 pNewGrid->SetDisabled(FALSE);
01887 pNewGrid->SetGridSelected(TRUE);
01888 }
01889 else
01890 {
01891 pNewGrid->SetGridParams(pOldGrid->GetDivisions(),pOldGrid->GetSubdivisions(),pOldGrid->GetUnits());
01892
01893 pNewGrid->SetGridSelected(pOldGrid->IsGridSelected());
01894 }
01895
01896 NodeGrid::RecalcNumSelectedGrids(SpreadClicked);
01897
01898
01899 pNewGrid->SetBoundingRect(Rect);
01900
01901
01902
01903
01904 if (FRedraw)
01905 {
01906 GridTool::ForceRedraw(SpreadClicked,Rect);
01907 GridTool::ForceRedraw(SpreadClicked,OldRect);
01908 }
01909 else
01910 GridTool::RenderAllGridBlobs(pNewGrid);
01911
01912
01913 GridInfoBarOp* pGridInfoBarOp = GridTool::GetGridInfoBarOp();
01914 if (pGridInfoBarOp != NULL)
01915 {
01916 PreOpDisplayedGrid = pGridInfoBarOp->GetLastGridDisplayed();
01917 pGridInfoBarOp->EnableControls();
01918 GridTool::DisplayGridInfo(pNewGrid);
01919 PostOpDisplayedGrid = pNewGrid;
01920 }
01921 }
01922 }
01923
01924 if (!ok)
01925 {
01926 if (pNewGrid != NULL) delete pNewGrid;
01927 if (IDS > 0) InformError(IDS,_R(IDS_OK));
01928 FailAndExecute();
01929 }
01930
01931
01932 if (OpGridNewResize::EndTheDrag)
01933 EndDrag();
01934
01935
01936 End();
01937 }
01938
01939
01940
01941
01942
01943
01944
01945
01946
01947
01948
01949
01950
01951
01952
01953 void OpGridNewResize::RenderMyDragBlobs()
01954 {
01955
01956
01957 DocRect Rect = DocRect( min(AnchorPoint.x, DragPoint.x),min(AnchorPoint.y, DragPoint.y),
01958 max(AnchorPoint.x, DragPoint.x),max(AnchorPoint.y, DragPoint.y) );
01959
01960 RenderDragBlobs(Rect,SpreadClicked, FALSE);
01961 }
01962
01963
01964
01965
01966
01967
01968
01969
01970
01971
01972
01973
01974
01975
01976
01977 void OpGridNewResize::RenderDragBlobs(DocRect Rect,Spread* pSpread, BOOL bSolidDrag)
01978 {
01979
01980
01981 DocRect RubberBox = DocRect( min(AnchorPoint.x,DragPoint.x),min(AnchorPoint.y,DragPoint.y),
01982 max(AnchorPoint.x,DragPoint.x),max(AnchorPoint.y,DragPoint.y) );
01983
01984 RenderRegion* pRegion = DocView::RenderOnTop( &Rect, pSpread, UnclippedEOR );
01985
01986 while ( pRegion != NULL )
01987 {
01988
01989 pRegion -> SetLineColour( COLOUR_XORDRAG );
01990
01991
01992 pRegion -> DrawDragRect( &RubberBox );
01993
01994
01995 pRegion = DocView::GetNextOnTop( &Rect );
01996 }
01997 }
01998
01999
02000
02001
02002
02003
02004
02005
02006
02007
02008
02009
02010
02011
02012 BOOL OpGridNewResize::Declare()
02013 {
02014 return (RegisterOpDescriptor(
02015 0,
02016 _R(IDS_GRID_TOOL),
02017 CC_RUNTIME_CLASS(OpGridNewResize),
02018 OPTOKEN_GRIDNEWRESIZE,
02019 OpGridNewResize::GetState,
02020 0,
02021 _R(IDBBL_NOOP),
02022 0
02023 ));
02024 }
02025
02026
02027
02028
02029
02030
02031
02032
02033
02034
02035
02036
02037
02038
02039
02040
02041 OpState OpGridNewResize::GetState(String_256* Description, OpDescriptor*)
02042 {
02043 OpState Grid;
02044
02045 return Grid;
02046 }
02047
02048
02049
02050
02051
02052
02053
02054
02055
02056
02057
02058
02059
02060
02061
02062
02063
02064
02065 void OpGridNewResize::GetOpName(String_256* OpName)
02066 {
02067 switch (OpType)
02068 {
02069 case NEW: *OpName = String_256(_R(IDS_GRID_UNDO_NEW)); break;
02070 case RESIZE: *OpName = String_256(_R(IDS_GRID_UNDO_RESIZE)); break;
02071 }
02072 }
02073
02074
02076
02077
02078
02079
02080
02081
02082
02083
02084
02085
02086
02087
02088
02089
02090 OpGridSelection::OpGridSelection()
02091 {
02092 }
02093
02094
02095
02096
02097
02098
02099
02100
02101
02102
02103
02104 OpGridSelection::~OpGridSelection()
02105 {
02106 }
02107
02108
02109
02110
02111
02112
02113
02114
02115
02116
02117
02118
02119
02120
02121
02122
02123 DocRect OpGridSelection::GetSelectedGridBounds(Spread* pSpread)
02124 {
02125 DocRect rect;
02126
02127 Node* pNode = pSpread->FindLastChild();
02128 Node* pPrevNode;
02129 while (pNode != NULL)
02130 {
02131 pPrevNode = pNode->FindPrevious();
02132
02133 if (pNode->IsKindOf(CC_RUNTIME_CLASS(NodeGrid)))
02134 {
02135 NodeGrid* pGrid = (NodeGrid*)pNode;
02136
02137 if (pGrid->IsGridSelected() && !pGrid->IsDefault())
02138 rect = rect.Union(pGrid->GetBoundingRect());
02139 }
02140 pNode = pPrevNode;
02141 }
02142
02143 return (rect);
02144 }
02145
02146
02147
02148
02149
02150
02151
02152
02153
02154
02155
02156
02157
02158 void OpGridSelection::DoDrag(Spread* pSpread,DocCoord PointClicked,NodeGrid* GridClicked)
02159 {
02160
02161 PreOpDisplayedGrid = GridClicked;
02162
02163 PostOpDisplayedGrid = NULL;
02164
02165 SpreadClicked = pSpread;
02166 SpreadDrag = pSpread;
02167 StartPoint = PointClicked;
02168 DragPoint = PointClicked;
02169
02170 NodeGrid::ResetDocRectSnap();
02171
02172 StartRect = GetSelectedGridBounds(pSpread);
02173 DragRect = StartRect;
02174
02175
02176 RenderMyDragBlobs();
02177
02178
02179 StartDrag( DRAGTYPE_AUTOSCROLL );
02180 }
02181
02182
02183
02184
02185
02186
02187
02188
02189
02190
02191
02192
02193
02194
02195
02196
02197
02198
02199
02200 void OpGridSelection::DragPointerMove( DocCoord PointerPos, ClickModifiers ClickMods,
02201 Spread* pSpread, BOOL bSolidDrag)
02202 {
02203
02204 RenderMyDragBlobs();
02205
02206 DocCoord PrevDragPoint = DragPoint;
02207
02208 DragPoint = PointerPos;
02209 SpreadDrag = pSpread;
02210
02211 DragRect = StartRect;
02212 DragRect.Translate(DragPoint.x - StartPoint.x , DragPoint.y - StartPoint.y);
02213 DocView::SnapCurrent(pSpread,&DragRect,PrevDragPoint,DragPoint);
02214
02215 RenderMyDragBlobs();
02216 }
02217
02218
02219
02220
02221
02222
02223
02224
02225
02226
02227
02228
02229
02230
02231
02232
02233
02234
02235
02236
02237
02238
02239
02240 void OpGridSelection::DragFinished( DocCoord PointerPos, ClickModifiers ClickMods,
02241 Spread* pSpread, BOOL Success, BOOL bSolidDrag)
02242 {
02243 BOOL ok = Success;
02244
02245
02246 BeginSlowJob();
02247
02248 INT32 XDelta = DragRect.lo.x - StartRect.lo.x;
02249 INT32 YDelta = DragRect.lo.y - StartRect.lo.y;
02250
02251 BOOL FRedraw = FALSE;
02252 UINT32 SelCount = 0;
02253 UINT32 IDS = 0;
02254
02255 DocView* pDocView = DocView::GetSelected();
02256 if (pDocView != NULL)
02257 FRedraw = pDocView->GetShowGridState();
02258
02259 FRedraw = TRUE;
02260
02261
02262 RenderMyDragBlobs();
02263
02264 Node* pNode = SpreadClicked->FindLastChild();
02265 Node* pPrevNode;
02266 while (pNode != NULL && ok)
02267 {
02268 pPrevNode = pNode->FindPrevious();
02269
02270 if (pNode->IsKindOf(CC_RUNTIME_CLASS(NodeGrid)))
02271 {
02272 NodeGrid* pOldGrid = (NodeGrid*)pNode;
02273
02274 if (pOldGrid->IsGridSelected() && !pOldGrid->IsDefault())
02275 {
02276 AttachNodeDirection AttDir;
02277 Node* pContextNode;
02278 NodeGrid* pNewGrid;
02279 Spread* pSrcSpread = SpreadClicked;
02280 Spread* pDestSpread;
02281 DocRect OldRect,NewRect;
02282
02283 SelCount++;
02284
02285 if (SpreadClicked == SpreadDrag)
02286 {
02287 pContextNode = pOldGrid;
02288 AttDir = NEXT;
02289 pDestSpread = SpreadClicked;
02290 }
02291 else
02292 {
02293 pContextNode = SpreadDrag;
02294 AttDir = LASTCHILD;
02295 pDestSpread = SpreadDrag;
02296 }
02297
02298 pNewGrid = DoDuplicateGrid( pOldGrid,AttDir,pContextNode,
02299 pSrcSpread,pDestSpread,FRedraw,
02300 XDelta,YDelta);
02301 ok = (pNewGrid != NULL);
02302 if (ok) ok = DoHideNode(pOldGrid,TRUE);
02303
02304 if (ok)
02305 {
02306 if (pOldGrid == PreOpDisplayedGrid)
02307 {
02308 GridTool::DisplayGridInfo(pNewGrid);
02309 PostOpDisplayedGrid = pNewGrid;
02310 }
02311 }
02312 }
02313 }
02314 pNode = pPrevNode;
02315 }
02316
02317 if (!ok)
02318 {
02319 if (IDS > 0) InformError( IDS, _R(IDS_OK) );
02320 FailAndExecute();
02321 }
02322
02323 Plural = (SelCount > 1);
02324
02325
02326 EndDrag();
02327
02328
02329 End();
02330 }
02331
02332
02333
02334
02335
02336
02337
02338
02339
02340
02341
02342
02343 void OpGridSelection::RenderMyDragBlobs()
02344 {
02345
02346
02347
02348
02349
02350
02351 DocRect SpreadRect = SpreadDrag->GetPasteboardRect();
02352 SpreadDrag->DocCoordToSpreadCoord(&SpreadRect);
02353
02354 RenderDragBlobs(SpreadRect,SpreadDrag, FALSE);
02355 }
02356
02357
02358
02359
02360
02361
02362
02363
02364
02365
02366
02367
02368
02369 void OpGridSelection::RenderDragBlobs(DocRect Rect,Spread* pSpread, BOOL bSolidDrag)
02370 {
02371
02372
02373 MILLIPOINT dx = DragRect.lo.x - StartRect.lo.x;
02374 MILLIPOINT dy = DragRect.lo.y - StartRect.lo.y;
02375 DocRect GridRect;
02376
02377 RenderRegion* pRegion = DocView::RenderOnTop( NULL, pSpread, UnclippedEOR );
02378
02379 while ( pRegion != NULL )
02380 {
02381
02382 pRegion -> SetLineColour( COLOUR_XORDRAG );
02383
02384 Node* pNode = SpreadClicked->FindLastChild();
02385 while (pNode != NULL)
02386 {
02387 if (pNode->IsKindOf(CC_RUNTIME_CLASS(NodeGrid)))
02388 {
02389 NodeGrid* pGrid = (NodeGrid*)pNode;
02390
02391 if (pGrid->IsGridSelected())
02392 {
02393 GridRect = pGrid->GetBoundingRect();
02394 GridRect.Translate(dx,dy);
02395 pRegion->DrawDragRect(&GridRect);
02396 }
02397 }
02398 pNode = pNode->FindPrevious();
02399 }
02400
02401
02402 pRegion = DocView::GetNextOnTop( &Rect );
02403 }
02404 }
02405
02406
02407
02408
02409
02410
02411
02412
02413
02414
02415
02416
02417
02418
02419 BOOL OpGridSelection::Declare()
02420 {
02421 return (RegisterOpDescriptor(
02422 0,
02423 _R(IDS_GRID_TOOL),
02424 CC_RUNTIME_CLASS(OpGridSelection),
02425 OPTOKEN_GRIDSELECTION,
02426 OpGridSelection::GetState,
02427 0,
02428 _R(IDBBL_NOOP),
02429 0
02430 ));
02431 }
02432
02433
02434
02435
02436
02437
02438
02439
02440
02441
02442
02443
02444
02445
02446
02447
02448 OpState OpGridSelection::GetState(String_256* Description, OpDescriptor*)
02449 {
02450 OpState Grid;
02451
02452 return Grid;
02453 }
02454
02455
02456
02457
02458
02459
02460
02461
02462
02463
02464
02465
02466
02467
02468
02469
02470
02471
02472 void OpGridSelection::GetOpName(String_256* OpName)
02473 {
02474 if (Plural)
02475 *OpName = String_256(_R(IDS_GRID_UNDO_SELECTS));
02476 else
02477 *OpName = String_256(_R(IDS_GRID_UNDO_SELECT));
02478 }
02479
02480
02481
02482
02483
02484
02485
02486
02487
02488
02489
02490
02491
02492
02493 OpGridChange::OpGridChange()
02494 {
02495 }
02496
02497
02498
02499
02500
02501
02502
02503
02504
02505
02506
02507 OpGridChange::~OpGridChange()
02508 {
02509 }
02510
02511
02512
02513
02514
02515
02516
02517
02518
02519
02520
02521
02522
02523 BOOL OpGridChange::Declare()
02524 {
02525 return (RegisterOpDescriptor(
02526 0,
02527 _R(IDS_GRID_TOOL),
02528 CC_RUNTIME_CLASS(OpGridChange),
02529 OPTOKEN_GRIDCHANGE,
02530 OpGridChange::GetState,
02531 0,
02532 _R(IDBBL_NOOP),
02533 0
02534 ));
02535 }
02536
02537
02538
02539
02540
02541
02542
02543
02544
02545
02546
02547
02548
02549
02550
02551
02552 OpState OpGridChange::GetState(String_256* Description, OpDescriptor*)
02553 {
02554 OpState Grid;
02555
02556 return Grid;
02557 }
02558
02559
02560
02561
02562
02563
02564
02565
02566
02567
02568
02569
02570
02571
02572
02573
02574
02575
02576 void OpGridChange::GetOpName(String_256* OpName)
02577 {
02578 *OpName = String_256(ChangeGridUndoIDS);
02579 }
02580
02581
02582
02583
02584
02585
02586
02587
02588
02589
02590
02591
02592
02593
02594
02595 void OpGridChange::DoChangeSelectedGrids(ChangeGrid* pChangeGrid)
02596 {
02597
02598 PreOpDisplayedGrid = NULL;
02599 PostOpDisplayedGrid = NULL;
02600
02601 Spread* SpreadClicked = GridTool::GetSpreadClicked();
02602
02603 GridInfoBarOp* pGridInfoBarOp = GridTool::GetGridInfoBarOp();
02604 if (pGridInfoBarOp != NULL)
02605 PreOpDisplayedGrid = pGridInfoBarOp->GetLastGridDisplayed();
02606
02607 BOOL ok = (SpreadClicked != NULL);
02608 if (ok) ok = (pChangeGrid != NULL);
02609
02610 if (ok)
02611 {
02612
02613 Node* pNode = SpreadClicked->FindFirstChild();
02614 while (pNode != NULL && ok)
02615 {
02616 Node* pNodeCurrent = pNode;
02617 pNode = pNode->FindNext();
02618
02619 if (pNodeCurrent->IsKindOf(CC_RUNTIME_CLASS(NodeGrid)))
02620 {
02621
02622 NodeGrid* pGrid = (NodeGrid*)pNodeCurrent;
02623
02624 if (pGrid->IsGridSelected())
02625 {
02626 GridTool::ForceRedraw(pGrid);
02627 ok = DoChangeGrid(pGrid,pChangeGrid);
02628 }
02629 }
02630 }
02631 }
02632
02633 if (!ok)
02634 FailAndExecute();
02635 else
02636 {
02637 ChangeGridUndoIDS = pChangeGrid->GetUndoIDS();
02638 if (PostOpDisplayedGrid != NULL)
02639 GridTool::DisplayGridInfo(PostOpDisplayedGrid);
02640 }
02641
02642 delete pChangeGrid;
02643
02644 End();
02645 }
02646
02647
02648
02649
02650
02651
02652
02653
02654
02655
02656
02657
02658
02659
02660
02661 BOOL OpGridChange::DoChangeGrid(NodeGrid* pOldGrid,ChangeGrid* pChangeGrid)
02662 {
02663 DocRect DummyRect;
02664 NodeGrid* pNewGrid;
02665 BOOL ok = TRUE;
02666
02667 switch (pChangeGrid->GetGridType(pOldGrid))
02668 {
02669 case RECTANGULAR : ALLOC_WITH_FAIL(pNewGrid,(new NodeGridRect()),this); break;
02670 case ISOMETRIC : ALLOC_WITH_FAIL(pNewGrid,(new NodeGridIso()), this); break;
02671 }
02672
02673 ok = (pNewGrid != NULL);
02674 if (ok) ok = DoInsertNewNode(pNewGrid,pOldGrid,NEXT,TRUE);
02675 if (ok) ok = DoInvalidateNodeRegion(pOldGrid, TRUE);
02676 if (ok) ok = DoHideNode(pOldGrid,TRUE);
02677
02678 if (ok)
02679 {
02680 pNewGrid->SetGridParams(pOldGrid->GetDivisions(),
02681 pOldGrid->GetSubdivisions(),
02682 pOldGrid->GetUnits());
02683
02684 pChangeGrid->Change(pNewGrid);
02685 PostOpDisplayedGrid = pNewGrid;
02686
02687 pNewGrid->SetBoundingRect(pOldGrid->GetBoundingRect());
02688 pNewGrid->SetGridSelected(pOldGrid->IsGridSelected());
02689 pNewGrid->SetDefault(pOldGrid->IsDefault());
02690 }
02691
02692 return (ok);
02693 }
02694
02695
02696
02697
02698
02699
02700
02701
02702
02703
02704
02705
02706
02707
02708
02709
02710
02711
02712 void ChangeGridUnits::Change(NodeGrid* pGrid)
02713 {
02714 pGrid->SetGridParams( pGrid->GetDivisions(),
02715 pGrid->GetSubdivisions(),
02716 NodeGrid::GetDefaultUnits());
02717 }
02718
02719 GridType ChangeGridUnits::GetGridType(NodeGrid* pGrid) { return pGrid->GetGridType(); }
02720
02721 UINT32 ChangeGridUnits::GetUndoIDS() { return _R(IDS_GRID_UNDO_UNITS); }
02722
02723
02724
02725
02726
02727
02728
02729
02730
02731
02732
02733
02734
02735
02736 void ChangeGridDivisions::Change(NodeGrid* pGrid)
02737 {
02738 pGrid->SetGridParams( NodeGrid::GetDefaultDivisions(),
02739 pGrid->GetSubdivisions(),
02740 pGrid->GetUnits());
02741 }
02742
02743 GridType ChangeGridDivisions::GetGridType(NodeGrid* pGrid) { return pGrid->GetGridType(); }
02744
02745 UINT32 ChangeGridDivisions::GetUndoIDS() { return _R(IDS_GRID_UNDO_DIVS); }
02746
02747
02748
02749
02750
02751
02752
02753
02754
02755
02756
02757
02758
02759
02760 void ChangeGridSubdivisions::Change(NodeGrid* pGrid)
02761 {
02762 pGrid->SetGridParams( pGrid->GetDivisions(),
02763 NodeGrid::GetDefaultSubdivisions(),
02764 pGrid->GetUnits());
02765 }
02766
02767 GridType ChangeGridSubdivisions::GetGridType(NodeGrid* pGrid) { return pGrid->GetGridType(); }
02768
02769 UINT32 ChangeGridSubdivisions::GetUndoIDS() { return _R(IDS_GRID_UNDO_SUBDIVS); }
02770
02771
02772
02773
02774
02775
02776
02777
02778
02779
02780
02781
02782
02783
02784 void ChangeGridType::Change(NodeGrid* pGrid)
02785 {
02786 }
02787
02788 GridType ChangeGridType::GetGridType(NodeGrid* pGrid) { return NodeGrid::GetDefaultGridType(); }
02789
02790 UINT32 ChangeGridType::GetUndoIDS() { return _R(IDS_GRID_UNDO_TYPE); }
02791
02792
02793
02794
02795
02796
02797
02798
02799
02800
02801
02802
02803
02804
02805
02806
02807
02808
02809
02810
02811
02812
02813
02814
02815
02816
02817 MsgResult GridInfoBarOp::Message(Msg* Message)
02818 {
02819
02820
02821 if (IS_OUR_DIALOG_MSG(Message))
02822 {
02823 DialogMsg* Msg = (DialogMsg*)Message;
02824
02825
02826 if (Msg->DlgMsg == DIM_CANCEL)
02827 {
02828 Close();
02829 }
02830 else if (Msg->DlgMsg == DIM_CREATE)
02831 {
02832
02833 InitControls();
02834 DisplayDefaultGridInfo();
02835 }
02836 else
02837 {
02838 ChangeGrid* pChangeGrid = NULL;
02839
02840
02841
02842 switch (Msg->GadgetID)
02843 {
02844 case _R(IDC_UNITS):
02845 {
02846 switch (Msg->DlgMsg)
02847 {
02848 case DIM_SELECTION_CHANGED :
02849 {
02850 WORD Index;
02851 GetValueIndex(_R(IDC_UNITS),&Index);
02852 DocUnitList* pDocUnitList = DocUnitList::GetCurrentDocUnitList();
02853 if ((Index >= 0) && (Index < pDocUnitList->GetNumUnits()))
02854 {
02855 DocUnitList* pDocUnitList = DocUnitList::GetCurrentDocUnitList();
02856 Unit* pUnit = pDocUnitList->FindUnit(Index);
02857 NodeGrid::SetDefaultUnits(pUnit->GetUnitType());
02858 pChangeGrid = new ChangeGridUnits;
02859 }
02860 }
02861 break;
02862 }
02863 }
02864 break;
02865
02866 case _R(IDC_GRIDTYPE):
02867 {
02868 switch (Msg->DlgMsg)
02869 {
02870 case DIM_SELECTION_CHANGED:
02871 {
02872 WORD Index;
02873 GetValueIndex(_R(IDC_GRIDTYPE),&Index);
02874 if ((Index >= 0) && (Index <= NUM_GRID_TYPES))
02875 {
02876 NodeGrid::SetDefaultGridType(GridTypeList[Index].Type);
02877 pChangeGrid = new ChangeGridType;
02878 }
02879 }
02880 break;
02881 }
02882 }
02883 break;
02884
02885 case _R(IDC_DIVISIONS):
02886 {
02887
02888 switch (Msg->DlgMsg)
02889 {
02890 case DIM_SELECTION_CHANGED:
02891 {
02892 WORD Index;
02893 GetValueIndex(_R(IDC_DIVISIONS),&Index);
02894
02895
02896 BOOL Valid=TRUE;
02897 double Div;
02898
02899 if (Index < 0)
02900 {
02901 String_32 StrVal = GetStringGadgetValue(_R(IDC_DIVISIONS),&Valid);
02902 camSscanf((TCHAR*)StrVal,"%NLf",&Div);
02903 }
02904 else
02905 Div = Index+1;
02906
02907 if (Valid)
02908 {
02909 NodeGrid::SetDefaultDivisions(Div);
02910 pChangeGrid = new ChangeGridDivisions;
02911 }
02912 }
02913 break;
02914 }
02915 }
02916 break;
02917
02918 case _R(IDC_SUBDIVISIONS):
02919 {
02920
02921 switch (Msg->DlgMsg)
02922 {
02923 case DIM_SELECTION_CHANGED:
02924 {
02925 WORD Index;
02926 GetValueIndex(_R(IDC_SUBDIVISIONS),&Index);
02927
02928
02929 BOOL Valid=TRUE;
02930 UINT32 Subdiv;
02931
02932 if (Index < 0)
02933 {
02934 String_32 StrVal = GetStringGadgetValue(_R(IDC_SUBDIVISIONS),&Valid);
02935 camSscanf((TCHAR*)StrVal,"%ld",&Subdiv);
02936 }
02937 else
02938 Subdiv = Index+1;
02939
02940 if (Valid)
02941 {
02942 NodeGrid::SetDefaultSubdivisions(Subdiv);
02943 pChangeGrid = new ChangeGridSubdivisions;
02944 }
02945 }
02946 break;
02947 }
02948 }
02949 break;
02950
02951 case _R(IDC_MAKEGRID) :
02952 {
02953
02954 switch (Msg->DlgMsg)
02955 {
02956 case DIM_LFT_BN_CLICKED:
02957 {
02958 GridTool::ToggleDefaultGrid();
02959
02960 EnableControls();
02961 }
02962 break;
02963 }
02964 }
02965 break;
02966 }
02967
02968 if (pChangeGrid != NULL)
02969 {
02970 OpGridChange* pOpGridChange = new OpGridChange;
02971 if (pOpGridChange != NULL)
02972 pOpGridChange->DoChangeSelectedGrids(pChangeGrid);
02973 }
02974 }
02975 }
02976 else if (MESSAGE_IS_A(Message,OpMsg))
02977 {
02978 OpMsg* pOpMsg = (OpMsg*)Message;
02979
02980 if (pOpMsg->MsgType == OpMsg::AFTER_UNDO || pOpMsg->MsgType == OpMsg::AFTER_REDO)
02981 {
02982 if (pOpMsg->pOp != NULL)
02983 {
02984 NodeGrid* pNodeGrid = NULL;
02985
02986 if (pOpMsg->pOp->IsKindOf(CC_RUNTIME_CLASS(OpGrid)))
02987 {
02988 NodeGrid::RecalcNumSelectedGrids(GridTool::GetSpreadClicked());
02989
02990 GridInfoBarOp* pGridInfoBarOp = GridTool::GetGridInfoBarOp();
02991 if (pGridInfoBarOp != NULL)
02992 pGridInfoBarOp->EnableControls();
02993
02994 OpGrid* pOpGrid = (OpGrid*)(pOpMsg->pOp);
02995
02996 if (pOpMsg->MsgType == OpMsg::AFTER_UNDO)
02997 pNodeGrid = pOpGrid->GetPreOpDisplayedGrid();
02998
02999 if (pOpMsg->MsgType == OpMsg::AFTER_REDO)
03000 pNodeGrid = pOpGrid->GetPostOpDisplayedGrid();
03001
03002 if (pNodeGrid != NULL)
03003 DisplayGridInfo(pNodeGrid);
03004 }
03005 }
03006 }
03007 }
03008 else if (MESSAGE_IS_A(Message,UnitMsg))
03009 {
03010 UnitMsg* pUnitMsg = (UnitMsg*)Message;
03011 BOOL UpdateInfoBar = FALSE;
03012 Unit* pThisUnit = NULL;
03013
03014 switch (pUnitMsg->MsgType)
03015 {
03016 case UnitMsg::BEFOREDELETE:
03017 case UnitMsg::NEW:
03018 case UnitMsg::CHANGED:
03019 pThisUnit = pUnitMsg->pDocUnitList->FindUnit(pUnitMsg->ThisUnitType);
03020 break;
03021 }
03022
03023 switch (pUnitMsg->MsgType)
03024 {
03025 case UnitMsg::BEFOREDELETE:
03026 if (NodeGrid::GetDefaultUnits() == pUnitMsg->ThisUnitType)
03027 NodeGrid::SetDefaultUnits(pThisUnit->GetBaseUnitType());
03028 break;
03029
03030 case UnitMsg::NEW:
03031 case UnitMsg::CHANGED:
03032 case UnitMsg::AFTERDELETE:
03033 UpdateInfoBar = TRUE;
03034 break;
03035 }
03036
03037 if (UpdateInfoBar)
03038 {
03039 InitControls();
03040 if (LastGridDisplayed == NULL)
03041 DisplayDefaultGridInfo();
03042 else
03043 DisplayGridInfo(LastGridDisplayed);
03044 }
03045
03046 ProcessGridUnitMsg* pGridProc = new ProcessGridUnitMsg(pUnitMsg);
03047 if (pGridProc != NULL)
03048 {
03049 NodeGrid::ProcessAllGrids(pGridProc);
03050 delete pGridProc;
03051 }
03052 }
03053 else if (MESSAGE_IS_A(Message,DocChangingMsg))
03054 {
03055
03056
03057
03058
03059
03060
03061
03062
03063
03064
03065
03066
03067
03068
03069
03070
03071
03072 DocChangingMsg* pDocChangingMsg = (DocChangingMsg*)Message;
03073
03074 switch (pDocChangingMsg->State)
03075 {
03076 case DocChangingMsg::DocState::SELCHANGED:
03077 GridTool::SetDoc(pDocChangingMsg->pNewDoc);
03078 break;
03079 }
03080 }
03081
03082
03083 return (InformationBarOp::Message(Message));
03084 }
03085
03086
03087
03088
03089
03090
03091
03092
03093
03094
03095
03096
03097
03098
03099
03100
03101
03102 void GridInfoBarOp::InitControls()
03103 {
03104
03105 if (Tool::GetCurrentID() != TOOLID_GRID) return;
03106 if (GridTool::GetDoc() == NULL) return;
03107
03108 INT32 i;
03109
03110 DeleteAllValues(_R(IDC_UNITS));
03111 DeleteAllValues(_R(IDC_GRIDTYPE));
03112
03113 DocUnitList* pDocUnitList = GridTool::GetDoc()->GetDocUnitList();
03114
03115 for (i=0; i < pDocUnitList->GetNumUnits(); i++)
03116 {
03117 Unit* pUnit = pDocUnitList->FindUnit(i);
03118 String_32 Str = pUnit->GetToken();
03119 TCHAR* p = Str;
03120 String_256 Str256 = p;
03121 SetStringGadgetValue(_R(IDC_UNITS),&Str256,FALSE,i);
03122 }
03123
03124 for (i=0; i<NUM_GRID_TYPES; i++)
03125 {
03126 String_32 Str = String_32(GridTypeList[i].IDS);
03127 SetStringGadgetValue(_R(IDC_GRIDTYPE),&Str,FALSE,i);
03128 }
03129
03130 INT32 l=1;
03131 for (i=0; i<10; i++,l++)
03132 {
03133 SetLongGadgetValue(_R(IDC_DIVISIONS), l,FALSE,i);
03134 SetLongGadgetValue(_R(IDC_SUBDIVISIONS),l,FALSE,i);
03135 }
03136
03137 EnableControls();
03138 }
03139
03140
03141
03142
03143
03144
03145
03146
03147
03148
03149
03150
03151
03152
03153
03154
03155 void GridInfoBarOp::EnableControls()
03156 {
03157
03158 if (Tool::GetCurrentID() != TOOLID_GRID) return;
03159
03160 Spread* pSpread = GridTool::GetSpreadClicked();
03161 BOOL enable = ((NodeGrid::GetNumSelectedGrids() > 0) && (pSpread != NULL));
03162
03163 EnableGadget(_R(IDC_DIVISIONS), enable);
03164 EnableGadget(_R(IDC_SUBDIVISIONS), enable);
03165 EnableGadget(_R(IDC_UNITS), enable);
03166 EnableGadget(_R(IDC_GRIDTYPE), enable);
03167
03168 EnableGadget(_R(IDC_MAKEGRID),pSpread != NULL);
03169 }
03170
03171
03172
03173
03174
03175
03176
03177
03178
03179
03180
03181
03182
03183 void GridInfoBarOp::DisplayDefaultGridInfo()
03184 {
03185 DisplayGridInfo( NodeGrid::GetDefaultDivisions(),
03186 NodeGrid::GetDefaultUnits(),
03187 NodeGrid::GetDefaultSubdivisions(),
03188 NodeGrid::GetDefaultGridType());
03189
03190 LastGridDisplayed = NULL;
03191 }
03192
03193
03194
03195
03196
03197
03198
03199
03200
03201
03202
03203
03204
03205
03206
03207 void GridInfoBarOp::DisplayGridInfo(NodeGrid* pGrid)
03208 {
03209
03210 if (Tool::GetCurrentID() != TOOLID_GRID) return;
03211
03212 DisplayGridInfo( pGrid->GetDivisions(),
03213 pGrid->GetUnits(),
03214 pGrid->GetSubdivisions(),
03215 pGrid->GetGridType());
03216
03217 LastGridDisplayed = pGrid;
03218
03219
03220 }
03221
03222
03223
03224
03225
03226
03227
03228
03229
03230
03231
03232
03233
03234
03235
03236
03237
03238
03239 void GridInfoBarOp::DisplayGridInfo(double Divisions, UnitType Units, UINT32 Subdivisions, GridType GType)
03240 {
03241
03242 if (Tool::GetCurrentID() != TOOLID_GRID) return;
03243
03244 INT32 i;
03245
03246 if (Units != NOTYPE)
03247 {
03248 DocUnitList* pDocUnitList = DocUnitList::GetCurrentDocUnitList();
03249 SetSelectedValueIndex(_R(IDC_UNITS),pDocUnitList->FindUnitIndex(Units));
03250 }
03251
03252
03253
03254
03255
03256
03257
03258
03259
03260 for (i=0;i<NUM_GRID_TYPES;i++)
03261 if (GridTypeList[i].Type == GType)
03262 SetSelectedValueIndex(_R(IDC_GRIDTYPE),i);
03263
03264 String_16 StringVal;
03265 TCHAR CharString[20];
03266
03267 camSprintf(CharString, _T("%.2g"), (double) Divisions);
03268 StringVal = CharString;
03269 SetStringGadgetValue(_R(IDC_DIVISIONS), &StringVal, FALSE, -1);
03270
03271 camSprintf(CharString, _T("%ld"), (INT32) Subdivisions);
03272 StringVal = CharString;
03273 SetStringGadgetValue(_R(IDC_SUBDIVISIONS), &StringVal, FALSE,-1);
03274 }
03275
03276
03277
03278
03279
03280
03281
03282
03283
03284
03285
03286
03287
03288
03289
03290
03291
03292
03293
03294
03295
03296
03297
03298
03299
03300
03301 OpState OpGridDelete::GetState(String_256* UIDescription, OpDescriptor*)
03302 {
03303 OpState OpSt;
03304 String_256 DisableReason;
03305
03306
03307 if (GridTool::GetDoc() == NULL)
03308 {
03309
03310 OpSt.Greyed = TRUE;
03311
03312 DisableReason = String_256(_R(IDS_NO_DOC));
03313 *UIDescription = DisableReason;
03314 }
03315 else
03316 {
03317 Spread* pSpread = GridTool::GetSpreadClicked();
03318 BOOL enable = ((NodeGrid::GetNumNonDefaultSelectedGrids() > 0) && (pSpread != NULL));
03319
03320 if (!enable)
03321 {
03322 OpSt.Greyed = TRUE;
03323
03324 DisableReason = String_256(_R(IDS_NO_OBJECTS_SELECTED));
03325 *UIDescription = DisableReason;
03326 }
03327 }
03328
03329 return (OpSt);
03330 }
03331
03332
03333
03334
03335
03336
03337
03338
03339
03340
03341
03342
03343
03344
03345
03346
03347
03348 void OpGridDelete::Do(OpDescriptor*)
03349 {
03350
03351 PreOpDisplayedGrid = NULL;
03352 PostOpDisplayedGrid = NULL;
03353
03354 Spread* SpreadClicked = GridTool::GetSpreadClicked();
03355
03356 GridInfoBarOp* pGridInfoBarOp = GridTool::GetGridInfoBarOp();
03357 if (pGridInfoBarOp != NULL)
03358 PreOpDisplayedGrid = pGridInfoBarOp->GetLastGridDisplayed();
03359
03360 BOOL ok = (SpreadClicked != NULL);
03361 UINT32 SelCount=0;
03362
03363 if (ok)
03364 {
03365
03366 Node* pNode = SpreadClicked->FindFirstChild();
03367 while (pNode != NULL && ok)
03368 {
03369 Node* pNodeCurrent = pNode;
03370 pNode = pNode->FindNext();
03371
03372 if (pNodeCurrent->IsKindOf(CC_RUNTIME_CLASS(NodeGrid)))
03373 {
03374
03375 NodeGrid* pGrid = (NodeGrid*)pNodeCurrent;
03376
03377 if (pGrid->IsGridSelected() && !pGrid->IsDefault())
03378 {
03379 SelCount++;
03380 GridTool::ForceRedraw(pGrid);
03381 ok = DoInvalidateNodeRegion(pGrid, TRUE);
03382 if (ok) ok = DoHideNode(pGrid,TRUE);
03383 }
03384 }
03385 }
03386 }
03387
03388 if (!ok)
03389 FailAndExecute();
03390 else
03391 {
03392 NodeGrid::RecalcNumSelectedGrids(SpreadClicked);
03393 pGridInfoBarOp->EnableControls();
03394 }
03395
03396 Plural = (SelCount > 1);
03397
03398 End();
03399 }
03400
03401
03402
03403
03404
03405
03406
03407
03408
03409
03410
03411
03412
03413
03414
03415
03416
03417
03418 void OpGridDelete::GetOpName(String_256* OpName)
03419 {
03420 if (Plural)
03421 *OpName = String_256(_R(IDS_GRID_UNDO_DELETES));
03422 else
03423 *OpName = String_256(_R(IDS_GRID_UNDO_DELETE));
03424 }
03425
03426
03427
03428
03429
03430
03431
03432
03433
03434
03435
03436
03437
03438
03439
03440
03441
03442
03443
03444
03445 OpState OpGridDuplicate::GetState(String_256* UIDescription, OpDescriptor*)
03446 {
03447 return (OpGridDelete::GetState(UIDescription,NULL));
03448 }
03449
03450
03451
03452
03453
03454
03455
03456
03457
03458
03459
03460
03461
03462
03463
03464
03465
03466 void OpGridDuplicate::Do(OpDescriptor*)
03467 {
03468
03469 PreOpDisplayedGrid = NULL;
03470 PostOpDisplayedGrid = NULL;
03471
03472 Spread* SpreadClicked = GridTool::GetSpreadClicked();
03473
03474 GridInfoBarOp* pGridInfoBarOp = GridTool::GetGridInfoBarOp();
03475 if (pGridInfoBarOp != NULL)
03476 PreOpDisplayedGrid = pGridInfoBarOp->GetLastGridDisplayed();
03477
03478 BOOL ok = (SpreadClicked != NULL);
03479 UINT32 SelCount=0;
03480
03481 if (ok)
03482 {
03483
03484 Node* pNode = SpreadClicked->FindFirstChild();
03485 while (pNode != NULL && ok)
03486 {
03487 Node* pNodeCurrent = pNode;
03488 pNode = pNode->FindNext();
03489
03490 if (pNodeCurrent->IsKindOf(CC_RUNTIME_CLASS(NodeGrid)))
03491 {
03492
03493 NodeGrid* pGrid = (NodeGrid*)pNodeCurrent;
03494
03495 if (pGrid->IsGridSelected() && !pGrid->IsDefault())
03496 {
03497 SelCount++;
03498
03499 NodeGrid* pNewGrid = DoDuplicateGrid( pGrid,NEXT,pGrid,
03500 SpreadClicked,SpreadClicked,TRUE,
03501 28346,-28346);
03502
03503 ok = (pNewGrid != NULL);
03504
03505 if (ok)
03506 {
03507 pGrid->SetGridSelected(FALSE);
03508 if (pGrid == PreOpDisplayedGrid)
03509 {
03510 GridTool::DisplayGridInfo(pNewGrid);
03511 PostOpDisplayedGrid = pNewGrid;
03512 }
03513 }
03514 }
03515 }
03516 }
03517 }
03518
03519 if (!ok)
03520 FailAndExecute();
03521 else
03522 {
03523 NodeGrid::RecalcNumSelectedGrids(SpreadClicked);
03524 pGridInfoBarOp->EnableControls();
03525 }
03526
03527 Plural = (SelCount > 1);
03528
03529 End();
03530 }
03531
03532
03533
03534
03535
03536
03537
03538
03539
03540
03541
03542
03543
03544
03545
03546
03547
03548
03549 void OpGridDuplicate::GetOpName(String_256* OpName)
03550 {
03551 if (Plural)
03552 *OpName = String_256(_R(IDS_GRID_UNDO_DUPS));
03553 else
03554 *OpName = String_256(_R(IDS_GRID_UNDO_DUP));
03555 }
03556
03557
03558
03559
03560
03561
03562
03563
03564
03565
03566
03567
03568
03569
03570
03571
03572
03573
03574
03575
03576
03577 static OpState NoClipboardOpGetState(String_256* UIDescription, OpDescriptor*)
03578 {
03579 OpState OpSt;
03580 String_256 DisableReason;
03581
03582
03583
03584 OpSt.Greyed = TRUE;
03585
03586 DisableReason = String_256(_R(IDS_NO_GRID_CLIPBOARD_OPS));
03587 *UIDescription = DisableReason;
03588
03589 return (OpSt);
03590 }
03591