sglcart.cpp

Go to the documentation of this file.
00001 // $Id: sglcart.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 // SGLibClipart.cpp - LibClipart SuperGallery classes - LibClipartSGallery and SGDisplayLibClipart
00099 
00100 #include "camtypes.h"
00101 #include "sglcart.h"
00102 #include <io.h>
00103 
00104 //#include "app.h"      // For GetApplication() - in camtypes.h [AUTOMATICALLY REMOVED]
00105 //#include "galstr.h"
00106 //#include "pathname.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00107 #include "sginit.h"
00108 #include "sglcart.h"    // This .cpp file's corresponding header
00109 #include "sglib.h"
00110 #include "sgmenu.h"
00111 //#include "sgtree.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00112 //#include "thumb.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00113 #include "sglfills.h"
00114 #include "thumbmsg.h"
00115 #include "grnddib.h"
00116 //#include "galres.h"
00117 //#include "richard.h"
00118 #include "sgliboil.h"
00119 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00120 //#include "fixmem.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00121 //#include "selop.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00122 #include "filedlgs.h"
00123 //#include "document.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00124 #include "progress.h"
00125 #include "camelot.h"
00126 #include "dragmgr.h"
00127 //#include "viewrc.h"       // FOR _R(IDC_CANDROPONPAGE)
00128 //#include "resource.h"
00129 //#include "docview.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00130 #include "scrcamvw.h"
00131 //#include "spread.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00132 //#include "sgscan.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00133 #include "sgscanf.h"
00134 #include "sglbase.h"
00135 #include "sgrmfile.h"   // For Lib settings
00136 //#include "richard2.h" // For yet more resource strings
00137 #include "keypress.h"   // For adjust checking
00138 #include "fileutil.h"
00139 #include "camdoc.h"
00140 #include "pathnmex.h"
00141 //#include "webster.h"
00142 #include "inetop.h"
00143 #include "camnet.h"
00144 //#include "simon.h"
00145 
00146 //#include "richard3.h" // For _R(IDS_GALLERY_FREEING_MEMORY_ON_CLOSE)
00147 
00148 #ifdef _BATCHING
00149 #define SAVEASWELL 1
00150 // For batching...
00151 #include <stdio.h>
00152 //#include "spread.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00153 //#include "document.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00154 #include "page.h"
00155 #include "pagesize.h"
00156 #include "optspage.h"
00157 //#include "units.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00158 #include "grid.h"
00159 #include "zoomops.h"
00160 #include "layer.h"
00161 //#include "node.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00162 #include "collist.h"
00163 #include "colourix.h"
00164 #include "colormgr.h"
00165 #include "webop.h"
00166 #endif
00167 
00168 #include "helpuser.h"       //For the help button
00169 //#include "xshelpid.h"     //For the help button
00170 //#include "helppath.h"
00171 //#include "mario.h"            //For _R(IDE_NOMORE_MEMORY)
00172 #include "resdll.h"
00173 
00174 using namespace InetUtils;
00175 
00176 
00177 // Implement the dynamic class bits...
00178 CC_IMPLEMENT_DYNCREATE(LibClipartSGallery, LibraryGallery)
00179 CC_IMPLEMENT_DYNCREATE(OpDisplayLibClipartGallery, Operation)
00180 CC_IMPLEMENT_DYNCREATE(SGClipartItem, SGLibDisplayItem)
00181 CC_IMPLEMENT_DYNCREATE(GalleryClipartDragInfo, BitmapDragInformation)
00182 CC_IMPLEMENT_DYNAMIC(SGClipartDragTarget, SGListDragTarget)
00183 CC_IMPLEMENT_DYNAMIC(SGOilClipartDragTarget, WinoilDragTarget)
00184 CC_IMPLEMENT_DYNCREATE(OpLibGalClipTheme, OpDescriptor);
00185 
00186 // This line mustn't go before any CC_IMPLEMENT_... macros
00187 #define new CAM_DEBUG_NEW
00188 
00189 /*
00190 //Static Variables
00191 #ifdef _DEBUG
00192 //String_256 LibClipartSGallery::DefaultLibraryPath = TEXT("\\\\deepthought\\camelotcd\\cd\\clipart");
00193 String_256 LibClipartSGallery::DefaultLibraryPath = TEXT("\\\\jimpc\\corelxra\\clipart");
00194 #else
00195 String_256 LibClipartSGallery::DefaultLibraryPath = TEXT("D:\\clipart");
00196 #endif
00197 */
00198 
00199 
00200 // Matt - 03/01/2001
00201 // New statics - we need to remember two directories (one for clipart, one for web themes) + I don't see the need for a debug
00202 // special version of these statics as \\jimpc won't have a '\themes' subdirectory anyway...
00203 
00204 // Statics
00205 String_256 LibClipartSGallery::ClipartPath = TEXT("D:\\clipart");
00206 String_256 LibClipartSGallery::WebThemePath = TEXT("D:\\themes");
00207 String_256 LibClipartSGallery::DefaultLibraryPath = ClipartPath;
00208 
00209 // For keeping the display modes constant when next loaded
00210 INT32 LibClipartSGallery::DefaultDisplayMode = 0;   // WEBSTER - markn 7/2/97 (changed default display mode)
00211 
00212 
00213 // For keeping the sort keys constant when next loaded (default == sort alphabetically)
00214 // 1st sort key = DefaultSortKeys & 0x8f
00215 // 2nd sort key = ((DefaultSortKeys>>8) & 0x8f)
00216 // 1st sort key reversed = ((DefaultSortKeys>>7) & 0x01)==1
00217 // 2nd sort key reversed = ((DefaultSortKeys>>15) & 0x01)==1
00218 // So 0 means no sorting at all
00219 // and 1 means sort the gallery alphabetically
00220 UINT32 LibClipartSGallery::DefaultSortKeys = 1;
00221 
00222 // Batching system will use this directory to put its output in
00223 String_256 LibClipartSGallery::BatchSaveLocation = "";
00224 
00225 BOOL LibClipartSGallery::DoSounds = TRUE;
00226 
00227 // Should always be pointing at a clipart gallery
00228 LibClipartSGallery *LibClipartSGallery::ThisGallery = NULL;
00229 
00230 LibClipartSGallery* LibClipartSGallery::m_pInstance = 0;
00231 
00232 // Quiet status of gallery
00233 BOOL LibClipartSGallery::QuietStatus = FALSE;
00234 
00235 
00236 
00237 //#define _PROFILE_REDRAW
00238 
00239 /********************************************************************************************
00240 
00241 >   LibClipartSGallery::LibClipartSGallery()
00242                                                  
00243     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00244     Created:    27/1/95 (base generated in sgbase.cpp)
00245     Purpose:    LibClipartSGallery default constructor
00246 
00247 ********************************************************************************************/
00248 
00249 LibClipartSGallery::LibClipartSGallery()
00250 {
00251     LibClipartSGallery::ThisGallery = this;
00252     m_bDiscardWebFolders = FALSE;
00253     // Default gallery size
00254     CSize Size(((333 * 2) - 32) - 32, 256);
00255     SetGallerySize(Size);
00256     m_pInstance = this;
00257     m_nClipTheme = 0;
00258     m_bRedraw = false;
00259 }
00260 
00261 
00262 
00263 /********************************************************************************************
00264 
00265 >   LibClipartSGallery::~LibClipartSGallery()
00266 
00267     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00268     Created:    27/1/95 (base generated in sgbase.cpp)
00269     Purpose:    LibClipartSGallery destructor.
00270 
00271 ********************************************************************************************/
00272 
00273 LibClipartSGallery::~LibClipartSGallery()
00274 {
00275     TRACEUSER( "Matt", _T("~LibClipartSGallery\n"));
00276 
00277     OpenLibFiles.DeleteAll();       // Ensure all open libraries are closed
00278     LibClipartSGallery::ThisGallery = NULL;
00279     m_pInstance = 0;
00280 }
00281 
00282 
00283 /********************************************************************************************
00284 >   static LibClipartSGallery* LibClipartSGallery::Instance()
00285 
00286     Author:     Priestley (Xara Group Ltd) <camelotdev@xara.com>
00287     Created:    18/09/2000
00288     Returns:    The current LibClipartSGallery object.
00289 ********************************************************************************************/
00290 
00291 LibClipartSGallery* LibClipartSGallery::Instance()
00292 {
00293     ERROR3IF(m_pInstance == 0, "LibClipartSGallery::Instance: no gallery");
00294     return m_pInstance;
00295 }
00296 
00297 
00298 
00299 /********************************************************************************************
00300 
00301 >   static BOOL LibClipartSGallery::Init(void)
00302 
00303     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00304     Created:    23/2/95
00305 
00306     Returns:    TRUE if the sgallery initialised successfully
00307                 FALSE if it failed to initialise
00308     Purpose:
00309 
00310 ********************************************************************************************/
00311 
00312 BOOL LibClipartSGallery::Init(void)
00313 {
00314     TRACEUSER( "Matt", _T("Init clipart gallery\n"));
00315 #ifdef _BATCHING
00316         
00317     GetApplication()->DeclareSection(TEXT("Batching"), 6);
00318     GetApplication()->DeclarePref(TEXT("Batching"), TEXT("OutputDirectory"), &LibClipartSGallery::BatchSaveLocation);
00319 
00320 #endif
00321 
00322     if (!OpClipartImport::Init())
00323         return(FALSE);
00324 
00325     if (!OpAsynchClipartImport::Init())
00326         return(FALSE);
00327 
00328 
00329     return(TRUE);
00330 }
00331 
00332 
00333 
00334 /********************************************************************************************
00335 
00336 >   BOOL LibClipartSGallery::PreCreate(void)
00337 
00338     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00339     Created:    27/1/95 (base generated in sgbase.cpp)
00340 
00341     Returns:    TRUE if the Gallery initialised successfully
00342                 FALSE if it should not be opened due to a failure to initialise
00343 
00344     Purpose:    The LibClipartSGallery PreCreate handler. This overrides the base class
00345                 PreCreate function. It is called at the very beginning of the
00346                 SuperGallery::Create method, before the window has been created.
00347 
00348     Notes:      As this is called before the window is open, it must not attempt to touch
00349                 any of the button gadgets in the window, or force redraws, etc. Also,
00350                 events cannot be passed to the tree, as the tree formatting relies on
00351                 knowing the window size - however, the tree will be reformatted and
00352                 redrawn automatically when the window is opened - this will happen shortly.
00353 
00354 ********************************************************************************************/
00355 
00356 BOOL LibClipartSGallery::PreCreate(void)
00357 {
00358     TRACEUSER( "Matt", _T("Precreating clipart window\n"));
00359     // If there isn't already one, create a DisplayTree
00360     if (DisplayTree == NULL)
00361     {
00362         DisplayTree = new SGDisplayRootScroll(this);    // New root node, with a scrollbar
00363         if (DisplayTree == NULL)
00364             return(FALSE);
00365     }
00366 
00367     // Add the library groups to the gallery if they're not there already
00368     if(OpenLibFiles.IsEmpty())
00369     {
00370         if(!AddGRMGroups(SGLib_ClipArt))
00371         {
00372             String_256 sLoc = ClipartPath;
00373             String_256 sLoc2 = WebThemePath;
00374             // Set DefaultLibraryPath to <ExeLocation>\Fills - the user might have installed
00375             // the fills to his hard disk:
00376             String_256 sExePath;
00377             if(CResDll::GetExecutablePath((TCHAR*)sExePath))
00378             {
00379                 INT32 oldi = GetClipTheme();
00380 
00381                 String_256 LibDirName;
00382                 LibDirName.MakeMsg(_R(IDS_LIBRARIES_CLIPART_DIRNAME));
00383                 ClipartPath = sExePath;
00384                 ClipartPath += "\\";
00385                 ClipartPath += LibDirName;
00386 
00387                 PathName ThisPath(ClipartPath);
00388                 if(!SGLibOil::FileExists(&ThisPath))    // will also work for paths (not just paths with a filename on the end)
00389                 {
00390                     SetClipTheme(0);
00391                     // Fills not on hard disk. Try the CD location
00392                     if(!ScanForLocation(SGLib_ClipArt, NULL))
00393                     {
00394                         // hard drive and CD location not found
00395                         // put the original path back
00396                         ClipartPath = sLoc;
00397                     }
00398                 }
00399 
00400                 String_256 LibDirName2;
00401                 LibDirName2.MakeMsg(_R(IDS_LIBRARIES_WEBTHEMES_DIRNAME));
00402                 WebThemePath = sExePath;
00403                 WebThemePath += "\\";
00404                 WebThemePath += LibDirName2;
00405 
00406                 PathName ThisPath2(WebThemePath);
00407                 if(!SGLibOil::FileExists(&ThisPath2))   // will also work for paths (not just paths with a filename on the end)
00408                 {
00409                     SetClipTheme(0);
00410                     // Fills not on hard disk. Try the CD location
00411                     if(!ScanForLocation(SGLib_ClipArt_WebThemes, NULL))
00412                     {
00413                         // hard drive and CD location not found
00414                         // put the original path back
00415                         WebThemePath = sLoc;
00416                     }
00417                 }
00418                 // reset the ClipTheme value
00419                 SetClipTheme(oldi);
00420             }
00421 
00422             LibraryGallery::AddLibraryGroups(SGLib_ClipArt, &ClipartPath);
00423             LibraryGallery::AddLibraryGroups(SGLib_ClipArt_WebThemes, &WebThemePath);
00424         }
00425     }
00426 
00427     // Use last time's display mode
00428     DisplayMode = LibClipartSGallery::DefaultDisplayMode;
00429 
00430     return(TRUE);
00431 }
00432 
00433 
00434 
00435 /********************************************************************************************
00436 
00437 >   void LibClipartSGallery::SortGallery(void)
00438 
00439     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00440     Created:    2/5/95
00441 
00442     Inputs:     
00443     Returns:
00444 
00445     Purpose:    Sorts the contents of the gallery in an alphabetical fashion, whilst keeping
00446                 the old sort key status...
00447     Notes:      
00448     SeeAlso:
00449 
00450 ********************************************************************************************/
00451 
00452 void LibClipartSGallery::SortGallery(void)
00453 {
00454     // Matt - 03/01/2001
00455     // Special case fix ('bodgeus horriblus')- when we are in the clipart gallery we need to remember the default paths for either the web themes or clipart
00456     // - this method is called just after the defaultlibrarypath is set in the base class, so now's a good time to remember them...
00457     if (GetClipTheme() == 0)
00458     {
00459         LibClipartSGallery::ClipartPath = LibClipartSGallery::DefaultLibraryPath;
00460     }
00461     else
00462     {
00463         LibClipartSGallery::WebThemePath = LibClipartSGallery::DefaultLibraryPath;
00464     }
00465 
00466     LibraryGallery::SortGallery();
00467 }
00468 
00469 
00470 /********************************************************************************************
00471 
00472 >   virtual BOOL LibClipartSGallery::ApplyAction(SGActionType Action)
00473 
00474     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00475     Created:    27/1/95 (base generated in sgbase.cpp)
00476 
00477     Inputs:     Action - Indicates what action to apply
00478 
00479     Returns:    TRUE to indicate successful handling of the action, or
00480                 FALSE to indicate failure
00481 
00482     Purpose:    Applies certain conventional gallery actions (usually associated with
00483                 gallery buttons, for new, edit, delete, etc)
00484 
00485     SeeAlso:    SGActionType
00486 
00487 ********************************************************************************************/
00488 
00489 BOOL LibClipartSGallery::ApplyAction(SGActionType Action)
00490 {
00491     // No display tree? Better forget about it then!
00492     if (DisplayTree == NULL)
00493         return(FALSE);
00494 
00495     switch(Action)
00496     {
00497         case SGACTION_REDEFINE:
00498             break;
00499 
00500         case SGACTION_APPLY:
00501             ImportClipart(TRUE, this);
00502             break;
00503         
00504 /*      case SGACTION_APPLYADJUST:
00505             ImportClipart(FALSE);
00506             break;*/
00507 
00508         case SGACTION_EDIT:
00509             // Ignored - libraries are currently read-only
00510             break;
00511 
00512         case SGACTION_DELETE:
00513             // Ignored - libraries are currently read-only
00514             break;
00515 
00516         case SGACTION_SETOPTIONS:   // Set values in the options dialogue as it is opened
00517             {
00518                 if (CurrentOptionsDlg == NULL)
00519                     return(FALSE);
00520             
00521                 CurrentOptionsDlg->AddDisplayModeName(_R(IDS_GALLERYDM_LARGE));     // 0
00522                 CurrentOptionsDlg->AddDisplayModeName(_R(IDS_GALLERYDM_FULLINFO));  // 1
00523                 CurrentOptionsDlg->AddDisplayModeName(_R(IDS_GALLERYDM_SMALL));     // 2
00524             }
00525             break;
00526 
00527         case SGACTION_SETSORTMODE:
00528             {
00529                 if (CurrentSortDlg == NULL)
00530                     return(FALSE);
00531 
00532                 CurrentSortDlg->AddSortKeyName(_R(IDS_SORTBY_NAME));
00533                 CurrentSortDlg->AddSortKeyName(_R(IDS_SORTBY_MEMORY));
00534                 CurrentSortDlg->AddSortKeyName(_R(IDS_SORTBY_NAMELENGTH));
00535                 CurrentSortDlg->AddSortKeyName(_R(IDS_SORTBY_FILETYPE));
00536             }
00537                                     
00538             break;
00539 
00540 
00541         case SGACTION_DISPLAYMODECHANGED:
00542             if(DisplayMode >= 3) DisplayMode = 0;
00543             LibClipartSGallery::DefaultDisplayMode = DisplayMode;
00544             InvalidateCachedFormat();
00545             ReformatAndRedrawIfNecessary();
00546             //ForceRedrawOfList();
00547             break;
00548     
00549         default:
00550             return(SuperGallery::ApplyAction(Action));
00551             break;
00552     }
00553 
00554     return(TRUE);
00555 }
00556 
00557 
00558 
00559 /********************************************************************************************
00560 
00561 >   virtual MsgResult LibClipartSGallery::Message(Msg* Message)
00562 
00563     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00564     Created:    27/1/95 (base generated in sgbase.cpp)
00565     Inputs:     Message - The message to handle
00566 
00567     Purpose:    A standard message handler, really.
00568 
00569     Notes:      Any messages that this does not handle must be passed down to the
00570                 SuperGallery base class message handler.
00571 
00572                 NOTE WELL that the SuperGallery base class handler does some funky things
00573                 for us - see SuperGallery::Message - such as deleting our display subtree
00574                 for any document which dies (which, uncannily, would explain why they go
00575                 away like that when you close documents ;-), and shading the gallery when
00576                 there are no documents present. [To override this behaviour in these cases,
00577                 you should respond to the message, and return OK rather than calling the
00578                 base class message handler]
00579 
00580     SeeAlso:    SuperGallery::Message
00581 
00582 ********************************************************************************************/
00583 
00584 MsgResult LibClipartSGallery::Message(Msg* Message)
00585 {
00586     // Added by Craig Hamilton 18/1/01.
00587     static HANDLE   handle = NULL;
00588     CString         mutexName = "autorunMutex";
00589     // End added.
00590 
00591     // If we have no displaytree, then we have not been shown, or something terrible has
00592     // happened, so we don't bother handling any of these messages.
00593     if (DisplayTree == NULL)
00594         return(LibraryGallery::Message(Message));
00595 
00596     if (IS_OUR_DIALOG_MSG(Message))
00597     {
00598         DialogMsg* Msg = (DialogMsg*)Message;
00599 
00600         switch (Msg->DlgMsg)
00601         {
00602             case DIM_CREATE:
00603                 // Added by Craig Hamilton 18/1/01.
00604                 // This and the section of code of the same date in the DIM_CANCEL handler below
00605                 // deal with the creation and destruction of a kernel object that is recognised by
00606                 // the autorun. If this object exists then the autorun does not run. This is so
00607                 // that the user can enter their resources cd while the gallery is open and not be
00608                 // annoyed by the autorun appearing.
00609                 handle = CreateMutex(NULL,TRUE,mutexName);
00610                 // End added.
00611 
00612                 SGInit::UpdateGalleryButton(OPTOKEN_DISPLAYCLIPARTGALLERY, TRUE);
00613                 GalleryAboutToReOpen();
00614                 break;
00615 
00616             case DIM_CANCEL:
00617                 // Added by Craig Hamilton 18/1/01.
00618                 if(handle != NULL)
00619                 {
00620                     CloseHandle(handle);
00621                 }
00622                 // End added.
00623 
00624                 SGInit::UpdateGalleryButton(OPTOKEN_DISPLAYCLIPARTGALLERY, FALSE);
00625 
00626                 // Flush the thumbnail cache
00627                 BROADCAST_TO_CLASS(ThumbMessage(ThumbMessage::ThumbState::KILLCACHE, SGLib_ClipArt), DialogOp);
00628                 BROADCAST_TO_CLASS(ThumbMessage(ThumbMessage::ThumbState::KILLCACHE, SGLib_ClipArt_WebThemes), DialogOp);
00629                 BROADCAST_TO_CLASS(ThumbMessage(ThumbMessage::ThumbState::KILLCACHE, SGLib_Bitmap), DialogOp);
00630 
00631                 GalleryAboutToClose();
00632                 
00633                 break;
00634 
00635             case DIM_LFT_BN_CLICKED:
00636                 switch (Msg->GadgetID)
00637                 {
00638                     case _R(IDC_LIBGAL_OPEN):
00639                         ImportClipart(TRUE, this);
00640                         break;
00641 
00642                     case _R(IDC_GALLERY_HELP):      // Show help page
00643                         HelpUserTopic(_R(IDS_HELPPATH_Gallery_Clipart));
00644                         break;
00645 
00646 
00647                     case _R(IDC_LIBGAL_UPDATE):
00648 #ifdef _BATCHING     
00649                         LoadAndSave();
00650 #endif
00651                         break;
00652                     
00653                     case _R(IDC_LIBGAL_IMPORT):
00654                         ImportClipart(FALSE, this);
00655                         break;
00656 
00657                     case _R(IDC_LIBGAL_BROWSE):
00658                     case _R(IDC_LIBGAL_ADD_CLIPART):
00659                         BrowseClicked();
00660                         break;
00661 
00662                     case _R(IDC_BMPGAL_SAVE):
00663 #ifdef _DEBUG
00664                         {
00665                             SGDisplayNode *Item = DisplayTree->FindNextSelectedItem(NULL);
00666                             if(Item != NULL && Item->IsKindOf(CC_RUNTIME_CLASS(SGLibDisplayItem)))
00667                             {
00668                                 SGLibDisplayItem *LibItem = (SGLibDisplayItem *)Item;
00669 
00670                                 Library *Parent = LibItem->GetParentLibrary();
00671                                 if(Parent != NULL)
00672                                 {
00673                                     Error::SetError(0, TEXT("Renumber ID's ? (Doing this will mess external thumbnails up in a major way !)"), 0); // Debug
00674                                     INT32 ButtonPressed = InformWarning(0, _R(IDS_OK), _R(IDS_KEEP), _R(IDS_CANCEL), NULL);
00675 
00676                                     if(ButtonPressed != 3)
00677                                     {
00678                                         PathName *Source = Parent->ReturnIndexLocation();
00679                                         PathName Dest(*Source);
00680                                         Dest.SetType((String_256)"BAK");
00681                                         SGLibOil::FileCopy(Source, &Dest);
00682                                         Parent->SaveIndexInDisplayedOrder(Source, (ButtonPressed == 1));
00683                                     }
00684                                 }
00685                             }
00686                         }
00687 #endif
00688                         break;
00689                     
00690                     default:
00691                         break;
00692                 }
00693 
00694 #ifdef _PROFILE_REDRAW
00695             case DIM_REDRAW:
00696                 if (Msg->GadgetID == GetListGadgetID())
00697                 {
00698                     ProfileRedraw((ReDrawInfoType*) Msg->DlgMsgParam);
00699                     return(DialogBarOp::Message(Message));
00700                     break;
00701                 }
00702                 break;
00703 #endif
00704         }
00705     }
00706     else if (MESSAGE_IS_A(Message, DocChangingMsg))
00707     {
00708         DocChangingMsg *Msg = (DocChangingMsg *) Message;
00709         switch (Msg->State)
00710         {
00711             case DocChangingMsg::DocState::SELCHANGED:
00712                 if (Msg->pNewDoc == NULL)
00713                 {
00714                     // There is no selected doc - this can only mean there are no docs
00715                     // at all, so we had better shade the gallery
00716                     SuperGallery::ShadeGallery(TRUE);
00717                 }
00718                 else
00719                 {
00720                     // Possibly a new document
00721                     SuperGallery::ShadeGallery(FALSE);
00722                     SelectionHasChanged();
00723                 }
00724                 break;
00725         }
00726     }
00727     else if (MESSAGE_IS_A(Message, ThumbMessage) && DisplayTree != NULL)
00728     {
00729         ThumbMessage *Msg = (ThumbMessage *) Message;
00730 
00731         // If a library Thumb message comes around, flush the redraw stuff, etc
00732         if(Msg->State == ThumbMessage::ThumbState::CACHESIZECHANGED)
00733         {
00734             FlushBackgroundRedraws();
00735             ForceRedrawOfList();
00736         }
00737     }
00738 
00739     return(LibraryGallery::Message(Message));
00740 }    
00741 
00742 
00743 
00744 
00745 
00746 /********************************************************************************************
00747 
00748 >   BOOL LibClipartSGallery::BrowseClicked(void)
00749 
00750     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00751     Created:    2/5/95
00752 
00753     Inputs:     
00754     Returns:    TRUE if the gallery has new stuff in it (FALSE if cancel clicked, etc)...
00755 
00756     Purpose:    Pops up the browse box and lets a new location be set for the clipart
00757                 directory
00758 
00759 ********************************************************************************************/
00760 
00761 BOOL LibClipartSGallery::BrowseClicked(void)
00762 {
00763     if (GetClipTheme() == 0)
00764     {
00765         return (LibraryGallery::BrowseClicked(&DefaultLibraryPath, SGLib_ClipArt, _R(IDS_REMOVE_OLD_GOUPS_CLIPART)));
00766     }
00767     else
00768     {
00769         return (LibraryGallery::BrowseClicked(&DefaultLibraryPath, SGLib_ClipArt_WebThemes, _R(IDS_REMOVE_OLD_GOUPS_CLIPART)));
00770     }
00771 }
00772 
00773 
00774 /********************************************************************************************
00775 
00776 >   virtual BOOL LibClipartSGallery::CanCreateIndexes(void)
00777 
00778     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00779     Created:    18/12/95
00780 
00781     Returns:    TRUE to if index generation is possible
00782 
00783     Purpose:    To determine if this gallery can generate indexes or not
00784 
00785 ********************************************************************************************/
00786 
00787 BOOL LibClipartSGallery::CanCreateIndexes(void)
00788 {
00789     return TRUE;
00790 }
00791 
00792 
00793 /********************************************************************************************
00794 
00795 >   virtual BOOL LibClipartSGallery::GetDefaults(String_256 *DefaultIndex, String_256 *IndexDesc, SGLibType *Type)
00796 
00797     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00798     Created:    18/12/95
00799 
00800     Outputs:    DefaultIndex    - The filename for the default index file (Xaraclip.txt)
00801                 IndexDesc       - Description of the index / gallery (Clipart)
00802                 Type            - Default library type associated with this gallery
00803 
00804     Returns:    TRUE if this was overridden successfully 
00805 
00806     Purpose:    To determine various library gallery default properties
00807 
00808 ********************************************************************************************/
00809 
00810 BOOL LibClipartSGallery::GetDefaults(String_256 *DefaultIndex, String_256 *IndexDesc, SGLibType *Type)
00811 {
00812     TRACEUSER( "Matt", _T("Getting defaults for clipart gallery\n"));
00813     if(DefaultIndex != NULL)
00814     {
00815         //Set the correct info filename for the current gallery style
00816         if (GetClipTheme() == 0)
00817         {
00818             *DefaultIndex = _R(IDS_LIBRARIES_CLIPART_FILENAME); // "XaraClip.txt";
00819         }
00820         else
00821         {
00822             *DefaultIndex = _R(IDS_LIBRARIES_WEBTHEMES_FILENAME);   // "XaraThem.txt";
00823         }
00824     }
00825 
00826     if(IndexDesc != NULL)
00827         *IndexDesc = _R(IDS_LIBRARIES_CLIPART_DESC);        // "Clipart";
00828 
00829     if(Type != NULL)
00830     {
00831         //Set the type of the gallery to be 'Clipart' or 'Web Themes'
00832         //so that the base classes attempt to load file info from the
00833         //correct URL - real handy...
00834         if (GetClipTheme() == 0)
00835         {
00836             *Type = SGLib_ClipArt;
00837         }
00838         else
00839         {
00840             *Type = SGLib_ClipArt_WebThemes;
00841         }
00842     }
00843 
00844     return TRUE;
00845 }
00846 
00847 /********************************************************************************************
00848 
00849 >   virtual BOOL LibClipartSGallery::GetLibraryDirectoryName(String_256 *LibDirName)
00850 
00851     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00852     Created:    19/12/95
00853 
00854     Outputs:    LibDirName  - Returns the Default directory (on the clipart CD) for the gallery
00855     Returns:    TRUE if overridden and directory obtained...
00856 
00857     Purpose:    Get the default CD directory name for the gallery
00858 
00859 ********************************************************************************************/
00860 
00861 BOOL LibClipartSGallery::GetLibraryDirectoryName(String_256 *LibDirName)
00862 {
00863     TRACEUSER( "Matt", _T("Getting library directory name for clipart gallery\n"));
00864     if (GetClipTheme() == 0)
00865     {
00866         LibDirName->MakeMsg(_R(IDS_LIBRARIES_CLIPART_DIRNAME));
00867     }
00868     else
00869     {
00870         LibDirName->MakeMsg(_R(IDS_LIBRARIES_WEBTHEMES_DIRNAME));
00871     }
00872     return TRUE;
00873 }
00874 
00875 /********************************************************************************************
00876 
00877 >   virtual BOOL LibClipartSGallery::CheckForIndexMatch(StringBase *Txt)
00878 
00879     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00880     Created:    18/12/95
00881 
00882     Inputs:     Txt     - Last column entry in the index.txt file (" A")
00883     Returns:    TRUE if this signifies the gallery in question...
00884 
00885     Purpose:    To see whether we should add this line of the index.txt file to this gallery
00886 
00887 ********************************************************************************************/
00888 
00889 BOOL LibClipartSGallery::CheckForIndexMatch(StringBase *Txt)
00890 {
00891     BOOL Match = FALSE;
00892 
00893     // Artwork, and Bitmaps...
00894     if(((Txt->Sub(String_8("A"))!=-1) || (Txt->Sub(String_8("a"))!=-1)) ) Match = TRUE;
00895     if(((Txt->Sub(String_8("B"))!=-1) || (Txt->Sub(String_8("b"))!=-1)) ) Match = TRUE;             
00896 
00897     return Match;
00898 }
00899 
00900 
00901 /********************************************************************************************
00902 
00903 >   virtual BOOL LibClipartSGallery::GetQuietStatus(void)
00904 
00905     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00906     Created:    19/12/95
00907     Returns:    TRUE if Quiet has been pressed (SetQuiet status called with TRUE)
00908     Purpose:    Get the Quiet status of the gallery
00909 
00910 ********************************************************************************************/
00911 
00912 BOOL LibClipartSGallery::GetQuietStatus(void)
00913 {
00914     return LibClipartSGallery::QuietStatus;
00915 }
00916 
00917 /********************************************************************************************
00918 
00919 >   virtual void LibClipartSGallery::SetQuietStatus(BOOL Status)
00920 
00921     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00922     Created:    19/12/95
00923     Inputs:     Status - Set to TRUE and call if Quiet has just been pressed on an 'adding
00924                          indexes' dialog
00925     Purpose:    Set the Quiet status of the gallery
00926 
00927 ********************************************************************************************/
00928         
00929 void LibClipartSGallery::SetQuietStatus(BOOL Status)
00930 {
00931     LibClipartSGallery::QuietStatus = Status;
00932 }
00933 
00934 
00935 /***********************************************************************************************
00936 
00937 >   virtual BOOL LibClipartSGallery::ScanForLocation(SGLibType Type, StringBase *Result = NULL);
00938 
00939     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00940     Created:    19/12/95
00941 
00942     Inputs:     Type of library to scan for
00943     Outputs:    (We assume the library static strings exist and use them - bit yucky)
00944                 If a Result pointer if given then we copy this into there as well..
00945     Returns:    FALSE if it fails; TRUE if we got a path
00946 
00947     Purpose:    Searches all the drives for a CDROM drive. If it finds the Camelot CD
00948                 mount here at Xara HQ, we point to that instead.
00949     Notes:
00950 
00951 ***********************************************************************************************/
00952 
00953 BOOL LibClipartSGallery::ScanForLocation(SGLibType Type, StringBase *Result)
00954 {
00955     // Search for a CD ROM drive
00956     String_256 DriveName;
00957     BOOL AreWeXara = FALSE;
00958     String_256 XaraDrive;
00959 
00960     BOOL Adjust = KeyPress::IsAdjustPressed();
00961 #ifndef _DEBUG
00962     Adjust = FALSE;
00963 #endif
00964 
00965     if(SGLibOil::LocateCDROMDrive(this, Type, &DriveName, &AreWeXara, &XaraDrive, Adjust))
00966     {
00967         if(AreWeXara)
00968             DriveName = XaraDrive;
00969 
00970         switch(Type)
00971         {
00972             case SGLib_ClipArt:
00973             case SGLib_ClipArt_WebThemes:
00974             case SGLib_Bitmap:
00975             {
00976                 LibClipartSGallery::DefaultLibraryPath = DriveName;
00977 #ifdef _DEBUG
00978                 if(Adjust)
00979                 {
00980                     LibClipartSGallery::DefaultLibraryPath += TEXT("Graphics\\XaraSt~1");
00981                 }
00982                 else
00983 #endif
00984                 {
00985                     String_256 LibDirName;
00986                     GetLibraryDirectoryName(&LibDirName);
00987                     LibClipartSGallery::DefaultLibraryPath += LibDirName;
00988                 }
00989 
00990                 if(Result)
00991                     *Result = LibClipartSGallery::DefaultLibraryPath;
00992 
00993                 if (GetClipTheme() == 0)
00994                 {
00995                     LibClipartSGallery::ClipartPath = LibClipartSGallery::DefaultLibraryPath;
00996                 }
00997                 else
00998                 {
00999                     LibClipartSGallery::WebThemePath = LibClipartSGallery::DefaultLibraryPath;
01000                 }
01001 
01002                 return TRUE;
01003             }
01004 
01005         }
01006     }
01007     return FALSE;
01008 }
01009 
01010 
01011 
01012 /********************************************************************************************
01013 
01014 >   virtual void LibClipartSGallery::HandleDragStart(DragMessage *DragMsg)
01015 
01016     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
01017     Created:    25/3/95
01018 
01019     Inputs:     DragMsg - The DRAGSTARTED message that we've just recieved, indicating
01020                 the type of drag being started
01021 
01022     Purpose:    Checks a DragMessage to see if it is a colour drag.
01023                 If it is, then it creates a drag target for this gallerys listbox.
01024 
01025     Notes:      Overrides the default base-class action. Calls down to the base class
01026                 if it is not a colour drag, so that dragging of gallery groups is allowed
01027 
01028 ********************************************************************************************/
01029 
01030 void LibClipartSGallery::HandleDragStart(DragMessage *DragMsg)
01031 {
01032     // If it's a bitmap drag, add a target for our window. If not, let the base class
01033     // have a look at it (to see if it is a gallery item being dragged)
01034     if (DragMsg->pInfo->IsKindOf(CC_RUNTIME_CLASS(GalleryClipartDragInfo)))
01035         SGClipartDragTarget *NewTarget = new SGClipartDragTarget(this, GetListGadgetID());
01036     else
01037         SuperGallery::HandleDragStart(DragMsg);
01038 }
01039 
01040 
01041 /* for profiling reasons */
01042 
01043 void LibClipartSGallery::ProfileRedraw(ReDrawInfoType *Param)
01044 {
01045 #ifdef _PROFILE_REDRAW
01046     RenderListBox(Param);
01047 #endif
01048 }
01049 
01050 /********************************************************************************************
01051 
01052 >   BOOL LibClipartSGallery::ImportClipart(BOOL NewDocument)
01053 
01054     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
01055     Created:    19/3/95
01056                     Asynchronous import code added by Adrian, 12/96
01057     Inputs:     NewDocument - Set to TRUE if you don't want the import to be added ontopof
01058                 the currently selected document.
01059     Outputs:
01060     Returns:    TRUE if things went OK, false otherwise
01061 
01062     Purpose:    To load/import all the selected clipart items one by one into camelot.              
01063     Notes:
01064     SeeAlso:
01065 
01066 *********************************************************************************************/
01067 
01068 BOOL LibClipartSGallery::ImportClipart(BOOL NewDocument, LibraryGallery* pSourceGallery)
01069 {
01070     TRACEUSER( "Matt", _T("Importing clipart in clipart gallery\n"));
01071     if (pSourceGallery->DisplayTree == NULL)
01072     {
01073         ERROR3("LibClipartSGallery::ImportClipart No display tree - bad !");
01074         return FALSE;
01075     }
01076 
01077     if(Document::GetSelected() == NULL && !NewDocument)
01078     {
01079         return FALSE;
01080     }
01081                                       
01082     BOOL ok = TRUE;
01083 
01084 
01085     // Find the first selected item (if any) and get the next item to start searching from
01086     // If there is no selection, then get the first item
01087     SGDisplayNode *Item = pSourceGallery->DisplayTree->FindNextSelectedItem(NULL);
01088     String_256 ItemText;
01089 
01090     while (Item != NULL)
01091     {
01092         if(Item->IsKindOf(CC_RUNTIME_CLASS(SGClipartItem)) || Item->IsKindOf(CC_RUNTIME_CLASS(SGFillsItem)))
01093         {
01094             Item->GetNameText(&ItemText);
01095 
01096             if(Item->Flags.Selected)
01097             {
01098                 PathName FileName;      
01099                 SGLibDisplayItem *ClipItem = (SGLibDisplayItem *) Item;
01100             
01101                 //if (Lib != NULL)
01102                 ok = ClipItem->GetFileName(&FileName);
01103 
01104                 if(ok)
01105                 {
01106                     // Bodge for clipart CD - 'Cow' in LScape should point to "Moo.tif", not just "Moo"
01107                     if(FileName.GetFileName(FALSE) == (String_256)"Moo")
01108                     {
01109                         INT32 Size = ClipItem->GetFileSize(NULL);
01110                         if(Size == 1080904)
01111                             FileName.SetType("TIF");
01112                     }
01113 
01114                     if(!FileName.IsValid(FileName.GetPath()))
01115                     {
01116                         ERROR3("LibClipartSGallery::ImportClipart - Filename is invalid");
01117                         return FALSE;
01118                     }
01119 
01120                     // Check if file has a long filename, and use that if it does...
01121                     String_256 FilePath((const TCHAR *)FileName.GetPath());
01122                     String_256 LongFileName;
01123                     BOOL LongPath = FileUtil::GetLongFileName((LPTSTR)FilePath, (LPTSTR)LongFileName, 255);
01124                     if(LongPath)
01125                     {
01126                         FilePath = FileName.GetLocation(TRUE);
01127                         FilePath += LongFileName;
01128                     }
01129 
01130                     // Check if the file really exists on the local drive
01131                     Library* pLibrary = ClipItem->GetParentLibrary();
01132                     if (!pLibrary)
01133                     {
01134                         ERROR3("Illegal NULL pointer");
01135                         return FALSE;
01136                     }
01137                     BOOL bIsLocalFile;
01138                     if (!pLibrary->IsWebLibrary())
01139                         bIsLocalFile = TRUE;
01140                     else 
01141                         bIsLocalFile = (_access((TCHAR*) FilePath, 0) != -1);
01142                         
01143                     if(NewDocument)
01144                     {
01145                         if (bIsLocalFile)
01146                         {
01147                             CWinApp* pApp = AfxGetApp();
01148                             BaseFileDialog::SelectedFilter = 0;
01149             
01150                             // Open a document
01151                             CCamDoc* pDoc = (CCamDoc*) pApp->OpenDocumentFile((TCHAR *)FilePath);
01152 
01153                             // And redraw the imported document
01154                             if(pDoc) pDoc->GetKernelDoc()->ForceRedraw();
01155                         }
01156                         else // do an asynch import
01157                         {
01158                             goto ASYNCH_IMPORT;
01159                         }
01160                     }
01161                     else
01162                     {
01163                         // Invoke the clipart import operation so that we get Undo.
01164                         if (bIsLocalFile) // if the file is local we do a normal import Op
01165                         {
01166 
01167                             OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(CC_RUNTIME_CLASS(OpClipartImport));
01168 
01169                             if (pOpDesc != NULL)
01170                             {
01171                                 ClipartImportParam Param;
01172 
01173                                 PathName FullPathName(FilePath);
01174 
01175                                 // Set up the parameters which we require to do the import operation
01176                                 Param.File = &FullPathName;
01177                                 Param.Import = !NewDocument;
01178                                 Param.Result = TRUE;
01179 
01180                                 // Import the specified file
01181                                 pOpDesc->Invoke((OpParam *) &Param);
01182 
01183                                 ok = Param.Result;
01184                                 if(!ok)
01185                                 {
01186                                     ERROR3("LibClipartSGallery::ImportClipart - Problem importing file");
01187                                     return FALSE;
01188                                 }
01189                             }
01190                         }
01191                         else // try an asynch import
01192                         {
01193 ASYNCH_IMPORT:
01194                             String_256 strFileURL = FilePath;
01195                             pLibrary->LocalPath2URL(&strFileURL);
01196                             OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(CC_RUNTIME_CLASS(OpAsynchClipartImport));
01197 
01198                             if (pOpDesc != NULL)
01199                             {
01200                                 AsynchClipartImportParam* Param = new AsynchClipartImportParam;
01201                                 ERROR2IF(!Param, FALSE, "Memory allocation error");
01202                                 // Set up the parameters which we require to import the clipart
01203                                 Param->File.SetPathName((TCHAR *)FilePath);
01204                                 String_256 strDescription;
01205                                 ClipItem->GetNameText(&strDescription);
01206                                 Param->strDescription = _T("'");
01207                                 Param->strDescription += strDescription;
01208                                 Param->strDescription += _T("'");
01209                                 Param->strURL = strFileURL;
01210                                 Param->Import = !NewDocument;
01211                                 Param->bDropped = FALSE;
01212                                 // Invoke the operation
01213                                 pOpDesc->Invoke((OpParam*) Param);
01214                             }
01215                         }
01216                     }
01217                 }
01218             }
01219         }
01220         Item = SGDisplayRoot::FindNextItemInTree(Item);
01221     }
01222 
01223     return TRUE;
01224 }
01225 
01226 /********************************************************************************************
01227 
01228 >   BOOL LibClipartSGallery::LoadAndSave(void)
01229 
01230     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
01231     Created:    19/3/95
01232     Inputs:
01233     Outputs:
01234     Returns:    TRUE if things went OK, false otherwise
01235 
01236     Purpose:    To load all the selected clipart items one by one into camelot and then
01237                 to save them out again - useful for updating documents.
01238                 
01239     Notes:      Code for this should only be compiled in DEBUG, and calling this is
01240                 not guaranteed to leave XS in a stable state on exit.
01241     SeeAlso:
01242 
01243 ********************************************************************************************/
01244 
01245 BOOL LibClipartSGallery::LoadAndSave(void)
01246 {
01247 
01248 #ifdef _BATCHING
01249 
01250     if (DisplayTree == NULL)
01251     {
01252         ERROR3("LibClipartSGallery::LoadAndSave No display tree - bad !");
01253         return FALSE;
01254     }
01255 
01256     // For centering items...
01257     PageTab PTab;
01258     if(!PTab.Init())
01259     {
01260         ERROR3("Can't init page resizing stuff...");
01261         return FALSE;
01262     }
01263 
01264     // Find the first selected item (if any) and get the next item to start searching from
01265     // If there is no selection, then get the first item
01266     SGDisplayNode *Item = DisplayTree->FindNextSelectedItem(NULL);
01267 
01268     String_256 ItemText;
01269 
01270     while (Item != NULL)
01271     {
01272         if(Item->IsKindOf(CC_RUNTIME_CLASS(SGClipartItem)))
01273         {
01274             Item->GetNameText(&ItemText);
01275 
01276             // Update selected ones, or all after first selected ?
01277             if(Item->Flags.Selected || TRUE)
01278             {
01279                 PathName FileName;      
01280                 SGLibDisplayItem *ClipItem = (SGLibDisplayItem *) Item;
01281 
01282                 BOOL ok = TRUE;
01283             
01284                 //if (Lib != NULL)
01285                 ok = ClipItem->GetFileName(&FileName);
01286 
01287                 // Check if we're an ai file, don't do it if we're not !
01288                 String_8 Ending;
01289                 if(ok) Ending = FileName.GetType();
01290                 if(ok) Ending.toLower();
01291                 if(/*Ending == (String_8)"art" &&*/ ok)
01292                 {
01293                     // Load a file
01294                     CWinApp* pApp = AfxGetApp();
01295                     BaseFileDialog::SelectedFilter = 0;
01296 
01297                     if(!FileName.IsValid(FileName.GetPath()))
01298                     {
01299                         ERROR3("Filename is invalid");
01300                     }
01301 
01302                     String_256 Path(FileName.GetPath());
01303                     
01304                     // Batching system will use this directory to put its output in
01305                     String_256 OutputPath(LibClipartSGallery::BatchSaveLocation);
01306                     
01307                     // Unless it == "" of course...
01308                     if(OutputPath.Length() == 0)
01309                         OutputPath = Path;
01310                     else
01311                     {
01312                         if(OutputPath[OutputPath.Length()-1] != '\\')
01313                             OutputPath += TEXT("\\");
01314                         OutputPath += FileName.GetFileName(TRUE);
01315                     }
01316 
01317                     PathName OutputPathART(OutputPath);
01318                     OutputPathART.SetType((String_256)"XAR");
01319                     String_256 SavePath(OutputPathART.GetPath());
01320 
01321                     Error::ClearError();
01322     
01323                     // Only do it if there isn't an art file there already...
01324                 //  if(!SGLibOil::FileExists(&OutputPathART))
01325                 //  {           
01326                 
01327                         MonotonicTime Time;
01328                         INT32 OpenTime = Time.Sample();
01329                         INT32 InitialSize = SGLibOil::FileSize(&FileName);
01330 
01331 // If this is not defined, we just load each file in turn, and spool any problems to 'load.txt'
01332 //#define SAVEASWELL
01333 
01334 #ifndef SAVEASWELL
01335                         FILE *FP = _tfopen("C:\\load.txt", "a"); // Debug
01336                         if(FP != NULL)
01337                         {
01338                             _ftprintf(FP, "Loading: %s\r\n", (TCHAR *)Path); // Debug
01339                             fclose(FP);
01340                         }
01341 #endif
01342 
01343                         // Open a document
01344                         CCamDoc* pDoc = (CCamDoc*) pApp->OpenDocumentFile((TCHAR *)Path);
01345                         /*Document *CurDoc = Document::GetSelected();
01346                             CCamDoc* pDoc = CurDoc->GetOilDoc();*/
01347 #ifndef SAVEASWELL
01348 
01349                         if(pDoc == NULL)
01350                         {
01351                             FP = _tfopen("C:\\batch.txt", "a"); // Debug
01352                             if(FP != NULL)
01353                             {
01354                                 _ftprintf(FP, "Problems: %s\r\n", (TCHAR *)Path); // Debug
01355                                 fclose(FP);
01356                             }
01357                         }
01358                         else
01359                         {
01360                             Error::ClearError();
01361                             // Close a document
01362                             ((CCamDoc *) (((CMDIFrameWnd *)                                      
01363                                 ((AfxGetApp())->m_pMainWnd))->MDIGetActive()    //Get Active Child Window
01364                                 )->GetActiveDocument()                          //Get Active Document
01365                                 )->OnFileClose();                               //Close Active Document
01366                         }   
01367                         Error::ClearError();
01368 
01369 #else
01370                         OpenTime = Time.Sample() - OpenTime;
01371 
01372                         if (pDoc != NULL)
01373                         {
01374                             INT32 Pass = 0;
01375 
01376                             /*do {*/
01377                                 /*******************/
01378 
01379                                 // Remove empty layers and rename clipart layer to 'Clipart'
01380 
01381 #if 0
01382                                 Document* OurDocument = pDoc->GetKernelDoc();
01383                                 Spread* OurSpread = OurDocument->FindFirstSpread();
01384                                 Page* CurrentPage = OurSpread->FindFirstPageInSpread(); 
01385 
01386                                 if(OurDocument == NULL || OurSpread == NULL || CurrentPage == NULL)
01387                                 {
01388                                     Error::SetError(0, String_256("NULL Page/Spread/Doc in batcher..."), 0); // Debug
01389                                     InformWarning(0, _R(IDS_OK), NULL);
01390                                     Error::ClearError();
01391                                 }
01392                                 else
01393                                 {
01394                                     OurDocument->SetCurrent();
01395 
01396                                     /* remove messed up layers from tree */
01397                                     Layer* pLayer = OurSpread->FindFirstLayer();
01398 
01399                                     INT32 Count = 0;
01400                                     while(pLayer)
01401                                     {
01402                                         Node* pNode = pLayer->FindFirstChild();
01403                                         BOOL ChildFound = FALSE;
01404 
01405                                         while (pNode != NULL && !ChildFound)
01406                                         {
01407                                             ChildFound = pNode->IsBounded(); //IsKindOf(CC_RUNTIME_CLASS(NodeRenderableBounded));
01408                                             pNode = pNode->FindNext();
01409                                         }
01410 
01411                                         Layer *tLayer = pLayer->FindNextLayer();
01412 
01413                                         if(!ChildFound)
01414                                             pLayer->UnlinkNodeFromTree();
01415                                         else
01416                                         {
01417                                             pLayer->SetVisible(TRUE);
01418                                             pLayer->SetLocked(FALSE);
01419                                             Count ++;
01420                                         }
01421 
01422                                         pLayer = tLayer;
01423                                     }
01424 
01425 
01426                                     if(Count == 1)
01427                                     {
01428                                         Layer* pLayer = OurSpread->FindFirstLayer();
01429                                         if(pLayer)
01430                                             pLayer->SetLayerID(String_256("Clipart")); // Debug
01431                                     }
01432 
01433 
01434                                     /**************************************/
01435 
01436                                     // Sort the page orientation out, centre the clipart and zoom to it
01437         
01438                                     DocRect OurItemRect = OurSpread->GetBoundingRect();
01439                                     DocRect OurPageRect = CurrentPage->GetPageRect();
01440 
01441                                     if (AppPrefsDlg::pPageSizesList != NULL)
01442                                     {
01443                                         PageId PageChosen = A4;
01444                                         MILLIPOINT Width;
01445                                         MILLIPOINT Height;
01446                                         AppPrefsDlg::pPageSizesList->GetSizeFromPageId(PageChosen, &Width, &Height);
01447 
01448                                         // Bodge it to landscape / portrait...
01449                                         if(    ((OurItemRect.Width() > OurItemRect.Height()) && (OurPageRect.Width() < OurPageRect.Height())) 
01450                                             || ((OurItemRect.Width() < OurItemRect.Height()) && (OurPageRect.Width() > OurPageRect.Height())) )
01451                                         {
01452                                             MILLIPOINT Tmp = Width;
01453                                             Width = Height;
01454                                             Height = Tmp;
01455                                         }
01456 
01457                                         TRACEUSER( "Richard", _T("width %d height %d in MP\n"),Width,Height);
01458 
01459                                         // Set up the parameters which we require to do the page resizing operation 
01460                                         PageResizeInfo Param;
01461 
01462                                         // Set up the new page parameters that we want
01463                                         Param.Height = Height;
01464                                         Param.Width = Width;
01465 
01466                                         MILLIPOINT Margin = Width / 2;
01467                                         if(Height < Width)
01468                                             Margin = Height / 2;
01469 
01470                                         Param.Margin = Margin;
01471                                         Param.Bleed = 0; //Bleed;
01472                                         Param.Portrait = (Width < Height); //Portrait;
01473                                         Param.Dps = FALSE; //Dps;
01474                                         Param.ShowDropShadow = TRUE; //DropShadow;
01475                                         // Set up the new default grid settings that we want 
01476                                         //Param.GridSpacing = CM_MP_VAL;
01477                                         //Param.GridSubDivisions = 2;
01478                                         //Param.GridUnits = CENTIMETRES;
01479                                         //Param.TypeOfGrid = RECTANGULAR;
01480 
01481                                         Param.pSpread = OurSpread;
01482                                         OptionsTabs::SetCurrentDocAndSpread(OurDocument); // set up the spread that we are currently workign on
01483 
01484                                         // Invoke the page centre / resize function...
01485                                         PTab.InvokeResizeAndCentre(&Param);
01486 
01487                                         // BODGE BODGE BODGE to make fakeinvoke work when the spread's not in view...
01488                                         LibClipartSGallery::DefaultSortKeys = TRUE;
01489 
01490                                         //OpZoomDescriptor::FakeInvoke(OPTOKEN_ZOOMSPREAD);
01491                                         OpZoomDescriptor::FakeInvoke(OPTOKEN_ZOOMDRAWING);
01492 
01493                                         LibClipartSGallery::DefaultSortKeys = FALSE;
01494 
01495                                         OurDocument->ForceRedraw();
01496                                     }
01497                                 }
01498 /*                              Pass ++;
01499                             } while(Pass < 5);*/
01500 
01501                             /*Document**/ OurDocument = pDoc->GetKernelDoc();
01502                             /*Spread**/ OurSpread = OurDocument->FindFirstSpread();
01503                             /*Page* */ CurrentPage = OurSpread->FindFirstPageInSpread(); 
01504 
01505                             DocRect OurItemRect = OurSpread->GetBoundingRect();
01506                             DocRect OurPageRect = CurrentPage->GetPageRect();
01507 
01508                             BOOL PossiblyOutsidePage = FALSE;
01509                             /*if(    (OurItemRect.lo.x < OurPageRect.lo.x)
01510                                 || (OurItemRect.hi.x > OurPageRect.hi.x)
01511                                 || (OurItemRect.lo.y < OurPageRect.lo.y)
01512                                 || (OurItemRect.hi.y > OurPageRect.hi.y) )
01513                                 PossiblyOutsidePage = TRUE;*/
01514 
01515                             /*******************/
01516 
01517                             // Remove duplicate colours
01518 
01519                             Document *TheDoc = OurDocument;
01520 
01521                             ColourList *ParentList = TheDoc->GetIndexedColours();
01522 
01523                             INT32 TotalItems = ParentList->GetCount();
01524                             INT32 DeletedItems = 0;
01525 
01526                             IndexedColour **KillList = new IndexedColourPtr[TotalItems+1];
01527                             if (KillList != NULL)
01528                             {
01529 
01530                                 DWORD KillIndex = 0;
01531                                 IndexedColour *Ptr = ParentList->GetUndeletedHead();
01532 
01533                                 while (Ptr != NULL)
01534                                 {
01535                                     if(!Ptr->IsInUse())
01536                                     {
01537                                         DeletedItems++;
01538                                         KillList[KillIndex++] = Ptr;
01539                                     }
01540 
01541                                     Ptr = ParentList->GetUndeletedNext(Ptr);
01542                                 }
01543     
01544                                 KillList[KillIndex] = NULL;     // NULL terminate the list
01545 
01546                                 // Delete (hide, with undo actually) the given colours
01547                                 ColourManager::HideColours(ParentList, KillList, TRUE);
01548 
01549                                 // HideColours has made a copy of this list for itself, so we are responsible
01550                                 // for deleting our original list
01551                                 delete [] KillList;
01552                             }
01553 
01554                             // Only add a new palette if there are now no colours...
01555                             if(TotalItems == DeletedItems)
01556                             {
01557                                 /*******************/
01558 
01559                                 // Import a blank document containing the 'default' colours
01560 
01561                                 PathName FileName((String_256)"C:\\pal.art");
01562                                 if(SGLibOil::FileExists(&FileName))
01563                                 {
01564                                     // Invoke the clipart import operation so that we get Undo.
01565                                     OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(CC_RUNTIME_CLASS(OpClipartImport));
01566 
01567                                     if (pOpDesc != NULL)
01568                                     {
01569                                         ClipartImportParam Param;
01570 
01571                                         // Set up the parameters which we require to do the page resizing operation 
01572                                         Param.File = &FileName;
01573                                         Param.Import = TRUE;
01574                                         Param.Result = TRUE;
01575 
01576                                         // Go for it!
01577                                         pOpDesc->Invoke((OpParam *) &Param);
01578 
01579                                         ok = Param.Result;
01580 
01581                                         if(!ok)
01582                                         {
01583                                             ERROR3("Batching... Problem importing file");
01584                                             return FALSE;
01585                                         }
01586                                     }
01587                                 }
01588 
01589                                 /*******************/
01590                             }
01591     
01592 #endif
01593                             INT32 CloseTime = Time.Sample();
01594 
01595                             BOOL Worked = TRUE;
01596 #if 0   //#ifndef NEW_NATIVE_FILTER
01597         // Save a document
01598                             Worked = pDoc->OnSaveDocument((TCHAR *)SavePath) && Worked;
01599                             Error::ClearError();
01600 
01601                             INT32 FinalSize = SGLibOil::FileSize(&OutputPathART);
01602                             CloseTime = Time.Sample() - CloseTime;
01603 #endif
01604 #if 0   // Save a document, but ensure it is in the old format!
01605                             Worked = pDoc->OnSaveVersion1Document((TCHAR *)SavePath) && Worked;
01606                             Error::ClearError();
01607 
01608                             INT32 FinalSize = SGLibOil::FileSize(&OutputPathART);
01609                             CloseTime = Time.Sample() - CloseTime;
01610 
01611 #endif
01612 
01613                             PathName path(SavePath);
01614 
01615 #if 0   // Do an Export of the file as a version 2 Native file
01616                             path.SetType(TEXT("CXN"));
01617                             path.SetType(TEXT("xar"));  // new files have this extension now
01618                             CCDiskFile file(path, ios::out | ios::binary | ios::trunc);
01619                             BOOL NativeExportWorked = InvokeNativeFileOp(OPTOKEN_SAVEASNATIVEV2, &file, FILTERID_NATIVE);
01620                             Error::ClearError();
01621                             Worked = NativeExportWorked && Worked;
01622 #endif
01623 #if 0   // Do an Export of the file as a Web file
01624                             path.SetType(TEXT("web"));
01625                             CCDiskFile webfile(path, ios::out | ios::binary | ios::trunc);
01626                             BOOL WebExportWorked = InvokeNativeFileOp(OPTOKEN_NATIVESAVE, &webfile, FILTERID_WEB);
01627                             Error::ClearError();
01628                             Worked = WebExportWorked && Worked;
01629 #endif
01630 #if 1   // Rename the file as a munged 8.3 file if saving in the same place - none of this is wheat germ and shouldn't
01631         // be in the kernel, however it only apears in _BATCHING debug builds
01632                             if (LibClipartSGallery::BatchSaveLocation.Length() == 0)
01633                             {
01634                                 // To perform the rename is a bit tricky 'cos we don't know the long filename,
01635                                 // but we can reference the original file through its short name, renaming it
01636                                 // to a temporary name then renaming the temporary back to the short name. We
01637                                 // can not simply rename the long to the short 'cos the operating system will
01638                                 // complain that the short name (i.e. the long one) already exists.
01639                                 BOOL RenameWorked = FALSE;
01640                                 String_256 TempName = FileName.GetLocation();   // temp file in this location
01641                                 // create a temp filename with an obvious prefix
01642                                 char * temmmmmp = _tempnam( TempName, TEXT("~XARA") );
01643                                 if( temmmmmp != NULL )  // pointer returned by _tempnam
01644                                 {
01645                                     // copy the name we created
01646                                     TempName = temmmmmp;
01647                                     // free memory allocated by _tempnam
01648                                     free( temmmmmp );
01649                                     temmmmmp = NULL;
01650                                     // rename our original by referencing it through the munged name
01651                                     if ( 0 == rename( FileName.GetPath(), TempName ) )
01652                                     {
01653                                         // THIS DOESN'T WORK just get original name back
01654                                         // rename the temp file back to the munged (original) name
01655                                         RenameWorked = !rename( TempName, FileName.GetPath() );
01656                                     }
01657                                 }
01658                                 Worked = RenameWorked && Worked;
01659                             }
01660                             else
01661                             {
01662                                 // we are not saving in the same place so save as a web file like above
01663                                 path.SetType(TEXT("web"));
01664                                 CCDiskFile webfile(path, ios::out | ios::binary | ios::trunc);
01665                                 BOOL WebExportWorked = InvokeNativeFileOp(OPTOKEN_NATIVESAVE, &webfile, FILTERID_WEB);
01666                                 Error::ClearError();
01667                                 Worked = WebExportWorked && Worked;
01668                             }
01669 #endif
01670 #if 1   // Do an Export of the file as a png thumbnail file to the "XaraInfo" directory
01671 
01672                             Document* OurDocument = pDoc->GetKernelDoc();
01673 PORTNOTE("spread", "Multi-spread warning!")
01674                             Spread* OurSpread = OurDocument->FindFirstSpread();
01675                             Layer* pLayer = OurSpread->FindFirstLayer();
01676                             DocRect Bounds;
01677                             while (pLayer != NULL)
01678                             {
01679                                 Bounds = Bounds.Union(pLayer->GetBoundingRect());
01680                                 pLayer = pLayer->FindNextLayer();
01681                             }       
01682 
01683                             INT32 d = Bounds.Width();
01684                             if (Bounds.Height() > d)
01685                                 d = Bounds.Height();
01686 
01687                             if (d < (72000*2))
01688                             {
01689                                 CCamDoc* pCCamDoc = OurDocument->GetOilDoc();
01690                                 pCCamDoc->ScaleContents(5.0,5.0);
01691                             }
01692 
01693                             
01694                             String_256 ThumbPathStr = path.GetLocation();
01695                             ThumbPathStr += String_16(_R(IDS_LIBRARIES_XARAINFO_DIRNAME));
01696                             ThumbPathStr += TEXT("\\");
01697                             ThumbPathStr += path.GetFileName();
01698 
01699                             path = PathName(ThumbPathStr);
01700 
01701                             path.SetType(TEXT("png"));
01702                             CCDiskFile thumbfile(path, ios::out | ios::binary | ios::trunc);
01703                             BOOL ThumbExportWorked = InvokeNativeFileOp(OPTOKEN_NATIVESAVE, &thumbfile, FILTERID_PREVIEW_PNG);
01704                             Error::ClearError();
01705                             Worked = ThumbExportWorked && Worked;
01706 #endif
01707 
01708 
01709                             // Close a document
01710                             if(Worked)
01711                                 ((CCamDoc *) (((CMDIFrameWnd *)                                      
01712                                     ((AfxGetApp())->m_pMainWnd))->MDIGetActive()    //Get Active Child Window
01713                                     )->GetActiveDocument()                          //Get Active Document
01714                                     )->OnFileClose();                               //Close Active Document
01715     
01716                             Error::ClearError();
01717                             //ERROR3IF(!Worked, "Ok, so it didn't work...");
01718 
01719                             /*FILE *FP = _tfopen("C:\\times.txt", "a");
01720                             if(FP != NULL)
01721                             {
01722                                 _ftprintf(FP, "%s\tLoad - %d\tSave - %d\tSize - %d to %d (%d%%)\r\n", (TCHAR *)SavePath, OpenTime, CloseTime, InitialSize, FinalSize, (FinalSize / InitialSize)*100);
01723                                 fclose(FP);
01724                             } */
01725 
01726                             if(!Worked)
01727                             {
01728                                 FILE *FP = _tfopen("C:\\batch.txt", "a"); // Debug
01729                                 if(FP != NULL)
01730                                 {
01731                                     _ftprintf(FP, "Problems  saving: %s\r\n", (TCHAR *)Path); // Debug
01732                                     fclose(FP);
01733                                 }
01734                             }
01735                             else
01736                             {
01737 #if 0
01738                                 if(PossiblyOutsidePage)
01739                                 {
01740                                     FILE *FP = _tfopen("C:\\batch.txt", "a"); // Debug
01741                                     if(FP != NULL)
01742                                     {
01743                                         _ftprintf(FP, "Possibly outside: %s\r\n", (TCHAR *)Path); // Debug
01744                                         fclose(FP);
01745                                     }
01746                                 }
01747 #endif
01748                             }
01749                         }
01750                         else
01751                         {
01752                             FILE *FP = _tfopen("C:\\batch.txt", "a"); // Debug
01753                             if(FP != NULL)
01754                             {
01755                                 _ftprintf(FP, "Problems loading: %s\r\n", (TCHAR *)Path); // Debug
01756                                 fclose(FP);
01757                             }
01758                         }
01759 #endif  //SAVEASWELL
01760                 //  }
01761                 }
01762             }
01763 
01764         }
01765 
01766         Item = SGDisplayRoot::FindNextItemInTree(Item);
01767     }
01768 
01769 #endif
01770     return TRUE;
01771 }
01772 
01773 
01774 /********************************************************************************************
01775 
01776 >   virtual SGDisplayItem *LibClipartSGallery::AddLibraryItem(SGDisplayGroup *LibraryGroup,
01777                                                 Library *ParentLib,
01778                                                 LibraryIndex ItemIndex)
01779     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
01780     Created:    22/2/95
01781 
01782     Inputs:     LibraryGroup - The group to add the item into
01783                 ParentLib - (For cross checking inputs) the library you allege the above
01784                 group is for.
01785                 ItemIndex - The Library generated index for this item
01786 
01787     Returns:    NULL, or a pointer to the created item
01788 
01789     Purpose:    Called by the Library class to create a display item for every item in 
01790                 a newly-scanned library file. It is essentially a callback to the gallery
01791                 which requested that the library be scanned.
01792                 
01793     Notes:      This method MUST BE OVERRIDDEN by the derived gallery that opens the library,
01794                 in order to create appropriate SGDisplayItem-derived nodes for the things
01795                 in the library (e.g. a clipart library gallery will have to create items
01796                 that display clipart thumbnails)
01797 
01798     SeeAlso:    SuperGallery::AddLibraryGroup; SuperGallery::RemoveLibraryGroup
01799 
01800 ********************************************************************************************/
01801 
01802 SGDisplayItem *LibClipartSGallery::AddLibraryItem(SGDisplayGroup *LibraryGroup, Library *ParentLib, LibraryIndex ItemIndex, BOOL bNew)
01803 {
01804     TRACEUSER( "Matt", _T("Add library item called in clipart gallery\n"));
01805     ERROR3IF(LibraryGroup == NULL || ParentLib == NULL,
01806                 "SuperGallery::AddLibraryItem - NULL params are illegal");
01807 
01808     ERROR3IF(LibraryGroup->GetParentLibrary() != ParentLib,
01809                 "SuperGallery::AddLibraryitem - The DisplayGroup is not for the same library!");
01810 
01811     // Create a clipart library item
01812 
01813     SGClipartItem *NewItem = new SGClipartItem(ItemIndex, bNew);
01814 
01815     // Check for, and don't include if found in the Studio group, the line:
01816     // Rolex.art,Rather expensive watch,36,Rolex,Object|Time|Watch|Machine,113852
01817     if((ParentLib->Title != NULL) && (ParentLib->Title->Sub((String_8)"Studio") == 0))
01818     {
01819         String_256 TmpPath;
01820         BOOL ok = ParentLib->GetFilename(ItemIndex, &TmpPath, FALSE);
01821 
01822         if(ok)
01823         {
01824             INT32 Size = NewItem->GetFileSize(ParentLib);
01825             if(Size == 113852)
01826             {
01827                 String_256 TmpPath;
01828                 BOOL ok = ParentLib->GetFilename(ItemIndex, &TmpPath, FALSE);
01829 
01830                 if(TmpPath == (String_16)"Rolex.art")
01831                 {
01832                     delete NewItem;
01833                     NewItem = FALSE;
01834                 }
01835             }
01836         }
01837     }
01838 
01839 /*  SGSortKey SortKeys[MaxSGSortKeys];
01840     for (INT32 i = 0; i < MaxSGSortKeys; i++)
01841     {
01842         SortKeys[i].SortKey  = 0;
01843         SortKeys[i].Reversed = FALSE;
01844     }
01845 
01846     SortKeys[0].SortKey  = 1;*/
01847 
01848     if (NewItem != NULL)
01849         LibraryGroup->AddItem(NewItem/*, (SGSortKey *)SortKeys*/);
01850 
01851     return(NewItem);
01852 }
01853 
01854 
01855 /********************************************************************************************
01856 
01857 >   void LibClipartSGallery::ModeHasChanged(void)
01858 
01859     Author:     Priestley (Xara Group Ltd) <camelotdev@xara.com>
01860     Created:    21/09/2000
01861 
01862     Purpose:    To toggle the visible/selectable items of this gallery between
01863                 clipart and web themes
01864     Notes:
01865 
01866 ********************************************************************************************/
01867 
01868 void LibClipartSGallery::ModeHasChanged(void)
01869 {
01870     TRACEUSER( "Matt", _T("MODE has changed called in clipart gallery\n"));
01871     if (DisplayTree == NULL)
01872     {
01873         return;
01874     }
01875 
01876     INT32 libindex = 0;
01877 
01878     //Search through our constructed library of clipart and themes...
01879     LibraryFile* pLibFile = (LibraryFile*) OpenLibFiles.GetHead();
01880     while (pLibFile)
01881     {
01882         Library* pLib = (Library*) pLibFile->Libraries.GetHead();
01883 
01884         while (pLib)
01885         {
01886             if ((pLib->Type == SGLib_ClipArt) && (GetClipTheme() != 0))
01887             {
01888                 pLib->ParentGroup->Flags.Invisible = true;
01889                 pLib->ParentGroup->Flags.CanSelect = false;
01890                 pLib->ParentGroup->Flags.Selected = false;
01891                 pLib->ParentGroup->Flags.Folded = true;
01892             }
01893             else if ((pLib->Type == SGLib_ClipArt_WebThemes) && (GetClipTheme() != 1))
01894             {
01895                 pLib->ParentGroup->Flags.Invisible = true;
01896                 pLib->ParentGroup->Flags.CanSelect = false;
01897                 pLib->ParentGroup->Flags.Selected = false;
01898                 pLib->ParentGroup->Flags.Folded = true;
01899             }
01900             else
01901             {
01902                 pLib->ParentGroup->Flags.Invisible = false;
01903                 pLib->ParentGroup->Flags.CanSelect = true;
01904             }
01905 
01906             pLib = (Library*) pLibFile->Libraries.GetNext(pLib);
01907         }
01908 
01909         pLibFile = (LibraryFile*) OpenLibFiles.GetNext(pLibFile);
01910     }
01911 
01912     ReformatNow(true);
01913 }
01914 
01915 
01916 
01917 /********************************************************************************************
01918 
01919 >   void LibClipartSGallery::SelectionHasChanged(void)
01920 
01921     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> (based on Jason code)
01922     Created:    28/3/95
01923 
01924     Purpose:    To inform the gallery that the selection has changed in some way.
01925                 We need to grey different buttons on different occasions
01926     Notes:
01927 
01928 ********************************************************************************************/
01929 
01930 void LibClipartSGallery::SelectionHasChanged(void)
01931 {
01932     TRACEUSER( "Matt", _T("Selection has changed called in clipart gallery\n"));
01933     if (DisplayTree == NULL)
01934         return;
01935 
01936     INT32 Count = DisplayTree->GetSelectedItemCount();
01937 
01938     EnableGadget(_R(IDC_LIBGAL_OPEN), (Count > 0));
01939 #ifdef _BATCHING
01940     EnableGadget(_R(IDC_LIBGAL_UPDATE), (Count > 0));
01941 #endif
01942 
01943 #ifndef STANDALONE
01944     EnableGadget(_R(IDC_LIBGAL_IMPORT), (Count > 0) && Document::GetSelected() != NULL);
01945 #else
01946     EnableGadget(_R(IDC_LIBGAL_IMPORT), FALSE);
01947 #endif
01948 
01949     EnableGadget(_R(IDC_LIBGAL_ADD_CLIPART), TRUE);
01950 
01951 
01952     // Standard library buttons
01953     LibraryGallery::SelectionHasChanged();
01954 }
01955 
01956 /********************************************************************************************
01957 
01958 >   void LibClipartSGallery::DoShadeGallery(BOOL ShadeIt)
01959 
01960     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> (based on Jason code)
01961     Created:    28/3/95
01962 
01963     Purpose:    To un-grey the options... button when there are no docs
01964     Notes:
01965 
01966 ********************************************************************************************/
01967 
01968 void LibClipartSGallery::DoShadeGallery(BOOL ShadeIt)
01969 {
01970     if (DisplayTree == NULL)
01971         return;
01972 
01973     // Keep this here always
01974     EnableGadget(_R(IDC_GALLERY_MENU), TRUE);
01975 
01976     if(ShadeIt)
01977     {
01978         EnableGadget(_R(IDC_LIBGAL_IMPORT), FALSE);
01979     }
01980 
01981     EnableGadget(_R(IDC_LIBGAL_ADD_CLIPART), TRUE);
01982 
01983     // Standard library buttons
01984     LibraryGallery::DoShadeGallery(ShadeIt);
01985 }
01986 
01987 /********************************************************************************************
01988 
01989 >   virtual BOOL LibClipartSGallery::CanSearchKeywords(void)
01990 
01991     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
01992     Created:    30/3/95
01993 
01994     Returns:    TRUE
01995 
01996     Purpose:    Used to determine if this type of gallery supports keyword searching.
01997                 This one does
01998                 
01999 ********************************************************************************************/
02000 
02001 BOOL LibClipartSGallery::CanSearchKeywords(void)
02002 {
02003     return(TRUE);
02004 }
02005 
02006 
02007 
02008 /********************************************************************************************
02009 
02010 >   virtual void LibClipartSGallery::WorkOutSectionName(String_256 *Section);
02011 
02012     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
02013     Created:    28/5/95
02014 
02015     Outputs:    Section - String used to return the section name
02016 
02017     Purpose:    Returns the section name to use in the grm file
02018 
02019 ********************************************************************************************/
02020 
02021 void LibClipartSGallery::WorkOutSectionName(String_256 *Section)
02022 {
02023     if(Section)
02024         *Section = _R(IDS_SGLCART_SECTION_NAME); // "ClipartGallery";
02025 }
02026 
02027 
02028 
02029 /***********************************************************************************************
02030 
02031 >   virtual SGDisplayGroup *LibClipartSGallery::AddLibraryGroup(Library *LibraryToDisplay, INT32 NumItems)
02032 
02033     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
02034     Created:    20/4/95
02035 
02036     Inputs:     LibraryToDisplay - Pointer to the library associated with the group
02037                 NumItems - Number of items in the group
02038     Returns:    The newly created library group, or NULL if there were problems
02039     Purpose:    Create a library group, as opposed to a display group
02040     Notes:
02041 
02042 ***********************************************************************************************/
02043 
02044 SGDisplayGroup *LibClipartSGallery::AddLibraryGroup(Library *LibraryToDisplay, INT32 NumItems)
02045 {
02046     TRACEUSER( "Matt", _T("Add library group called in clipart gallery\n"));
02047     ERROR3IF(LibraryToDisplay == NULL, "LibClipartSGallery::AddLibraryGroup - NULL parameter is illegal");
02048 
02049     if (DisplayTree == NULL)
02050     {
02051         ERROR3("LibClipartSGallery::AddLibraryGroup called before the DisplayTree was initialised!");
02052         return(NULL);
02053     }
02054 
02055     //Flag the gallery to redraw and check the group against the state of the web themes / clipart box
02056     m_bRedraw = true;
02057     SGLibGroup *TheGroup = (SGLibGroup *)DisplayTree->FindSubtree(this, NULL, LibraryToDisplay);
02058 
02059     if (TheGroup == NULL)
02060     {
02061         // No existing group for that library, so create a new one
02062         TheGroup = new SGLibGroup(this, NULL, LibraryToDisplay);
02063 
02064         if (TheGroup == NULL)               // Failed!
02065             return(NULL);
02066         
02067         // And add it to our display tree
02068         if (((GetClipTheme() == 0) && (LibraryToDisplay->Type == SGLib_ClipArt_WebThemes)) || ((GetClipTheme() == 1) && (LibraryToDisplay->Type == SGLib_ClipArt)))
02069         {
02070             TheGroup->Flags.Invisible = true;
02071             TheGroup->Flags.CanSelect = false;
02072         }
02073         DisplayTree->AddItem(TheGroup);
02074         TRACEUSER( "Matt", _T("...Add library group has just added the item to the display tree\n"));
02075     }
02076     else
02077     {
02078         if (((GetClipTheme() == 0) && (LibraryToDisplay->Type == SGLib_ClipArt_WebThemes)) || ((GetClipTheme() == 1) && (LibraryToDisplay->Type == SGLib_ClipArt)))
02079         {
02080             TheGroup->Flags.Invisible = true;
02081             TheGroup->Flags.CanSelect = false;
02082         }
02083 
02084         TheGroup->DestroySubtree(FALSE);    // Delete all items in the group
02085     }
02086 
02087     return(TheGroup);
02088 }
02089 
02090 
02091 
02092 
02093 /********************************************************************************************
02094 
02095 >   virtual SGDisplayItem *LibClipartSGallery::CopyDisplayItem(SGDisplayItem *SourceItem, 
02096                                                     SGDisplayGroup *DestGroup,
02097                                                     SGDisplayItem *TargetPosition = NULL)
02098     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
02099     Created:    25/4/95
02100 
02101     Inputs:     SourceItem - The item to copy elsewhere in the tree (see below)
02102 
02103                 DestGroup - The group into which the item should be inserted
02104 
02105                 TargetPosition - NULL (to add the copied item to the end of the sibling
02106                 list), or points to an item BEFORE which the copied item will be inserted.
02107 
02108     Returns:    NULL (failed) or a pointer to the new (copied) display item
02109 
02110     Purpose:    "Copies" the existing node in the tree in an appropriate fashion.
02111                 
02112                 This method is normally called when a gallery-organising drag completes,
02113                 and it is discovered that the dragged item(s) have been dragged to a 
02114                 different display group.
02115 
02116     Notes:      This method should be overridden by derived galleries to provide
02117                 appropriate behaviour (some galleries (e.g colour) will copy the real-item
02118                 that the given display-item references to the new group (document), while
02119                 other galleries (layer) may just move the item after all).
02120 
02121                 Note the handy InsertCopiedItem and MoveBefore/After methods which
02122                 are available to take all of the hard work out of copying/moving items!
02123 
02124                 See the body of this method in the source code for example pseudocode.
02125                 For real code, see the Colour Gallery (sgcolour.cpp)
02126 
02127     SeeAlso:    SuperGallery::InsertCopiedItem; SGDisplayItem::MoveBefore;
02128                 SGDisplayItem::MoveAfter; ColourSGallery::CopyDisplayItem
02129 
02130 ********************************************************************************************/
02131 
02132 SGDisplayItem *LibClipartSGallery::CopyDisplayItem(SGDisplayItem *SourceItem, 
02133                                 SGDisplayGroup *DestGroup, SGDisplayItem *TargetPosition)
02134 {
02135     TRACEUSER( "Matt", _T("Copy display item called in clipart gallery\n"));
02136     if(SourceItem == NULL || DestGroup == NULL)
02137     {
02138         ERROR3("LibClipartSGallery::CopyDisplayItem -> Illegal NULL param");
02139         return NULL;
02140     }
02141 
02142     // Check if we've dragged from one group to another and warn if that's the case
02143     if(DestGroup->IsKindOf(CC_RUNTIME_CLASS(SGLibGroup)))
02144     {
02145         SGDisplayNode *SourceGroup = SourceItem->GetParent();
02146         if((SGDisplayGroup *)SourceGroup != DestGroup)
02147         {
02148             // "Can't move clipart between groups."
02149             InformError(_R(IDS_CLIPART_BETWEEN_GROUPS), _R(IDS_OK));
02150             Error::ClearError();
02151         }
02152     }
02153 
02154     return(NULL);
02155 }
02156 
02157 
02158 
02159 /********************************************************************************************
02160 
02161 >   virtual BOOL LibClipartSGallery::InitMenuCommands(void)
02162                                                  
02163     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
02164     Created:    18/9/95
02165 
02166     Returns:    TRUE for success
02167 
02168     Purpose:    Initialises any menu commands that this gallery needs.
02169 
02170     Notes:      Will only create the menu commands once - further calls in the future
02171                 will return TRUE immediately wihtout doing anything.
02172 
02173 ********************************************************************************************/
02174 
02175 BOOL LibClipartSGallery::InitMenuCommands(void)
02176 {
02177     TRACEUSER( "Matt", _T("Clipart Gallery InitMenuCommands() called\n"));
02178     static BOOL MenusInitialised = FALSE;
02179 
02180     BOOL ok = TRUE;
02181 
02182     if (!MenusInitialised)
02183     {
02184         // Initialise menu command Ops
02185 
02186         // "Standard" entries for options menu
02187         ok = ok && InitMenuCommand((StringBase *) &SGCmd_Find, _R(IDS_SGMENU_FIND));
02188         ok = ok && InitMenuCommand((StringBase *) &SGCmd_Sort, _R(IDS_SGMENU_SORT));
02189         ok = ok && InitMenuCommand((StringBase *) &SGCmd_Properties, _R(IDS_SGMENU_PROPERTIES));
02190 
02191         // "Special" entries for options menu
02192         ok = ok && InitMenuCommand((StringBase *) &SGCmd_Add, _R(IDS_SGMENU_ADDCLIPART));
02193         ok = ok && InitMenuCommand((StringBase *) &SGCmd_EmptyClipartCache, _R(IDS_SGMENU_EMPTYCLIPARTCACHE));
02194 
02195         // "Special" entries for over-list menu
02196         ok = ok && InitMenuCommand((StringBase *) &SGCmd_Open, _R(IDS_SGMENU_OPEN));
02197         ok = ok && InitMenuCommand((StringBase *) &SGCmd_Import, _R(IDS_SGMENU_IMPORT));
02198         ok = ok && InitMenuCommand((StringBase *) &SGCmd_Remove, _R(IDS_SGMENU_REMOVE));
02199 
02200         // "Standard" commands for over-list menu
02201         ok = ok && InitMenuCommand((StringBase *) &SGCmd_FoldGroup, _R(IDS_SGMENU_FOLD));
02202         ok = ok && InitMenuCommand((StringBase *) &SGCmd_UnfoldGroup, _R(IDS_SGMENU_UNFOLD));
02203 
02204         ok = ok && InitMenuCommand((StringBase *) &SGCmd_NextGroup, _R(IDS_SGMENU_NEXTGROUP));
02205         ok = ok && InitMenuCommand((StringBase *) &SGCmd_PrevGroup, _R(IDS_SGMENU_PREVGROUP));
02206 
02207 
02208         MenusInitialised = TRUE;
02209     }
02210 
02211     return(ok);
02212 }
02213 
02214 
02215 
02216 /********************************************************************************************
02217 
02218 >   virtual BOOL LibClipartSGallery::BuildCommandMenu(GalleryContextMenu *TheMenu, SGMenuID MenuID)
02219 
02220     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
02221     Created:    15/9/95
02222 
02223     Inputs:     TheMenu - The menu to add commands to
02224                 MenuID  - The type of menu (over-list or from-options-button) to create
02225 
02226     Returns:    TRUE if it succeeded
02227 
02228     Purpose:    To build a menu of commands to be popped up over the gallery.
02229     
02230     Notes:      Override this method to stop the default menus being built
02231 
02232 ********************************************************************************************/
02233 
02234 BOOL LibClipartSGallery::BuildCommandMenu(GalleryContextMenu *TheMenu, SGMenuID MenuID)
02235 {
02236     BOOL ok = TRUE;
02237 
02238     if (MenuID == SGMENU_OPTIONS)
02239     {
02240         // Options menu
02241         ok = ok && AddCommand(TheMenu, (StringBase *) &SGCmd_Add);  
02242         ok = ok && AddCommand(TheMenu, (StringBase *) &SGCmd_EmptyClipartCache, TRUE);
02243 
02244         ok = ok && AddCommand(TheMenu, (StringBase *) &SGCmd_Find);
02245         ok = ok && AddCommand(TheMenu, (StringBase *) &SGCmd_Sort);
02246         ok = ok && AddCommand(TheMenu, (StringBase *) &SGCmd_Properties);
02247     }
02248     else
02249     {
02250         // Over-list menu
02251         ok = ok && AddCommand(TheMenu, (StringBase *) &SGCmd_Open);
02252         ok = ok && AddCommand(TheMenu, (StringBase *) &SGCmd_Import);
02253         ok = ok && AddCommand(TheMenu, (StringBase *) &SGCmd_Remove, TRUE);     // With separator
02254 
02255         SGDisplayGroup *TheGroup = FindCommandGroup();      // Fold or unfold as appropriate
02256         if (TheGroup == NULL || !TheGroup->Flags.Folded)
02257             ok = ok && AddCommand(TheMenu, (StringBase *) &SGCmd_FoldGroup);
02258         else
02259             ok = ok && AddCommand(TheMenu, (StringBase *) &SGCmd_UnfoldGroup);
02260 
02261         ok = ok && AddCommand(TheMenu, (StringBase *) &SGCmd_PrevGroup);
02262         ok = ok && AddCommand(TheMenu, (StringBase *) &SGCmd_NextGroup);
02263     }
02264 
02265     return(ok);
02266 }
02267 
02268 
02269 
02270 /********************************************************************************************
02271 
02272 >   virtual OpState LibClipartSGallery::GetCommandState(StringBase *CommandID, String_256 *ShadeReason)
02273 
02274     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
02275     Created:    15/9/95
02276 
02277     Inputs:     CommandID - TheString ID of the command
02278     Outputs:    ShadeReason - If you return (OpState.Greyed == TRUE) then this should be filled
02279                 ion with the reason that the item is shaded/greyed.
02280 
02281     Returns:    An OpState indicating the current menu item state.
02282 
02283     Purpose:    To determine the state of a given menu item. This method is an exact
02284                 parallel to an Op's GetState method (in fact, it is called by an Op's GetState)
02285     
02286     Notes:      Override this method to provide state info for your special commands
02287                 Call the base class for unknown commands to allow it to handle them for you
02288 
02289                 The base class handles all of these (maybe more - see the base class help)
02290                     Properties, Sort, Find;
02291                     New, Edit, Delete, Redefine;
02292                     NextGroup, PrevGroup, FoldGroup, UnfoldGroup;
02293 
02294 ********************************************************************************************/
02295 
02296 OpState LibClipartSGallery::GetCommandState(StringBase *CommandID, String_256 *ShadeReason)
02297 {
02298     OpState State;
02299 
02300     if (*CommandID == SGCmd_Add)                                            // --- Add (always available)
02301         return(State);
02302 
02303     if (*CommandID == SGCmd_EmptyClipartCache)
02304     {
02305         if (m_bDiscardWebFolders)
02306             State.Greyed = TRUE;
02307         return (State);
02308     }
02309 
02310     if (*CommandID == SGCmd_Open || *CommandID == SGCmd_Import)             // --- Open/Import
02311     {
02312         if (GetSelectedItemCount() < 1)
02313         {
02314             State.Greyed = TRUE;
02315             ShadeReason->MakeMsg(_R(IDS_SGSHADE_NOSEL));
02316         }
02317     }
02318     else if (*CommandID == SGCmd_Remove)                                    // --- Remove
02319     {
02320         if (GetSelectedGroupCount() < 1)
02321         {
02322             State.Greyed = TRUE;
02323             ShadeReason->MakeMsg(_R(IDS_SGSHADE_NOSELGROUP));
02324         }
02325     }
02326     else if (*CommandID == SGCmd_Properties)                                    // --- Properties - disabled if the gallery is currently downloading thumnails
02327     {
02328         if (!m_lstPendingThumbs.empty())
02329         {
02330             State.Greyed = TRUE;
02331             ShadeReason->MakeMsg(_R(IDS_SGSHADE_DOWNLOADING));
02332         }
02333     }
02334     else
02335         return(SuperGallery::GetCommandState(CommandID, ShadeReason));      // Unknown command- pass to baseclass
02336 
02337     return(State);
02338 }
02339 
02340 
02341 
02342 /********************************************************************************************
02343 
02344 >   virtual void LibClipartSGallery::DoCommand(StringBase *CommandID)
02345 
02346     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
02347     Created:    15/9/95
02348 
02349     Inputs:     CommandID - The String ID of the command
02350 
02351     Purpose:    To apply a given command when it is chosen from the menu.
02352     
02353     Notes:      Override this method to provide handling for your special commands.
02354                 Call the base class if you don't recognise the command, so that it can
02355                 handle standard commands.
02356 
02357                 The base class handles all of these (maybe more - see the base class help)
02358                     Properties, Sort, Find;
02359                     New, Edit, Delete, Redefine; (it calls ApplyAction as appropriate)
02360                     NextGroup, PrevGroup, FoldGroup, UnfoldGroup;
02361 
02362 ********************************************************************************************/
02363 
02364 void LibClipartSGallery::DoCommand(StringBase *CommandID)
02365 {
02366     if (*CommandID == SGCmd_Open)                                           // --- Open
02367         ImportClipart(TRUE, this);
02368     else if (*CommandID == SGCmd_Import)                                    // --- Import
02369         ImportClipart(FALSE, this);
02370     else if (*CommandID == SGCmd_Add)                                       // --- Add clipart
02371         BrowseClicked();
02372     else if (*CommandID == SGCmd_EmptyClipartCache)                 // --- Remove web folders
02373     {
02374         RemoveWebFolders(SGLib_ClipArt); //This will actually remove both clipart and web themes!
02375     }
02376     else if (*CommandID == SGCmd_Remove)                                    // --- Remove
02377     {
02378         RemoveSelectedLibraries(TRUE);
02379         UpdateGRMFile();
02380     }
02381     else
02382         SuperGallery::DoCommand(CommandID);     // Unknown command- pass to the base class
02383 }
02384 
02385 
02386 /********************************************************************************************
02387 >   INT32 LibClipartSGallery::GetClipTheme() const
02388 
02389     Author:     Priestley (Xara Group Ltd) <camelotdev@xara.com>
02390     Created:    18/09/2000
02391     Returns:    The index of the theme/clipart currently shown in the selector.
02392     SeeAlso:    LibClipartSGallery::SetPropertyIndex
02393 ********************************************************************************************/
02394 
02395 INT32 LibClipartSGallery::GetClipTheme() const
02396 {
02397     return m_nClipTheme;
02398 }
02399 
02400 
02401 
02402 /********************************************************************************************
02403 >   INT32 LibClipartSGallery::SetClipTheme(INT32 nNewIndex)
02404 
02405     Author:     Priestley (Xara Group Ltd) <camelotdev@xara.com>
02406     Created:    18/09/2000
02407     Inputs:     nNewIndex   ---     the new index to show.
02408     Returns:    The old value of the index.
02409     SeeAlso:    LibClipartSGallery::GetPropertyIndex
02410 ********************************************************************************************/
02411 
02412 INT32 LibClipartSGallery::SetClipTheme(INT32 nNewIndex)
02413 {
02414     ERROR3IF(0 > nNewIndex, "LibClipartSGallery::SetClipTheme: index out of range");
02415     INT32 n = m_nClipTheme;
02416     m_nClipTheme = nNewIndex;
02417     return n;
02418 }
02419 
02420 
02421 
02422 
02423 /********************************************************************************************
02424 
02425 >   BOOL OpDisplayLibClipartGallery::Init()
02426 
02427     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
02428     Created:    9/2/95 (base generated in sgbase.cpp)
02429     Inputs:     -
02430     Outputs:    -
02431     Returns:    TRUE if the operation could be successfully initialised 
02432                 FALSE if no more memory could be allocated 
02433                 
02434     Purpose:    OpDisplayLibClipartGallery initialiser method
02435     Errors:     ERROR will be called if there was insufficient memory to allocate the 
02436                 operation.
02437     SeeAlso:    -
02438 
02439 ********************************************************************************************/
02440 
02441 BOOL OpDisplayLibClipartGallery::Init()
02442 {
02443 
02444     ERRORIF(new OpLibGalClipTheme == 0, _R(IDE_NOMORE_MEMORY), FALSE);
02445 
02446     return (RegisterOpDescriptor(
02447                                 0,
02448                                 _R(IDS_DISPLAY_CLIPART_GALLERY),
02449                                 CC_RUNTIME_CLASS(OpDisplayLibClipartGallery),
02450                                 OPTOKEN_DISPLAYCLIPARTGALLERY,
02451                                 OpDisplayLibClipartGallery::GetState,
02452                                 0,  /* help ID */
02453                                 _R(IDBBL_DISPLAY_CLIPART_GALLERY),
02454                                 0   /* bitmap ID */));
02455 }               
02456 
02457 /********************************************************************************************
02458 
02459 >   OpState OpDisplayLibClipartGallery::GetState(String_256*, OpDescriptor*)
02460 
02461     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
02462     Created:    9/2/95 (base generated in sgbase.cpp)
02463     Inputs:     -
02464     Outputs:    -
02465     Returns:    The state of the OpDisplayLibClipartGallery operation
02466     Purpose:    For finding the OpDisplayLibClipartGallery's state. 
02467     Errors:     -
02468     SeeAlso:    -
02469 
02470 ********************************************************************************************/
02471 
02472 OpState OpDisplayLibClipartGallery::GetState(String_256* UIDescription, OpDescriptor*)
02473 {
02474     OpState OpSt;  
02475 
02476     // If the gallery is currenty open, then the menu item should be ticked
02477     DialogBarOp* pDialogBarOp = FindGallery();
02478     if (pDialogBarOp != NULL)
02479         OpSt.Ticked = pDialogBarOp->IsVisible();
02480 
02481 //  OpSt.Greyed = (Document::GetSelected() == NULL);
02482     return(OpSt);   
02483 }
02484 
02485 
02486 
02487 /********************************************************************************************
02488 
02489 >   void OpDisplayLibClipartGallery::Do(OpDescriptor*)
02490 
02491     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
02492     Created:    9/2/95 (base generated in sgbase.cpp)
02493     Inputs:     -
02494     Outputs:    -
02495     Returns:    -
02496     Purpose:    Displays the LibCliparts gallery
02497                 Updates the button state for this Op (the button sticks down while the
02498                 gallery is open)
02499     Errors:     -
02500     SeeAlso:    -
02501 
02502 ********************************************************************************************/
02503 
02504 void OpDisplayLibClipartGallery::Do(OpDescriptor*)
02505 {
02506     TRACEUSER( "Matt", _T("OpDisplayLibClipartGallery::Do called\n"));
02507     DialogBarOp *pDialogBarOp = FindGallery();
02508 
02509     if (pDialogBarOp != NULL)
02510     {
02511         // Toggle the visible state of the gallery window
02512         pDialogBarOp->SetVisibility( !pDialogBarOp->IsVisible() );
02513 
02514         // And update our button state
02515         SGInit::UpdateGalleryButton(OPTOKEN_DISPLAYCLIPARTGALLERY, pDialogBarOp->IsVisible());
02516 
02517         // If we're closing the gallery, flush the thumbnail caches
02518         if(pDialogBarOp->IsVisible() == FALSE)
02519         {
02520             // Flush the thumbnail cache
02521             BROADCAST_TO_CLASS(ThumbMessage(ThumbMessage::ThumbState::KILLCACHE, SGLib_ClipArt), DialogOp);
02522             BROADCAST_TO_CLASS(ThumbMessage(ThumbMessage::ThumbState::KILLCACHE, SGLib_ClipArt_WebThemes), DialogOp);
02523             BROADCAST_TO_CLASS(ThumbMessage(ThumbMessage::ThumbState::KILLCACHE, SGLib_Bitmap), DialogOp);
02524 
02525             // Ensure all open libraries are closed and memory reclaimed when the gallery closes
02526             if(LibClipartSGallery::ThisGallery != NULL)
02527             {
02528                 LibClipartSGallery::ThisGallery->GalleryAboutToClose();
02529             }
02530             else
02531             {
02532                 ERROR3("Clipart gallery seems to have been closed before I could reclaim my memory");
02533             }
02534 
02535         }
02536 /*      else
02537         {
02538             if(LibClipartSGallery::ThisGallery != NULL)
02539             {
02540                 LibClipartSGallery::ThisGallery->GalleryAboutToReOpen();
02541             }
02542         }*/
02543     }
02544 
02545     End();
02546 }
02547 
02548 
02549 
02550 /********************************************************************************************
02551 
02552 >   static DialogBarOp *OpDisplayLibClipartGallery::FindGallery(void)
02553 
02554     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
02555     Created:    9/2/95 (base generated in sgbase.cpp)
02556 
02557     Returns:    NULL or a pointer to the LibClipart gallery instance
02558 
02559     Purpose:    Finds the LibClipart gallery class instance
02560 
02561     Notes:      The bars system always keeps one LibClipart gallery alive for us.
02562                 If one is not found, this usually indicates that it can't be found
02563                 in bars.ini: Check that the 'Name' string *exactly* matches the
02564                 title string given in bars.ini.
02565                 Also check that bars.ini indicates the bar is of the LibClipartSGallery class
02566 
02567 ********************************************************************************************/
02568 
02569 DialogBarOp *OpDisplayLibClipartGallery::FindGallery(void)
02570 {
02571     String_32 Name = _R(IDS_SGLCART_GALLERY_NAME); // "Clipart gallery";
02572     DialogBarOp* pDialogBarOp = DialogBarOp::FindDialogBarOp(Name);
02573 
02574     if (pDialogBarOp != NULL)
02575     {
02576         if (pDialogBarOp->GetRuntimeClass() == CC_RUNTIME_CLASS(LibClipartSGallery))
02577             return(pDialogBarOp);
02578 
02579         ERROR3("Got the Clipart gallery but it's not of the LibClipartSGallery class");
02580     }
02581     else
02582     {
02583         ERROR3("Can't find the Clipart gallery in bars.ini!\n");
02584     }
02585 
02586     return(NULL);
02587 }
02588 
02589 /***********************************************************************************************
02590 
02591 >   virtual LibDisplayType SGClipartItem::GetDisplayType(SGMiscInfo *MiscInfo)
02592 
02593     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
02594     Created:    16/3/95
02595 
02596     Inputs:     MiscInfo - Contains a few useful bits of info that may be
02597                 needed for all event types.
02598     Outputs:    
02599     Returns:    The display mode type to use (position of text, and size of thumb)
02600 
02601     Purpose:    Return the display type to use - clipart gallery override
02602     Notes:
02603     SeeAlso:
02604 
02605 ***********************************************************************************************/
02606 
02607 LibDisplayType SGClipartItem::GetDisplayType(SGMiscInfo *MiscInfo)
02608 {
02609     switch(MiscInfo->DisplayMode)
02610     {
02611         case 2:
02612             return LibDisplay_SmallThumbText;
02613             break;
02614         case 1:
02615             return LibDisplay_FullInfo;
02616             break;
02617         case 0:
02618         default:
02619             return LibDisplay_LargeThumbTextUnder;
02620             break;
02621     }
02622 
02623     return LibDisplay_LargeThumbTextUnder;
02624 }
02625 
02626 /***********************************************************************************************
02627 
02628 >   SGClipartItem::SGClipartItem(LibraryIndex LibraryIndexToDisplay);
02629 
02630     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
02631     Created:    16/3/95
02632     Inputs:     LibraryIndex - Offset into index file which describes this item
02633     Outputs:    
02634     Returns:
02635     Purpose:    Creates and initialises a new item for the clipart gallery
02636     Notes:
02637     SeeAlso:
02638 
02639 ***********************************************************************************************/
02640 
02641 SGClipartItem::SGClipartItem(LibraryIndex LibraryIndexToDisplay, BOOL bNew) :
02642     SGLibDisplayItem(LibraryIndexToDisplay, bNew)
02643 {
02644 }
02645 
02646 /* default constructor and destructor */
02647 
02648 SGClipartItem::SGClipartItem()
02649 {
02650 }
02651 
02652 SGClipartItem::~SGClipartItem()
02653 {
02654     TRACEUSER( "Matt", _T("~SGClipartItem called\n"));
02655 }
02656 
02657 
02658 
02659 
02660 
02661 
02662 
02663 /***********************************************************************************************
02664 
02665 >   virtual BOOL SGClipartItem::HandleEvent(SGEventType EventType, void *EventInfo,
02666                                              SGMiscInfo *MiscInfo)
02667 
02668     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
02669     Created:    27/1/95 (base generated in sgbase.cpp)
02670 
02671     Inputs:     EventType - An enumerated value describing what type of event is to be processed
02672 
02673                 EventInfo - A structure describing the event (may be NULL). The exact thing
02674                             pointed at by this pointer depends upon the event type:
02675 
02676                             MonoOn
02677                             Event               Thing EventInfo points at
02678                             SGEVENT_FORMAT      (SGFormatInfo *)
02679                             SGEVENT_REDRAW      (SGRedrawInfo *)
02680                             SGEVENT_MOUSECLICK  (SGMouseInfo *)
02681                             MonoOff
02682                 Use the provided SGDisplayNode::Get[Format]Info() inlines to retrieve this
02683                 information - they provide useful error/type checking, and hide the cast
02684 
02685                 MiscInfo - always provided. Contains a few useful bits of info that may be
02686                 needed for all event types.
02687 
02688     Outputs:    FormatInfo is updated as appropriate
02689 
02690     Returns:    TRUE if the event was handled successfully
02691                 FALSE if it was not
02692 
02693     Purpose:    Handles a SuperGallery DisplayTree event
02694 
02695     Notes:      This overrides the pure virtual SGDisplayNode::HandleEvent method
02696 
02697                 A node need not handle a specific event - if it does not handle it, it
02698                 should return FALSE.
02699 
02700                 Redraw and Formatting handlers should never return TRUE, as this will
02701                 prevent the event from continuing through the tree.
02702 
02703                 Non-leaf-nodes must call SGDisplayNode::GiveEventToMyChildren in order
02704                 to pass the event dow the tree. THIS node is a leaf-node, so it doesn't.
02705 
02706     SeeAlso:    SGDisplayNode::HandleEvent
02707 
02708 ***********************************************************************************************/
02709 
02710 BOOL SGClipartItem::HandleEvent(SGEventType EventType, void *EventInfo, SGMiscInfo *MiscInfo)
02711 {
02712     switch (EventType)
02713     {
02714         case SGEVENT_MOUSECLICK:
02715         {
02716             SGMouseInfo *Mouse = GetMouseInfo(EventType, EventInfo);
02717 
02718             if (Mouse != NULL && FormatRect.ContainsCoord(Mouse->Position))
02719             {   
02720                 if(LibClipartSGallery::DoSounds)
02721                 {
02722                     Library *Lib = GetParentLibrary();
02723                     if (Lib != NULL)
02724                     {
02725                         String_64 Key("Sample");
02726                         String_256 SampleString;
02727                         Lib->GetSingleField(TheLibraryIndex, &Key, &SampleString);
02728                         if(SampleString.Length() > 2)
02729                         {
02730                             String_256 SubPath = Lib->SubLibPath->GetPath();
02731                             BOOL Done = SGLibOil::PlayRandomSample(&SampleString, &SubPath);
02732                             ERROR3IF(!Done, "Problems playing sample");
02733                         }
02734                     }
02735                 }
02736 
02737                 INT32 XSize=0, YSize=0;
02738                 if(SGLibDisplayItem::StartDrag(EventType, EventInfo, MiscInfo, &XSize, &YSize))
02739                 {
02740                     GalleryClipartDragInfo *DragClipart;
02741                     DragClipart = new GalleryClipartDragInfo(this, Mouse, MiscInfo,
02742                                                         Mouse->MenuClick, XSize, YSize);
02743                     if (DragClipart != NULL)
02744                         DragManagerOp::StartDrag(DragClipart, GetListWindow());
02745                     else
02746                     {
02747                         if(LibClipartSGallery::TmpDraggingBitmap != NULL)
02748                         {
02749                             delete LibClipartSGallery::TmpDraggingBitmap;
02750                             LibClipartSGallery::TmpDraggingBitmap = NULL;
02751                         }
02752                     }
02753                 }
02754                 return TRUE;        // Claim this event - nobody else can own this click
02755             }
02756         }
02757     }
02758     
02759     return(SGLibDisplayItem::HandleEvent(EventType, EventInfo, MiscInfo));
02760 }
02761 
02762 
02763 /********************************************************************************************
02764 
02765 >   SGClipartDragTarget::SGClipartDragTarget(DialogOp *TheDialog, CGadgetID TheGadget = NULL)
02766      
02767     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
02768     Created:    25/3/95
02769     Inputs:     TheDialog - The kernel dialog in which the target exists
02770                 TheGadget - The gadget within that dialogue which is the target
02771 
02772     Purpose:    Constructor
02773 
02774 ********************************************************************************************/
02775 
02776 SGClipartDragTarget::SGClipartDragTarget(DialogOp *TheDialog, CGadgetID TheGadget)
02777                     : SGListDragTarget(TheDialog, TheGadget)
02778 {
02779     ERROR3IF(!TheDialog->IsKindOf(CC_RUNTIME_CLASS(LibClipartSGallery)),
02780             "You can only use SGClipartDragTargets with LibClipartSGallery dialogues!");
02781 }
02782 
02783 
02784 
02785 /********************************************************************************************
02786 
02787     BOOL SGClipartDragTarget::ProcessEvent(DragEventType Event, DragInformation *pDragInfo,
02788                                             OilCoord *pMousePos, KeyPress* pKeyPress)
02789 
02790     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
02791     Created:    25/3/95
02792     Inputs:     Event - Indicates what has happened
02793                 pDragInfo - points to drag information describing this drag. This
02794                 should be a ClipartDragInformation or derivation thereof
02795                 pMousePos - points to information on the current mouse position, in OIL coords
02796                 pKeyPress - NULL, or if for a keypress event, keypress information
02797 
02798     Returns:    TRUE to claim the event, FALSE to let it through to other targets
02799 
02800     Purpose:    Event Handler for SuperGallery listitem drag events. Overrides the
02801                 base class handler to enable it to sort out the node being dragged
02802                 for Clipart drags.
02803 
02804 ********************************************************************************************/
02805 
02806 BOOL SGClipartDragTarget::ProcessEvent(DragEventType Event, DragInformation *pDragInfo,
02807                                         OilCoord *pMousePos, KeyPress* pKeyPress)
02808 {
02809     TRACEUSER( "Matt", _T("SGClipartDragTarget::ProcessEvent called\n"));
02810     if (!pDragInfo->IsKindOf(CC_RUNTIME_CLASS(BitmapDragInformation)))
02811         return(FALSE);
02812 
02813     SGDisplayNode *DraggedNode = NULL;
02814     BOOL IsSimpleBitmapDrag = TRUE;
02815 
02816     if (IS_A(pDragInfo, GalleryClipartDragInfo))
02817     {
02818         DraggedNode = ((GalleryClipartDragInfo *)pDragInfo)->GetDraggedClipart();
02819         IsSimpleBitmapDrag = FALSE;
02820     }
02821 
02822     if (DraggedNode != NULL)
02823     {
02824         switch(Event)
02825         {
02826             case DRAGEVENT_COMPLETED:
02827                 HandleDragCompleted((SuperGallery *) TargetDialog,
02828                                     DraggedNode, pMousePos, IsSimpleBitmapDrag);
02829                 return(TRUE);
02830 
02831 
02832             case DRAGEVENT_MOUSESTOPPED:
02833             case DRAGEVENT_MOUSEMOVED:
02834             case DRAGEVENT_MOUSEIDLE:
02835                 {
02836                     // Specialised cursor changing code - can't drag between groups...
02837 
02838                     SuperGallery *ParentGallery = (SuperGallery *) TargetDialog;
02839                     if (ParentGallery != NULL && pMousePos != NULL && DraggedNode != NULL)
02840                     {
02841                         // Convert the OilCoords into DocCoords
02842                         DocCoord MousePos(pMousePos->x, pMousePos->y);
02843                         SGDisplayNode *DestNode = ParentGallery->FindNodeUnderPointer(&MousePos);
02844 
02845                         if(DestNode != NULL)
02846                         {
02847                             SGDisplayNode *DestGroup = DestNode->GetParent();
02848                             SGDisplayNode *SourceGroup = DraggedNode->GetParent();
02849 
02850                             if(DestGroup != NULL && SourceGroup != NULL)
02851                             {   
02852                                 // We're dragging within a group - that's ok
02853                                 if(SourceGroup == DestGroup)
02854                                     return(DetermineCursorShape(ParentGallery, DraggedNode, pMousePos));
02855                             }
02856                         }       
02857                     }
02858                 }
02859 
02860                 // If we're trying to drag to unimplemented areas (between groups), set the no-can-do cursor
02861                 CurrentCursorID = _R(IDC_DRAGGING_COLOUR);      // No-can-drop cursor shape
02862                 return TRUE;
02863         }
02864     }
02865 
02866     // Otherwise, we aren't interested in the event, so we don't claim it
02867     return(FALSE);
02868 }
02869 
02870 /********************************************************************************************
02871 
02872 >   void GalleryClipartDragInfo::GalleryClipartDragInfo() 
02873      
02874     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
02875     Created:    19/3/95       
02876 
02877     Purpose:    Default constructor - do not call this constructor
02878 
02879 ********************************************************************************************/
02880 
02881 GalleryClipartDragInfo::GalleryClipartDragInfo()
02882 {
02883     ERROR3("Default GalleryClipartDragInfo constructor called");    
02884 }
02885 
02886 
02887 /********************************************************************************************
02888 
02889 >   void GalleryClipartDragInfo::~GalleryClipartDragInfo() 
02890      
02891     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
02892     Created:    27/4/95       
02893 
02894     Purpose:    Destructor - need to unlock thumbnail
02895 
02896 ********************************************************************************************/
02897 
02898 GalleryClipartDragInfo::~GalleryClipartDragInfo()
02899 {
02900     TRACEUSER( "Richard", _T("~GalleryClipartDragInfo called\n"));
02901 
02902     if(LibraryGallery::TmpDraggingBitmap != NULL)
02903     {
02904         delete LibraryGallery::TmpDraggingBitmap;
02905         LibraryGallery::TmpDraggingBitmap = NULL;
02906     }
02907 }
02908 
02909 /********************************************************************************************
02910 
02911 >   GalleryClipartDragInfo::GalleryClipartDragInfo(SGClipartItem *pSourceItem,
02912                                             SGMouseInfo *pMouseInfo, SGMiscInfo *pMiscInfo,
02913                                             BOOL IsAdjust = FALSE,
02914                                             INT32 XSize = 0, INT32 YSize = 0)
02915      
02916     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
02917     Created:    19/3/95       
02918 
02919     Inputs:     pSourceItem - The gallery item from which the drag originated
02920                 pMouseInfo  - The mouse info which made the item start the drag
02921                 pMiscInfo   - The MiscInfo which accompanied the mouse event
02922                 IsAdjust    - TRUE if this is an adjust (line-Bitmap) drag
02923                 XSize       - Width in pixels of preview to drag
02924                 YSize       - Height in pixels of preview to drag
02925 
02926     Purpose:    Constructor
02927 
02928 ********************************************************************************************/
02929 
02930 GalleryClipartDragInfo::GalleryClipartDragInfo(SGClipartItem *pSourceItem,
02931                                             SGMouseInfo *pMouseInfo, SGMiscInfo *pMiscInfo,
02932                                             BOOL IsAdjust, INT32 XSize, INT32 YSize)
02933                                   : BitmapDragInformation(LibraryGallery::TmpDraggingBitmap,
02934                                         /*pSourceItem->GetDisplayedKernelBitmap(pMiscInfo, TRUE)*/
02935                                         XSize, YSize, 0, 0, IsAdjust)
02936 {
02937     SourceItem  = pSourceItem;  // Copy the source item pointer
02938     MouseInfo   = *pMouseInfo;  // Duplicate the structures (they may cease to exist
02939     MiscInfo    = *pMiscInfo;   // soon after the drag is started)
02940 }
02941 
02942 
02943 
02944 /********************************************************************************************
02945 
02946 >   void GalleryClipartDragInfo::OnClick(INT32 Flags,POINT Point) 
02947      
02948     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
02949     Created:    19/3/95       
02950     Inputs:     -
02951     Outputs:    -
02952     Returns:    -
02953     Purpose:    This is called if a drag was attempted but never started because it was a 
02954                 click all along. It calls back the SourceItem SGDisplayBitmap, to get it
02955                 to handle the click.
02956     Errors:     -
02957     SeeAlso:    -
02958 
02959 ********************************************************************************************/
02960 
02961 void GalleryClipartDragInfo::OnClick(INT32 Flags ,POINT Point)
02962 {
02963     TRACEUSER( "Matt", _T("GalleryClipartDragInfo::OnClick called\n"));
02964     if (SourceItem != NULL)
02965         SourceItem->DragWasReallyAClick(&MouseInfo, &MiscInfo);
02966 }
02967 
02968 /********************************************************************************************
02969 
02970 >   void GalleryClipartDragInfo::GetCursorID(DragTarget* pDragTarget)
02971 
02972     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
02973     Created:    25/3/95
02974     Purpose:    Set cursor over this target
02975 
02976 
02977 ********************************************************************************************/
02978 
02979 UINT32 GalleryClipartDragInfo::GetCursorID(DragTarget* pDragTarget)
02980 {
02981     if (pDragTarget && pDragTarget->IS_KIND_OF(ViewDragTarget))
02982     {
02983         PageDropInfo PageDropInfo;
02984         ((ViewDragTarget*)pDragTarget)->GetDropInfo(&PageDropInfo);
02985 
02986         NodeRenderableInk* pObjectHit   = PageDropInfo.pObjectHit;
02987         ObjectDragTarget TargetHit      = PageDropInfo.TargetHit;
02988 
02989         if (pObjectHit)
02990             TargetHit = NO_TARGET;
02991 
02992         switch (TargetHit)
02993         {
02994             case NO_TARGET:
02995                 return _R(IDC_CANDROPONPAGE);
02996         };
02997 
02998         return _R(IDC_CANDROPONPAGE);
02999     }
03000 
03001     return _R(IDC_CANTDROP);
03002 }
03003 
03004 /********************************************************************************************
03005 
03006 >   virtual BOOL GalleryClipartDragInfo::GetStatusLineText(String_256 * TheText, DragTarget* pDragTarget)
03007 
03008     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
03009     Created:    25/3/95
03010     Returns:    Whether String is valid
03011     Purpose:    provide status line text for this target
03012    
03013 ********************************************************************************************/
03014 
03015 BOOL GalleryClipartDragInfo::GetStatusLineText(String_256 * TheText, DragTarget* pDragTarget)
03016 {
03017     ERROR2IF(TheText==NULL,FALSE,"NULL string in GetStatusLineText()");
03018 
03019     if (TheBitmap == NULL || TheBitmap->ActualBitmap == NULL)
03020         return FALSE;
03021 
03022     String_256 DragString;
03023     String_256 ItemName;
03024     SourceItem->GetNameText(&ItemName);
03025 
03026     // "Dragging clipart '#1%s'"
03027     DragString.MakeMsg(_R(IDS_CLIPART_DRAGGING), (TCHAR *)ItemName);
03028 
03029     if (pDragTarget && pDragTarget->IS_KIND_OF(ViewDragTarget))
03030     {
03031         DragString += String_8(_R(IDS_SGDFONTS_STAT_COLON_SEP)); //" : ";
03032 
03033         PageDropInfo PageDropInfo;
03034         ((ViewDragTarget*)pDragTarget)->GetDropInfo(&PageDropInfo);
03035 
03036         NodeRenderableInk* pObjectHit   = PageDropInfo.pObjectHit;
03037         ObjectDragTarget TargetHit      = PageDropInfo.TargetHit;
03038 
03039         if (pObjectHit)
03040             TargetHit = NO_TARGET;              // Ignore NodeBitmap objects
03041 
03042         switch (TargetHit)
03043         {
03044             case NO_TARGET:
03045             {
03046                 // + "Drop to Insert the clipart at this point on the Page";
03047                 String_64 DropToThis(_R(IDS_CLIPART_DROP));
03048                 DragString += DropToThis;
03049                 break;
03050             }
03051         };
03052 
03053         *TheText = DragString;
03054         return TRUE;
03055     }
03056     
03057     *TheText = DragString;
03058     return TRUE;
03059 }
03060 
03061 /********************************************************************************************
03062 
03063 >   BOOL GalleryClipartDragInfo::OnPageDrop(ViewDragTarget* pDragTarget)
03064 
03065     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
03066     Created:    19/3/95       
03067     Inputs:     pDragTarget, the ViewDragTarget that we were dropped onto.
03068     Returns:    TRUE, if we handled the drop.
03069     Purpose:    Called when Clipart is dropped onto the page.
03070                 Use pDragTarget->GetDropInfo(), to details of the drop.
03071 
03072 ********************************************************************************************/
03073 
03074 BOOL GalleryClipartDragInfo::OnPageDrop(ViewDragTarget* pDragTarget)
03075 {
03076     PageDropInfo PageDropInfo;
03077     ((ViewDragTarget*)pDragTarget)->GetDropInfo(&PageDropInfo);
03078 
03079     PathName FileName;      
03080     SGLibDisplayItem *ClipItem = SourceItem;
03081 
03082     BOOL ok = ClipItem->GetFileName(&FileName);
03083 
03084     if(ok)
03085     {
03086         // Bodge for clipart CD - 'Cow' in LScape should point to "Moo.tif", not just "Moo"
03087         if(FileName.GetFileName(FALSE) == (String_256)"Moo")
03088         {
03089             INT32 Size = ClipItem->GetFileSize(NULL);
03090             if(Size == 1080904)
03091                 FileName.SetType("TIF");
03092         }
03093 
03094         if(!FileName.IsValid(FileName.GetPath()))
03095         {
03096             ERROR3("LibClipartSGallery::ImportClipart - Filename is invalid");
03097             return FALSE;
03098         }
03099 
03100         // Check if file has a long filename, and use that if it does...
03101         String_256 FilePath((const TCHAR *)FileName.GetPath());
03102         String_256 LongFileName;
03103         BOOL LongPath = FileUtil::GetLongFileName((LPTSTR)FilePath, (LPTSTR)LongFileName, 255);
03104         if(LongPath)
03105         {
03106             FilePath = FileName.GetLocation(TRUE);
03107             FilePath += LongFileName;
03108         }
03109 
03110 #ifdef STANDALONE
03111         CWinApp* pApp = AfxGetApp();
03112         BaseFileDialog::SelectedFilter = 0;
03113 
03114         // Open a document
03115         CCamDoc* pDoc = (CCamDoc*) pApp->OpenDocumentFile((TCHAR *)FilePath);
03116 
03117         // And redraw the imported document
03118         if(pDoc) pDoc->GetKernelDoc()->ForceRedraw();
03119 #else
03120         // Invoke the clipart import operation so that we get Undo.
03121 
03122         Library* pLibrary = ClipItem->GetParentLibrary();
03123         if (!pLibrary)
03124         {
03125             ERROR3("Illegal NULL pointer");
03126             return FALSE;
03127         }
03128         BOOL bIsLocalFile;
03129         if (!pLibrary->IsWebLibrary())
03130             bIsLocalFile = TRUE;
03131         else 
03132             bIsLocalFile = (_access((TCHAR*) FilePath, 0) != -1);
03133 
03134         
03135         
03136         if (bIsLocalFile) // local file, do a normal import Op
03137         {
03138             OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(CC_RUNTIME_CLASS(OpClipartImport));
03139 
03140             if (pOpDesc != NULL)
03141             {
03142                 ClipartImportParam Param;
03143 
03144                 // Set up the parameters which we require to import the clipart
03145                 PathName FullPathName((TCHAR *)FilePath);
03146                 Param.File = &FullPathName;
03147 
03148                 Param.Import = TRUE;
03149                 if(PageDropInfo.pDoc == NULL)
03150                     Param.Import = FALSE;
03151 
03152                 Param.Result = TRUE;
03153                 Param.DropInfo =  &PageDropInfo; // for positioning and scaling
03154 
03155                 // Go for it!
03156                 pOpDesc->Invoke((OpParam *) &Param);
03157 
03158                 ok = Param.Result;
03159 
03160                 if(!ok)
03161                 {
03162                     ERROR3("LibClipartSGallery::ImportClipart - Problem importing file");
03163                     return FALSE;
03164                 }
03165             }
03166         }
03167         else // try an asynch import
03168         {
03169             String_256 strFileURL = FilePath;
03170             pLibrary->LocalPath2URL(&strFileURL);
03171             OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(CC_RUNTIME_CLASS(OpAsynchClipartImport));
03172             if (pOpDesc != NULL)
03173             {
03174                 AsynchClipartImportParam* Param = new AsynchClipartImportParam;
03175                 ERROR2IF(!Param, FALSE, "Memory allocation error");
03176                 // Set up the parameters which we require to import the clipart
03177                 Param->File.SetPathName((TCHAR *)FilePath);
03178                 Param->strURL = strFileURL;
03179                 String_256 strDescription;
03180                 ClipItem->GetNameText(&strDescription);
03181                 Param->strDescription = _T("'");
03182                 Param->strDescription += strDescription;
03183                 Param->strDescription += _T("'");
03184                 Param->bDropped = TRUE;
03185                 Param->Import = (PageDropInfo.pDoc == NULL) ? FALSE : TRUE;
03186                 ((ViewDragTarget*)pDragTarget)->GetDropInfo(&Param->DropInfo);
03187                 pOpDesc->Invoke((OpParam *) Param);
03188             }
03189         }
03190 #endif
03191     }
03192 
03193     return TRUE;
03194 }
03195 
03196 
03197 
03198 /********************************************************************************************
03199 
03200 >   BOOL GalleryClipartDragInfo::OnMainFrameDrop(DragTarget* pDragTarget)
03201 
03202     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
03203     Created:    13/12/95          
03204     Inputs:     pDragTarget, the Target that this drag finished over.
03205     Returns:    TRUE, if we handled the drop.
03206                 FALSE, if we want to let the target handle it.
03207     Purpose:    Called when this DragInfo is dropped onto the MainFrame. We open the file
03208                 into a new document...
03209 
03210 ********************************************************************************************/
03211 
03212 BOOL GalleryClipartDragInfo::OnMainFrameDrop(DragTarget* pDragTarget)
03213 {
03214     SGLibDisplayItem* ClipItem = (SGLibDisplayItem*) SourceItem;
03215     String_256 ItemText;
03216 
03217     if (ClipItem->IsKindOf(CC_RUNTIME_CLASS(SGClipartItem)))
03218     {
03219         ClipItem->GetNameText(&ItemText);
03220         PathName FileName;      
03221     
03222         //if (Lib != NULL)
03223         BOOL ok = ClipItem->GetFileName(&FileName);
03224 
03225         if(ok)
03226         {
03227             // Bodge for clipart CD - 'Cow' in LScape should point to "Moo.tif", not just "Moo"
03228             if(FileName.GetFileName(FALSE) == (String_256)"Moo")
03229             {
03230                 INT32 Size = ClipItem->GetFileSize(NULL);
03231                 if(Size == 1080904)
03232                     FileName.SetType("TIF");
03233             }
03234 
03235             if(!FileName.IsValid(FileName.GetPath()))
03236             {
03237                 ERROR3("LibClipartSGallery::ImportClipart - Filename is invalid");
03238                 return FALSE;
03239             }
03240 
03241             // Check if file has a long filename, and use that if it does...
03242             String_256 FilePath((const TCHAR *)FileName.GetPath());
03243             String_256 LongFileName;
03244             BOOL LongPath = FileUtil::GetLongFileName((LPTSTR)FilePath, (LPTSTR)LongFileName, 255);
03245             if(LongPath)
03246             {
03247                 FilePath = FileName.GetLocation(TRUE);
03248                 FilePath += LongFileName;
03249             }
03250 
03251             // Check if the file really exists on the local drive
03252             Library* pLibrary = ClipItem->GetParentLibrary();
03253             if (!pLibrary)
03254             {
03255                 ERROR3("Illegal NULL pointer");
03256                 return FALSE;
03257             }
03258             BOOL bIsLocalFile;
03259             if (!pLibrary->IsWebLibrary())
03260                 bIsLocalFile = TRUE;
03261             else 
03262                 bIsLocalFile = (_access((TCHAR*) FilePath, 0) != -1);
03263                 
03264             if (bIsLocalFile)
03265             {
03266                 CWinApp* pApp = AfxGetApp();
03267                 BaseFileDialog::SelectedFilter = 0;
03268 
03269                 // Open a document
03270                 CCamDoc* pDoc = (CCamDoc*) pApp->OpenDocumentFile((TCHAR *)FilePath);
03271 
03272                 // And redraw the imported document
03273                 if(pDoc) pDoc->GetKernelDoc()->ForceRedraw();
03274             }
03275             else // do an asynch import
03276             {
03277                 String_256 strFileURL = FilePath;
03278                 pLibrary->LocalPath2URL(&strFileURL);
03279                 OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(CC_RUNTIME_CLASS(OpAsynchClipartImport));
03280                 if (pOpDesc != NULL)
03281                 {
03282                     AsynchClipartImportParam* Param = new AsynchClipartImportParam;
03283                     ERROR2IF(!Param, FALSE, "Memory allocation error");
03284                     // Set up the parameters which we require to import the clipart
03285                     Param->File.SetPathName((TCHAR *)FilePath);
03286                     String_256 strDescription;
03287                     ClipItem->GetNameText(&strDescription);
03288                     Param->strDescription = _T("'");
03289                     Param->strDescription += strDescription;
03290                     Param->strDescription += _T("'");
03291                     Param->strURL = strFileURL;
03292                     Param->Import = FALSE;
03293                     Param->bDropped = FALSE;
03294                     // Invoke the operation
03295                     pOpDesc->Invoke((OpParam*) Param);
03296                 }
03297             }
03298         }
03299         return TRUE;
03300     }   
03301     return FALSE;
03302 }
03303 
03304 
03305 
03306 
03307 
03308 /********************************************************************************************
03309 
03310 >   SGOilClipartDragTarget::SGOilClipartDragTarget(HWND TheWindow, CRect *ClientArea = NULL)
03311 
03312     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
03313     Created:    13/12/95          
03314     Inputs:     TheWindow   - Window to use for drag target
03315                 ClientArea  - Rectangle in window to use for drag target
03316 
03317     Purpose:    Constructor
03318 
03319 ********************************************************************************************/
03320 
03321 SGOilClipartDragTarget::SGOilClipartDragTarget(HWND TheWindow, CRect *ClientArea)
03322                     : WinoilDragTarget(TheWindow, ClientArea)
03323 {
03324 }
03325     
03326 /********************************************************************************************
03327 
03328 >   UINT32 SGOilClipartDragTarget::GetCursorID()
03329 
03330     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
03331     Created:    13/12/95          
03332     Returns:    Cursor ID for clipart drags over the mainframe
03333     Purpose:    Get cursor ID
03334 
03335 ********************************************************************************************/
03336 
03337 UINT32 SGOilClipartDragTarget::GetCursorID()
03338 {
03339     return _R(IDC_CANDROPONPAGE);
03340 }
03341 
03342 /********************************************************************************************
03343 
03344 >   BOOL SGOilClipartDragTarget::GetStatusLineText(String_256 * TheText)
03345 
03346     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
03347     Created:    13/12/95          
03348     Outputs:    Text for status line
03349     Returns:    TRUE if we extracted a wee tad of status line text
03350     Purpose:    Obtains status line text for when we're dragging an item of clipart over the
03351                 blank mainframe area...
03352 
03353 ********************************************************************************************/
03354 
03355 BOOL SGOilClipartDragTarget::GetStatusLineText(String_256 * TheText)
03356 {
03357     ERROR2IF(TheText==NULL,FALSE,"NULL string in GetStatusLineText()");
03358 
03359     DragInformation *pDragInfo = DragManagerOp::GetCurrentDragInfo();
03360     if (pDragInfo == NULL || !pDragInfo->IsKindOf(CC_RUNTIME_CLASS(GalleryClipartDragInfo)))
03361         return(FALSE);
03362     SGClipartItem *pClipartItem = ((GalleryClipartDragInfo *)pDragInfo)->SourceItem;
03363 
03364     String_256 DragString;
03365     String_256 ItemName;
03366     pClipartItem->GetNameText(&ItemName);
03367 
03368     // "Dragging clipart '#1%s' : Drop to open a new document containing the clipart"
03369     DragString.MakeMsg(_R(IDS_CLIPART_DRAGGING), (TCHAR *)ItemName);
03370     DragString += String_8(_R(IDS_SGDFONTS_STAT_COLON_SEP));
03371     DragString += String_256(_R(IDS_CLIPART_OPEN_DROP));
03372 
03373     *TheText = DragString;
03374     return TRUE;
03375 }
03376 
03377 /********************************************************************************************
03378 
03379 >   BOOL SGOilClipartDragTarget::ProcessEvent(DragEventType Event,
03380             DragInformation *pDragInfo, CPoint *pMousePos, KeyPress* pKeyPress)
03381 
03382     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
03383     Created:    13/12/95          
03384     Inputs:     Standard drag target stuff...
03385     Returns:    TRUE if we processed our event ok...
03386     Purpose:    Process an event such as a completed drag...
03387 
03388 ********************************************************************************************/
03389 
03390 BOOL SGOilClipartDragTarget::ProcessEvent(DragEventType Event,
03391             DragInformation *pDragInfo, CPoint *pMousePos, KeyPress* pKeyPress)
03392 {
03393     if (!pDragInfo->IsKindOf(CC_RUNTIME_CLASS(GalleryClipartDragInfo)))
03394         return(FALSE);
03395 
03396     SGDisplayNode *DraggedNode = NULL;
03397     BOOL IsSimpleClipartDrag = TRUE;
03398 
03399     if (IS_A(pDragInfo, GalleryClipartDragInfo))
03400     {
03401         DraggedNode = ((GalleryClipartDragInfo *)pDragInfo)->GetDraggedClipart();
03402         IsSimpleClipartDrag = FALSE;
03403     }
03404 
03405     if (DraggedNode != NULL)
03406     {
03407         switch(Event)
03408         {
03409             case DRAGEVENT_COMPLETED:
03410             {
03411                 // Open the clipart file into a brand-spanking-new document
03412                 return(((GalleryClipartDragInfo *)pDragInfo)->OnMainFrameDrop(this));
03413             }
03414 
03415             case DRAGEVENT_MOUSESTOPPED:
03416             case DRAGEVENT_MOUSEMOVED:
03417             case DRAGEVENT_MOUSEIDLE:
03418                 return(TRUE);       // Claim the event so the mouse cursor changes
03419         }
03420     }
03421 
03422     // Otherwise, we aren't interested in the event, so we don't claim it
03423     return(FALSE);
03424 }
03425 
03426 
03427 
03428 /**********************************************************************************************
03429 >   OpLibGalClipTheme::OpLibGalClipTheme()
03430 
03431     Author:     Priestley (Xara Group Ltd) <camelotdev@xara.com>
03432     Created:    18/09/2000
03433     Purpose:    Constructs an OpLibGalClipTheme object.
03434 **********************************************************************************************/
03435 
03436 /*
03437     OpDescriptor constructor's arguments:-
03438 
03439                  UINT32 toolID,                         // Module Identifier
03440                  UINT32 txID,                         // String Resource ID
03441                  CCRuntimeClass* Op,                // pointer to the Op's runtime class
03442                  TCHAR* tok,                        // pointer to the token string
03443                  pfnGetState gs,                    // pointer to the GetState function
03444                  UINT32 helpId = 0,                 // help identifier 
03445                  UINT32 bubbleID = 0,                   // string resource for bubble help
03446                  UINT32 resourceID = 0,             // bitmap ("icon") or resource ID
03447                  UINT32 controlID =0,                   // control ID
03448                  BOOL ReceiveMessages = FALSE,
03449                  BOOL Smart = FALSE,
03450                  BOOL Clean = TRUE,
03451                  UINT32 OneOpenInstID = 0,          // When not 0 only one live instance
03452                                                     // of the operation is permitted, and
03453                                                     // OneOpenInstID is the string resource
03454                                                     // ID describing why.This will be useful
03455                                                     // for 1 open instance dialogs.
03456                  UINT32 AutoStateFlags = 0          // Flags which indicate conditions when
03457                                                     // the operation should automatically be
03458                                                     // greyed/ticked etc..(This cuts down the 
03459                                                     // number of tests that need to be made
03460                                                     // in the GetState function).
03461 */
03462 
03463 OpLibGalClipTheme::OpLibGalClipTheme()
03464   : OpDescriptor(0,
03465                  _R(IDS_LIBGAL_CLIPTHEME),
03466                  CC_RUNTIME_CLASS(OpLibGalClipTheme),
03467                  OPTOKEN_LIBGAL_CLIPTHEME,
03468                  OpDisplayLibClipartGallery::GetState,
03469                  0,
03470                  _R(IDBBL_LIBGAL_CLIPTHEME),
03471                  0,
03472                  _R(IDC_LIBGAL_CLIPTHEME),
03473                  TRUE)
03474 {
03475     // Empty.
03476 }
03477 
03478 
03479 
03480 
03481 /***********************************************************************************************
03482 >   virtual void OpLibGalClipTheme::OnControlCreate(OpDescControlCreateMsg* pCreateMsg)
03483 
03484     Author:     Priestley (Xara Group Ltd) <camelotdev@xara.com>
03485     Created:    18/09/2000
03486     Inputs:     pCreateMsg      ---     message describing this creation event
03487     Purpose:    Called when the combo-boxes associated with this descriptor are created.
03488 ***********************************************************************************************/
03489 
03490 void OpLibGalClipTheme::OnControlCreate(OpDescControlCreateMsg* pCreateMsg)
03491 {
03492     // Fill up the gadget's list with the names of properties.  These must be in
03493     // ascending order of property indices.
03494     pCreateMsg->pDlgOp->SetStringGadgetValue(
03495                             pCreateMsg->SetGadgetID, &String(_R(IDS_LIBGAL_CLIPTHEME_CLIPART)));
03496     pCreateMsg->pDlgOp->SetStringGadgetValue(
03497                             pCreateMsg->SetGadgetID, &String(_R(IDS_LIBGAL_CLIPTHEME_WEBTHEME)));
03498 
03499     // Resize the list to fit and update associated gadgets.
03500     pCreateMsg->pDlgOp->SetComboListLength(pCreateMsg->SetGadgetID);
03501     UpdateGadgets();
03502 }
03503 
03504 
03505 
03506 /**********************************************************************************************
03507 >   void OpLibGalClipTheme::OnSelectionChange(OpDescControlMsg* pSelChangedMsg,
03508                                                        List* pGadgetList)
03509 
03510     Author:     Priestley (Xara Group Ltd) <camelotdev@xara.com>
03511     Created:    18/09/2000
03512     Inputs:     pSelChangedMsg      ---     message describing the change event
03513                 pGadgetList         ---     list of gadgets associated with this
03514     Purpose:    Called when the combo-boxes associated with this descriptor are changed.
03515 **********************************************************************************************/
03516 
03517 void OpLibGalClipTheme::OnSelectionChange(OpDescControlMsg* pSelChangedMsg, List*)
03518 {
03519     LibClipartSGallery::Instance()->m_bRedraw = TRUE;
03520 
03521     // Extract the index of the item selected from the list, if any.
03522     INT32 i = pSelChangedMsg->pDlgOp->GetSelectedValueIndex(pSelChangedMsg->SetGadgetID);
03523     if (i == -1)
03524     {
03525         LibClipartSGallery::Instance()->m_bRedraw = FALSE;
03526         i = LibClipartSGallery::Instance()->GetClipTheme();
03527     }
03528 
03529     //Only redraw if the mode has actually been changed...
03530     if (i != LibClipartSGallery::Instance()->GetClipTheme())
03531     {
03532         // Matt - 02/01/2001 - in search of a quick fix...
03533         // Store DefaultLibraryPath information in the appropriate static...
03534         if (i == 1)
03535         {
03536             LibClipartSGallery::ClipartPath = LibClipartSGallery::DefaultLibraryPath;
03537             LibClipartSGallery::DefaultLibraryPath = LibClipartSGallery::WebThemePath;
03538         }
03539         else
03540         {
03541             LibClipartSGallery::WebThemePath = LibClipartSGallery::DefaultLibraryPath;
03542             LibClipartSGallery::DefaultLibraryPath = LibClipartSGallery::ClipartPath;
03543         }
03544 
03545         // Update the gallery's property index.
03546         LibClipartSGallery::Instance()->SetClipTheme((INT32) i);
03547         UpdateGadgets();
03548 
03549         //Now Redraw the gallery after changing between Clipart and Web Themes...
03550         if (LibClipartSGallery::Instance()->m_bRedraw)
03551         {
03552             LibClipartSGallery::Instance()->ModeHasChanged();
03553             LibClipartSGallery::Instance()->SelectionHasChanged();
03554             LibClipartSGallery::Instance()->ForceRedrawOfList();
03555         }
03556     }
03557 }
03558 
03559 
03560 /**********************************************************************************************
03561 >   void OpLibGalClipTheme::UpdateGadgets()
03562 
03563     Author:     Priestley (Xara Group Ltd) <camelotdev@xara.com>
03564     Created:    18/09/2000
03565     Purpose:    Sets the text in all the combos associated with this descriptor to the
03566                 currently selected clipart/web theme selection.
03567     SeeAlso:    OpDescriptor::BuildGadgetList
03568 **********************************************************************************************/
03569 
03570 void OpLibGalClipTheme::UpdateGadgets()
03571 {
03572     // Create a list of all the gadget IDs
03573     List theGadgets;
03574     if (BuildGadgetList(&theGadgets))
03575     {
03576         // Iterate over each control in the list.
03577         INT32 nVal = LibClipartSGallery::Instance()->GetClipTheme();
03578         for (GadgetListItem* pgli = (GadgetListItem*) theGadgets.GetHead(); 
03579              pgli != 0; 
03580              pgli = (GadgetListItem*) theGadgets.GetNext(pgli))
03581         {
03582             // Set each control to display the text.
03583             pgli->pDialogBarOp->SetSelectedValueIndex(pgli->gidGadgetID, nVal);
03584         }
03585 
03586         // Tidy up.
03587         theGadgets.DeleteAll();
03588     }
03589 } 
03590 
03591 
03592 
03593 /********************************************************************************************
03594 
03595 >   BOOL LibClipartSGallery::OnGetButtonClicked()
03596 
03597     Author:     Priestley (Xara Group Ltd) <camelotdev@xara.com> - quite blatantly ripped from Adrian - then changed a lot...
03598     Created:    19/09/2000
03599 
03600     Inputs:     None
03601     Returns:    TRUE if web folders have been added successfully
03602 
03603     Purpose:    Attempts to download the main web resource index file from our web site,
03604                 parse it and create corresponding gallery folders
03605 
03606 ********************************************************************************************/
03607 
03608 BOOL LibClipartSGallery::OnGetButtonClicked()
03609 {
03610     // Connect to the Net if not yet connected
03611     if (!InternetManager::AttemptConnection())
03612     {
03613         InformError(_R(IDS_NOTCONNECTED), _R(IDS_OK));
03614         return FALSE;
03615     }
03616 
03617     // (re)enable thumbnail downloading in case it has been stopped
03618     ResumeThumbnailDownloading();
03619     ForceRedrawOfList();
03620 
03621     if (OpAddWebFolders::Success[SGLib_ClipArt] && OpAddWebFolders::Success[SGLib_ClipArt_WebThemes] && !m_bDiscardWebFolders) // nothing else to do
03622     {
03623         //Now I've loaded ALL of the clipart and web themes... Redraw everything just in case...
03624         ModeHasChanged();
03625         SelectionHasChanged();
03626         ReformatAndRedrawIfNecessary();
03627         
03628 
03629         return TRUE;
03630     }
03631     m_bDiscardWebFolders = FALSE;
03632 
03633 
03634     //Now make a list of Clipart
03635     String_256 strIndexURL(GetStringField((UINT32) SGLib_ClipArt, _R(IDS_MAININDEXURL)));
03636 
03637     // We initiate the download of the web clipart index file to a temporary file in $WINDIR\Temporary Internet Files
03638     String_256 strTempFile;
03639     GetTempInetDir(&strTempFile);
03640     strTempFile += GetStringField((UINT32) SGLib_ClipArt, _R(IDS_TMPFILES));
03641 
03642     OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(CC_RUNTIME_CLASS(OpAddWebFolders));
03643     if (pOpDesc != NULL)
03644     {
03645         TRACEUSER( "Matt", _T("Starting Download of Clipart\n"));
03646         AddWebFoldersParam* Param = new AddWebFoldersParam;
03647         ERROR2IF(!Param, FALSE, "Memory allocation error");
03648         // Set up the op's param
03649         Param->localFile.SetPathName((TCHAR *) strTempFile); // local path of index file
03650         Param->strURL = strIndexURL; // URL of index file on our web server
03651         Param->pLibGal = this; // pointer to the gallery to add folders to
03652         Param->type = SGLib_ClipArt;
03653         // Invoke the operation - this will initiate the download of the index file
03654         // No result is returned, but the Op will report itself any error that might occur
03655         pOpDesc->Invoke((OpParam*) Param);
03656         TRACEUSER( "Matt", _T("Invoked Download of Clipart\n"));
03657     }
03658     else
03659     {
03660         ERROR3("OpAddWebFolders not found");
03661         return FALSE;
03662     }
03663 
03664     //Now make a list of Web Themes
03665     String_256 strIndexWebThemesURL(_R(IDS_CLIPART_WEBTHEMES_URL));
03666     String_256 strTempFileWebThemes;
03667     GetTempInetDir(&strTempFileWebThemes);
03668     strTempFileWebThemes += String_256(_R(IDS_CLIPART_WEBTHEMES_TEMPFILE));
03669 
03670     OpDescriptor* pOpDescWebThemes = OpDescriptor::FindOpDescriptor(CC_RUNTIME_CLASS(OpAddWebFolders));
03671     if (pOpDescWebThemes != NULL)
03672     {
03673         TRACEUSER( "Matt", _T("Starting Download of Web Themes\n"));
03674         AddWebFoldersParam* ParamWebThemes = new AddWebFoldersParam;
03675         ERROR2IF(!ParamWebThemes, FALSE, "Memory allocation error");
03676         // Set up the op's param
03677         ParamWebThemes->localFile.SetPathName((TCHAR *) strTempFileWebThemes); // local path of index file
03678         ParamWebThemes->strURL = strIndexWebThemesURL; // URL of index file on our web server
03679         ParamWebThemes->pLibGal = this; // pointer to the gallery to add folders to
03680         ParamWebThemes->type = SGLib_ClipArt_WebThemes;
03681         // Invoke the operation - this will initiate the download of the index file
03682         // No result is returned, but the Op will report itself any error that might occur
03683         pOpDescWebThemes->Invoke((OpParam*) ParamWebThemes);
03684         TRACEUSER( "Matt", _T("Invoked Download of Web Themes\n"));
03685     }
03686     else
03687     {
03688         ERROR3("OpAddWebFolders not found");
03689         return FALSE;
03690     }
03691 
03692 
03693     //All clipart and web themes now downloaded...
03694 
03695     return TRUE;
03696 }
03697 
03698 
03699 /********************************************************************************************
03700 
03701 >   BOOL LibClipartSGallery::RemoveWebFolders(SGLibType type)
03702 
03703     Author:     Priestley (Xara Group Ltd) <camelotdev@xara.com> - ripped from Adrian
03704     Created:    20/09/2000
03705 
03706     Inputs:     type - one of   SGLib_ClipArt,  SGLib_Font, SGLib_Fractal
03707     Returns:    TRUE if the folders are removed, FALSE otherwise 
03708 
03709     Purpose:    Reclaims space taken up by downloaded files of a certain type
03710                         on the local machine
03711 
03712 ********************************************************************************************/
03713 BOOL LibClipartSGallery::RemoveWebFolders(SGLibType type)
03714 {
03715     TRACEUSER( "Matt", _T("REMOVING WEB FOLDERS! in Clipart gallery\n"));
03716     if (AskQuestion(_R(IDS_WARNREMOVE), _R(IDS_EMPTY), _R(IDS_CANCEL)) == _R(IDS_CANCEL))
03717         return FALSE;
03718 
03719     String_256 strLocation;
03720     GetAppDataPath(&strLocation);
03721     strLocation += GetStringField(SGLib_ClipArt, _R(IDS_CACHEDIR));
03722 
03723     BOOL ok = true;
03724 
03725     if (_access((TCHAR*) strLocation, 0) != -1) // found it
03726     {
03727         DownloadCache::Traverse(strLocation, TRUE);
03728         DownloadCache::Refresh();
03729         SelectionHasChanged();
03730     }
03731     else
03732     {
03733         ok = FALSE;
03734     }
03735 
03736     GetAppDataPath(&strLocation);
03737     strLocation += GetStringField(SGLib_ClipArt_WebThemes, _R(IDS_CACHEDIR));
03738     if (_access((TCHAR*) strLocation, 0) != -1) // found it
03739     {
03740         DownloadCache::Traverse(strLocation, TRUE);
03741         DownloadCache::Refresh();
03742         SelectionHasChanged();
03743     }
03744     else
03745     {
03746         ok = FALSE;
03747     }
03748 
03749     return ok;
03750 }

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