00001 // $Id: sglfills.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 00099 // SGLFills.cpp - LibFills SuperGallery classes 00100 00101 #include "camtypes.h" 00102 #include "sglfills.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 "sglfills.h" // This .cpp file's corresponding header 00109 #include "sglib.h" 00110 #include "sgmenu.h" 00111 //#include "thumb.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00112 #include "thumbmsg.h" 00113 00114 //#include "fillval.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00115 #include "grnddib.h" 00116 //#include "galres.h" 00117 00118 //#include "richard.h" 00119 #include "sgliboil.h" 00120 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00121 //#include "fixmem.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00122 //#include "selop.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00123 00124 //#include "attrmgr.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00125 //#include "fillattr.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00126 #include "progress.h" 00127 #include "camelot.h" 00128 00129 #include "dragmgr.h" 00130 //#include "viewrc.h" // FOR _R(IDC_CANDROPONPAGE) 00131 //#include "resource.h" // FOR _R(IDC_CANDROPONPAGE) 00132 //#include "docview.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00133 //#include "spread.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00134 #include "nodebmp.h" 00135 00136 // For LibraryGallery 00137 #include "sglbase.h" 00138 00139 //#include "sgscan.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00140 #include "sgscanf.h" 00141 00142 //#include "richard2.h" 00143 #include "keypress.h" 00144 #include "backgrnd.h" // OpBackground 00145 #include <io.h> 00146 #include "inetop.h" 00147 #include "helpuser.h" 00148 //#include "xshelpid.h" 00149 //#include "helppath.h" 00150 #include "resdll.h" 00151 00152 00153 // Implement the dynamic class bits... 00154 CC_IMPLEMENT_DYNCREATE(LibFillsSGallery, LibraryGallery) 00155 CC_IMPLEMENT_DYNCREATE(OpDisplayLibFillsGallery, Operation) 00156 CC_IMPLEMENT_DYNCREATE(SGFillsItem, SGLibDisplayItem) 00157 00158 CC_IMPLEMENT_DYNCREATE(GalleryFillsDragInfo, BitmapDragInformation) 00159 CC_IMPLEMENT_DYNAMIC(SGFillsDragTarget, SGListDragTarget) 00160 00161 // This line mustn't go before any CC_IMPLEMENT_... macros 00162 #define new CAM_DEBUG_NEW 00163 00164 using namespace InetUtils; 00165 00166 // Static variables 00167 #ifdef _DEBUG 00168 //String_256 LibFillsSGallery::DefaultLibraryPath = TEXT("\\\\deepthought\\camelotcd\\cd\\fills"); 00169 //String_256 LibFillsSGallery::DefaultLibraryPath = TEXT("\\\\jimpc\\corelxra\\fills"); 00170 String_256 LibFillsSGallery::DefaultLibraryPath = TEXT("D:\\fills"); 00171 #else 00172 String_256 LibFillsSGallery::DefaultLibraryPath = TEXT("D:\\fills"); 00173 #endif 00174 00175 // display mode setting for ini file 00176 INT32 LibFillsSGallery::DefaultDisplayMode = 0; 00177 00178 // For keeping the sort keys constant when next loaded (default == sort alphabetically) 00179 // 1st sort key = DefaultSortKeys & 0x8f 00180 // 2nd sort key = ((DefaultSortKeys>>8) & 0x8f) 00181 // 1st sort key reversed = ((DefaultSortKeys>>7) & 0x01)==1 00182 // 2nd sort key reversed = ((DefaultSortKeys>>15) & 0x01)==1 00183 // So 0 means no sorting at all 00184 // and 1 means sort the gallery alphabetically 00185 UINT32 LibFillsSGallery::DefaultSortKeys = 1; 00186 00187 // Pointer to the gallery itself... 00188 LibFillsSGallery *LibFillsSGallery::ThisGallery = NULL; 00189 00190 // Quiet status of gallery 00191 BOOL LibFillsSGallery::QuietStatus = FALSE; 00192 00193 /******************************************************************************************** 00194 00195 > LibFillsSGallery::LibFillsSGallery() 00196 00197 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00198 Created: 23/3/95 00199 Purpose: LibFillsSGallery default constructor 00200 00201 ********************************************************************************************/ 00202 00203 LibFillsSGallery::LibFillsSGallery() 00204 { 00205 LibFillsSGallery::ThisGallery = this; 00206 00207 // Default gallery size 00208 CSize Size(((333 * 2) - 32) - 32, 256); 00209 SetGallerySize(Size); 00210 } 00211 00212 00213 00214 /******************************************************************************************** 00215 00216 > LibFillsSGallery::~LibFillsSGallery() 00217 00218 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00219 Created: 23/3/95 00220 Purpose: LibFillsSGallery destructor. 00221 00222 ********************************************************************************************/ 00223 00224 LibFillsSGallery::~LibFillsSGallery() 00225 { 00226 OpenLibFiles.DeleteAll(); // Ensure all open libraries are closed 00227 LibFillsSGallery::ThisGallery = NULL; 00228 } 00229 00230 00231 00232 /******************************************************************************************** 00233 00234 > static BOOL LibFillsSGallery::Init(void) 00235 00236 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00237 Created: 23/3/95 00238 Returns: TRUE if the sgallery initialised successfully 00239 FALSE if it failed to initialise 00240 Purpose: 00241 00242 ********************************************************************************************/ 00243 00244 BOOL LibFillsSGallery::Init(void) 00245 { 00246 return(TRUE); 00247 } 00248 00249 00250 00251 /******************************************************************************************** 00252 00253 > BOOL LibFillsSGallery::PreCreate(void) 00254 00255 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00256 Created: 23/3/95 00257 Returns: TRUE if the Gallery initialised successfully 00258 FALSE if it should not be opened due to a failure to initialise 00259 00260 Purpose: The LibFillsSGallery PreCreate handler. This overrides the base class 00261 PreCreate function. It is called at the very beginning of the 00262 SuperGallery::Create method, before the window has been created. 00263 00264 Notes: As this is called before the window is open, it must not attempt to touch 00265 any of the button gadgets in the window, or force redraws, etc. Also, 00266 events cannot be passed to the tree, as the tree formatting relies on 00267 knowing the window size - however, the tree will be reformatted and 00268 redrawn automatically when the window is opened - this will happen shortly. 00269 00270 ********************************************************************************************/ 00271 00272 BOOL LibFillsSGallery::PreCreate(void) 00273 { 00274 // If there isn't already one, create a DisplayTree 00275 if (DisplayTree == NULL) 00276 { 00277 DisplayTree = new SGDisplayRootScroll(this); // New root node, with a scrollbar 00278 if (DisplayTree == NULL) 00279 return(FALSE); 00280 } 00281 00282 // Add the library groups to the gallery if they're not there already 00283 if(OpenLibFiles.IsEmpty()) 00284 { 00285 String_256 sLoc = DefaultLibraryPath; 00286 // Set DefaultLibraryPath to <ExeLocation>\Fills - the user might have installed 00287 // the fills to his hard disk: 00288 if(CResDll::GetExecutablePath((TCHAR*)DefaultLibraryPath)) 00289 { 00290 // Look for the resources in the main Xara X folder first 00291 String_256 LibDirName; 00292 GetLibraryDirectoryName(&LibDirName); 00293 DefaultLibraryPath += "\\"; 00294 DefaultLibraryPath += LibDirName; 00295 PathName ThisPath(DefaultLibraryPath); 00296 if(!SGLibOil::FileExists(&ThisPath)) // will also work for paths (not just paths with a filename on the end) 00297 { 00298 // Fills not on hard disk. Try the CD location 00299 if(!ScanForLocation(SGLib_Texture, NULL)) 00300 { 00301 // hard drive and CD location not found 00302 // put the original path back 00303 DefaultLibraryPath = sLoc; 00304 } 00305 } 00306 } 00307 00308 LibraryGallery::AddLibraryGroups(SGLib_Texture, &DefaultLibraryPath); 00309 } 00310 00311 // Use last time's display mode 00312 DisplayMode = LibFillsSGallery::DefaultDisplayMode; 00313 00314 return TRUE; 00315 } 00316 00317 /******************************************************************************************** 00318 00319 > void LibFillsSGallery::SortGallery(void) 00320 00321 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00322 Created: 2/5/95 00323 00324 Inputs: 00325 Returns: 00326 00327 Purpose: Sorts the contents of the gallery in an alphabetical fashion, whilst keeping 00328 the old sort key status... 00329 Notes: 00330 SeeAlso: 00331 00332 ********************************************************************************************/ 00333 00334 void LibFillsSGallery::SortGallery(void) 00335 { 00336 LibraryGallery::SortGallery(); 00337 } 00338 00339 /******************************************************************************************** 00340 00341 > BOOL LibFillsSGallery::BrowseClicked(void) 00342 00343 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00344 Created: 2/5/95 00345 00346 Inputs: 00347 Returns: TRUE if the gallery has new stuff in it (FALSE if cancel clicked, etc)... 00348 00349 Purpose: Pops up the browse box and lets a new location be set for the data 00350 00351 ********************************************************************************************/ 00352 00353 BOOL LibFillsSGallery::BrowseClicked(void) 00354 { 00355 return (LibraryGallery::BrowseClicked(&DefaultLibraryPath, SGLib_Texture, _R(IDS_REMOVE_OLD_GOUPS_FILLS))); 00356 } 00357 00358 /******************************************************************************************** 00359 00360 > virtual BOOL LibFillsSGallery::CanCreateIndexes(void) 00361 00362 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00363 Created: 18/12/95 00364 00365 Returns: TRUE to if index generation is possible 00366 00367 Purpose: To determine if this gallery can generate indexes or not 00368 00369 ********************************************************************************************/ 00370 00371 BOOL LibFillsSGallery::CanCreateIndexes(void) 00372 { 00373 return TRUE; 00374 } 00375 00376 /******************************************************************************************** 00377 00378 > virtual BOOL LibFillsSGallery::GetDefaults(String_256 *DefaultIndex, String_256 *IndexDesc, SGLibType *Type) 00379 00380 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00381 Created: 18/12/95 00382 00383 Outputs: DefaultIndex - The filename for the default index file (Xaraclip.txt) 00384 IndexDesc - Description of the index / gallery (Clipart) 00385 Type - Default library type associated with this gallery 00386 00387 Returns: TRUE if this was overridden successfully 00388 00389 Purpose: To determine various library gallery default properties 00390 00391 ********************************************************************************************/ 00392 00393 BOOL LibFillsSGallery::GetDefaults(String_256 *DefaultIndex, String_256 *IndexDesc, SGLibType *Type) 00394 { 00395 if(DefaultIndex != NULL) 00396 *DefaultIndex = _R(IDS_LIBRARIES_FILLS_FILENAME); // "XaraText.txt"; 00397 00398 if(IndexDesc != NULL) 00399 *IndexDesc = _R(IDS_LIBRARIES_FILLS_DESC); // "Fills"; 00400 00401 if(Type != NULL) 00402 *Type = SGLib_Texture; 00403 00404 return TRUE; 00405 } 00406 00407 00408 /******************************************************************************************** 00409 00410 > virtual BOOL LibFillsSGallery::GetLibraryDirectoryName(String_256 *LibDirName) 00411 00412 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00413 Created: 19/12/95 00414 00415 Outputs: LibDirName - Returns the Default directory (on the clipart CD) for the gallery 00416 Returns: TRUE if overridden and directory obtained... 00417 00418 Purpose: Get the default CD directory name for the gallery 00419 00420 ********************************************************************************************/ 00421 00422 BOOL LibFillsSGallery::GetLibraryDirectoryName(String_256 *LibDirName) 00423 { 00424 LibDirName->MakeMsg(_R(IDS_LIBRARIES_FILLS_DIRNAME)); 00425 return TRUE; 00426 } 00427 00428 /******************************************************************************************** 00429 00430 > virtual BOOL LibFillsSGallery::GetQuietStatus(void) 00431 00432 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00433 Created: 19/12/95 00434 Returns: TRUE if Quiet has been pressed (SetQuiet status called with TRUE) 00435 Purpose: Get the Quiet status of the gallery 00436 00437 ********************************************************************************************/ 00438 00439 BOOL LibFillsSGallery::GetQuietStatus(void) 00440 { 00441 return LibFillsSGallery::QuietStatus; 00442 } 00443 00444 /******************************************************************************************** 00445 00446 > virtual void LibFillsSGallery::SetQuietStatus(BOOL Status) 00447 00448 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00449 Created: 19/12/95 00450 Inputs: Status - Set to TRUE and call if Quiet has just been pressed on an 'adding 00451 indexes' dialog 00452 Purpose: Set the Quiet status of the gallery 00453 00454 ********************************************************************************************/ 00455 00456 void LibFillsSGallery::SetQuietStatus(BOOL Status) 00457 { 00458 LibFillsSGallery::QuietStatus = Status; 00459 } 00460 00461 /*********************************************************************************************** 00462 00463 > virtual BOOL LibFillsSGallery::ScanForLocation(SGLibType Type, StringBase *Result = NULL); 00464 00465 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00466 Created: 19/12/95 00467 00468 Inputs: Type of library to scan for 00469 Outputs: (We assume the library static strings exist and use them - bit yucky) 00470 If a Result pointer if given then we copy this into there as well.. 00471 Returns: FALSE if it fails; TRUE if we got a path 00472 00473 Purpose: Searches all the drives for a CDROM drive. If it finds the Camelot CD 00474 mount here at Xara HQ, we point to that instead. 00475 Notes: 00476 00477 ***********************************************************************************************/ 00478 00479 BOOL LibFillsSGallery::ScanForLocation(SGLibType Type, StringBase *Result) 00480 { 00481 #ifndef STANDALONE 00482 // Search for a CD ROM drive 00483 String_256 DriveName; 00484 BOOL AreWeXara = FALSE; 00485 String_256 XaraDrive; 00486 00487 BOOL Adjust = KeyPress::IsAdjustPressed(); 00488 #ifndef _DEBUG 00489 Adjust = FALSE; 00490 #endif 00491 00492 if(SGLibOil::LocateCDROMDrive(this, Type, &DriveName, &AreWeXara, &XaraDrive, Adjust)) 00493 { 00494 if(AreWeXara) 00495 DriveName = XaraDrive; 00496 00497 switch(Type) 00498 { 00499 case SGLib_Texture: 00500 case SGLib_Fractal: 00501 LibFillsSGallery::DefaultLibraryPath = DriveName; 00502 #ifdef _DEBUG 00503 if(Adjust) 00504 { 00505 LibFillsSGallery::DefaultLibraryPath += TEXT("Graphics\\Fills"); 00506 } 00507 else 00508 #endif 00509 { 00510 String_256 LibDirName; 00511 GetLibraryDirectoryName(&LibDirName); 00512 LibFillsSGallery::DefaultLibraryPath += LibDirName; 00513 } 00514 00515 if(Result) 00516 *Result = LibFillsSGallery::DefaultLibraryPath; 00517 00518 return TRUE; 00519 } 00520 } 00521 #endif 00522 return FALSE; 00523 } 00524 00525 00526 /******************************************************************************************** 00527 00528 > virtual BOOL LibFillsSGallery::CheckForIndexMatch(StringBase *Txt) 00529 00530 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00531 Created: 18/12/95 00532 00533 Inputs: Kind - Last column entry in the index.txt file (" T") 00534 Returns: TRUE if this signifies the gallery in question... 00535 00536 Purpose: To see whether we should add this line of the index.txt file to this gallery 00537 00538 ********************************************************************************************/ 00539 00540 BOOL LibFillsSGallery::CheckForIndexMatch(StringBase *Txt) 00541 { 00542 BOOL Match = FALSE; 00543 00544 // Textures (fills) 00545 if(((Txt->Sub(String_8("T"))!=-1) || (Txt->Sub(String_8("t"))!=-1)) ) Match = TRUE; 00546 00547 return Match; 00548 } 00549 00550 00551 /******************************************************************************************** 00552 00553 > virtual BOOL LibFillsSGallery::ApplyAction(SGActionType Action) 00554 00555 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00556 Created: 23/3/95 00557 00558 Inputs: Action - Indicates what action to apply 00559 00560 Returns: TRUE to indicate successful handling of the action, or 00561 FALSE to indicate failure 00562 00563 Purpose: Applies certain conventional gallery actions (usually associated with 00564 gallery buttons, for new, edit, delete, etc) 00565 00566 SeeAlso: SGActionType 00567 00568 ********************************************************************************************/ 00569 00570 BOOL LibFillsSGallery::ApplyAction(SGActionType Action) 00571 { 00572 // No display tree? Better forget about it then! 00573 if (DisplayTree == NULL) 00574 return(FALSE); 00575 00576 // Now, process the action TO DO! - see Colour gallery for examples 00577 switch(Action) 00578 { 00579 case SGACTION_APPLYADJUST: 00580 // Drop through to SGACTION_APPLY handler 00581 00582 case SGACTION_APPLY: 00583 // Import the current selection and apply it as a fill 00584 if(Document::GetSelected() == NULL) 00585 return FALSE; 00586 00587 if(!FillUsingFillGallerySelection(ApplyToObject)) 00588 return FALSE; 00589 00590 break; 00591 00592 case SGACTION_SETOPTIONS: // Set values in the options dialogue as it is opened 00593 { 00594 if (CurrentOptionsDlg == NULL) 00595 return(FALSE); 00596 00597 CurrentOptionsDlg->AddDisplayModeName(_R(IDS_GALLERYDM_LARGE)); // 0 00598 CurrentOptionsDlg->AddDisplayModeName(_R(IDS_GALLERYDM_FULLINFO)); // 1 00599 CurrentOptionsDlg->AddDisplayModeName(_R(IDS_GALLERYDM_SMALL)); // 2 00600 } 00601 break; 00602 00603 case SGACTION_SETSORTMODE: 00604 { 00605 if (CurrentSortDlg == NULL) 00606 return(FALSE); 00607 00608 CurrentSortDlg->AddSortKeyName(_R(IDS_SORTBY_NAME)); 00609 CurrentSortDlg->AddSortKeyName(_R(IDS_SORTBY_MEMORY)); 00610 CurrentSortDlg->AddSortKeyName(_R(IDS_SORTBY_NAMELENGTH)); 00611 CurrentSortDlg->AddSortKeyName(_R(IDS_SORTBY_FILETYPE)); 00612 } 00613 break; 00614 00615 00616 case SGACTION_DISPLAYMODECHANGED: 00617 if(DisplayMode >= 3) DisplayMode = 0; 00618 DefaultDisplayMode = DisplayMode; 00619 InvalidateCachedFormat(); 00620 ReformatAndRedrawIfNecessary(); 00621 break; 00622 00623 default: 00624 return(SuperGallery::ApplyAction(Action)); 00625 break; 00626 } 00627 00628 return(TRUE); 00629 } 00630 00631 00632 00633 /******************************************************************************************** 00634 00635 > virtual MsgResult LibFillsSGallery::Message(Msg* Message) 00636 00637 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00638 Created: 23/3/95 00639 Inputs: Message - The message to handle 00640 00641 Purpose: A standard message handler, really. 00642 00643 Notes: Any messages that this does not handle must be passed down to the 00644 SuperGallery base class message handler. 00645 00646 NOTE WELL that the SuperGallery base class handler does some funky things 00647 for us - see SuperGallery::Message - such as deleting our display subtree 00648 for any document which dies (which, uncannily, would explain why they go 00649 away like that when you close documents ;-), and shading the gallery when 00650 there are no documents present. [To override this behaviour in these cases, 00651 you should respond to the message, and return OK rather than calling the 00652 base class message handler] 00653 00654 SeeAlso: SuperGallery::Message 00655 00656 ********************************************************************************************/ 00657 00658 MsgResult LibFillsSGallery::Message(Msg* Message) 00659 { 00660 // Added by Craig Hamilton 18/1/01. 00661 static HANDLE handle = NULL; 00662 CString mutexName = "autorunMutex"; 00663 // End added. 00664 00665 // If we have no displaytree, then we have not been shown, or something terrible has 00666 // happened, so we don't bother handling any of these messages. 00667 if (DisplayTree == NULL) 00668 return(LibraryGallery::Message(Message)); 00669 00670 KernelBitmap *SelectedBitmap = NULL; 00671 00672 if (IS_OUR_DIALOG_MSG(Message)) 00673 { 00674 DialogMsg* Msg = (DialogMsg*)Message; 00675 00676 switch (Msg->DlgMsg) 00677 { 00678 case DIM_CREATE: 00679 // Added by Craig Hamilton 18/1/01. 00680 // This and the section of code of the same date in the DIM_CANCEL handler below 00681 // deal with the creation and destruction of a kernel object that is recognised by 00682 // the autorun. If this object exists then the autorun does not run. This is so 00683 // that the user can enter their resources cd while the gallery is open and not be 00684 // annoyed by the autorun appearing. 00685 handle = CreateMutex(NULL,TRUE,mutexName); 00686 // End added. 00687 00688 SGInit::UpdateGalleryButton(OPTOKEN_DISPLAYFILLSGALLERY, TRUE); 00689 LibFillsSGallery::ThisGallery->GalleryAboutToReOpen(); 00690 break; 00691 00692 case DIM_CANCEL: 00693 // Added by Craig Hamilton 18/1/01. 00694 if(handle != NULL) 00695 { 00696 CloseHandle(handle); 00697 } 00698 // End added. 00699 00700 SGInit::UpdateGalleryButton(OPTOKEN_DISPLAYFILLSGALLERY, FALSE); 00701 00702 // Flush the thumbnail cache 00703 BROADCAST_TO_CLASS(ThumbMessage(ThumbMessage::ThumbState::KILLCACHE, SGLib_Texture), DialogOp); 00704 BROADCAST_TO_CLASS(ThumbMessage(ThumbMessage::ThumbState::KILLCACHE, SGLib_Fractal), DialogOp); 00705 GalleryAboutToClose(); 00706 break; 00707 00708 case DIM_LFT_BN_CLICKED: 00709 switch (Msg->GadgetID) 00710 { 00711 case _R(IDC_LIBGAL_OPEN): 00712 if(Document::GetSelected() != NULL) 00713 FillUsingFillGallerySelection(AddToPage); 00714 break; 00715 00716 case _R(IDC_LIBGAL_IMPORT): 00717 FillUsingFillGallerySelection(AddToPage); 00718 break; 00719 00720 case _R(IDC_LIBGAL_BROWSE): 00721 case _R(IDC_LIBGAL_ADD_FILLS): 00722 BrowseClicked(); 00723 break; 00724 00725 case _R(IDC_BMPGAL_FILL): 00726 if(!FillUsingFillGallerySelection(ApplyToObject)) 00727 { 00728 return(SuperGallery::Message(Message)); 00729 } 00730 break; 00731 00732 case _R(IDC_BMPGAL_TEXTURE): 00733 if(Document::GetSelected() != NULL) 00734 if(!FillUsingFillGallerySelection(ApplyToObjectAsTransp)) 00735 { 00736 return(SuperGallery::Message(Message)); 00737 } 00738 break; 00739 00740 case _R(IDC_BMPGAL_BACKGROUND): 00741 if(Document::GetSelected() != NULL) 00742 if(!FillUsingFillGallerySelection(SetBackground)) 00743 { 00744 return(SuperGallery::Message(Message)); 00745 } 00746 break; 00747 00748 case _R(IDC_BMPGAL_SAVE): 00749 #ifdef _DEBUG 00750 { 00751 SGDisplayNode *Item = DisplayTree->FindNextSelectedItem(NULL); 00752 if(Item != NULL && Item->IsKindOf(CC_RUNTIME_CLASS(SGLibDisplayItem))) 00753 { 00754 SGLibDisplayItem *LibItem = (SGLibDisplayItem *)Item; 00755 00756 Library *Parent = LibItem->GetParentLibrary(); 00757 if(Parent != NULL) 00758 { 00759 PathName *Source = Parent->ReturnIndexLocation(); 00760 PathName Dest(*Source); 00761 Dest.SetType((String_256)"BAK"); 00762 SGLibOil::FileCopy(Source, &Dest); 00763 00764 Parent->SaveIndexInDisplayedOrder(Source, TRUE); 00765 } 00766 } 00767 } 00768 #endif 00769 break; 00770 00771 case _R(IDC_GALLERY_HELP): // Show help page 00772 HelpUserTopic(_R(IDS_HELPPATH_Gallery_Fill)); 00773 break; 00774 00775 00776 00777 default: 00778 break; 00779 } 00780 } 00781 } 00782 else if (MESSAGE_IS_A(Message, DocChangingMsg)) 00783 { 00784 DocChangingMsg *Msg = (DocChangingMsg *) Message; 00785 switch (Msg->State) 00786 { 00787 case DocChangingMsg::DocState::SELCHANGED: 00788 if (Msg->pNewDoc == NULL) 00789 { 00790 // There is no selected doc - this can only mean there are no docs 00791 // at all, so we had better shade the gallery 00792 DoShadeGallery(TRUE); 00793 SuperGallery::ShadeGallery(TRUE); 00794 } 00795 else 00796 { 00797 // Possibly a new document 00798 DoShadeGallery(FALSE); 00799 SuperGallery::ShadeGallery(FALSE); 00800 SelectionHasChanged(); 00801 } 00802 break; 00803 } 00804 } 00805 else if (MESSAGE_IS_A(Message, ThumbMessage) && DisplayTree != NULL) 00806 { 00807 ThumbMessage *Msg = (ThumbMessage *) Message; 00808 00809 // If a library Thumb message comes around, flush the redraw stuff, etc 00810 if(Msg->State == ThumbMessage::ThumbState::CACHESIZECHANGED) 00811 { 00812 FlushBackgroundRedraws(); 00813 ForceRedrawOfList(); 00814 } 00815 } 00816 00817 return(LibraryGallery::Message(Message)); 00818 } 00819 00820 00821 /******************************************************************************************** 00822 00823 > void LibFillsSGallery::SelectionHasChanged(void) 00824 00825 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> (based on Jason code) 00826 Created: 28/3/95 00827 00828 Purpose: To inform the gallery that the selection has changed in some way. 00829 We need to grey different buttons on different occasions 00830 Notes: 00831 00832 ********************************************************************************************/ 00833 00834 void LibFillsSGallery::SelectionHasChanged(void) 00835 { 00836 if (DisplayTree == NULL) 00837 return; 00838 00839 // As we now allow the gallery to be closed and all the groups to remain, we must now 00840 // also check to see if the gallery is visible i.e. open or not. If not then get out now. 00841 // Required as SetStringGadgetValue will ERROR and memory leak if called when dialog closed. 00842 if (!IsVisible()) 00843 return; 00844 00845 INT32 Count = DisplayTree->GetSelectedItemCount(); 00846 BOOL Documents = (Document::GetSelected() != NULL); 00847 00848 // Set up button states 00849 00850 // Enable the import button if there is a selection and valid documents 00851 EnableGadget(_R(IDC_LIBGAL_IMPORT), (Count > 0) && Documents); 00852 00853 String_256 strCommand, strDummy; 00854 00855 BOOL bEnable = Count == 1 && Documents; 00856 00857 // Import button 00858 strCommand = SGCmd_Import; 00859 EnableGadget(_R(IDC_LIBGAL_IMPORT), bEnable && !((GetCommandState(&strCommand, &strDummy)).Greyed)); 00860 00861 // Fill button 00862 strCommand = SGCmd_Fill; 00863 EnableGadget(_R(IDC_BMPGAL_FILL), bEnable && !((GetCommandState(&strCommand, &strDummy)).Greyed)); 00864 00865 // Transp button 00866 strCommand = SGCmd_Transp; 00867 EnableGadget(_R(IDC_BMPGAL_TEXTURE), bEnable && !((GetCommandState(&strCommand, &strDummy)).Greyed)); 00868 00869 // Background button 00870 strCommand = SGCmd_SetBackground; 00871 EnableGadget(_R(IDC_BMPGAL_BACKGROUND), bEnable && !((GetCommandState(&strCommand, &strDummy)).Greyed)); 00872 00873 EnableGadget(_R(IDC_LIBGAL_ADD_FILLS), TRUE); 00874 00875 LibraryGallery::SelectionHasChanged(); 00876 } 00877 00878 /******************************************************************************************** 00879 00880 > void LibFillsSGallery::DoShadeGallery(BOOL ShadeIt) 00881 00882 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> (based on Jason code) 00883 Created: 28/3/95 00884 00885 Purpose: To un-grey the options... button when there are no docs 00886 Notes: 00887 00888 ********************************************************************************************/ 00889 00890 void LibFillsSGallery::DoShadeGallery(BOOL ShadeIt) 00891 { 00892 if (DisplayTree == NULL) 00893 return; 00894 00895 // Keep this here always 00896 EnableGadget(_R(IDC_GALLERY_MENU), TRUE); 00897 00898 EnableGadget(_R(IDC_LIBGAL_IMPORT), !ShadeIt); 00899 EnableGadget(_R(IDC_BMPGAL_FILL), !ShadeIt); 00900 EnableGadget(_R(IDC_BMPGAL_TEXTURE), !ShadeIt); 00901 00902 EnableGadget(_R(IDC_BMPGAL_BACKGROUND), !ShadeIt); 00903 00904 EnableGadget(_R(IDC_LIBGAL_ADD_FILLS), TRUE); 00905 00906 LibraryGallery::DoShadeGallery(ShadeIt); 00907 } 00908 00909 /******************************************************************************************** 00910 00911 > BOOL LibFillsSGallery::FillUsingFillGallerySelection(FillTypeEnum FillType) 00912 00913 Author: Jonathan_Payne (Xara Group Ltd) <camelotdev@xara.com> 00914 Created: 20/9/2000 00915 Inputs: FillType - The type of fill required (see def. of FillTypeEnum) 00916 Returns: TRUE if things went OK, false otherwise 00917 Purpose: To import a fill into camelot, then apply it in the mannor selected 00918 SeeAlso: OnPageDrop 00919 00920 ********************************************************************************************/ 00921 00922 bool LibFillsSGallery::FillUsingFillGallerySelection(FillTypeEnum FillType) 00923 { 00924 PathName FileName; 00925 00926 UINT32 TagObjectToFill = 0; // used for ApplyToObject and ApplyToObjectAsTransp 00927 // when downloading a fill 00928 00929 if (GetSelectedItemCount() != 1 && FillType != AddToPage) 00930 { 00931 TRACEUSER( "Jonathan", _T("Fills: FillUsingGallerySelection failing due to multiple selection\n")); 00932 return false; 00933 } 00934 00935 SGLibDisplayItem *FillItem = static_cast<SGLibDisplayItem *>(DisplayTree->FindNextSelectedItem()); 00936 00937 if (!FillItem->GetFileName(&FileName)) 00938 return false; 00939 00940 if (!FileName.IsValid(FileName.GetPath())) 00941 { 00942 ERROR3("Filename is invalid"); 00943 return false; 00944 } 00945 00946 bool NeedToDownload; 00947 if (_taccess(FileName.GetPath(), 0) == -1) 00948 NeedToDownload = true; 00949 else 00950 NeedToDownload = false; 00951 00952 if (FillType == ApplyToObject || FillType == ApplyToObjectAsTransp) 00953 { 00954 SelRange* Sel = GetApplication()->FindSelection(); 00955 if (Sel==0) 00956 { 00957 ERROR3("Can't find SelRange!"); 00958 return false; 00959 } 00960 if (NeedToDownload) 00961 { 00962 Node *NodeToFill = Sel->FindFirst(); 00963 if (Sel->FindNext(NodeToFill) != 0) 00964 { 00965 // If mulitple objects are selected, saving the tag of just one object is not 00966 // going to do much good so for now we just give up in this case 00967 InformError(_R(IDE_SGLFILLS_NOMULTI_DL_FILL)); 00968 return false; 00969 } 00970 if (NodeToFill) 00971 TagObjectToFill = NodeToFill->GetTag(); 00972 else 00973 { 00974 // No node selected. This means the user has pressed fill from the gallery 00975 // with no selection, intending to set the default fill of the document. To 00976 // do this we set TagObjectToFill to zero which results in TagObjectValid not 00977 // being set. We do not have to use this logic in the case where the fill is 00978 // already downloaded as the ApplyFill(...) stuff just uses the current selection 00979 // (or the lack of current selection). 00980 TagObjectToFill = 0; 00981 } 00982 } 00983 } 00984 // Calculate where to put an imported object 00985 DocCoord DropPos; 00986 DocRect PageRect; 00987 Spread *s; 00988 if ((s = Document::GetSelectedSpread()) != 0) 00989 { 00990 if (s->GetPagesRect(&PageRect)) 00991 DropPos = PageRect.Centre(); 00992 else 00993 return false; 00994 } 00995 else 00996 return false; 00997 00998 if (!NeedToDownload) 00999 // Don't need to download the fill 01000 { 01001 TRACEUSER( "Jonathan", _T("Fills: File in cache\n")); 01002 OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(CC_RUNTIME_CLASS(OpBitmapImport)); 01003 01004 if (pOpDesc != 0) 01005 { 01006 BitmapImportParam Param; 01007 01008 Param.File = &FileName; 01009 Param.Result = TRUE; 01010 Param.pTargetDoc = Document::GetSelected(); 01011 Param.FillType = FillType; 01012 Param.pSpread = Document::GetSelectedSpread(); 01013 Param.DropPos = DropPos; 01014 Param.TagObjectValid = false; 01015 Param.pObjectValid = false; 01016 01017 // Do it... 01018 pOpDesc->Invoke((OpParam *) &Param); 01019 01020 if (!Param.Result) 01021 { 01022 ERROR3("Problem importing file from cache"); 01023 return false; 01024 } 01025 } 01026 } 01027 else 01028 // Need to download the fill 01029 { 01030 TRACEUSER( "Jonathan", _T("Fills: File not in cache : downloading\n")); 01031 OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(CC_RUNTIME_CLASS(OpAsynchBitmapImport)); 01032 01033 if (pOpDesc != 0) 01034 { 01035 AsynchBitmapImportParam* Param = new AsynchBitmapImportParam; 01036 01037 if (!Param) 01038 return false; 01039 Library* pLibrary = FillItem->GetParentLibrary(); 01040 String_256 strFileURL = FileName.GetPath(); 01041 pLibrary->LocalPath2URL(&strFileURL); 01042 Param->file = FileName; 01043 Param->pTargetDoc = Document::GetSelected(); 01044 Param->strURL = strFileURL; 01045 String_256 strDescription; 01046 FillItem->GetNameText(&strDescription); 01047 Param->strDescription = _T("'"); 01048 Param->strDescription += strDescription; 01049 Param->strDescription += _T("'"); 01050 Param->type = TYPE_FILL; 01051 Param->FillType = FillType; 01052 Param->priority = AsynchDownload::PRIORITY_HIGH; 01053 Param->pSpread = Document::GetSelectedSpread(); 01054 Param->DropPos = DropPos; 01055 Param->TagObjectToFill = TagObjectToFill; 01056 Param->pObjectValid = false; 01057 // If TagObjectToFill == 0, don't set pObjectValid or TagObjectValid so 01058 // ApplyFill(...) just applies the fill to nothing (except if the user has 01059 // changed the selection during the download, in which case that object will 01060 // get filled - bit bad, but that is a very rare case). 01061 if (TagObjectToFill) 01062 Param->TagObjectValid = true; 01063 else 01064 Param->TagObjectValid = false; 01065 01066 // Do it... 01067 pOpDesc->Invoke((OpParam *) Param); 01068 } 01069 } 01070 return true; 01071 } 01072 01073 01074 /******************************************************************************************** 01075 01076 > virtual SGDisplayItem *LibFillsSGallery::AddLibraryItem(SGDisplayGroup *LibraryGroup, 01077 Library *ParentLib, 01078 LibraryIndex ItemIndex) 01079 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 01080 Created: 23/3/95 01081 01082 Inputs: LibraryGroup - The group to add the item into 01083 ParentLib - (For cross checking inputs) the library you allege the above 01084 group is for. 01085 ItemIndex - The Library generated index for this item 01086 01087 Returns: NULL, or a pointer to the created item 01088 01089 Purpose: Called by the Library class to create a display item for every item in 01090 a newly-scanned library file. It is essentially a callback to the gallery 01091 which requested that the library be scanned. 01092 01093 Notes: This method MUST BE OVERRIDDEN by the derived gallery that opens the library, 01094 in order to create appropriate SGDisplayItem-derived nodes for the things 01095 in the library (e.g. a Fills library gallery will have to create items 01096 that display Fills thumbnails) 01097 01098 SeeAlso: SuperGallery::AddLibraryGroup; SuperGallery::RemoveLibraryGroup 01099 01100 ********************************************************************************************/ 01101 01102 SGDisplayItem *LibFillsSGallery::AddLibraryItem(SGDisplayGroup *LibraryGroup, 01103 Library *ParentLib, 01104 LibraryIndex ItemIndex, BOOL bNew) 01105 { 01106 ERROR3IF(LibraryGroup == NULL || ParentLib == NULL, 01107 "LibFillsSGallery::AddLibraryItem - NULL params are illegal"); 01108 01109 ERROR3IF(LibraryGroup->GetParentLibrary() != ParentLib, 01110 "LibFillsSGallery::AddLibraryitem - The DisplayGroup is not for the same library!"); 01111 01112 // Create a Fills library item 01113 SGFillsItem *NewItem = new SGFillsItem(ItemIndex, bNew); 01114 01115 // Alphabetic add... 01116 /* SGSortKey SortKeys[MaxSGSortKeys]; 01117 for (INT32 i = 0; i < MaxSGSortKeys; i++) 01118 { 01119 SortKeys[i].SortKey = 0; 01120 SortKeys[i].Reversed = FALSE; 01121 } 01122 01123 SortKeys[0].SortKey = 1;*/ 01124 01125 if (NewItem != NULL) 01126 LibraryGroup->AddItem(NewItem/*, (SGSortKey *)SortKeys*/); 01127 01128 return(NewItem); 01129 } 01130 01131 01132 /******************************************************************************************** 01133 01134 > virtual BOOL LibFillsSGallery::CanSearchKeywords(void) 01135 01136 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 01137 Created: 30/3/95 01138 01139 Returns: TRUE 01140 01141 Purpose: Used to determine if this type of gallery supports keyword searching. 01142 This one does 01143 01144 ********************************************************************************************/ 01145 01146 BOOL LibFillsSGallery::CanSearchKeywords(void) 01147 { 01148 return(TRUE); 01149 } 01150 01151 01152 /******************************************************************************************** 01153 01154 > virtual void LibFillsSGallery::HandleDragStart(DragMessage *DragMsg) 01155 01156 Author: Will_Cowling (Xara Group Ltd) <camelotdev@xara.com> 01157 Created: 25/3/95 01158 01159 Inputs: DragMsg - The DRAGSTARTED message that we've just recieved, indicating 01160 the type of drag being started 01161 01162 Purpose: Checks a DragMessage to see if it is a colour drag. 01163 If it is, then it creates a drag target for this gallerys listbox. 01164 01165 Notes: Overrides the default base-class action. Calls down to the base class 01166 if it is not a colour drag, so that dragging of gallery groups is allowed 01167 01168 ********************************************************************************************/ 01169 01170 void LibFillsSGallery::HandleDragStart(DragMessage *DragMsg) 01171 { 01172 // If it's a bitmap drag, add a target for our window. If not, let the base class 01173 // have a look at it (to see if it is a gallery item being dragged) 01174 if (DragMsg->pInfo->IsKindOf(CC_RUNTIME_CLASS(GalleryFillsDragInfo))) 01175 SGFillsDragTarget *NewTarget = new SGFillsDragTarget(this, GetListGadgetID()); 01176 else 01177 SuperGallery::HandleDragStart(DragMsg); 01178 } 01179 01180 /******************************************************************************************** 01181 01182 > virtual void LibFillsSGallery::WorkOutSectionName(String_256 *Section); 01183 01184 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 01185 Created: 28/5/95 01186 01187 Outputs: Section - String used to return the section name 01188 01189 Purpose: Returns the section name to use in the grm file 01190 01191 ********************************************************************************************/ 01192 01193 void LibFillsSGallery::WorkOutSectionName(String_256 *Section) 01194 { 01195 if(Section) 01196 *Section = _R(IDS_SGLFILLS_SECTION_NAME); // "FillsGallery"; 01197 } 01198 01199 01200 01201 /******************************************************************************************** 01202 01203 > virtual BOOL LibFillsSGallery::InitMenuCommands(void) 01204 01205 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 01206 Created: 18/9/95 01207 01208 Returns: TRUE for success 01209 01210 Purpose: Initialises any menu commands that this gallery needs. 01211 01212 Notes: Will only create the menu commands once - further calls in the future 01213 will return TRUE immediately wihtout doing anything. 01214 01215 ********************************************************************************************/ 01216 01217 BOOL LibFillsSGallery::InitMenuCommands(void) 01218 { 01219 static BOOL MenusInitialised = FALSE; 01220 01221 BOOL ok = TRUE; 01222 01223 if (!MenusInitialised) 01224 { 01225 // Initialise menu command Ops 01226 01227 // "Standar