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
00101 #include "camtypes.h"
00102 #include "sglib.h"
00103 #include <io.h>
00104
00105 #include "ccdc.h"
00106
00107 #include "grnddib.h"
00108
00109 #include "bitmpinf.h"
00110 #include "nodebmp.h"
00111
00112 #include "sgliboil.h"
00113
00114 #include "thumbmsg.h"
00115
00116
00117
00118
00119 #include "sglbase.h"
00120 #include "progress.h"
00121 #include "sglcart.h"
00122 #include "inetop.h"
00123
00124
00125
00126
00127
00128 CC_IMPLEMENT_DYNAMIC(SGLibDisplayItem, SGDisplayItem)
00129 CC_IMPLEMENT_DYNAMIC(SGLibGroup, SGDisplayGroup)
00130
00131
00132 #define new CAM_DEBUG_NEW
00133
00134 using namespace InetUtils;
00135
00136
00137 const INT32 SG_SPACE_UNDER = SG_GapAboveText / 2;
00138
00139
00140 #define GROUP_BAR_ICON_WIDTH 16500
00141
00142
00143 BOOL SGLibGroup::LibraryVirtualisingEnabled = TRUE;
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166 SGLibDisplayItem::SGLibDisplayItem()
00167 {
00168 ERROR3("Illegal call on default SGLibDisplayItem constructor - call the other one!");
00169 TheLibraryIndex = NULL;
00170
00171 }
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189 SGLibDisplayItem::SGLibDisplayItem(LibraryIndex LibraryIndexToDisplay, BOOL bNew)
00190 {
00191 TheLibraryIndex = LibraryIndexToDisplay;
00192 bIsDownloadingThumb = FALSE;
00193 pDownloadOp = NULL;
00194 nPercentageDownloaded = 0;
00195 bIsNew = bNew;
00196 }
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210 SGLibDisplayItem::~SGLibDisplayItem()
00211 {
00212 if (IsDownloadingThumb() && pDownloadOp)
00213 pDownloadOp->Abort();
00214 }
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233 INT32 SGLibDisplayItem::GetTextWidth(SGFormatInfo *FormatInfo, SGMiscInfo *MiscInfo)
00234 {
00235 INT32 XSize = SG_InfiniteWidth;
00236 INT32 OnePixel = (INT32) DevicePixels(MiscInfo, 1);
00237
00238
00239 LibDisplayType DType = GetDisplayType(MiscInfo);
00240
00241
00242 switch(DType)
00243 {
00244 case LibDisplay_SmallThumbTextUnder:
00245 case LibDisplay_MediumThumbTextUnder:
00246 case LibDisplay_LargeThumbTextUnder:
00247
00248 XSize = 0;
00249 break;
00250
00251 case LibDisplay_SmallThumb:
00252 case LibDisplay_MediumThumb:
00253 case LibDisplay_LargeThumb:
00254
00255 XSize = 0;
00256 break;
00257
00258 case LibDisplay_FullInfo:
00259 case LibDisplay_SingleLineFullInfo:
00260
00261 XSize = SG_DefaultNameText * 2;
00262 break;
00263
00264 case LibDisplay_JustText:
00265
00266 XSize = (SG_DefaultNameText * 4) / 3;
00267 break;
00268
00269 default:
00270
00271 XSize = (SG_DefaultNameText * 2) / 3;
00272 break;
00273 }
00274
00275
00276 XSize = GridLock(MiscInfo, XSize);
00277
00278
00279 XSize += (3 * 2 * OnePixel);
00280
00281 return XSize;
00282 }
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310 void SGLibDisplayItem::CalculateMyRect(SGFormatInfo *FormatInfo, SGMiscInfo *MiscInfo)
00311 {
00312 INT32 XSize = SG_InfiniteWidth;
00313 INT32 YSize = SG_DefaultLargeIcon;
00314 INT32 OnePixel = (INT32) DevicePixels(MiscInfo, 1);
00315 Library *ParentLib = GetParentLibrary();
00316
00317
00318 LibDisplayType DType = GetDisplayType(MiscInfo);
00319
00320
00321 XSize = GetTextWidth(FormatInfo, MiscInfo);
00322
00323
00324 switch(DType)
00325 {
00326 case LibDisplay_SmallThumbTextUnder:
00327 case LibDisplay_MediumThumbTextUnder:
00328 case LibDisplay_LargeThumbTextUnder:
00329
00330 YSize = SG_GapAboveText + SG_SPACE_UNDER;
00331 break;
00332
00333 default:
00334
00335 YSize = 0;
00336 break;
00337 }
00338
00339
00340 YSize = GridLock(MiscInfo, YSize);
00341
00342
00343 YSize += (3 * 2 * OnePixel);
00344
00345
00346 switch(DType)
00347 {
00348 case LibDisplay_SmallThumbTextUnder:
00349 case LibDisplay_SmallThumbText:
00350 case LibDisplay_SmallThumb:
00351 YSize += GridLock(MiscInfo, ParentLib->PreviewBMPHeight(SGThumb_Small) * OnePixel);
00352 XSize += GridLock(MiscInfo, ParentLib->PreviewBMPWidth(SGThumb_Small) * OnePixel);
00353 break;
00354
00355 case LibDisplay_LargeThumbTextUnder:
00356 case LibDisplay_Default:
00357 case LibDisplay_LargeThumbText:
00358 case LibDisplay_LargeThumb:
00359 YSize += GridLock(MiscInfo, ParentLib->PreviewBMPHeight(SGThumb_Large) * OnePixel);
00360 XSize += GridLock(MiscInfo, ParentLib->PreviewBMPWidth(SGThumb_Large) * OnePixel);
00361 break;
00362
00363 case LibDisplay_MediumThumbTextUnder:
00364 case LibDisplay_MediumThumbText:
00365 case LibDisplay_MediumThumb:
00366 YSize += GridLock(MiscInfo, ParentLib->PreviewBMPHeight(SGThumb_Medium) * OnePixel);
00367 XSize += GridLock(MiscInfo, ParentLib->PreviewBMPWidth(SGThumb_Medium) * OnePixel);
00368 break;
00369
00370 case LibDisplay_FullInfo:
00371 case LibDisplay_SingleLineFullInfo:
00372 YSize += GridLock(MiscInfo, ParentLib->PreviewBMPHeight(SGThumb_Medium) * OnePixel);
00373 XSize += GridLock(MiscInfo, ParentLib->PreviewBMPWidth(SGThumb_Medium) * OnePixel);
00374
00375 break;
00376
00377 case LibDisplay_JustText:
00378
00379 YSize = GridLock(MiscInfo, 18 * OnePixel);
00380 XSize = GridLock(MiscInfo, SG_DefaultNameText);
00381 break;
00382 }
00383
00384
00385 CalculateFormatRect(FormatInfo, MiscInfo, XSize, YSize);
00386 }
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412 void SGLibDisplayItem::HandleRedraw(SGRedrawInfo *RedrawInfo, SGMiscInfo *MiscInfo)
00413 {
00414
00415 StartRendering(RedrawInfo, MiscInfo);
00416
00417
00418 Library *ParentLib = GetParentLibrary();
00419
00420 DocRect BmpRect(FormatRect);
00421 DocRect UnscaledRect(FormatRect);
00422
00423 RenderRegion *Renderer = RedrawInfo->Renderer;
00424
00425 INT32 OnePixel = (INT32) DevicePixels(MiscInfo, 1);
00426 INT32 TwoPixels = (INT32) DevicePixels(MiscInfo, 2);
00427
00428 LibDisplayType DType = GetDisplayType(MiscInfo);
00429
00430
00431
00432
00433
00434
00435
00436 Renderer->SetLineWidth(0);
00437 Renderer->SetLineColour(RedrawInfo->Transparent);
00438
00439 if(DType == LibDisplay_JustText)
00440 {
00441 BmpRect.hi.x = BmpRect.lo.x + OnePixel;
00442 }
00443 else
00444 {
00445 INT32 XSize = 0;
00446
00447 switch(DType)
00448 {
00449 case LibDisplay_MediumThumbTextUnder:
00450 case LibDisplay_MediumThumbText:
00451 case LibDisplay_MediumThumb:
00452 case LibDisplay_FullInfo:
00453 case LibDisplay_SingleLineFullInfo:
00454 XSize = ParentLib->PreviewBMPWidth(SGThumb_Medium);
00455 break;
00456
00457 case LibDisplay_SmallThumbText:
00458 case LibDisplay_SmallThumbTextUnder:
00459 case LibDisplay_SmallThumb:
00460 XSize = ParentLib->PreviewBMPWidth(SGThumb_Small);
00461 break;
00462
00463 case LibDisplay_Default:
00464 case LibDisplay_LargeThumbText:
00465 case LibDisplay_LargeThumb:
00466 case LibDisplay_LargeThumbTextUnder:
00467 default:
00468
00469 XSize = ParentLib->PreviewBMPWidth(SGThumb_Large);
00470 break;
00471 }
00472
00473
00474 XSize *= OnePixel;
00475
00476
00477 BmpRect.hi.x = BmpRect.lo.x + XSize + (6 * OnePixel);
00478
00479
00480 BmpRect.Inflate(-(TwoPixels+OnePixel));
00481
00482
00483 switch(DType)
00484 {
00485 case LibDisplay_SmallThumbTextUnder:
00486 case LibDisplay_MediumThumbTextUnder:
00487 case LibDisplay_LargeThumbTextUnder:
00488 BmpRect.lo.y += SG_GapAboveText + SG_SPACE_UNDER;
00489 break;
00490 default:
00491 break;
00492 }
00493
00494
00495 GridLockRect(MiscInfo, &BmpRect);
00496
00497
00498 if (Flags.Selected)
00499 {
00500 if(BmpRect.hi.x > UnscaledRect.hi.x) BmpRect.hi.x = UnscaledRect.hi.x;
00501
00502 BmpRect.Inflate(TwoPixels+OnePixel);
00503 GridLockRect(MiscInfo, &BmpRect);
00504 DrawSelectionOutline(RedrawInfo, MiscInfo, &BmpRect);
00505
00506 BmpRect.Inflate(-(TwoPixels+OnePixel));
00507 }
00508
00509 DrawItemThumbnail(RedrawInfo, MiscInfo, &BmpRect);
00510 }
00511
00512
00513 DrawItemText(Renderer, RedrawInfo, MiscInfo, &UnscaledRect, &BmpRect, Flags.Selected);
00514
00515
00516
00517 StopRendering(RedrawInfo, MiscInfo);
00518 }
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540 void SGLibDisplayItem::DrawItemThumbnail(SGRedrawInfo* pRedrawInfo, SGMiscInfo* pMiscInfo, DocRect* pDocRect)
00541 {
00542 RenderRegion* pRenderer = pRedrawInfo->Renderer;
00543 if (Library::BackgroundRedraw)
00544 {
00545 BOOL DrawnBitmap = DrawThumb(pRenderer, pRedrawInfo, pMiscInfo, pDocRect, FALSE);
00546 if (ShouldDownloadThumb())
00547 DownloadThumbnail();
00548 if (ShouldIDrawForeground(DrawnBitmap))
00549 {
00550 if (!DrawnBitmap)
00551 {
00552 if (!DrawThumb(pRenderer, pRedrawInfo, pMiscInfo, pDocRect, TRUE))
00553 {
00554 if (IsDownloadingThumb())
00555 DrawPlaceholder(pRenderer, pMiscInfo, pDocRect, TRUE);
00556 else
00557 DrawPlaceholder(pRenderer, pMiscInfo, pDocRect, FALSE);
00558 }
00559 }
00560 }
00561 else if (!DrawnBitmap)
00562 DrawPlaceholder(pRenderer, pMiscInfo, pDocRect, TRUE);
00563 }
00564 else if (!DrawThumb(pRenderer, pRedrawInfo, pMiscInfo, pDocRect, TRUE))
00565 DrawPlaceholder(pRenderer, pMiscInfo, pDocRect, FALSE);
00566 }
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592 BOOL SGLibDisplayItem::ShouldIDrawForeground(BOOL ForceForeground)
00593 {
00594 if (pDownloadOp)
00595 return SGDisplayNode::ShouldIDrawForeground(TRUE);
00596 else
00597 return SGDisplayNode::ShouldIDrawForeground(ForceForeground);
00598 }
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630 void SGLibDisplayItem::DrawItemText(RenderRegion *Renderer, SGRedrawInfo *RedrawInfo,
00631 SGMiscInfo *MiscInfo, DocRect *Rectangle, DocRect *BmpRect, BOOL Selected)
00632 {
00633 LibDisplayType DType = GetDisplayType(MiscInfo);
00634
00635
00636 DocRect TextRect(*Rectangle);
00637
00638 INT32 OnePixel = (INT32) DevicePixels(MiscInfo, 1);
00639
00640 switch(DType)
00641 {
00642 case LibDisplay_SmallThumbTextUnder:
00643 case LibDisplay_MediumThumbTextUnder:
00644 case LibDisplay_LargeThumbTextUnder:
00645 TextRect = *Rectangle;
00646
00647
00648 TextRect.lo.y = TextRect.lo.y + SG_SPACE_UNDER;
00649
00650 TextRect.hi.y = TextRect.lo.y + SG_GapAboveText;
00651
00652
00653 TextRect.Inflate(0, -OnePixel);
00654 break;
00655
00656 case LibDisplay_SmallThumb:
00657 case LibDisplay_MediumThumb:
00658 case LibDisplay_LargeThumb:
00659
00660 return;
00661 break;
00662
00663 default:
00664 TextRect = *Rectangle;
00665 TextRect.lo.x = BmpRect->hi.x + SG_GapBeforeText;
00666 break;
00667 }
00668
00669 GridLockRect(MiscInfo, &TextRect);
00670
00671 Renderer->SetLineWidth(0);
00672 Renderer->SetLineColour(RedrawInfo->Transparent);
00673 DocColour red(0xFF, 0, 0);
00674
00675
00676 if (Selected)
00677 {
00678 Renderer->SetFillColour(RedrawInfo->SelBackground);
00679
00680 switch(DType)
00681 {
00682 case LibDisplay_SmallThumbTextUnder:
00683 case LibDisplay_MediumThumbTextUnder:
00684 case LibDisplay_LargeThumbTextUnder:
00685 Renderer->DrawRect(&TextRect);
00686 break;
00687
00688 case LibDisplay_FullInfo:
00689 {
00690
00691 DocRect SelRect(TextRect);
00692
00693
00694 if(TextRect.lo.x > Rectangle->hi.x) return;
00695
00696 SelRect.hi.y = TextRect.lo.y + TextRect.Height()/2 - (OnePixel * 2);
00697 SelRect.lo.y = TextRect.lo.y + TextRect.Height()/2 + (OnePixel * 2);
00698 SelRect.hi.y += SG_DefaultLargeIcon + OnePixel*4;
00699 SelRect.lo.y -= (SG_DefaultLargeIcon + OnePixel*5);
00700 SelRect.hi.x = TextRect.hi.x;
00701
00702 GridLockRect(MiscInfo, &SelRect);
00703
00704 Renderer->DrawRect(&SelRect);
00705 }
00706 break;
00707
00708 default:
00709 {
00710 DocRect SelRect(TextRect);
00711
00712
00713 if(TextRect.lo.x > Rectangle->hi.x) return;
00714
00715 SelRect.hi.y = TextRect.lo.y + TextRect.Height()/2 - (OnePixel * 2);
00716 SelRect.lo.y = TextRect.lo.y + TextRect.Height()/2 + (OnePixel * 2);
00717 SelRect.hi.y += SG_DefaultLargeIcon/2;
00718 SelRect.lo.y -= (SG_DefaultLargeIcon/2 + OnePixel);
00719 SelRect.hi.x = TextRect.hi.x;
00720
00721 GridLockRect(MiscInfo, &SelRect);
00722
00723 Renderer->DrawRect(&SelRect);
00724 }
00725 break;
00726 }
00727 Renderer->SetFixedSystemTextColours(&RedrawInfo->SelForeground, &RedrawInfo->SelBackground);
00728 }
00729 else
00730 Renderer->SetFixedSystemTextColours(&RedrawInfo->Foreground, &RedrawInfo->Background);
00731
00732
00733
00734 if(TextRect.lo.x + (OnePixel * 4) > Rectangle->hi.x)
00735 return;
00736
00737
00738 String_256 DisplayText;
00739 String_256 DisplayText2;
00740
00741 switch(DType)
00742 {
00743 case LibDisplay_FullInfo:
00744
00745
00746 if(!GetActualDisplayedText(&DisplayText, 1))
00747 DisplayText = TEXT("");
00748
00749 if(!GetActualDisplayedText(&DisplayText2, 2))
00750 DisplayText2 = TEXT("");
00751 break;
00752
00753 default:
00754 if(!GetActualDisplayedText(&DisplayText, 0))
00755 DisplayText = TEXT("");
00756 break;
00757 }
00758
00759 if (bIsNew)
00760 {
00761 String_256 strTemp(_R(IDS_FOLDERNEW));
00762 strTemp += _T(" ");
00763 strTemp += DisplayText;
00764 DisplayText = strTemp;
00765 }
00766
00767
00768
00769 switch(DType)
00770 {
00771 case LibDisplay_SmallThumbTextUnder:
00772 case LibDisplay_MediumThumbTextUnder:
00773 case LibDisplay_LargeThumbTextUnder:
00774 {
00775
00776
00777
00778 DocRect TextBoundRect;
00779 Renderer->GetFixedSystemTextSize(&DisplayText, &TextBoundRect);
00780
00781
00782 TextBoundRect.Translate(TextRect.lo.x + (TextRect.Width()-TextBoundRect.Width())/2,
00783 TextRect.lo.y + (TextRect.Height()-TextBoundRect.Height())/2);
00784
00785
00786 if(TextBoundRect.Width() > TextRect.Width() || TextBoundRect.Height() > TextRect.Height())
00787 TextBoundRect = TextRect;
00788
00789
00790 Renderer->DrawFixedSystemText(&DisplayText, TextBoundRect);
00791 if (bIsNew)
00792 {
00793 *camStrchr(DisplayText, _T(' ')) = 0x00;
00794 Renderer->SetFixedSystemTextColours(&red, &RedrawInfo->Background);
00795 Renderer->DrawFixedSystemText(&DisplayText, TextBoundRect);
00796 Renderer->SetFixedSystemTextColours(&RedrawInfo->Foreground, &RedrawInfo->Background);
00797 }
00798 }
00799 break;
00800
00801 case LibDisplay_FullInfo:
00802 {
00803
00804
00805
00806 DocRect TextBoundRect;
00807 Renderer->GetFixedSystemTextSize(&DisplayText, &TextBoundRect);
00808
00809
00810 TextRect.lo.x += (OnePixel * 4);
00811 DocRect TopTextRect(TextRect);
00812 DocRect BottomTextRect(TextRect);
00813 INT32 Shift = (TextBoundRect.Height()/2) + (OnePixel * 2);
00814
00815 TopTextRect.lo.y += Shift;
00816 TopTextRect.hi.y += Shift;
00817 BottomTextRect.lo.y -= Shift;
00818 BottomTextRect.hi.y -= Shift;
00819
00820
00821 Renderer->DrawFixedSystemText(&DisplayText, TopTextRect);
00822 if (bIsNew)
00823 {
00824 *camStrchr(DisplayText, _T(' ')) = 0x00;
00825 Renderer->SetFixedSystemTextColours(&red, &RedrawInfo->Background);
00826 Renderer->DrawFixedSystemText(&DisplayText, TopTextRect);
00827 Renderer->SetFixedSystemTextColours(&RedrawInfo->Foreground, &RedrawInfo->Background);
00828 }
00829 Renderer->DrawFixedSystemText(&DisplayText2, BottomTextRect);
00830 }
00831 break;
00832
00833 default:
00834
00835 TextRect.lo.x += (OnePixel * 4);
00836 Renderer->DrawFixedSystemText(&DisplayText, TextRect);
00837 if (bIsNew)
00838 {
00839 *camStrchr(DisplayText, _T(' ')) = 0x00;
00840 Renderer->SetFixedSystemTextColours(&red, &RedrawInfo->Background);
00841 Renderer->DrawFixedSystemText(&DisplayText, TextRect);
00842 Renderer->SetFixedSystemTextColours(&RedrawInfo->Foreground, &RedrawInfo->Background);
00843 }
00844
00845 break;
00846 }
00847 }
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882 BOOL SGLibDisplayItem::GetThumbSize(SGMiscInfo *MiscInfo, DocRect *Rectangle, KernelBitmap *Bitmap,
00883 INT32 *XSize, INT32 *YSize, double *Scale, INT32 *XTrans, INT32 *YTrans, BOOL *Outline)
00884 {
00885 if( MiscInfo == NULL || Bitmap == NULL || Rectangle == NULL || Bitmap->ActualBitmap == NULL
00886 || XSize == NULL || YSize == NULL)
00887 {
00888 ERROR3("SGLibDisplayItem::GetThumbSize given null params");
00889 return FALSE;
00890 }
00891
00892
00893 BitmapInfo Info;
00894 BOOL InfoOK = Bitmap->ActualBitmap->GetInfo( &Info );
00895
00896 if(InfoOK == FALSE)
00897 {
00898 ERROR3("SGLibDisplayItem::GetThumbSize can't get bitmap info - corrupt bitmap ?");
00899 return FALSE;
00900 }
00901
00902 MILLIPOINT BmpWidth = 0;
00903 MILLIPOINT BmpHeight = 0;
00904
00905 INT32 OnePixel = DevicePixels(MiscInfo, 1);
00906
00907 BmpWidth = Info.PixelWidth * OnePixel;
00908 BmpHeight = Info.PixelHeight * OnePixel;
00909
00910 MILLIPOINT BoundWidth = 0;
00911 MILLIPOINT BoundHeight = 0;
00912
00913
00914
00915 BoundWidth = Rectangle->Width();
00916 BoundHeight = Rectangle->Height();
00917
00918 double XScale = (double)BmpWidth / (double)BoundWidth;
00919 double YScale = (double)BmpHeight / (double)BoundHeight;
00920
00921 double TheScale = 1.0;
00922
00923
00924 if(XScale > YScale)
00925 TheScale = XScale;
00926 else
00927 TheScale = YScale;
00928
00929
00930 if(TheScale > 0.8 && TheScale < 1.0)
00931 TheScale = (double)1.0;
00932
00933
00934 if(TheScale == 0)
00935 return FALSE;
00936
00937 *XSize = (INT32)(BmpWidth / TheScale);
00938 *YSize = (INT32)(BmpHeight / TheScale);
00939
00940 if(Scale != NULL)
00941 *Scale = TheScale;
00942
00943 if(XTrans != NULL)
00944 *XTrans = Rectangle->lo.x + ((BoundWidth - ((INT32)(BmpWidth / TheScale))) / 2);
00945
00946 if(YTrans != NULL)
00947 *YTrans = Rectangle->lo.y + ((BoundHeight - ((INT32)(BmpHeight / TheScale))) / 2);
00948
00949 if(Outline != NULL && (XScale/YScale) > 1.6)
00950 *Outline = TRUE;
00951
00952 return TRUE;
00953 }
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980 BOOL SGLibDisplayItem::DrawThumb(RenderRegion *Renderer, SGRedrawInfo *RedrawInfo,
00981 SGMiscInfo *MiscInfo, DocRect *Rectangle, BOOL Background)
00982 {
00983 KernelBitmap *Bitmap = GetDisplayedKernelBitmap(MiscInfo, Background);
00984
00985
00986 if(Bitmap == NULL)
00987 return FALSE;
00988
00989 INT32 XSize = 0;
00990 INT32 YSize = 0;
00991 double Scale = (double)1;
00992 INT32 XTrans = 0;
00993 INT32 YTrans = 0;
00994 BOOL Outline = FALSE;
00995
00996 if(!GetThumbSize(MiscInfo, Rectangle, Bitmap, &XSize, &YSize, &Scale, &XTrans, &YTrans, &Outline))
00997 return FALSE;
00998
00999 DocRect BmpRect(0, 0, XSize, YSize);
01000 BmpRect.Translate(XTrans, YTrans);
01001
01002 #if 0
01003
01004 UINT32 InputBPP = Bitmap->GetBPP();
01005 if(InputBPP >= 24)
01006 {
01007 CDC *pDC = Renderer->GetRenderDC();
01008 INT32 OutputBPP = pDC->GetDeviceCaps(BITSPIXEL);
01009
01010 if(OutputBPP == 8)
01011 {
01012
01013 }
01014 }
01015 #endif
01016
01017
01018 NodeBitmap *DummyBmp = new NodeBitmap();
01019
01020 if(DummyBmp == NULL)
01021 {
01022 ERROR3("SGLibDisplayItem::DrawThumb can't get node bitmap - not enough memory ?");
01023 return FALSE;
01024 }
01025
01026 DummyBmp->SetUpPath();
01027 DummyBmp->CreateShape(BmpRect);
01028 DummyBmp->GetBitmapRef()->SetBitmap(Bitmap);
01029
01030
01031
01032
01033
01034
01035
01036 DummyBmp->Render(Renderer);
01037
01038 delete DummyBmp;
01039
01040
01041 LibDisplayType DType = GetDisplayType(MiscInfo);
01042
01043
01044 switch(DType)
01045 {
01046 case LibDisplay_SmallThumbTextUnder:
01047 case LibDisplay_MediumThumbTextUnder:
01048 case LibDisplay_LargeThumbTextUnder:
01049
01050
01051 if(Outline)
01052 {
01053 INT32 OnePixel = DevicePixels(MiscInfo, 1);
01054
01055 Renderer->SetLineWidth(0);
01056 Renderer->SetLineColour(DocColour(COLOUR_TRANS));
01057 Renderer->SetFillColour(DocColour(COLOUR_GREY));
01058
01059 DocRect TempRect(*Rectangle);
01060 TempRect.Inflate(OnePixel);
01061 TempRect.hi.x = TempRect.lo.x + OnePixel;
01062 Renderer->DrawRect(&TempRect);
01063
01064 TempRect = *Rectangle;
01065 TempRect.Inflate(OnePixel);
01066 TempRect.lo.y = TempRect.hi.y - OnePixel;
01067 Renderer->DrawRect(&TempRect);
01068
01069 TempRect = *Rectangle;
01070 TempRect.Inflate(OnePixel);
01071 TempRect.lo.x = TempRect.hi.x - OnePixel;
01072 Renderer->DrawRect(&TempRect);
01073
01074 TempRect = *Rectangle;
01075 TempRect.Inflate(OnePixel);
01076 TempRect.hi.y = TempRect.lo.y + OnePixel;
01077 Renderer->DrawRect(&TempRect);
01078 }
01079 break;
01080
01081 default:
01082
01083 break;
01084 }
01085
01086
01087 return TRUE;
01088 }
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115 void SGLibDisplayItem::DrawNullBitmapRect(RenderRegion *Renderer, SGMiscInfo *MiscInfo,
01116 DocRect *Rectangle, BOOL Background)
01117 {
01118
01119 if(Renderer == NULL || MiscInfo == NULL || Rectangle == NULL)
01120 {
01121 ERROR3("SGLibDisplayItem::DrawNullBitmapRect null params are BAD");
01122 return;
01123 }
01124
01125
01126
01127
01128
01129 if(!Background)
01130 Renderer->SetFillColour(COLOUR_GREY);
01131 else
01132 {
01133 DocColour NullBitmapColour(230L, 230L, 230L);
01134 Renderer->SetFillColour(NullBitmapColour);
01135 }
01136
01137 GridLockRect(MiscInfo, Rectangle);
01138 Renderer->DrawRect(Rectangle);
01139
01140
01141 INT32 OnePixel = MiscInfo->PixelSize;
01142
01143 Renderer->SetLineWidth(0);
01144 Renderer->SetLineColour(DocColour(COLOUR_TRANS));
01145 Renderer->SetFillColour(DocColour(COLOUR_BLACK));
01146
01147 DocRect TempRect(*Rectangle);
01148 TempRect.hi.x = TempRect.lo.x + OnePixel;
01149 Renderer->DrawRect(&TempRect);
01150
01151 TempRect = *Rectangle;
01152 TempRect.lo.y = TempRect.hi.y - OnePixel;
01153 Renderer->DrawRect(&TempRect);
01154
01155 TempRect = *Rectangle;
01156 TempRect.lo.x = TempRect.hi.x - OnePixel;
01157 Renderer->DrawRect(&TempRect);
01158
01159 TempRect = *Rectangle;
01160 TempRect.hi.y = TempRect.lo.y + OnePixel;
01161 Renderer->DrawRect(&TempRect);
01162
01163 if(!Background)
01164 {
01165
01166
01167 TempRect = *Rectangle;
01168 TempRect.hi.y = TempRect.lo.y + (TempRect.Height() / 2);
01169 TempRect.lo.y = TempRect.hi.y;
01170 GridLockRect(MiscInfo, &TempRect);
01171 TempRect.hi.y += OnePixel;
01172 Renderer->DrawRect(&TempRect);
01173
01174 TempRect = *Rectangle;
01175 TempRect.hi.x = TempRect.lo.x + (TempRect.Width() / 2);
01176 TempRect.lo.x = TempRect.hi.x;
01177 GridLockRect(MiscInfo, &TempRect);
01178 TempRect.hi.x += OnePixel;
01179 Renderer->DrawRect(&TempRect);
01180 }
01181 }
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197
01198
01199
01200
01201
01202
01203
01204 LibDisplayType SGLibDisplayItem::GetDisplayType(SGMiscInfo *MiscInfo)
01205 {
01206 switch(MiscInfo->DisplayMode)
01207 {
01208 case 1:
01209 return LibDisplay_SmallThumbText;
01210 break;
01211 case 2:
01212 return LibDisplay_FullInfo;
01213 break;
01214 case 0:
01215 default:
01216 return LibDisplay_LargeThumbTextUnder;
01217 break;
01218 }
01219
01220 return LibDisplay_LargeThumbTextUnder;
01221 }
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238 void SGLibDisplayItem::GetFileName(String_256 *Result)
01239 {
01240 ERROR3IF(Result == NULL, "SGLibDisplayItem::GetFileName given a NULL param");
01241
01242
01243 Library *Lib = GetParentLibrary();
01244
01245 if (Lib != NULL)
01246 {
01247 Lib->GetFilename(TheLibraryIndex, Result, FALSE);
01248 }
01249 else
01250 {
01251 *Result = "";
01252 }
01253 }
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272 BOOL SGLibDisplayItem::GetFileNamePtr(TCHAR **Result)
01273 {
01274 ERROR3IF(Result == NULL, "SGLibDisplayItem::GetFileName given a NULL param");
01275
01276 BOOL ok = FALSE;
01277
01278
01279 Library *Lib = GetParentLibrary();
01280
01281 if (Lib != NULL)
01282 ok = Lib->GetFilename(TheLibraryIndex, Result);
01283 else
01284 ok = FALSE;
01285
01286 return (ok);
01287 }
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297
01298
01299
01300
01301
01302
01303
01304
01305 void SGLibDisplayItem::GetNameText(String_256 *Result)
01306 {
01307 ERROR3IF(Result == NULL, "SGLibDisplayItem::GetNameText given a NULL param");
01308
01309
01310 Library *Lib = GetParentLibrary();
01311
01312 if (Lib != NULL)
01313 {
01314 if(!Lib->GetTitle(TheLibraryIndex, Result))
01315 Lib->GetFilename(TheLibraryIndex, Result, FALSE);
01316 }
01317 else
01318 {
01319 *Result = "";
01320 }
01321 }
01322
01323
01324
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342 BOOL SGLibDisplayItem::GetNameTextPtr(TCHAR **Result)
01343 {
01344 ERROR3IF(Result == NULL, "SGLibDisplayItem::GetNameText given a NULL param");
01345
01346
01347 Library *Lib = GetParentLibrary();
01348
01349 BOOL ok = FALSE;
01350
01351 if (Lib != NULL)
01352 {
01353 ok = Lib->GetTitle(TheLibraryIndex, Result);
01354 if(!ok)
01355 ok = Lib->GetFilename(TheLibraryIndex, Result);
01356 }
01357
01358 return ok;
01359 }
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377 void SGLibDisplayItem::GetFullInfoText(String_256 *Result)
01378 {
01379
01380 GetFullInfoText(Result, 0);
01381 }
01382
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403 void SGLibDisplayItem::GetFullInfoText(String_256 *Result, INT32 Line)
01404 {
01405 ERROR3IF(Result == NULL, "SGLibDisplayItem::GetFullInfoText given a NULL param");
01406
01407
01408 Library *Lib = GetParentLibrary();
01409
01410 if (Lib == NULL)
01411 {
01412 ERROR3("Lib == NULL in GetFullInfoText");
01413 *Result = "";
01414 }
01415 else
01416 {
01417
01418 *Result = TEXT("");
01419
01420 String_256 Text;
01421
01422
01423 if(Line < 2 && Line >= 0)
01424 {
01425 GetDisplayedTextDescription(&Text);
01426 BOOL FullDescription = (Text.Length() > 0);
01427 *Result = Text;
01428
01429
01430 if(Lib->GetTitle(TheLibraryIndex, &Text))
01431 {
01432 if(FullDescription)
01433 {
01434
01435 String_256 TmpResult;
01436 TmpResult.MakeMsg(_R(IDS_SGLIB_FULLDESCRIPTION), (TCHAR *)Text);
01437 *Result += TmpResult;
01438 }
01439 else
01440 *Result += Text;
01441 }
01442 }
01443
01444
01445
01446
01447
01448 BOOL GiveLineFileName = FALSE;
01449
01450 if((Line == 0) || (Line == 1 && Result->Length() == 0))
01451 GiveLineFileName = TRUE;
01452
01453 if(Line == 2)
01454 {
01455 GiveLineFileName = FALSE;
01456
01457 GetDisplayedTextDescription(&Text);
01458 if(Text.Length() > 0)
01459 GiveLineFileName = TRUE;
01460
01461
01462 if(Lib->GetTitle(TheLibraryIndex, &Text))
01463 if(Text.Length() > 0)
01464 GiveLineFileName = TRUE;
01465 }
01466
01467
01468 if(GiveLineFileName)
01469 {
01470
01471 Lib->GetFilename(TheLibraryIndex, &Text, FALSE);
01472
01473
01474
01475
01476
01477
01478
01479
01480
01481
01482
01483 String_256 FileNameBit;
01484
01485 switch(Line)
01486 {
01487 case 0:
01488 FileNameBit.MakeMsg(_R(IDS_SGLIB_FNAMEBIT_LINE0), (TCHAR *)Text);
01489 break;
01490
01491 case 1:
01492 FileNameBit.MakeMsg(_R(IDS_SGLIB_FNAMEBIT_LINE1), (TCHAR *)Text);
01493 break;
01494
01495 default:
01496 FileNameBit.MakeMsg(_R(IDS_SGLIB_FNAMEBIT_DEFAULT), (TCHAR *)Text);
01497 break;
01498 }
01499
01500 *Result += FileNameBit;
01501 }
01502
01503
01504 if((Line == 0) || (Line == 2))
01505 {
01506 INT32 FileSize = GetFileSize(Lib);
01507 if(Convert::BytesToString(&Text, (UINT32)FileSize))
01508 {
01509 *Result += Text;
01510 }
01511 }
01512 }
01513 }
01514
01515
01516
01517
01518
01519
01520
01521
01522
01523
01524
01525
01526
01527
01528
01529
01530
01531
01532
01533
01534
01535
01536 void SGLibDisplayItem::GetKeyWords(String_256 *Result)
01537 {
01538 ERROR3IF(Result == NULL, "SGLibDisplayItem::GetKeyWords given a NULL param");
01539 if(Result == NULL)
01540 return;
01541
01542 *Result = "";
01543
01544
01545 SuperGallery *Parent = (SuperGallery *)GetParentGallery();
01546
01547 if(Parent != NULL)
01548 {
01549 if(Parent->CanSearchKeywords())
01550 {
01551 Library *Lib = GetParentLibrary();
01552 if (Lib != NULL)
01553 {
01554 String_64 Key(_R(IDS_LIBRARIES_INDEX_ITEM_KEY));
01555 Lib->GetSingleField(TheLibraryIndex, &Key, Result);
01556 }
01557 }
01558 }
01559 }
01560
01561
01562
01563
01564
01565
01566
01567
01568
01569
01570
01571
01572
01573
01574
01575
01576
01577
01578
01579
01580
01581
01582
01583
01584 INT32 SGLibDisplayItem::GetFileSize(Library *Lib)
01585 {
01586
01587 if (Lib == NULL)
01588 Lib = GetParentLibrary();
01589
01590 if (Lib != NULL)
01591 {
01592 String_64 SizeTxt(_R(IDS_LIBRARIES_INDEX_ITEM_SIZE));
01593 String_64 Result;
01594 if(Lib->GetSingleField(TheLibraryIndex, &SizeTxt, &Result))
01595 {
01596 INT32 size = _ttoi((TCHAR *)Result);
01597 if(size > 0)
01598 return size;
01599 }
01600 }
01601
01602
01603
01604 PathName ItemPath;
01605 GetFileName(&ItemPath);
01606 return SGLibOil::FileSize(&ItemPath);
01607 }
01608
01609
01610
01611
01612
01613
01614
01615
01616
01617
01618
01619
01620
01621
01622
01623
01624
01625
01626
01627
01628
01629
01630
01631
01632
01633
01634
01635
01636 BOOL SGLibDisplayItem::GetBubbleHelp(DocCoord *MousePos, String_256 *Result)
01637 {
01638 ERROR3IF(MousePos == NULL || Result == NULL, "Invalid NULL params");
01639
01640 return FALSE;
01641 }
01642
01643
01644
01645
01646
01647
01648
01649
01650
01651
01652
01653
01654
01655
01656
01657
01658
01659
01660
01661
01662
01663
01664
01665
01666
01667
01668
01669
01670
01671
01672 BOOL SGLibDisplayItem::GetStatusLineHelp(DocCoord *MousePos, String_256 *Result)
01673 {
01674 ERROR3IF(MousePos == NULL || Result == NULL, "Invalid NULL params");
01675
01676 GetNameText(Result);
01677
01678
01679 String_32 SizeString;
01680 INT32 FileSize = GetFileSize(NULL);
01681 if(Convert::BytesToString(&SizeString, (UINT32)GetFileSize(NULL)))
01682 {
01683 String_32 TmpStr;
01684 TmpStr.MakeMsg(_R(IDS_SGLIB_STAT_LINE_SIZE), (TCHAR *)SizeString);
01685 *Result += TmpStr;
01686 }
01687
01688
01689 String_256 DClick(_R(IDS_LIBRARY_DOUBLE_CLICK_OPEN));
01690
01691 *Result += String_8(_R(IDS_SGFONTS_STATUS_LINE_SEP));
01692 *Result += DClick;
01693
01694 return(TRUE);
01695 }
01696
01697
01698
01699
01700
01701
01702
01703
01704
01705
01706
01707
01708
01709
01710
01711
01712
01713
01714
01715
01716
01717
01718
01719
01720
01721
01722
01723
01724
01725
01726
01727
01728
01729
01730
01731
01732
01733
01734
01735
01736
01737
01738
01739
01740
01741
01742
01743
01744
01745
01746
01747
01748
01749 BOOL SGLibDisplayItem::HandleEvent(SGEventType EventType, void *EventInfo,
01750 SGMiscInfo *MiscInfo)
01751 {
01752 switch (EventType)
01753 {
01754 case SGEVENT_FORMAT:
01755 {
01756 SGFormatInfo *FormatInfo = GetFormatInfo(EventType, EventInfo);
01757 CalculateMyRect(FormatInfo, MiscInfo);
01758 }
01759 break;
01760
01761
01762 case SGEVENT_REDRAW:
01763 {
01764 DocRect MyRect(FormatRect);
01765 SGRedrawInfo *RedrawInfo = GetRedrawInfo(EventType, EventInfo);
01766
01767 if (IMustRedraw(RedrawInfo))
01768 HandleRedraw(RedrawInfo, MiscInfo);
01769 }
01770 break;
01771
01772
01773 case SGEVENT_MOUSECLICK:
01774 {
01775 SGMouseInfo *Mouse = GetMouseInfo(EventType, EventInfo);
01776
01777 if (FormatRect.ContainsCoord(Mouse->Position))
01778 {
01779
01780 DefaultClickHandler(Mouse, MiscInfo);
01781 return(TRUE);
01782 }
01783 }
01784 break;
01785
01786 default:
01787 return(SGDisplayItem::HandleEvent(EventType, EventInfo, MiscInfo));
01788 break;
01789 }
01790
01791
01792 return(FALSE);
01793 }
01794
01795
01796
01797
01798
01799
01800
01801
01802
01803
01804
01805
01806
01807
01808
01809
01810
01811
01812
01813
01814
01815
01816
01817
01818
01819
01820
01821
01822 BOOL SGLibDisplayItem::StartDrag(SGEventType EventType, void *EventInfo, SGMiscInfo *MiscInfo, INT32 *XSize, INT32 *YSize)
01823 {
01824 SGMouseInfo *Mouse = GetMouseInfo(EventType, EventInfo);
01825
01826 if (Mouse->DoubleClick)
01827 {
01828 DefaultClickHandler(Mouse, MiscInfo);
01829 return FALSE;
01830 }
01831 else
01832 {
01833 DefaultPreDragHandler(Mouse, MiscInfo);
01834
01835
01836 KernelBitmap *DispBmp = GetDisplayedKernelBitmap(MiscInfo, TRUE);
01837 if(DispBmp)
01838 LibraryGallery::TmpDraggingBitmap = DIBUtil::CopyKernelBitmap(DispBmp, TRUE);
01839 else
01840 LibraryGallery::TmpDraggingBitmap = NULL;
01841
01842
01843 Library *ParentLib = GetParentLibrary();
01844 if(ParentLib != 0)
01845 {
01846
01847 SGThumbs *Thumbs = ParentLib->Thumbnails;
01848 if(Thumbs != NULL)
01849 {
01850
01851 SGThumbSize ThumbSize = SGThumb_Large;
01852 if(Thumbs->GetSize(&ThumbSize))
01853 {
01854 *XSize = ParentLib->PreviewBMPWidth(ThumbSize);
01855 *YSize = ParentLib->PreviewBMPHeight(ThumbSize);
01856
01857 if(LibraryGallery::TmpDraggingBitmap != NULL)
01858 {
01859 INT32 OnePixel = (INT32) DevicePixels(MiscInfo, 1);
01860 DocRect Rectangle(0, 0, (*XSize) * OnePixel, (*YSize) * OnePixel);
01861
01862
01863 if(!GetThumbSize(MiscInfo, &Rectangle, LibraryGallery::TmpDraggingBitmap, XSize, YSize))
01864 {
01865 *YSize = 0;
01866 *XSize = 0;
01867 }
01868 else
01869 {
01870
01871 *XSize = (*XSize) / OnePixel;
01872 *YSize = (*YSize) / OnePixel;
01873 }
01874 }
01875 }
01876 }
01877 }
01878 }
01879 return TRUE;
01880 }
01881
01882
01883
01884
01885
01886
01887
01888
01889
01890
01891
01892
01893
01894
01895
01896
01897
01898 Library *SGLibDisplayItem::GetParentLibrary(void)
01899 {
01900 SGDisplayGroup *Parent = (SGDisplayGroup *) GetParent();
01901 if (Parent == NULL)
01902 {
01903 ERROR2RAW("Infeasible gallery display tree structure detected");
01904 return(NULL);
01905 }
01906
01907 Library *ParentLib = Parent->GetParentLibrary();
01908
01909
01910
01911
01912
01913
01914 return(ParentLib);
01915 }
01916
01917
01918
01919
01920
01921
01922
01923
01924
01925
01926
01927
01928
01929
01930
01931
01932
01933
01934
01935
01936
01937
01938 KernelBitmap *SGLibDisplayItem::GetDisplayedKernelBitmap(SGMiscInfo *MiscInfo, BOOL Background)
01939 {
01940 KernelBitmap *BM = NULL;
01941 SGThumbSize Size = SGThumb_Large;
01942
01943
01944 LibDisplayType DType = GetDisplayType(MiscInfo);
01945
01946
01947 switch(DType)
01948 {
01949 case LibDisplay_MediumThumbText:
01950 case LibDisplay_MediumThumbTextUnder:
01951 case LibDisplay_MediumThumb:
01952 case LibDisplay_FullInfo:
01953 case LibDisplay_SingleLineFullInfo:
01954 Size = SGThumb_Medium;
01955 break;
01956
01957 case LibDisplay_SmallThumbText:
01958 case LibDisplay_SmallThumbTextUnder:
01959 case LibDisplay_SmallThumb:
01960 Size = SGThumb_Small;
01961 break;
01962
01963 case LibDisplay_JustText:
01964 return NULL;
01965
01966 default:
01967 Size = SGThumb_Large;
01968 break;
01969 }
01970
01971
01972 Library *Lib = GetParentLibrary();
01973
01974
01975
01976 BOOL GotIt = FALSE;
01977
01978 if (Lib != NULL)
01979 GotIt = Lib->GetThumbnail(TheLibraryIndex, Size, Background, &BM);
01980
01981 if(GotIt)
01982 return(BM);
01983 else
01984 return NULL;
01985 }
01986
01987
01988
01989
01990
01991
01992
01993
01994
01995
01996
01997
01998
01999
02000
02001
02002
02003
02004 BOOL SGLibDisplayItem::GetDisplayedTextDescription(String_256 *Result)
02005 {
02006 ERROR3IF(Result == NULL,
02007 "SGLibDisplayItem::GetDisplayedTextDescription - NULL param is illegal");
02008
02009 BOOL ok = FALSE;
02010
02011 Library *Lib = GetParentLibrary();
02012
02013
02014 if (Lib != NULL)
02015 ok = Lib->GetTextname(TheLibraryIndex, Result);
02016
02017
02018 if(!ok)
02019 *Result = TEXT("");
02020
02021 return ok;
02022 }
02023
02024
02025
02026
02027
02028
02029
02030
02031
02032
02033
02034
02035
02036
02037
02038
02039
02040
02041
02042 BOOL SGLibDisplayItem::GetDisplayedTextDescription(TCHAR **Result)
02043 {
02044 ERROR3IF(Result == NULL,
02045 "SGLibDisplayItem::GetDisplayedTextDescription - NULL param is illegal");
02046 Library *Lib = GetParentLibrary();
02047
02048
02049 if (Lib != NULL)
02050 return(Lib->GetTextname(TheLibraryIndex, Result));
02051
02052 return(FALSE);
02053 }
02054
02055
02056
02057
02058
02059
02060
02061
02062
02063
02064
02065
02066
02067
02068
02069
02070 BOOL SGLibDisplayItem::GetFileName(PathName *Result)
02071 {
02072 ERROR3IF(Result == NULL,
02073 "SGLibDisplayItem::GetFileName - NULL param is illegal");
02074 Library *Lib = GetParentLibrary();
02075
02076 Result->SetPathName(String_8(""), FALSE);
02077
02078
02079
02080 if (Lib != NULL)
02081 {
02082 String_256 TmpPath;
02083 BOOL ok = Lib->GetFilename(TheLibraryIndex, &TmpPath, TRUE);
02084 Result->SetPathName(TmpPath);
02085
02086
02087 if(!ok && !Result->IsValid())
02088 ok = FALSE;
02089 return ok;
02090 }
02091
02092 return FALSE;
02093 }
02094
02095
02096
02097
02098
02099
02100
02101
02102
02103
02104
02105
02106
02107
02108
02109
02110
02111
02112
02113
02114
02115
02116
02117
02118
02119 BOOL SGLibDisplayItem::GetActualDisplayedText(String_256 *String, INT32 Line)
02120 {
02121 ERROR3IF(String == NULL, "SGLibDisplayItem::GetActualDisplayedText with params is a real recipe for disaster");
02122
02123
02124 SGMiscInfo MiscInfo;
02125 SuperGallery *ParentGal = GetParentGallery();
02126 ERROR3IF(ParentGal == NULL, "SGLibDisplayItem::GetActualDisplayedText with null parent gallery");
02127 MiscInfo.DisplayMode = ParentGal->GetDisplayMode();
02128 LibDisplayType DType = GetDisplayType(&MiscInfo);
02129
02130
02131 switch(DType)
02132 {
02133 case LibDisplay_FullInfo:
02134 case LibDisplay_SingleLineFullInfo:
02135
02136 GetFullInfoText(String, Line);
02137 break;
02138
02139 default:
02140
02141 GetNameText(String);
02142 break;
02143 }
02144
02145 return TRUE;
02146 }
02147
02148
02149
02150
02151
02152
02153
02154
02155
02156
02157
02158
02159
02160
02161
02162
02163
02164
02165
02166
02167
02168
02169 BOOL SGLibDisplayItem::GetActualDisplayedTextPtr(TCHAR **String, INT32 Line)
02170 {
02171 ERROR3IF(String == NULL, "SGLibDisplayItem::GetActualDisplayedText with params is a real recipe for disaster");
02172
02173
02174 SGMiscInfo MiscInfo;
02175 SuperGallery *ParentGal = GetParentGallery();
02176 ERROR3IF(ParentGal == NULL, "SGLibDisplayItem::GetActualDisplayedText with null parent gallery");
02177 MiscInfo.DisplayMode = ParentGal->GetDisplayMode();
02178 LibDisplayType DType = GetDisplayType(&MiscInfo);
02179
02180
02181 switch(DType)
02182 {
02183 case LibDisplay_FullInfo:
02184 case LibDisplay_SingleLineFullInfo:
02185
02186 return FALSE;
02187
02188 default:
02189
02190 return GetNameTextPtr(String);
02191 }
02192
02193 return FALSE;
02194 }
02195
02196
02197
02198
02199
02200
02201
02202
02203
02204
02205
02206
02207
02208
02209
02210
02211
02212
02213
02214
02215
02216
02217
02218
02219
02220
02221
02222
02223
02224 INT32 SGLibDisplayItem::CompareTo(SGDisplayNode *Other, INT32 SortKey)
02225 {
02226 switch(SortKey)
02227 {
02228 case 1:
02229
02230
02231
02232 {
02233 BOOL FoundPtr = FALSE;
02234
02235 #ifndef _BATCHING
02236
02237
02238 TCHAR *pOurName = NULL;
02239 TCHAR *pTheirName = NULL;
02240 FoundPtr = GetActualDisplayedTextPtr(&pOurName);
02241 if(FoundPtr)
02242 {
02243 FoundPtr = ((SGLibDisplayItem *)Other)->GetActualDisplayedTextPtr(&pTheirName);
02244 if(FoundPtr)
02245 {
02246
02247 INT32 Value = 0;
02248
02249
02250
02251
02252
02253
02254 Value = CompareString(LOCALE_USER_DEFAULT,
02255 (NORM_IGNORECASE | NORM_IGNOREKANATYPE | NORM_IGNOREWIDTH),
02256 pOurName, -1, pTheirName, -1);
02257 Value -= 2;
02258
02259 return (Value);
02260 }
02261 }
02262
02263
02264 String_256 MyName;
02265 String_256 ItsName;
02266
02267 GetActualDisplayedText(&MyName);
02268 MyName.toLower();
02269 ((SGLibDisplayItem *)Other)->GetActualDisplayedText(&ItsName);
02270 ItsName.toLower();
02271
02272 return(MyName.CompareTo(ItsName));
02273 #else
02274
02275 String_256 MyName;
02276 String_256 ItsName;
02277
02278 GetActualDisplayedText(&MyName);
02279 MyName.toLower();
02280 ((SGLibDisplayItem *)Other)->GetActualDisplayedText(&ItsName);
02281 ItsName.toLower();
02282
02283 if(Library::MaxFieldCacheEntries == 50 && MyName == ItsName)
02284 {
02285 ERROR3_PF(("Identical sort entries found: '%s'", (TCHAR *)MyName));
02286 }
02287
02288 INT32 FSize = GetFileSize(NULL);
02289 if(FSize == 0)
02290 {
02291 ERROR3_PF(("Filesize <= 0 found: '%s'", (TCHAR *)MyName));
02292 }
02293
02294 INT32 MRCount = MyName.Length() - 1;
02295 BOOL MFound = FALSE;
02296 TCHAR TheChar = ((TCHAR *)MyName)[MRCount];
02297
02298 while(((TheChar == ' ') || (TheChar >= '0' && TheChar <= '9')) && MRCount > 0)
02299 {
02300 if(TheChar != ' ')
02301 MFound = TRUE;
02302 TheChar = ((TCHAR *)MyName)[--MRCount];
02303 }
02304
02305 INT32 IRCount = ItsName.Length() - 1;
02306 BOOL IFound = FALSE;
02307 TheChar = ((TCHAR *)ItsName)[IRCount];
02308
02309 while(((TheChar == ' ') || (TheChar >= '0' && TheChar <= '9')) && IRCount > 0)
02310 {
02311 if(TheChar != ' ')
02312 IFound = TRUE;
02313 TheChar = ((TCHAR *)ItsName)[--IRCount];
02314 }
02315
02316 if(IFound && MFound)
02317 {
02318 String_256 MyLeft;
02319 String_256 ItsLeft;
02320
02321 MyName.Left(&MyLeft, MRCount + 1);
02322 ItsName.Left(&ItsLeft, IRCount + 1);
02323
02324 if(MyLeft == ItsLeft)
02325 {
02326 String_256 MyRight;
02327 String_256 ItsRight;
02328
02329 MyName.Right(&MyRight, MyName.Length() - MRCount - 1);
02330 ItsName.Right(&ItsRight, ItsName.Length() - IRCount - 1);
02331
02332 INT32 Me = _ttoi((TCHAR *)MyRight);
02333 INT32 It = _ttoi((TCHAR *)ItsRight);
02334
02335 if(Me > It)
02336 return 1;
02337 else if(Me < It)
02338 return -1;
02339 }
02340 }
02341
02342 return(MyName.CompareTo(ItsName, FALSE));
02343 #endif
02344 }
02345 case 2:
02346
02347 {
02348 Library *Lib = GetParentLibrary();
02349 return(GetFileSize(Lib) - ((SGLibDisplayItem *)Other)->GetFileSize(Lib));
02350 }
02351
02352 case 3:
02353
02354 {
02355 String_256 MyName;
02356 String_256 ItsName;
02357
02358 GetActualDisplayedText(&MyName);
02359 ((SGLibDisplayItem *)Other)->GetActualDisplayedText(&ItsName);
02360
02361 return (MyName.Length() - ItsName.Length());
02362 }
02363 break;
02364
02365 case 4:
02366
02367 {
02368 PathName MyPath;
02369 PathName ItsPath;
02370
02371 GetFileName(&MyPath);
02372 ((SGLibDisplayItem *)Other)->GetFileName(&ItsPath);
02373
02374 Error::ClearError();
02375
02376 if(MyPath.IsValid() && ItsPath.IsValid())
02377 {
02378 String_8 MyType(MyPath.GetType());
02379 String_8 ItsType(ItsPath.GetType());
02380
02381 return(MyType.CompareTo(ItsType, FALSE));
02382 }
02383 }
02384 break;
02385 }
02386 return (SGDisplayNode::CompareTo(Other, SortKey));
02387 }
02388
02389
02390
02391
02392
02393
02394
02395
02396
02397
02398
02399
02400
02401
02402
02403
02404
02405
02406
02407
02408
02409 void SGLibDisplayItem::DragWasReallyAClick(SGMouseInfo *Mouse, SGMiscInfo *MiscInfo)
02410 {
02411
02412 DefaultClickHandler(Mouse, MiscInfo, TRUE);
02413 }
02414
02415
02416
02417
02418
02419
02420
02421
02422
02423
02424
02425
02426
02427
02428
02429
02430
02431
02432
02433
02434
02435
02436
02437
02438
02439
02440 SGLibGroup::SGLibGroup(SuperGallery *ParentGal,
02441 Document *ParentDoc, Library *ParentLib)
02442 : SGDisplayGroup(ParentGal, ParentDoc, ParentLib)
02443 {
02444
02445 Flags.CanSelect = TRUE;
02446
02447 SetVirtualisedState(FALSE);
02448 }
02449
02450
02451
02452
02453
02454
02455
02456
02457
02458
02459
02460
02461
02462
02463 void SGLibGroup::ReadGroupTitle(void)
02464 {
02465 }
02466
02467
02468
02469
02470
02471
02472
02473
02474
02475
02476
02477
02478
02479
02480
02481
02482
02483
02484
02485
02486
02487
02488
02489
02490
02491
02492
02493
02494
02495
02496
02497
02498
02499
02500
02501 BOOL SGLibGroup::HandleEvent(SGEventType EventType, void *EventInfo, SGMiscInfo *MiscInfo)
02502 {
02503 switch (EventType)
02504 {
02505 case SGEVENT_THUMBMSG:
02506 {
02507 ThumbMessage *Msg = (ThumbMessage *) EventInfo;
02508 if(Msg != NULL)
02509 {
02510 switch (Msg->State)
02511 {
02512
02513 case ThumbMessage::ThumbState::CACHESIZECHANGED:
02514 {
02515 Library *TheLib = GetParentLibrary();
02516
02517 if(TheLib == NULL)
02518 {
02519 ERROR3("SGLibGroup::HandleEvent Library == NULL for library group - bad !!!");
02520 }
02521 else
02522 {
02523
02524 SGThumbs *Thumbs = TheLib->Thumbnails;
02525
02526 if(Thumbs != NULL)
02527 {
02528
02529 PathName OldPath(*(Thumbs->GetDirectory()));
02530 SGLibType OldType = Thumbs->GetType();
02531 SGThumbSize OldSize;
02532 Thumbs->GetSize(&OldSize);
02533
02534
02535 SGThumbs::MaxThumbnails = Msg->NewSize;
02536
02537
02538 delete Thumbs;
02539
02540
02541 Thumbs = new SGThumbs(&OldPath, OldType, OldSize);
02542
02543
02544 TheLib->Thumbnails = Thumbs;
02545 }
02546 }
02547 }
02548 break;
02549
02550 case ThumbMessage::ThumbState::KILLCACHE:
02551 {
02552 Library *TheLib = GetParentLibrary();
02553
02554 if(TheLib == NULL)
02555 {
02556 ERROR3("SGLibGroup::HandleEvent Library == NULL for library group - bad !!!");
02557 }
02558 else
02559 {
02560
02561 SGThumbs *Thumbs = TheLib->Thumbnails;
02562
02563 if(Thumbs != NULL)
02564 {
02565 if(Thumbs->GetType() == Msg->Type)
02566 {
02567
02568 Thumbs->DeleteThumbnails();
02569 }
02570 }
02571 }
02572 }
02573 break;
02574 }
02575 }
02576 }
02577 break;
02578 }
02579
02580
02581 return SGDisplayGroup::HandleEvent(EventType, EventInfo, MiscInfo);
02582 }
02583
02584
02585
02586
02587
02588
02589
02590
02591
02592
02593
02594
02595
02596
02597
02598
02599
02600
02601
02602
02603
02604
02605
02606
02607
02608
02609
02610
02611
02612
02613 BOOL SGLibGroup::GetBubbleHelp(DocCoord *MousePos, String_256 *Result)
02614 {
02615 ERROR3IF(MousePos == NULL || Result == NULL, "Invalid NULL params");
02616
02617 return FALSE;
02618 }
02619
02620
02621
02622
02623
02624
02625
02626
02627
02628
02629
02630
02631
02632
02633
02634
02635
02636
02637
02638
02639
02640
02641
02642
02643
02644
02645
02646
02647
02648
02649 BOOL SGLibGroup::GetStatusLineHelp(DocCoord *MousePos, String_256 *Result)
02650 {
02651 ERROR3IF(MousePos == NULL || Result == NULL, "Invalid NULL params");
02652
02653 if(MousePos->x <= GROUP_BAR_ICON_WIDTH)
02654 {
02655 if(Flags.Folded)
02656
02657 Result->MakeMsg(_R(IDS_LIBRARY_FOLDER_CLICK_TO_OPEN));
02658 else
02659
02660 Result->MakeMsg(_R(IDS_LIBRARY_FOLDER_CLICK_TO_CLOSE));
02661 }
02662 else
02663 {
02664 if(Flags.Selected)
02665 {
02666
02667 Result->MakeMsg(_R(IDS_LIBRARY_SECTION_CLICK_SELECTED));
02668 *Result += String_8(_R(IDS_SGFONTS_STATUS_LINE_SEP));
02669 }
02670 else if(Flags.CanSelect)
02671 {
02672
02673 Result->MakeMsg(_R(IDS_LIBRARY_SECTION_CLICK_DESELECTED));
02674 *Result += String_8(_R(IDS_SGFONTS_STATUS_LINE_SEP));
02675 }
02676
02677 String_256 DClick;
02678 if(Flags.Folded)
02679
02680 DClick.MakeMsg(_R(IDS_LIBRARY_SECTION_DCLICK_TO_OPEN));
02681 else
02682
02683 DClick.MakeMsg(_R(IDS_LIBRARY_SECTION_DCLICK_TO_CLOSE));
02684
02685 *Result += DClick;
02686 }
02687 return(TRUE);
02688 }
02689
02690
02691
02692
02693
02694
02695
02696
02697
02698
02699
02700
02701
02702
02703
02704
02705 BOOL SGLibGroup::CanVirtualise(void)
02706 {
02707 return SGLibGroup::LibraryVirtualisingEnabled;
02708 }
02709
02710
02711
02712
02713
02714
02715
02716
02717
02718
02719
02720
02721
02722
02723 BOOL SGLibGroup::DeVirtualise(void)
02724 {
02725 if(!IsVirtualised())
02726 return TRUE;
02727
02728
02729 Progress ProgMsg(_R(IDS_GALLERY_PREPARE_FOR_UNFOLD), -1);
02730 ParentLibrary->ProgressBar = &ProgMsg;
02731
02732 INT32 Count = ParentLibrary->CreateItems();
02733
02734 #ifdef _DEBUG
02735 ForceRedrawOfMyselfAndChildren();
02736 #endif
02737
02738 ParentLibrary->ProgressBar = NULL;
02739
02740 return (Count > 0);
02741 }
02742
02743
02744
02745
02746
02747
02748
02749
02750
02751
02752
02753
02754
02755
02756
02757
02758
02759 BOOL SGLibDisplayItem::ShouldDownloadThumb()
02760 {
02761 Library* pLibrary = GetParentLibrary();
02762 ERROR2IF(!pLibrary, FALSE, "Illegal NULL pointer");
02763
02764 String_256 thumbPath;
02765 if (pLibrary->IsWebLibrary())
02766 {
02767 GetThumbFileName(&thumbPath);
02768 return (_access((TCHAR*) thumbPath, 0) == -1 && !IsDownloadingThumb() &&
02769 (!((LibraryGallery*) GetParentGallery())->IsThumbDownloadingSuspended()) &&
02770 !OpThumbDownload::GetLastError(this));
02771 }
02772 else
02773 {
02774 return FALSE;
02775 }
02776 }
02777
02778
02779
02780
02781
02782
02783
02784
02785
02786
02787
02788
02789
02790
02791
02792
02793
02794 BOOL SGLibDisplayItem::DownloadThumbnail()
02795 {
02796 nPercentageDownloaded = 0;
02797 OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(CC_RUNTIME_CLASS(OpThumbDownload));
02798 if (pOpDesc != NULL)
02799 {
02800 ThumbDownloadParam* Param = new ThumbDownloadParam;
02801 ERROR3IF(!Param, "Memory allocation error");
02802 Param->pItem = this;
02803 Param->type = GetParentLibrary()->GetType();
02804
02805 pOpDesc->Invoke((OpParam*) Param);
02806 if (Param->bSuccess)
02807 {
02808 pDownloadOp = Param->pOp;
02809 bIsDownloadingThumb = TRUE;
02810 return TRUE;
02811 }
02812 }
02813 return FALSE;
02814 }
02815
02816
02817
02818
02819
02820
02821
02822
02823
02824
02825
02826
02827
02828
02829
02830
02831
02832
02833
02834
02835
02836 void SGLibDisplayItem::OnThumbDownloadComplete()
02837 {
02838 bIsDownloadingThumb = FALSE;
02839 ForceRedrawOfMyself();
02840 GetParentGallery()->PaintListNow();
02841 pDownloadOp = NULL;
02842 }
02843
02844
02845
02846
02847
02848
02849
02850
02851
02852
02853
02854
02855
02856
02857
02858
02859
02860
02861 void SGLibDisplayItem::OnThumbDownloadProgress(const INT32 nPercentageCompleted)
02862 {
02863 nPercentageDownloaded = nPercentageCompleted;
02864 ForceRedrawOfMyself(FALSE);
02865 GetParentGallery()->PaintListNow();
02866 }
02867
02868
02869
02870
02871
02872
02873
02874
02875
02876
02877
02878
02879
02880
02881
02882
02883
02884
02885
02886
02887
02888
02889
02890
02891
02892
02893
02894
02895 void SGLibDisplayItem::DrawPlaceholder(RenderRegion *Renderer, SGMiscInfo *MiscInfo,
02896 DocRect *Rectangle, BOOL Background)
02897 {
02898 if (Renderer == NULL || MiscInfo == NULL || Rectangle == NULL)
02899 {
02900 ERROR3("Illegal NULL pointer");
02901 return;
02902 }
02903 #ifdef _WIN32
02904 if (Background)
02905 {
02906 DocColour NullBitmapColour(230L, 230L, 230L);
02907 Renderer->SetFillColour(NullBitmapColour);
02908 GridLockRect(MiscInfo, Rectangle);
02909 Renderer->DrawRect(Rectangle);
02910 INT32 OnePixel = MiscInfo->PixelSize;
02911 Renderer->SetLineWidth(0);
02912 Renderer->SetLineColour(DocColour(COLOUR_TRANS));
02913 Renderer->SetFillColour(DocColour(COLOUR_BLACK));
02914 DocRect TempRect(*Rectangle);
02915 TempRect.hi.x = TempRect.lo.x + OnePixel;
02916 Renderer->DrawRect(&TempRect);
02917 TempRect = *Rectangle;
02918 TempRect.lo.y = TempRect.hi.y - OnePixel;
02919 Renderer->DrawRect(&TempRect);
02920 TempRect = *Rectangle;
02921 TempRect.lo.x = TempRect.hi.x - OnePixel;
02922 Renderer->DrawRect(&TempRect);
02923 TempRect = *Rectangle;
02924 TempRect.hi.y = TempRect.lo.y + OnePixel;
02925 Renderer->DrawRect(&TempRect);
02926 if (IsDownloadingThumb())
02927 {
02928 String_32 strLabel(GetStringField(0, _R(IDS_LOADINGTHUMB)));
02929 DocRect rcText;
02930 Renderer->DrawFixedSystemText(&strLabel, rcText, FORMAT_NOPREFIX | FORMAT_CALCRECT | FORMAT_SINGLELINE | FORMAT_CENTER | FORMAT_VCENTER);
02931 if (rcText.Width() >= Rectangle->Width())
02932 {
02933 camSprintf((TCHAR*) strLabel, _T("%s%d%%"), (TCHAR*) (String_256) GetStringField(1, _R(IDS_LOADINGTHUMB)), nPercentageDownloaded);
02934
02935 Renderer->DrawFixedSystemText(&strLabel, rcText, FORMAT_NOPREFIX | FORMAT_CALCRECT);
02936 DocRect rcAdjusted = *Rectangle;
02937 rcAdjusted.hi.y -= ((rcAdjusted.hi.y - rcAdjusted.lo.y) - (rcText.hi.y - rcText.lo.y))/2;
02938 Renderer->DrawFixedSystemText(&strLabel, rcAdjusted, FORMAT_NOPREFIX | FORMAT_CENTER);
02939 }
02940 else
02941 {
02942 camSprintf((TCHAR*) strLabel, _T("%s%d%%"), (TCHAR*) (String_256) GetStringField(2, _R(IDS_LOADINGTHUMB)), nPercentageDownloaded);
02943 Renderer->DrawFixedSystemText(&strLabel, *Rectangle, FORMAT_NOPREFIX | FORMAT_SINGLELINE | FORMAT_CENTER | FORMAT_VCENTER);
02944 }
02945 }
02946 }
02947 else
02948 {
02949 DrawNullBitmapRect(Renderer, MiscInfo, Rectangle, Background);
02950 }
02951 #else
02952 DrawNullBitmapRect(Renderer, MiscInfo, Rectangle, Background);
02953 #endif
02954 }
02955
02956
02957
02958
02959
02960
02961
02962
02963
02964
02965
02966
02967
02968
02969
02970
02971
02972
02973
02974 BOOL SGLibDisplayItem::GetThumbFileName(String_256* path)
02975 {
02976 PathName filePath;
02977 GetFileName(&filePath);
02978 Library* pLibrary = GetParentLibrary();
02979 if (!pLibrary)
02980 {
02981 ERROR3("Ilegal NULL pointer!");
02982 return FALSE;
02983 }
02984 if (!pLibrary->IsWebLibrary())
02985 {
02986 ERROR3("This function should only be called for web folders");
02987 return FALSE;
02988 }
02989 PathName indexPath(*(pLibrary->ReturnIndexLocation()));
02990 String_256 thumbPath(indexPath.GetLocation());
02991 thumbPath += filePath.GetFileName(FALSE);
02992 thumbPath += _T(".png");
02993 *path = thumbPath;
02994 return TRUE;
02995 }
02996
02997
02998
02999
03000