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 #include "camtypes.h"
00103
00104 DECLARE_SOURCE("$Revision: 1282 $");
00105
00106 #include "camelot.h"
00107
00108 #include "aligndlg.h"
00109
00110
00111
00112
00113
00114
00115
00116 #include "rnddlgs.h"
00117 #include "ccdc.h"
00118 #include "progress.h"
00119 #include "grnddib.h"
00120
00121
00122 #include "page.h"
00123
00124
00125 #include "qualattr.h"
00126 #include "dlgcol.h"
00127
00128 #include "keypress.h"
00129 #include "bubbleid.h"
00130 #include "ophist.h"
00131
00132 CC_IMPLEMENT_DYNCREATE(ArrangeAlignment, DialogOp)
00133 CC_IMPLEMENT_DYNCREATE(OpAlign, TransOperation)
00134 #define new CAM_DEBUG_NEW
00135
00136 const CDlgMode ArrangeAlignment::Mode=MODELESS;
00137 const UINT32 ArrangeAlignment::IDD =_R(IDD_ALIGNDIALOG);
00138
00139
00140 const CGadgetID TargetArea[]={_R(IDC_ALIGNDIALOG_TOSELECTION),
00141 _R(IDC_ALIGNDIALOG_TOPAGE),
00142
00143 #ifndef WEBSTER
00144 _R(IDC_ALIGNDIALOG_TOSPREAD),
00145 #endif //webster
00146 0};
00147
00148
00149
00150 const INT32 HAlignIDS[]={_R(IDS_HALIGNNONE),
00151 _R(IDS_HALIGNLEFT),
00152 _R(IDS_HALIGNCENTRE),
00153 _R(IDS_HALIGNRIGHT),
00154 _R(IDS_HDISTRIBUTELEFT),
00155 _R(IDS_HDISTRIBUTECENTRE),
00156 _R(IDS_HDISTRIBUTERIGHT),
00157 _R(IDS_HDISTRIBUTEEQUI),
00158 0};
00159 const INT32 VAlignIDS[]={_R(IDS_VALIGNNONE),
00160 _R(IDS_VALIGNBOTTOM),
00161 _R(IDS_VALIGNCENTRE),
00162 _R(IDS_VALIGNTOP),
00163 _R(IDS_VDISTRIBUTEBOTTOM),
00164 _R(IDS_VDISTRIBUTECENTRE),
00165 _R(IDS_VDISTRIBUTETOP),
00166 _R(IDS_VDISTRIBUTEEQUI),
00167 0};
00168
00169
00170 const INT32 DiagWidth =100;
00171 const INT32 DiagHeight=100;
00172 const INT32 DiagRectWidth[DiagRects]={6,14,22,30};
00173 const INT32 DiagRectHeight[DiagRects]={6,30,14,22};
00174 const INT32 DiagRectOrderX[DiagRects]={1,3,0,2};
00175 const INT32 DiagRectOrderY[DiagRects]={0,2,1,3};
00176 const INT32 DiagRectGapX[DiagRects-1]={13,6,8};
00177 const INT32 DiagRectGapY[DiagRects-1]={13,6,8};
00178 LineData ArrangeAlignment::DiagRectX[8][DiagRects];
00179 LineData ArrangeAlignment::DiagRectY[8][DiagRects];
00180
00181
00182 AlignParam ArrangeAlignment::Align={AlignNone,AlignNone,ToSelection};
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193 ArrangeAlignment::ArrangeAlignment():
00194 DialogOp(ArrangeAlignment::IDD, ArrangeAlignment::Mode)
00195 {
00196 }
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 BOOL ArrangeAlignment::Init()
00208 {
00209
00210 ArrangeAlignment::CalcDiagramRectsOneAxis(ArrangeAlignment::DiagRectX,DiagRectWidth,
00211 DiagRectOrderX,DiagRectGapX,DiagWidth-1);
00212 ArrangeAlignment::CalcDiagramRectsOneAxis(ArrangeAlignment::DiagRectY,DiagRectHeight,
00213 DiagRectOrderY,DiagRectGapY,DiagHeight-1);
00214
00215 return RegisterOpDescriptor(
00216 0,
00217 _R(IDS_ARRANGE_ALIGNMENT),
00218 CC_RUNTIME_CLASS(ArrangeAlignment),
00219 OPTOKEN_ALIGNDLG,
00220 ArrangeAlignment::GetState,
00221 0,
00222 _R(IDBBL_ALIGNEMENT),
00223 _R(IDD_BARCONTROLSTORE),
00224 _R(IDC_ALIGNEMENT),
00225 SYSTEMBAR_EDIT,
00226 TRUE,
00227 FALSE,
00228 TRUE,
00229 0,
00230 _R(IDS_ARRANGEALIGNMENT_ONE),
00231 (DONT_GREY_WHEN_SELECT_INSIDE | GREY_WHEN_NO_CURRENT_DOC)
00232 );
00233 }
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249 void ArrangeAlignment::CalcDiagramRectsOneAxis(
00250 LineData x[8][DiagRects],
00251 const INT32 width[DiagRects],
00252 const INT32 order[DiagRects],
00253 const INT32 gap[DiagRects-1],
00254 const INT32 DiagWidth
00255 )
00256 {
00257 INT32 i;
00258 INT32 sum=0;
00259 for (i=0; i<DiagRects; i++)
00260 sum+=width[i];
00261 float first=(float)width[order[0]];
00262 float last =(float)width[order[DiagRects-1]];
00263 float PosnLeft=(float)0;
00264 float PosnCntr=first/2;
00265 float PosnRght=first;
00266 float PosnEqui=(float)0;
00267 float GapLeft =((float)DiagWidth-last)/3;
00268 float GapCntr =((float)DiagWidth-first/2-last/2)/3;
00269 float GapRght =((float)DiagWidth-first)/3;
00270 float GapEqui =(float)(DiagWidth-sum)/3;
00271 for (i=0; i<DiagRects; i++)
00272 {
00273 INT32 j=order[i];
00274 x[AlignNone ][j].lo = i ? x[AlignNone][order[i-1]].hi+gap[i-1] : 0;
00275 x[AlignLow ][j].lo = 0;
00276 x[AlignCentre ][j].lo =(DiagWidth-width[j])/2;
00277 x[AlignHigh ][j].lo = DiagWidth-width[j];
00278 x[DistributeLow ][j].lo = (INT32)PosnLeft;
00279 x[DistributeCentre][j].lo = (INT32)(PosnCntr-width[j]/2);
00280 x[DistributeHigh ][j].lo = (INT32)(PosnRght-width[j]);
00281 x[DistributeEqui ][j].lo = (INT32)PosnEqui;
00282
00283 PosnLeft+=GapLeft;
00284 PosnCntr+=GapCntr;
00285 PosnRght+=GapRght;
00286 PosnEqui+=GapEqui+width[j];
00287
00288 INT32 w=width[j];
00289 x[AlignNone ][j].hi = x[AlignNone ][j].lo + w;
00290 x[AlignLow ][j].hi = x[AlignLow ][j].lo + w;
00291 x[AlignCentre ][j].hi = x[AlignCentre ][j].lo + w;
00292 x[AlignHigh ][j].hi = x[AlignHigh ][j].lo + w;
00293 x[DistributeLow ][j].hi = x[DistributeLow ][j].lo + w;
00294 x[DistributeCentre][j].hi = x[DistributeCentre][j].lo + w;
00295 x[DistributeHigh ][j].hi = x[DistributeHigh ][j].lo + w;
00296 x[DistributeEqui ][j].hi = x[DistributeEqui ][j].lo + w;
00297 }
00298 }
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309 OpState ArrangeAlignment::GetState(String_256* pHelpString, OpDescriptor*)
00310 {
00311 static OpState DialogState;
00312 DialogState.Greyed=FALSE;
00313
00314
00315
00316 return DialogState;
00317 }
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327 void ArrangeAlignment::Do(OpDescriptor*)
00328 {
00329 Create();
00330 Open();
00331 }
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341 MsgResult ArrangeAlignment::Message(Msg* Message)
00342 {
00343 if (IS_OUR_DIALOG_MSG(Message))
00344 {
00345 DialogMsg* Msg=(DialogMsg*)Message;
00346
00347 switch (Msg->DlgMsg)
00348 {
00349 case DIM_CREATE:
00350 BuildIDSDropList(_R(IDC_ALIGNDIALOG_HORIZONTAL), HAlignIDS, Align.h);
00351 BuildIDSDropList(_R(IDC_ALIGNDIALOG_VERTICAL), VAlignIDS, Align.v);
00352 SetRadioGroup(TargetArea, TargetArea[Align.target]);
00353 UpdateState();
00354 break;
00355
00356 case DIM_LFT_BN_CLICKED:
00357 case DIM_SELECTION_CHANGED:
00358 UpdateState();
00359 break;
00360
00361 case DIM_LFT_BN_DOWN:
00362 if (Msg->GadgetID == _R(IDC_ALIGNDIALOG_DIAGRAM))
00363 DiagramClicked((ReDrawInfoType*) Msg->DlgMsgParam);
00364 break;
00365
00366 case DIM_REDRAW:
00367 if (Msg->GadgetID == _R(IDC_ALIGNDIALOG_DIAGRAM))
00368 RedrawDiagram((ReDrawInfoType*)Msg->DlgMsgParam);
00369 break;
00370
00371 case DIM_COMMIT:
00372 DialogOKed();
00373 break;
00374
00375 case DIM_CANCEL:
00376
00377
00378 break;
00379
00380 default:
00381 break;
00382 }
00383 }
00384 else if (MESSAGE_IS_A(Message, SelChangingMsg))
00385 {
00386
00387 if ( ((SelChangingMsg*)Message)->State == SelChangingMsg::SELECTIONCHANGED )
00388 UpdateState();
00389 }
00390
00391
00392 return DialogOp::Message(Message);
00393 }
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406 void ArrangeAlignment::DiagramClicked(ReDrawInfoType *Info)
00407 {
00408
00409 Align.h = Align.v = AlignNone;
00410
00411
00412 if (!KeyPress::IsConstrainPressed())
00413 {
00414 if (Info->pMousePos->x < Info->dx/3)
00415 Align.h = AlignLow;
00416 else if (Info->pMousePos->x < (2 * Info->dx)/3)
00417 Align.h = AlignCentre;
00418 else
00419 Align.h = AlignHigh;
00420 }
00421
00422
00423 if (!KeyPress::IsAdjustPressed())
00424 {
00425 if (Info->pMousePos->y < Info->dy/3)
00426 Align.v = AlignLow;
00427 else if (Info->pMousePos->y < (2 * Info->dy)/3)
00428 Align.v = AlignCentre;
00429 else
00430 Align.v = AlignHigh;
00431 }
00432
00433
00434 SetSelectedValueIndex(_R(IDC_ALIGNDIALOG_HORIZONTAL), Align.h);
00435 SetSelectedValueIndex(_R(IDC_ALIGNDIALOG_VERTICAL), Align.v);
00436 UpdateState();
00437 }
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451 void ArrangeAlignment::RedrawDiagram(ReDrawInfoType* ExtraInfo)
00452 {
00453
00454
00455
00456 INT32 scale=1000;
00457
00458
00459 DocRect VirtRendRect;
00460 VirtRendRect.lo.x=-1*scale;
00461 VirtRendRect.lo.y=-2*scale;
00462 VirtRendRect.hi.x=(DiagWidth +1)*scale;
00463 VirtRendRect.hi.y=(DiagHeight+2)*scale;
00464 RenderRegion* pRender=CreateGRenderRegion(&VirtRendRect,ExtraInfo);
00465
00466 if (pRender!=NULL)
00467 {
00468 pRender->SaveContext();
00469
00470
00471 Quality AntiAliasQuality(Quality::QualityMax);
00472 QualityAttribute AntiAliasQualityAttr(AntiAliasQuality);
00473 pRender->SetQuality(&AntiAliasQualityAttr,FALSE);
00474
00475
00476 DialogColourInfo RedrawColours;
00477 pRender->SetLineColour(RedrawColours.DialogBack());
00478 pRender->SetFillColour(RedrawColours.DialogBack());
00479 pRender->DrawRect(&VirtRendRect);
00480
00481
00482 RadialFillAttribute Fill;
00483
00484
00485 Fill.MakeElliptical();
00486 Fill.Colour=DocColour(255,255,255);
00487 pRender->SetLineColour(BLACK);
00488 pRender->SetLineWidth(0);
00489
00490 for (INT32 i=0; i<DiagRects; i++)
00491 {
00492
00493 INT32 j=DiagRects-1-i;
00494
00495
00496 switch (j)
00497 {
00498 case 0: Fill.EndColour=DocColour(255,255,0); break;
00499 case 1: Fill.EndColour=DocColour(0,0,255); break;
00500 case 2: Fill.EndColour=DocColour(255,0,0); break;
00501 case 3: Fill.EndColour=DocColour(0,160,0); break;
00502 default: Fill.EndColour=DocColour(0,0,0); break;
00503 }
00504
00505
00506 INT32 x=DiagRectX[Align.h][j].lo*scale;
00507 INT32 w=DiagRectX[Align.h][j].hi*scale-x;
00508 INT32 y=DiagRectY[Align.v][j].lo*scale;
00509 INT32 h=DiagRectY[Align.v][j].hi*scale-y;
00510
00511
00512 Path shape;
00513 shape.Initialise(16,8);
00514 shape.IsFilled=TRUE;
00515 shape.FindStartOfPath();
00516 switch (j)
00517 {
00518 case 0:
00519 {
00520
00521 shape.InsertMoveTo(DocCoord(x,y));
00522 shape.InsertLineTo(DocCoord(x,y+h));
00523 shape.InsertLineTo(DocCoord(x+w,y+h));
00524 shape.InsertLineTo(DocCoord(x+w,y));
00525 shape.InsertLineTo(DocCoord(x,y));
00526
00527
00528
00529
00530
00531 break;
00532 }
00533
00534 case 1:
00535 {
00536
00537 shape.InsertMoveTo( DocCoord(x,y+h/2));
00538 shape.InsertCurveTo(DocCoord(x,y+h*3/4), DocCoord(x+w/4,y+h), DocCoord(x+w/2,y+h));
00539 shape.InsertCurveTo(DocCoord(x+w*3/4,y+h),DocCoord(x+w,y+h*3/4),DocCoord(x+w,y+h/2));
00540 shape.InsertCurveTo(DocCoord(x+w,y+h/4), DocCoord(x+w*3/4,y), DocCoord(x+w/2,y));
00541 shape.InsertCurveTo(DocCoord(x+w/4,y), DocCoord(x,y+h/4), DocCoord(x,y+h/2));
00542
00543
00544
00545
00546
00547 break;
00548 }
00549
00550 default:
00551 {
00552
00553 shape.InsertMoveTo( DocCoord(x,y+h/2));
00554 shape.InsertCurveTo(DocCoord(x,y+h), DocCoord(x,y+h), DocCoord(x+w/2,y+h));
00555 shape.InsertCurveTo(DocCoord(x+w,y+h),DocCoord(x+w,y+h),DocCoord(x+w,y+h/2));
00556 shape.InsertCurveTo(DocCoord(x+w,y), DocCoord(x+w,y), DocCoord(x+w/2,y));
00557 shape.InsertCurveTo(DocCoord(x,y), DocCoord(x,y), DocCoord(x,y+h/2));
00558
00559
00560
00561
00562
00563 break;
00564 }
00565
00566 }
00567
00568 pRender->SetFillColour(Fill.EndColour);
00569 pRender->DrawPath(&shape);
00570 }
00571
00572 pRender->RestoreContext();
00573 DestroyGRenderRegion(pRender);
00574 }
00575 }
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586 void ArrangeAlignment::UpdateState()
00587 {
00588
00589 CGadgetID Target = ReadRadioGroup(TargetArea,TargetArea[0]);
00590 if (Target == _R(IDC_ALIGNDIALOG_TOSELECTION))
00591 {
00592 Align.target=ToSelection;
00593 }
00594 else if (Target == _R(IDC_ALIGNDIALOG_TOPAGE))
00595 {
00596 Align.target=ToPage;
00597 }
00598
00599 #ifndef WEBSTER
00600 else if (Target == _R(IDC_ALIGNDIALOG_TOSPREAD))
00601 {
00602 Align.target=ToSpread;
00603 }
00604 #endif //webster
00605 else
00606 {
00607 ERROR3("ArrangeAlignment::UpdateState() - unknown target");
00608 }
00609
00610
00611 Align.h = (AlignType)GetSelectedValueIndex(_R(IDC_ALIGNDIALOG_HORIZONTAL));
00612 Align.v = (AlignType)GetSelectedValueIndex(_R(IDC_ALIGNDIALOG_VERTICAL));
00613
00614
00615 InvalidateGadget(_R(IDC_ALIGNDIALOG_DIAGRAM));
00616
00617
00618 INT32 NumObjs = 0;
00619 if (Document::GetSelected())
00620 NumObjs = GetApplication()->FindSelection()->Count();
00621 BOOL ApplyButtonState = (NumObjs>0);
00622 if (NumObjs==1 && Target==_R(IDC_ALIGNDIALOG_TOSELECTION)) ApplyButtonState = FALSE;
00623 if (Align.h==AlignNone && Align.v==AlignNone) ApplyButtonState = FALSE;
00624 EnableGadget(_R(IDOK),ApplyButtonState);
00625 }
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636 void ArrangeAlignment::DialogOKed()
00637 {
00638 if (Align.h!=AlignNone || Align.v!=AlignNone)
00639 {
00640 OpDescriptor* pOpDesc=OpDescriptor::FindOpDescriptor(OPTOKEN_OPALIGN);
00641 ERROR3IF_PF(pOpDesc==NULL,("Couldn't find OPTOKEN_OPALIGN op descriptor"));
00642 pOpDesc->Invoke((OpParam*)&Align);
00643 }
00644 }
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660 void ArrangeAlignment::BuildIDSDropList(const CGadgetID DropListID,
00661 const INT32* IDSList, INT32 Default)
00662 {
00663
00664 DeleteAllValues(DropListID);
00665
00666
00667 String_32 Str;
00668 INT32 i=0;
00669 while (IDSList[i])
00670 {
00671 Str.MakeMsg(IDSList[i]);
00672 SetStringGadgetValue( DropListID, Str );
00673 i++;
00674 }
00675 SetComboListLength(DropListID);
00676
00677
00678 if (Default<0 || Default>=i)
00679 {
00680 ERROR3("BuildIDSDropList() passed a default outside the list");
00681 Default=0;
00682 }
00683 SetSelectedValueIndex(DropListID,Default);
00684 }
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700 CGadgetID ArrangeAlignment::ReadRadioGroup(const CGadgetID* IDCList,
00701 const CGadgetID IDCDefault)
00702 {
00703 BOOL valid;
00704 INT32 i=0;
00705 while (IDCList[i])
00706 {
00707 if (GetLongGadgetValue(IDCList[i],0,1,0,&valid))
00708 return (IDCList[i]);
00709 i++;
00710 }
00711 return (IDCDefault);
00712 }
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729 void ArrangeAlignment::SetRadioGroup(const CGadgetID* IDCList, const CGadgetID IDC)
00730 {
00731 INT32 i=0;
00732 while (IDCList[i])
00733 {
00734 SetLongGadgetValue(IDCList[i],IDCList[i]==IDC);
00735 i++;
00736 }
00737 }
00738
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749 OpAlign::OpAlign() : TransOperation()
00750 {
00751 }
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762 BOOL OpAlign::Init()
00763 {
00764 return RegisterOpDescriptor(
00765 0,
00766 _R(IDS_OPALIGN),
00767 CC_RUNTIME_CLASS(OpAlign),
00768 OPTOKEN_OPALIGN,
00769 OpAlign::GetState,
00770 0,
00771 0,
00772 0,
00773 0
00774
00775 );
00776 }
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786 OpState OpAlign::GetState(String_256* pString, OpDescriptor* pOpDesc)
00787 {
00788 return ArrangeAlignment::GetState(pString, pOpDesc);
00789 }
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799 void OpAlign::DoWithParam(OpDescriptor* pOp, OpParam* pAlignParam)
00800 {
00801
00802 SelRange Selection(*(GetApplication()->FindSelection()));
00803
00804 RangeControl rg = Selection.GetRangeControlFlags();
00805 rg.PromoteToParent = TRUE;
00806 Selection.Range::SetRangeControl(rg);
00807
00808 DocRect SelRect = Selection.GetBoundingRect();
00809 DocRect TargetRect;
00810 TargetRect.MakeEmpty();
00811 INT32 NumObjs = Selection.Count();
00812 AlignParam* pAlign =(AlignParam*)pAlignParam;
00813
00814 BOOL moved=FALSE;
00815 BeginSlowJob(-1,FALSE);
00816 BOOL OK=DoStartTransOp(FALSE);
00817
00818
00819 Node* pFirstNode=NULL;
00820 Spread* pSpread =NULL;
00821 if (OK)
00822 {
00823 pFirstNode=Selection.FindFirst();
00824 if (pFirstNode!=NULL)
00825 pSpread=pFirstNode->FindParentSpread();
00826 OK=(pSpread!=NULL);
00827 if (!OK)
00828 ERROR2RAW("OpAlign::DoWithParam() - could not find parent spread");
00829 }
00830
00831
00832 if (pAlign->target==ToSelection)
00833 TargetRect=SelRect;
00834 else
00835 {
00836 Page* pPage=pSpread->FindFirstPageInSpread();
00837 while (pPage)
00838 {
00839 DocRect PageRect=pPage->GetPageRect();
00840 if (pAlign->target==ToSpread || SelRect.IsIntersectedWith(PageRect))
00841 TargetRect=TargetRect.Union(PageRect);
00842 pPage=pPage->FindNextPage();
00843 }
00844 }
00845
00846
00847 Node** pObj=NULL;
00848 ObjInfo* x =NULL;
00849 ObjInfo* y =NULL;
00850 INT32* dx =NULL;
00851 INT32* dy =NULL;
00852 if (OK) ALLOC_WITH_FAIL(pObj,(Node**) CCMalloc(NumObjs*sizeof(Node*)), this);
00853 if (pObj!=NULL) ALLOC_WITH_FAIL(x, (ObjInfo*)CCMalloc(NumObjs*sizeof(ObjInfo)),this);
00854 if ( x!=NULL) ALLOC_WITH_FAIL(y, (ObjInfo*)CCMalloc(NumObjs*sizeof(ObjInfo)),this);
00855 if ( y!=NULL) ALLOC_WITH_FAIL(dx, (INT32*) CCMalloc(NumObjs*sizeof(INT32)), this);
00856 if ( dx!=NULL) ALLOC_WITH_FAIL(dy, (INT32*) CCMalloc(NumObjs*sizeof(INT32)), this);
00857 OK=(dy!=NULL);
00858
00859
00860
00861 DocRect EmptyRect;
00862 if (OK && TargetRect!=EmptyRect)
00863 {
00864
00865 Node* pNode=Selection.FindFirst();
00866 INT32 i=0;
00867 while (pNode!=NULL)
00868 {
00869 if (pNode->IsBounded() && !((NodeRenderableBounded*)pNode)->GetBoundingRect(TRUE).IsEmpty())
00870 pObj[i++]=pNode;
00871 pNode=Selection.FindNext(pNode);
00872 }
00873 NumObjs=i;
00874
00875
00876 XLONG SumObjWidths =0;
00877 XLONG SumObjHeights=0;
00878 for (i=0; i<NumObjs; i++)
00879 {
00880 DocRect ObjRect=((NodeRenderableBounded*)pObj[i])->GetBoundingRect();
00881 x[i].i=i;
00882 x[i].lo=ObjRect.lo.x;
00883 x[i].hi=ObjRect.hi.x;
00884 SumObjWidths+=ObjRect.hi.x-ObjRect.lo.x;
00885 y[i].i=i;
00886 y[i].lo=ObjRect.lo.y;
00887 y[i].hi=ObjRect.hi.y;
00888 SumObjHeights+=ObjRect.hi.y-ObjRect.lo.y;
00889 }
00890
00891
00892 AlignOneAxis(pAlign->h,NumObjs,SumObjWidths, TargetRect.lo.x,TargetRect.hi.x,x,dx);
00893 AlignOneAxis(pAlign->v,NumObjs,SumObjHeights,TargetRect.lo.y,TargetRect.hi.y,y,dy);
00894
00895
00896 for (i=0; i<NumObjs; i++)
00897 if (dx[i]!=0 || dy[i]!=0)
00898 {
00899 moved=TRUE;
00900 Trans2DMatrix* pMatrix=new Trans2DMatrix(dx[i],dy[i]);
00901 DoTransformNode((NodeRenderableInk*)pObj[i],pMatrix);
00902 }
00903 }
00904
00905
00906 CCFree(dx);
00907 CCFree(dy);
00908 CCFree(x);
00909 CCFree(y);
00910 CCFree(pObj);
00911
00912 if (moved)
00913 {
00914 Document::GetSelected()->ForceRedraw(pSpread, TargetRect);
00915 GetApplication()->UpdateSelection();
00916 }
00917 else
00918 FailAndExecute();
00919 End();
00920 EndSlowJob();
00921 }
00922
00923
00924
00925
00926 extern "C" INT32 CompareObjInfoLow(const void* elem1, const void* elem2)
00927 {
00928 ObjInfo* a=(ObjInfo*)elem1;
00929 ObjInfo* b=(ObjInfo*)elem2;
00930 if (a->lo == b->lo)
00931 return (a->i < b->i ? -1 : 1);
00932 else
00933 return (a->lo < b->lo ? -1 : 1);
00934 }
00935
00936 extern "C" INT32 CompareObjInfoHigh(const void* elem1, const void* elem2)
00937 {
00938 ObjInfo* a=(ObjInfo*)elem1;
00939 ObjInfo* b=(ObjInfo*)elem2;
00940 if (a->hi == b->hi)
00941 return (a->i < b->i ? -1 : 1);
00942 else
00943 return (a->hi < b->hi ? -1 : 1);
00944 }
00945
00946 extern "C" INT32 CompareObjInfoCentre(const void* elem1, const void* elem2)
00947 {
00948 ObjInfo* a=(ObjInfo*)elem1;
00949 ObjInfo* b=(ObjInfo*)elem2;
00950 INT32 d=(a->lo+a->hi)-(b->lo+b->hi);
00951 if (d==0)
00952 return (a->i < b->i ? -1 : 1);
00953 else
00954 return ( d < 0 ? -1 : 1);
00955 }
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975 void OpAlign::AlignOneAxis(AlignType Align, INT32 NumObjs, XLONG SumObjWidths,
00976 INT32 RectLow, INT32 RectHigh, ObjInfo* x, INT32* dx)
00977 {
00978 INT32 i;
00979
00980 switch (Align)
00981 {
00982 case DistributeLow:
00983 if (NumObjs==1)
00984 dx[0]=0;
00985 else
00986 {
00987 qsort(x,NumObjs,sizeof(ObjInfo),CompareObjInfoLow);
00988 INT32 RectWidth=RectHigh-RectLow;
00989 INT32 LastObjWidth =x[NumObjs-1].hi-x[NumObjs-1].lo;
00990 INT32 gap=(RectWidth-LastObjWidth)/(NumObjs-1);
00991 INT32 pos=RectLow;
00992 for (i=0; i<NumObjs; i++)
00993 {
00994 dx[x[i].i]=pos-x[i].lo;
00995 pos+=gap;
00996 }
00997 }
00998 break;
00999
01000 case DistributeHigh:
01001 if (NumObjs==1)
01002 dx[0]=0;
01003 else
01004 {
01005 qsort(x,NumObjs,sizeof(ObjInfo),CompareObjInfoHigh);
01006 INT32 RectWidth=RectHigh-RectLow;
01007 INT32 FirstObjWidth=x[0].hi-x[0].lo;
01008 INT32 gap=(RectWidth-FirstObjWidth)/(NumObjs-1);
01009 INT32 pos=RectLow+FirstObjWidth;
01010 for (i=0; i<NumObjs; i++)
01011 {
01012 dx[x[i].i]=pos-x[i].hi;
01013 pos+=gap;
01014 }
01015 }
01016 break;
01017
01018 case DistributeCentre:
01019 if (NumObjs==1)
01020 dx[0]=0;
01021 else
01022 {
01023 qsort(x,NumObjs,sizeof(ObjInfo),CompareObjInfoCentre);
01024 INT32 RectWidth=RectHigh-RectLow;
01025 INT32 LastObjWidth =x[NumObjs-1].hi-x[NumObjs-1].lo;
01026 INT32 FirstObjWidth=x[0].hi-x[0].lo;
01027 INT32 gap=(RectWidth-(FirstObjWidth+LastObjWidth)/2)/(NumObjs-1);
01028 INT32 pos=RectLow+FirstObjWidth/2;
01029 for (i=0; i<NumObjs; i++)
01030 {
01031 dx[x[i].i]=pos-(x[i].hi+x[i].lo)/2;
01032 pos+=gap;
01033 }
01034 }
01035 break;
01036
01037 case DistributeEqui:
01038 if (NumObjs==1)
01039 dx[0]=0;
01040 else
01041 {
01042 qsort(x,NumObjs,sizeof(ObjInfo),CompareObjInfoCentre);
01043 INT32 RectWidth=RectHigh-RectLow;
01044 INT32 gap=((XLONG)RectWidth-SumObjWidths)/(NumObjs-1);
01045 INT32 pos=RectLow;
01046 for (i=0; i<NumObjs; i++)
01047 {
01048 dx[x[i].i]=pos-x[i].lo;
01049 pos+=gap+x[i].hi-x[i].lo;
01050 }
01051 }
01052 break;
01053
01054 case AlignLow:
01055 for (i=0; i<NumObjs; i++)
01056 dx[i]=RectLow-x[i].lo;
01057 break;
01058
01059 case AlignCentre:
01060 for (i=0; i<NumObjs; i++)
01061 dx[i]=(RectHigh-x[i].hi+RectLow-x[i].lo)/2;
01062 break;
01063
01064 case AlignHigh:
01065 for (i=0; i<NumObjs; i++)
01066 dx[i]=RectHigh-x[i].hi;
01067 break;
01068
01069 case AlignNone:
01070 for (i=0; i<NumObjs; i++)
01071 dx[i]=0;
01072 break;
01073 }
01074 }