00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 #include "camtypes.h"
00101
00102 #include "oilbitmap.h"
00103
00104
00105
00106
00107 #include "bitfilt.h"
00108 #ifndef WEBSTER
00109
00110 #endif //WEBSTER
00111
00112
00113
00114
00115
00116 #include "thumbmsg.h"
00117 #include "sgliboil.h"
00118
00119
00120
00121
00122
00123
00124 CC_IMPLEMENT_MEMDUMP(SGThumbs, CC_CLASS_MEMDUMP)
00125
00126
00127 CC_IMPLEMENT_DYNAMIC(ThumbMessage, Msg)
00128
00129
00130 #define new CAM_DEBUG_NEW
00131
00132
00133
00134
00135 INT32 SGThumbs::MaxThumbnails = 25;
00136
00137
00138 const INT32 ThumbFileSizeThreshold = 50*1024;
00139
00140
00141
00142
00143
00144
00145
00146
00147 #define THUMB_CHECK_REVERSED_FILENAME
00148
00149
00150 #define THUMB_CHECK_FILENAME_WITH_BMP
00151
00152
00153 #define THUMB_CHECK_FILENAME_WITH_PNG
00154
00155
00156
00157 #define THUMB_CHECKBMPS
00158
00159 #define THUMB_CHECKPNGS
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 SGThumbs::SGThumbs()
00175 {
00176 ERROR3("WRONG SGThumb constructor called");
00177 }
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193 SGThumbs::~SGThumbs()
00194 {
00195 DeleteThumbnails();
00196
00197 if(Thumbnails != NULL)
00198 {
00199 CCFree(Thumbnails);
00200 Thumbnails = NULL;
00201 }
00202
00203 if(Directory != NULL)
00204 {
00205 delete Directory;
00206 Directory = NULL;
00207 }
00208 }
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226 SGThumbs::SGThumbs(PathName *Dir, SGLibType Type, SGThumbSize Size)
00227 {
00228
00229
00230
00231
00232
00233
00234
00235 if(Dir != NULL)
00236 Directory = new PathName(*Dir);
00237 else
00238 Directory = NULL;
00239
00240 InitThumbnails(Type, Size);
00241 }
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258 BOOL SGThumbs::GetThumbnailName(UINT32 ID, String_8 *Filename)
00259 {
00260 ERROR3IF(Filename == NULL, "SGThumbs::GetThumbnailName passed a null ptr");
00261
00262 TCHAR type;
00263 TCHAR size;
00264
00265 switch(ThumbnailsLibType) {
00266 case SGLib_ClipArt:
00267 case SGLib_ClipArt_WebThemes:
00268 type = 'A';
00269 break;
00270 case SGLib_Bitmap:
00271 type = 'B';
00272 break;
00273 case SGLib_Colour:
00274 type = 'C';
00275 break;
00276 case SGLib_Font:
00277 type = 'F';
00278 break;
00279 case SGLib_Texture:
00280 type = 'T';
00281 break;
00282 default:
00283 type = ' ';
00284 break;
00285 }
00286
00287 switch(ThumbnailsSize) {
00288 case SGThumb_Small:
00289 size = 'S';
00290 break;
00291 case SGThumb_Medium:
00292 size = 'M';
00293 break;
00294 case SGThumb_Large:
00295 size = 'L';
00296 break;
00297 default:
00298 size = ' ';
00299 break;
00300 }
00301
00302 Filename->_MakeMsg(_T("%c%05d%c"), type, ID, size);
00303
00304 return TRUE;
00305 }
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322 BOOL SGThumbs::InitThumbnails(SGLibType Type, SGThumbSize Size)
00323 {
00324
00325
00326
00327
00328
00329 Entries = MaxThumbnails;
00330
00331 Thumbnails = (struct TN*)CCMalloc(sizeof(struct TN) * Entries);
00332 if(Thumbnails != NULL)
00333 {
00334 INT32 i;
00335 ThumbnailsLibType = Type;
00336 ThumbnailsSize = Size;
00337
00338 for(i=0; i<Entries; i++)
00339 {
00340 Thumbnails[i].ID = 0;
00341 Thumbnails[i].Usage = 0;
00342 Thumbnails[i].Valid = FALSE;
00343 Thumbnails[i].Size = ThumbnailsSize;
00344 Thumbnails[i].buffer = NULL;
00345 }
00346 ThumbnailsInitialised = TRUE;
00347 return TRUE;
00348 }
00349 else
00350 {
00351 ThumbnailsInitialised = TRUE;
00352 return FALSE;
00353 }
00354 }
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368 BOOL SGThumbs::DeleteThumbnails(void)
00369 {
00370 INT32 i;
00371 if(!ThumbnailsInitialised) return FALSE;
00372 for(i=0; i<Entries; i++)
00373 {
00374 Thumbnails[i].ID = 0;
00375 Thumbnails[i].Usage = 0;
00376 Thumbnails[i].Valid = FALSE;
00377 Thumbnails[i].Size = ThumbnailsSize;
00378 if(Thumbnails[i].buffer)
00379 {
00380
00381
00382 delete Thumbnails[i].buffer;
00383 Thumbnails[i].buffer = NULL;
00384 }
00385 }
00386
00387 return TRUE;
00388 }
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403 BOOL SGThumbs::OffsetInCache(UINT32 ID, UINT32 *Offset)
00404 {
00405 if(Offset == NULL)
00406 {
00407 ERROR3("SGThumbs::OffsetInCache given a null offset");
00408 return FALSE;
00409 }
00410
00411 INT32 i;
00412
00413 for(i=0; i<Entries; i++)
00414 {
00415 if(Thumbnails[i].ID == ID && Thumbnails[i].Valid && Thumbnails[i].Size == ThumbnailsSize)
00416 {
00417 *Offset = i;
00418 return TRUE;
00419 }
00420 }
00421
00422 return FALSE;
00423 }
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437 BOOL SGThumbs::FindNewSlotInBuffer(UINT32 *Slot)
00438 {
00439 if(Slot == NULL)
00440 {
00441 ERROR3("SGThumbs::FindNewSlotInBuffer given a null slot");
00442 return FALSE;
00443 }
00444
00445
00446 INT32 i;
00447
00448 for(i=0; i<Entries; i++)
00449 {
00450 if(!Thumbnails[i].Valid || (Thumbnails[i].Size != ThumbnailsSize))
00451 {
00452 *Slot = i;
00453 return TRUE;
00454 }
00455 }
00456
00457 UINT32 SmallestOffset = 0;
00458 UINT32 Smallest = Thumbnails[0].Usage;
00459
00460 for(i=1; i<Entries; i++)
00461 {
00462 if(Thumbnails[i].Usage < Smallest)
00463 {
00464 SmallestOffset = i;
00465 Smallest = Thumbnails[i].Usage;
00466 }
00467 }
00468
00469 *Slot = SmallestOffset;
00470 return TRUE;
00471 }
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500 BOOL SGThumbs::LoadThumbnailIntoSlot(UINT32 Slot, UINT32 ID, PathName *ActualFile)
00501 {
00502
00503
00504
00505 PORTNOTETRACE("dialog","SGThumbs::LoadThumbnailIntoSlot - do nothing");
00506 #ifndef EXCLUDE_FROM_XARALX
00507 if(Directory == NULL || ActualFile == NULL)
00508 {
00509 ERROR3("SGThumbs::LoadThumbnailIntoSlot Directory == NULL || ActualFile == NULL");
00510 return FALSE;
00511 }
00512
00513
00514 if(Thumbnails[Slot].Valid && Thumbnails[Slot].buffer)
00515 {
00516 delete Thumbnails[Slot].buffer;
00517 Thumbnails[Slot].buffer=NULL;
00518 }
00519
00520
00521 Thumbnails[Slot].Valid = FALSE;
00522
00523 BOOL CheckFilenameBmp = TRUE;
00524 BOOL CheckFilenamePng = TRUE;
00525 BOOL CheckFilenameReversed = TRUE;
00526 BOOL CheckFilenameTif = TRUE;
00527 BOOL CheckEncodedBmp = TRUE;
00528 BOOL CheckEncodedPng = TRUE;
00529 BOOL CheckEncodedTif = TRUE;
00530
00531 BOOL UseActualFile = FALSE;
00532
00533 BOOL IsRIFFTypeFile = FALSE;
00534 BOOL IsPCDTypeFile = FALSE;
00535
00536
00537 String_256 Type(ActualFile->GetType());
00538 Type.toLower();
00539
00540
00541 if( (Type.Sub((String_8)"art") != -1) ||
00542 (Type.Sub((String_8)"xar") != -1) )
00543 {
00544 UseActualFile = TRUE;
00545 CheckFilenameReversed = FALSE;
00546 }
00547 else if ( (Type.Sub((String_8)"web") != -1) ||
00548 (Type.Sub((String_8)"cxw") != -1) ||
00549 (Type.Sub((String_8)"cxn") != -1) )
00550 {
00551
00552
00553
00554 UseActualFile = TRUE;
00555 CheckFilenameReversed = FALSE;
00556 }
00557 else if ( (Type.Sub((String_8)"cdr") != -1) ||
00558 (Type.Sub((String_8)"cmx") != -1) )
00559 {
00560 IsRIFFTypeFile = TRUE;
00561 UseActualFile = TRUE;
00562 CheckFilenameReversed = FALSE;
00563 }
00564 else if( Type.Sub((String_8)"ttf") != -1 ||
00565 Type.Sub((String_8)"pfb") != -1)
00566 {
00567
00568 CheckFilenamePng =
00569 CheckFilenameBmp =
00570 CheckFilenameReversed =
00571 CheckFilenameTif =
00572 CheckEncodedTif = FALSE;
00573
00574 CheckEncodedBmp = TRUE;
00575 CheckEncodedPng = TRUE;
00576
00577 UseActualFile = FALSE;
00578 }
00579 else if( Type.Sub((String_8)"pcd") != -1 )
00580 {
00581 IsPCDTypeFile = TRUE;
00582 UseActualFile = TRUE;
00583 }
00584
00585
00586 BOOL Found = FALSE;
00587 CWxBitmap *pCWxBitmap = NULL;
00588 BOOL ReadOK = FALSE;
00589
00590
00591
00592
00593 CCDiskFile File(1024, FALSE, FALSE);
00594
00595
00596 if(UseActualFile)
00597 {
00598
00599 Found = OpenThumbnailFile( &File, *ActualFile );
00600
00601 if(Found)
00602 {
00603
00604
00605 pCWxBitmap = new CWxBitmap;
00606 if (pCWxBitmap == NULL)
00607 {
00608 ERROR3("Problem creating thumbnail bitmap");
00609 return FALSE;
00610 }
00611
00612
00613
00614 if(IsRIFFTypeFile)
00615 {
00616 #ifndef WEBSTER //WEBSTER-Martin-21/01/97
00617 if ( AccusoftFilters::GetVersionNumber() > 0)
00618 {
00619
00620 if ( CMXImportFilter::SkipToPreviewBitmap(&File) )
00621 {
00622 TRACEUSER( "Martin", _T("Accusoft read RIFF preview\n"));
00623 ReadOK = AccusoftFilters::ReadFromFile( &File, &pCWxBitmap->BMInfo, &pCWxBitmap->BMBytes, TRUE, NULL, NULL, TRUE );
00624 }
00625 }
00626 else
00627 {
00628 TRACEUSER( "Martin", _T("Accusoft filter not loaded\n"));
00629 ReadOK = FALSE;
00630 }
00631 #endif //WEBSTER
00632 }
00633 else if(IsPCDTypeFile)
00634 {
00635 #ifndef WEBSTER //WEBSTER-Martin-21/01/97
00636 if ( AccusoftFilters::GetVersionNumber() > 0)
00637 {
00638 TRACEUSER( "Martin", _T("Accusoft read PCD preview\n"));
00639
00640 AccusoftFilters::ImagePageToRead = 2;
00641 ReadOK = AccusoftFilters::ReadFromFile( &File, &pCWxBitmap->BMInfo, &pCWxBitmap->BMBytes, TRUE, NULL, NULL, TRUE );
00642 }
00643 else
00644 {
00645 TRACEUSER( "Martin", _T("Accusoft filter not loaded\n"));
00646 ReadOK = FALSE;
00647 }
00648 #endif //WEBSTER
00649 }
00650 else
00651 {
00652
00653
00654 BOOL IsNewFormat = FALSE;
00655 UINT32 FilterId = FILTERID_NONE;
00656 if (BaseCamelotFilter::SkipToPreviewBitmap(&File, &IsNewFormat, &FilterId))
00657 {
00658
00659 if (FilterId != FILTERID_NONE)
00660 {
00661 Filter* pFilter = Filter::FindFilterFromID(FilterId);
00662 if (pFilter != NULL)
00663 {
00664 ERROR3IF( !pFilter->IS_KIND_OF(BaseBitmapFilter), "Preview filter is not a BaseBitmapFilter\n" );
00665 ReadOK = ((BaseBitmapFilter *)pFilter)->ReadFromFile( pCWxBitmap, NULL, &File, FALSE );
00666 }
00667 }
00668
00669
00670
00671 else
00672 {
00673 UseActualFile = FALSE;
00674 Found = FALSE;
00675 File.close();
00676
00677 delete pCWxBitmap;
00678 pCWxBitmap = NULL;
00679 }
00680 }
00681
00682
00683
00684 else
00685 {
00686 if (AccusoftFilters::GetVersionNumber() > 0)
00687 ReadOK = AccusoftFilters::ReadFromFile( &File, &pCWxBitmap->BMInfo, &pCWxBitmap->BMBytes, TRUE );
00688 else
00689 ReadOK = FALSE;
00690 }
00691 }
00692 }
00693 else
00694 {
00695 TRACEUSER( "Martin", _T("Failed to find original file %s\n"), (const TCHAR *)ActualFile->GetFileName(TRUE));
00696 Error::ClearError();
00697
00698 UseActualFile = FALSE;
00699 }
00700 }
00701
00702
00703 if(!UseActualFile)
00704 {
00705
00706 #ifdef THUMB_CHECK_FILENAME_WITH_PNG
00707 if(CheckFilenamePng && !Found)
00708 {
00709
00710 String_256 FAP;
00711
00712 FAP = Directory->GetPath(TRUE);
00713 FAP += ActualFile->GetFileName(FALSE);
00714 FAP += TEXT(".png");
00715
00716
00717
00718 PathName ThumbPath(FAP);
00719
00720
00721 Found = OpenThumbnailFile( &File, ThumbPath );
00722
00723 if(Found)
00724 {
00725
00726 pCWxBitmap = new CWxBitmap;
00727 if (pCWxBitmap == NULL)
00728 {
00729 ERROR3("Problem creating bitmap");
00730 return FALSE;
00731 }
00732
00733
00734 INT32 TransColour;
00735 ReadOK = PNGUtil::ReadFromFile( &File, &pCWxBitmap->BMInfo, &pCWxBitmap->BMBytes, &TransColour );
00736 }
00737 }
00738 #endif
00739
00740 #ifdef THUMB_CHECK_FILENAME_WITH_BMP
00741 if(CheckFilenameBmp && !Found)
00742 {
00743
00744 String_256 FAP;
00745
00746 FAP = Directory->GetPath(TRUE);
00747 FAP += ActualFile->GetFileName(FALSE);
00748 FAP += TEXT(".bmp");
00749
00750 PathName ThumbPath(FAP);
00751
00752
00753 Found = OpenThumbnailFile( &File, ThumbPath );
00754
00755 if(Found)
00756 {
00757
00758 pCWxBitmap = new CWxBitmap;
00759 if (pCWxBitmap == NULL)
00760 {
00761 ERROR3("Problem creating bitmap");
00762 return FALSE;
00763 }
00764
00765
00766 ReadOK = DIBUtil::ReadFromFile( &File, &pCWxBitmap->BMInfo, &pCWxBitmap->BMBytes, TRUE );
00767
00768 if ( !ReadOK )
00769 {
00770 delete pCWxBitmap;
00771 pCWxBitmap = NULL;
00772 Found = FALSE;
00773 Error::ClearError();
00774
00775
00776
00777 File.close();
00778 Found = OpenThumbnailFile( &File, ThumbPath );
00779 }
00780 }
00781 }
00782 #endif
00783
00784 #ifdef THUMB_CHECK_REVERSED_FILENAME
00785 if( CheckFilenameReversed && !Found )
00786 {
00787
00788 String_256 FAP;
00789
00790 FAP = Directory->GetPath(TRUE);
00791 FAP += ActualFile->GetFileName(FALSE);
00792 String_256 Ending(ActualFile->GetType());
00793 _tcsrev((TCHAR *)Ending);
00794 FAP += TEXT(".");
00795 FAP += (TCHAR *)Ending;
00796
00797
00798
00799 PathName ThumbPath(FAP);
00800
00801
00802 Found = OpenThumbnailFile( &File, ThumbPath );
00803
00804 if(Found)
00805 {
00806
00807 pCWxBitmap = new CWxBitmap;
00808 if (pCWxBitmap == NULL)
00809 {
00810 return FALSE;
00811 }
00812
00813
00814 ReadOK = DIBUtil::ReadFromFile( &File, &pCWxBitmap->BMInfo, &pCWxBitmap->BMBytes, TRUE );
00815
00816 if ( ReadOK )
00817 {
00818
00819 String_256 Name(ActualFile->GetFileName(FALSE));
00820 pCWxBitmap->SetName(Name);
00821 }
00822 else
00823 {
00824 delete pCWxBitmap;
00825 pCWxBitmap = NULL;
00826 Found = FALSE;
00827 Error::ClearError();
00828
00829
00830
00831 File.close();
00832 Found = OpenThumbnailFile( &File, ThumbPath );
00833 }
00834 }
00835 }
00836
00837 #endif
00838
00839 #ifdef THUMB_CHECK_FILENAME_WITH_TIF
00840 if( CheckFilenameTif && !Found )
00841 {
00842
00843
00844 String_256 FullThumbnailPath(Directory->GetPath(TRUE));
00845 FullThumbnailPath += ActualFile->GetFileName(FALSE);
00846 FullThumbnailPath += TEXT(".tif");
00847
00848 TRACEUSER( "Richard", _T("Filename: %s\n"), (TCHAR *)FullThumbnailPath);
00849
00850 PathName FileAndPath(FullThumbnailPath);
00851
00852
00853 Found = OpenThumbnailFile( &File, FileAndPath );
00854 }
00855 #endif
00856
00857
00858 String_256 FullThumbnailPathWithoutExtension;
00859 if(!Found)
00860 {
00861 String_8 EncodedThumbnail;
00862
00863
00864 if(!GetThumbnailName(ID, &EncodedThumbnail))
00865 return FALSE;
00866
00867
00868 FullThumbnailPathWithoutExtension = Directory->GetPath(TRUE);
00869 FullThumbnailPathWithoutExtension += EncodedThumbnail;
00870 }
00871
00872
00873 #ifdef THUMB_CHECKBMPS
00874 if(CheckEncodedBmp && !Found)
00875 {
00876
00877
00878
00879
00880 String_256 FullThumbnailPath(FullThumbnailPathWithoutExtension);
00881 FullThumbnailPath += TEXT(".bmp");
00882 TRACEUSER( "Richard", _T("Filename: %s\n"), (TCHAR *)FullThumbnailPath);
00883
00884 PathName FileAndPath(FullThumbnailPath);
00885
00886
00887 Found = OpenThumbnailFile( &File, FileAndPath );
00888
00889 if(Found)
00890 {
00891
00892 pCWxBitmap = new CWxBitmap;
00893 if (pCWxBitmap == NULL)
00894 {
00895 ERROR3("Problem creating bitmap");
00896 return FALSE;
00897 }
00898
00899
00900 String_256 Name(FileAndPath.GetFileName(FALSE));
00901 pCWxBitmap->SetName(Name);
00902
00903
00904 ReadOK = DIBUtil::ReadFromFile( &File, &pCWxBitmap->BMInfo, &pCWxBitmap->BMBytes, TRUE );
00905
00906 if(!ReadOK)
00907 {
00908 delete pCWxBitmap;
00909 pCWxBitmap = NULL;
00910 Found = FALSE;
00911 Error::ClearError();
00912
00913
00914
00915 File.close();
00916 Found = OpenThumbnailFile( &File, FileAndPath );
00917 }
00918 }
00919 }
00920 #endif
00921
00922 #ifdef THUMB_CHECKPNGS
00923 if(CheckEncodedPng && !Found)
00924 {
00925
00926
00927
00928
00929 String_256 FullThumbnailPath(FullThumbnailPathWithoutExtension);
00930 FullThumbnailPath += TEXT(".png");
00931 TRACEUSER( "Richard", _T("Filename: %s\n"), (TCHAR *)FullThumbnailPath);
00932
00933 PathName FileAndPath(FullThumbnailPath);
00934
00935
00936 Found = OpenThumbnailFile( &File, FileAndPath );
00937
00938 if(Found)
00939 {
00940
00941 pCWxBitmap = new CWxBitmap;
00942 if (pCWxBitmap == NULL)
00943 {
00944 ERROR3("Problem creating bitmap");
00945 return FALSE;
00946 }
00947
00948
00949 String_256 Name(FileAndPath.GetFileName(FALSE));
00950 pCWxBitmap->SetName(Name);
00951
00952
00953 INT32 TransColour;
00954 ReadOK = PNGUtil::ReadFromFile( &File, &pCWxBitmap->BMInfo, &pCWxBitmap->BMBytes, &TransColour );
00955 }
00956 }
00957 #endif
00958
00959 #ifdef THUMB_CHECKTIFS
00960 if(CheckEncodedTif && !Found)
00961 {
00962
00963
00964
00965 String_256 FullThumbnailPath(FullThumbnailPathWithoutExtension);
00966 FullThumbnailPath += TEXT(".tif");
00967 TRACEUSER( "Richard", _T("Filename: %s\n"), (TCHAR *)FullThumbnailPath);
00968
00969 PathName FileAndPath(FullThumbnailPath);
00970
00971
00972 Found = OpenThumbnailFile( &File, FileAndPath );
00973 }
00974 #endif
00975
00976 #ifndef WEBSTER //WEBSTER-Martin-21/01/97
00977 if ( Found && !ReadOK )
00978 {
00979
00980 if ( AccusoftFilters::GetVersionNumber() > 0)
00981 {
00982 ReadOK = AccusoftFilters::ReadFromFile( &File, &pCWxBitmap->BMInfo, &pCWxBitmap->BMBytes, TRUE, NULL, NULL, TRUE );
00983 }
00984 else
00985 {
00986 TRACEUSER( "Martin", _T("Accusoft filter not loaded\n"));
00987 ReadOK = FALSE;
00988 }
00989 }
00990 #endif //WEBSTER
00991 }
00992
00993 if(!ReadOK || pCWxBitmap == NULL)
00994 {
00995
00996 TRACEUSER( "Richard", _T("Can't find/load thumbnail"));
00997
00998
00999 Error::ClearError();
01000
01001 if(pCWxBitmap != NULL)
01002 {
01003 delete pCWxBitmap;
01004 pCWxBitmap = NULL;
01005 }
01006 return FALSE;
01007 }
01008
01009
01010 String_256 Name(ActualFile->GetFileName(FALSE));
01011 pCWxBitmap->SetName(Name);
01012
01013
01014 Thumbnails[Slot].buffer = new KernelBitmap(pCWxBitmap, TRUE);
01015 if (Thumbnails[Slot].buffer == NULL)
01016 {
01017 ERROR3("Problem creating kernel bitmap for thumbnail");
01018 delete pCWxBitmap;
01019 pCWxBitmap = NULL;
01020 return FALSE;
01021 }
01022
01023
01024 Thumbnails[Slot].Valid = TRUE;
01025 Thumbnails[Slot].ID = ID;
01026 Thumbnails[Slot].Usage = 0;
01027 Thumbnails[Slot].Size = ThumbnailsSize;
01028
01029 Error::ClearError();
01030 #endif
01031
01032 return TRUE;
01033 }
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056 BOOL SGThumbs::OpenThumbnailFile( CCDiskFile* pFile, const PathName& ThumbFileName ) const
01057 {
01058 ERROR3IF( pFile==NULL, "SGThumbs::OpenThumbnailFile passed a null ptr" );
01059
01060 TRACEUSER( "Martin", _T("Open thumb file: %s\n"), (const TCHAR *)ThumbFileName.GetPath() );
01061
01062 BOOL Found = FALSE;
01063
01064 if(!ThumbFileName.IsValid())
01065 {
01066
01067 ERROR3("SGThumbs::OpenThumbnailFile received an invalid xarainfo\\<filename> file");
01068 Error::ClearError();
01069 return FALSE;
01070 }
01071
01072
01073 if( !( Found = pFile->open( ThumbFileName, ios::in | ios::binary ) ) )
01074 {
01075 Found = FALSE;
01076 Error::ClearError();
01077 }
01078
01079 return Found;
01080 }
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108 BOOL SGThumbs::GetThumbnail(UINT32 ID, BOOL Urgent, KernelBitmap **Result, PathName *File, LP_SGTHUMBS_MOREINFO MoreInfo)
01109 {
01110 PORTNOTETRACE("dialog","SGThumbs::GetThumbnail - do nothing");
01111 #ifndef EXCLUDE_FROM_XARALX
01112 #ifndef EXCLUDE_GALS
01113
01114 if(Result == NULL)
01115 {
01116 ERROR3("SGThumbs::GetThumbnail - NULL result parameters are illegal");
01117 return FALSE;
01118 }
01119
01120 *Result = NULL;
01121
01122 if(!ThumbnailsInitialised) return FALSE;
01123
01124 BOOL ok = TRUE;
01125 UINT32 Slot = 0;
01126
01127 ok = OffsetInCache(ID, &Slot);
01128
01129
01130 if(!ok && !Urgent)
01131 return FALSE;
01132
01133 MonotonicTime TempTime;
01134
01135 if(!ok)
01136 {
01137 ok = FindNewSlotInBuffer(&Slot);
01138 if(!ok) return FALSE;
01139
01140 if(Directory == NULL)
01141 {
01142 if(MoreInfo == NULL)
01143 {
01144 ERROR3("SGThumbs::GetThumbnail MoreInfo is NULL as is Directory. Can't generate the thumbnail");
01145 return FALSE;
01146 }
01147
01148 if(Thumbnails[Slot].Valid && Thumbnails[Slot].buffer)
01149 {
01150 delete Thumbnails[Slot].buffer;
01151 Thumbnails[Slot].buffer=NULL;
01152 }
01153
01154
01155 Thumbnails[Slot].Valid = FALSE;
01156
01157 switch(ThumbnailsLibType)
01158 {
01159 case SGLib_Font:
01160 ok = ((SGDisplayPreviewFonts *)MoreInfo)->CreateThumbnail(&Thumbnails[Slot].buffer);
01161 break;
01162
01163 default:
01164 TRACEUSER( "Richard", _T("Cannot create thumbnails of this type"));
01165 return FALSE;
01166 }
01167
01168 if(ok)
01169 {
01170
01171 Thumbnails[Slot].Valid = TRUE;
01172 Thumbnails[Slot].ID = ID;
01173 Thumbnails[Slot].Usage = 0;
01174 Thumbnails[Slot].Size = ThumbnailsSize;
01175 }
01176 }
01177 else
01178 {
01179 if(File != NULL)
01180 {
01181 ok = LoadThumbnailIntoSlot(Slot, ID, File);
01182 if(!ok)
01183 {
01184 TRACEUSER( "Richard", _T("PROBLEMS loading thumbnail"));
01185 return FALSE;
01186 }
01187
01188
01189 #ifndef WEBSTER
01190 #ifndef STANDALONE
01191 if(ThumbnailsLibType == SGLib_Font)
01192 {
01193 StringToBitmap::ContoneFontBitmap(Thumbnails[Slot].buffer);
01194 }
01195 #endif
01196 #endif //WEBSTER
01197 }
01198 else
01199 {
01200 ERROR3("SGThumbs::GetThumbnail - No filename given for the thumbnail");
01201 return FALSE;
01202 }
01203 }
01204 }
01205
01206
01207 Thumbnails[Slot].Usage = TempTime.Sample();
01208 *Result = Thumbnails[Slot].buffer;
01209 #endif
01210 #endif
01211 return TRUE;
01212 }
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228 BOOL SGThumbs::SetSize(SGThumbSize Size)
01229 {
01230 if(ThumbnailsSize == Size) return TRUE;
01231 ThumbnailsSize = Size;
01232 return(DeleteThumbnails());
01233 }
01234
01235
01236
01237
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247 BOOL SGThumbs::GetSize(SGThumbSize *Size)
01248 {
01249 if(Size == NULL)
01250 {
01251 ERROR3("SGThumbs::GetSize passed a null size");
01252 return FALSE;
01253 }
01254
01255 *Size = ThumbnailsSize;
01256 return TRUE;
01257 }
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271 void SGThumbs::DumpCache(char *DumpFile)
01272 {
01273 #if 0
01274 UINT32 i;
01275 if(!ThumbnailsInitialised)
01276 {
01277 _tprintf("Thumbnails not initialised\n");
01278 return;
01279 }
01280
01281 FILE *fp;
01282 fp = _tfopen(DumpFile, "w");
01283
01284 if(!fp)
01285 {
01286 _tprintf("Error opening %s\n", DumpFile);
01287 return;
01288 }
01289
01290 _tprintf("Dumping's going OK\n");
01291
01292
01293 _ftprintf(fp, "Directory %s\n", Directory->GetPath());
01294 _ftprintf(fp, "Initialised %d\n", ThumbnailsInitialised);
01295 _ftprintf(fp, "Size %d\n", ThumbnailsSize);
01296 _ftprintf(fp, "LibType %d\n\n", ThumbnailsLibType);
01297
01298 for(i=0; i<Entries; i++)
01299 {
01300 _ftprintf(fp, "Entry %d - Valid %d, ID %d, Usage %d, Size %d, buffer %d\n", i, Thumbnails[i].Valid, Thumbnails[i].ID, Thumbnails[i].Usage, Thumbnails[i].Size, (INT32)Thumbnails[i].buffer);
01301 }
01302
01303 fclose(fp);
01304 #endif
01305 }
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320 BOOL SGThumbs::ResizeAllThumbCaches(INT32 Entries)
01321 {
01322
01323 BROADCAST_TO_CLASS(ThumbMessage(ThumbMessage::CACHESIZECHANGED, Entries), DialogOp);
01324 return TRUE;
01325 }