layergal.cpp

Go to the documentation of this file.
00001 // $Id: layergal.cpp 1282 2006-06-09 09:46:49Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 // The Layers gallery
00099 
00100 /*
00101 */
00102 
00103 #include "camtypes.h"
00104 #include "layergal.h"
00105 
00106 DECLARE_SOURCE("$Revision: 1282 $");
00107 
00108 //#include "ensure.h"
00109 #include "sprdmsg.h"
00110 //#include "markn.h"
00111 //#include "simon.h"
00112 //#include "document.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00113 //#include "docview.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00114 #include "layermgr.h"
00115 //#include "spread.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00116 #include "insertnd.h"
00117 //#include "ink.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00118 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00119 //#include "resource.h"
00120 //#include "barsdlgs.h" 
00121 #include "guides.h" 
00122 #include "nodetxts.h"
00123 #include "textops.h"
00124 #include "bubbleid.h"
00125 #include "ophist.h"
00126 #include "sglayer.h"        // The LayerSGallery class
00127 #include "sginit.h"
00128 
00129 //#include "will2.h"
00130 //#include "galstr.h"           // _R(IDS_DELETEPAGEBACKGROUND)
00131 //#include "prevwres.h"     // _R(IDS_DISPLAY_FRAME_GALLERY) _R(IDD_ANIMATIONBAR) ...
00132 //#include "sgframe.h"      // FrameSGallery
00133 
00134 //#include "frameops.h"     // Frame related ops
00135 //#include "aprps.h"
00136 
00137 #include "nodetxts.h"       //TextStory::SetFocusStory
00138 
00139 #include "layermsg.h"       // LayerMsg::LayerReason::REDRAW_LAYER
00140 //#include "xshelpid.h"     //For the help id
00141 
00142 #define Swap(a,b)       { (a)^=(b), (b)^=(a), (a)^=(b); }
00143 
00144 //-----------------------------------------------------------------------
00145 //-----------------------------------------------------------------------
00146 
00147 CC_IMPLEMENT_DYNCREATE(OpDeletePageBackground,OpLayerGalChange);
00148 CC_IMPLEMENT_DYNCREATE(OpLayerGalChange,UndoableOperation);
00149 CC_IMPLEMENT_DYNCREATE(OpDisplayLayerGallery,Operation);
00150 PORTNOTE("galleries", "disabled frame gallery")
00151 #ifndef EXCLUDE_FROM_XARALX
00152 CC_IMPLEMENT_DYNCREATE(OpDisplayFrameGallery,Operation);
00153 #endif
00154 CC_IMPLEMENT_DYNCREATE(LayerNameDlg, DialogOp)   
00155 CC_IMPLEMENT_DYNCREATE(LayerStateAction,Action)
00156               
00157 const CDlgMode  LayerNameDlg::Mode          = MODAL;   // The dialog is modal
00158 const INT32     LayerNameDlg::IDD           = _R(IDD_LAYER_NAME);
00159 BOOL            LayerNameDlg::IsOpen        = FALSE;  // It's not open yet
00160 LayerNameDlg*   LayerNameDlg::pLayerNameDlg = NULL;  // The layer name dlg that is open
00161 
00162 // This will get Camelot to display the filename and linenumber of any memory allocations
00163 // that are not released at program exit
00164 #define new CAM_DEBUG_NEW
00165 
00166 
00167 //------------------------------------------------------------------------------------------
00168 // Methods for the OpDeletePageBackground
00169 
00170 /********************************************************************************************
00171 
00172 >   OpDeletePageBackground::OpDeletePageBackground() 
00173 
00174     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00175     Created:    10/4/97
00176     Purpose:    OpDeletePageBackground constructor (Creates an undoable operation)
00177     Errors:     -
00178     SeeAlso:    -
00179 
00180 ********************************************************************************************/
00181 
00182 OpDeletePageBackground::OpDeletePageBackground()                                
00183 {                              
00184     // nothing to do yet
00185 }
00186 
00187 /********************************************************************************************
00188 
00189 >   OpState OpDeletePageBackground::GetState(String_256*, OpDescriptor*)
00190 
00191     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00192     Created:    10/4/97
00193     Inputs:     Name of the OpDescriptor being queried
00194     Outputs:    The string to show to the user
00195     Returns:    The state of the OpDeletePageBackground operation
00196     Purpose:    For finding the OpDeletePageBackground's state. 
00197     Errors:     -
00198     SeeAlso:    -
00199 
00200 ********************************************************************************************/
00201 
00202 OpState OpDeletePageBackground::GetState(String_256* pUIDescription, OpDescriptor* pOpDesc)
00203 {
00204     OpState OpSt;  
00205 
00206     // Is there a selected spread?
00207     Spread * pSpread = Document::GetSelectedSpread();
00208     if (pSpread)
00209     {
00210         // yes, so check if there is a background layer
00211         Layer* pLayer = pSpread->FindFirstPageBackgroundLayer();
00212         if (pLayer)
00213         {
00214             // Yes, so we are allowed to delete it
00215             OpSt.Greyed = FALSE;
00216         }
00217         else
00218         {
00219             // No, so we are greyed
00220             OpSt.Greyed = TRUE;
00221         }
00222     }
00223     else
00224     {
00225         // No selected spread, so we are greyed
00226         OpSt.Greyed = TRUE;
00227     }
00228 
00229     return OpSt;   
00230 }
00231 
00232 /********************************************************************************************
00233 
00234 >   void OpDeletePageBackground::Do(OpDescriptor* pOpDesc)
00235 
00236     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00237     Created:    10/4/97
00238     Inputs:     OpDescriptor (unused)
00239     Outputs:    -
00240     Returns:    -
00241     Purpose:    Finds and deletes the page background layer from the selected spread.
00242     Errors:     -
00243     SeeAlso:    -
00244 
00245 ********************************************************************************************/
00246 
00247 void OpDeletePageBackground::Do(OpDescriptor* pOpDesc)
00248 {
00249     // Just find the background layer and then ask our baseclass to delete it for us
00250     // Is there a selected spread?
00251     Spread * pSpread = Document::GetSelectedSpread();
00252     if (pSpread)
00253     {
00254         // yes, so check if there is a background layer
00255         Layer* pLayer = pSpread->FindFirstPageBackgroundLayer();
00256         if (pLayer)
00257         {
00258             OpLayerGalParam Param(PAGEBACKGROUND_DEFAULT, pSpread);
00259             Param.pLayer = pLayer;
00260             DoWithParam(pOpDesc, (OpParam*)&Param);
00261         }
00262     }
00263 
00264     return;
00265 }
00266 
00267 //------------------------------------------------------------------------------------------
00268 // Methods for the OpLayerGalChange
00269 
00270 /********************************************************************************************
00271 
00272 >   OpLayerGalChange::OpLayerGalChange() 
00273 
00274     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00275     Created:    4/8/94
00276     Inputs:     -
00277     Outputs:    -
00278     Returns:    -
00279     Purpose:    OpLayerGalChange constructor (Creates an undoable operation)
00280     Errors:     -
00281     SeeAlso:    -
00282 
00283 ********************************************************************************************/
00284             
00285             
00286 OpLayerGalChange::OpLayerGalChange(): UndoableOperation()                               
00287 {                              
00288     pSpread                 = NULL;
00289     UndoIDS                 = _R(IDS_NOTYPE);
00290     BroadcastLayerChanges   = TRUE;
00291     pOpUndoLayer            = NULL;
00292     pOpRedoLayer            = NULL;
00293 }
00294 
00295 /********************************************************************************************
00296 
00297 >   BOOL OpLayerGalChange::Init()
00298 
00299     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00300     Created:    4/8/94
00301     Inputs:     -
00302     Outputs:    -
00303     Returns:    TRUE if the operation could be successfully initialised 
00304                 FALSE if no more memory could be allocated 
00305                 
00306     Purpose:    OpLayerGalChange initialiser method
00307     Errors:     ERROR will be called if there was insufficient memory to allocate the 
00308                 operation.
00309     SeeAlso:    -
00310 
00311 ********************************************************************************************/
00312 
00313 BOOL OpLayerGalChange::Init()
00314 {
00315     return (
00316             RegisterOpDescriptor(
00317                                 0,
00318                                 _R(IDS_LAYERCHANGEOP),
00319                                 CC_RUNTIME_CLASS(OpLayerGalChange),
00320                                 OPTOKEN_LAYERGALCHANGE,
00321                                 OpLayerGalChange::GetState,
00322                                 0,  /* help ID */
00323                                 _R(IDBBL_LAYERCHANGEOP),
00324                                 0   /* bitmap ID */
00325                                 ) &&
00326             RegisterOpDescriptor(
00327                                 0,
00328                                 _R(IDS_DELETEPAGEBACKGROUND),
00329                                 CC_RUNTIME_CLASS(OpDeletePageBackground),
00330                                 OPTOKEN_DELETEPAGEBACKGROUND,
00331                                 OpDeletePageBackground::GetState,
00332                                 0,          // help ID
00333                                 0,          // bubble help id
00334                                 0           // bitmap ID
00335                                 )
00336             // special frame operations
00337                                 &&
00338 PORTNOTE("galleries", "Disabled frame stuff")
00339 #ifndef EXCLUDE_FROM_XARALX
00340             RegisterOpDescriptor(
00341                                 0,                              // Tool ID 
00342                                 _R(IDS_SELECTSTARTFRAME),           // String resource ID
00343                                 CC_RUNTIME_CLASS(OpSelectStartFrame),   // Runtime class
00344                                 OPTOKEN_FRAME_STARTFRAME,       // Token string
00345                                 OpSelectStartFrame::GetState,   // GetState function
00346                                 0,                              // help ID
00347                                 _R(IDBBL_SELECTSTARTFRAME),         // bubble help
00348                                 _R(IDD_ANIMATIONBAR),               // resource ID
00349                                 _R(IDC_PREVIEW_STARTFRAME),         // control ID
00350                                 SYSTEMBAR_ANIMATION,            // Bar ID
00351                                 TRUE,                           // Recieve system messages
00352                                 FALSE,                          // Smart duplicate operation
00353                                 TRUE,                           // Clean operation
00354                                 NULL,                           // String for one copy only error
00355                                 (DONT_GREY_WHEN_SELECT_INSIDE | GREY_WHEN_NO_CURRENT_DOC) // Auto state flags
00356                                 )
00357                                 &&
00358             RegisterOpDescriptor(
00359                                 0,                              // Tool ID 
00360                                 _R(IDS_SELECTENDFRAME),             // String resource ID
00361                                 CC_RUNTIME_CLASS(OpSelectEndFrame), // Runtime class
00362                                 OPTOKEN_FRAME_ENDFRAME,         // Token string
00363                                 OpSelectEndFrame::GetState, // GetState function
00364                                 0,                              // help ID
00365                                 _R(IDBBL_SELECTENDFRAME),           // bubble help
00366                                 _R(IDD_ANIMATIONBAR),               // resource ID
00367                                 _R(IDC_PREVIEW_ENDFRAME),           // control ID
00368                                 SYSTEMBAR_ANIMATION,            // Bar ID
00369                                 TRUE,                           // Recieve system messages
00370                                 FALSE,                          // Smart duplicate operation
00371                                 TRUE,                           // Clean operation
00372                                 NULL,                           // String for one copy only error
00373                                 (DONT_GREY_WHEN_SELECT_INSIDE | GREY_WHEN_NO_CURRENT_DOC) // Auto state flags
00374                                 )
00375                                 &&
00376             RegisterOpDescriptor(
00377                                 0,                              // Tool ID 
00378                                 _R(IDS_SELECTPREVFRAME),            // String resource ID
00379                                 CC_RUNTIME_CLASS(OpSelectPrevFrame),    // Runtime class
00380                                 OPTOKEN_FRAME_PREVFRAME,        // Token string
00381                                 OpSelectPrevFrame::GetState,    // GetState function
00382                                 0,                              // help ID
00383                                 _R(IDBBL_SELECTPREVFRAME),          // bubble help
00384                                 _R(IDD_ANIMATIONBAR),               // resource ID
00385                                 _R(IDC_PREVIEW_PREVFRAME),          // control ID
00386                                 SYSTEMBAR_ANIMATION,            // Bar ID
00387                                 TRUE,                           // Recieve system messages
00388                                 FALSE,                          // Smart duplicate operation
00389                                 TRUE,                           // Clean operation
00390                                 NULL,                           // String for one copy only error
00391                                 (DONT_GREY_WHEN_SELECT_INSIDE | GREY_WHEN_NO_CURRENT_DOC) // Auto state flags
00392                                 )
00393                                 &&
00394             RegisterOpDescriptor(
00395                                 0,                              // Tool ID 
00396                                 _R(IDS_SELECTNEXTFRAME),            // String resource ID
00397                                 CC_RUNTIME_CLASS(OpSelectNextFrame),    // Runtime class
00398                                 OPTOKEN_FRAME_NEXTFRAME,        // Token string
00399                                 OpSelectNextFrame::GetState,    // GetState function
00400                                 0,                              // help ID
00401                                 _R(IDBBL_SELECTNEXTFRAME),          // bubble help
00402                                 _R(IDD_ANIMATIONBAR),               // resource ID
00403                                 _R(IDC_PREVIEW_NEXTFRAME),          // control ID
00404                                 SYSTEMBAR_ANIMATION,            // Bar ID
00405                                 TRUE,                           // Recieve system messages
00406                                 FALSE,                          // Smart duplicate operation
00407                                 TRUE,                           // Clean operation
00408                                 NULL,                           // String for one copy only error
00409                                 (DONT_GREY_WHEN_SELECT_INSIDE | GREY_WHEN_NO_CURRENT_DOC) // Auto state flags
00410                                 )
00411                                 &&
00412             RegisterOpDescriptor(
00413                                 0,                              // Tool ID 
00414                                 _R(IDS_NEWFRAME),                   // String resource ID
00415                                 CC_RUNTIME_CLASS(OpCreateNewFrame), // Runtime class
00416                                 OPTOKEN_FRAME_NEWFRAME,         // Token string
00417                                 OpCreateNewFrame::GetState,     // GetState function
00418                                 0,                              // help ID
00419                                 _R(IDBBL_NEWFRAME),                 // bubble help
00420                                 _R(IDD_ANIMATIONBAR),               // resource ID
00421                                 _R(IDC_FRAME_NEWFRAME),             // control ID
00422                                 SYSTEMBAR_ANIMATION,            // Bar ID
00423                                 TRUE,                           // Recieve system messages
00424                                 FALSE,                          // Smart duplicate operation
00425                                 TRUE,                           // Clean operation
00426                                 NULL,                           // String for one copy only error
00427                                 (DONT_GREY_WHEN_SELECT_INSIDE | GREY_WHEN_NO_CURRENT_DOC) // Auto state flags
00428                                 )
00429                                 &&
00430             RegisterOpDescriptor(
00431                                 0,                              // Tool ID 
00432                                 _R(IDS_COPYFRAME),                  // String resource ID
00433                                 CC_RUNTIME_CLASS(OpCopyFrame),  // Runtime class
00434                                 OPTOKEN_FRAME_COPYFRAME,        // Token string
00435                                 OpCopyFrame::GetState,          // GetState function
00436                                 0,                              // help ID
00437                                 _R(IDBBL_COPYFRAME),                // bubble help
00438                                 _R(IDD_ANIMATIONBAR),               // resource ID
00439                                 _R(IDC_FRAME_COPYFRAME),            // control ID
00440                                 SYSTEMBAR_ANIMATION,            // Bar ID
00441                                 TRUE,                           // Recieve system messages
00442                                 FALSE,                          // Smart duplicate operation
00443                                 TRUE,                           // Clean operation
00444                                 NULL,                           // String for one copy only error
00445                                 (DONT_GREY_WHEN_SELECT_INSIDE | GREY_WHEN_NO_CURRENT_DOC) // Auto state flags
00446                                 )
00447                                 &&
00448             RegisterOpDescriptor(
00449                                 0,                              // Tool ID 
00450                                 _R(IDS_DELETEFRAME),                // String resource ID
00451                                 CC_RUNTIME_CLASS(OpDeleteFrame),// Runtime class
00452                                 OPTOKEN_FRAME_DELETEFRAME,      // Token string
00453                                 OpDeleteFrame::GetState,        // GetState function
00454                                 0,                              // help ID
00455                                 _R(IDBBL_DELETEFRAME),              // bubble help
00456                                 _R(IDD_ANIMATIONBAR),               // resource ID
00457                                 _R(IDC_FRAME_DELETEFRAME),          // control ID
00458                                 SYSTEMBAR_ANIMATION,            // Bar ID
00459                                 TRUE,                           // Recieve system messages
00460                                 FALSE,                          // Smart duplicate operation
00461                                 TRUE,                           // Clean operation
00462                                 NULL,                           // String for one copy only error
00463                                 (DONT_GREY_WHEN_SELECT_INSIDE | GREY_WHEN_NO_CURRENT_DOC) // Auto state flags
00464                                 )
00465                                 &&
00466 #endif // EXCLUDE_FROM_XARALX
00467                                 TRUE
00468             );
00469 }               
00470     
00471 /********************************************************************************************
00472 
00473 >   OpState OpLayerGalChange::GetState(String_256*, OpDescriptor*)
00474 
00475     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00476     Created:    4/8/94
00477     Inputs:     -
00478     Outputs:    -
00479     Returns:    The state of the OpLayerGalChange operation
00480     Purpose:    For finding the OpLayerGalChange's state. 
00481     Errors:     -
00482     SeeAlso:    -
00483 
00484 ********************************************************************************************/
00485 
00486 OpState OpLayerGalChange::GetState(String_256* UIDescription, OpDescriptor*)
00487 {
00488     OpState OpSt;  
00489     return(OpSt);   
00490 }
00491 
00492 /********************************************************************************************
00493 
00494 >   void OpLayerGalChange::DoWithParam(OpDescriptor*,OpParam* pOpParam)
00495 
00496     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00497     Created:    4/8/94
00498     Inputs:     OpDescriptor (unused)
00499                 pOpParam - this is really a ptr to an OpLayerGalParam
00500     Outputs:    -
00501     Returns:    -
00502     Purpose:    Performs the layer change operation defined by ((OpLayerGalParam*)pOpParam)->Reason.
00503                 It handles the creation, deletion, changing, and moving of the layer provided.
00504 
00505     Errors:     -
00506     SeeAlso:    -
00507 
00508 ********************************************************************************************/
00509 // The bounding rectangle of the current layer must be invalidated in all the following cases. 
00510 
00511 // If the visible status has changed 
00512 // If the Quality level has changed 
00513 // If the layer has been deleted 
00514 // If the z-order of the layer has changed
00515 
00516             
00517 void OpLayerGalChange::DoWithParam(OpDescriptor*, OpParam* pOpParam)
00518 {   
00519     OpLayerGalParam* pOpLayerGalParam = (OpLayerGalParam*)pOpParam;
00520 
00521     pSpread = pOpLayerGalParam->GetParentSpread();
00522     Reason  = pOpLayerGalParam->GetReason();
00523 
00524     Layer*              pLayer      = pOpLayerGalParam->pLayer;
00525     Node*               pContextNode= pOpLayerGalParam->pContextNode;
00526     AttachNodeDirection AttDir      = pOpLayerGalParam->AttDir;
00527     LayerStatus         NewStatus   = pOpLayerGalParam->Status;
00528 
00529     BOOL FrameLayer = FALSE;
00530 
00531     switch (Reason)
00532     {
00533         //--------------------------------------------------------------------------------------------
00534         // Select a Frame layer
00535         case (FRAME_SELECT):
00536             // Check for being given a null layer or an already active layer
00537             if (pLayer == NULL || pLayer->IsActive())
00538                 goto EndOperation;
00539 
00540 PORTNOTE("galleries", "disabled frame gallery")
00541 #ifndef EXCLUDE_FROM_XARALX
00542             // Make the layer we have been passed the active one
00543             FrameSGallery::MakeActiveLayer(pLayer);
00544 #endif
00545             UndoIDS = _R(IDS_FRAME_UNDO_SELECTNEW);
00546             break;
00547         //--------------------------------------------------------------------------------------------
00548         // Create a new layer
00549         case (FRAME_NEW):
00550             FrameLayer = TRUE;
00551         case (LAYER_NEW):
00552             {
00553                 // Attempt to create a new layer node 
00554                 ALLOC_WITH_FAIL(pLayer, (new Layer()), this);         
00555                 if (pLayer == NULL)
00556                     goto EndOperation; // We were unable to create a new layer so 
00557                                        // abort the operation 
00558 
00559                 // Set the new layer's status  
00560                 pLayer->SetLayerStatus(NewStatus); 
00561 
00562                 // Set the frame layer flag according to the operation type i.e FRAME_NEW = set flag
00563                 if (FrameLayer)
00564                 {
00565                     pLayer->SetFrame(TRUE);
00566                     pLayer->SetEdited(TRUE);
00567                 }
00568 
00569                 // Insert new layer in the tree
00570                 // Rule: if there is a guide layer at the top, then place the new layer
00571                 // beneath this layer, otherwise, put the new layer at the top.
00572                 Layer* pLastLayer = pSpread->FindLastLayer();
00573                 if(pLastLayer && pLastLayer->IsGuide())
00574                 {
00575                     // this layer is a guide layer - get the next one
00576                     pLastLayer = pLastLayer->FindPrevLayer();
00577                 }
00578                 Node* pNodeToInsert;
00579                 if(pLastLayer)
00580                 {
00581                     pNodeToInsert = pLastLayer;
00582                 }
00583                 else
00584                 {
00585                     // what?! can't find a Last Layer to use?
00586                     pNodeToInsert = pContextNode;
00587                 }
00588 
00589                 if (DoInsertNewNode(pLayer, pLastLayer, NEXT, FALSE))
00590                 {
00591 PORTNOTE("galleries", "Disabled frame gallery")
00592 #ifndef EXCLUDE_FROM_XARALX
00593                     if (FrameLayer)
00594                         FrameSGallery::MakeActiveLayer(pLayer);
00595                     else
00596 #endif
00597                         LayerSGallery::MakeActiveLayer(pLayer);
00598 
00599                     // Note the layer inserted so we can clear any selection on the layer when this op is undone
00600                     pOpUndoLayer = pLayer;
00601                     pLayer->EnsureUniqueLayerID();
00602                 }
00603             }
00604 
00605             if (FrameLayer)
00606                 UndoIDS = _R(IDS_FRAME_UNDO_NEW);
00607             else
00608                 UndoIDS = _R(IDS_LAYER_UNDO_NEW);
00609             break;
00610 
00611         //--------------------------------------------------------------------------------------------
00612         // Delete a layer
00613         case (FRAME_DELETE):
00614             FrameLayer = TRUE;
00615         case (LAYER_DELETE):
00616         case (PAGEBACKGROUND_DEFAULT):
00617             {
00618                 // This doesn't seem to be an important ensure as it works when the layer
00619                 // is not active
00620                 // Disabled 10/4/97
00621                 //ERROR3IF(pLayer->IsActive(),"Deleting layer, yet it is not active");
00622 
00623                 // We need to find 'prev' and 'next' before we delete the layer
00624                 Layer* pPrevLayer = pLayer->FindPrevLayer();
00625                 Layer* pNextLayer = pLayer->FindNextLayer();
00626 
00627                 if (pLayer->IsVisible())
00628                 {
00629                     if (!DoInvalidateLayerRegion(pLayer))
00630                         goto EndOperation;
00631                 }
00632 
00633                 NodeRenderableInk::DeselectAllOnLayer(pLayer); 
00634 
00635                 if (!DoHideNode(pLayer,TRUE)) // Hide the node 
00636                     goto EndOperation;
00637 
00638                 // Note the layer inserted so we can clear any selection on the layer when this op is redone
00639                 // i.e. deleted again after a redo
00640                 pOpRedoLayer = pLayer;
00641 
00642                 // If the last layer has been deleted, create a new one and make it the active layer
00643                 if (pSpread->FindFirstLayer() == NULL)
00644                 {
00645                     Layer* pFirstLayer;
00646 
00647                     ALLOC_WITH_FAIL(pFirstLayer, (new Layer()), this);        
00648                     if (pFirstLayer == NULL)
00649                         goto EndOperation; // We were unable to create a new layer so 
00650                                            // abort the operation 
00651 
00652                     // Set the new layer's status and ID  
00653                     pFirstLayer->SetActive(TRUE);
00654                     pFirstLayer->GetLayerStatus().StringLayerID = LayerSGallery::CreateUniqueLayerID(pSpread);
00655 
00656                     // Make it the last child of the spread
00657                     if (DoInsertNewNode(pFirstLayer,pSpread,LASTCHILD,FALSE,TRUE,TRUE,TRUE))
00658                     {
00659                         // Note the layer inserted so we can clear any selection on the layer when this op is undone
00660                         // i.e. deleted after an undo
00661                         pOpUndoLayer = pLayer;
00662                     }
00663                 }
00664                 else
00665                 {
00666                     // if we've deleted the active layer, make one of the others active
00667                     if (pLayer->IsActive())
00668                     {
00669                         Layer* pNewActiveLayer = pNextLayer;
00670 
00671                         if (pNewActiveLayer == NULL)
00672                             pNewActiveLayer = pPrevLayer;
00673 
00674                         if (pNewActiveLayer != NULL)
00675                         {
00676 PORTNOTE("galleries", "disabled frame gallery")
00677 #ifndef EXCLUDE_FROM_XARALX
00678                             if (FrameLayer)
00679                                 FrameSGallery::MakeActiveLayer(pNewActiveLayer);
00680                             else
00681 #endif
00682                                 LayerSGallery::MakeActiveLayer(pNewActiveLayer);
00683                         }
00684 
00685                         ERROR3IF(pNewActiveLayer == NULL,"Can't find another layer to make active");
00686 
00687                         // Make sure that when it comes back (through an undo) it is not flagged as active
00688                         pLayer->SetActive(FALSE);
00689                     }
00690                 }
00691             }
00692 
00693             if (FrameLayer)
00694                 UndoIDS = _R(IDS_FRAME_UNDO_DELETE);
00695             else
00696             {
00697                 if (Reason == LAYER_DELETE)
00698                     UndoIDS = _R(IDS_LAYER_UNDO_DELETE);
00699                 else
00700                     UndoIDS = _R(IDS_UNDO_DEFAULTBACKGROUND);
00701             }
00702             break;
00703 
00704         //--------------------------------------------------------------------------------------------
00705         // Change a layer's status (i.e. it's layer attributes)
00706         case (LAYER_CHANGE_NAME):
00707             UndoIDS = _R(IDS_LAYER_UNDO_CHANGENAME);
00708             // Fall through!!!!
00709 //      case (LAYER_CHANGE):
00710             {
00711                 // if UndoIDS has not been changed via the LAYER_CHANGE_NAME entry point,
00712                 // change it to something relevent
00713                 if (UndoIDS == _R(IDS_NOTYPE)) UndoIDS = _R(IDS_LAYER_UNDO_CHANGE);
00714 
00715                 // Try to create an action to restore the attribute changes we 
00716                 // are about to make 
00717                 ChangeLyrAttribAction* UndoAttribChngAction;                          
00718 
00719                 if ( ChangeLyrAttribAction::Init(this,                    
00720                                               &UndoActions,
00721                                               sizeof(InvalidateRegionAction),  
00722                                               pLayer->GetLayerStatus(),
00723                                               pLayer, 
00724                                               ( Action**)(&UndoAttribChngAction))
00725                                               != AC_FAIL) 
00726                 {
00727                     LayerStatus OldStatus = pLayer->GetLayerStatus();
00728 
00729                     // Get the state of the layer before the change
00730                     BOOL PrevVisible = pLayer->IsVisible();
00731                     BOOL PrevLocked  = pLayer->IsLocked();
00732                     BOOL PrevOutline = pLayer->IsOutline();
00733 
00734                     // This is the real state of the visible flag before the change
00735                     BOOL PrevVisibleReal = pLayer->GetVisibleFlagState();
00736 
00737                     // change the layer's status info
00738                     pLayer->SetLayerStatus(NewStatus);
00739 
00740                     // Get the state of the layer after the change
00741                     BOOL PostVisible = pLayer->IsVisible();
00742                     BOOL PostLocked  = pLayer->IsLocked();
00743                     BOOL PostOutline = pLayer->IsOutline();
00744 
00745                     // This is the real state of the visible flag after the change
00746                     BOOL PostVisibleReal = pLayer->GetVisibleFlagState();
00747 
00748                     // If the visibility flag has changed, or if visible and the outline state has changed,
00749                     // then do a redraw.
00750                     if ((PrevVisibleReal != PostVisibleReal) || (PostVisible && (PrevOutline != PostOutline)))
00751                     {
00752                         if (!DoInvalidateLayerRegion(pLayer))
00753                             goto EndOperation;
00754                     } 
00755 
00756                     // If become invisible or become locked, then remove the selections on the layer 
00757                     if ( ((PrevVisible != PostVisible) && !PostVisible) ||
00758                          ((PrevLocked  != PostLocked)  && PostLocked) )
00759                     {
00760                         NodeRenderableInk::DeselectAllOnLayer(pLayer); 
00761                     } 
00762                     pLayer->EnsureUniqueLayerID();
00763                 }
00764                 else 
00765                     goto EndOperation; // We have failed 
00766 
00767             }
00768             break;
00769 
00770         //--------------------------------------------------------------------------------------------
00771         // Move the layer somewhere else
00772         case (FRAME_MOVE):
00773             FrameLayer = TRUE;
00774         case (LAYER_MOVE):
00775             // Move the layer to the new pos
00776             if(!DoMoveNode(pLayer, pContextNode, AttDir))
00777                 goto EndOperation; 
00778 
00779             GetApplication()->UpdateSelection();
00780 
00781             // Horrible bodge that ensures that the layer that moves remains the active layer.
00782             // The DoMoveNode() call above causes a hidden node to be generated that references a layer.
00783             // This in turn generates a LAYERSCHANGED spread message that causes the layer gallery to do
00784             // a validity check to ensure that there's an active layer on the spread.
00785             // If there isn't an active layer (which there isn't in this case because it's just been
00786             // hidden) the check selects the first layer in the spread.
00787             // Not easy to fix properly, but easy to bodge it.
00788             if (FrameLayer)
00789             {
00790                 // Ensure that the frame layer flag is on
00791                 pLayer->SetFrame(TRUE);
00792                 pLayer->SetEdited(TRUE);
00793 PORTNOTE("galleries", "Disabled frame gallery")
00794 #ifndef EXCLUDE_FROM_XARALX
00795                 FrameSGallery::MakeActiveLayer(pLayer);
00796 #endif
00797             }
00798             else
00799                 LayerSGallery::MakeActiveLayer(pLayer);
00800 
00801             pOpUndoLayer = pLayer;
00802             pOpRedoLayer = pLayer;
00803 
00804             // Invalidate the region if the layer is visible
00805             if (pOpLayerGalParam->MoveRedraw)
00806             {
00807                 if (!DoInvalidateLayerRegion(pLayer))
00808                     goto EndOperation;
00809             }
00810 
00811             if (pOpLayerGalParam->ToggleBackground)
00812                 LayerStateAction::Init(this,&UndoActions,*pOpLayerGalParam);
00813 
00814             if (FrameLayer)
00815                 UndoIDS = _R(IDS_FRAME_UNDO_MOVE);
00816             else
00817                 UndoIDS = _R(IDS_LAYER_UNDO_MOVE);
00818             break;
00819 
00820         //--------------------------------------------------------------------------------------------
00821         // Copy the layer 
00822         case (FRAME_COPY):
00823             FrameLayer = TRUE;
00824         case (LAYER_COPY):
00825             {
00826                 BOOL ok = TRUE;
00827                 Layer* pCopyOfLayer = NULL;
00828 
00829                 if (pLayer == NULL)
00830                     goto EndOperation;
00831 
00832 
00833                 // The following lump of code makes sure that the layer being copied does not 
00834                 // contain the insertion node, otherwise it will be copied in the new layer,
00835                 // resulting in the doc having two insertion nodes. (Markn 17/10/96)
00836                 /*
00837                 {
00838                     BaseDocument* pBaseDoc = pLayer->FindOwnerDoc();
00839 
00840                     if (pBaseDoc != NULL && IS_A(pBaseDoc,Document))
00841                     {
00842                         Document* pDoc = (Document*)pBaseDoc;
00843                         InsertionNode* pInsertNode = pDoc->GetInsertionPosition();
00844                         if (pInsertNode != NULL)
00845                         {
00846                             Layer* pInsertLayer = (Layer*)pInsertNode->FindParent(CC_RUNTIME_CLASS(Layer));
00847                             if (pInsertLayer == pLayer)
00848                             {
00849                                 pInsertNode->UnlinkNodeFromTree();
00850                                 delete pInsertNode;
00851                                 pInsertNode = NULL;
00852                             }
00853                         }
00854                     }
00855                 }
00856                 */
00857 
00858                 // Copy the layer and all its children, without placing the copy in the tree
00859                 CALL_WITH_FAIL(pLayer->NodeCopy((Node**)&pCopyOfLayer), this, ok);
00860                 if (!ok) goto EndOperation; 
00861 
00862                 //Graham 1/8/97: Clear the text tool's internal record of the focus story
00863                 //This is a bug fix
00864                 TextStory::SetFocusStory(NULL);
00865 
00866                 // Set the new layer's status  
00867                 pCopyOfLayer->SetLayerStatus(NewStatus); 
00868 
00869                 // Set the frame layer flag according to the operation type i.e FRAME_NEW = set flag
00870                 if (FrameLayer)
00871                 {
00872                     pCopyOfLayer->SetFrame(TRUE);
00873                     pCopyOfLayer->SetEdited(TRUE);
00874                 }
00875 
00876                 // Insert layer and its children in the tree somewhere
00877                 // Rule: if there is a guide layer at the top, then place the new layer
00878                 // beneath this layer, otherwise, put the new layer at the top.
00879                 Layer* pLastLayer = pSpread->FindLastLayer();
00880                 if(pLastLayer && pLastLayer->IsGuide())
00881                 {
00882                     // this layer is a guide layer - get the next one
00883                     // (there will (ought to be) only one guide layer...)
00884                     pLastLayer = pLastLayer->FindPrevLayer();
00885                 }
00886                 Node* pNodeToInsert;
00887                 if(pLastLayer)
00888                 {
00889                     pNodeToInsert = pLastLayer;
00890                 }
00891                 else
00892                 {
00893                     // what?! can't find a Last Layer to use?
00894                     pNodeToInsert = pContextNode;
00895                 }
00896 
00897                 if (!DoInsertNewNode(pCopyOfLayer, pNodeToInsert, NEXT, FALSE))
00898                 {
00899                     // Tidy up if we fail
00900                     pCopyOfLayer->CascadeDelete(); 
00901                     delete pCopyOfLayer; 
00902                     goto EndOperation; 
00903                 } 
00904 
00905                 // Call PostDuplicate so things sort their lives out.
00906                 Node* pCurrent = pCopyOfLayer->FindFirstDepthFirst();
00907                 while (pCurrent!=NULL && ok)
00908                 {
00909                     ok = pCurrent->PostDuplicate(this);
00910                     pCurrent = pCurrent->FindNextDepthFirst(pCopyOfLayer);
00911                 }
00912                 if (!ok) goto EndOperation; 
00913             
00914                 if (!DoInvalidateLayerRegion(pCopyOfLayer))
00915                     goto EndOperation;
00916 
00917                 // Note the layer inserted so we can clear any selection on the layer when this op is undone
00918                 // i.e. when the copied layer is removed after an undo
00919                 pOpUndoLayer = pCopyOfLayer;
00920 
00921                 // Make it the active layer
00922 PORTNOTE("galleries", "Disabled frame gallery")
00923 #ifndef EXCLUDE_FROM_XARALX
00924                 if (FrameLayer)
00925                     FrameSGallery::MakeActiveLayer(pCopyOfLayer);
00926                 else
00927 #endif
00928                     LayerSGallery::MakeActiveLayer(pCopyOfLayer);
00929 
00930                 NodeRenderableInk::DeselectAllOnLayer(pLayer);
00931                 pCopyOfLayer->EnsureUniqueLayerID();
00932             }
00933 
00934             if (FrameLayer)
00935                 UndoIDS = _R(IDS_FRAME_UNDO_COPY);
00936             else
00937                 UndoIDS = _R(IDS_LAYER_UNDO_COPY);
00938             break;
00939 
00940         //--------------------------------------------------------------------------------------------
00941         // Toggle the layer's background flag
00942         case (LAYER_TOGGLEBACKGROUND):
00943             LayerStateAction::Init(this, &UndoActions, *pOpLayerGalParam);
00944             BroadcastLayerChanges = FALSE;
00945             UndoIDS = _R(IDS_LAYER_UNDO_MOVE);
00946             break;
00947 
00948         //--------------------------------------------------------------------------------------------
00949         // Change the layer's visibility
00950         case (LAYER_VISIBLE):
00951             LayerStateAction::Init(this, &UndoActions, *pOpLayerGalParam);
00952             BroadcastLayerChanges = FALSE;
00953             UndoIDS = _R(IDS_LAYER_UNDO_VISIBLE);
00954             break;
00955 
00956         //--------------------------------------------------------------------------------------------
00957         // Change the layer's locked state
00958         case (LAYER_LOCKED):
00959             LayerStateAction::Init(this, &UndoActions, *pOpLayerGalParam);
00960             BroadcastLayerChanges = FALSE;
00961             UndoIDS = _R(IDS_LAYER_UNDO_LOCKED);
00962             break;
00963 
00964         //--------------------------------------------------------------------------------------------
00965         // Change the layer's doc's 'all visible' state
00966         case (FRAME_ALLVISIBLE):
00967             FrameLayer = TRUE;
00968         case (LAYER_ALLVISIBLE):
00969             LayerStateAction::Init(this, &UndoActions, *pOpLayerGalParam);
00970             BroadcastLayerChanges = FALSE;
00971             if (FrameLayer)
00972                 UndoIDS = _R(IDS_FRAME_UNDO_ALLVISIBLE);
00973             else
00974                 UndoIDS = _R(IDS_LAYER_UNDO_ALLVISIBLE);
00975             break;
00976 
00977         //--------------------------------------------------------------------------------------------
00978         // Change the layer's doc's 'multilayer' state
00979         case (FRAME_MULTILAYER):
00980             FrameLayer = TRUE;
00981         case (LAYER_MULTILAYER):
00982             LayerStateAction::Init(this, &UndoActions, *pOpLayerGalParam);
00983             BroadcastLayerChanges = FALSE;
00984             if (FrameLayer)
00985                 UndoIDS = _R(IDS_FRAME_UNDO_MULTILAYER);
00986             else
00987                 UndoIDS = _R(IDS_LAYER_UNDO_MULTILAYER);
00988             break;
00989 
00990         //--------------------------------------------------------------------------------------------
00991         // Change the layer's name, visibility & editability, all on one go
00992         case (LAYER_CHANGE):
00993             LayerStateAction::Init(this, &UndoActions, *pOpLayerGalParam);
00994             //BroadcastLayerChanges = FALSE;
00995             UndoIDS = _R(IDS_OPCHANGELAYERPROPERTIES);
00996             break;
00997 
00998         //--------------------------------------------------------------------------------------------
00999         // Change the layer's solid state
01000         case (LAYER_SOLID):
01001 // Cannot do this as this causes the gallery items to be destructed whilst handling
01002 // clicks on one of the items.
01003 //          // Check that all visible layers are actually frame layers
01004 //          FrameSGallery::EnsureFrameLayerIntegrity(pSpread);
01005             // Set up the action
01006             LayerStateAction::Init(this, &UndoActions, *pOpLayerGalParam);
01007             BroadcastLayerChanges = FALSE;
01008             UndoIDS = _R(IDS_LAYER_UNDO_SOLID);
01009             break;
01010         //--------------------------------------------------------------------------------------------
01011         // Change the layer's solid state
01012         case (LAYER_OVERLAY):
01013 //          // Check that all visible layers are actually frame layers
01014 //          FrameSGallery::EnsureFrameLayerIntegrity(pSpread);
01015             // Set up the action
01016             LayerStateAction::Init(this, &UndoActions, *pOpLayerGalParam);
01017             BroadcastLayerChanges = FALSE;
01018             UndoIDS = _R(IDS_LAYER_UNDO_OVERLAY);
01019             break;
01020 
01021         //--------------------------------------------------------------------------------------------
01022         // Change the layer's active state
01023         case (LAYER_ACTIVE):
01024             // Set up the action
01025             LayerStateAction::Init(this, &UndoActions, *pOpLayerGalParam);
01026             BroadcastLayerChanges = FALSE;
01027             UndoIDS = _R(IDS_LAYER_UNDO_ACTIVE);
01028             break;
01029 
01030         // Trap any other reasons here
01031         default:
01032             ERROR3("Unknown OpLayerGalChange reason code");
01033             break;
01034     }
01035 
01036     if (BroadcastLayerChanges)
01037     {
01038         BROADCAST_TO_ALL(SpreadMsg(pSpread,SpreadMsg::LAYERCHANGES));
01039     }
01040 
01041     EndOperation:
01042 
01043     ERROR3IF(UndoIDS == 0,"The undo ID string is zero. No too useful!");
01044     End(); 
01045 }
01046 
01047 /********************************************************************************************
01048 
01049 >   BOOL OpLayerGalChange::DoInvalidateLayerRegion(Layer* pLayer)
01050 
01051     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01052     Created:    21/9/95
01053     Inputs:     pLayer = ptr to layer
01054     Outputs:    -
01055     Returns:    TRUE for success, FALSE otherwise
01056     Purpose:    This invalidates the areas of the screen covered by the given layer
01057                 This copes with guidelines if the given layer is a guides layer
01058 
01059                 We have to do guidelines separately, because guidelines don't get included in the bounding
01060                 rect of the layer, hence DoInvalidateNodeRegion(pLayer) won't work
01061     Errors:     -
01062     SeeAlso:    -
01063 
01064 ********************************************************************************************/
01065 
01066 BOOL OpLayerGalChange::DoInvalidateLayerRegion(Layer* pLayer)
01067 {
01068     ERROR2IF(pLayer  == NULL,FALSE, "pLayer is NULL");
01069     ERROR2IF(pSpread == NULL,FALSE,"pSpread is NULL");
01070 
01071     BOOL ok = TRUE;
01072 
01073     if (pLayer->IsGuide())
01074     {
01075         Node* pNode = pLayer->FindFirstChild(CC_RUNTIME_CLASS(NodeGuideline));
01076         while (pNode != NULL && ok)
01077         {
01078             DocRect Rect = ((NodeGuideline*)pNode)->GetRenderRect();
01079             ok = DoInvalidateRegion(pSpread,Rect);
01080 
01081             pNode = pNode->FindNext(CC_RUNTIME_CLASS(NodeGuideline));
01082         }
01083     }
01084 
01085     if (ok) ok = DoInvalidateNodeRegion(pLayer, TRUE);
01086 
01087     return ok;
01088 }
01089 
01090 /********************************************************************************************
01091 
01092 >   void OpLayerGalChange::GetOpName(String_256* OpName) 
01093 
01094     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01095     Created:    5/8/94
01096     Inputs:     -
01097     Outputs:    The undo string for the operation
01098     Returns:    
01099     Purpose:    The GetOpName fn is overridden so that we return back a description 
01100                 appropriate to the type of attribute that the operation applies. 
01101                     
01102     Errors:     -
01103     SeeAlso:    -
01104 
01105 ********************************************************************************************/
01106 
01107 void OpLayerGalChange::GetOpName(String_256* OpName) 
01108 { 
01109     *OpName = String_256(UndoIDS);
01110 }  
01111 
01112 
01113 /********************************************************************************************
01114 
01115 >   void OpLayerGalChange::Undo() 
01116 
01117     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
01118     Created:    4/8/94
01119     Inputs:     -
01120     Outputs:    -
01121     Returns:    -
01122     Purpose:    The overloaded Undo operation refreshes the layer details in the layer 
01123                 manager   
01124     Errors:     -
01125     SeeAlso:    -
01126 
01127 ********************************************************************************************/
01128 
01129 BOOL OpLayerGalChange::Undo() 
01130 {
01131     // Do some stuff before the undo takes place, relevent to the operation being undone
01132     switch (Reason)
01133     {
01134         // Only LAYER_NEW and LAYER_COPY need to worry if pOpUndoLayer is NULL
01135         // LAYER_DELETE op only creates a pOpUndoLayer ptr after the last layer is deleted and
01136         // automatically replaced by a new blank layer.
01137 
01138         case FRAME_NEW:
01139         case FRAME_COPY:
01140         case LAYER_NEW:
01141         case LAYER_COPY:
01142 
01143             ERROR3IF(pOpUndoLayer == NULL,"The op's undo layer ptr is NULL");
01144 
01145             // **** Fall through...
01146 
01147         case FRAME_DELETE:
01148         case LAYER_DELETE:
01149         case PAGEBACKGROUND_DEFAULT:
01150 
01151             // If undoing, make sure there are no selected nodes on the layer before
01152             // it disappears
01153             if (pOpUndoLayer != NULL && pOpUndoLayer->FindParent() != NULL)
01154                 NodeRenderableInk::DeselectAllOnLayer(pOpUndoLayer);
01155 
01156             // **** Fall through...
01157 
01158         case FRAME_MOVE:
01159         case LAYER_MOVE:
01160 
01161             // All the above reasons generate hidden nodes, so the HideNode and ShowNode code
01162             // will broadcast layer changes on undo and redo (hopefully!)
01163             BroadcastLayerChanges = FALSE;
01164             break;
01165 
01166         default:
01167             break;
01168     }
01169 
01170     BOOL Result = Operation::Undo(); 
01171     if (Result)
01172     {
01173         // Do some stuff after the undo takes place, relevent to the operation being undone
01174         switch (Reason)
01175         {
01176             // When moving layers about, we need to make sure the layer moved remains the active layer
01177             case FRAME_MOVE:
01178             case LAYER_MOVE:
01179                 GetApplication()->UpdateSelection();
01180                 if (pOpUndoLayer != NULL)
01181                 {
01182 PORTNOTE("galleries", "Disabled frame gallery")
01183 #ifndef EXCLUDE_FROM_XARALX
01184                     if (Reason == FRAME_MOVE)
01185                         FrameSGallery::MakeActiveLayer(pOpUndoLayer);
01186                     else
01187 #endif
01188                         LayerSGallery::MakeActiveLayer(pOpUndoLayer);
01189                     BroadcastLayerChanges = TRUE;
01190                 }
01191                 break;
01192             default:
01193                 break;
01194         }       
01195 
01196         if (BroadcastLayerChanges)
01197         {
01198             BROADCAST_TO_ALL(SpreadMsg(pSpread,SpreadMsg::LAYERCHANGES));
01199         }
01200     }
01201     return (Result); 
01202 }       
01203 
01204 /********************************************************************************************
01205 
01206 >   void OpLayerGalChange::Redo()
01207 
01208     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
01209     Created:    4/8/94
01210     Inputs:     -
01211     Outputs:    -
01212     Returns:    -
01213     Purpose:    The overloaded Redo operation refreshes the layer details in the layer
01214                 manager 
01215     Errors:     -
01216     SeeAlso:    -
01217 
01218 ********************************************************************************************/
01219 
01220 BOOL OpLayerGalChange::Redo()
01221 {
01222     // Do some stuff before the redo takes place, relevent to the operation being redone
01223     switch (Reason)
01224     {
01225         case FRAME_DELETE:
01226         case LAYER_DELETE:
01227         case PAGEBACKGROUND_DEFAULT:
01228 
01229             ERROR3IF(pOpRedoLayer == NULL,"The op's redo layer ptr is NULL");
01230 
01231             // If redoing a layer delete, make sure there are no selected nodes on the layer before
01232             // it disappears
01233             if (pOpRedoLayer != NULL && pOpRedoLayer->FindParent() != NULL)
01234                 NodeRenderableInk::DeselectAllOnLayer(pOpRedoLayer);
01235 
01236             // **** Fall through...
01237 
01238         case FRAME_NEW:
01239         case FRAME_COPY:
01240         case FRAME_MOVE:
01241         case LAYER_NEW:
01242         case LAYER_COPY:
01243         case LAYER_MOVE:
01244 
01245             // All the above reasons generate hidden nodes, so the HideNode and ShowNode code
01246             // will broadcast layer changes on undo and redo (hopefully!)
01247             BroadcastLayerChanges = FALSE;
01248             break;
01249 
01250         default:
01251             break;
01252     }
01253 
01254     BOOL Result = Operation::Redo(); 
01255     if (Result)
01256     {
01257         // Do some stuff after the redo takes place, relevent to the operation being redone
01258         switch (Reason)
01259         {
01260             // When moving layers about, we need to make sure the layer moved remains the active layer
01261             case FRAME_MOVE:
01262             case LAYER_MOVE:
01263                 GetApplication()->UpdateSelection();
01264                 if (pOpRedoLayer != NULL)
01265                 {
01266 PORTNOTE("galleries", "Disabled frame gallery")
01267 #ifndef EXCLUDE_FROM_XARALX
01268                     if (Reason == FRAME_MOVE)
01269                         FrameSGallery::MakeActiveLayer(pOpRedoLayer);
01270                     else
01271 #endif
01272                         LayerSGallery::MakeActiveLayer(pOpRedoLayer);
01273                     BroadcastLayerChanges = TRUE;
01274                 }
01275                 break;
01276 
01277             default:
01278                 break;
01279         }       
01280 
01281         if (BroadcastLayerChanges)
01282         {
01283             BROADCAST_TO_ALL(SpreadMsg(pSpread,SpreadMsg::LAYERCHANGES));
01284         }
01285     }
01286     return (Result); 
01287 }
01288 
01289 /********************************************************************************************
01290 
01291 >   static BOOL OpLayerGalChange::IsFrameMode()
01292 
01293     Author:     Ranbir_Rana (Xara Group Ltd) <camelotdev@xara.com>
01294     Created:    21/10/97
01295     Inputs:     -
01296     Outputs:    -
01297     Returns:    TRUE if the document is frame based, else FALSE.
01298     Purpose:    
01299     
01300 ********************************************************************************************/
01301 
01302 BOOL OpLayerGalChange::IsFrameMode()
01303 {
01304     // Flag variables.
01305     BOOL FramedDoc = FALSE;     // Flag to determine the document type.
01306     
01307     // Get a ptr to the selected spread
01308     Spread* pSpread = Document::GetSelectedSpread();
01309 
01310     // Ensure a valid spread ptr.
01311     if(pSpread)
01312     {
01313         // Are there any frame layers?
01314         Layer* pFrameLayer = pSpread->FindFirstFrameLayer();    
01315 
01316         //If a frame layer exists, then this is an animation doc.
01317         if (pFrameLayer)
01318             FramedDoc = TRUE;
01319     }
01320 
01321     return FramedDoc;
01322 }
01323 
01324 //------------------------------------------------------------------------
01325 //------------------------------------------------------------------------
01326 //------------------------------------------------------------------------
01327 
01328 // The layer stuff dialog
01329 /********************************************************************************************
01330 
01331 >   LayerNameDlg::LayerNameDlg(): DialogOp(LayerNameDlg::IDD, LayerNameDlg::Mode) 
01332 
01333 
01334     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01335     Created:    9/8/94
01336     Inputs:     -
01337     Outputs:    -
01338     Returns:    -
01339     Purpose:    LayerNameDlg constructor. Creates a non-undoable operation
01340     Errors:     -
01341     SeeAlso:    -
01342 
01343 ********************************************************************************************/
01344                                                                                 
01345 
01346 LayerNameDlg::LayerNameDlg(): DialogOp(LayerNameDlg::IDD, LayerNameDlg::Mode) 
01347 {   
01348     pLayer  = NULL;
01349     pSpread = NULL;
01350 }        
01351 
01352 /********************************************************************************************
01353 
01354 >   MsgResult LayerNameDlg::Message( CDlgMessage DlgMsg, CGadgetID Gadget)
01355 
01356     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01357     Created:    9/8/94
01358     Inputs:     -
01359     Outputs:    -
01360     Returns:    -
01361     Purpose:    Handles all the scale dialog's messages 
01362     Errors:     -
01363     SeeAlso:    -
01364 
01365 ********************************************************************************************/
01366 
01367 MsgResult LayerNameDlg::Message(Msg* Message)
01368 {
01369     if (IS_OUR_DIALOG_MSG(Message))
01370     {
01371         DialogMsg* Msg = (DialogMsg*)Message;
01372         BOOL EndDialog = FALSE;
01373 
01374         switch (Msg->DlgMsg)
01375         {
01376             case DIM_CREATE:
01377                 ShowLayerDetails();
01378                 LayerNameDlg::IsOpen = TRUE;
01379                 LayerNameDlg::pLayerNameDlg = this;
01380                 SetKeyboardFocus(_R(IDC_LAYER_NAME));
01381                 HighlightText (_R(IDC_LAYER_NAME));
01382                 break;
01383                 
01384             case DIM_COMMIT:
01385                 EndDialog = TRUE;
01386                 CommitDialogValues();
01387                 break;
01388 
01389             case DIM_SOFT_COMMIT:
01390                 //TRACE( _T("Rgt OK handling here\n"));
01391                 break; 
01392 
01393             case DIM_CANCEL:
01394                 EndDialog = TRUE;
01395                 break;
01396 
01397             case DIM_LFT_BN_CLICKED:
01398                 break; 
01399 
01400             case DIM_TEXT_CHANGED:
01401                 break;
01402 
01403             default:
01404                 break;
01405         }
01406 
01407         if (EndDialog)  // Dialog communication over 
01408         {              // Isn't this pretty?
01409             Close();  // Close the dialog 
01410             End();   // Destroy dialog 
01411 
01412             LayerNameDlg::IsOpen        = FALSE;    // We no longer have a current layer name dialog
01413             LayerNameDlg::pLayerNameDlg = NULL;     // so reset the static vars
01414             return (DLG_EAT_IF_HUNGRY(Msg)); 
01415         }
01416     }
01417 //  return OK; 
01418 
01419     // Pass everything on to the base class . . .
01420     return DialogOp::Message(Message);
01421 }  
01422 
01423 
01424 /********************************************************************************************
01425 
01426 >   OpState LayerNameDlg::GetState(String_256*, OpDescriptor*)
01427 
01428     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01429     Created:    9/8/94
01430     Inputs:     -
01431     Outputs:    -
01432     Returns:    -
01433     Purpose:    LayerNameDlg GetState method
01434     Errors:     -
01435     SeeAlso:    -
01436 
01437 ********************************************************************************************/
01438 
01439 OpState LayerNameDlg::GetState(String_256*, OpDescriptor*)
01440 {    
01441     OpState OpSt;
01442     return(OpSt);
01443 }
01444          
01445 /********************************************************************************************
01446 
01447 >   BOOL LayerNameDlg::Init()
01448 
01449     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01450     Created:    9/8/94
01451     Inputs:     -
01452     Outputs:    -
01453     Returns:    -
01454     Purpose:    LayerNameDlg Init method
01455     Errors:     -
01456     SeeAlso:    -
01457 
01458 ********************************************************************************************/
01459 
01460 
01461 
01462 BOOL LayerNameDlg::Init()
01463 {  
01464     return (RegisterOpDescriptor(
01465                                 0,
01466                                 _R(IDS_LAYERNAMEDLG),
01467                                 CC_RUNTIME_CLASS(LayerNameDlg),
01468                                 OPTOKEN_LAYERNAMEDLG,
01469                                 LayerNameDlg::GetState,
01470                                 0,  // help ID
01471                                 0   // bubble ID
01472                                 )
01473             ); 
01474 }   
01475  
01476 /********************************************************************************************
01477 
01478 >   static void LayerNameDlg::StartUp(LayerDlgParam* pParam)
01479 
01480     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01481     Created:    9/8/94
01482     Inputs:     pParam - ptr to all the info the dlg needs in order to do its stuff
01483     Outputs:    -
01484     Returns:    -
01485     Purpose:    Starts up a LayerNameDlg using the OPTOKEN_LAYERNAMEDLG op token
01486     Errors:     -
01487     SeeAlso:    -
01488 
01489 ********************************************************************************************/
01490 
01491 void LayerNameDlg::StartUp(LayerDlgParam* pParam)
01492 {
01493     if (!LayerNameDlg::IsOpen)
01494     {
01495         OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_LAYERNAMEDLG); 
01496         if (pOpDesc != NULL)
01497             pOpDesc->Invoke((OpParam*)pParam);
01498         else
01499         {
01500             ERROR3("Couldn't find OPTOKEN_LAYERNAMEDLG op descriptor");
01501         }
01502     }
01503     else if (LayerNameDlg::pLayerNameDlg != NULL)
01504         LayerNameDlg::pLayerNameDlg->BringToTop();
01505         // SetActiveWindow(LayerNameDlg::pLayerNameDlg->WindowID);
01506 }
01507 
01508        
01509 /********************************************************************************************
01510 
01511 >   BOOL LayerNameDlg::Create()
01512 
01513     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01514     Created:    9/8/94
01515     Inputs:     -
01516     Outputs:    -
01517     Returns:    TRUE if successful, else FALSE
01518     Purpose:    LayerNameDlg create method 
01519     Errors:     -
01520     SeeAlso:    -
01521 
01522 ********************************************************************************************/
01523 
01524        
01525 BOOL LayerNameDlg::Create()
01526 {
01527     if (DialogOp::Create())
01528     {
01529         //ShowLayerDetails();
01530         return TRUE;
01531     }
01532     else
01533         return FALSE;
01534 
01535 }
01536 
01537 /********************************************************************************************
01538 
01539 >   void LayerNameDlg::DoWithParam(OpDescriptor*,OpParam* pOpParam)
01540 
01541     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01542     Created:    9/8/94
01543     Inputs:     pOpParam = ptr to a OpLayerGalReason struct, cast as an OpParam* 
01544     Outputs:    -
01545     Returns:    -
01546     Purpose:    Creates then opens the dialog 
01547     Errors:     -
01548     SeeAlso:    -
01549 
01550 ********************************************************************************************/
01551 
01552 
01553 void LayerNameDlg::DoWithParam(OpDescriptor*,OpParam* pOpParam)
01554 {
01555     // If there's already one layer name dlg open, return.
01556     if (LayerNameDlg::IsOpen)
01557         return;
01558 
01559     LayerDlgParam* pParam = (LayerDlgParam*)pOpParam;
01560 
01561     // Why are you creating me. I need to know, God damn it!
01562     Reason = pParam->GetReason();
01563 
01564     // Extract the spread and layer in question
01565     pSpread = pParam->GetSpread();
01566     pLayer  = pParam->GetLayer();
01567 
01568     // If we have a layer but not a spread, find the spread via the given layer
01569     if (pLayer != NULL && pSpread == NULL)
01570         pSpread = pLayer->FindParentSpread();
01571 
01572     BOOL ok=FALSE;
01573     
01574     switch (Reason)
01575     {
01576         // If  we're changing the layer's name or copying it, we need both a layer and a spread
01577         case LAYER_CHANGE_NAME:
01578         case LAYER_COPY:
01579             ERROR3IF(pLayer  == NULL, "I don't have a layer");
01580             ERROR3IF(pSpread == NULL, "I dont' have a spread");
01581             ok = ((pLayer != NULL) && (pSpread != NULL));
01582             break;
01583 
01584         case LAYER_NEW:
01585             ERROR3IF(pSpread == NULL, "I dont' have a spread");
01586             ok = (pSpread != NULL);
01587             break;
01588 
01589         default:
01590             ERROR3("The layer name dialog can't process the given reason");
01591             ok = FALSE;
01592             break;
01593     }
01594 
01595     if (ok) ok = Create();
01596 //  if (ok) Open();
01597 
01598     if (!ok)            // Could not create 
01599     {
01600         InformError(0,_R(IDS_OK));
01601         End();          // End the operation 
01602     }
01603 //  else
01604 //  {
01605 //      LayerNameDlg::IsOpen        = TRUE;
01606 //      LayerNameDlg::pLayerNameDlg = this;
01607 //  }
01608 }
01609 
01610 
01611 /********************************************************************************************
01612 
01613 >   void LayerNameDlg::ShowLayerDetails()
01614 
01615     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01616     Created:    9/8/94
01617     Inputs:     - 
01618     Outputs:    -
01619     Returns:    -
01620     Purpose:    Shows layer details in the dialog
01621     Errors:     -
01622     SeeAlso:    -
01623 
01624 ********************************************************************************************/
01625 
01626 void LayerNameDlg::ShowLayerDetails()
01627 {
01628     String_256 Name;
01629 
01630     switch (Reason)
01631     {
01632         case LAYER_CHANGE_NAME:
01633             Name = pLayer->GetLayerID();
01634             break;
01635 
01636         case LAYER_COPY:
01637             CreateUniqueLayerCopyName(pLayer->GetLayerID(), &Name);
01638             break;
01639             break;
01640 
01641         case LAYER_NEW:
01642             Name = LayerSGallery::CreateUniqueLayerID(pSpread);
01643             break;
01644 
01645         default:
01646             ERROR3("Unknown OpLayerGalReason reason");
01647             break;
01648     }
01649 
01650     SetStringGadgetValue(_R(IDC_LAYER_NAME),Name);
01651 }
01652 
01653 
01654 
01655 /********************************************************************************************
01656 >   static void LayerNameDlg::CreateUniqueLayerCopyName(const String_256& strName,
01657                                                         String_256* pCopyName)
01658     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
01659     Created:    30/6/95
01660     Inputs:     strName         the name of the layer to be copied          
01661     Outputs:    pCopyName       the name of copy of the layer, which is unique
01662     Purpose:    Generates a unique name for a layer to be copied.
01663     SeeAlso:    LayerNameDlg::ShowLayerDetails
01664 ********************************************************************************************/
01665 
01666 void LayerNameDlg::CreateUniqueLayerCopyName(const String_256& strName, String_256* pCopyName)
01667 {
01668     // First, check for junk inputs.
01669     ERROR3IF(pCopyName == NULL,
01670                 "Null output String_256* in LayerNameDlg::CreateUniqueLayerCopyName");
01671 
01672     // The rest of this function is a complete bodge, because to do this properly would
01673     // mean a rewrite of the brain-damaged way that layers are named, copied, and
01674     // identified as unique.  So what I'm going to do is prepend a "Copy of " string
01675     // and make sure it doesn't overflow when I do.
01676     pCopyName->Load(_R(IDS_LAYERGAL_COPYOF));
01677     String_256 strNewName;
01678     if ((strName.Length() + pCopyName->Length()) >= pCopyName->MaxLength())
01679     {
01680         // We must truncate so it won't overflow.
01681         strName.Left(&strNewName, pCopyName->MaxLength() - pCopyName->Length());
01682     }
01683     else
01684     {
01685         // We don't need to truncate.
01686         strNewName = strName;
01687     }
01688 
01689     // Prepend and return the result.
01690     *pCopyName += strNewName;
01691 }
01692 
01693 
01694 
01695 /********************************************************************************************
01696 
01697 >   void LayerNameDlg::CommitDialogValues()
01698 
01699     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01700     Created:    9/8/94
01701     Inputs:     - 
01702     Outputs:    -
01703     Returns:    -
01704     Purpose:    Takes the values in the dialog and sets the Layer object
01705                 accordingly.
01706                 Called when the OK button is selected
01707     Errors:     -
01708     SeeAlso:    -
01709 
01710 ********************************************************************************************/
01711 
01712 void LayerNameDlg::CommitDialogValues()
01713 {
01714     String_256 NewName;
01715 //  TCHAR* pD = NewName;
01716     BOOL Valid;
01717 
01718     // Get the string from the layer name dialog
01719     NewName = GetStringGadgetValue(_R(IDC_LAYER_NAME),&Valid);
01720 
01721     // If we're changing the layer's name, but the name hasn't changed, 
01722     // return without doing anything
01723     if (Reason == LAYER_CHANGE_NAME)
01724     {
01725         if (pLayer->GetLayerID() == NewName)
01726             return;
01727     }
01728 
01729     // Initialise the param structure
01730     OpLayerGalParam Param(Reason, pSpread);
01731     Param.pLayer = pLayer;
01732 
01733     // Change the name to the new name
01734     Param.Status.StringLayerID = NewName;
01735 
01736     // If we are copying or creating a new the layer, set up the context node 
01737     // and where to place it relative to the context node
01738     if (Reason == LAYER_COPY || Reason == LAYER_NEW)
01739     {
01740         Param.pContextNode  = pSpread;
01741         Param.AttDir        = LASTCHILD;
01742     }
01743 
01744     // Invoke the operation
01745     OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_LAYERGALCHANGE); 
01746     if (pOpDesc != NULL)
01747         pOpDesc->Invoke((OpParam*)&Param);
01748     else
01749     {
01750         ERROR3("Couldn't find OPTOKEN_LAYERGALCHANGE op descriptor");
01751     }
01752 }
01753 
01754 //-----------------------------------------------------------------------------------------------
01755 //-----------------------------------------------------------------------------------------------
01756 //-----------------------------------------------------------------------------------------------
01757 //-----------------------------------------------------------------------------------------------
01758 
01759 // OpDisplayLayerGallery - the operation that is used to display the layers gallery
01760 
01761 /********************************************************************************************
01762 
01763 >   BOOL OpDisplayLayerGallery::Init()
01764 
01765     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01766     Created:    11/8/94
01767     Inputs:     -
01768     Outputs:    -
01769     Returns:    TRUE if the operation could be successfully initialised 
01770                 FALSE if no more memory could be allocated 
01771                 
01772     Purpose:    OpDisplayLayerGallery initialiser method
01773     Errors:     ERROR will be called if there was insufficient memory to allocate the 
01774                 operation.
01775     SeeAlso:    -
01776 
01777 ********************************************************************************************/
01778 
01779 BOOL OpDisplayLayerGallery::Init()
01780 {
01781     return (RegisterOpDescriptor(
01782                                 0,
01783                                 _R(IDS_DISPLAY_LAYER_GALLERY),
01784                                 CC_RUNTIME_CLASS(OpDisplayLayerGallery),
01785                                 OPTOKEN_DISPLAYLAYERGALLERY,
01786                                 OpDisplayLayerGallery::GetState,
01787                                 0,  /* help ID */
01788                                 _R(IDBBL_DISPLAY_LAYER_GALLERY),
01789                                 _R(IDC_BTN_SGLAYER), // UINT32 resourceID = 0,  // resource ID
01790                                 _R(IDC_BTN_SGLAYER), // UINT32 controlID = 0,   // control ID
01791                                 SYSTEMBAR_ILLEGAL,    // SystemBarType GroupBarID = SYSTEMBAR_ILLEGAL,  // group bar ID
01792                                 TRUE,     // BOOL ReceiveMessages = TRUE,   // BODGE
01793                                 FALSE,    // BOOL Smart = FALSE,
01794                                 TRUE,     // BOOL Clean = TRUE,   
01795                                 NULL,     // OpDescriptor *pVertOpDesc = NULL,
01796                                 0,    // UINT32 OneOpenInstID = 0,      
01797                                 0,    // UINT32 AutoStateFlags = 0,
01798                                 TRUE      // BOOL fCheckable = FALSE
01799                                 )
01800                                 );
01801 }               
01802     
01803 /********************************************************************************************
01804 
01805 >   OpState OpDisplayLayerGallery::GetState(String_256*, OpDescriptor*)
01806 
01807     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01808     Created:    11/8/94
01809     Inputs:     -
01810     Outputs:    -
01811     Returns:    The state of the OpDisplayLayerGallery operation
01812     Purpose:    For finding the OpDisplayLayerGallery's state. 
01813     Errors:     -
01814     SeeAlso:    -
01815 
01816 ********************************************************************************************/
01817 
01818 OpState OpDisplayLayerGallery::GetState(String_256* UIDescription, OpDescriptor*)
01819 {
01820     // The Layer gallery op has been modified so that 
01821     // it can only be opened on a layer based document.
01822     
01823     OpState OpSt;  
01824 
01825     // Flag variables.
01826     BOOL LayerDoc = TRUE;       // Flag to determine whether this is a layer document.
01827 
01828     // Get a ptr to the selected spread
01829     Spread* pSpread = Document::GetSelectedSpread();
01830 
01831     // Ensure a valid spread ptr.
01832     if(pSpread)
01833     {
01834         // Are there any frame layers?
01835         Layer* pFrameLayer = pSpread->FindFirstFrameLayer();    
01836 
01837         //If a frame layer exists, then this is an animation doc.
01838         if (pFrameLayer)
01839             LayerDoc = FALSE;
01840     }
01841 
01842     if(LayerDoc)
01843     {
01844         // If the gallery is currenty open, then the menu item should be ticked
01845         SuperGallery* pSuperGallery = SuperGallery::FindSuperGallery(_R(IDD_LAYERSGALLERY));
01846 
01847         if (pSuperGallery != NULL)
01848         {
01849             if (pSuperGallery->GetRuntimeClass() == CC_RUNTIME_CLASS(LayerSGallery))
01850             OpSt.Ticked = pSuperGallery->IsVisible();
01851         }
01852 
01853         // If there are no open documents, you can't toggle the gallery
01854         OpSt.Greyed = (Document::GetSelected() == NULL);
01855     }
01856     else
01857     {
01858         // This is a frame document, so set the menu item to the correct state.
01859         OpSt.Ticked = FALSE;
01860         OpSt.Greyed = TRUE;
01861         *UIDescription = String_256 (_R(IDS_NO_LAYERS));
01862     }
01863 
01864     return(OpSt);   
01865 }
01866 
01867 /********************************************************************************************
01868 
01869 >   void OpDisplayLayerGallery::Do(OpDescriptor*)
01870 
01871     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01872     Created:    11/8/94
01873     Inputs:     -
01874     Outputs:    -
01875     Returns:    -
01876     Purpose:    Displays the layers gallery
01877     Errors:     -
01878     SeeAlso:    -
01879 
01880 ********************************************************************************************/
01881 
01882 void OpDisplayLayerGallery::Do(OpDescriptor*)
01883 {
01884     SuperGallery* pSuperGallery = SuperGallery::FindSuperGallery(_R(IDD_LAYERSGALLERY));
01885 
01886     if (!pSuperGallery) pSuperGallery = new LayerSGallery;
01887 
01888     if (pSuperGallery != NULL)
01889     {
01890         if (pSuperGallery->GetRuntimeClass() == CC_RUNTIME_CLASS(LayerSGallery))
01891         {
01892             // Toggle the visible state of the gallery window
01893             pSuperGallery->SetVisibility( !pSuperGallery->IsVisible() );
01894         }
01895         else
01896         {
01897             ERROR3("Got the layer gallery but it's not of the LayerSGallery class");
01898         }
01899 
01900         SGInit::UpdateGalleryButton(_R(OPTOKEN_DISPLAYLAYERGALLERY), pSuperGallery->IsVisible());
01901     }
01902 
01903     ERROR3IF(pSuperGallery == NULL,"Couldn't find the layer gallery bar");
01904 
01905     End();
01906 }
01907 
01908 PORTNOTE("galleries", "disable frame gallery")
01909 #ifndef EXCLUDE_FROM_XARALX
01910 //-----------------------------------------------------------------------------------------------
01911 //-----------------------------------------------------------------------------------------------
01912 //-----------------------------------------------------------------------------------------------
01913 //-----------------------------------------------------------------------------------------------
01914 
01915 // OpDisplayFrameGallery - the operation that is used to display the frame gallery
01916 
01917 /********************************************************************************************
01918 
01919 >   BOOL OpDisplayFrameGallery::Init()
01920 
01921     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01922     Created:    16/4/97
01923     Inputs:     -
01924     Outputs:    -
01925     Returns:    TRUE if the operation could be successfully initialised 
01926                 FALSE if no more memory could be allocated 
01927                 
01928     Purpose:    OpDisplayFrameGallery initialiser method
01929     Errors:     ERROR will be called if there was insufficient memory to allocate the 
01930                 operation.
01931     SeeAlso:    -
01932 
01933 ********************************************************************************************/
01934 
01935 BOOL OpDisplayFrameGallery::Init()
01936 {
01937     return (RegisterOpDescriptor(
01938                                 0,
01939                                 _R(IDS_DISPLAY_FRAME_GALLERY),
01940                                 CC_RUNTIME_CLASS(OpDisplayFrameGallery),
01941                                 OPTOKEN_DISPLAYFRAMEGALLERY,
01942                                 OpDisplayFrameGallery::GetState,
01943                                 _R(IDH_Gallery_Frame),  /* help ID */
01944                                 _R(IDBBL_DISPLAY_FRAME_GALLERY),
01945                                 0   /* bitmap ID */));
01946 }               
01947     
01948 /********************************************************************************************
01949 
01950 >   OpState OpDisplayFrameGallery::GetState(String_256*, OpDescriptor*)
01951 
01952     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01953     Created:    16/4/97
01954     Inputs:     -
01955     Outputs:    -
01956     Returns:    The state of the OpDisplayFrameGallery operation
01957     Purpose:    For finding the OpDisplayFrameGallery's state. 
01958     Errors:     -
01959     SeeAlso:    -
01960 
01961 ********************************************************************************************/
01962 
01963 OpState OpDisplayFrameGallery::GetState(String_256* UIDescription, OpDescriptor*)
01964 {
01965     // The frame gallery op has been modified so that 
01966     // it can only be opened on a frame based document.
01967 
01968     OpState OpSt;
01969 
01970 #ifdef WEBSTER
01971         
01972     // If the gallery is currenty open, then the menu item should be ticked
01973     SuperGallery* pSuperGallery = SuperGallery::FindSuperGallery(_R(IDD_LAYERSGALLERY));
01974 
01975     if (pSuperGallery != NULL)
01976     {
01977         if (pSuperGallery->GetRuntimeClass() == CC_RUNTIME_CLASS(FrameSGallery))
01978             OpSt.Ticked = pSuperGallery->IsVisible();
01979     }
01980 
01981     // If there are no open documents, you can't toggle the gallery
01982     OpSt.Greyed = (Document::GetSelected() == NULL);
01983 
01984 #else
01985 
01986     // Flag variables.
01987     BOOL FramedDoc = FALSE;     // Flag to determine whether this is a framelayer(animation) document.
01988 
01989     // Get a ptr to the selected spread
01990     Spread* pSpread = Document::GetSelectedSpread();
01991 
01992     // Ensure a valid spread ptr.
01993     if(pSpread)
01994     {
01995         // Are there any frame layers?
01996         Layer* pFrameLayer = pSpread->FindFirstFrameLayer();    
01997 
01998         //If a frame layer exists, then this is an animation doc.
01999         if (pFrameLayer)
02000             FramedDoc = TRUE;
02001     }
02002 
02003     // If this is an animation Doc, then set the correct menu item state.
02004     if(FramedDoc)
02005     {
02006         // If the gallery is currenty open, then the menu item should be ticked
02007         String_32 Name(_R(IDS_FRAMEGAL_GALLNAME));
02008         SuperGallery* pSuperGallery = SuperGallery::FindSuperGallery(Name);
02009 
02010         if (pSuperGallery != NULL)
02011         {
02012             if (pSuperGallery->GetRuntimeClass() == CC_RUNTIME_CLASS(FrameSGallery))
02013                 OpSt.Ticked = pSuperGallery->IsVisible();
02014         }
02015 
02016         // If there are no open documents, you can't toggle the gallery
02017         OpSt.Greyed = (Document::GetSelected() == NULL);
02018     }
02019     else
02020     {
02021         // This is a layer document, so the Frame Gallery isn't needed.
02022         //  Set up item up as greyed and give a reason.
02023         OpSt.Ticked = FALSE;
02024         OpSt.Greyed = TRUE;
02025         *UIDescription = String_256 (_R(IDS_NO_FRAMES));
02026     }
02027 
02028 #endif
02029 
02030     // Lets go back..
02031     return(OpSt);   
02032 }
02033 
02034 /********************************************************************************************
02035 
02036 >   void OpDisplayFrameGallery::Do(OpDescriptor*)
02037 
02038     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
02039     Created:    16/4/97
02040     Inputs:     -
02041     Outputs:    -
02042     Returns:    -
02043     Purpose:    Displays the frame gallery
02044     Errors:     -
02045     SeeAlso:    -
02046 
02047 ********************************************************************************************/
02048 
02049 void OpDisplayFrameGallery::Do(OpDescriptor*)
02050 {
02051     String_32 Name(_R(IDS_FRAMEGAL_GALLNAME));
02052     SuperGallery* pSuperGallery = SuperGallery::FindSuperGallery(Name);
02053 
02054     if (pSuperGallery != NULL)
02055     {
02056         if (pSuperGallery->GetRuntimeClass() == CC_RUNTIME_CLASS(FrameSGallery))
02057         {
02058             GIFAnimationPropertyTabs::SetFrameGalleryOpen(FALSE);
02059 
02060             // Toggle the visible state of the gallery window
02061             pSuperGallery->SetVisibility( !pSuperGallery->IsVisible() );
02062         }
02063         else
02064         {
02065             ERROR3("Got the frame gallery but it's not of the LayerSGallery class");
02066         }
02067 
02068         SGInit::UpdateGalleryButton(_R(OPTOKEN_DISPLAYFRAMEGALLERY), pSuperGallery->IsVisible());
02069 
02070         GIFAnimationPropertyTabs::SetFrameGalleryOpen(TRUE);
02071     }
02072 
02073     ERROR3IF(pSuperGallery == NULL,"Couldn't find the frame gallery bar");
02074 
02075     End();
02076 }
02077 #endif
02078 
02079 //-----------------------------------------------------
02080 //-----------------------------------------------------
02081 //-----------------------------------------------------
02082 //-----------------------------------------------------
02083 
02084 /********************************************************************************************
02085 
02086 >   LayerStateAction::LayerStateAction()
02087 
02088     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02089     Created:    7/3/95
02090     Inputs:     -
02091     Outputs:    -
02092     Returns:    -
02093     Purpose:    Constructor for the action
02094     Errors:     -
02095     SeeAlso:    -
02096 
02097 ********************************************************************************************/
02098 
02099 LayerStateAction::LayerStateAction()
02100 {
02101 }
02102 
02103 
02104 /********************************************************************************************
02105 
02106 >   ActionCode LayerStateAction::Init(UndoableOperation* pOp,
02107                                         ActionList* pActionList,
02108                                         OpLayerGalParam EntryParam)
02109 
02110     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02111     Created:    7/3/95
02112     Inputs:     pOp         = ptr to the operation to which this action belongs
02113                 pActionList = ptr to action list to which this action should be added
02114                 Param       = Contains all the info needed to change the layer
02115     Outputs:    -
02116     Returns:    ActionCode, one of AC_OK, AC_NO_RECORD or AC_FAIL
02117     Purpose:    This is the function which creates an instance of this action. If there is no room 
02118                 in the undo buffer (which is determined by the base class Init function called within)
02119                 the function will either return AC_NO_RECORD which means the operation can continue, 
02120                 but no undo information needs to be stored, or AC_OK which means the operation should
02121                 continue AND record undo information. If the function returns AC_FAIL, there was not 
02122                 enough memory to record the undo information, and the user has decided not to continue
02123                 with the operation.
02124 
02125                 This changes a flag associated with the layer to the value in 'NewState' in an
02126                 undoable way
02127     Errors:     -
02128     SeeAlso:    Action::Init()
02129 
02130 ********************************************************************************************/
02131 
02132 
02133 
02134 ActionCode LayerStateAction::Init(  UndoableOperation* pOp,
02135                                     ActionList* pActionList,
02136                                     OpLayerGalParam EntryParam)
02137 {
02138     UINT32 ActSize = sizeof(LayerStateAction);
02139 
02140     LayerStateAction* pNewAction;
02141     ActionCode Ac = Action::Init(pOp,pActionList,ActSize,CC_RUNTIME_CLASS(LayerStateAction),(Action**)&pNewAction);
02142 
02143     if (Ac != AC_FAIL && pNewAction != NULL)
02144     {
02145         pNewAction->Param = EntryParam;
02146         OpLayerGalParam& Param = pNewAction->Param;
02147 
02148         switch (Param.GetReason())
02149         {
02150             case LAYER_VISIBLE:
02151                 ERROR3IF(Param.pLayer == NULL,"Param.pLayer == NULL");
02152 
02153                 if (Param.pLayer != NULL)
02154                     LayerSGallery::DoChangeVisible(Param.pLayer,Param.NewState);
02155                 break;
02156 
02157             case LAYER_LOCKED:
02158                 ERROR3IF(Param.pLayer == NULL,"Param.pLayer == NULL");
02159 
02160                 if (Param.pLayer != NULL)
02161                     LayerSGallery::DoChangeLocked(Param.pLayer,Param.NewState);
02162                 break;
02163 
02164             case LAYER_ALLVISIBLE:
02165             case FRAME_ALLVISIBLE:
02166                 if (Param.pLayerSGal != NULL)
02167                 {
02168                     Param.pLayerSGal->DoChangeAllVisible(Param.NewState);
02169                     Param.pLayerSGal->ForceRedrawOfList();
02170                 }
02171                 break;
02172 
02173             case LAYER_MULTILAYER:
02174             case FRAME_MULTILAYER:
02175                 if (Param.pLayerSGal != NULL)
02176                 {
02177                     Param.pLayerSGal->DoChangeMultilayer(Param.NewState);
02178                     Param.pLayerSGal->ForceRedrawOfList();
02179                 }
02180                 break;
02181 
02182             case FRAME_MOVE:
02183             case LAYER_MOVE:
02184             case LAYER_TOGGLEBACKGROUND:
02185                 ERROR3IF(Param.pLayer == NULL,"Param.pLayer == NULL");
02186                 ERROR3IF(Param.pLayerSGal == NULL,"Param.pLayerSGal == NULL");
02187 
02188                 if (Param.pLayer != NULL)
02189                 {
02190                     if (Param.GetReason() == FRAME_MOVE)
02191                     {
02192                         Param.pLayer->SetBackground(FALSE);
02193                         Param.pLayer->SetPrintable(!Param.pLayer->IsPrintable());
02194                     }
02195                     else
02196                     {
02197                         Param.pLayer->SetBackground(!Param.pLayer->IsBackground());
02198                         Param.pLayer->SetPrintable(!Param.pLayer->IsPrintable());
02199                     }
02200                     // Cause the layer gallery items to be recreated
02201                     Param.pLayerSGal->CreateNewSubtree(Param.pLayer->FindDocument());
02202                 }
02203                 break;
02204 
02205             case LAYER_CHANGE:
02206                 ERROR3IF(Param.pLayer == NULL,"Param.pLayer == NULL");
02207 
02208                 if (Param.pLayer != NULL)
02209                 {
02210                     Param.OldVisibleState   = Param.pLayer->IsVisible();
02211                     Param.OldLockedState    = Param.pLayer->IsLocked();
02212                     Param.OldName           = Param.pLayer->GetLayerID();
02213 
02214                     LayerSGallery::DoChangeVisible(Param.pLayer,Param.VisibleState);
02215                     LayerSGallery::DoChangeLocked(Param.pLayer,Param.LockedState);
02216                     Param.pLayer->SetLayerID(Param.NewName);
02217                 }
02218                 break;
02219 
02220             case LAYER_SOLID:
02221                 ERROR3IF(Param.pLayer == NULL,"Param.pLayer == NULL");
02222 
02223                 if (Param.pLayer != NULL)
02224                 {
02225 PORTNOTE("galleries", "Disabled frame gallery")
02226 #ifndef EXCLUDE_FROM_XARALX
02227                     FrameSGallery::DoChangeSolid(Param.pLayer,Param.NewState);
02228 #endif
02229                     Param.pLayer->SetEdited(TRUE);
02230                     Param.pLayer->SetFrame(TRUE);   // double check this
02231 #ifdef _DEBUG
02232                     // Tell the frame gallery to update its display of the frame
02233                     BROADCAST_TO_ALL(LayerMsg(Param.pLayer, LayerMsg::REDRAW_LAYER));
02234 #endif
02235                 }
02236                 break;
02237 
02238             case LAYER_OVERLAY:
02239                 ERROR3IF(Param.pLayer == NULL,"Param.pLayer == NULL");
02240 
02241                 if (Param.pLayer != NULL)
02242                 {
02243 PORTNOTE("galleries", "Disabled frame gallery")
02244 #ifndef EXCLUDE_FROM_XARALX
02245                     FrameSGallery::DoChangeOverlay(Param.pLayer,Param.NewState);
02246 #endif
02247                     Param.pLayer->SetEdited(TRUE);
02248                     Param.pLayer->SetFrame(TRUE);   // double check this
02249 #ifdef _DEBUG
02250                     // Tell the frame gallery to update its display of the frame
02251                     BROADCAST_TO_ALL(LayerMsg(Param.pLayer, LayerMsg::REDRAW_LAYER));
02252 #endif
02253                 }
02254                 break;
02255 
02256             case LAYER_MAKEFRAME:
02257                 ERROR3IF(Param.pLayer == NULL,"Param.pLayer == NULL");
02258                 if (Param.pLayer != NULL)
02259                 {
02260                     Param.pLayer->SetFrame(Param.NewState);
02261                 }
02262                 break;
02263 
02264             case LAYER_ACTIVE:
02265                 ERROR3IF(Param.pLayer == NULL,"Param.pLayer == NULL");
02266                 if (Param.pLayer != NULL)
02267                 {
02268                     Param.pLayer->SetActive(Param.NewState);
02269 
02270                     // Ensure that the gallery is updated with the new active layer details
02271                     BROADCAST_TO_ALL(LayerMsg(Param.pLayer, LayerMsg::UPDATE_ACTIVE_LAYER));
02272                 }
02273                 break;
02274 
02275             default:
02276                 ERROR3("Unknown Reason code");
02277                 break;
02278         }
02279     }
02280 
02281     return Ac;
02282 }
02283 
02284 /********************************************************************************************
02285 
02286 >   ActionCode LayerStateAction::Execute();
02287 
02288     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02289     Created:    7/3/95
02290     Inputs:     -
02291     Outputs:    -
02292     Returns:    ActionCode, one of AC_OK, AC_NO_RECORD or AC_FAIL
02293     Purpose:    Executes the action.  
02294                 Puts the action's layer's visible state to the opposite setting.
02295     Errors:     -
02296     SeeAlso:    Action::Init()
02297 
02298 ********************************************************************************************/
02299 
02300 ActionCode LayerStateAction::Execute()
02301 {
02302     ActionCode Ac = AC_FAIL;
02303 
02304     if (pOperation->IS_KIND_OF(UndoableOperation))
02305     {
02306         Param.NewState = !Param.NewState;
02307 
02308         // Swap LAYER_CHANGE vars
02309         Swap(Param.VisibleState,Param.OldVisibleState);
02310         Swap(Param.LockedState, Param.OldLockedState);
02311         String_256 Str      = Param.OldName;
02312         Param.OldName       = Param.NewName;
02313         Param.NewName       = Str;
02314 
02315         Ac = LayerStateAction::Init((UndoableOperation*)pOperation,pOppositeActLst,Param);
02316 
02317         if (Ac != AC_FAIL)
02318         {
02319             LayerSGallery*  pGal = Param.pLayerSGal;
02320 
02321             if (pGal != NULL)
02322             {
02323                 pGal->ForceRedrawOfList();
02324 
02325                 Document* pDoc = GetWorkingDoc();
02326 
02327                 if (pDoc != NULL && pGal->IsVisible())
02328                 {
02329                     pGal->SetBoolGadgetSelected(_R(IDC_BTN_MULTILAYER),!(pDoc->IsMultilayer() == 0));
02330                     pGal->SetBoolGadgetSelected(_R(IDC_BTN_ALLVISIBLE),!(pDoc->IsAllVisible() == 0));
02331                 }
02332             }
02333         }
02334     }
02335     else
02336     {
02337         ERROR3("LayerStateAction::Execute() called with op that's not an undoable op");
02338     }
02339 
02340     return Ac;
02341 }
02342 
02343 LayerStateAction::~LayerStateAction()
02344 {
02345 }

Generated on Sat Nov 10 03:45:36 2007 for Camelot by  doxygen 1.4.4