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 #include "camtypes.h"
00101
00102
00103
00104 #include "slice.h"
00105
00106 #include "ngcore.h"
00107 #include "ngitem.h"
00108
00109 #include "xshelpid.h"
00110
00111
00112
00113 #include "progress.h"
00114 #include "osrndrgn.h"
00115
00116 #include "giffiltr.h"
00117 #include "bmpfiltr.h"
00118 #include "pngfiltr.h"
00119 #include "extfilts.h"
00120
00121 #include "exjpeg.h"
00122
00123 #include "page.h"
00124
00125
00126 #include "mrhbits.h"
00127 #include "selall.h"
00128
00129 #include "slicehelper.h"
00130
00131
00132 #include "bmapprev.h"
00133
00134 #include "ngprop.h"
00135 #include "ngsentry.h"
00136
00137 #include "webattr.h"
00138
00139
00140
00141 #include "userattr.h"
00142 #include "tmpltatr.h"
00143
00144 #include "desnotes.h"
00145 #include <io.h>
00146 #include "helpuser.h"
00147
00148
00149
00150 #include "nodetxts.h"
00151 #include "nodetxtl.h"
00152 #include "nodetext.h"
00153
00154
00155
00156
00157 #ifdef _DEBUG
00158 #undef THIS_FILE
00159 static char BASED_CODE THIS_FILE[] = __FILE__;
00160 #endif
00161
00162 DECLARE_SOURCE("$Revision: 1282 $");
00163
00164 CC_IMPLEMENT_DYNCREATE(OpSlice, OpMenuImport);
00165
00166 #define new CAM_DEBUG_NEW
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180 CSlice::CSlice()
00181 {
00182 top = bottom = left = right = 0;
00183 row = colm = -1;
00184 rowspan = colmspan = 1;
00185 rowheight = colmwidth = 0;
00186 name.Empty();
00187 FileTypeExtStr = "gif";
00188 deleteme = FALSE;
00189 IsNamedSlice = FALSE;
00190 ButtonNumber = 0;
00191 IsEmpty = FALSE;
00192 HasURL = FALSE;
00193 pFrameText = NULL;
00194 ExistsOnLayerState[0] = 0;
00195 ExistsOnLayerState[1] = 0;
00196 ExistsOnLayerState[2] = 0;
00197 ExistsOnLayerState[3] = 0;
00198 }
00199
00200 CSlice::CSlice(INT32 Ax, INT32 Ay, INT32 Cx, INT32 Cy, String_256 ThisName, String_16 FileExt, BOOL Named)
00201 {
00202 top = min(Ay, Cy);
00203 left = min(Ax, Cx);
00204 right = max(Ax, Cx);
00205 bottom = max(Ay, Cy);
00206 name = ThisName;
00207 row = colm = -1;
00208 rowspan = colmspan = 1;
00209 rowheight = colmwidth = 0;
00210 FileTypeExtStr = FileExt;
00211 deleteme = FALSE;
00212 IsNamedSlice = Named;
00213 ButtonNumber = 0;
00214 IsEmpty = FALSE;
00215 HasURL = FALSE;
00216 pFrameText = NULL;
00217 ExistsOnLayerState[0] = 0;
00218 ExistsOnLayerState[1] = 0;
00219 ExistsOnLayerState[2] = 0;
00220 ExistsOnLayerState[3] = 0;
00221 }
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 void CSlice::SwapSpreadAndSliceCoords()
00236 {
00237 INT32 temp = top;
00238 top = -bottom;
00239 bottom = -temp;
00240 }
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253 BOOL OpSlice::Init()
00254 {
00255 return RegisterOpDescriptor(
00256 0,
00257 _R(IDS_IMAGESLICE),
00258 CC_RUNTIME_CLASS(OpSlice),
00259 OPTOKEN_IMAGESLICE,
00260 GetState,
00261 _R(IDH_Command_Import_from_Web),
00262 _R(IDBBL_IMAGESLICE),
00263 _R(IDD_BARCONTROLSTORE),
00264 _R(IDC_IMAGESLICE),
00265 SYSTEMBAR_FILE,
00266 TRUE,
00267 FALSE,
00268 TRUE,
00269 0,
00270 (DONT_GREY_WHEN_SELECT_INSIDE | GREY_WHEN_NO_CURRENT_DOC)
00271 );
00272
00273 }
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285 void OpSlice::Do(OpDescriptor*)
00286 {
00287
00288 Spread* pSelSpread = Document::GetSelectedSpread();
00289 if (pSelSpread == NULL)
00290 return;
00291
00292
00293
00294 BmapPrevDlg::m_bSlicingImage = TRUE;
00295
00296 m_ErrorStr = "none";
00297 m_HTMLext = "htm";
00298
00299 m_NumberOfButtons = 0;
00300
00301
00302
00303
00304
00305 m_PathName.SetPathName("c:\\untitled.non");
00306
00307 m_InjectHTML = FALSE;
00308
00309 m_ExportedHTMLOK = TRUE;
00310
00311
00312 Progress LongJob;
00313 LongJob.Start();
00314
00315
00316 m_UsesDesignNotes = UsesDesignNotes();
00317
00318
00319 DocColour dcol = Page::GetPageColour();
00320 m_lRed = m_lGreen = m_lBlue = 255;
00321
00322 BOOL HasBitmapBackground = FALSE;
00323
00324 Layer * pLayer = pSelSpread->FindFirstPageBackgroundLayer();
00325 if (pLayer)
00326 {
00327 Node * pNode = SliceHelper::FindNextOfClass(pLayer, pLayer, CC_RUNTIME_CLASS(AttrFlatColourFill));
00328 if (pNode)
00329 dcol = *(((AttrFlatFill *)pNode)->GetStartColour());
00330 else
00331 {
00332 if (SliceHelper::FindNextOfClass(pLayer, pLayer, CC_RUNTIME_CLASS(AttrBitmapColourFill)))
00333 HasBitmapBackground = TRUE;
00334 }
00335 }
00336
00337 dcol.GetRGBValue(&m_lRed, &m_lGreen, &m_lBlue);
00338
00339
00340
00341
00342
00343 CList <CSlice *, CSlice *> MosaicList;
00344 MosaicList.RemoveAll();
00345
00346
00347 DocRect SpreadBounds = BaseBitmapFilter::GetSizeOfDrawing(pSelSpread);
00348
00349
00350 Range Sel(*(GetApplication()->FindSelection()));
00351
00352
00353 RangeControl rg = Sel.GetRangeControlFlags();
00354 rg.PromoteToParent = TRUE;
00355 Sel.Range::SetRangeControl(rg);
00356 BOOL UseWholeDrawing = TRUE;
00357
00358
00359
00360
00361 if (!Sel.IsEmpty())
00362 {
00363 SpreadBounds = Sel.GetBoundingRect();
00364 UseWholeDrawing = FALSE;
00365 }
00366
00367 PixelAlignedInflate(&SpreadBounds);
00368
00369
00370 NameGallery* pNameGallery = NameGallery::Instance();
00371 SGUsedNames* pNames = pNameGallery?NameGallery->GetUsedNames():NULL;
00372
00373 if (!pNames)
00374 {
00375 InformWarning( _R(IDS_NOSLICES) );
00376
00377 BmapPrevDlg::m_bSlicingImage = FALSE;
00378 return;
00379 }
00380
00381
00382 pNameGallery->FastUpdateNamedSetSizes();
00383
00384
00385 BOOL NoProblems = TRUE;
00386 BOOL AddedASlice = FALSE;
00387 BOOL OutsideSpread = FALSE;
00388
00389 INT32 Attempts = 0;
00390 String_256 strName(TEXT("Empty"));
00391 String_256 Slice1ErrorStr = "";
00392 String_256 Slice2ErrorStr = "";
00393 INT32 SlicesDefinedInDrawing = 0;
00394
00395 do
00396 {
00397 NoProblems = TRUE;
00398 AddedASlice = FALSE;
00399 OutsideSpread = FALSE;
00400 SlicesDefinedInDrawing = 0;
00401
00402
00403
00404 TidyMosaicList(&MosaicList);
00405 MosaicList.AddHead(new CSlice(SpreadBounds.lox, SpreadBounds.loy, SpreadBounds.hix, SpreadBounds.hiy));
00406
00407 SGNameItem* pItem = (SGNameItem*) pNames->GetChild();
00408
00409 while (pItem != 0 && NoProblems)
00410 {
00411
00412 BOOL UseThisSlice = TRUE;
00413 NamedTickboxProp * pSliceTick = (NamedTickboxProp *) pItem->GetProperty(1);
00414 if (pSliceTick)
00415 {
00416 UseThisSlice = pSliceTick->GetState();
00417 if (UseThisSlice)
00418 SlicesDefinedInDrawing++;
00419 }
00420
00421
00422 if (!UseWholeDrawing && pItem->IsNoneSelected())
00423 UseThisSlice = FALSE;
00424
00425 if (UseThisSlice)
00426 {
00427 DocRect r;
00428 r = pItem->GetSetBounds();
00429
00430 pItem->GetNameText(&strName);
00431
00432
00433 ScanTextStorySliceBounds(strName, r);
00434
00435 if (Attempts == 0)
00436 {
00437 DocRect rLarge = ScanLargeSliceBounds(strName);
00438 r = r.Union(rLarge);
00439 }
00440
00441
00442
00443 PixelAlignedInflate(&r);
00444
00445
00446 r = r.Intersection(SpreadBounds);
00447
00448
00449
00450 if (r.IsValid() && r.Height() > 0 && r.Width() > 0)
00451 {
00452 NoProblems = NoProblems && AddSlice(r.lox, r.loy, r.hix, r.hiy, &MosaicList, strName);
00453 AddedASlice = TRUE;
00454 }
00455 else
00456 {
00457 TRACEUSER( "SimonK", _T("Slice outside bounds of the drawing!!!\n"));
00458 }
00459 }
00460
00461 if (NoProblems) pItem = (SGNameItem*) pItem->GetNext();
00462 }
00463
00464 Attempts++;
00465 if (!NoProblems)
00466 {
00467 Slice1ErrorStr = m_ErrorStr;
00468 Slice2ErrorStr = strName;
00469 }
00470
00471 } while (!NoProblems && Attempts < 2);
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495 POSITION Test = NULL;
00496
00497 if (NoProblems && AddedASlice)
00498 {
00499
00500
00501 SortSlices(&MosaicList, SpreadBounds);
00502
00503
00504 m_FoundRolloverStates = ScanForRolloverStates(&MosaicList);
00505
00506 BOOL ReplaceFiles = TRUE;
00507 BOOL FilesOverwriten = FALSE;
00508 do
00509
00510 {
00511
00512
00513
00514 if (!SaveFileDlg())
00515 {
00516
00517 TidyMosaicList(&MosaicList);
00518 Error::ClearError();
00519
00520 BmapPrevDlg::m_bSlicingImage = FALSE;
00521 return;
00522 }
00523
00524
00525
00526 String_256 temp = m_PathName.GetFileName(FALSE);
00527 INT32 dot = temp.FindNextChar(TCHAR ('.'));
00528 if (dot > 0)
00529 {
00530 String_256 end = "";
00531 temp.Split(&temp, &end, dot, FALSE);
00532 if (end.CompareTo(".html", FALSE) == 0)
00533 {
00534 m_HTMLext = "html";
00535 m_PathName.SetFileName(temp);
00536 }
00537 }
00538
00539 CString ClickedFile(temp);
00540 ClickedFile += "." + m_HTMLext;
00541
00542 ReplaceFiles = FileExists(ClickedFile);
00543 FilesOverwriten = FALSE;
00544
00545 if (!ReplaceFiles)
00546 {
00547
00548 Test = MosaicList.GetHeadPosition();
00549 while (Test && !FilesOverwriten)
00550 {
00551 CSlice* pTestSlice = MosaicList.GetNext(Test);
00552 CString TestName (pTestSlice->name);
00553
00554
00555
00556 FilesOverwriten = FileExists(TestName + ".gif");
00557 if (!FilesOverwriten) FilesOverwriten = FileExists(TestName + ".jpg");
00558 if (!FilesOverwriten) FilesOverwriten = FileExists(TestName + ".jpeg");
00559 if (!FilesOverwriten) FilesOverwriten = FileExists(TestName + ".png");
00560 if (!FilesOverwriten) FilesOverwriten = FileExists(TestName + ".bmp");
00561 }
00562 }
00563
00564 if (FilesOverwriten && !ReplaceFiles)
00565 {
00566
00567
00568 if (InformWarning(_R(IDS_CONFLICTING_SLICE_FILENAMES), _R(IDS_OVERWRITE_GRAPHIC), _R(IDS_SAVE_ELSEWHERE)) == 1)
00569 ReplaceFiles = TRUE;
00570 }
00571
00572 } while (FilesOverwriten && !ReplaceFiles);
00573
00574
00575
00576
00577 BmapPrevDlg::m_pthExport = m_PathName;
00578
00579
00580 BitmapExportOptions * pExportOptions = NULL;
00581 BOOL ok = TRUE;
00582
00583 ShowRolloverLayer(ALL_LAYERS);
00584
00585
00586
00587
00588 String_256 strExt = m_PathName.GetType();
00589 strExt.toLower();
00590 if (strExt.CompareTo("jpg") == 0)
00591 {
00592 JPEGExportFilter f;
00593 ok = f.SetUpExportOptions(&pExportOptions);
00594 }
00595 else
00596 if (strExt.CompareTo("bmp") == 0)
00597 {
00598 BMPFilter f;
00599 ok = f.SetUpExportOptions(&pExportOptions);
00600 }
00601 else
00602 if (strExt.CompareTo("png") == 0)
00603 {
00604 PNGFilter f;
00605 ok = f.SetUpExportOptions(&pExportOptions);
00606 }
00607 else
00608
00609 {
00610 TI_GIFFilter f;
00611 ok = f.SetUpExportOptions(&pExportOptions);
00612 }
00613
00614
00615
00616 pExportOptions = BmapPrevDlg::m_pExportOptions;
00617
00618 BmapPrevDlg::m_pExportOptions = 0;
00619
00620
00621 if (!ok)
00622 {
00623 if (pExportOptions)
00624 {
00625 delete pExportOptions;
00626 }
00627
00628 TidyMosaicList(&MosaicList);
00629 Error::ClearError();
00630
00631 BmapPrevDlg::m_bSlicingImage = FALSE;
00632 return;
00633 }
00634
00635
00636
00637
00638 m_PathName = BmapPrevDlg::m_pthExport;
00639
00640
00641
00642 (DocView::GetSelected())->ForceRedraw();
00643 GetApplication()->OnIdle(TRUE);
00644
00645
00646
00647 UpdateSliceFileExts(&MosaicList);
00648
00649
00650
00651 if (!HasBitmapBackground)
00652 MarkEmptySlices(&MosaicList, SpreadBounds, pExportOptions);
00653
00654
00655 Test = MosaicList.GetHeadPosition();
00656 while (Test)
00657 {
00658 CSlice* pTestSlice = MosaicList.GetNext(Test);
00659
00660 if (m_FoundRolloverStates && pTestSlice->IsNamedSlice)
00661
00662 ExportRollOverSlice(pTestSlice, pExportOptions);
00663 else
00664
00665 {
00666
00667 if (!pTestSlice->IsEmpty)
00668 ExportSliceGraphic(pTestSlice, pExportOptions, pTestSlice->name);
00669 }
00670
00671
00672
00673
00674
00675
00676 }
00677
00678
00679 if (pExportOptions != 0)
00680 {
00681 delete pExportOptions;
00682 pExportOptions = 0;
00683 }
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694 m_UsedShimGraphic = FALSE;
00695 PathName HTMLPath = m_PathName;
00696 HTMLPath.SetType(m_HTMLext);
00697 m_pLinkName = NULL;
00698 INT32 i = 0;
00699 String_256 LaunchString = HTMLPath.GetFileName();
00700
00701 INT32 LinkEntries = max (m_NumberOfButtons, 1);
00702 m_pLinkName = new String_256[LinkEntries];
00703
00704 if (m_pLinkName)
00705 {
00706 m_pLinkName[0] = HTMLPath.GetPath();
00707
00708 INT32 FileNumber = 0;
00709
00710 for (i = 0; i < m_NumberOfButtons; i++)
00711 {
00712 m_pLinkName[i] = m_PathName.GetFileName(FALSE);
00713
00714 CSlice * pTestSlice = GetButtonNumber (&MosaicList, i+1);
00715 if (pTestSlice && pTestSlice->ExistsOnLayerState[SELECTED])
00716 {
00717 FileNumber++;
00718
00719 if (m_FoundRolloverStates && m_RolloverState[SELECTED].Exists && FileNumber > 1)
00720 {
00721 String_256 NewName;
00722 NewName.MakeMsg(_R(IDS_HTML_NAME_SPEC), (LPCSTR) m_PathName.GetFileName(FALSE), FileNumber);
00723 m_pLinkName[i] = NewName;
00724 }
00725 }
00726
00727 m_pLinkName[i] += ".";
00728 m_pLinkName[i] += m_HTMLext;
00729 }
00730
00731
00732
00733 URLScan(m_pLinkName, &MosaicList);
00734
00735 FileNumber = 0;
00736
00737
00738 if (m_RolloverState[SELECTED].Exists)
00739 for (i = 0; i < LinkEntries; i++)
00740 {
00741 String_256 NewName = m_pLinkName[i];
00742 String_256 Temp = "";
00743
00744
00745 NewName.Left(&Temp,5);
00746 BOOL isURL = (Temp.CompareTo("http:", FALSE) == 0);
00747 if (!isURL)
00748 {
00749 NewName.Right(&Temp,1);
00750 isURL = (Temp.CompareTo("/") == 0);
00751 }
00752
00753 CSlice * pTestSlice = GetButtonNumber (&MosaicList, i+1);
00754 if (pTestSlice && pTestSlice->ExistsOnLayerState[SELECTED])
00755 {
00756 FileNumber++;
00757
00758 if (isURL)
00759 {
00760 NewName.MakeMsg(_R(IDS_HTML_NAME_SPEC), (LPCSTR) m_PathName.GetFileName(FALSE), FileNumber);
00761 NewName += ".";
00762 NewName += m_HTMLext;
00763 }
00764
00765 HTMLPath.SetPathName(NewName);
00766
00767 if (!ExportImageSliceHTML(&MosaicList, HTMLPath.GetPath(), i+1))
00768 FailledToExportHTML (HTMLPath.GetPath());
00769
00770
00771 if (FileNumber == 1)
00772 {
00773 LaunchString = HTMLPath.GetFileName();
00774 }
00775 }
00776
00777 }
00778 else
00779 if (!ExportImageSliceHTML(&MosaicList, HTMLPath.GetPath()))
00780 FailledToExportHTML (HTMLPath.GetPath());
00781
00782 delete [] m_pLinkName;
00783 m_pLinkName = NULL;
00784 }
00785
00786
00787 if (m_UsedShimGraphic)
00788 {
00789
00790
00791 PathName ShimPath = m_PathName;
00792
00793 ShimPath.SetFileName("shim");
00794 ShimPath.SetType("gif");
00795
00796 CCDiskFile File;
00797 if(File.open(ShimPath.GetPath(), (ios::in | ios::out | ios::binary)))
00798 {
00799 BYTE buf[] = {0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00,
00800 0x01, 0x00, 0x80, 0x00, 0x00, 0xFF, 0xFF, 0xFF,
00801 0x00, 0x00, 0x00, 0x21, 0xF9, 0x04, 0x01, 0x14,
00802 0x00, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00,
00803 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x44,
00804 0x01, 0x00, 0x3B, 0x00 };
00805
00806
00807 buf[13] = (BYTE) m_lRed;
00808 buf[14] = (BYTE) m_lGreen;
00809 buf[15] = (BYTE) m_lBlue;
00810
00811
00812 File.write((BYTE *)buf, 44);
00813 File.close();
00814 }
00815 }
00816
00817
00818 if (m_ExportedHTMLOK && AskQuestion(_R(IDS_SHOW_HTML_NOW), _R(IDS_YES), _R(IDS_NO)) == 1)
00819 {
00820
00821 HINSTANCE hChild = ShellExecute(HWND_DESKTOP, "open", LaunchString, NULL, NULL ,SW_SHOW);
00822
00823
00824 INT32 Result = (INT32)hChild;
00825
00826 if (Result <= 32)
00827 {
00828 InformWarning(_R(IDS_NO_BROWSER));
00829 }
00830 }
00831
00832 }
00833 else if (!AddedASlice)
00834 {
00835 if (SlicesDefinedInDrawing == 0)
00836 InformWarning( _R(IDS_NOSLICES) );
00837 else
00838 InformWarning( _R(IDS_NOSLICES_SELECTED) );
00839 }
00840 else
00841 {
00842 if (OutsideSpread)
00843 {
00844
00845 InformWarning(_R(IDS_SLICE_OUT_OF_BOUNDS));
00846 }
00847 else
00848 {
00849
00850 String_256 temp(TEXT(""));
00851 temp.MakeMsg(_R(IDS_SLICES_OVERLAP), (LPCTSTR) m_ErrorStr, (LPCTSTR) strName);
00852
00853 ErrorInfo Info;
00854 Info.ErrorMsg = 0;
00855 Info.Button[0] = _R(IDS_OK);
00856 Info.Button[1] = _R(IDS_HELP);
00857 Info.OK = 1;
00858 Info.Help = 2;
00859 Info.Title = _R(IDBBL_IMAGESLICE);
00860
00861 BOOL Again;
00862 do
00863 {
00864
00865 Error::SetError( 0, temp, 0 );
00866
00867 Again = FALSE;
00868 switch (AskQuestion(&Info))
00869 {
00870 case _R(IDS_HELP):
00871 HelpUserTopic(_R(IDS_HELPPATH_Alert_Named_Objects_Overlap));
00872 Again = TRUE;
00873 break;
00874 }
00875 } while (Again);
00876 }
00877 }
00878
00879
00880 TidyMosaicList(&MosaicList);
00881
00882
00883
00884
00885
00886 BmapPrevDlg::m_bSlicingImage = FALSE;
00887 }
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899 INT32 OpSlice::TidyMosaicList(CList <CSlice *, CSlice *> * pMosaicList)
00900 {
00901
00902 INT32 Pieces = 0;
00903 POSITION Test = pMosaicList->GetHeadPosition();
00904 while (Test)
00905 {
00906 CSlice * pTestSlice = pMosaicList->GetNext(Test);
00907 pMosaicList->RemoveHead();
00908 delete pTestSlice;
00909 Pieces++;
00910 }
00911
00912 return Pieces;
00913 }
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924 void OpSlice::UpdateSliceFileExts(CList <CSlice *, CSlice *> * pMosaicList)
00925 {
00926 POSITION Test = pMosaicList->GetHeadPosition();
00927 while (Test)
00928 {
00929 CSlice * pTestSlice = pMosaicList->GetNext(Test);
00930 if (pTestSlice->FileTypeExtStr.CompareTo("non") == 0)
00931 pTestSlice->FileTypeExtStr = m_PathName.GetType();
00932 }
00933
00934 }
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946 OpState OpSlice::GetState(String_256*, OpDescriptor*)
00947 {
00948 OpState OpSt;
00949
00950
00951 OpSt.Greyed = TRUE;
00952 Spread* pSpread = Document::GetSelectedSpread();
00953 if (pSpread && !pSpread->FindActiveLayer()->IsFrame())
00954 OpSt.Greyed = FALSE;
00955
00956 return OpSt;
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 BOOL OpSlice::AddSlice (INT32 Ax, INT32 Ay, INT32 Cx, INT32 Cy, CList <CSlice *, CSlice *> * pMosaicList, String_256 SliceName)
00984 {
00985
00986
00987
00988 if (Ax == Cx || Ay == Cy) return TRUE;
00989
00990
00991
00992 NudgeSliceIfClose(Ax, Ay, Cx, Cy, pMosaicList);
00993
00994 BOOL ok = TRUE;
00995 POSITION pos = pMosaicList->GetHeadPosition();
00996
00997 while (pos)
00998 {
00999 POSITION thispos = pos;
01000 CSlice * pRect = pMosaicList->GetNext(pos);
01001 BOOL RemoveMe = TRUE;
01002
01003 if (Ax == pRect->left && Cx == pRect->right && Ay == pRect->top && Cy == pRect->bottom)
01004 {
01005
01006
01007 if (!pRect->name.IsEmpty())
01008 {
01009 TRACE( _T("Identically named slices\n"));
01010 if (SliceName.IsEmpty())
01011 SliceName = pRect->name;
01012 }
01013 }
01014 else
01015 if (InRect(pRect, Ax, Ay))
01016 ok = Slice (pRect, Ax, Ay, Cx, Ay, pMosaicList);
01017 else
01018 if (InRect(pRect, Cx, Ay))
01019 ok = Slice (pRect, Ax, Ay, Cx, Ay, pMosaicList);
01020 else
01021 if (CutsRect(pRect, Ax, Ay, Cx, Ay))
01022 ok = Slice (pRect, Ax, Ay, Cx, Ay, pMosaicList);
01023 else
01024 if (InRect(pRect, Cx, Cy))
01025 ok = Slice (pRect, Cx, Ay, Cx, Cy, pMosaicList);
01026 else
01027 if (CutsRect(pRect, Cx, Ay, Cx, Cy))
01028 ok = Slice (pRect, Cx, Ay, Cx, Cy, pMosaicList);
01029 else
01030 if (InRect(pRect, Ax, Cy))
01031 ok = Slice (pRect, Ax, Ay, Ax, Cy, pMosaicList);
01032 else
01033 if (CutsRect(pRect, Ax, Ay, Ax, Cy))
01034 ok = Slice (pRect, Ax, Ay, Ax, Cy, pMosaicList);
01035 else
01036 if (CutsRect(pRect, Ax, Cy, Cx, Cy))
01037 ok = Slice (pRect, Ax, Cy, Cx, Cy, pMosaicList);
01038 else
01039 if (pRect->left >= Ax && pRect->right <= Cx && pRect->top >= Ay && pRect->bottom <= Cy)
01040
01041 {
01042 TRACE( _T("remove sub rect\n"));
01043
01044 }
01045 else
01046 RemoveMe = FALSE;
01047
01048 if (!ok)
01049 return FALSE;
01050
01051 pos = thispos;
01052
01053 pRect = pMosaicList->GetNext(pos);
01054
01055 if (RemoveMe)
01056 {
01057 pMosaicList->RemoveAt(thispos);
01058 delete pRect;
01059 }
01060 }
01061
01062
01063
01064
01065 RemoveIlligalFileAndJavaChars(SliceName);
01066 pMosaicList->AddHead(new CSlice(Ax, Ay, Cx, Cy, SliceName, m_PathName.GetType(), TRUE));
01067
01068 return ok;
01069 }
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081 BOOL OpSlice::InRect(CSlice * pRect, INT32 x, INT32 y)
01082 {
01083 if (x > pRect->left && x < pRect->right
01084 && y > pRect->top && y < pRect->bottom)
01085 return TRUE;
01086
01087 return FALSE;
01088 }
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101 BOOL OpSlice::Slice (CSlice * pRect, INT32 Ax, INT32 Ay, INT32 Bx, INT32 By, CList <CSlice *, CSlice *> * pMosaicList)
01102 {
01103 if (!pRect->name.IsEmpty())
01104 {
01105 m_ErrorStr = pRect->name;
01106
01107 return FALSE;
01108 }
01109
01110 BOOL ok = FALSE;
01111
01112 if (Ax == Bx)
01113 {
01114 pMosaicList->AddTail(new CSlice(pRect->left, pRect->top, Ax, pRect->bottom, "", m_PathName.GetType()));
01115 pMosaicList->AddTail(new CSlice(Ax, pRect->top, pRect->right, pRect->bottom, "", m_PathName.GetType()));
01116 ok = TRUE;
01117 }
01118 else
01119 if (Ay == By)
01120 {
01121 pMosaicList->AddTail(new CSlice(pRect->left, pRect->top, pRect->right, Ay, "", m_PathName.GetType()));
01122 pMosaicList->AddTail(new CSlice(pRect->left, Ay, pRect->right, pRect->bottom, "", m_PathName.GetType()));
01123 ok = TRUE;
01124 }
01125
01126 return ok;
01127 }
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139 BOOL OpSlice::CutsRect(CSlice * pRect, INT32 Ax, INT32 Ay, INT32 Bx, INT32 By)
01140 {
01141 if (Ax == Bx)
01142 {
01143
01144
01145 if (Ay <= pRect->top && By >= pRect->bottom
01146 && Ax < pRect->right && Ax > pRect->left)
01147 return TRUE;
01148 }
01149 else
01150 if (Ay == By)
01151 {
01152
01153
01154 if (Ax <= pRect->left && Bx >= pRect->right
01155 && Ay < pRect->bottom && Ay > pRect->top)
01156 return TRUE;
01157 }
01158
01159 return FALSE;
01160 }
01161
01162
01163 void ReAlignEdge ( INT32 OldEdge, INT32 NewEdge, BOOL Horiz, CList <CSlice *, CSlice *> * pMosaicList)
01164 {
01165 POSITION pos = pMosaicList->GetHeadPosition();
01166
01167 while (pos)
01168 {
01169 CSlice * pRect = pMosaicList->GetNext(pos);
01170
01171 if (Horiz)
01172 {
01173 if (pRect->left == OldEdge)
01174 pRect->left = NewEdge;
01175 else
01176 if (pRect->right == OldEdge)
01177 pRect->right = NewEdge;
01178 }
01179 else
01180 {
01181 if (pRect->bottom == OldEdge)
01182 pRect->bottom = NewEdge;
01183 else
01184 if (pRect->top == OldEdge)
01185 pRect->top = NewEdge;
01186 }
01187 }
01188 }
01189
01190
01191
01192
01193
01194
01195
01196
01197
01198
01199
01200
01201
01202 void OpSlice::NudgeSliceIfClose(INT32 &Ax, INT32 &Ay, INT32 &Cx, INT32 &Cy, CList <CSlice *, CSlice *> * pMosaicList)
01203 {
01204 INT32 OldAx = Ax;
01205 INT32 OldAy = Ay;
01206 INT32 OldCx = Cx;
01207 INT32 OldCy = Cy;
01208
01209 BOOL done = FALSE;
01210
01211
01212 for (INT32 size = 750 ; size <= 1500 && !done ; size += 750)
01213 {
01214 POSITION pos = pMosaicList->GetHeadPosition();
01215
01216 whil