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 #include "camtypes.h"
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 #include "layergal.h"
00115 #include "sgdrag.h"
00116 #include "sginit.h"
00117 #include "sglayer.h"
00118 #include "sgmenu.h"
00119
00120
00121 #include "layer.h"
00122
00123
00124
00125
00126 #include "sprdmsg.h"
00127
00128 #include "dragmgr.h"
00129
00130
00131 #include "ccdc.h"
00132
00133 #include "grnddib.h"
00134 #include "guides.h"
00135
00136 #include "layerprp.h"
00137 #include "layermsg.h"
00138
00139
00140
00141
00142
00143
00144 #include "layermgr.h"
00145
00146 #include "helpuser.h"
00147
00148
00149
00150 void Beep();
00151
00152 #ifndef EXCLUDE_GALS
00153
00154 CC_IMPLEMENT_DYNCREATE(LayerSGallery, SuperGallery)
00155 CC_IMPLEMENT_DYNAMIC(SGLayerGroup, SGDisplayGroup)
00156 CC_IMPLEMENT_DYNAMIC(SGDisplayLayer, SGDisplayItem)
00157 #else
00158 CC_IMPLEMENT_DYNCREATE(LayerSGallery, Operation)
00159 #endif
00160
00161
00162 #define new CAM_DEBUG_NEW
00163
00164
00165
00166 #ifdef _DEBUG
00167
00168 #define DO_SNAP_BUTTON (0)
00169 #else
00170 #define DO_SNAP_BUTTON (0)
00171 #endif
00172
00173
00174 #ifndef EXCLUDE_GALS
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 SGLayerGroup::SGLayerGroup(SuperGallery *ParentGal,
00200 Document *ParentDoc, Library *ParentLib,BOOL IsForeground)
00201 : SGDisplayGroup(ParentGal, ParentDoc, ParentLib)
00202 {
00203 Foreground = IsForeground;
00204 }
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231 BOOL SGLayerGroup::HandleEvent(SGEventType EventType, void *EventInfo,
00232 SGMiscInfo *MiscInfo)
00233 {
00234
00235 switch (EventType)
00236 {
00237 case SGEVENT_REDRAW:
00238 {
00239 DocRect MyRect(FormatRect);
00240
00241 SGRedrawInfo *RedrawInfo = GetRedrawInfo(EventType, EventInfo);
00242
00243 if (IMustRedraw(RedrawInfo))
00244 {
00245 StartRendering(RedrawInfo, MiscInfo);
00246
00247 DocColour Col(192L, 192L, 192L);
00248
00249 RedrawInfo->Renderer->SetLineWidth(0);
00250 RedrawInfo->Renderer->SetLineColour(RedrawInfo->Transparent);
00251 RedrawInfo->Renderer->SetFillColour(Col);
00252 RedrawInfo->Renderer->DrawRect(&MyRect);
00253
00254 ReadGroupTitle();
00255
00256
00257 MyRect.lo.x += IndentWidth + MiscInfo->PixelSize;
00258
00259
00260 DocRect VisibleBtn;
00261 DocRect LockedBtn;
00262 DocRect SnapBtn;
00263 SGDisplayLayer::CalculateButtonRects(MiscInfo, &MyRect,
00264 &VisibleBtn, &LockedBtn, &SnapBtn);
00265
00266 DrawBitmap(RedrawInfo->Renderer, &VisibleBtn, _R(IDB_LGAL_VISIBLE));
00267 DrawBitmap(RedrawInfo->Renderer, &LockedBtn, _R(IDB_LGAL_LOCKED));
00268 #if DO_SNAP_BUTTON
00269 DrawBitmap(RedrawInfo->Renderer, &SnapBtn, _R(IDB_LGAL_SNAP));
00270 #endif
00271
00272
00273 MyRect.lo.x += SG_GapBeforeText;
00274 if (MyRect.lo.x < MyRect.hi.x)
00275 {
00276 RedrawInfo->Renderer->SetFixedSystemTextColours(&RedrawInfo->Foreground, &Col);
00277
00278 String_256 NewTitleText;
00279
00280 UINT32 IDS = _R(IDS_LAYERGAL_FOREGROUND);
00281 if (!IsForeground())
00282 IDS = _R(IDS_LAYERGAL_BACKGROUND);
00283
00284 NewTitleText.MakeMsg(IDS, (TCHAR *)TitleText);
00285 RedrawInfo->Renderer->DrawFixedSystemText(&NewTitleText, MyRect);
00286 }
00287
00288 StopRendering(RedrawInfo, MiscInfo);
00289 }
00290
00291
00292
00293
00294 if (GetChild() == NULL ||
00295 !ChildArea.IsIntersectedWith(RedrawInfo->Bounds))
00296 {
00297 return(FALSE);
00298 }
00299 }
00300 break;
00301
00302
00303 case SGEVENT_MOUSECLICK:
00304
00305
00306 {
00307 SGMouseInfo *MouseInfo = GetMouseInfo(EventType, EventInfo);
00308 if (FormatRect.ContainsCoord(MouseInfo->Position))
00309 return(TRUE);
00310 }
00311 break;
00312
00313
00314 default:
00315
00316 return(SGDisplayGroup::HandleEvent(EventType, EventInfo, MiscInfo));
00317 break;
00318 }
00319
00320
00321 return(GiveEventToMyChildren(EventType, EventInfo, MiscInfo));
00322 }
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333 SGDisplayLayer *SGDisplayLayer::LastClickedLayer = NULL;
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348 SGDisplayLayer::SGDisplayLayer()
00349 {
00350 ERROR3("Illegal call on default SGDisplayLayer constructor - call the other one!");
00351 TheLayer = NULL;
00352 }
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369 SGDisplayLayer::SGDisplayLayer(Layer *LayerToDisplay)
00370 {
00371 ERROR3IF(LayerToDisplay == NULL,
00372 "SGDisplayLayer - trying to construct me with a NULL parameter is bad");
00373
00374 TheLayer = LayerToDisplay;
00375 }
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392 SGDisplayLayer::~SGDisplayLayer()
00393 {
00394
00395 if (this == LastClickedLayer)
00396 LastClickedLayer = NULL;
00397 }
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427 void SGDisplayLayer::CalculateMyRect(SGFormatInfo *FormatInfo, SGMiscInfo *MiscInfo)
00428 {
00429 INT32 XSize = SG_InfiniteWidth;
00430 INT32 YSize = SG_DefaultSmallIcon;
00431
00432 CalculateFormatRect(FormatInfo, MiscInfo, XSize, YSize);
00433 }
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460 void SGDisplayLayer::CalculateButtonRects(SGMiscInfo *MiscInfo, DocRect *MyRect,
00461 DocRect *VisibleBtn, DocRect *LockedBtn, DocRect *SnapBtn)
00462 {
00463 INT32 ButtonGap = MiscInfo->PixelSize * 2;
00464 INT32 ButtonSize = MiscInfo->PixelSize * 16;
00465
00466
00467 *VisibleBtn = *MyRect;
00468 VisibleBtn->hi.x = VisibleBtn->lo.x + ButtonSize;
00469
00470 INT32 Excess = VisibleBtn->Height() - ButtonSize;
00471 Excess = GridLock(MiscInfo, Excess / 2);
00472 VisibleBtn->lo.y += Excess;
00473 VisibleBtn->hi.y = VisibleBtn->lo.y + ButtonSize;
00474
00475 MyRect->lo.x = VisibleBtn->hi.x + ButtonGap;
00476
00477
00478 *LockedBtn = *MyRect;
00479 LockedBtn->hi.x = LockedBtn->lo.x + ButtonSize;
00480 LockedBtn->lo.y = VisibleBtn->lo.y;
00481 LockedBtn->hi.y = VisibleBtn->hi.y;
00482
00483 MyRect->lo.x = LockedBtn->hi.x + ButtonGap;
00484
00485 #if DO_SNAP_BUTTON
00486 if (SnapBtn != NULL)
00487 {
00488 *SnapBtn = *MyRect;
00489 SnapBtn->hi.x = SnapBtn->lo.x + ButtonSize;
00490 SnapBtn->lo.y = VisibleBtn->lo.y;
00491 SnapBtn->hi.y = VisibleBtn->hi.y;
00492
00493 MyRect->lo.x = SnapBtn->hi.x + ButtonGap;
00494 }
00495 #else
00496
00497 if (SnapBtn != NULL)
00498 *SnapBtn = *LockedBtn;
00499 #endif
00500
00501
00502
00503 GridLockRect(MiscInfo, VisibleBtn);
00504 GridLockRect(MiscInfo, LockedBtn);
00505 if (SnapBtn != NULL)
00506 GridLockRect(MiscInfo, SnapBtn);
00507 GridLockRect(MiscInfo, MyRect);
00508 }
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533 void SGDisplayLayer::HandleRedraw(SGRedrawInfo *RedrawInfo, SGMiscInfo *MiscInfo)
00534 {
00535 StartRendering(RedrawInfo, MiscInfo);
00536
00537 DocRect MyRect(FormatRect);
00538
00539 RenderRegion *Renderer = RedrawInfo->Renderer;
00540
00541
00542
00543
00544 Renderer->SetLineWidth(0);
00545 Renderer->SetLineColour(RedrawInfo->Transparent);
00546 DocColour fill(191, 191, 191);
00547 Renderer->SetFillColour(fill);
00548
00549
00550
00551
00552
00553
00554
00555 DocRect VisibleBtn;
00556 DocRect LockedBtn;
00557 DocRect SnapBtn;
00558
00559 CalculateButtonRects(MiscInfo, &MyRect, &VisibleBtn, &LockedBtn, &SnapBtn);
00560
00561
00562 BOOL ActiveAndVisEd = (GetDisplayedLayer()->IsActive() && Layer::ActiveLayerVisibleAndEditable);
00563 BOOL Visible = GetDisplayedLayer()->IsVisible();
00564 BOOL Locked = GetDisplayedLayer()->IsLocked();
00565 BOOL Guide = GetDisplayedLayer()->IsGuide();
00566 Document* pDoc = (Document*)GetDisplayedLayer()->FindOwnerDoc();
00567
00568 ERROR3IF(pDoc == NULL,"Displayed layer doesn't have an owner doc");
00569 if (pDoc == NULL) return;
00570
00571
00572 if (Visible)
00573 {
00574 if (!Guide && (ActiveAndVisEd || pDoc->IsAllVisible()))
00575 DrawBitmap(Renderer, &VisibleBtn, _R(IDB_LGAL_TICKFORCED));
00576 else
00577 DrawBitmap(Renderer, &VisibleBtn, _R(IDB_LGAL_TICKON));
00578 }
00579 else
00580 DrawBitmap(Renderer, &VisibleBtn, _R(IDB_LGAL_TICKOFF));
00581
00582
00583 if (!Locked)
00584 {
00585 if (ActiveAndVisEd || pDoc->IsMultilayer())
00586 DrawBitmap(Renderer, &LockedBtn, _R(IDB_LGAL_TICKFORCED));
00587 else
00588 DrawBitmap(Renderer, &LockedBtn, _R(IDB_LGAL_TICKON));
00589 }
00590 else
00591 DrawBitmap(Renderer, &LockedBtn, _R(IDB_LGAL_TICKOFF));
00592
00593 #if DO_SNAP_BUTTON
00594
00595 if (Snap)
00596 {
00597 if (FALSE)
00598 DrawBitmap(Renderer, &SnapBtn, _R(IDB_LGAL_TICKFORCED));
00599 else
00600 DrawBitmap(Renderer, &SnapBtn, _R(IDB_LGAL_TICKON));
00601 }
00602 else
00603 DrawBitmap(Renderer, &SnapBtn, _R(IDB_LGAL_TICKOFF));
00604 #endif
00605
00606 Layer* pLayer = GetDisplayedLayer();
00607 ERROR3IF(pLayer == NULL, "I'm displaying a NULL layer? Serious screwup has occurred!");
00608 if (pLayer == NULL)
00609 return;
00610
00611 DocColour Foreground = RedrawInfo->Foreground;
00612 DocColour Background = RedrawInfo->Background;
00613 DocColour SelForeground = RedrawInfo->SelForeground;
00614 DocColour SelBackground = RedrawInfo->SelBackground;
00615
00616 if (pLayer->IsGuide())
00617 {
00618 Foreground = DocColour(COLOUR_RED);
00619 SelBackground = DocColour(COLOUR_RED);
00620 }
00621
00622 if (pLayer->IsPageBackground())
00623 {
00624 Foreground = DocColour(COLOUR_MIDGREY);
00625 SelBackground = DocColour(COLOUR_MIDGREY);
00626 }
00627
00628
00629 if (Flags.Selected)
00630 {
00631
00632
00633 Renderer->SetFillColour(SelBackground);
00634 Renderer->DrawRect(&MyRect);
00635 Renderer->SetFixedSystemTextColours(&SelForeground,&SelBackground);
00636 }
00637 else
00638 Renderer->SetFixedSystemTextColours(&Foreground, &Background);
00639
00640 MyRect.lo.x += SG_GapBeforeText;
00641
00642
00643 String_256 MyText = pLayer->GetLayerID();
00644 Renderer->DrawFixedSystemText(&MyText, MyRect);
00645
00646 StopRendering(RedrawInfo, MiscInfo);
00647 }
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680 void SGDisplayLayer::ChangeRangeState(SGDisplayLayer *Start, SGDisplayLayer *End,
00681 BOOL Range, INT32 WhichButton, SGMiscInfo *MiscInfo)
00682 {
00683 ERROR3IF(Start == NULL || MiscInfo == NULL, "Illegal NULL params");
00684
00685 SuperGallery *ParentGallery = GetParentGallery();
00686 ERROR3IF(ParentGallery == NULL, "No parent gallery?! Weird!");
00687
00688
00689 BOOL NewState = TRUE;
00690 switch (WhichButton)
00691 {
00692 case 0:
00693 NewState = !(GetDisplayedLayer()->GetVisibleFlagState());
00694 break;
00695
00696 case 1:
00697 NewState = !(GetDisplayedLayer()->GetLockedFlagState());
00698 break;
00699
00700 case 2:
00701 #if DO_SNAP_BUTTON
00702
00703 NewState = !(GetDisplayedLayer()->GetVisibleFlagState());
00704 #endif
00705 break;
00706
00707 default:
00708 ERROR3("Illegal WhichButton parameter to SGDisplayLayer::ChangeRangeState (must be 0..2)");
00709 break;
00710 }
00711
00712
00713
00714 SGDisplayLayer *Ptr = NULL;
00715
00716 if (!Range || End == NULL)
00717 End = Start;
00718
00719 BOOL FoundStart = FALSE;
00720 BOOL FoundEnd = FALSE;
00721 BOOL MustSwap = FALSE;
00722
00723 Ptr = (SGDisplayLayer *) (Start->GetParent()->GetChild());
00724 while (Ptr != NULL)
00725 {
00726 if (Ptr == Start)
00727 FoundStart = TRUE;
00728
00729 if (Ptr == End)
00730 {
00731 FoundEnd = TRUE;
00732 MustSwap = !FoundStart;
00733 }
00734
00735 Ptr = (SGDisplayLayer *) Ptr->GetNext();
00736 }
00737
00738 if (!FoundStart)
00739 {
00740 ERROR3("Start node not found");
00741 return;
00742 }
00743
00744 if (!FoundEnd)
00745 End = Start;
00746
00747 if (MustSwap)
00748 {
00749 Ptr = Start;
00750 Start = End;
00751 End = Ptr;
00752 }
00753
00754
00755
00756 Ptr = Start;
00757
00758 while (Ptr != NULL)
00759 {
00760 DocRect MyRect(Ptr->FormatRect);
00761 DocRect VisibleBtn;
00762 DocRect LockedBtn;
00763 DocRect SnapBtn;
00764 Ptr->CalculateButtonRects(MiscInfo, &MyRect, &VisibleBtn, &LockedBtn, &SnapBtn);
00765
00766 switch (WhichButton)
00767 {
00768 case 0:
00769 Ptr->DoChangeState(LAYER_VISIBLE, NewState);
00770 ParentGallery->ForceRedrawOfArea(&VisibleBtn);
00771 break;
00772
00773 case 1:
00774 Ptr->DoChangeState(LAYER_LOCKED, NewState);
00775 ParentGallery->ForceRedrawOfArea(&LockedBtn);
00776 break;
00777
00778 case 2:
00779 #if DO_SNAP_BUTTON
00780
00781 Ptr->DoChangeState(LAYER_VISIBLE, NewState);
00782 ParentGallery->ForceRedrawOfArea(&SnapBtn);
00783 #endif
00784 break;
00785 }
00786
00787 if (Ptr == End)
00788 Ptr = NULL;
00789 else
00790 Ptr = (SGDisplayLayer *) Ptr->GetNext();
00791 }
00792 }
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843 BOOL SGDisplayLayer::HandleEvent(SGEventType EventType, void *EventInfo,
00844 SGMiscInfo *MiscInfo)
00845 {
00846 switch (EventType)
00847 {
00848 case SGEVENT_FORMAT:
00849 {
00850 SGFormatInfo *FormatInfo = GetFormatInfo(EventType, EventInfo);
00851 CalculateMyRect(FormatInfo, MiscInfo);
00852 }
00853 break;
00854
00855
00856 case SGEVENT_REDRAW:
00857 {
00858 DocRect MyRect(FormatRect);
00859 SGRedrawInfo *RedrawInfo = GetRedrawInfo(EventType, EventInfo);
00860
00861 if (IMustRedraw(RedrawInfo))
00862 HandleRedraw(RedrawInfo, MiscInfo);
00863 }
00864 break;
00865
00866
00867 case SGEVENT_MOUSECLICK:
00868 {
00869 SGMouseInfo *Mouse = GetMouseInfo(EventType, EventInfo);
00870
00871 SuperGallery *ParentGallery = GetParentGallery();
00872 ERROR3IF(ParentGallery == NULL, "No parent gallery?! Weird!");
00873
00874 if (FormatRect.ContainsCoord(Mouse->Position))
00875 {
00876 DocRect MyRect(FormatRect);
00877 DocRect VisibleBtn;
00878 DocRect LockedBtn;
00879 DocRect SnapBtn;
00880 Document* pDoc = (Document*)GetDisplayedLayer()->FindOwnerDoc();
00881 ERROR2IF(pDoc == NULL,TRUE,"Can't find owner doc for layer");
00882 ERROR2IF(!IS_A(pDoc,Document),TRUE,"Owner doc is not a Document");
00883
00884 Layer* pLayer = GetDisplayedLayer();
00885 ERROR2IF(pLayer == NULL,TRUE,"GetDisplayedLayer() returned NULL");
00886
00887
00888 BOOL ActiveAndVisEd = (pLayer->IsActive() && Layer::ActiveLayerVisibleAndEditable);
00889
00890
00891 BOOL Guide = pLayer->IsGuide();
00892 BOOL PageBackground = pLayer->IsPageBackground();
00893
00894
00895 CalculateButtonRects(MiscInfo, &MyRect, &VisibleBtn, &LockedBtn, &SnapBtn);
00896
00897
00898 if (!Mouse->MenuClick && VisibleBtn.ContainsCoord(Mouse->Position))
00899 {
00900
00901
00902 if (Guide || (!pDoc->IsAllVisible() && !ActiveAndVisEd))
00903 {
00904 ChangeRangeState(this, LastClickedLayer, Mouse->Extend, 0, MiscInfo);
00905
00906
00907
00908
00909 LastClickedLayer = this;
00910 }
00911 else
00912 {
00913 UINT32 IDS = _R(IDS_LAYER_NOCHANGE_VISIBLE);
00914
00915 if (ActiveAndVisEd)
00916 IDS = _R(IDS_LAYER_NOCHANGE_VISIBLE_ACTIVE);
00917
00918 String_256 msg(IDS);
00919 GetApplication()->UpdateStatusBarText(&msg);
00920 Beep();
00921 }
00922
00923 break;
00924 }
00925
00926
00927 if (!Mouse->MenuClick && LockedBtn.ContainsCoord(Mouse->Position))
00928 {
00929
00930
00931
00932 if (!PageBackground && !pDoc->IsMultilayer() && !ActiveAndVisEd)
00933 {
00934 ChangeRangeState(this, LastClickedLayer, Mouse->Extend, 1, MiscInfo);
00935
00936
00937
00938
00939 LastClickedLayer = this;
00940 }
00941 else
00942 {
00943 UINT32 IDS = _R(IDS_LAYER_NOCHANGE_LOCKED);
00944
00945 if (PageBackground)
00946 IDS = _R(IDS_LAYER_NOCHANGE_BACKGROUND);
00947
00948 if (ActiveAndVisEd)
00949 IDS = _R(IDS_LAYER_NOCHANGE_LOCKED_ACTIVE);
00950
00951 String_256 msg(IDS);
00952 GetApplication()->UpdateStatusBarText(&msg);
00953 Beep();
00954 }
00955
00956 break;
00957 }
00958
00959 #if DO_SNAP_BUTTON
00960
00961 if (!Mouse->MenuClick && SnapBtn.ContainsCoord(Mouse->Position))
00962 {
00963
00964
00965
00966
00967
00968 if (!pDoc->IsAllVisible() && !ActiveAndVisEd)
00969 {
00970 ChangeRangeState(this, LastClickedLayer, Mouse->Extend, 2, MiscInfo);
00971
00972
00973
00974
00975 LastClickedLayer = this;
00976 }
00977 else
00978 {
00979 UINT32 IDS = _R(IDS_LAYER_NOCHANGE_VISIBLE);
00980
00981 if (ActiveAndVisEd)
00982 IDS = _R(IDS_LAYER_NOCHANGE_VISIBLE_ACTIVE);
00983
00984 String_256 msg(IDS);
00985 GetApplication()->UpdateStatusBarText(&msg);
00986 Beep();
00987 }
00988
00989 break;
00990 }
00991 #endif
00992
00993
00994
00995 if (MyRect.ContainsCoord(Mouse->Position))
00996 {
00997
00998
00999 if (!Flags.Selected)
01000 {
01001
01002 Layer* pLayer = GetDisplayedLayer();
01003 LayerSGallery::MakeActiveLayer(pLayer);
01004
01005
01006 ParentGallery->SelectItems(FALSE);
01007
01008
01009
01010
01011
01012
01013
01014 ParentGallery->PaintListNow();
01015
01016
01017 SetSelected(TRUE);
01018
01019
01020 ForceRedrawOfMyself();
01021
01022
01023
01024 ParentGallery->SelectionHasChanged();
01025 }
01026
01027
01028 LastClickedLayer = this;
01029
01030
01031 SGListDragInfo* pDragInfo = new SGListDragInfo(ParentGallery,this,Mouse,Mouse->MenuClick);
01032
01033 if (pDragInfo != NULL)
01034 DragManagerOp::StartDrag(pDragInfo, GetParentGallery()->GetReadWriteWindowID());
01035 }
01036
01037 return(TRUE);
01038 }
01039 }
01040 break;
01041
01042
01043 default:
01044
01045 return(SGDisplayItem::HandleEvent(EventType, EventInfo, MiscInfo));
01046 }
01047
01048
01049 return(FALSE);
01050 }
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070 void SGDisplayLayer::DoChangeState(OpLayerGalReason Reason,BOOL NewState)
01071 {
01072 LayerSGallery* pGal = (LayerSGallery*)GetParentGallery();
01073 ERROR3IF(!IS_A(pGal,LayerSGallery),"Parent not a layer gallery");
01074 if (!IS_A(pGal,LayerSGallery)) return;
01075
01076 Layer* pLayer = GetDisplayedLayer();
01077 pGal->DoChangeLayerState(pLayer,Reason,NewState);
01078 }
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137 void SGDisplayLayer::MoveAfter(SGDisplayNode *NodeToMove)
01138 {
01139 ERROR3IF(NodeToMove == NULL, "Illegal NULL param");
01140 if (NodeToMove == this || NodeToMove == NULL)
01141 return;
01142
01143
01144 SGDisplayItem::MoveAfter(NodeToMove);
01145
01146
01147 MoveLayer(NodeToMove,FALSE,FALSE);
01148 }
01149
01150
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184 void SGDisplayLayer::MoveBefore(SGDisplayNode *NodeToMove)
01185 {
01186 ERROR3IF(NodeToMove == NULL, "Illegal NULL param");
01187 if (NodeToMove == this || NodeToMove == NULL)
01188 return;
01189
01190
01191 SGDisplayItem::MoveBefore(NodeToMove);
01192
01193
01194 MoveLayer(NodeToMove,TRUE,FALSE);
01195 }
01196
01197
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219 void SGDisplayLayer::MoveLayer(SGDisplayNode *NodeToMove,BOOL Before,BOOL ToggleBackground)
01220 {
01221 PORTNOTE("galleries", "disabled frame gallery")
01222 #ifndef EXCLUDE_FROM_XARALX
01223 ERROR3IF((!IS_A(NodeToMove,SGDisplayLayer) && !IS_A(NodeToMove,SGDisplayFrame)),"The node to move is not a SGDisplayLayer");
01224 if (!IS_A(NodeToMove,SGDisplayLayer) && !IS_A(NodeToMove,SGDisplayFrame))
01225 return;
01226 #else
01227 ERROR3IF((!IS_A(NodeToMove,SGDisplayLayer)),"The node to move is not a SGDisplayLayer");
01228 if (!IS_A(NodeToMove,SGDisplayLayer))
01229 return;
01230 #endif
01231
01232 Layer* pLayerToMove = ((SGDisplayLayer*)NodeToMove)->GetDisplayedLayer();
01233 Layer* pThisLayer = GetDisplayedLayer();
01234
01235 Spread* pSpread = pLayerToMove->FindParentSpread();
01236 ERROR3IF(pSpread == NULL,"Parent spread is NULL");
01237 if (pSpread == NULL)
01238 return;
01239
01240 OpLayerGalReason Reason;
01241
01242 if (pLayerToMove == pThisLayer)
01243 {
01244
01245
01246 ERROR3IF(!ToggleBackground,"Not moving the layer OR toggling the background flag, so why did you call?");
01247 if (!ToggleBackground)
01248 return;
01249
01250 Reason = LAYER_TOGGLEBACKGROUND;
01251 }
01252 else
01253 Reason = LAYER_MOVE;
01254
01255
01256 OpLayerGalParam Param(Reason,pSpread);
01257
01258 Param.pLayer = pLayerToMove;
01259 Param.pContextNode = pThisLayer;
01260 Param.MoveRedraw = TRUE;
01261 Param.ToggleBackground = ToggleBackground;
01262 Param.pLayerSGal = (LayerSGallery*)GetParentGallery();
01263
01264 if (Before)
01265 Param.AttDir = NEXT;
01266 else
01267 Param.AttDir = PREV;
01268
01269 OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_LAYERGALCHANGE);
01270 if (pOpDesc != NULL)
01271 pOpDesc->Invoke((OpParam*)&Param);
01272 else
01273 {
01274 ENSURE(FALSE,"Couldn't find OPTOKEN_LAYERGALCHANGE op descriptor");
01275 }
01276 }
01277
01278 #endif // EXCLUDE_GALS
01279
01280
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290 LayerSGallery::LayerSGallery()
01291 {
01292 #ifndef EXCLUDE_GALS
01293 DlgResID = _R(IDD_LAYERSGALLERY);
01294 pSpread = NULL;
01295 pDoc = NULL;
01296 DisplayForeground = NULL;
01297 DisplayBackground = NULL;
01298
01299 OldGuideLayerState = -1;
01300 NewGuideLayerState = -1;
01301 m_NewDocBorn = FALSE;
01302 #endif
01303 }
01304
01305
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317 LayerSGallery::~LayerSGallery()
01318 {
01319 }
01320
01321 #ifndef EXCLUDE_GALS
01322
01323
01324
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346
01347
01348 void LayerSGallery::CreateNewSubtree(Document *ParentDoc, SGDisplayGroup *ExistingGroup)
01349 {
01350 if (DisplayTree == NULL)
01351 return;
01352
01353 TRACEUSER( "Neville", _T("LayerSGallery::CreateNewSubtree Just about to DestroySubtree\n"));
01354
01355
01356 DisplayTree->DestroySubtree();
01357
01358
01359 DisplayForeground = NULL;
01360 DisplayBackground = NULL;
01361
01362 TRACEUSER( "Neville", _T("LayerSGallery::CreateNewSubtree completed DestroySubtree\n"));
01363
01364 if (ParentDoc == NULL)
01365 return;
01366
01367 SGDisplayLayer *DisplayLayer = NULL;
01368
01369 EnsureActiveLayerIntegrity();
01370
01371
01372 DisplayForeground = new SGLayerGroup(this, ParentDoc,NULL,TRUE);
01373 if (DisplayForeground == NULL)
01374 return;
01375 DisplayTree->AddItem(DisplayForeground);
01376
01377
01378 DisplayBackground = new SGLayerGroup(this, ParentDoc,NULL,FALSE);
01379 if (DisplayBackground == NULL)
01380 return;
01381 DisplayTree->AddItem(DisplayBackground);
01382
01383
01384 Spread* pSelSpread = GetSelectedSpread();
01385 ERROR3IF(pSelSpread == NULL,"No selected spread in LayerSGallery");
01386 if (pSelSpread == NULL) return;
01387
01388 Layer* pLayer = pSelSpread->FindLastLayer();
01389 Layer* pActiveLayer = NULL;
01390 Layer* pGuideLayer = NULL;
01391
01392 while (pLayer != NULL)
01393 {
01394
01395 if (pLayer->IsGuide())
01396 pGuideLayer = pLayer;
01397
01398 DisplayLayer = new SGDisplayLayer(pLayer);
01399
01400 if (DisplayLayer != NULL)
01401 {
01402 if (pLayer->IsBackground())
01403 DisplayBackground->AddItem(DisplayLayer);
01404 else
01405 DisplayForeground->AddItem(DisplayLayer);
01406 }
01407
01408 if (pLayer->IsActive())
01409 {
01410 ERROR3IF(pActiveLayer != NULL,
01411 "Found more than one active layer in the selected spread");
01412 pActiveLayer = pLayer;
01413
01414 DisplayLayer->SetSelected(TRUE);
01415 }
01416
01417 pLayer = pLayer->FindPrevLayer();
01418 }
01419
01420
01421 OldGuideLayerState = NewGuideLayerState;
01422
01423 if (pGuideLayer == NULL)
01424 NewGuideLayerState = -1;
01425 else
01426 NewGuideLayerState = pGuideLayer->IsVisible();
01427
01428 if (IsVisible())
01429 {
01430 SetBoolGadgetSelected(_R(IDC_BTN_MULTILAYER),!(ParentDoc->IsMultilayer() == 0));
01431 SetBoolGadgetSelected(_R(IDC_BTN_ALLVISIBLE),!(ParentDoc->IsAllVisible() == 0));
01432 }
01433
01434 TRACEUSER( "Neville", _T("LayerSGallery::CreateNewSubtree exit\n"));
01435 }
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454 BOOL LayerSGallery::PreCreate(void)
01455 {
01456 NewSelectedSpread();
01457
01458
01459 if (DisplayTree == NULL)
01460 {
01461 DisplayTree = new SGDisplayRootScroll(this);
01462 if (DisplayTree == NULL)
01463 return(FALSE);
01464 }
01465
01466
01467
01468
01469 CreateNewSubtree(Document::GetSelected());
01470
01471 return(TRUE);
01472 }
01473
01474
01475
01476
01477
01478
01479
01480
01481
01482
01483
01484
01485
01486
01487
01488
01489
01490
01491
01492 BOOL LayerSGallery::PostCreate(void)
01493 {
01494 Document *ParentDoc = Document::GetSelected();
01495 if (ParentDoc != NULL)
01496 {
01497 SetBoolGadgetSelected(_R(IDC_BTN_MULTILAYER),!(ParentDoc->IsMultilayer() == 0));
01498 SetBoolGadgetSelected(_R(IDC_BTN_ALLVISIBLE),!(ParentDoc->IsAllVisible() == 0));
01499 }
01500
01501 EnableGadget(_R(IDC_GALLERY_COPY),ParentDoc != NULL && !IsSelectedItemGuideLayer());
01502
01503 return(TRUE);
01504 }
01505
01506
01507
01508
01509
01510
01511
01512
01513
01514
01515
01516
01517
01518
01519
01520
01521
01522
01523
01524
01525
01526
01527 BOOL LayerSGallery::ApplyAction(SGActionType Action)
01528 {
01529
01530 if (DisplayTree == NULL)
01531 return(FALSE);
01532
01533
01534 Document *SelectedDoc = Document::GetSelected();
01535 SGDisplayGroup *DocumentGroup = DisplayTree->FindSubtree(this, SelectedDoc, NULL);
01536 SGDisplayLayer *FirstSelected = NULL;
01537
01538 if (DocumentGroup != NULL)
01539 FirstSelected = (SGDisplayLayer *) DocumentGroup->FindNextSelectedItem(NULL);
01540
01541
01542 switch(Action)
01543 {
01544 case SGACTION_CREATE:
01545 DoCreateNewItem();
01546 break;
01547
01548 case SGACTION_EDIT:
01549 DoChangeName();
01550 break;
01551
01552 case SGACTION_DELETE:
01553 if (PrepareToDelete())
01554 DoDeleteSelection();
01555 break;
01556
01557
01558
01559
01560
01561
01562
01563 default:
01564 return(SuperGallery::ApplyAction(Action));
01565 }
01566
01567 return(TRUE);
01568 }
01569
01570
01571
01572
01573
01574
01575
01576
01577
01578
01579
01580
01581
01582
01583
01584
01585
01586
01587
01588
01589
01590
01591
01592
01593
01594
01595
01596
01597 MsgResult LayerSGallery::Message(Msg* Message)
01598 {
01599 if (IS_OUR_DIALOG_MSG(Message))
01600 {
01601 DialogMsg* Msg = (DialogMsg*)Message;
01602
01603 switch (Msg->DlgMsg)
01604 {
01605 case DIM_CREATE:
01606 SGInit::UpdateGalleryButton(_R(OPTOKEN_DISPLAYLAYERGALLERY), TRUE);
01607 break;
01608
01609 case DIM_CANCEL:
01610 SGInit::UpdateGalleryButton(_R(OPTOKEN_DISPLAYLAYERGALLERY), FALSE);
01611 break;
01612
01613 default:
01614 break;
01615 }
01616 }
01617
01618
01619
01620
01621 if (DisplayTree == NULL)
01622 return(SuperGallery::Message(Message));
01623
01624
01625 if (IS_OUR_DIALOG_MSG(Message))
01626 {
01627 DialogMsg* Msg = (DialogMsg*)Message;
01628 INT32 state;
01629
01630 switch (Msg->DlgMsg)
01631 {
01632 case DIM_LFT_BN_CLICKED:
01633 {
01634
01635 if (FALSE) {}
01636 else if (Msg->GadgetID == _R(IDC_BTN_MULTILAYER))
01637 {
01638 state = GetLongGadgetValue(_R(IDC_BTN_MULTILAYER),0,1);
01639 DoChangeLayerState(NULL,LAYER_MULTILAYER,state);
01640
01641
01642 }
01643 else if (Msg->GadgetID == _R(IDC_BTN_ALLVISIBLE))
01644 {
01645 state = GetLongGadgetValue(_R(IDC_BTN_ALLVISIBLE),0,1);
01646 DoChangeLayerState(NULL,LAYER_ALLVISIBLE,state);
01647
01648
01649 }
01650 else if (Msg->GadgetID == _R(IDC_GALLERY_UPONE))
01651 {
01652 DoMoveLayer(MOVELAYER_UPONE);
01653 }
01654 else if (Msg->GadgetID == _R(IDC_GALLERY_DOWNONE))
01655 {
01656 DoMoveLayer(MOVELAYER_DOWNONE);
01657 }
01658 else if (Msg->GadgetID == _R(IDC_GALLERY_NAME))
01659 {
01660
01661
01662 }
01663 else if (Msg->GadgetID == _R(IDC_GALLERY_PROPERTIES))
01664 {
01665 DoLayerProperties();
01666 }
01667 else if (Msg->GadgetID == _R(IDC_GALLERY_COPY))
01668 {
01669 DoCopyLayer();
01670 }
01671 else if (Msg->GadgetID == _R(IDC_LAYER_MOVE_TO_ACTIVE))
01672 {
01673 DoMoveSelectionToActiveLayer();
01674 }
01675 #ifndef WEBSTER
01676 else if (Msg->GadgetID == _R(IDC_GALLERY_HELP))
01677 {
01678 HelpUserTopic(_R(IDS_HELPPATH_Gallery_Layer));
01679 }
01680 #endif
01681 }
01682 default:
01683 break;
01684 }
01685 }
01686 else if (MESSAGE_IS_A(Message, OpMsg))
01687 {
01688 switch (((OpMsg*)Message)->MsgType)
01689 {
01690 case OpMsg::AFTER_UNDO:
01691 case OpMsg::AFTER_REDO:
01692 EnsureSelSpreadSelectionIntegrity();
01693 break;
01694 default:
01695 break;
01696 }
01697 }
01698 else if (MESSAGE_IS_A(Message, SpreadMsg))
01699 {
01700 SpreadMsg* pSpreadMsg = (SpreadMsg*) Message;
01701
01702 switch (pSpreadMsg->Reason)
01703 {
01704 case SpreadMsg::SELCHANGED:
01705 NewSelectedSpread(pSpreadMsg->pNewSpread);
01706 if (pDoc != NULL && IsVisible())
01707 {
01708 TRACEUSER( "Neville", _T("SpreadMsg::SELCHANGED CreateNewSubtree\n"));
01709 CreateNewSubtree(pDoc);
01710 ForceRedrawOfList();
01711 }
01712 break;
01713
01714
01715 case SpreadMsg::LAYERCHANGES:
01716 if (IsVisible())
01717 {
01718 if (pSpreadMsg->pNewSpread == pSpread)
01719 {
01720 if (pSpread->FindFirstLayer() != NULL)
01721 {
01722 EnsureActiveLayerIntegrity();
01723 if (pDoc != NULL && IsVisible())
01724 {
01725 TRACEUSER( "Neville", _T("SpreadMsg::LAYERCHANGES CreateNewSubtree\n"));
01726 CreateNewSubtree(pDoc);
01727 ForceRedrawOfList();
01728 }
01729 }
01730 }
01731 }
01732 else
01733 {
01734 if (pSpreadMsg->pNewSpread->FindFirstLayer() != NULL)
01735 {
01736 pSpread = pSpreadMsg->pNewSpread;
01737 EnsureActiveLayerIntegrity();
01738 }
01739 }
01740 break;
01741 default:
01742 break;
01743 }
01744 }
01745 else if (MESSAGE_IS_A(Message, DocChangingMsg))
01746 {
01747 DocChangingMsg *Msg = (DocChangingMsg *) Message;
01748 switch (Msg->State)
01749 {
01750 case DocChangingMsg::TITLECHANGED:
01751
01752
01753
01754
01755
01756
01757
01758 ForceRedrawOfList();
01759 break;
01760
01761
01762 case DocChangingMsg::SELCHANGED:
01763 {
01764 if (Msg->pNewDoc == NULL)
01765 {
01766
01767
01768 TRACEUSER( "Neville", _T("DocChangingMsg::SELCHANGED CreateNewSubtree\n"));
01769 CreateNewSubtree(NULL);
01770 ForceRedrawOfList();
01771 }
01772 else
01773 {
01774 #ifdef WEBSTER
01775
01776 ShadeGallery(FALSE);
01777 #else
01778
01779 if ( !GetNewDocBorn() )
01780 {
01781
01782 BOOL LayerMode = FALSE;
01783
01784
01785 Document* pDoc = Msg->pNewDoc;
01786
01787 if(pDoc)
01788 {
01789
01790 LayerMode = IsLayerMode(pDoc);
01791
01792
01793
01794 if( !LayerMode && IsVisible() )
01795 {
01796
01797 if( CloseLayerGallery() )
01798 {
01799
01800 OpenFrameGallery();
01801 }
01802 }
01803 }
01804 }
01805
01806
01807 if(IsVisible())
01808 {
01809
01810 ShadeGallery(FALSE);
01811 }
01812
01813 #endif
01814 }
01815 break;
01816 }
01817 #ifndef WEBSTER
01818 case DocChangingMsg::BORN:
01819 {
01820
01821
01822
01823
01824
01825
01826
01827 if( IsVisible() )
01828 {
01829
01830
01831 SetNewDocBorn(TRUE);
01832 }
01833 break;
01834 }
01835
01836 case DocChangingMsg::BORNANDSTABLE:
01837 {
01838
01839 BOOL LayerMode = FALSE;
01840
01841
01842
01843 Document* pChangingDoc = Msg->pChangingDoc;
01844
01845 if(pChangingDoc)
01846 {
01847
01848 LayerMode = IsLayerMode(pChangingDoc);
01849
01850
01851
01852 if( !LayerMode && IsVisible() )
01853 {
01854
01855 if(CloseLayerGallery())
01856 {
01857
01858 OpenFrameGallery();
01859
01860
01861 SetNewDocBorn(FALSE);
01862 }
01863 }
01864 }
01865 break;
01866 }
01867
01868 case DocChangingMsg::KILLED:
01869 case DocChangingMsg::ABOUTTODIE:
01870 {
01871
01872 SetNewDocBorn(FALSE);
01873 break;
01874 }
01875
01876 #endif
01877 }
01878 }
01879
01880
01881 else if (MESSAGE_IS_A(Message, DocViewMsg))
01882 {
01883 DocViewMsg *Msg = (DocViewMsg *) Message;
01884 switch (Msg->State)
01885 {
01886 case DocViewMsg::SELABOUTTOCHANGE:
01887 OldGuideLayerState = GetGuideLayerState(Msg->pNewDocView);
01888 break;
01889
01890 case DocViewMsg::SELCHANGED:
01891 {
01892 if (IsVisible())
01893 {
01894 NewGuideLayerState = GetGuideLayerState(Msg->pNewDocView);
01895 if (OldGuideLayerState != NewGuideLayerState)
01896 {
01897 TRACEUSER( "Neville", _T("DocViewMsg::SELCHANGED CreateNewSubtree\n"));
01898 CreateNewSubtree(Msg->pNewDocView ? Msg->pNewDocView->GetDoc() : NULL);
01899 ForceRedrawOfList();
01900 }
01901 }
01902 }
01903 break;
01904 default:
01905 break;
01906 }
01907 }
01908 else if (MESSAGE_IS_A(Message, LayerMsg))
01909 {
01910 LayerMsg *pMsg = (LayerMsg *) Message;
01911
01912 switch ( pMsg->Reason )
01913 {
01914
01915 case LayerMsg::ACTIVE_LAYER_CHANGED:
01916 {
01917 EnableGadget(_R(IDC_GALLERY_COPY),pMsg->pNewLayer != NULL && !pMsg->pNewLayer->IsGuide());
01918 }
01919 break;
01920
01921
01922
01923 case LayerMsg::LAYER_VISIBILITY_CHANGED:
01924 {
01925 ForceRedrawOfList();
01926 }
01927 break;
01928
01929
01930 case LayerMsg::UPDATE_ACTIVE_LAYER:
01931 {
01932
01933
01934 SGDisplayLayer *pDisplayItem = NULL;
01935 if (DisplayForeground != NULL)
01936 pDisplayItem = GetSelectedLayerGalItem();
01937 if (pDisplayItem != NULL)
01938 {
01939 if (pDisplayItem->GetDisplayedLayer() != pMsg->pNewLayer)
01940 {
01941 Layer* pNewActiveLayer = pMsg->pNewLayer;
01942
01943 SGDisplayLayer *pWantedDispLayer = NULL;
01944 SGDisplayLayer *pDispLayer = ((SGDisplayLayer *) DisplayForeground->GetChild());
01945 while (pDispLayer != NULL)
01946 {
01947 if (pDispLayer->GetDisplayedLayer() == pNewActiveLayer)
01948 pWantedDispLayer = pDispLayer;
01949 pDispLayer = (SGDisplayLayer *) pDispLayer->GetNext();
01950 }
01951
01952
01953 if (pWantedDispLayer)
01954 {
01955
01956 SelectItems(FALSE);
01957
01958 pWantedDispLayer->SetSelected(TRUE);
01959 }
01960 }
01961 }
01962 }
01963 break;
01964 default:
01965 break;
01966 }
01967 }
01968
01969 return(SuperGallery::Message(Message));
01970 }
01971
01972
01973
01974
01975
01976
01977
01978
01979
01980
01981
01982
01983
01984
01985
01986
01987
01988
01989
01990 INT32 LayerSGallery::GetGuideLayerState(DocView* pDocView)
01991 {
01992 Spread* pSelSpread = GetSelectedSpread();
01993
01994 if (pSelSpread != NULL)
01995 {
01996 Layer* pLayer = pSelSpread->FindFirstGuideLayer();
01997 if (pLayer != NULL)
01998 return (pLayer->IsVisible(pDocView));
01999 }
02000
02001 return -1;
02002 }
02003
02004
02005
02006
02007
02008
02009
02010
02011
02012
02013
02014
02015
02016
02017
02018
02019
02020
02021 void LayerSGallery::NewSelectedSpread(Spread* pNewSelSpread)
02022 {
02023 if (pNewSelSpread == NULL)
02024 pSpread = Document::GetSelectedSpread();
02025 else
02026 pSpread = pNewSelSpread;
02027
02028 pDoc = Document::GetSelected();
02029 }
02030
02031
02032
02033
02034
02035
02036
02037
02038
02039
02040
02041
02042
02043
02044
02045
02046
02047
02048
02049
02050 void LayerSGallery::EnsureSelSpreadSelectionIntegrity()
02051 {
02052 if (pSpread == NULL) return;
02053
02054
02055 Layer* pLayer = pSpread->FindFirstLayer();
02056
02057 while (pLayer != NULL)
02058 {
02059
02060 if (!pLayer->IsVisible() || pLayer->IsLocked())
02061 NodeRenderableInk::DeselectAllOnLayer(pLayer);
02062
02063 pLayer = pLayer->FindNextLayer();
02064 }
02065 }
02066
02067 #endif // EXCLUDE_GALS
02068
02069
02070
02071
02072
02073
02074
02075
02076
02077
02078
02079
02080
02081
02082
02083 void LayerSGallery::ForceRedrawLayer(Document* pDoc,Layer* pLayer)
02084 {
02085 Spread* pSpread = pLayer->FindParentSpread();
02086
02087 if (pSpread != NULL)
02088 {
02089 DocRect rect = pLayer->GetUnionBlobBoundingRect();
02090 pDoc->ForceRedraw(pSpread, rect, FALSE, pLayer);
02091
02092 if (pLayer->IsGuide())
02093 {
02094 Node* pNode = pLayer->FindFirstChild(CC_RUNTIME_CLASS(NodeGuideline));
02095 while (pNode != NULL)
02096 {
02097 rect = ((NodeGuideline*)pNode)->GetRenderRect();
02098 pDoc->ForceRedraw(pSpread, rect, FALSE, pLayer);
02099 pNode = pNode->FindNext(CC_RUNTIME_CLASS(NodeGuideline));
02100 }
02101 }
02102 }
02103 }
02104
02105
02106
02107
02108
02109
02110
02111
02112
02113
02114
02115
02116
02117
02118
02119
02120
02121
02122
02123
02124 void LayerSGallery::SetActive(Document* pDoc,Layer* pLayer,BOOL state)
02125 {
02126
02127 BOOL ClearSelection = FALSE;
02128
02129
02130 BOOL PrevVisibleState = pLayer->IsVisible();
02131 BOOL PrevLockedState = pLayer->IsLocked();
02132
02133
02134 pLayer->SetActive(state);
02135
02136
02137 BOOL PostVisibleState = pLayer->IsVisible();
02138 BOOL PostLockedState = pLayer->IsLocked();
02139
02140 if (PrevVisibleState != PostVisibleState)
02141 {
02142
02143 LayerSGallery::ForceRedrawLayer(pDoc,pLayer);
02144
02145
02146 ClearSelection = (ClearSelection || !PostVisibleState);
02147 }
02148
02149
02150 if (PrevLockedState != PostLockedState)
02151 ClearSelection = (ClearSelection || PostLockedState);
02152
02153
02154 if (ClearSelection)
02155 NodeRenderableInk::DeselectAllOnLayer(pLayer);
02156 }
02157
02158
02159
02160
02161
02162
02163
02164
02165
02166
02167
02168
02169
02170
02171
02172
02173
02174
02175
02176
02177
02178
02179 void LayerSGallery::MakeActiveLayer(Layer* pNewActiveLayer, BOOL TellAll)
02180 {
02181 Spread* pSpread = pNewActiveLayer->FindParentSpread();
02182 ERROR3IF(pSpread == NULL,"Eh up, the layer has no parent spread");
02183 if (pSpread == NULL) return;
02184
02185 Document *pDoc = pSpread->FindParentDocument();
02186 if (pDoc == NULL) return;
02187
02188 {
02189
02190 Layer* pLayer = pSpread->FindFirstLayer();
02191 while (pLayer != NULL)
02192 {
02193 if (pLayer->IsActive() && pLayer != pNewActiveLayer)
02194 LayerSGallery::SetActive(pDoc,pLayer,FALSE);
02195
02196 pLayer = pLayer->FindNextLayer();
02197 }
02198 }
02199
02200
02201 if (!pNewActiveLayer->IsActive())
02202 LayerSGallery::SetActive(pDoc,pNewActiveLayer,TRUE);
02203
02204 #if defined(EXCLUDE_FROM_RALPH)
02205
02206 #else
02207 if (TellAll)
02208 BROADCAST_TO_ALL(LayerMsg(pNewActiveLayer,LayerMsg::ACTIVE_LAYER_CHANGED));
02209 #endif
02210 }
02211
02212
02213
02214
02215
02216
02217
02218
02219
02220
02221
02222
02223
02224
02225
02226
02227
02228
02229
02230
02231 void LayerSGallery::EnsureActiveLayerIntegrity(Spread* pSpread,Layer** ppActiveLayer)
02232 {
02233 if (pSpread == NULL) return;
02234
02235
02236 Layer* pFirstLayer = pSpread->FindFirstLayer();
02237
02238
02239 Layer* pActiveLayer = NULL;
02240
02241
02242 Layer* pLayer = pFirstLayer;
02243
02244 INT32 ActiveLayers = 0;
02245
02246 while (pLayer != NULL && pActiveLayer == NULL)
02247 {
02248 if (pLayer->IsActive())
02249 {
02250 ActiveLayers++;
02251 pActiveLayer = pLayer;
02252 }
02253
02254 pLayer = pLayer->FindNextLayer();
02255 }
02256
02257
02258
02259
02260
02261 if (pActiveLayer == NULL)
02262
02263 pActiveLayer = pSpread->FindLastLayer();
02264
02265
02266
02267
02268 if ((pActiveLayer != NULL) )
02269 LayerSGallery::MakeActiveLayer(pActiveLayer);
02270
02271
02272 if (ppActiveLayer != NULL)
02273 *ppActiveLayer = pActiveLayer;
02274 }
02275
02276
02277
02278
02279
02280
02281
02282
02283
02284
02285
02286
02287
02288
02289
02290
02291
02292
02293
02294 void LayerSGallery::MakeTopLayerActive(Spread* pSpread)
02295 {
02296
02297 if (pSpread == NULL)
02298 return;
02299
02300
02301
02302 Layer* pLayer = pSpread->FindLastLayer();
02303 if (pLayer != NULL)
02304 MakeActiveLayer(pLayer);
02305 }
02306
02307
02308
02309
02310
02311
02312
02313
02314
02315
02316
02317
02318
02319
02320
02321
02322
02323
02324
02325
02326
02327 String_256 LayerSGallery::CreateUniqueLayerID(Spread* pSpread)
02328 {
02329 if (pSpread == NULL) return String_256("");
02330
02331 String_256 UniqueLayerID;
02332 INT32 NumLayers = 0;
02333
02334 Layer* pLayer = pSpread->FindFirstLayer();
02335
02336
02337 while (pLayer != NULL)
02338 {
02339
02340 if(!pLayer->IsGuide())
02341 {
02342 NumLayers++;
02343 }
02344 pLayer = pLayer->FindNextLayer();
02345 }
02346
02347 INT32 NewLayerNum = NumLayers+1;
02348
02349 BOOL Unique;
02350 do
02351 {
02352
02353
02354 UniqueLayerID.MakeMsg(_R(IDS_SGLAYER_LAYER_NUM), NewLayerNum);
02355
02356
02357 Unique = TRUE;
02358 pLayer = pSpread->FindFirstLayer();
02359 while (pLayer != NULL)
02360 {
02361 if (UniqueLayerID == pLayer->GetLayerID())
02362 {
02363 Unique = FALSE;
02364
02365
02366 NewLayerNum++;
02367 break;
02368 }
02369 pLayer = pLayer->FindNextLayer();
02370 }
02371
02372 } while (!Unique);
02373
02374 return(UniqueLayerID);
02375 }
02376
02377 #ifndef EXCLUDE_GALS
02378
02379
02380
02381
02382
02383
02384
02385
02386
02387
02388
02389
02390
02391
02392
02393
02394
02395 BOOL LayerSGallery::CheckVarsAreValid()
02396 {
02397 return ((pSpread != NULL) && (pDoc != NULL));
02398 }
02399
02400
02401
02402
02403
02404
02405
02406
02407
02408
02409
02410
02411
02412
02413
02414
02415 void LayerSGallery::EnsureActiveLayerIntegrity()
02416 {
02417 LayerSGallery::EnsureActiveLayerIntegrity(pSpread);
02418 }
02419
02420
02421
02422
02423
02424
02425
02426
02427
02428
02429
02430
02431
02432
02433
02434
02435
02436 SGDisplayLayer *LayerSGallery::GetSelectedLayerGalItem()
02437 {
02438 SGDisplayLayer* pDispLayer = NULL;
02439
02440 if (CheckVarsAreValid())
02441 {
02442 ERROR3IF(DisplayForeground == NULL || DisplayBackground == NULL,"Fore and/or background group(s) are/is NULL");
02443 if (DisplayForeground == NULL || DisplayBackground == NULL)
02444 return NULL;
02445
02446
02447 pDispLayer = ((SGDisplayLayer *) DisplayForeground->FindNextSelectedItem(NULL));
02448
02449
02450 if (pDispLayer == NULL)
02451 pDispLayer = ((SGDisplayLayer *) DisplayBackground->FindNextSelectedItem(NULL));
02452
02453 ERROR3IF(pDispLayer == NULL,"Can't find the selected layer item in the layer gallery");
02454
02455
02456
02457
02458 }
02459
02460 return(pDispLayer);
02461 }
02462
02463
02464
02465
02466
02467
02468
02469
02470
02471
02472
02473
02474
02475
02476
02477
02478
02479
02480
02481
02482
02483 BOOL LayerSGallery::HasLayerGotChildren(Layer* pLayer)
02484 {
02485 ERROR2IF(pLayer == NULL,FALSE,"HasLayerGotChildren bad param!");
02486 return pLayer->HasLayerGotRenderableChildren();
02487 }
02488
02489
02490
02491
02492
02493
02494
02495
02496
02497
02498
02499
02500
02501
02502
02503 BOOL LayerSGallery::PrepareToDelete(void)
02504 {
02505 SGDisplayLayer* pLayerGalItem = GetSelectedLayerGalItem();
02506
02507 if (pLayerGalItem != NULL)
02508 {
02509 if (HasLayerGotChildren(pLayerGalItem->GetDisplayedLayer()) != FALSE)
02510 {
02511
02512 INT32 ButtonPressed = AskQuestion(_R(IDS_LAYER_CONSTAINSOBJECTS),
02513 _R(IDS_LAYER_DELETE), _R(IDB_CANCEL), 0, 0,
02514 2, 2);
02515
02516 if (ButtonPressed == 1)
02517 return(TRUE);
02518
02519
02520 return(FALSE);
02521 }
02522 else
02523 return(TRUE);
02524 }
02525
02526 return (pLayerGalItem != NULL);
02527 }
02528
02529
02530
02531
02532
02533
02534
02535
02536
02537
02538
02539
02540
02541
02542
02543
02544
02545
02546
02547
02548
02549 BOOL LayerSGallery::DoDeleteSelection(void)
02550 {
02551 SGDisplayLayer* pLayerGalItem = GetSelectedLayerGalItem();
02552
02553 if (pLayerGalItem != NULL)
02554 {
02555 OpLayerGalParam Param(LAYER_DELETE,pSpread);
02556 Param.pLayer = pLayerGalItem->GetDisplayedLayer();
02557
02558 OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_LAYERGALCHANGE);
02559 if (pOpDesc != NULL)
02560 pOpDesc->Invoke((OpParam*)&Param);
02561 else
02562 {
02563 ERROR3("Couldn't find OPTOKEN_LAYERGALCHANGE op descriptor");
02564 }
02565 return (TRUE);
02566 }
02567
02568 return (pLayerGalItem != NULL);
02569 }
02570
02571
02572
02573
02574
02575
02576
02577
02578
02579
02580
02581
02582
02583
02584
02585
02586
02587
02588
02589 void LayerSGallery::DoCreateNewItem(void)
02590 {
02591 if (!CheckVarsAreValid())
02592 return;
02593 LayerDlgParam Param(LAYER_NEW,pSpread,NULL);
02594 LayerNameDlg::StartUp(&Param);
02595
02596 }
02597
02598
02599
02600
02601
02602
02603
02604
02605
02606
02607
02608
02609
02610 void LayerSGallery::DoChangeName()
02611 {
02612 SGDisplayLayer* pLayerGalItem = GetSelectedLayerGalItem();
02613
02614 if (pLayerGalItem != NULL)
02615 {
02616 LayerDlgParam Param(LAYER_CHANGE_NAME,NULL,pLayerGalItem->GetDisplayedLayer());
02617 LayerNameDlg::StartUp(&Param);
02618 }
02619 }
02620
02621
02622
02623
02624
02625
02626
02627
02628
02629
02630
02631
02632
02633
02634
02635
02636
02637 void LayerSGallery::DoCopyLayer()
02638 {
02639 SGDisplayLayer* pLayerGalItem = GetSelectedLayerGalItem();
02640
02641 if (pLayerGalItem != NULL)
02642 {
02643 LayerDlgParam Param(LAYER_COPY,NULL,pLayerGalItem->GetDisplayedLayer());
02644 LayerNameDlg::StartUp(&Param);
02645 }
02646 }
02647
02648
02649
02650
02651
02652
02653
02654
02655
02656
02657
02658
02659
02660
02661 void LayerSGallery::DoLayerProperties()
02662 {
02663 #ifndef STANDALONE
02664
02665 OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_LAYERPROPERTYTABS);
02666
02667 if (pOpDesc != NULL)
02668 {
02669 String_256 Str;
02670 OpState State = pOpDesc->GetOpsState(&Str);
02671 if (!State.Greyed)
02672 pOpDesc->Invoke();
02673 else
02674 {
02675
02676
02677
02678
02679 LayerPropertyTabs * pTabHandler = LayerPropertyTabsDlg::GetLayerPropertiesTabs();
02680
02681 if (pTabHandler)
02682 {
02683 DialogTabOp* pDlg = pTabHandler->GetTabbedDlg();
02684 if (pDlg != NULL)
02685 pDlg->Open();
02686 }
02687 }
02688 }
02689 #endif
02690 }
02691
02692
02693
02694
02695
02696
02697
02698
02699
02700
02701
02702
02703
02704 void LayerSGallery::DoCreateGuideLayer()
02705 {
02706 #ifndef WEBSTER
02707 OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_GUIDELINE);
02708 ERROR3IF(pOpDesc == NULL,"FindOpDescriptor(OPTOKEN_GUIDELINE) failed");
02709
02710 if (pOpDesc != NULL)
02711 {
02712 OpGuidelineParam GuidelineParam;
02713
02714 GuidelineParam.Method = GUIDELINEOPMETHOD_CREATE_GUIDE_LAYER;
02715
02716 pOpDesc->Invoke(&GuidelineParam);
02717 }
02718 #endif // WEBSTER
02719 }
02720
02721
02722
02723
02724
02725
02726
02727
02728
02729
02730
02731
02732
02733
02734
02735
02736 void LayerSGallery::DoChangeAllVisible(BOOL AllVisible)
02737 {
02738 if (!CheckVarsAreValid()) return;
02739
02740
02741 BOOL PrevAllVisible = pDoc->IsAllVisible();
02742
02743
02744 if (PrevAllVisible == AllVisible) return;
02745
02746 Layer* pLayer = pSpread->FindFirstLayer();
02747
02748 while (pLayer != NULL)
02749 {
02750
02751 if (!pLayer->IsPageBackground())
02752 {
02753 pDoc->SetAllVisible(PrevAllVisible);
02754 BOOL PrevVisible = pLayer->IsVisible();
02755
02756
02757 pDoc->SetAllVisible(AllVisible);
02758 BOOL PostVisible = pLayer->IsVisible();
02759
02760
02761 if (PrevVisible != PostVisible)
02762 {
02763 LayerSGallery::ForceRedrawLayer(pDoc,pLayer);
02764
02765 if (!PostVisible)
02766 NodeRenderableInk::DeselectAllOnLayer(pLayer);
02767 }
02768 }
02769
02770 pLayer = pLayer->FindNextLayer();
02771 }
02772
02773 pDoc->SetAllVisible(AllVisible);
02774
02775
02776 BROADCAST_TO_ALL(LayerMsg(pLayer, LayerMsg::LAYER_VISIBILITY_CHANGED));
02777 }
02778
02779
02780
02781
02782
02783
02784
02785
02786
02787
02788
02789
02790
02791
02792
02793
02794
02795
02796 void LayerSGallery::DoChangeMultilayer(BOOL Multilayer)
02797 {
02798 if (!CheckVarsAreValid()) return;
02799
02800
02801 BOOL PrevMultilayer = pDoc->IsMultilayer();
02802
02803
02804 if (PrevMultilayer == Multilayer) return;
02805
02806 Layer* pLayer = pSpread->FindFirstLayer();
02807 BOOL PrevLocked;
02808 BOOL PostLocked;
02809
02810 while (pLayer != NULL)
02811 {
02812
02813 if (!pLayer->IsPageBackground())
02814 {
02815 pDoc->SetMultilayer(PrevMultilayer);
02816 PrevLocked = pLayer->IsLocked();
02817 pDoc->SetMultilayer(Multilayer);
02818 PostLocked = pLayer->IsLocked();
02819
02820 if ((PrevLocked != PostLocked) && PostLocked)
02821 NodeRenderableInk::DeselectAllOnLayer(pLayer);
02822 }
02823
02824 pLayer = pLayer->FindNextLayer();
02825 }
02826
02827 pDoc->SetMultilayer(Multilayer);
02828 }
02829
02830
02831
02832
02833
02834
02835
02836
02837
02838
02839
02840
02841
02842
02843
02844
02845
02846
02847
02848
02849
02850 void LayerSGallery::DoChangeVisible(Layer* pLayer,BOOL Visible)
02851 {
02852 ERROR3IF(pLayer == NULL,"pLayer == NULL");
02853 if (pLayer == NULL) return;
02854
02855 BOOL PrevVisible = pLayer->IsVisible();
02856 pLayer->SetVisible(Visible);
02857 BOOL PostVisible = pLayer->IsVisible();
02858
02859 if (PrevVisible != PostVisible)
02860 {
02861
02862 LayerSGallery::ForceRedrawLayer(pLayer->FindDocument(), pLayer);
02863
02864
02865 BROADCAST_TO_ALL(LayerMsg(pLayer, LayerMsg::LAYER_VISIBILITY_CHANGED));
02866
02867
02868 if (!PostVisible)
02869 NodeRenderableInk::DeselectAllOnLayer(pLayer);
02870 }
02871 }
02872
02873
02874
02875
02876
02877
02878
02879
02880
02881
02882
02883
02884
02885
02886
02887
02888
02889
02890
02891 void LayerSGallery::DoChangeLocked(Layer* pLayer,BOOL Locked)
02892 {
02893 ERROR3IF(pLayer == NULL,"pLayer == NULL");
02894 if (pLayer == NULL) return;
02895
02896 BOOL PrevLocked = pLayer->IsLocked();
02897 pLayer->SetLocked(Locked);
02898 BOOL PostLocked = pLayer->IsLocked();
02899
02900 if (PrevLocked != PostLocked)
02901 NodeRenderableInk::DeselectAllOnLayer(pLayer);
02902 }
02903
02904
02905
02906
02907
02908
02909
02910
02911
02912
02913
02914
02915
02916
02917
02918
02919 void LayerSGallery::DoChangeLayerStatus(Layer* pLayer, const LayerStatus& NewStatus)
02920 {
02921 if (!CheckVarsAreValid()) return;
02922
02923 OpLayerGalParam Param(LAYER_CHANGE, pSpread);
02924
02925 Param.pLayer = pLayer;
02926 Param.Status = NewStatus;
02927
02928 OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_LAYERGALCHANGE);
02929 if (pOpDesc != NULL)
02930 pOpDesc->Invoke((OpParam*)&Param);
02931 else
02932 {
02933 ENSURE(FALSE,"Couldn't find OPTOKEN_LAYERGALCHANGE op descriptor");
02934 }
02935 }
02936
02937
02938
02939
02940
02941
02942
02943
02944
02945
02946
02947
02948
02949
02950
02951 void LayerSGallery::DoChangeLayerState(Layer* pLayer,OpLayerGalReason Reason,BOOL NewState)
02952 {
02953 if (!CheckVarsAreValid()) return;
02954
02955 OpLayerGalParam Param(Reason, pSpread);
02956
02957 Param.pLayer = pLayer;
02958 Param.NewState = NewState;
02959 Param.pLayerSGal= this;
02960
02961 OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_LAYERGALCHANGE);
02962 if (pOpDesc != NULL)
02963 pOpDesc->Invoke((OpParam*)&Param);
02964 else
02965 {
02966 ERROR3("Couldn't find OPTOKEN_LAYERGALCHANGE op descriptor");
02967 }
02968 }
02969
02970
02971
02972
02973
02974
02975
02976
02977
02978
02979
02980
02981
02982
02983
02984
02985
02986 void LayerSGallery::DoMoveLayer(MoveLayerType Reason)
02987 {
02988 SGDisplayLayer* pLayerGalItem = GetSelectedLayerGalItem();
02989
02990 if (pLayerGalItem != NULL)
02991 {
02992 OpLayerGalParam Param(LAYER_MOVE, pSpread);
02993
02994 Param.pLayer = pLayerGalItem->GetDisplayedLayer();
02995
02996 switch (Reason)
02997 {
02998 case (MOVELAYER_UPONE) :
02999 Param.pContextNode = Param.pLayer->FindNextLayer();
03000 Param.AttDir = NEXT;
03001 break;
03002
03003 case (MOVELAYER_DOWNONE) :
03004 Param.pContextNode = Param.pLayer->FindPrevLayer();
03005 Param.AttDir = PREV;
03006 break;
03007
03008 default:
03009 ENSURE(FALSE,"Unrecognised MoveLayer reason");
03010 break;
03011 }
03012
03013 if (Param.pContextNode != NULL)
03014 {
03015
03016
03017 Param.MoveRedraw = ((Layer*)Param.pContextNode)->IsVisible() &&
03018 Param.pLayer->IsVisible();
03019
03020
03021 Param.MoveRedraw = TRUE;
03022
03023 OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_LAYERGALCHANGE);
03024 if (pOpDesc != NULL)
03025 pOpDesc->Invoke((OpParam*)&Param);
03026 else
03027 {
03028 ENSURE(FALSE,"Couldn't find OPTOKEN_LAYERGALCHANGE op descriptor");
03029 }
03030 }
03031 }
03032 }
03033
03034
03035
03036
03037
03038
03039
03040
03041
03042
03043
03044
03045
03046
03047
03048
03049
03050 BOOL LayerSGallery::IsSelectedItemGuideLayer()
03051 {
03052 SGDisplayLayer* pItem = GetSelectedLayerGalItem();
03053 Layer* pLayer = NULL;
03054
03055 if (pItem != NULL)
03056 pLayer = pItem->GetDisplayedLayer();
03057
03058 if (pLayer != NULL)
03059 return (pLayer->IsGuide());
03060
03061 return TRUE;
03062 }
03063
03064
03065
03066
03067
03068
03069
03070
03071
03072
03073
03074
03075
03076
03077
03078
03079
03080
03081
03082
03083 void LayerSGallery::DoShadeGallery(BOOL ShadeIt)
03084 {
03085 BOOL fEnableMove = FALSE;
03086 OpDescriptor* pDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_MOVE_SEL_TO_ACTIVE_LAYER);
03087 if (pDesc != 0)
03088 {
03089 String_256 str;
03090 OpState os = pDesc->GetOpsState(&str);
03091 fEnableMove = !os.Greyed;
03092 }
03093
03094 EnableGadget(_R(IDC_LAYER_MOVE_TO_ACTIVE), !ShadeIt && fEnableMove);
03095 EnableGadget(_R(IDC_GALLERY_UPONE), !ShadeIt);
03096 EnableGadget(_R(IDC_GALLERY_DOWNONE), !ShadeIt);
03097 EnableGadget(_R(IDC_GALLERY_PROPERTIES), !ShadeIt);
03098 EnableGadget(_R(IDC_GALLERY_COPY), !ShadeIt && !IsSelectedItemGuideLayer());
03099
03100 EnableGadget(_R(IDC_BTN_MULTILAYER), !ShadeIt);
03101 EnableGadget(_R(IDC_BTN_ALLVISIBLE), !ShadeIt);
03102
03103
03104 }
03105
03106
03107
03108
03109
03110
03111
03112
03113
03114
03115
03116
03117
03118
03119
03120
03121
03122
03123
03124
03125
03126
03127
03128
03129
03130
03131
03132
03133
03134
03135
03136
03137
03138
03139
03140
03141
03142
03143
03144
03145
03146
03147 SGDisplayItem *LayerSGallery::CopyDisplayItem(SGDisplayItem *SourceItem,
03148 SGDisplayGroup *DestGroup, SGDisplayItem *TargetPosition)
03149 {
03150 ERROR3IF(SourceItem == NULL || DestGroup == NULL, "Illegal NULL param");
03151 if (SourceItem == NULL || DestGroup == NULL)
03152 return(NULL);
03153
03154 ERROR3IF(!IS_A(DestGroup,SGLayerGroup),"DestGroup is not a SGLayerGroup");
03155 ERROR3IF(!IS_A(SourceItem,SGDisplayLayer),"SourceItem is not a SGDisplayLayer");
03156 if (!IS_A(DestGroup,SGLayerGroup) || !IS_A(SourceItem,SGDisplayLayer))
03157 return(NULL);
03158
03159 SGLayerGroup* pDestLayerGroup = (SGLayerGroup*)DestGroup;
03160 SGDisplayLayer* pSourceLayerItem = (SGDisplayLayer*)SourceItem;
03161
03162 SGDisplayItem* pDestItem = TargetPosition;
03163 BOOL Before = TRUE;
03164
03165 if (pDestItem == NULL)
03166 {
03167 pDestItem = (SGDisplayItem*) pDestLayerGroup->GetChild();
03168 Before = TRUE;
03169
03170 if (pDestItem == NULL)
03171 {
03172 SGDisplayNode* pNode = SourceItem;
03173 while (pNode != NULL)
03174 {
03175 pDestItem = (SGDisplayItem*) pNode;
03176 if (pDestLayerGroup->IsForeground())
03177 pNode = pNode->GetPrevious();
03178 else
03179 pNode = pNode->GetNext();
03180 }
03181
03182 Before = pDestLayerGroup->IsForeground();
03183 }
03184 else
03185 {
03186 SGDisplayItem* pLastDestItem = NULL;
03187 while (pDestItem != NULL)
03188 {
03189 pLastDestItem = pDestItem;
03190 pDestItem = (SGDisplayItem*)(pDestItem->GetNext());
03191 }
03192
03193 pDestItem = pLastDestItem;
03194 Before = FALSE;
03195 }
03196 }
03197
03198 ERROR3IF(pDestItem == NULL,"pDestItem is still NULL");
03199 if (pDestItem == NULL)
03200 return(NULL);
03201
03202
03203 SourceItem->RemoveFromTree();
03204 SuperGallery::InsertCopiedItem(SourceItem, DestGroup, TargetPosition);
03205
03206 if (pDestItem != NULL)
03207 {
03208 ERROR3IF(!IS_A(pDestItem,SGDisplayLayer),"SourceItem is not a SGDisplayLayer");
03209 if (!IS_A(pDestItem,SGDisplayLayer))
03210 return(NULL);
03211
03212 SGDisplayLayer* pDestLayerItem = (SGDisplayLayer*)pDestItem;
03213 pDestLayerItem->MoveLayer(pSourceLayerItem,Before,TRUE);
03214 }
03215
03216 return(SourceItem);
03217 }
03218
03219
03220
03221
03222
03223
03224
03225
03226
03227
03228
03229
03230
03231
03232
03233
03234
03235
03236
03237 BOOL LayerSGallery::InitMenuCommands(void)
03238 {
03239 static BOOL MenusInitialised = FALSE;
03240
03241 BOOL ok = TRUE;
03242
03243 if (!MenusInitialised)
03244 {
03245
03246
03247 ok = ok && InitMenuCommand((StringBase *) &SGCmd_Copy, _R(IDS_SGMENU_COPY));
03248 ok = ok && InitMenuCommand((StringBase *) &SGCmd_Delete, _R(IDS_SGMENU_DELETE));
03249 ok = ok && InitMenuCommand((StringBase *) &SGCmd_New, _R(IDS_NEW_LAYER));
03250 ok = ok && InitMenuCommand((StringBase *) &SGCmd_Create, _R(IDS_CREATE_GUIDE_LAYER));
03251 ok = ok && InitMenuCommand((StringBase *) &SGCmd_Properties,_R(IDS_SGMENU_PROPERTIES));
03252
03253 MenusInitialised = TRUE;
03254 }
03255
03256 return(ok);
03257 }
03258
03259
03260
03261
03262
03263
03264
03265
03266
03267
03268
03269
03270
03271
03272
03273
03274
03275
03276
03277
03278
03279 BOOL LayerSGallery::BuildCommandMenu(GalleryContextMenu *TheMenu, SGMenuID MenuID)
03280 {
03281 BOOL ok = TRUE;
03282
03283 if (MenuID == SGMENU_OVERITEM)
03284 {
03285
03286 SGDisplayLayer* pLayerGalItem = GetSelectedLayerGalItem();
03287
03288 #ifndef STANDALONE
03289
03290 if (pLayerGalItem != NULL)
03291 {
03292
03293
03294
03295
03296 LayerPropertyTabs * pTabHandler = LayerPropertyTabsDlg::GetLayerPropertiesTabs();
03297
03298 if (pTabHandler)
03299 {
03300 pTabHandler->SetCurrentLayer(pLayerGalItem->GetDisplayedLayer());
03301 }
03302 }
03303 #endif
03304 ok = ok && AddCommand(TheMenu, (StringBase *) &SGCmd_New);
03305 ok = ok && AddCommand(TheMenu, (StringBase *) &SGCmd_Copy);
03306 ok = ok && AddCommand(TheMenu, (StringBase *) &SGCmd_Delete,TRUE);
03307 ok = ok && AddCommand(TheMenu, (StringBase *) &SGCmd_Create);
03308 #ifndef STANDALONE
03309 ok = ok && AddCommand(TheMenu, (StringBase *) &SGCmd_Properties);
03310 #endif
03311 }
03312
03313 return(ok);
03314 }
03315
03316
03317
03318
03319
03320
03321
03322
03323
03324
03325
03326
03327
03328
03329
03330
03331
03332
03333
03334
03335
03336
03337
03338
03339
03340
03341
03342
03343
03344 OpState LayerSGallery::GetCommandState(StringBase *CommandID, String_256 *ShadeReason)
03345 {
03346 OpState State;
03347
03348 if (AmShaded)
03349 {
03350 State.Greyed = TRUE;
03351 return(State);
03352 }
03353
03354 if (*CommandID == SGCmd_Copy ||
03355 *CommandID == SGCmd_Delete ||
03356 *CommandID == SGCmd_Properties)
03357 {
03358 SGDisplayLayer* pItem = GetSelectedLayerGalItem();
03359
03360 if (pItem == NULL)
03361 {
03362 State.Greyed = TRUE;
03363 ShadeReason->MakeMsg(_R(IDS_SGSHADE_SINGLECOL));
03364 }
03365 else if (*CommandID == SGCmd_Copy)
03366 State.Greyed = IsSelectedItemGuideLayer();
03367 #ifndef STANDALONE
03368 else if (*CommandID == SGCmd_Properties)
03369 {
03370
03371
03372
03373
03374 LayerPropertyTabs * pTabHandler = LayerPropertyTabsDlg::GetLayerPropertiesTabs();
03375
03376 if (pTabHandler)
03377 State.Greyed = (pTabHandler->GetTabbedDlg() != NULL);
03378 else
03379 State.Greyed = TRUE;
03380 }
03381 #endif
03382 }
03383 else if (*CommandID == SGCmd_Create)
03384 {
03385 Spread* pSpread = Document::GetSelectedSpread();
03386 Layer* pGuideLayer = NULL;
03387
03388 if (pSpread != NULL)
03389 pGuideLayer = pSpread->FindFirstGuideLayer();
03390
03391 State.Greyed = (pGuideLayer != NULL);
03392 }
03393
03394
03395
03396
03397 return(State);
03398 }
03399
03400
03401
03402
03403
03404
03405
03406
03407
03408
03409
03410
03411
03412
03413
03414
03415
03416
03417
03418
03419
03420
03421
03422
03423
03424 void LayerSGallery::DoCommand(StringBase *CommandID)
03425 {
03426 if (*CommandID == SGCmd_Copy)
03427 DoCopyLayer();
03428 else if (*CommandID == SGCmd_New)
03429 DoCreateNewItem();
03430 else if (*CommandID == SGCmd_Delete)
03431 {
03432 if (PrepareToDelete())
03433 DoDeleteSelection();
03434 }
03435 else if (*CommandID == SGCmd_Properties)
03436 DoLayerProperties();
03437 else if (*CommandID == SGCmd_Create)
03438 DoCreateGuideLayer();
03439
03440
03441 }
03442
03443
03444
03445
03446
03447
03448
03449
03450
03451
03452
03453
03454 BOOL LayerSGallery::CloseLayerGallery()
03455 {
03456 SuperGallery* pSuperGallery = SuperGallery::FindSuperGallery(_R(IDD_LAYERSGALLERY));
03457
03458
03459 if (pSuperGallery == NULL)
03460 return FALSE;
03461
03462 if (pSuperGallery->GetRuntimeClass() == CC_RUNTIME_CLASS(LayerSGallery))
03463 {
03464 PORTNOTE("galleries", "Disabled frame gallery")
03465 #ifndef EXCLUDE_FROM_XARALX
03466 GIFAnimationPropertyTabs::SetFrameGalleryOpen(FALSE);
03467 #endif
03468
03469 pSuperGallery->SetVisibility( FALSE );
03470 }
03471 else
03472 {
03473 ERROR3("Got the frame gallery but it's not of the LayerSGallery class");
03474 }
03475
03476 SGInit::UpdateGalleryButton(_R(OPTOKEN_DISPLAYLAYERGALLERY), FALSE);
03477
03478
03479 return TRUE;
03480 }
03481
03482
03483
03484
03485
03486
03487
03488
03489
03490
03491
03492
03493 BOOL LayerSGallery::OpenFrameGallery()
03494 {
03495
03496 OpDescriptor* OpDesc;
03497 OpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_DISPLAYFRAMEGALLERY);
03498
03499
03500 if(!OpDesc)
03501 return FALSE;
03502
03503
03504 OpDesc->Invoke();
03505
03506
03507 return TRUE;
03508 }
03509
03510
03511
03512
03513
03514
03515
03516
03517
03518
03519
03520
03521
03522 BOOL LayerSGallery::IsLayerMode(Document* pDoc)
03523 {
03524 ERROR3IF(pDoc == NULL,"pDoc == NULL");
03525
03526
03527 BOOL LayerMode = TRUE;
03528
03529
03530 Spread* pSpread = pDoc->GetSelectedSpread();
03531
03532
03533 if(pSpread)
03534 {
03535
03536 Layer* pFrameLayer = pSpread->FindFirstFrameLayer();
03537
03538
03539 if (pFrameLayer)
03540 LayerMode = FALSE;
03541 }
03542
03543
03544 return LayerMode;
03545 }
03546
03547
03548
03549
03550
03551
03552
03553
03554
03555
03556
03557
03558
03559
03560
03561
03562 BOOL LayerSGallery::DoMoveSelectionToActiveLayer()
03563 {
03564
03565 OpDescriptor* OpDesc;
03566 OpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_MOVE_SEL_TO_ACTIVE_LAYER);
03567
03568
03569 if(!OpDesc)
03570 return FALSE;
03571
03572
03573 OpDesc->Invoke();
03574
03575
03576 return TRUE;
03577 }
03578
03579
03580
03581
03582 #endif // EXCLUDE_GALS