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->