filelist.cpp

Go to the documentation of this file.
00001 // $Id: filelist.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 operation to handle the Recent File List
00099 
00100 /*
00101 */
00102 
00103 #include "camtypes.h"
00104 #include "filelist.h"
00105 
00106 #include "camelot.h"
00107 #include "camdoc.h"
00108 //#include "document.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00109 //#include "docview.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00110 //#include "mario.h"
00111 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00112 #include "bubbleid.h"
00113 
00114 // An implement to match the Declare in the .h file.
00115 CC_IMPLEMENT_DYNCREATE(FileListOp, Operation)
00116 
00117 // This will get Camelot to display the filename and linenumber of any memory allocations
00118 #define new CAM_DEBUG_NEW
00119 
00120 
00121 
00122 
00123 // Here is a macro to make the ::Init function a little neater in this class.
00124 #define REG_FILELISTOP(a) RegisterOpDescriptor(0, _R(IDS_FILE_MRU_FILE), CC_RUNTIME_CLASS(FileListOp), (a), FileListOp::GetState, 0, _R(IDBBL_FILEOP), 0)
00125 
00126 
00127 
00128 
00129 /*********************************************************************************************
00130 
00131     Preference: MaxFileListSize
00132     Section:    Recent File List
00133     Range:      1-9
00134     Purpose:    Describes how many files will be displayed in the Recent file list.
00135 
00136 **********************************************************************************************/ 
00137 
00138 INT32 FileListOp::MaxFileListSize = 4;
00139 
00140 
00141 
00142 
00143 /********************************************************************************************
00144 
00145 >   FileListOp::FileListOp()
00146 
00147     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00148     Created:    3/1/95
00149     Purpose:    Constructor for the File List Operation.
00150 
00151 ********************************************************************************************/
00152 
00153 FileListOp::FileListOp()
00154 {
00155 }
00156 
00157 
00158 /********************************************************************************************
00159 
00160 >   static BOOL FileListOp::Init()
00161 
00162     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00163     Created:    3/1/95
00164     Returns:    TRUE if it inited OK, FALSE if not.
00165     Purpose:    Initialises the FileList Operation. It tries to create several OpDescriptors
00166                 that will be associated with each of the menu items on the recent file list.
00167                 They will all invoke this operation and the operation will try to work out
00168                 which one invoked it.
00169 
00170 ********************************************************************************************/
00171 
00172 BOOL FileListOp::Init()
00173 {
00174     // Register some preferences
00175     if (Camelot.DeclareSection(TEXT("Recent File List"), 3))
00176     {
00177         Camelot.DeclarePref(NULL, TEXT("FileListSize"), &MaxFileListSize, 1, 9);
00178     }
00179 
00180     // Try and create an OpDescriptor. This uses a macro that is define at the top of this file.
00181     BOOL Worked = REG_FILELISTOP(OPTOKEN_MRU_FILE1);
00182 
00183     // See if it worked
00184     ERROR1IF(!Worked, FALSE, _R(IDE_NOMORE_MEMORY));
00185 
00186     // And do the same for all the others
00187     Worked = REG_FILELISTOP(OPTOKEN_MRU_FILE2);
00188     ERROR1IF(!Worked, FALSE, _R(IDE_NOMORE_MEMORY));
00189 
00190     // File 3
00191     Worked = REG_FILELISTOP(OPTOKEN_MRU_FILE3);
00192     ERROR1IF(!Worked, FALSE, _R(IDE_NOMORE_MEMORY));
00193 
00194     // File 4
00195     Worked = REG_FILELISTOP(OPTOKEN_MRU_FILE4);
00196     ERROR1IF(!Worked, FALSE, _R(IDE_NOMORE_MEMORY));
00197 
00198     // File 5
00199     Worked = REG_FILELISTOP(OPTOKEN_MRU_FILE5);
00200     ERROR1IF(!Worked, FALSE, _R(IDE_NOMORE_MEMORY));
00201 
00202     // File 6
00203     Worked = REG_FILELISTOP(OPTOKEN_MRU_FILE6);
00204     ERROR1IF(!Worked, FALSE, _R(IDE_NOMORE_MEMORY));
00205 
00206     // File 7
00207     Worked = REG_FILELISTOP(OPTOKEN_MRU_FILE7);
00208     ERROR1IF(!Worked, FALSE, _R(IDE_NOMORE_MEMORY));
00209 
00210     // File 8
00211     Worked = REG_FILELISTOP(OPTOKEN_MRU_FILE8);
00212     ERROR1IF(!Worked, FALSE, _R(IDE_NOMORE_MEMORY));
00213 
00214     // File 9
00215     Worked = REG_FILELISTOP(OPTOKEN_MRU_FILE9);
00216     ERROR1IF(!Worked, FALSE, _R(IDE_NOMORE_MEMORY));
00217 
00218     // All worked
00219     return TRUE;
00220 }
00221 
00222 
00223 
00224 /********************************************************************************************
00225 
00226 >   OpState FileListOp::GetState(String_256*, OpDescriptor*)
00227 
00228     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00229     Created:    3/1/95
00230     Purpose:    Descides if this operation shold be available or not
00231     Errors:     -
00232     SeeAlso:    -
00233 
00234 ********************************************************************************************/
00235 
00236 OpState FileListOp::GetState(String_256* Title, OpDescriptor* pOp)
00237 {
00238     OpState State;
00239 
00240     // Get the first 2 chars of the opdescriptors description as this holds the
00241     // file number of the recent file.
00242     TCHAR FileNum[3];
00243     camStrncpy(FileNum, pOp->Token, 2);
00244     FileNum[2] = 0;
00245 
00246     // make sure that it contains digits.
00247     if (isdigit(FileNum[0]) && isdigit(FileNum[1]))
00248     {
00249         // Find out which number was chosen
00250         TCHAR *pszMark;
00251         INT32 Index = camStrtol( FileNum, &pszMark, 10 );
00252         
00253         // Only the first 'MaxFileListSize' items will appear
00254         if (Index > MaxFileListSize)
00255             State.RemoveFromMenu = TRUE;
00256         else
00257         {
00258             // Change the menu string to whatever it needs to be
00259             CCamApp* pApp = (CCamApp*)&AfxGetApp();
00260             if (!pApp->GetRecentFileText(Index-1, Title))
00261             {
00262                 State.Greyed = TRUE;
00263 
00264                 // if this is the first item in the list, then it wants to stay in the menu, only greyed
00265                 if (Index!=1)
00266                     State.RemoveFromMenu = TRUE;
00267             }
00268         }
00269     }
00270 
00271     return State;
00272 }
00273 
00274 
00275 
00276 /********************************************************************************************
00277 
00278 >   void FileListOp::Do(OpDescriptor* pOpDesc)
00279 
00280     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00281     Created:    3/1/95
00282     Inputs:     pOpDesc - The opdescriptor that invoked this operation.
00283     Purpose:    Attempts to load a file that was in the Recent file list.
00284 
00285 ********************************************************************************************/
00286 
00287 void FileListOp::Do(OpDescriptor* pOpDesc)
00288 {
00289     // Get the first 2 chars of the opdescriptors description as this holds the
00290     // file number of the recent file.
00291     TCHAR FileNum[3];
00292     BOOL WorkedOK = FALSE;
00293     camStrncpy(FileNum, pOpDesc->Token, 2);
00294     FileNum[2] = 0;
00295 
00296     TRACEUSER( "jlh92", _T("Op = %s\n"), FileNum );
00297 
00298     // make sure that it contains digits.
00299     if (isdigit(FileNum[0]) && isdigit(FileNum[1]))
00300     {
00301         // Find out which number was chosen
00302         TCHAR *pszMark;
00303         INT32 RecentFileNum = camStrtol( FileNum, &pszMark, 10 );
00304 
00305         TRACEUSER( "jlh92", _T("Recent = %d\n"), RecentFileNum );
00306 
00307         // Ask the app to load the file specified (it will look up the file name etc)
00308         WorkedOK = AfxGetApp().OnRecentFile(RecentFileNum-1);
00309         CCamDoc::EnableRemoveUntouchedDocs();
00310     }
00311 
00312     // See if it worked
00313     if (!WorkedOK)
00314     {
00315         // At this point Current is NULL, so we should put it back
00316         // we have to do this as the creation of a new document went wrong, leaving the pointers upset
00317         Document* pDoc = Document::GetSelected();
00318         if (pDoc==NULL)
00319             Document::SetNoCurrent();
00320         else
00321             pDoc->SetCurrent();
00322 
00323         // Same for the view
00324         DocView* pView = DocView::GetSelected();
00325         if (pView==NULL)
00326             DocView::SetNoCurrent();
00327         else
00328             pView->SetCurrent();
00329 
00330         // and fail
00331         FailAndExecute();
00332     }
00333 
00334     // End the operations.
00335     End();
00336 }
00337 
00338 

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