sglbase.cpp

Go to the documentation of this file.
00001 // $Id: sglbase.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 // sglbase.cpp - SuperGallery Library Base class (standard library gallery stuff)
00099 
00100 #include "camtypes.h"
00101 #include "sglbase.h"
00102 #include <io.h>
00103 #include <string.h>
00104 #include <strstrea.h>
00105 #include "pathnmex.h" 
00106 #include "sgscanf.h"
00107 //#include "sgscan.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00108 //#include "galstr.h"
00109 //#include "pathname.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00110 #include "sginit.h"
00111 #include "sglcart.h"    // This .cpp file's corresponding header
00112 #include "sglib.h"
00113 //#include "sgtree.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00114 //#include "thumb.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00115 #include "thumbmsg.h"
00116 #include "grnddib.h"
00117 //#include "galres.h"
00118 //#include "richard.h"
00119 //#include "simon.h"        // _R(IDC_CONTINUE)
00120 #include "sgliboil.h"
00121 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00122 //#include "fixmem.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00123 #include "filedlgs.h"
00124 //#include "document.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00125 #include "progress.h"
00126 #include "camelot.h"
00127 
00128 #include "dragmgr.h"
00129 //#include "viewrc.h"       // FOR _R(IDC_CANDROPONPAGE)
00130 //#include "resource.h"
00131 //#include "docview.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00132 //#include "spread.h"
00133 
00134 #include "sgrmfile.h"   // For Lib settings
00135 //#include "richard2.h"
00136 //#include "richard3.h"
00137 
00138 #include "registry.h"   // SaveRegistryEntries LoadRegistryEntries
00139 #include "product.h"    // PRODUCT_GALLERY_REGISTRYKEY
00140 //#include "webster.h"
00141 #include "inetop.h"
00142 
00143 // Implement the dynamic class bits...
00144 CC_IMPLEMENT_DYNCREATE(LibraryGallery, SuperGallery)
00145 
00146 // This line mustn't go before any CC_IMPLEMENT_... macros
00147 #define new CAM_DEBUG_NEW
00148 
00149 using namespace InetUtils;
00150 
00151 // Statics...
00152 
00153 // Ask the user if they want to 'remove all existing groups before adding this one or not'
00154 BOOL LibraryGallery::AskAboutRemoving = FALSE;
00155 
00156 // Offset into folders of the first one removed by RemoveSimilarLibraryGroups
00157 INT32 LibraryGallery::OffsetOfFirstGroupRemoved = -1;
00158 
00159 // Was the first removed group selected or not ?
00160 BOOL LibraryGallery::FirstGroupRemovedSelectionState = FALSE;
00161 
00162 // Temporary bitmap used for dragging
00163 KernelBitmap *LibraryGallery::TmpDraggingBitmap = NULL;
00164 
00165 
00166 /***********************************************************************************************
00167 
00168 >   class LibraryGallery : public SuperGallery
00169 
00170     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00171     Created:    18/5/95 (Finally)
00172     Purpose:    A base library gallery class with common library gallery stuff in
00173 
00174     Notes:      SuperGalleries are specced in a number of docs including
00175                     specs\sgallery.doc ("super" gallery extensions)
00176                     specs\propui.doc  (gallery basic ui)
00177                 There is also howtouse\sgallery.doc which describes creating a supergallery
00178 
00179     SeeAlso:    SuperGallery; SGDisplayLibClipart
00180 
00181 ***********************************************************************************************/
00182 
00183 LibraryGallery::LibraryGallery()
00184 {
00185     if (!OpAddWebFolders::Init() || !OpAddWebLibrary::Init() || !OpThumbDownload::Init())
00186     {
00187         ERROR3("Failed to init web operations");
00188     }
00189 
00190     // Initialising to true means Camelot will try and download thumbnails without you having to press the 'Get Fills' 
00191     // (or equivalent) button. Because downloading is now suspended when an error occurs, offline users (with a
00192     // partial thumb stock) no longer get continual popups when scrolling down a page of unloaded thumbnails.
00193     // Fixes, with inetop.cpp change, #10471
00194     bThumbDownloading = TRUE;
00195     m_bDiscardWebFolders = FALSE;
00196 }
00197 
00198 LibraryGallery::~LibraryGallery()
00199 {
00200     TRACEUSER( "Richard", _T("~LibraryGallery called\n"));
00201 }
00202 
00203 
00204 
00205 /********************************************************************************************
00206 
00207 >   virtual MsgResult LibraryGallery::Message(Msg* Message)
00208 
00209     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00210     Created:    26/5/95
00211     Inputs:     Message - The message to handle
00212 
00213     Purpose:    Standard library gallery message handler
00214 
00215     Notes:      Any messages that this does not handle must be passed down to the
00216                 SuperGallery base class message handler.
00217 
00218                 NOTE WELL that the SuperGallery base class handler does some funky things
00219                 for us - see SuperGallery::Message - such as deleting our display subtree
00220                 for any document which dies (which, uncannily, would explain why they go
00221                 away like that when you close documents ;-), and shading the gallery when
00222                 there are no documents present. [To override this behaviour in these cases,
00223                 you should respond to the message, and return OK rather than calling the
00224                 base class message handler]
00225 
00226     SeeAlso:    SuperGallery::Message; LibClipartSGallery::Message; etc...
00227 
00228 ********************************************************************************************/
00229 
00230 MsgResult LibraryGallery::Message(Msg* Message)
00231 {
00232     // If we have no displaytree, then we have not been shown, or something terrible has
00233     // happened, so we don't bother handling any of these messages.
00234     if (DisplayTree == NULL)
00235         return(SuperGallery::Message(Message));
00236 
00237     if (IS_OUR_DIALOG_MSG(Message))
00238     {
00239         DialogMsg* Msg = (DialogMsg*)Message;
00240 
00241         switch (Msg->DlgMsg)
00242         {
00243             case DIM_LFT_BN_CLICKED:
00244                 switch (Msg->GadgetID)
00245                 {
00246                     case _R(IDC_LIBGAL_REMOVE):
00247                         RemoveSelectedLibraries(TRUE);
00248                         UpdateGRMFile();
00249                         break;
00250 // >>webster (adrian 15/12/96)
00251                     case _R(IDC_LIBGAL_WEB_CLIPART):
00252                     case _R(IDC_LIBGAL_WEB_FILLS):
00253                     case _R(IDC_LIBGAL_WEB_FONTS):
00254                         OnGetButtonClicked();
00255                         break;
00256                     case _R(IDC_LIBGAL_STOP_LOADING):
00257                         SuspendThumbnailDownloading();
00258                         break;
00259 // <<webster
00260                 }
00261         }
00262     }
00263 
00264     return SuperGallery::Message(Message);
00265 }
00266 
00267 /********************************************************************************************
00268 
00269 >   virtual BOOL LibraryGallery::CanSearchKeywords(void)
00270 
00271     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00272     Created:    26/5/95
00273 
00274     Returns:    TRUE
00275 
00276     Purpose:    Used to determine if this type of gallery supports keyword searching.
00277                 At the moment, all except the fonts gallery do.
00278                 
00279 ********************************************************************************************/
00280 
00281 BOOL LibraryGallery::CanSearchKeywords(void)
00282 {
00283     return SuperGallery::CanSearchKeywords();
00284 }
00285 
00286 
00287 /***********************************************************************************************
00288 
00289 >   virtual SGDisplayGroup *LibClipartSGallery::AddLibraryGroup(Library *LibraryToDisplay, INT32 NumItems)
00290 
00291     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00292     Created:    26/5/95
00293 
00294     Inputs:     LibraryToDisplay - Pointer to the library associated with the group
00295                 NumItems - Number of items in the group
00296     Returns:    The newly created library group, or NULL if there were problems
00297     Purpose:    Create a library group, as opposed to a display group
00298 
00299 ***********************************************************************************************/
00300 
00301 SGDisplayGroup *LibraryGallery::AddLibraryGroup(Library *LibraryToDisplay, INT32 NumItems)
00302 {
00303     return SuperGallery::AddLibraryGroup(LibraryToDisplay, NumItems);
00304 }
00305 
00306 
00307 /********************************************************************************************
00308 
00309 >   void LibrarybGallery::SelectionHasChanged(void)
00310 
00311     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00312     Created:    26/5/95
00313 
00314     Purpose:    To inform the gallery that the selection has changed in some way.
00315                 This function handles the default library gallery buttons       
00316 
00317 ********************************************************************************************/
00318 
00319 void LibraryGallery::SelectionHasChanged(void)
00320 {
00321     // Always ungrey the library menu and browse buttons
00322     EnableGadget(_R(IDC_GALLERY_MENU), TRUE);
00323     EnableGadget(_R(IDC_LIBGAL_BROWSE), TRUE);
00324 
00325     // Check if we should grey the 'remove' button
00326     INT32 Count = DisplayTree->GetSelectedGroupCount();
00327     EnableGadget(_R(IDC_LIBGAL_REMOVE), (Count > 0));
00328     EnableGadget(_R(IDC_LIBGAL_STOP_LOADING), !m_lstPendingThumbs.empty());
00329 }
00330 
00331 /********************************************************************************************
00332 
00333 >   virtual void LibraryGallery::DoShadeGallery(BOOL ShadeIt)
00334 
00335     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00336     Created:    26/4/95
00337 
00338     Purpose:    Handles the standard library gallery button shading in the gallery
00339     Notes:
00340 
00341 ********************************************************************************************/
00342 
00343 void LibraryGallery::DoShadeGallery(BOOL ShadeIt)
00344 {
00345     // make sure the standard gallery buttons are updated properly
00346     LibraryGallery::SelectionHasChanged();
00347 } 
00348 
00349 /********************************************************************************************
00350 
00351 >   virtual BOOL LibraryGallery::PreCreate(void)
00352 
00353     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00354     Created:    26/5/95
00355 
00356     Returns:    TRUE if the Gallery initialised successfully
00357                 FALSE if it should not be opened due to a failure to initialise
00358 
00359     Purpose:    The LibraryGallery PreCreate handler. This overrides the base class
00360                 PreCreate function. It is called at the very beginning of the
00361                 SuperGallery::Create method, before the window has been created.
00362 
00363     Notes:      As this is called before the window is open, it must not attempt to touch
00364                 any of the button gadgets in the window, or force redraws, etc. Also,
00365                 events cannot be passed to the tree, as the tree formatting relies on
00366                 knowing the window size - however, the tree will be reformatted and
00367                 redrawn automatically when the window is opened - this will happen shortly.
00368 
00369 ********************************************************************************************/
00370 
00371 BOOL LibraryGallery::PreCreate(void)
00372 {
00373     return SuperGallery::PreCreate();
00374 }
00375 
00376 /********************************************************************************************
00377 
00378 >   virtual BOOL LibraryGallery::ApplyAction(SGActionType Action)
00379 
00380     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00381     Created:    26/5/95
00382 
00383     Inputs:     Action - Indicates what action to apply
00384 
00385     Returns:    TRUE to indicate successful handling of the action, or
00386                 FALSE to indicate failure
00387 
00388     Purpose:    Applies certain conventional gallery actions (usually associated with
00389                 gallery buttons, for new, edit, delete, etc)
00390 
00391     SeeAlso:    SGActionType
00392 
00393 ********************************************************************************************/
00394 
00395 BOOL LibraryGallery::ApplyAction(SGActionType Action)
00396 {
00397     return SuperGallery::ApplyAction(Action);
00398 }
00399 
00400 
00401 /********************************************************************************************
00402 
00403 >   virtual BOOL LibraryGallery::AddNewLibrary(PathName *LibPath, BOOL WipeOld, SGLibType LibType, BOOL Update = FALSE)
00404 
00405     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00406     Created:    11/4/95
00407 
00408     Inputs:     LibPath - should be set to the new library location
00409                 WipeOld - will wipe the old groups from the gallery if TRUE
00410                 LibType - should be set the the library type for adding
00411                 Update  - set to true if updating rather than adding a new library. This just causes the
00412                           new group to keep the position where the old group was.
00413 
00414     Returns:    TRUE if things went OK
00415 
00416     Purpose:    This call will optionally kill all the old library groups and then recreate
00417                 library groups for the given libpath
00418     Notes:      
00419     SeeAlso:
00420 
00421 ********************************************************************************************/
00422 
00423 BOOL LibraryGallery::AddNewLibrary(PathName *LibPath, BOOL WipeOld, SGLibType LibType, BOOL Update)
00424 {
00425 /*  String_256 P(LibPath->GetPath());
00426     ERROR3_PF(("LibraryGallery::AddNewLibrary -> %s", (TCHAR *)P));*/
00427 
00428     ERROR3IF(DisplayTree==NULL, "No display tree!");
00429     if(DisplayTree == NULL) return FALSE;
00430 
00431     if(LibPath == NULL)
00432     {
00433         ERROR3("LibraryGallery::AddNewLibrary given null LibPath");
00434         return FALSE;
00435     }
00436 
00437     if(WipeOld)
00438     {
00439         // Kill all existing lib groups
00440         OpenLibFiles.DeleteAll();
00441         LibraryGallery::SelectionHasChanged();
00442     }
00443 
00444     // Open the new index and add it to the gallery
00445     LibraryFile *LibFile = new LibraryFile;
00446     if (LibFile != NULL)
00447     {
00448         // OK. Lets initialise the library. This will call us back via base-class
00449         // SuperGallery methods to add a group and items for each {sub}library
00450         // found in the given library file.
00451         if(!LibPath->IsValid())
00452         {
00453             ERROR3("LibraryGallery::AddNewLibrary given an invalid default library path");
00454             delete LibFile;
00455             InvalidateCachedFormat();
00456             ReformatAndRedrawIfNecessary();
00457             return FALSE;
00458         }
00459 
00460         String_64 SlowJob(_R(IDS_LIBRARY_SCANNING));
00461         BeginSlowJob(-1, FALSE, &SlowJob);
00462 
00463         InvalidateCachedFormat();
00464 
00465         // This will give the option of generating a new index file - Don't do the scroll redraw here...
00466         if (!LibFile->Init(this, LibPath, LibType, Update, FALSE))
00467         {
00468             // InformError if it returned FALSE? **** !!!!
00469             TRACEUSER( "Richard", _T("Problems with this new library... -> LibFile::Init returned false\n"));
00470             delete LibFile;
00471             EndSlowJob();
00472             // And force a redraw of the entire list
00473             ReformatAndRedrawIfNecessary();
00474             return FALSE;
00475         }
00476         else
00477         {
00478             SortOutGroupsAfterLibraryAdd(LibFile, Update);
00479         }
00480 
00481         EndSlowJob();
00482     }
00483     
00484     // And force a redraw of the entire list
00485     InvalidateCachedFormat();
00486     ReformatAndRedrawIfNecessary();
00487     return TRUE;
00488 }
00489 
00490 
00491 
00492 
00493 
00494 /********************************************************************************************
00495 
00496 >   virtual BOOL LibraryGallery::SortOutGroupsAfterLibraryAdd(LibraryFile *LibFile, BOOL Update)
00497 
00498     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00499     Created:    5/9/95
00500     Inputs:     LibFile - LibraryFile just created and initialised
00501                 Update  - set to true if updating rather than adding a new library. This just causes the
00502                           new group to keep the position where the old group was.
00503     Returns:    TRUE if things went OK
00504     Purpose:    This call will scroll to and redraw the newly added groups. Also, if we've just updated
00505                 the group which is being added, we'll work out where it should be placed in the
00506                 gallery...
00507     Notes:      We assume the last group added to the gallery was placed at the end of the list...
00508     
00509 ********************************************************************************************/
00510 
00511 BOOL LibraryGallery::SortOutGroupsAfterLibraryAdd(LibraryFile *LibFile, BOOL Update)
00512 {
00513     // If updating a group then adding it back to the gallery, we want it added in the position
00514     // that the old group was in...
00515     BOOL AddedLibFileToOpenLibList = FALSE;
00516 
00517     if(Update && LibraryGallery::OffsetOfFirstGroupRemoved > -1 && GetDisplayTree() != NULL)
00518     {
00519         // If we were updating a group, then adding it, we need to move the new group into the old group's
00520         // position         
00521         // Get the last group, and move it to where it should be...
00522         SGLibGroup *LastGroup = (SGLibGroup *)GetDisplayTree()->GetChild(); 
00523         if(LastGroup != NULL)
00524         {
00525             while(LastGroup->GetNext() != NULL)
00526                 LastGroup = (SGLibGroup *)LastGroup->GetNext();
00527                             
00528             LastGroup->SetSelected(LibraryGallery::FirstGroupRemovedSelectionState);
00529 
00530             // Find the group at offset 'OffsetOfFirstGroupRemoved'
00531             INT32 GroupCount = 0;
00532             SGLibGroup *Group = (SGLibGroup *)GetDisplayTree()->GetChild();     
00533             while(Group != NULL && GroupCount < LibraryGallery::OffsetOfFirstGroupRemoved)
00534             {
00535                 Group = (SGLibGroup *)Group->GetNext();
00536                 GroupCount ++;
00537             }
00538 
00539             // If we were the last item anyhow, don't worry about moving the groups and stuff...
00540             if(Group != NULL && Group->GetNext() != NULL)
00541             {
00542                 Group->MoveBefore(LastGroup);
00543                 OpenLibFiles.InsertBefore((LISTPOS)LibraryGallery::OffsetOfFirstGroupRemoved, LibFile);
00544                 AddedLibFileToOpenLibList = TRUE;
00545             }
00546         }
00547     }
00548 
00549     // Just a simple, add to bottom of list, type addition...
00550     if(!AddedLibFileToOpenLibList)
00551         OpenLibFiles.AddTail(LibFile);
00552 
00553     // Now we've fiddled about with the groups, it should be safe to redraw properly...
00554     LibFile->DoScrollRedraw();
00555 
00556     UpdateGRMFile();
00557 
00558     return TRUE;
00559 }
00560 
00561 /********************************************************************************************
00562 
00563 >   virtual SGDisplayItem *LibraryGallery::AddLibraryItem(SGDisplayGroup *LibraryGroup,
00564                                                 Library *ParentLib,
00565                                                 LibraryIndex ItemIndex)
00566     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00567     Created:    26/5/95
00568 
00569     Inputs:     LibraryGroup - The group to add the item into
00570                 ParentLib - (For cross checking inputs) the library you allege the above
00571                 group is for.
00572                 ItemIndex - The Library generated index for this item
00573 
00574     Returns:    NULL, or a pointer to the created item
00575 
00576     Purpose:    Called by the Library class to create a display item for every item in 
00577                 a newly-scanned library file. It is essentially a callback to the gallery
00578                 which requested that the library be scanned.
00579                 
00580     Notes:      This method MUST BE OVERRIDDEN by the derived gallery that opens the library,
00581                 in order to create appropriate SGDisplayItem-derived nodes for the things
00582                 in the library (e.g. a clipart library gallery will have to create items
00583                 that display clipart thumbnails)
00584 
00585     SeeAlso:    SuperGallery::AddLibraryGroup; SuperGallery::RemoveLibraryGroup
00586 
00587 ********************************************************************************************/
00588 
00589 SGDisplayItem *LibraryGallery::AddLibraryItem(SGDisplayGroup *LibraryGroup, Library *ParentLib, LibraryIndex ItemIndex, BOOL bNew)
00590 {
00591     return SuperGallery::AddLibraryItem(LibraryGroup, ParentLib, ItemIndex, bNew);
00592 }
00593 
00594 
00595 /********************************************************************************************
00596 
00597 >   virtual void LibraryGallery::HandleDragStart(DragMessage *DragMsg)
00598 
00599     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00600     Created:    26/5/95
00601 
00602     Inputs:     DragMsg - The DRAGSTARTED message that we've just recieved, indicating
00603                 the type of drag being started
00604 
00605     Purpose:    Checks a DragMessage to see if it is a colour drag.
00606                 If it is, then it creates a drag target for this gallerys listbox.
00607 
00608     Notes:      Overrides the default base-class action. Calls down to the base class
00609                 if it is not a colour drag, so that dragging of gallery groups is allowed
00610 
00611 ********************************************************************************************/
00612 
00613 void LibraryGallery::HandleDragStart(DragMessage *DragMsg)
00614 {
00615     SuperGallery::HandleDragStart(DragMsg);
00616 }
00617 
00618 /********************************************************************************************
00619 
00620 >   virtual SGDisplayItem *LibraryGallery::CopyDisplayItem(SGDisplayItem *SourceItem, 
00621                                                     SGDisplayGroup *DestGroup,
00622                                                     SGDisplayItem *TargetPosition = NULL)
00623     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00624     Created:    26/5/95
00625 
00626     Inputs:     SourceItem - The item to copy elsewhere in the tree (see below)
00627 
00628                 DestGroup - The group into which the item should be inserted
00629 
00630                 TargetPosition - NULL (to add the copied item to the end of the sibling
00631                 list), or points to an item BEFORE which the copied item will be inserted.
00632 
00633     Returns:    NULL (failed) or a pointer to the new (copied) display item
00634 
00635     Purpose:    "Copies" the existing node in the tree in an appropriate fashion.
00636                 
00637                 This method is normally called when a gallery-organising drag completes,
00638                 and it is discovered that the dragged item(s) have been dragged to a 
00639                 different display group.
00640 
00641     Notes:      This method should be overridden by derived galleries to provide
00642                 appropriate behaviour (some galleries (e.g colour) will copy the real-item
00643                 that the given display-item references to the new group (document), while
00644                 other galleries (layer) may just move the item after all).
00645 
00646                 Note the handy InsertCopiedItem and MoveBefore/After methods which
00647                 are available to take all of the hard work out of copying/moving items!
00648 
00649                 See the body of this method in the source code for example pseudocode.
00650                 For real code, see the Colour Gallery (sgcolour.cpp)
00651 
00652     SeeAlso:    SuperGallery::InsertCopiedItem; SGDisplayItem::MoveBefore;
00653                 SGDisplayItem::MoveAfter; ColourSGallery::CopyDisplayItem
00654 
00655 ********************************************************************************************/
00656 
00657 SGDisplayItem *LibraryGallery::CopyDisplayItem(SGDisplayItem *SourceItem, 
00658                                 SGDisplayGroup *DestGroup, SGDisplayItem *TargetPosition)
00659 {
00660     return SuperGallery::CopyDisplayItem(SourceItem, DestGroup, TargetPosition);
00661 }
00662 
00663 /********************************************************************************************
00664 
00665 >   virtual BOOL LibraryGallery::BrowseClicked(void)
00666 
00667     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00668     Created:    26/5/95
00669 
00670     Purpose:    Handle clicks on the browse button
00671 
00672 ********************************************************************************************/
00673 
00674 BOOL LibraryGallery::BrowseClicked(void)
00675 {
00676     return FALSE;
00677 }
00678 
00679 
00680 /********************************************************************************************
00681 
00682 >   virtual BOOL LibraryGallery::BrowseClicked(String_256 *DefaultPath, SGLibType Type, INT32 Message)
00683 
00684     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00685     Created:    18/12/95
00686 
00687     Inputs:     DefaultPath - Default path for Browse dialog to open up in
00688                 Type        - Type of Browse dialog
00689                 Message     - Message to ask whether we should kill all the groups or not
00690     Outputs:    DefaultPath - Updated if browse dialog added a new library
00691     
00692     Purpose:    Shared Library Gallery Browse Clicked procedure
00693 
00694 ********************************************************************************************/
00695 
00696 BOOL LibraryGallery::BrowseClicked(String_256 *DefaultPath, SGLibType Type, INT32 Message)
00697 {
00698     BOOL Updated = FALSE;
00699     PathName ThePath(*DefaultPath); 
00700 
00701     // This returns FALSE if Cancel was hit, or an error occurred.
00702     if(SGLibOil::GetLibPath(this, &ThePath, CanCreateIndexes(), Type, &Updated))
00703     {
00704         if(!ThePath.IsValid())
00705         {
00706             String_256 Tmp(ThePath.GetPath());
00707             ERROR3_PF(("LibraryGallery::BrowseClicked GetLibPath returned an invalid pathname - '%s'", (TCHAR *)Tmp));
00708         }
00709         else
00710         {                           
00711             // Remove by default
00712             INT32 ButtonPressed = 2;
00713 
00714             if(LibraryGroupsInGallery() > 0 && LibraryGallery::AskAboutRemoving)
00715             {
00716                 // Find out whether we should kill all the other groups
00717                 ButtonPressed = InformMessage(Message, _R(IDS_REMOVE), _R(IDS_KEEP), _R(IDS_CANCEL)/*, _R(IDS_HELP)*/);
00718                 Error::ClearError();
00719 
00720                 if(ButtonPressed == 3)
00721                     return FALSE;
00722             }
00723 
00724             // Remove clicked if button pressed == 1
00725             if(AddNewLibrary(&ThePath, ButtonPressed == 1, Type, Updated))
00726             {                           
00727                 // Remember the new path for the next time
00728                 *DefaultPath = ThePath.GetPath();
00729             }
00730 
00731             // Sort the entire gallery alphabetically
00732             SortGallery();
00733 
00734             ReformatAndRedrawIfNecessary();
00735 
00736             return TRUE;
00737         }
00738     }
00739     return FALSE;
00740 }
00741 
00742 /********************************************************************************************
00743 
00744 >   virtual BOOL LibraryGallery::CanCreateIndexes(void)
00745 
00746     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00747     Created:    18/12/95
00748 
00749     Returns:    TRUE to if index generation is possible
00750 
00751     Purpose:    To determine if this gallery can generate indexes or not
00752                 If you want to create indexes, override and return TRUE
00753 
00754 ********************************************************************************************/
00755 
00756 BOOL LibraryGallery::CanCreateIndexes(void)
00757 {
00758     return FALSE;
00759 }
00760 
00761 
00762 /********************************************************************************************
00763 
00764 >   virtual BOOL GetDefaults(String_256 *DefaultIndex, String_256 *IndexDesc, SGLibType *Type)
00765 
00766     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00767     Created:    18/12/95
00768 
00769     Outputs:    DefaultIndex    - The filename for the default index file (Xaraclip.txt)
00770                 IndexDesc       - Description of the index / gallery (Clipart)
00771                 Type            - Default library type associated with this gallery
00772 
00773     Returns:    TRUE if this was overridden successfully 
00774 
00775     Purpose:    To determine various library gallery default properties
00776 
00777 ********************************************************************************************/
00778 
00779 BOOL LibraryGallery::GetDefaults(String_256 *DefaultIndex, String_256 *IndexDesc, SGLibType *Type)
00780 {
00781 /*  case SGLib_ClipArt:
00782         *DefaultIndex = _R(IDS_LIBRARIES_CLIPART_FILENAME); // "XaraClip.txt";
00783         *IndexDesc = _R(IDS_LIBRARIES_CLIPART_DESC);        // "Clipart";
00784         break;
00785     
00786     case SGLib_Bitmap:
00787         *DefaultIndex = _R(IDS_LIBRARIES_BITMAPS_FILENAME); // "XaraBitm.txt";
00788         *IndexDesc = _R(IDS_LIBRARIES_BITMAPS_DESC);        // "Bitmap clipart";
00789         break;
00790         
00791     case SGLib_Font:
00792         *DefaultIndex = _R(IDS_LIBRARIES_FONTS_FILENAME);   // "XaraFont.txt";
00793         *IndexDesc = _R(IDS_LIBRARIES_FONTS_DESC);          // "Font";
00794         break;
00795 
00796     case SGLib_Texture:
00797         *DefaultIndex = _R(IDS_LIBRARIES_FILLS_FILENAME);   // "XaraText.txt";
00798         *IndexDesc = _R(IDS_LIBRARIES_FILLS_DESC);          // "Fills";
00799         break;
00800     
00801     case SGLib_Fractal:
00802         *DefaultIndex = _R(IDS_LIBRARIES_FRACTALS_FILENAME);// "XaraFrac.txt";
00803         *IndexDesc = _R(IDS_LIBRARIES_FRACTALS_DESC);       // "Fractal";
00804         break;
00805 
00806     case SGLib_Colour:
00807         *DefaultIndex = _R(IDS_LIBRARIES_COLOURS_FILENAME); // "XaraColo.txt";
00808         *IndexDesc = _R(IDS_LIBRARIES_COLOURS_DESC);        // "Colour";
00809         break;*/
00810 
00811     return FALSE;
00812 }
00813 
00814 
00815 
00816 /********************************************************************************************
00817 
00818 >   virtual BOOL LibraryGallery::GetLibraryDirectoryName(String_256 *LibDirName)
00819 
00820     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00821     Created:    19/12/95
00822 
00823     Outputs:    LibDirName  - Returns the Default directory (on the clipart CD) for the gallery
00824     Returns:    TRUE if overridden and directory obtained...
00825 
00826     Purpose:    Get the default CD directory name for the gallery
00827 
00828 ********************************************************************************************/
00829 
00830 BOOL LibraryGallery::GetLibraryDirectoryName(String_256 *LibDirName)
00831 {
00832     /*case SGLib_Font:
00833         CDPath += String_16(_R(IDS_LIBRARIES_FONTS_DIRNAME));
00834         break;
00835     case SGLib_ClipArt:
00836     case SGLib_Blank:
00837         CDPath += String_16(_R(IDS_LIBRARIES_CLIPART_DIRNAME));
00838         break;
00839     case SGLib_Bitmap:
00840         CDPath += String_16(_R(IDS_LIBRARIES_BITMAPS_DIRNAME));
00841         break;
00842     case SGLib_Texture:
00843         CDPath += String_16(_R(IDS_LIBRARIES_FILLS_DIRNAME));
00844         break;
00845     case SGLib_Fractal:
00846         CDPath += String_16(_R(IDS_LIBRARIES_FRACTALS_DIRNAME));
00847         break;
00848     case SGLib_Colour:
00849         CDPath += String_16(_R(IDS_LIBRARIES_COLOURS_DIRNAME));
00850         break;*/
00851 
00852     return FALSE;
00853 }
00854 
00855 
00856 /********************************************************************************************
00857 
00858 >   virtual BOOL LibraryGallery::CheckForIndexMatch(StringBase *Txt)
00859 
00860     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00861     Created:    18/12/95
00862 
00863     Inputs:     Kind    - Last column entry in the index.txt file (" F")
00864     Returns:    TRUE if this signifies the gallery in question...
00865 
00866     Purpose:    To see whether we should add this line of the index.txt file to this gallery
00867 
00868 ********************************************************************************************/
00869 
00870 BOOL LibraryGallery::CheckForIndexMatch(StringBase *Txt)
00871 {
00872 /*  if(Type == SGLib_ClipArt && ((Kind.Sub(String_8("A"))!=-1) || (Kind.Sub(String_8("a"))!=-1)) ) Match = TRUE;
00873     if(Type == SGLib_ClipArt && ((Kind.Sub(String_8("B"))!=-1) || (Kind.Sub(String_8("b"))!=-1)) ) Match = TRUE;                
00874     //if(Type == SGLib_Bitmap  && ((Kind.Sub(String_8("B"))!=-1) || (Kind.Sub(String_8("b"))!=-1)) ) Match = TRUE;
00875     if(Type == SGLib_Font    && ((Kind.Sub(String_8("F"))!=-1) || (Kind.Sub(String_8("f"))!=-1)) ) Match = TRUE;
00876     if(Type == SGLib_Texture && ((Kind.Sub(String_8("T"))!=-1) || (Kind.Sub(String_8("t"))!=-1)) ) Match = TRUE;
00877     if(Type == SGLib_Fractal && ((Kind.Sub(String_8("R"))!=-1) || (Kind.Sub(String_8("r"))!=-1)) ) Match = TRUE;
00878     if(Type == SGLib_Colour  && ((Kind.Sub(String_8("C"))!=-1) || (Kind.Sub(String_8("c"))!=-1)) ) Match = TRUE;*/
00879 
00880     return FALSE;
00881 }
00882 
00883 
00884 /********************************************************************************************
00885 
00886 >   virtual BOOL LibraryGallery::GetQuietStatus(void)
00887 
00888     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00889     Created:    19/12/95
00890     Returns:    TRUE if Quiet has been pressed (SetQuiet status called with TRUE)
00891     Purpose:    Get the Quiet status of the gallery
00892 
00893 ********************************************************************************************/
00894 
00895 BOOL LibraryGallery::GetQuietStatus(void)
00896 {
00897     return FALSE;
00898 }
00899 
00900 /********************************************************************************************
00901 
00902 >   virtual void LibraryGallery::SetQuietStatus(BOOL Status)
00903 
00904     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00905     Created:    19/12/95
00906     Inputs:     Status - Set to TRUE and call if Quiet has just been pressed on an 'adding
00907                          indexes' dialog
00908     Purpose:    Set the Quiet status of the gallery
00909 
00910 ********************************************************************************************/
00911         
00912 void LibraryGallery::SetQuietStatus(BOOL Status)
00913 {
00914 }
00915 
00916 /***********************************************************************************************
00917 
00918 >   virtual BOOL LibraryGallery::ScanForLocation(SGLibType Type, StringBase *Result = NULL);
00919 
00920     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00921     Created:    19/12/95
00922 
00923     Inputs:     Type of library to scan for
00924     Outputs:    (We assume the library static strings exist and use them - bit yucky)
00925                 If a Result pointer if given then we copy this into there as well..
00926     Returns:    FALSE if it fails; TRUE if we got a path
00927 
00928     Purpose:    Searches all the drives for a CDROM drive. If it finds the Camelot CD
00929                 mount here at Xara HQ, we point to that instead.
00930     Notes:
00931 
00932 ***********************************************************************************************/
00933 
00934 BOOL LibraryGallery::ScanForLocation(SGLibType Type, StringBase *Result)
00935 {
00936     return FALSE;
00937 }
00938 
00939 /********************************************************************************************
00940 
00941 >   virtual void LibraryGallery::SortGallery(void)
00942 
00943     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00944     Created:    26/5/95
00945 
00946     Purpose:    Sort the entire gallery alphabetically
00947 
00948 ********************************************************************************************/
00949 
00950 void LibraryGallery::SortGallery(void)
00951 {
00952     // auto sorting disabled
00953     return;
00954     
00955     // Sort alphabetically (and keep old sort keys)...
00956     SGSortKey TmpSortKeys[MaxSGSortKeys];
00957     for (INT32 i = 0; i < MaxSGSortKeys; i++)
00958     {
00959         TmpSortKeys[i] = SortKeys[i];
00960         SortKeys[i].SortKey  = 0;
00961         SortKeys[i].Reversed = FALSE;
00962     }
00963     SortKeys[0].SortKey = 1;
00964 
00965     ApplySortNow(TRUE);
00966 
00967     for (i = 0; i < MaxSGSortKeys; i++)
00968         SortKeys[i] = TmpSortKeys[i];
00969 
00970 }
00971 
00972 /********************************************************************************************
00973 
00974 >   INT32 LibraryGallery::GetDisplayMode(void)
00975 
00976     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00977     Created:    26/5/95
00978 
00979     Purpose:    Get the current gallery display mode as passing in miscinfo structures...
00980 
00981 ********************************************************************************************/
00982 
00983 INT32 LibraryGallery::GetDisplayMode(void)
00984 {
00985     // Current display mode identifier
00986     return DisplayMode;
00987 }
00988 
00989 /********************************************************************************************
00990 
00991 >   void LibraryGallery::RemoveSelectedLibraries(BOOL Warn)
00992 
00993     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00994     Created:    26/5/95
00995     Inputs:     Warn    - Warn user before removing groups (doesn't warn if no groups)
00996 
00997     Purpose:    Removes all the selected groups in the library
00998 
00999 ********************************************************************************************/
01000 
01001 void LibraryGallery::RemoveSelectedLibraries(BOOL Warn)
01002 {
01003     BOOL FullRedrawNecessary = FALSE;
01004 
01005     ERROR3IF(DisplayTree == NULL, "LibraryGallery::RemoveSelectedLibraries called with null display tree");
01006 
01007     INT32 GroupCount = GetSelectedGroupCount();
01008 
01009     //ERROR3_PF(("Selected Group Count %d", GroupCount));
01010 
01011     if(GroupCount > 0)
01012     {
01013         INT32 ButtonPressed = 1;
01014         
01015         if(Warn)
01016             ButtonPressed = InformMessage(_R(IDS_LIBRARY_CHECK_REMOVE), _R(IDS_REMOVE), _R(IDS_CANCEL));
01017 
01018         if(ButtonPressed == 1)
01019         {
01020             SGDisplayGroup *Group = DisplayTree->FindNextSelectedGroup(NULL);
01021             SGDisplayGroup *NextGroup = NULL;
01022             BOOL DoingSlowJob = FALSE;
01023 
01024             INT32 ActualCount = 0;
01025             if(GroupCount > 0)
01026             {
01027                 String_64 SlowJob(_R(IDS_LIBRARY_REMOVING_FOLDERS));
01028                 BeginSlowJob(GroupCount, FALSE, &SlowJob);
01029                 DoingSlowJob = TRUE;
01030             }
01031 
01032             while(Group != NULL)
01033             {
01034                 NextGroup = DisplayTree->FindNextSelectedGroup(Group);
01035 
01036                 INT32 LibFileCount = OpenLibFiles.GetCount();
01037                 BOOL DeletedGroup = FALSE;
01038 
01039                 if(LibFileCount > 0)
01040                 {
01041                     // Count so we can tell where we are in the libfile list
01042                     INT32 LibFilesDeleted = 0;
01043                     INT32 OriginalLibFileCount = LibFileCount;
01044 
01045                     // Loop through library files
01046                     for(INT32 LibFileLoop = 0; LibFileLoop < OriginalLibFileCount; LibFileLoop ++)
01047                     {
01048                         LibraryFile *LibFile = (LibraryFile *)OpenLibFiles.FindItem(LibFileLoop - LibFilesDeleted);
01049 
01050                         INT32 LibCount = LibFile->Libraries.GetCount();
01051 
01052                         if(LibCount > 0)
01053                         {
01054                             // Count so we can tell where we are in the libfile list
01055                             INT32 LibsDeleted = 0;
01056                             INT32 OriginalLibCount = LibCount;
01057 
01058                             // Loop through library groups
01059                             for(INT32 LibLoop = 0; LibLoop < OriginalLibCount; LibLoop ++)
01060                             {
01061                                 Library *Lib = (Library *)LibFile->Libraries.FindItem(LibLoop - LibsDeleted);
01062 
01063                                 if(Lib->ParentGroup == Group)
01064                                 {
01065                                     if(Lib->ParentGroup->GetNext() == NULL)
01066                                         FullRedrawNecessary = TRUE;
01067 
01068                                     Lib->ParentGroup->DestroySubtree(TRUE);
01069                                     // >>webster
01070                                     if (Lib->IsWebLibrary())
01071                                     {
01072                                         OpAddWebFolders::Success[Lib->GetType()] = FALSE;
01073                                         // Remove the files from the hard disk
01074                                         DownloadCache::RemoveFile(Lib->ReturnIndexLocation()->GetPath());
01075                                     }
01076                                     // <<webster
01077                                     // Found our group
01078                                     delete(LibFile->Libraries.RemoveItem(Lib));
01079                                     LibsDeleted ++;
01080 
01081                                     LibCount = LibFile->Libraries.GetCount();
01082                                     if(LibCount == 0)
01083                                     {
01084                                         delete(OpenLibFiles.RemoveItem(OpenLibFiles.FindItem(LibFileLoop)));
01085                                         LibFilesDeleted ++;
01086                                     }
01087 
01088                                     DeletedGroup = TRUE;
01089                                 }
01090 
01091                                 if(DeletedGroup)
01092                                     break;
01093                             }
01094                         }
01095                         if(DeletedGroup)
01096                             break;
01097                     }
01098                 }
01099 
01100                 // Get the next selected group from the gallery
01101                 Group = NextGroup;
01102 
01103                 // Update the progress bar for each group
01104                 if(DoingSlowJob)
01105                     ContinueSlowJob(++ActualCount);
01106             }
01107 
01108             if(DoingSlowJob)
01109                 EndSlowJob();
01110 
01111             // Update the button shading status - 'Remove' should now be greyed out
01112             SelectionHasChanged();
01113 
01114             // Update the gallery
01115             InvalidateCachedFormat();
01116             if(FullRedrawNecessary)
01117                 ForceRedrawOfList();
01118             else
01119                 ReformatAndRedrawIfNecessary();
01120         }
01121     }
01122 }
01123 
01124 /********************************************************************************************
01125 
01126 >   INT32 LibraryGallery::RemoveSimilarLibraryGroups(PathName *IndexFile, BOOL RemoveFirstOne = TRUE, BOOL Redraw = TRUE
01127                 , Library *DontKill = NULL)
01128 
01129     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
01130     Created:    30/8/95
01131     Inputs:     IndexFile       - Path of index for group with which similar ones should be removed
01132                 RemoveFirstOne  - Set to TRUE if you want ALL the groups with the same index removed
01133                                 - Set to FALSE and all but the first will be removed...
01134                 Redraw          - Set to TRUE if you want the new gallery redrawn...
01135                 DontKill        - Pointer to a Library not to kill
01136 
01137     Returns:    Number of groups removed
01138 
01139     Purpose:    Removes all the groups with the same Index path...
01140 
01141 ********************************************************************************************/
01142 
01143 INT32 LibraryGallery::RemoveSimilarLibraryGroups(PathName *FilesPath, String_256 *IndexFileName, BOOL RemoveFirstOne,
01144                          BOOL Redraw, Library *DontKill)
01145 {
01146     ERROR3IF(FilesPath == NULL || IndexFileName == NULL, "LibraryGallery::RemoveSimilarLibraryGroups given null params");
01147     ERROR3IF(DisplayTree == NULL, "LibraryGallery::RemoveSimilarLibraryGroups called with null display tree");
01148 
01149     INT32 RemovedGroups = 0;
01150 
01151     BOOL FullRedrawNecessary = FALSE;
01152     INT32 GroupCount = LibraryGroupsInGallery();
01153 
01154     LibraryGallery::OffsetOfFirstGroupRemoved = -1;
01155     INT32 OffsetCount = 0;
01156     
01157     if(GroupCount > 0)
01158     {
01159         // Sort out the path we're checking against
01160         String_256 UpperIndex(*IndexFileName);
01161         UpperIndex.toUpper();
01162         String_256 UpperFiles(FilesPath->GetPath());
01163         LibraryFile::TidyUpSubPath(&UpperFiles);
01164         UpperFiles.toUpper();
01165     
01166         SGDisplayGroup *Group = (SGDisplayGroup *)DisplayTree->GetChild();
01167         SGDisplayGroup *NextGroup = NULL;
01168 
01169         // Loop through groups...
01170         while(Group != NULL)
01171         {
01172             NextGroup = (SGDisplayGroup *)Group->GetNext();
01173 
01174             INT32 LibFileCount = OpenLibFiles.GetCount();
01175             BOOL DeletedGroup = FALSE;
01176 
01177             if(LibFileCount > 0)
01178             {
01179                 // Count so we can tell where we are in the libfile list
01180                 INT32 LibFilesDeleted = 0;
01181                 INT32 OriginalLibFileCount = LibFileCount;
01182 
01183                 // Loop through library files
01184                 for(INT32 LibFileLoop = 0; LibFileLoop < OriginalLibFileCount; LibFileLoop ++)
01185                 {
01186                     LibraryFile *LibFile = (LibraryFile *)OpenLibFiles.FindItem(LibFileLoop - LibFilesDeleted);
01187                     INT32 LibCount = LibFile->Libraries.GetCount();
01188 
01189                     if(LibCount > 0)
01190                     {
01191                         // Count so we can tell where we are in the libfile list
01192                         INT32 LibsDeleted = 0;
01193                         INT32 OriginalLibCount = LibCount;
01194 
01195                         // Loop through library groups
01196                         for(INT32 LibLoop = 0; LibLoop < OriginalLibCount; LibLoop ++)
01197                         {
01198                             Library *Lib = (Library *)LibFile->Libraries.FindItem(LibLoop - LibsDeleted);
01199 
01200                             if(Lib->ParentGroup == Group && Lib->SubLibPath != NULL && Lib->IndexFile != NULL && Lib != DontKill)
01201                             {
01202                                 String_256 LibraryPath(Lib->SubLibPath->GetPath());
01203                                 String_256 LibraryIndex(Lib->IndexFile->GetFileName(TRUE));
01204                                 LibraryPath.toUpper();
01205                                 LibraryIndex.toUpper();
01206                                 
01207                                 // Found a duplicate group - vape city !
01208                                 if(UpperFiles == LibraryPath && UpperIndex == LibraryIndex)
01209                                 {
01210                                     // Keep the offset count in a static so we can do a proper insert for updated groups
01211                                     if(LibraryGallery::OffsetOfFirstGroupRemoved == -1)
01212                                     {
01213                                         LibraryGallery::OffsetOfFirstGroupRemoved = OffsetCount;
01214                                         LibraryGallery::FirstGroupRemovedSelectionState = Group->IsSelected();
01215                                     }
01216 
01217                                     RemovedGroups++;
01218 
01219                                     if(Lib->ParentGroup->GetNext() == NULL)
01220                                         FullRedrawNecessary = TRUE;
01221 
01222                                     Lib->ParentGroup->DestroySubtree(TRUE);
01223 
01224                                     delete(LibFile->Libraries.RemoveItem(Lib));
01225                                     LibsDeleted ++;
01226 
01227                                     LibCount = LibFile->Libraries.GetCount();
01228                                     if(LibCount == 0)
01229                                     {
01230                                         delete(OpenLibFiles.RemoveItem(OpenLibFiles.FindItem(LibFileLoop)));
01231                                         LibFilesDeleted ++;
01232                                     }
01233 
01234                                     DeletedGroup = TRUE;
01235                                 }
01236                             }
01237 
01238                             if(DeletedGroup)
01239                                 break;
01240                         }
01241                     }
01242                     if(DeletedGroup)
01243                         break;
01244                 }
01245             }
01246 
01247             // Get the next group from the gallery
01248             Group = NextGroup;
01249             OffsetCount++;
01250         }
01251 
01252         // Update the button shading status - 'Remove' should now be greyed out
01253         SelectionHasChanged();
01254 
01255         // Update the gallery
01256         if(Redraw)
01257         {
01258             InvalidateCachedFormat();
01259             if(FullRedrawNecessary)
01260                 ForceRedrawOfList();
01261             else
01262                 ReformatAndRedrawIfNecessary();
01263         }
01264     }
01265 
01266     return RemovedGroups;
01267 }
01268 
01269 
01270 /********************************************************************************************
01271 
01272 >   virtual void LibraryGallery::WorkOutSectionName(String_256 *Section)
01273 
01274     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
01275     Created:    27/5/95
01276     Inputs:
01277     Outputs:    A section name to use for the library gallery
01278 
01279     Purpose:    Works out which library gallery we are and returns a section name as appropriate
01280 
01281     Notes:      Ideally this function should be overidden by the individual galleries...
01282 
01283 ********************************************************************************************/
01284 
01285 void LibraryGallery::WorkOutSectionName(String_256 *Section)
01286 {
01287     ERROR3IF(Section == NULL, "LibraryGallery::WorkOutSectionName given null section");
01288 
01289     *Section = _R(IDS_SGLBASE_SECTION_NAME); // TEXT("LibraryGallery");
01290 }
01291 
01292 /********************************************************************************************
01293 
01294 >   virtual void LibraryGallery::WorkOutDescriptionSectionName(String_256 *Section)
01295 
01296     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
01297     Created:    9/1/96
01298     Inputs:
01299     Outputs:    A section name to use for the library gallery which denotes group descriptions
01300 
01301     Purpose:    Works out which library gallery we are and returns a description section name
01302                 as appropriate
01303 
01304 ********************************************************************************************/
01305 
01306 void LibraryGallery::WorkOutDescriptionSectionName(String_256 *Section)
01307 {
01308     ERROR3IF(Section == NULL, "LibraryGallery::WorkOutDescriptionSectionName given null section");
01309 
01310     WorkOutSectionName(Section);
01311     *Section += String_256(_R(IDS_GRMFILE_DESCRIPTIONS));
01312 }
01313 
01314 
01315 /********************************************************************************************
01316 
01317 >   virtual void LibraryGallery::WorkOutLibraryTypeSectionName(String_256 *Section)
01318 
01319     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
01320     Created:    9/1/96
01321     Inputs:
01322     Outputs:    A section name to use for the library gallery which denotes library types
01323 
01324     Purpose:    Works out which library gallery we are and returns a library type section name
01325                 as appropriate
01326 
01327 ********************************************************************************************/
01328 
01329 void LibraryGallery::WorkOutLibraryTypeSectionName(String_256 *Section)
01330 {
01331     ERROR3IF(Section == NULL, "LibraryGallery::WorkOutLibraryTypeSectionName given null section");
01332 
01333     WorkOutSectionName(Section);
01334     *Section += String_256(_R(IDS_GRMFILE_LIBRARYTYPES));
01335 }
01336 
01337 
01338 /********************************************************************************************
01339 
01340 >   static BOOL LibraryGallery::WipeGallerySettings()
01341 
01342     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01343     Created:    28/2/97
01344     Inputs:     -
01345     Purpose:    Function to remove all the current gallery settings
01346 
01347 ********************************************************************************************/
01348 
01349 BOOL LibraryGallery::WipeGallerySettings(void)
01350 {
01351 
01352 #ifdef SAVE_PREFS_TO_REGISTRY
01353     // Wipe the gallery settings from the registry
01354     // need to use this delete function so that works on Windows 95 and NT
01355     DeleteRegKeyAndSubKeys(hAppStateRegKey, PRODUCT_REGISTRYKEY_GALLERY);
01356     
01357     // We must wipe the ini file as well as otherwise when the code checks to 
01358     // see if the registry settings and then falls back on the ini file if they
01359     // are not there, then we wont be using the default settings.
01360 #endif
01361 
01362     // Wipe the GRM ini file
01363     LibSettings::NukeSettings();
01364 
01365     return TRUE;
01366 }
01367 
01368 /********************************************************************************************
01369 
01370 >   void LibraryGallery::UpdateGRMFile(void)
01371 
01372     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
01373     Created:    27/5/95
01374     Inputs:     
01375 
01376     Purpose:    Updates the GRM file to reflect the status of the gallery (all the groups)
01377 
01378 ********************************************************************************************/
01379 
01380 void LibraryGallery::UpdateGRMFile(void)
01381 {
01382     if(DisplayTree == NULL)
01383         ERROR3("LibraryGallery::UpdateGRMFile called with null display tree");
01384 
01385     String_64 SlowJob(_R(IDS_LIBRARY_UPDATING_GRMF));
01386     BeginSlowJob(-1, TRUE, &SlowJob);
01387 
01388     INT32 Pass = 0;
01389     String_256 SectionName;
01390     
01391     // We now do 3 passes (webster), the first builds the pathnames section, the second does the descriptions
01392     // the third lists the index files corresponding to web folders. Note - doing the section first is important so we 
01393     // can detect if the descriptions are out of date,
01394     // or rather that the SectionName bit was generated by an old version (which will always add it to
01395     // the end of the file...)
01396 
01397     //OK, we now do 4 passes - the extra pass adds the Library type for each item - needed for clipart gallery to
01398     //support multiple download and cache locations...
01399     while(++Pass <= 3)
01400     {
01401         if(Pass == 1)
01402             WorkOutSectionName(&SectionName);
01403         else if (Pass == 2)
01404             WorkOutDescriptionSectionName(&SectionName);
01405         else if (Pass == 3)
01406             WorkOutLibraryTypeSectionName(&SectionName);
01407 
01408 #ifdef SAVE_PREFS_TO_REGISTRY
01409         // This is the main section name in the registry for gallery settings.
01410         String_256 KeySectionName(PRODUCT_REGISTRYKEY_GALLERY TEXT("\\"));
01411         // add in the required sub-section name that we are going to use
01412         KeySectionName += SectionName;
01413 
01414         SaveRegistryEntries Saver;
01415         BOOL StartedOk = Saver.StartSaving(&KeySectionName);
01416         ERROR3IF(!StartedOk,"LibraryGallery::UpdateGRMFile couldn't start saving the settings");
01417 
01418         if(!OpenLibFiles.IsEmpty() && StartedOk)
01419         {
01420             INT32 LibFileCount = OpenLibFiles.GetCount();
01421 
01422             if(LibFileCount > 0)
01423             {
01424                 // Loop through library files
01425                 for(INT32 LibFileLoop = 0; LibFileLoop < LibFileCount; LibFileLoop ++)
01426                 {
01427                     LibraryFile *LibFile = (LibraryFile *)OpenLibFiles.FindItem(LibFileLoop);
01428                     INT32 LibCount = LibFile->Libraries.GetCount();
01429                     if(LibCount > 0)
01430                     {
01431                         // Loop through library groups
01432                         for(INT32 LibLoop = 0; LibLoop < LibCount; LibLoop ++)
01433                         {
01434                             Library *Lib = (Library *)LibFile->Libraries.FindItem(LibLoop);
01435 
01436                             // Add the pathname of the index file to the grm file
01437                             if(Lib != NULL && Lib->IndexFile != NULL)
01438                             {
01439                                 String_256 Line;
01440                                 if(Pass == 1)
01441                                     Line = Lib->IndexFile->GetPath();
01442                                 else if (Pass == 2)
01443                                     Lib->GetLibraryTitle(&Line);
01444                                 else if (Pass == 3)
01445                                 {
01446                                     INT32 libtype = Lib->Type;
01447                                     String_256 libstringtype;
01448                                     libstringtype._MakeMsg("#1%d",libtype);
01449                                     Line = libstringtype;
01450                                 }
01451 
01452                                 if (Line.Length())
01453                                 {
01454                                     if (!Saver.SaveNextEntry(&Line))
01455                                     {
01456                                         // Possibly write access denied on grm file... or disk full...
01457                                         EndSlowJob();
01458                                         return;
01459                                     }
01460                                 }
01461                             }
01462                         }
01463                     }
01464                 }
01465             }
01466         }
01467         
01468         // Close down the saving
01469         Saver.StopSaving();
01470 #else
01471         LibSettings::StartOutput(&SectionName);
01472         LibSettings::AddSection(&SectionName);
01473 
01474         if(!OpenLibFiles.IsEmpty())
01475         {
01476             INT32 LibFileCount = OpenLibFiles.GetCount();
01477 
01478             if(LibFileCount > 0)
01479             {
01480                 // Loop through library files
01481                 for(INT32 LibFileLoop = 0; LibFileLoop < LibFileCount; LibFileLoop ++)
01482                 {
01483                     LibraryFile *LibFile = (LibraryFile *)OpenLibFiles.FindItem(LibFileLoop);
01484                     INT32 LibCount = LibFile->Libraries.GetCount();
01485                     if(LibCount > 0)
01486                     {
01487                         // Loop through library groups
01488                         for(INT32 LibLoop = 0; LibLoop < LibCount; LibLoop ++)
01489                         {
01490                             Library *Lib = (Library *)LibFile->Libraries.FindItem(LibLoop);
01491 
01492                             // Add the pathname of the index file to the grm file
01493                             if(Lib != NULL && Lib->IndexFile != NULL)
01494                             {
01495                                 String_256 Line;
01496                                 if(Pass == 1)
01497                                     Line = Lib->IndexFile->GetPath();
01498                                 else if (Pass == 2)
01499                                     Lib->GetLibraryTitle(&Line);
01500                                 else if (Pass == 3)
01501                                 {
01502                                     INT32 libtype = Lib->Type;
01503                                     String_256 libstringtype;
01504                                     libstringtype._MakeMsg("#1%d",libtype);
01505                                     Line = libstringtype;
01506                                 }
01507 
01508                                 if(!LibSettings::AddLine(&Line))
01509                                 {
01510                                     // Possibly write access denied on grm file... or disk full...
01511                                     EndSlowJob();
01512                                     return;
01513                                 }
01514                             }
01515                         }
01516                     }
01517                 }
01518             }
01519         }
01520 #endif
01521     }
01522 #ifdef SAVE_PREFS_TO_REGISTRY
01523     String_256 RootURLKeySectionName(PRODUCT_REGISTRYKEY_GALLERY TEXT("\\"));
01524     RootURLKeySectionName += String_256(_R(IDS_ROOTURL));
01525     SaveRegistryEntries Saver;  
01526     BOOL StartedOk = Saver.StartSaving(&RootURLKeySectionName);
01527     ERROR3IF(!StartedOk,"LibraryGallery::UpdateGRMFile couldn't start saving the settings");
01528     Saver.SaveNextEntry(&Library::URLBase);
01529 #else
01530     String_256 strRootURLSectionName(_R(IDS_ROOTURL));
01531     LibSettings::StartOutput(&strRootURLSectionName);
01532     LibSettings::AddSection(&strRootURLSectionName);
01533     LibSettings::AddLine(&Library::URLBase);
01534 #endif
01535 
01536     EndSlowJob();
01537 }
01538 
01539 
01540 
01541 /********************************************************************************************
01542 
01543 >   BOOL LibraryGallery::AddLibraryGroups(SGLibType LibType, String_256 *DefaultLibraryPath);
01544 
01545     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
01546     Created:    28/5/95
01547 
01548     Inputs:     LibType - The type of library we're adding
01549                 DefaultLibraryPath  - Library path to use if non found in grm file
01550     Returns:    TRUE if new groups added
01551 
01552     Purpose:    Creates all teh library groups described in the GRM file, or passed in if
01553                 non were in the GRM...
01554 
01555 ********************************************************************************************/
01556 
01557 BOOL LibraryGallery::AddLibraryGroups(SGLibType LibType, String_256 *DefaultLibraryPath)
01558 {
01559     TRACEUSER( "Matt", _T("AddLibraryGroups called in Base Class\n"));
01560 //  ERROR3_PF(("LibraryGallery::AddLibraryGroups -> %s", (TCHAR *)*DefaultLibraryPath));
01561 
01562     BOOL AddedGroups = FALSE;
01563 
01564     if(AddGRMGroups(LibType))
01565     {
01566         AddedGroups = TRUE;
01567     }
01568     else
01569     {
01570 
01571 // Matt - 03/01/2001
01572 // This method is only ever called from derived classes and the check below is made in each one of them before calling...
01573 // Therefore, this change will not affect their operation - it DOES mean that we can now pre-create  a gallery with CD stuff
01574 // from multiple sources... used in the clipart/web themes precreation...
01575 
01576 //      if (OpenLibFiles.IsEmpty())     // We have no libraries, so open the default library
01577 //      {
01578             String_64 SlowJob(_R(IDS_LIBRARY_SCANNING));
01579             BeginSlowJob(-1, FALSE, &SlowJob);
01580 
01581             // open the library file
01582             LibraryFile *LibFile = new LibraryFile;
01583             if (LibFile != NULL)
01584             {
01585                 // OK. Lets initialise the library. This will call us back via base-class
01586                 // SuperGallery methods to add a group and items for each {sub}library
01587                 // found in the given library file.         
01588                 PathName ThePath(*DefaultLibraryPath);
01589                 if (!LibFile->Init(this, &ThePath, LibType))
01590                 {
01591                     // InformError if it returned FALSE? **** !!!!
01592                     delete LibFile;
01593                 }
01594                 else
01595                 {
01596                     OpenLibFiles.AddTail(LibFile);
01597                     AddedGroups = TRUE;
01598                     //SortGallery();
01599                 }
01600             }
01601 
01602             EndSlowJob();
01603 //      }
01604     }
01605 
01606     return AddedGroups;
01607 }
01608 
01609 /********************************************************************************************
01610 
01611 >   BOOL LibraryGallery::AddGRMGroups(SGLibType LibType);
01612 
01613     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
01614     Created:    28/5/95
01615 
01616     Inputs:     LibType - The type of library we're adding
01617     Returns:    TRUE if new groups added
01618 
01619     Purpose:    Creates all the library groups described in the GRM file
01620 
01621 ********************************************************************************************/
01622 
01623 BOOL LibraryGallery::AddGRMGroups(SGLibType LibType)
01624 {
01625     TRACEUSER( "Matt", _T("AddGRMGroups Called in base class\n"));
01626     String_256 SectionName;
01627     WorkOutSectionName(&SectionName);
01628 
01629     // The two lists we are going to use to keep track of the two section that we require
01630     // Errr.. now there's three lists... Sorry. (Matt 25/09/2000)
01631     List *PathList = NULL;
01632     List *DescList = NULL;
01633     List *TypeList = NULL;
01634 
01635     BOOL bRetVal = FALSE;
01636 
01637 #ifdef SAVE_PREFS_TO_REGISTRY
01638     // Check to see if we have the gallery settings section in the registry
01639     // if we do then use that.
01640     // Otherwise, use check for the older ini file version and if present use that
01641     
01642     // This is the main section name in the registry for gallery settings.
01643     String_256 KeySectionName(PRODUCT_REGISTRYKEY_GALLERY TEXT("\\"));
01644     // add in the required sub-section name that we are going to use
01645     KeySectionName += SectionName;
01646 
01647     BOOL SectionPresent = CheckForRegistryEntry(KeySectionName);
01648     if (SectionPresent)
01649     {
01650         // We need to read the data from the registry as the section is present
01651         
01652         // First do the pathnames list section
01653         LoadRegistryEntries Loader;
01654         BOOL StartedOk = Loader.StartLoading(&KeySectionName);
01655         ERROR3IF(!StartedOk,"LibraryGallery::UpdateGRMFile couldn't start saving the settings");
01656 
01657         PathList = new List;
01658 
01659         // read all the lines from that section
01660         BOOL AddedItems = FALSE;
01661         INT32 NumberSectionItems = 0;
01662         if (PathList && StartedOk)
01663         {
01664             String_256 Entry;
01665             while (Loader.LoadNextEntry(&Entry))
01666             {
01667                 LibSettingsListItem *LibSettingsItem = new LibSettingsListItem(&Entry);
01668                 PathList->AddTail((ListItem *)LibSettingsItem);
01669                 AddedItems = TRUE;
01670             }
01671             // remember how many items we got
01672             NumberSectionItems = Loader.GetNumberOfItemsLoaded();
01673             Loader.StopLoading();
01674         }
01675 
01676         // See if we've got descriptions section as well
01677         String_256 DescriptionSectionName;
01678         WorkOutDescriptionSectionName(&DescriptionSectionName);
01679         // This is the main section name in the registry for gallery settings.
01680         String_256 DescriptionKeySectionName(PRODUCT_REGISTRYKEY_GALLERY TEXT("\\"));
01681         // add in the required sub-section name that we are going to use
01682         DescriptionKeySectionName += DescriptionSectionName;
01683         BOOL DescriptionsPresent = FALSE;
01684         String_256 DescEntry;
01685 
01686         // First do the pathnames list section
01687         LoadRegistryEntries DescLoader;
01688         DescriptionsPresent = DescLoader.StartLoading(&DescriptionKeySectionName);
01689         ERROR3IF(!DescriptionsPresent,"LibraryGallery::UpdateGRMFile couldn't start saving the settings");
01690 
01691         // build up a list of the items in this section
01692         DescList = new List;
01693         INT32 NumberDescriptionItems = 0;
01694         if (DescList && DescriptionsPresent)
01695         {
01696             while (DescLoader.LoadNextEntry(&DescEntry))
01697             {
01698                 LibSettingsListItem *LibSettingsItem = new LibSettingsListItem(&DescEntry);
01699                 DescList->AddTail((ListItem *)LibSettingsItem);
01700                 AddedItems = TRUE;
01701             }
01702             // remember how many items we got
01703             NumberDescriptionItems = DescLoader.GetNumberOfItemsLoaded();
01704             DescLoader.StopLoading();
01705         }
01706 
01707 
01708         // See if we've got library types section as well
01709         String_256 LibraryTypesSectionName;
01710         WorkOutLibraryTypeSectionName(&LibraryTypesSectionName);
01711         // This is the main section name in the registry for gallery settings.
01712         String_256 LibraryTypesKeySectionName(PRODUCT_REGISTRYKEY_GALLERY TEXT("\\"));
01713         // add in the required sub-section name that we are going to use
01714         LibraryTypesKeySectionName += LibraryTypesSectionName;
01715         BOOL LibraryTypesPresent = FALSE;
01716         String_256 TypesEntry;
01717 
01718         // First do the pathnames list section
01719         LoadRegistryEntries TypesLoader;
01720         LibraryTypesPresent = TypesLoader.StartLoading(&LibraryTypesKeySectionName);
01721         ERROR3IF(!LibraryTypesPresent,"LibraryGallery::UpdateGRMFile couldn't start saving the LibraryTypes");
01722 
01723         // build up a list of the items in this section
01724         TypeList = new List;
01725         INT32 NumberLibraryTypesItems = 0;
01726         if (TypeList && LibraryTypesPresent)
01727         {
01728             while (TypesLoader.LoadNextEntry(&TypesEntry))
01729             {
01730                 LibSettingsListItem *LibSettingsItem = new LibSettingsListItem(&TypesEntry);
01731                 TypeList->AddTail((ListItem *)LibSettingsItem);
01732                 AddedItems = TRUE;
01733             }
01734             // remember how many items we got
01735             NumberLibraryTypesItems = TypesLoader.GetNumberOfItemsLoaded();
01736             TypesLoader.StopLoading();
01737         }
01738         
01739         
01740 // >>webster        
01741         // This is the main section name in the registry for gallery settings.
01742         String_256 RootURLKeySectionName(PRODUCT_REGISTRYKEY_GALLERY TEXT("\\"));
01743         // add in the required sub-section name that we are going to use
01744         RootURLKeySectionName += String_256(_R(IDS_ROOTURL));
01745         LoadRegistryEntries URLLoader;
01746         if (URLLoader.StartLoading(&RootURLKeySectionName)) 
01747             URLLoader.LoadNextEntry(&Library::URLBase);
01748         URLLoader.StopLoading();
01749     // <<webster
01750 
01751         // If we have a matching set of pathname and description sections then add those items
01752         // Otherwise, just leave the gallery blank
01753         if (NumberDescriptionItems == NumberSectionItems && 
01754             NumberSectionItems != 0 && NumberDescriptionItems != 0 &&
01755             PathList != NULL && DescList != NULL)
01756         {
01757             // Add the sections to the gallery
01758             bRetVal = GoAndAddGRMGroups(/*LibType*/TypeList , PathList, DescList, DescriptionsPresent, &SectionName, &DescriptionSectionName);
01759         }
01760     }
01761     else
01762 #endif
01763     {
01764         // read the data from the ini file
01765         String_256 Entry;
01766 
01767         // Right, only return false if the section wasn't found in the file
01768         // The contents of the section could be null, this would mean there are no libraries
01769         // shown, but if that's what they want then fair enough
01770         FilePos SectionNamePos = 0;
01771         if(!LibSettings::GetEntry(&SectionName, 0, &Entry, &SectionNamePos))
01772             return FALSE;
01773 
01774         // See if we've got descriptions as well
01775         String_256 DescriptionSectionName(SectionName);
01776         WorkOutDescriptionSectionName(&DescriptionSectionName);
01777         BOOL DescriptionsPresent = FALSE;
01778         String_256 DescEntry;
01779         FilePos DescriptionPos = 0;
01780         if(LibSettings::GetEntry(&DescriptionSectionName, 0, &DescEntry, &DescriptionPos))
01781             DescriptionsPresent = TRUE;
01782         
01783         // If the [SectionName] appears later than the [DescriptionSectionName] then the
01784         // [Description] one is invalid...
01785         // Perhaps in the future we should change the SectionNames so that old versions of Camelot
01786         // won't affect new things like this...
01787         if(DescriptionPos < SectionNamePos)
01788             DescriptionsPresent = FALSE;
01789 
01790         // See if we've got library types as well
01791         String_256 LibraryTypesSectionName(SectionName);
01792         WorkOutLibraryTypeSectionName(&LibraryTypesSectionName);
01793         BOOL LibraryTypesPresent = FALSE;
01794         String_256 TypeEntry;
01795         FilePos LibraryTypesPos = 0;
01796         if(LibSettings::GetEntry(&LibraryTypesSectionName, 0, &TypeEntry, &LibraryTypesPos))
01797             LibraryTypesPresent = TRUE;
01798 
01799 
01800         PathList = new List;
01801         if(PathList != NULL && !LibSettings::BuildList(&SectionName, PathList))
01802         {
01803             PathList->DeleteAll();
01804             delete PathList;
01805             PathList = NULL;
01806         }
01807 
01808         DescList = NULL;
01809         if(DescriptionsPresent)
01810         {
01811             DescList = new List;
01812             if(DescList != NULL && !LibSettings::BuildList(&DescriptionSectionName, DescList))
01813             {
01814                 DescList->DeleteAll();
01815                 delete DescList;
01816                 DescList = NULL;
01817             }
01818         }
01819 
01820         TypeList = new List;
01821         if(LibraryTypesPresent)
01822         {
01823             TypeList = new List;
01824             if(TypeList != NULL && !LibSettings::BuildList(&LibraryTypesSectionName, TypeList))
01825             {
01826                 TypeList->DeleteAll();
01827                 delete TypeList;
01828                 TypeList = NULL;
01829             }
01830         }
01831 
01832 
01833 
01834         //>> webster (Adrian 3/01/97)
01835         String_256 strURLBaseSectionName(_R(IDS_ROOTURL));
01836         String_256 strRootURL;
01837         if (LibSettings::GetEntry(&strURLBaseSectionName, 1, &strRootURL, NULL))    
01838             Library::URLBase = strRootURL;
01839         //<< webster
01840 
01841         bRetVal = ActuallyAddGRMGroups(TypeList /*LibType*/, PathList, DescList, DescriptionsPresent, &SectionName, &DescriptionSectionName);
01842 
01843     }
01844 
01845     // Free up memory entailed in lists
01846     if(PathList != NULL)
01847     {
01848         PathList->DeleteAll();
01849         delete PathList;
01850     }
01851 
01852     if(DescList != NULL)
01853     {
01854         DescList->DeleteAll();
01855         delete DescList;
01856     }
01857 
01858     if(TypeList != NULL)
01859     {
01860         TypeList->DeleteAll();
01861         delete TypeList;
01862     }
01863 
01864     return bRetVal;
01865 }
01866 
01867 /********************************************************************************************
01868 
01869 >   BOOL LibraryGallery::GoAndAddGRMGroups(SGLibType LibType, List *PathList, List *DescList, BOOL DescPresent,
01870                                            String_256 *SectionName, String_256 *DescriptionSectionName)
01871 
01872     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01873     Created:    26/2/97
01874 
01875     Inputs:     LibType     - The type of library we're adding
01876                 PathList    - List of Pathnames for the groups (optional, can be NULL, but slower...)
01877                 DescList    - List of Descriptions to display for the groups (optional, can be NULL, but slower...)
01878                 DescPresent - Are descriptions present ?
01879                 SectionName - Section name for the paths
01880                 DescriptionSectionName - Section name for the descriptions
01881 
01882     Returns:    TRUE if new groups added
01883 
01884     Purpose:    Given two lists, create all the groups in the gallery from them.
01885                 Same as ActuallyAddGRMGroups but if the lists are null, then it doesn't
01886                 go through the grmfile itself, slowly... as this is no longer relevent.
01887 
01888     SeeAlso:    ActuallyAddGRMGroups;           
01889                 
01890 
01891 ********************************************************************************************/
01892 
01893 BOOL LibraryGallery::GoAndAddGRMGroups(/*SGLibType LibType*/ List *TypeList, List *PathList, List *DescList, BOOL DescPresent,
01894                                        String_256 *SectionName, String_256 *DescriptionSectionName)
01895 {
01896     ERROR2IF(PathList == NULL || DescList == NULL,FALSE,"GoAndAddGRMGroups bad lists!");
01897     ERROR2IF(SectionName == NULL || DescriptionSectionName == NULL,FALSE,"GoAndAddGRMGroups bad section names!");
01898 
01899     ListItem *TypeItem = NULL;
01900     ListItem *PathItem = NULL;
01901     ListItem *DescItem = NULL;
01902     String_256 Entry;
01903     INT32 LineCount = 0;
01904     INT32 Line = 1;
01905     BOOL ValidLine = TRUE;
01906     BOOL GroupsAdded = FALSE;
01907 
01908     LineCount = PathList->GetCount() + 1;
01909 
01910     // Work out the location of web folders so we can flag them as such
01911     String_256 strWebFoldersPath;
01912     GetAppCachePath(&strWebFoldersPath);
01913 
01914     if (LineCount > 0)
01915     {
01916         String_64 SlowJob(_R(IDS_LIBRARY_SCANNING));
01917         BeginSlowJob(LineCount, FALSE, &SlowJob);
01918 
01919         // Need to reset the Quiet status before a stream of Library::Init calls
01920         SetQuietStatus(FALSE);
01921 
01922         Line = 1;
01923         ValidLine = TRUE;
01924 
01925         BOOL EscapePressed = FALSE;
01926     
01927         while (ValidLine && !EscapePressed)
01928         {
01929             EscapePressed = !ContinueSlowJob(Line);
01930 
01931             if(PathItem == NULL)
01932                 PathItem = PathList->GetHead();
01933             else
01934                 PathItem = PathList->GetNext(PathItem);
01935             ValidLine = (PathItem != NULL && ((LibSettingsListItem *)PathItem)->Line != NULL);
01936             if (ValidLine)
01937                 Entry = *((LibSettingsListItem *)PathItem)->Line;
01938             Line ++;
01939 
01940             if (ValidLine)
01941             {
01942                 // See if we've got descriptions as well
01943                 String_256 *pDescString = NULL;
01944                 String_256 DescString;
01945                 if (DescPresent)
01946                 {
01947                     if(DescItem == NULL)
01948                         DescItem = DescList->GetHead();
01949                     else
01950                         DescItem = DescList->GetNext(DescItem);
01951 
01952                     if(DescItem != NULL && ((LibSettingsListItem *)DescItem)->Line != NULL)
01953                     {
01954                         DescString = *((LibSettingsListItem *)DescItem)->Line;
01955                         pDescString = &DescString;
01956                     }
01957                 }
01958 
01959                 Line ++;
01960 
01961 
01962                 // See if we've got library types as well
01963                 SGLibType m_SGLibType;
01964                 String_256 TypeString;
01965                 INT32 TypeInt;
01966                 if (DescPresent)
01967                 {
01968                     if(TypeItem == NULL)
01969                         TypeItem = TypeList->GetHead();
01970                     else
01971                         TypeItem = TypeList->GetNext(TypeItem);
01972 
01973                     if(TypeItem != NULL && ((LibSettingsListItem *)TypeItem)->Line != NULL)
01974                     {
01975                         INT32 pos = 0;
01976                         TypeString = *((LibSettingsListItem *)TypeItem)->Line;
01977                         TypeInt = TypeString.ConvertToInteger(pos);
01978                         m_SGLibType = (SGLibType)TypeInt;
01979                     }
01980                 }
01981                 //>> webster (Adrian 3/01/96)
01982                 // Check if the catalog file still exists and is accessible - the web clipart folder
01983                 // might have been deleted in the meantime - in which case we'll skip it
01984                 BOOL bIsWebFolder = !_tcsncicmp(Entry, strWebFoldersPath, _tcsclen(strWebFoldersPath));
01985                 // BUT if it is a CD based folder and the CD ROM is not present then this test will fail.
01986                 // This is very very very bad. We need to only check this if we are in the web case.
01987                 // Otherwise, if the user opens the gallery without the CD ROM present, they loose all their
01988                 // CD gallery entries. Older versions always show the glalery entries and it is only when
01989                 // the user opens a section that it errors and tells them about the problem, giving them
01990                 // a chance to fix it.
01991                 // Neville 12/11/97
01992                 BOOL bIsIndexPresent = (_access((TCHAR*) Entry, 0) != -1);
01993                 if (!bIsWebFolder || (bIsWebFolder && bIsIndexPresent))
01994                 {
01995                     // open the library file
01996                     LibraryFile *LibFile = new LibraryFile;
01997                     if (LibFile != NULL)
01998                     {
01999                         PathName path(Entry);
02000                         if(!LibFile->AddSpecificIndex(this, &path, m_SGLibType, pDescString, 0, bIsWebFolder))
02001                             delete LibFile;                                         
02002                         else
02003                         {
02004                             OpenLibFiles.AddTail(LibFile);
02005                             GroupsAdded = TRUE;
02006                         }
02007                     }
02008                 }
02009             }   
02010         }
02011         EndSlowJob();
02012     }
02013 
02014     return GroupsAdded;
02015 }
02016 
02017 /********************************************************************************************
02018 
02019 >   BOOL LibraryGallery::ActuallyAddGRMGroups(SGLibType LibType, List *PathList, List *DescList, BOOL DescPresent,
02020     String_256 *SectionName, String_256 *DescriptionSectionName)
02021 
02022     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
02023     Created:    26/1/96
02024 
02025     Inputs:     LibType     - The type of library we're adding
02026                 PathList    - List of Pathnames for the groups (optional, can be NULL, but slower...)
02027                 DescList    - List of Descriptions to display for the groups (optional, can be NULL, but slower...)
02028                 DescPresent - Are descriptions present ?
02029                 SectionName - Section name for the paths
02030                 DescriptionSectionName - Section name for the descriptions
02031 
02032     Returns:    TRUE if new groups added
02033 
02034     Purpose:    Given two lists, create all the groups in the gallery from them. If the lists are null, then
02035                 we go through the grmfile itself, slowly...
02036 
02037 ********************************************************************************************/
02038 
02039 BOOL LibraryGallery::ActuallyAddGRMGroups(/*SGLibType LibType*/ List *TypeList, List *PathList, List *DescList, BOOL DescPresent,
02040     String_256 *SectionName, String_256 *DescriptionSectionName)
02041 {
02042     ListItem *TypeItem = NULL;
02043     ListItem *PathItem = NULL;
02044     ListItem *DescItem = NULL;
02045     String_256 Entry;
02046     INT32 LineCount = 0;
02047     INT32 Line = 1;
02048     BOOL ValidLine = TRUE;
02049     BOOL GroupsAdded = FALSE;
02050 
02051     // Work out the location of web folders so we can flag them as such
02052     String_256 strWebFoldersPath;
02053     GetAppCachePath(&strWebFoldersPath);
02054 
02055     if(PathList != NULL)
02056         LineCount = PathList->GetCount() + 1;
02057     else
02058         while(ValidLine)
02059         {
02060             ValidLine = LibSettings::GetEntry(SectionName, Line++, &Entry);
02061             LineCount ++;
02062         };
02063 
02064     if(LineCount > 0)
02065     {
02066         String_64 SlowJob(_R(IDS_LIBRARY_SCANNING));
02067         BeginSlowJob(LineCount, FALSE, &SlowJob);
02068 
02069         // Need to reset the Quiet status before a stream of Library::Init calls
02070         SetQuietStatus(FALSE);
02071 
02072         Line = 1;
02073         ValidLine = TRUE;
02074 
02075         BOOL EscapePressed = FALSE;
02076     
02077         while(ValidLine && !EscapePressed)
02078         {
02079             EscapePressed = !ContinueSlowJob(Line);
02080 
02081             if(PathList != NULL)
02082             {
02083                 if(PathItem == NULL)
02084                     PathItem = PathList->GetHead();
02085                 else
02086                     PathItem = PathList->GetNext(PathItem);
02087                 ValidLine = (PathItem != NULL && ((LibSettingsListItem *)PathItem)->Line != NULL);
02088                 if(ValidLine)
02089                     Entry = *((LibSettingsListItem *)PathItem)->Line;
02090                 Line ++;
02091             }
02092             else
02093                 ValidLine = LibSettings::GetEntry(SectionName, Line++, &Entry);
02094 
02095             if(ValidLine)
02096             {
02097                 // See if we've got descriptions as well
02098                 String_256 *pDescString = NULL;
02099                 String_256 DescString;
02100                 if(DescPresent)
02101                 {
02102                     if(DescList != NULL)
02103                     {
02104                         if(DescItem == NULL)
02105                             DescItem = DescList->GetHead();
02106                         else
02107                             DescItem = DescList->GetNext(DescItem);
02108 
02109                         if(DescItem != NULL && ((LibSettingsListItem *)DescItem)->Line != NULL)
02110                         {
02111                             DescString = *((LibSettingsListItem *)DescItem)->Line;
02112                             pDescString = &DescString;
02113                         }
02114                         Line ++;
02115                     }
02116                     else
02117                     {
02118                         if(LibSettings::GetEntry(DescriptionSectionName, (Line-1), &DescString))
02119                             pDescString = &DescString;
02120                     }
02121                 }
02122 
02123                 // See if we've got library types as well
02124                 SGLibType m_SGLibType;
02125                 String_256 TypeString;
02126                 INT32 TypeInt;
02127                 if(DescPresent)
02128                 {
02129                     if(TypeList != NULL)
02130                     {
02131                         if(TypeItem == NULL)
02132                             TypeItem = TypeList->GetHead();
02133                         else
02134                             TypeItem = TypeList->GetNext(DescItem);
02135 
02136                         if(TypeItem != NULL && ((LibSettingsListItem *)TypeItem)->Line != NULL)
02137                         {
02138                             INT32 pos = 0;
02139                             TypeString = *((LibSettingsListItem *)TypeItem)->Line;
02140                             TypeInt = TypeString.ConvertToInteger(pos);
02141                             m_SGLibType = (SGLibType)TypeInt;
02142                         }
02143                     }
02144                     else
02145                     {
02146                         String_256 LibraryTypesSectionName;
02147                         WorkOutLibraryTypeSectionName(&LibraryTypesSectionName);
02148                         if(LibSettings::GetEntry(&LibraryTypesSectionName, (Line-1), &TypeString))
02149                         {
02150                             INT32 pos = 0;
02151                             TypeInt = TypeString.ConvertToInteger(pos);
02152                             m_SGLibType = (SGLibType)TypeInt;
02153                         }
02154                     }
02155                 }
02156 
02157 
02158                 //>> webster (Adrian 3/01/96)
02159                 // Check if the catalog file still exists and is accessible - the web clipart folder
02160                 // might have been deleted in the meantime - in which case we'll skip it
02161                 BOOL bIsWebFolder = (camStrstr((TCHAR*) Entry, (TCHAR*) strWebFoldersPath) != NULL);
02162                 // BUT if it is a CD based folder and the CD ROM is not present then this test will fail.
02163                 // This is very very very bad. We need to only check this if we are in the web case.
02164                 // Otherwise, if the user opens the gallery without the CD ROM present, they loose all their
02165                 // CD gallery entries. Older versions always show the glalery entries and it is only when
02166                 // the user opens a section that it errors and tells them about the problem, giving them
02167                 // a chance to fix it.
02168                 // Neville 12/11/97
02169                 BOOL bIsIndexPresent = (_access((TCHAR*) Entry, 0) != -1);
02170                 if (!bIsWebFolder || (bIsWebFolder && bIsIndexPresent))
02171                 {
02172                     // open the library file
02173                     LibraryFile *LibFile = new LibraryFile;
02174                     if (LibFile != NULL)
02175                     {
02176                         // 'Entry' now points to a specific index file. We have to add this to the
02177                         // gallery...
02178                         PathName path(Entry);
02179                         if(!LibFile->AddSpecificIndex(this, &path, m_SGLibType, pDescString, 0, bIsWebFolder))
02180                             delete LibFile;                                         
02181                         else
02182                         {
02183                             OpenLibFiles.AddTail(LibFile);
02184                             GroupsAdded = TRUE;
02185                         }
02186                     }
02187                 }
02188             }   
02189         }
02190         EndSlowJob();
02191     }
02192 
02193     return GroupsAdded;
02194 }
02195 
02196 /********************************************************************************************
02197 
02198 >   INT32 LibraryGallery::LibraryGroupsInGallery(void);
02199 
02200     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
02201     Created:    29/5/95
02202 
02203     Inputs:     
02204     Returns:    Number of library groups in the gallery
02205 
02206     Purpose:    Count the number of library groups in the gallery
02207 
02208 ********************************************************************************************/
02209 
02210 INT32 LibraryGallery::LibraryGroupsInGallery(void)
02211 {
02212     return (OpenLibFiles.GetCount());
02213 }
02214 
02215 /********************************************************************************************
02216 
02217 >   void LibraryGallery::GalleryAboutToClose(void)
02218 
02219     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
02220     Created:    1/6/95
02221 
02222     Purpose:    The gallery is about to close, so free any excess memory taken up by the indexes
02223                 and things...
02224 
02225 ********************************************************************************************/
02226 
02227 void LibraryGallery::GalleryAboutToClose(void)
02228 {
02229     TRACEUSER( "Richard", _T("Gallery about to close\n"));
02230 
02231     // Update the GRM file
02232     UpdateGRMFile();
02233 
02234     String_64 ProgMsg(_R(IDS_GALLERY_FREEING_MEMORY_ON_CLOSE));
02235     BeginSlowJob(-1, TRUE, &ProgMsg);
02236 
02237     if(FALSE)
02238     {
02239         // This will delete ALL the memory used by galleries when they close...
02240         OpenLibFiles.DeleteAll();
02241     }
02242     else
02243     {
02244         if(!OpenLibFiles.IsEmpty())
02245         {
02246             INT32 LibFileCount = OpenLibFiles.GetCount();
02247 
02248             if(LibFileCount > 0)
02249             {
02250                 // Loop through library files
02251                 for(INT32 LibFileLoop = 0; LibFileLoop < LibFileCount; LibFileLoop ++)
02252                 {
02253                     LibraryFile *LibFile = (LibraryFile *)OpenLibFiles.FindItem(LibFileLoop);
02254                     INT32 LibCount = LibFile->Libraries.GetCount();
02255                     if(LibCount > 0)
02256                     {
02257                         // Loop through library groups
02258                         for(INT32 LibLoop = 0; LibLoop < LibCount; LibLoop ++)
02259                         {
02260                             Library *Lib = (Library *)LibFile->Libraries.FindItem(LibLoop);
02261                             if(Lib != NULL)
02262                                 Lib->FreeCachedIndexes();
02263                         }
02264                     }
02265                 }
02266             }
02267         }
02268     }
02269 
02270     EndSlowJob();
02271 
02272     VirtualiseAllFoldedGroups();
02273 }
02274 
02275 /********************************************************************************************
02276 
02277 >   virtual void LibraryGallery::VirtualiseAllFoldedGroups(void)
02278 
02279     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
02280     Created:    11/1/96
02281 
02282     Purpose:    Go through the gallery tree and virtualise all folded groups which can be
02283                 virtualised.
02284 
02285     Notes:      There is now a time-out facility if we find we are taking too long...
02286 
02287 ********************************************************************************************/
02288 
02289 void LibraryGallery::VirtualiseAllFoldedGroups(void)
02290 {
02291     const INT32 TimeLimit = 1 * 1000; // 1 second time out...
02292     
02293     SGDisplayGroup *Group = (SGDisplayGroup *)GetDisplayTree()->GetChild(); 
02294     if(Group != NULL)
02295     {
02296         INT32 Groups = 0;
02297         while(Group != NULL)
02298         {
02299             Groups++;
02300             Group = (SGDisplayGroup *)Group->GetNext();
02301         }
02302 
02303         String_64 ProgMsg(_R(IDS_GALLERY_FREEING_MEMORY_ON_CLOSE));
02304         BeginSlowJob(Groups, TRUE, &ProgMsg);
02305 
02306         INT32 Count = 0;
02307         Group = (SGDisplayGroup *)GetDisplayTree()->GetChild();
02308 
02309         MonotonicTime TimeCheck;
02310         BOOL DoneAGroup = FALSE;
02311 
02312         while(Group != NULL)
02313         {
02314             if(ContinueSlowJob(Count++))
02315             {
02316                 if(Group->Flags.Folded && !Group->IsVirtualised() && Group->CanVirtualise() && !Group->IsSelected()
02317                     && !Group->Flags.Modified)
02318                 {
02319                     Group->Virtualise();
02320                     DoneAGroup = TRUE;
02321                 }
02322                 Group = (SGDisplayGroup *)Group->GetNext();
02323             }
02324             else
02325                 Group = NULL; // Escape pressed - stop virtualising right now !
02326 
02327             // Do it here so we ALWAYS release at least one group (if there are any)
02328             if(DoneAGroup && TimeCheck.Elapsed(TimeLimit))
02329                 Group = NULL; // Time limit exceeded - stop virtualising right now !
02330         }
02331 
02332         EndSlowJob();
02333     }
02334 }
02335 
02336 
02337 /********************************************************************************************
02338 
02339 >   void LibraryGallery::GalleryAboutToReOpen(void)
02340 
02341     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
02342     Created:    1/6/95
02343 
02344     Purpose:    The gallery is about to reopen, so recache any indexes or other information
02345                 that we might need...
02346 
02347     Notes:      This is called every time the gallery opens, so the static at the start stops
02348                 the code from being used the first time... (Since the initialisation routines
02349                 are supposed to handle everything correctly)
02350 
02351 ********************************************************************************************/
02352 
02353 void LibraryGallery::GalleryAboutToReOpen(void)
02354 {
02355     TRACEUSER( "Richard", _T("Gallery about to open\n"));
02356 
02357     if(!OpenLibFiles.IsEmpty())
02358     {
02359         INT32 LibFileCount = OpenLibFiles.GetCount();
02360 
02361         if(LibFileCount > 0)
02362         {
02363             // Dummy run to count the groups for the progress bar
02364             INT32 GroupCount = 0;
02365             INT32 LibFileLoop = 0;
02366             for(LibFileLoop = 0; LibFileLoop < LibFileCount; LibFileLoop ++)
02367             {
02368                 LibraryFile *LibFile = (LibraryFile *)OpenLibFiles.FindItem(LibFileLoop);
02369                 if(LibFile != NULL)
02370                     GroupCount += LibFile->Libraries.GetCount();
02371             }
02372 
02373             if(GroupCount > 0)
02374             {
02375                 String_64 SlowJob(_R(IDS_LIBRARY_CACHING_INDEXES));
02376                 BeginSlowJob(GroupCount, FALSE, &SlowJob);
02377             }
02378 
02379             // Count so we can tell where we are in the LibFile list
02380             INT32 LibFilesDeleted = 0;
02381             INT32 OriginalLibFileCount = LibFileCount;
02382             INT32 ActualCount = 0;  
02383 
02384             // Used by the error box if the CD's not there...           
02385             INT32 LastButtonPressed = 2;    
02386 
02387             // Loop through library files
02388             for(LibFileLoop = 0; LibFileLoop < OriginalLibFileCount; LibFileLoop ++)
02389             {
02390                 LibraryFile *LibFile = (LibraryFile *)OpenLibFiles.FindItem(LibFileLoop - LibFilesDeleted);
02391                 if(LibFile != NULL)
02392                 {
02393                     INT32 LibCount = LibFile->Libraries.GetCount();
02394                     if(LibCount > 0)
02395                     {
02396                         // Count so we can tell where we are in the lib list
02397                         INT32 LibsDeleted = 0;
02398                         INT32 OriginalLibCount = LibCount;
02399                     
02400                         // Loop through library groups
02401                         for(INT32 LibLoop = 0; LibLoop < OriginalLibCount; LibLoop ++)
02402                         {
02403                             // Found a library, possibly without its index file in memory...
02404                             Library *Lib = (Library *)LibFile->Libraries.FindItem(LibLoop - LibsDeleted);
02405                             if(Lib != NULL)
02406                             {
02407                                 if(LastButtonPressed != 3)
02408                                     LastButtonPressed = 2;
02409 
02410                                 BOOL RepeatTheLoop = FALSE;
02411                                 BOOL Remove = FALSE;
02412                                 BOOL Recache = TRUE;
02413                                 do {
02414                                     RepeatTheLoop = FALSE;
02415                                     
02416                                     Recache = Lib->ReCacheIndexes();
02417                                     if(!Recache)
02418                                     {
02419                                         if(LastButtonPressed != 3)
02420                                         {
02421                                             String_256 WarnMsg;
02422                                             String_256 Section;                     
02423                                             String_64 SmallSection;                     
02424                                             Lib->GetLibraryTitle(&Section);
02425                                             Section.Left(&SmallSection, 36);
02426                                             // Be very careful that this message does not exceed 255 bytes...
02427                                             WarnMsg.MakeMsg(_R(IDS_LIBRARY_CD_REMOVED), (TCHAR *)SmallSection);
02428 
02429                                             Error::SetError(0, WarnMsg, 0);
02430                                             LastButtonPressed = InformWarning(0, _R(IDS_CONTINUE), _R(IDS_RETRY), _R(IDS_QUIET), NULL, 2, 1);
02431 
02432                                             // RETRY
02433                                             if(LastButtonPressed == 2)
02434                                                 RepeatTheLoop = TRUE;
02435                                         }                           
02436                                         // Continue or Quiet                
02437                                         if(LastButtonPressed == 1 || LastButtonPressed == 3)
02438                                             Remove = TRUE;
02439                                     }
02440                                 } while(RepeatTheLoop);
02441 
02442                                 if(Remove)
02443                                 {
02444                                     // If there were problems recaching the index, delete the group from the gallery
02445                                     Lib->ParentGroup->DestroySubtree(TRUE);
02446 
02447                                     // Delete the relevant library
02448                                     delete(LibFile->Libraries.RemoveItem(Lib));
02449                                     LibsDeleted ++;
02450 
02451                                     // And delete the libfile structure
02452                                     LibCount = LibFile->Libraries.GetCount();
02453                                     if(LibCount == 0)
02454                                     {
02455                                         delete(OpenLibFiles.RemoveItem(LibFile));
02456                                         LibFilesDeleted ++;
02457                                     }
02458                                 }
02459                             }
02460                             // Update the progress bar for each group
02461                             ContinueSlowJob(++ActualCount);     
02462                         }
02463                     }
02464                 }
02465             }
02466             EndSlowJob();
02467         }
02468     }
02469 }
02470 
02471 
02472 /********************************************************************************************
02473 
02474 >   BOOL LibraryGallery::RemoveWebFolders(SGLibType type)
02475 
02476     Author:     Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
02477     Created:    3/01/97
02478 
02479     Inputs:     type - one of   SGLib_ClipArt,  SGLib_Font, SGLib_Fractal
02480     Returns:    TRUE if the folders are removed, FALSE otherwise 
02481 
02482     Purpose:    Reclaims space taken up by downloaded files of a certain type
02483                         on the local machine
02484 
02485 ********************************************************************************************/
02486 
02487 BOOL LibraryGallery::RemoveWebFolders(SGLibType type)
02488 {
02489     if (AskQuestion(_R(IDS_WARNREMOVE), _R(IDS_EMPTY), _R(IDS_CANCEL)) == _R(IDS_CANCEL))
02490         return FALSE;
02491 
02492     // If the application is installed on the local hard disk, web folders will be in the cache
02493     String_256 strLocation;
02494     GetAppDataPath(&strLocation);
02495     strLocation += GetStringField(type, _R(IDS_CACHEDIR));
02496 
02497     if (_access((TCHAR*) strLocation, 0) != -1) // found it
02498     {
02499         DownloadCache::Traverse(strLocation, TRUE);
02500         DownloadCache::Refresh();
02501         SelectionHasChanged();
02502         return TRUE;
02503     }
02504     else 
02505         return FALSE;
02506 }
02507 
02508 
02509 
02510 
02511 /********************************************************************************************
02512 >   void LibraryGallery::SuspendThumbnailDownloading()
02513 
02514     Author:     Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
02515     Created:    3/01/97
02516 
02517     Inputs:     none
02518     Returns:    -
02519 
02520     Purpose:    Prevents further thumbnail downloading and cancels the downloads
02521                     already queued up. Used in response to a user cancel or a serious 
02522                     error.
02523 
02524 ********************************************************************************************/
02525 void LibraryGallery::SuspendThumbnailDownloading()
02526 
02527 {
02528     bThumbDownloading = FALSE;
02529     if (!m_lstPendingThumbs.empty()) // we have downloads pending, so we must end them
02530     {
02531         OpThumbDownload::Suspend(); // temporarily suspend executing downloads so that the pending download list is frozen
02532         // Iterate through the download list and end all download operation
02533         std::list<OpThumbDownload*>::iterator listIterator = m_lstPendingThumbs.begin();
02534         INT32 nListSize = m_lstPendingThumbs.size();
02535         for (INT32 i = 0; i < nListSize; i++)
02536         {
02537             OpThumbDownload* pDownloadOp = *listIterator++;
02538             ERROR3IF(!pDownloadOp || !pDownloadOp->IsKindOf(CC_RUNTIME_CLASS(OpThumbDownload)), "Ooops! Invalid pointer - we're about to crash");
02539             pDownloadOp->End();
02540         }
02541         OpThumbDownload::Resume(); // we're done - let the thumbs requested by other galleries continue downloading
02542         ERROR3IF(!m_lstPendingThumbs.empty(),"Failed to remove all pending downloads"); // just in case
02543     }
02544 }
02545 
02546     
02547 /********************************************************************************************
02548 
02549 >   void LibraryGallery::ResumeThumbnailDownloading()
02550 
02551     Author:     Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
02552     Created:    3/01/97
02553 
02554     Inputs:     none
02555     Returns:    -
02556 
02557     Purpose:    Restarts thumbnail downloading and clears all previous download erorrs
02558 
02559 ********************************************************************************************/
02560 
02561 void LibraryGallery::ResumeThumbnailDownloading()
02562 {
02563     OpThumbDownload::ClearErrors();
02564     bThumbDownloading = TRUE;
02565 }
02566 
02567 
02568 
02569 /********************************************************************************************
02570 
02571 >   BOOL LibraryGallery::OnGetButtonClicked()
02572 
02573     Author:     Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
02574     Created:    15/12/96
02575 
02576     Inputs:     
02577     Returns:    TRUE if web folders have been added successfully
02578 
02579     Purpose:    Attempts to download the main web resource index file from our web site,
02580                     parse it and create corresponding gallery folders
02581 
02582 ********************************************************************************************/
02583 
02584 BOOL LibraryGallery::OnGetButtonClicked()
02585 
02586 {
02587     // Connect to the Net if not yet connected
02588     // This works only to some extent i.e. AttemptConnection() returns TRUE if the dial-up dialog has been created
02589     // successfully but it can't tell if a TCP/IP connection is eventually established. Anyway, all network operations
02590     // will eventually time out if nothing seems to be happening.
02591     if (!InternetManager::AttemptConnection())
02592     {
02593         InformError(_R(IDS_NOTCONNECTED), _R(IDS_OK));
02594         return FALSE;
02595     }
02596     // (re)enable thumbnail downloading in case it has been stopped
02597     ResumeThumbnailDownloading();
02598     ForceRedrawOfList();
02599     if (OpAddWebFolders::Success[GetGalleryType()] && !m_bDiscardWebFolders) // nothing else to do
02600         return TRUE;
02601     m_bDiscardWebFolders = FALSE;
02602     String_256 strIndexURL(GetStringField((UINT32) GetGalleryType(), _R(IDS_MAININDEXURL)));
02603     // We initiate the download of the web clipart index file to a temporary file in $WINDIR\Temporary Internet Files
02604     String_256 strTempFile;
02605     GetTempInetDir(&strTempFile);
02606     strTempFile += GetStringField((UINT32) GetGalleryType(), _R(IDS_TMPFILES));
02607     OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(CC_RUNTIME_CLASS(OpAddWebFolders));
02608     if (pOpDesc != NULL)
02609     {
02610         AddWebFoldersParam* Param = new AddWebFoldersParam;
02611         ERROR2IF(!Param, FALSE, "Memory allocation error");
02612         // Set up the op's param
02613         Param->localFile.SetPathName((TCHAR *) strTempFile); // local path of index file
02614         Param->strURL = strIndexURL; // URL of index file on our web server
02615         Param->pLibGal = this; // pointer to the gallery to add folders to
02616         Param->type = GetGalleryType();
02617         // Invoke the operation - this will initiate the download of the index file
02618         // No result is returned, but the Op will report itself any error that might occur
02619         pOpDesc->Invoke((OpParam*) Param);
02620     }
02621     else
02622     {
02623         ERROR3("OpAddWebFolders not found");
02624         return FALSE;
02625     }
02626     return TRUE;
02627 }
02628 
02629 
02630 
02631 
02632 /********************************************************************************************
02633 
02634 >   Library* LibraryGallery::FindLibrary(const String_256& strLibPath)
02635 
02636     Author:     Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
02637     Created:    15/12/96
02638 
02639     Inputs:     strLibPath - full path to the library index file
02640     Returns:    a pointer to the library if found, NULL otherwise
02641 
02642 ********************************************************************************************/
02643 
02644 
02645 Library* LibraryGallery::FindLibrary(const String_256& rLibPath)
02646 {
02647     String_256 strLibPath(rLibPath);
02648     LibraryFile* pLibFile = (LibraryFile*) OpenLibFiles.GetHead();
02649     while (pLibFile)
02650     {
02651         Library* pLib = (Library*) pLibFile->Libraries.GetHead();
02652         while (pLib)
02653         {
02654             if (strLibPath.CompareTo(pLib->ReturnIndexLocation()->GetPath(), FALSE))
02655                 pLib = (Library*) pLibFile->Libraries.GetNext(pLib);
02656             else
02657                 return pLib; // we found it
02658         }
02659         pLibFile = (LibraryFile*) OpenLibFiles.GetNext(pLibFile);
02660     }
02661     return NULL;
02662 }

Generated on Sat Nov 10 03:46:54 2007 for Camelot by  doxygen 1.4.4