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 #include "camtypes.h"
00100
00101
00102
00103
00104 #if !defined(EXCLUDE_FROM_XARLIB)
00105 #include "cartctl.h"
00106 #include "drawctl.h"
00107 #include "colourmat.h"
00108 #endif
00109
00110
00111
00112
00113 #define PRELOAD_BITMAPS 0
00114
00115 CC_IMPLEMENT_DYNCREATE(CamResource, CCObject)
00116
00117
00118 #define new CAM_DEBUG_NEW
00119
00120 ResIDToString * CamResource::pHash = NULL;
00121 ResIDToString * CamResource::pObjectNameHash = NULL;
00122 wxFileSystem * CamResource::pwxFileSystem = NULL;
00123 wxBitmap * CamResource::pSplashBitmap= NULL;
00124 wxAdvSplashScreen * CamResource::pSplashScreen = NULL;
00125 wxString * CamResource::pResourcePath = NULL;
00126 CamResourceRemember * CamResource::pFirstRemember=NULL;
00127 BOOL CamResource::HaveCheckedResourcePath = FALSE;
00128 wxLocale * CamResource::m_pLocale = NULL;
00129 wxHelpProvider * CamResource::m_pHelpProvider = NULL;
00130 BOOL CamResource::s_GenerateXRCCheck = FALSE;
00131
00132 ResourceStringToBitmap * CamResource::pBitmapHash = NULL;
00133
00134 TCHAR * CamResource::DefaultString = _T("[Resource string not found]");
00135 TCHAR * CamResource::DefaultObjectName = _T("[Object name not Found]");
00136
00137 wxArrayString CamResource::BitmapExtensions;
00138
00139 #if 0
00140 #if !defined(EXCLUDE_FROM_XARLIB)
00141
00142 wxImage imageBevelTool;
00143 wxImage imageBezTool;
00144 wxImage imageBlendTool;
00145 wxImage imageContourTool;
00146 wxImage imageElipTool;
00147 wxImage imageFHandTool;
00148 wxImage imageGradTool;
00149 wxImage imageLiveEffectTool;
00150 wxImage imageMouldTool;
00151 wxImage imagePenTool;
00152 wxImage imagePush;
00153 wxImage imageRectTool;
00154 wxImage imageRegShapeTool;
00155 wxImage imageSelTool;
00156 wxImage imageShadrwTool;
00157 wxImage imageSlicetool;
00158 wxImage imageTextTool;
00159 wxImage imageTransTool;
00160 wxImage imageZoomTool;
00161 #endif
00162 #endif
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247 #define CRFNH_BUCKETS 1024
00248
00249 class CamResourceFixNameEntry
00250 {
00251 public:
00252 static UINT32 MakeHash(const TCHAR * k)
00253 {
00254 UINT32 hash = 0;
00255
00256 while( *k )
00257 {
00258 hash += *k++;
00259 hash += (hash << 10);
00260 hash ^= (hash >> 6);
00261 }
00262 hash += (hash << 3);
00263 hash ^= (hash >> 11);
00264
00265 return (hash + (hash << 15)) % CRFNH_BUCKETS;
00266 }
00267
00268 typedef CamResourceFixNameEntry * pCamResourceFixNameEntry;
00269
00270 static const TCHAR * Find(const TCHAR * from, const TCHAR * to = NULL)
00271 {
00272
00273 if (!pArray)
00274 {
00275 pArray=new pCamResourceFixNameEntry[CRFNH_BUCKETS];
00276 UINT32 i;
00277 for (i=0; i<CRFNH_BUCKETS; i++) pArray[i]=NULL;
00278 }
00279 if (!pArray) return from;
00280 UINT32 h = MakeHash(from);
00281 pCamResourceFixNameEntry * pPoint = &(pArray[h]);
00282 while (*pPoint)
00283 {
00284 if (!camStrcmp( (*pPoint)->MapFrom, from ) ) return ( (*pPoint)->MapTo );
00285 pPoint = &((*pPoint)->pNext);
00286 }
00287
00288
00289 if (!to) return from;
00290
00291 *pPoint = new(CamResourceFixNameEntry);
00292 if (*pPoint)
00293 {
00294
00295
00296 (*pPoint)->MapFrom = from;
00297 (*pPoint)->MapTo = to;
00298 }
00299 return to;
00300 }
00301
00302 static void MakeResources()
00303 {
00304 if (pArray)
00305 {
00306 INT32 i;
00307 for (i=0; i<CRFNH_BUCKETS; i++)
00308 {
00309 pCamResourceFixNameEntry p=pArray[i];
00310 while (p)
00311 {
00312 CamResource::GetResourceID(p->MapFrom);
00313 p = p->pNext;
00314 }
00315 }
00316 }
00317 }
00318
00319 const TCHAR * MapFrom;
00320 const TCHAR * MapTo;
00321 CamResourceFixNameEntry * pNext;
00322
00323 static pCamResourceFixNameEntry *pArray;
00324
00325 CamResourceFixNameEntry() {MapFrom =NULL ; MapTo = NULL ; pNext = NULL;}
00326 };
00327
00328 CamResourceFixNameEntry::pCamResourceFixNameEntry *CamResourceFixNameEntry::pArray = NULL;
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352 #define FNOMAP(x,y) CamResourceFixNameEntry::Find(_T(x),_T(y))
00353
00354 const TCHAR * CamResource::FixObjectName(const TCHAR * ObjectName)
00355 {
00356 if (!CamResourceFixNameEntry::pArray)
00357 {
00358
00359 FNOMAP("IDOK", "wxID_OK");
00360 FNOMAP("IDCANCEL", "wxID_CANCEL");
00361 FNOMAP("IDAPPLY", "wxID_APPLY");
00362 FNOMAP("ID_APPLY_NOW", "wxID_APPLY");
00363 FNOMAP("ID_CC_APPLY_NOW", "wxID_APPLY");
00364 FNOMAP("ID_FILE_OPEN", "wxID_OPEN");
00365 FNOMAP("ID_FILE_CLOSE", "wxID_CLOSE");
00366 FNOMAP("ID_FILE_SAVE", "wxID_SAVE");
00367 FNOMAP("ID_FILE_SAVE_AS", "wxID_SAVEAS");
00368 FNOMAP("ID_APP_EXIT", "wxID_EXIT");
00369 FNOMAP("ID_FILE_PRINT", "wxID_PRINT");
00370 FNOMAP("ID_FILE_PRINT_PREVIEW", "wxID_PREVIEW");
00371 FNOMAP("ID_FILE_PRINT_SETUP", "wxID_PRINT_SETUP");
00372 FNOMAP("ID_APP_ABOUT", "wxID_ABOUT");
00373 FNOMAP("ID_EDIT_UNDO", "wxID_UNDO");
00374 FNOMAP("ID_EDIT_CUT", "wxID_CUT");
00375 FNOMAP("ID_EDIT_COPY", "wxID_COPY");
00376 FNOMAP("ID_EDIT_PASTE", "wxID_PASTE");
00377 FNOMAP("IDYES", "wxID_YES");
00378 FNOMAP("IDNO", "wxID_NO");
00379 FNOMAP("IDHELP", "wxID_HELP");
00380
00381 CamResourceFixNameEntry::MakeResources();
00382 }
00383 const TCHAR * ret= CamResourceFixNameEntry::Find(ObjectName);
00384 if (pObjectNameHash && ret !=ObjectName)
00385 {
00386 TRACEUSER("amb",_T("**Mapped %s to %s"),ObjectName,ret);
00387 }
00388 return ret;
00389 }
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413 void CamResource::RememberDuringStaticInit(const TCHAR * ObjectName)
00414 {
00415 TCHAR * text = camStrdup(ObjectName);
00416 if (!text) return;
00417 CamResourceRemember * pRem = new CamResourceRemember;
00418 if (!pRem) return;
00419
00420 pRem->text = text;
00421
00422
00423 pRem->next = pFirstRemember?pFirstRemember:NULL;
00424 pFirstRemember=pRem;
00425 return;
00426 }
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449 void CamResource::AddStringResource(const TCHAR * name, const TCHAR * text, ResourceID r)
00450 {
00451 ResourceID r2=GetResourceID(name);
00452 if (r)
00453 {
00454 if (r != r2)
00455 {
00456 TRACE(_T("Possible duplicate label %s\n"),text);
00457 }
00458 }
00459 else
00460 {
00461 r = r2;
00462 }
00463
00464 if (!name || !text)
00465 {
00466 TRACE(_T("Resource ID %d is blank\n"),r);
00467 ERROR3("Resource is blank");
00468 }
00469 else
00470 {
00471 ResIDToString::iterator i=pHash->find(r);
00472 if (i!=pHash->end())
00473 {
00474 TRACE(_T("Resource ID %d name <%s> has duplicate definitions: <%s> and <%s>\n"),r,name,text,i->second);
00475 }
00476 else
00477 {
00478 const TCHAR * tcopy = camStrdup(text);
00479 (*pHash)[r] = tcopy;
00480
00481 const TCHAR * t = GetText(r);
00482 if (t!=tcopy)
00483 {
00484 ERROR3("Resource string does not match local copy");
00485 }
00486 }
00487 }
00488 }
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508 BOOL CamResource::ReadStringTableFile()
00509 {
00510 TRACET(_T("ReadStringTableFile() called"));
00511 CamResource res;
00512 INT32 count=0;
00513
00514 wxFSFile* f = res.OpenwxFSFile(_T("strings.lst"));
00515 if (!f)
00516 {
00517 TRACE(_T("Could not load strings.lst"));
00518 return FALSE;
00519 }
00520
00521 wxInputStream * s = f->GetStream();
00522 if (!s)
00523 {
00524 TRACE(_T("Could not load strings.lst - no stream"));
00525 return FALSE;
00526 }
00527
00528 while (!s->Eof())
00529 {
00530 #define MAX_TAG_LENGTH 1024
00531 char buf[MAX_TAG_LENGTH];
00532
00533 char c=0;
00534 INT32 l=0;
00535 while (!s->Eof() && (c=s->GetC()) && (c != '\n') && (c != '\t') && (l<MAX_TAG_LENGTH))
00536 {
00537 buf[l++]=c;
00538 }
00539 buf[l++]=0;
00540 buf[MAX_TAG_LENGTH-1]=0;
00541 if (buf[0])
00542 {
00543 wxString name(buf, wxConvUTF8);
00544
00545 if (c == '\n')
00546 {
00547 buf[0]=0;
00548 }
00549 else
00550 {
00551 l=0;
00552 while (!s->Eof() && (c=s->GetC()) && (c != '\n') && (l<MAX_TAG_LENGTH))
00553 {
00554 buf[l++]=c;
00555 }
00556 buf[MAX_TAG_LENGTH-1]=0;
00557 }
00558 buf[l++]=0;
00559 wxString text(buf, wxConvUTF8);
00560
00561
00562 wxString otext;
00563 UINT32 n=0;
00564 while (n<text.Length())
00565 {
00566 wxChar tc=text.GetChar(n++);
00567 if (tc==_T('&'))
00568 {
00569
00570 wxString seq;
00571 while (tc !=_T(';') && n<text.Length())
00572 {
00573 tc=text.GetChar(n++);
00574 seq+=tc;
00575 }
00576
00577 if (seq == _T("amp;"))
00578 {
00579 tc=_T('&');
00580 }
00581 else if (seq == _T("lt;"))
00582 {
00583 tc=_T('<');
00584 }
00585 else if (seq == _T("gt;"))
00586 {
00587 tc=_T('>');
00588 }
00589 else if (seq == _T("quot;"))
00590 {
00591 tc=_T('"');
00592 }
00593 else if ((seq.Length()>3) && (seq.GetChar(0)==_T('#')) && (seq.GetChar(1)==_T('x')))
00594 {
00595 tc=_T('?');
00596 UINT32 code=tc;
00597
00598 #if wxUSE_UNICODE
00599 sscanf((const char*)seq.mb_str(wxConvUTF8), "#x%x;", &code);
00600 #else
00601 sscanf((const char*)seq.c_str(), "#x%x;", &code);
00602 #endif
00603 tc=(TCHAR)(code);
00604 }
00605 else if ((seq.Length()>2) && (seq.GetChar(0)==_T('#')) && ((seq.GetChar(1)>=_T('0')) && (seq.GetChar(1)<=_T('9'))))
00606 {
00607 tc=_T('?');
00608 UINT32 code=tc;
00609
00610 #if wxUSE_UNICODE
00611 sscanf((const char*)seq.mb_str(wxConvUTF8), "#%d;", &code);
00612 #else
00613 sscanf((const char*)seq.c_str(), "#%d;", &code);
00614 #endif
00615 tc=(TCHAR)(code);
00616 }
00617 else
00618 {
00619 TRACE(_T("CamResource::ReadStringTableFile - Unknown XML escape sequence [&%s] in %s, %s"),seq.c_str(),name.c_str(),text.c_str());
00620 otext+=_T('&')+seq;
00621 tc=0;
00622 }
00623 }
00624 if (tc)
00625 {
00626 otext+=tc;
00627 }
00628 }
00629
00630
00631
00632
00633 count++;
00634 AddStringResource(name.c_str(), ::wxGetTranslation(otext.c_str()));
00635 }
00636 }
00637
00638 TRACE(_T("Added %d strings"),count);
00639 if (count<1000) return FALSE;
00640
00641 return TRUE;
00642 }
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664 void CamResource::ProcessWindowAndChildren(wxWindow * pWindow)
00665 {
00666
00667 if (pWindow->IsKindOf(CLASSINFO(wxStaticText)))
00668 {
00669 ResourceID r=(ResourceID) pWindow->GetId();
00670
00671
00672
00673
00674
00675
00676
00677
00678 wxString sname = pWindow->GetName();
00679 wxString stext = pWindow->GetLabel();
00680
00681 AddStringResource((const TCHAR *)sname.c_str(),(const TCHAR *)stext.c_str(), r);
00682
00683 }
00684
00685
00686 wxWindowList::Node * pNode = pWindow->GetChildren().GetFirst();
00687 while (pNode)
00688 {
00689 ProcessWindowAndChildren(pNode->GetData());
00690 pNode = pNode->GetNext();
00691 }
00692 return;
00693 }
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711 BOOL CamResource::InitXmlResource()
00712 {
00713 TRACET(_T("CamResource::InitXmlResource() called, doing Load() of strings.xrc"));
00714
00715 if (!wxXmlResource::Get()->Load(GetResourceFilePath(_T("strings.xrc"))))
00716 {
00717 TRACE(_T("Could not load strings.xrc"));
00718 return FALSE;
00719 }
00720
00721 TRACET(_T("CamResource::InitXmlResource() called - loaded strings"));
00722
00723 return true;
00724 }
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749 wxString CamResource::GetResourceFilePath( const wxString &str, BOOL AllowOverride )
00750 {
00751
00752
00753 if ( ((str.Find(_T(':')))>=0) || ((str.Find(_T('/')))>=0) || ((str.Find(_T('\\')))>=0) )
00754 {
00755 return str;
00756 }
00757
00758 wxString mfn = _T("memory:resources#zip:");
00759
00760 if (AllowOverride && pResourcePath && pwxFileSystem)
00761 {
00762 wxString fn = *pResourcePath + _T('/');
00763
00764
00765 if (!HaveCheckedResourcePath)
00766 {
00767 if (CheckResourcePath(mfn+_T("xrc.check"),fn+_T("xrc.check")))
00768 {
00769 HaveCheckedResourcePath = TRUE;
00770 }
00771 else
00772 {
00773 wxMessageBox(_T("Ignoring resource path specified on command line due to bad resource checksum"), _T("Resource loading error"));
00774 delete (pResourcePath);
00775 pResourcePath = NULL;
00776 }
00777 }
00778
00779 if (str.IsEmpty() && pResourcePath)
00780 return fn;
00781
00782 fn += str;
00783
00784 if (pResourcePath)
00785 {
00786 wxFSFile * pTwxFSFile = pwxFileSystem->OpenFile(fn);
00787 if (pTwxFSFile)
00788 {
00789
00790 delete pTwxFSFile;
00791 return fn;
00792 }
00793 }
00794 }
00795 return mfn + str;
00796 }
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815 void * CamResource::LoadFile( const wxString &str1, UINT32* pSize )
00816 {
00817 wxFSFile * pTwxFSFile1 = pwxFileSystem->OpenFile(str1);
00818 if (!pTwxFSFile1)
00819 {
00820 delete pTwxFSFile1;
00821 return NULL;
00822 }
00823
00824 wxInputStream * pStream1 = pTwxFSFile1->GetStream();
00825 if (!pStream1)
00826 {
00827 delete (pTwxFSFile1);
00828 return NULL;
00829 }
00830
00831 UINT32 size1=pStream1->GetSize();
00832
00833 if (!size1)
00834 {
00835 delete (pTwxFSFile1);
00836 return NULL;
00837 }
00838
00839 void * mem1 = malloc(size1+4);
00840 if (!mem1)
00841 {
00842 delete (pTwxFSFile1);
00843 return NULL;
00844 }
00845
00846 memset(mem1, 0, size1);
00847 pStream1->Read(mem1, size1);
00848
00849 delete (pTwxFSFile1);
00850
00851 if (pSize)
00852 *pSize=size1;
00853 return mem1;
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 BOOL CamResource::CheckResourcePath( const wxString &str1, const wxString &str2 )
00879 {
00880 if (!pwxFileSystem) return FALSE;
00881
00882 UINT32 size1=0;
00883 UINT32 size2=0;
00884 void * mem1=LoadFile(str1, &size1);
00885 void * mem2=LoadFile(str2, &size2);
00886
00887 if (!mem1)
00888 {
00889 if (mem2)
00890 free(mem2);
00891 return FALSE;
00892 }
00893
00894 BOOL same = mem2 && ( size1 == size2) && !memcmp(mem1, mem2, size1);
00895
00896 if (!same && s_GenerateXRCCheck)
00897 {
00898 wxMessageBox(_T("You have requested XaraLX to generate a checksum for resources which may not match the binary in question. "
00899 "A checksum will be generated, but the program may not be stable."), _T("XaraLX Resource system warning"));
00900
00901 wxFile f;
00902 f.Create(str2, wxFile::write);
00903 if (!f.IsOpened() || (f.Write(mem1, size1) != size1))
00904 {
00905 wxMessageBox(_T("Failed to write xrc.check file ")+str2, _T("XaraLX resource system"));
00906 }
00907 f.Close();
00908 same=TRUE;
00909 }
00910
00911
00912 if (mem1)
00913 free (mem1);
00914
00915 if (mem2)
00916 free (mem2);
00917
00918 return same;
00919 }
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942 void CamResource::SetResourceFilePath( const wxString &str )
00943 {
00944 if (pResourcePath)
00945 {
00946 delete (pResourcePath);
00947 pResourcePath = NULL;
00948 }
00949
00950 HaveCheckedResourcePath=FALSE;
00951
00952 if (!str.IsEmpty())
00953 {
00954 pResourcePath = new(wxString);
00955 if (pResourcePath) *pResourcePath = str;
00956 }
00957 return;
00958 }
00959
00960
00961 #if !defined(EXCLUDE_FROM_XARLIB)
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979 BOOL CamResource::AddBitmaps(wxString &Path)
00980 {
00981 ERROR2IF(!pBitmapHash, FALSE, "No bitmap hash");
00982 ERROR2IF(!pwxFileSystem, FALSE, "No filesystem");
00983
00984 TRACEUSER("amb",_T("Adding bitmaps from %s"),Path.c_str());
00985
00986 wxString fn = pwxFileSystem->FindFirst(Path+_T("*.*"), wxFILE);
00987 while (!fn.IsEmpty())
00988 {
00989 wxString LeafName = fn.Mid(Path.Length());
00990
00991 if (IsBitmapName(LeafName))
00992 {
00993
00994 ResourceStringToBitmap::iterator i=pBitmapHash->find(LeafName);
00995
00996 if (i==pBitmapHash->end())
00997 {
00998 #if PRELOAD_BITMAPS
00999 wxImage * pBitmap=new wxImage;
01000 if (!pBitmap)
01001 return FALSE;
01002
01003
01004 if (LoadwxImage(*pBitmap, LeafName))
01005 (*pBitmapHash)[camStrdup(LeafName.c_str())]=pBitmap;
01006 else
01007 {
01008 ERROR3_PF((_T("Could not load bitmap %s"),fn.c_str()));
01009 delete pBitmap;
01010 }
01011 #else
01012 (*pBitmapHash)[camStrdup(LeafName.c_str())]=NULL;
01013 #endif
01014 }
01015 }
01016
01017 fn = pwxFileSystem->FindNext();
01018 }
01019 return TRUE;
01020 }
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038 BOOL CamResource::IsBitmapName(const wxString &str)
01039 {
01040 wxString ext=GetBitmapExtension(str);
01041 return (BitmapExtensions.Index(ext) != wxNOT_FOUND);
01042 }
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060 wxString CamResource::GetBitmapExtension(const wxString &str)
01061 {
01062
01063 INT32 i=str.Find(_T('.'), TRUE);
01064 if (i<0)
01065 return wxEmptyString;
01066 else
01067 return str.Mid(i+1);
01068 }
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086 wxString CamResource::GetBitmapBaseName(const wxString &str)
01087 {
01088
01089 INT32 i=str.Find(_T('.'), TRUE);
01090 if (i<0)
01091 return wxEmptyString;
01092 wxString barestr = str.Left(i);
01093
01094
01095 i=barestr.Find(_T('-'), TRUE);
01096 if (i<0)
01097 return barestr;
01098
01099
01100 INT32 j;
01101 for (j=i+1; j<(INT32)barestr.Length(); j++)
01102 {
01103 wxChar c=barestr[j];
01104 if ((c<_T('a')) || (c>_T('z')))
01105 return barestr;
01106 }
01107 return barestr.Left(i);
01108 }
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126 wxString CamResource::GetBitmapFlagString(const wxString &str)
01127 {
01128
01129 INT32 i=str.Find(_T('.'), TRUE);
01130 if (i<0)
01131 return wxEmptyString;
01132 wxString barestr = str.Left(i);
01133
01134
01135 i=barestr.Find(_T('-'), TRUE);
01136 if (i<0)
01137 return wxEmptyString;
01138
01139
01140 INT32 j;
01141 for (j=i+1; j<(INT32)barestr.Length(); j++)
01142 {
01143 wxChar c=barestr[j];
01144 if ((c<_T('a')) || (c>_T('z')))
01145 return wxEmptyString;
01146 }
01147 return barestr.Mid(i+1);
01148 }
01149
01150
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170 void CamResource::MakeVariantBitmaps(ResourceStringToBitmap::iterator * it)
01171 {
01172 if (!pBitmapHash)
01173 return;
01174
01175
01176 CamArtFlags flag=CAF_CACHE_MAX;
01177 while ((flag=(CamArtFlags)(flag>>1)) !=0 )
01178 {
01179 if ((flag==CAF_GREYED) || (flag==CAF_SELECTED))
01180 {
01181
01182
01183 ResourceStringToBitmap NewHash;
01184 NewHash.clear();
01185
01186 ResourceStringToBitmap::iterator current;
01187 if (it)
01188 current=*it;
01189 else
01190 current = pBitmapHash->begin();
01191
01192
01193 while (current != pBitmapHash->end())
01194 {
01195 if (current->second)
01196 {
01197 wxString fn(current->first);
01198
01199
01200
01201 if (IsBitmapName(fn) && !(CamArtProvider::GetBitmapFlags(fn) & flag))
01202 {
01203
01204 wxString gfn=MakeBitmapString(GetBitmapBaseName(fn),
01205 CamArtProvider::MakeBitmapFlagString((CamArtFlags)
01206 (CamArtProvider::GetBitmapFlags(fn) |
01207 flag)),
01208 GetBitmapExtension(fn));
01209 ResourceStringToBitmap::iterator i=pBitmapHash->find(gfn.c_str());
01210 if (i==pBitmapHash->end())
01211 {
01212
01213
01214
01215
01216 wxImage *pBitmap = new wxImage;
01217 if (pBitmap)
01218 {
01219 *pBitmap=current->second->Copy();
01220
01221 if (current->second->HasAlpha() && !pBitmap->HasAlpha())
01222 {
01223
01224 pBitmap->SetAlpha();
01225 memcpy( pBitmap->GetAlpha(), current->second->GetAlpha(), pBitmap->GetWidth()*pBitmap->GetHeight());
01226 }
01227 switch (flag)
01228 {
01229 case CAF_GREYED:
01230 MakeGreyImage(*pBitmap);
01231 break;
01232 case CAF_SELECTED:
01233 MakeHotImage(*pBitmap);
01234 break;
01235 default:
01236 ERROR3("Unsupported automatic variant");
01237 break;
01238 }
01239 NewHash[camStrdup(gfn.c_str())] = pBitmap;
01240 }
01241 }
01242 }
01243 }
01244
01245 if (it)
01246 {
01247 break;
01248 }
01249 else
01250 {
01251 ++current;
01252 }
01253 }
01254
01255
01256 for( current = NewHash.begin(); current != NewHash.end(); ++current )
01257 (*pBitmapHash)[current->first]=current->second;
01258 }
01259 }
01260
01261 return;
01262 }
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280 wxImage* CamResource::GetCachedBitmap(const TCHAR * pName)
01281 {
01282 if (!pBitmapHash) return NULL;
01283 ResourceStringToBitmap::iterator i=pBitmapHash->find(pName);
01284 if (i==pBitmapHash->end())
01285 {
01286
01287
01288
01289 wxString fn(pName);
01290
01291
01292 BOOL Found=FALSE;
01293
01294 CamArtFlags flag=CAF_CACHE_MAX;
01295 while ((flag=(CamArtFlags)(flag>>1)) !=0 )
01296 {
01297 if ((flag==CAF_GREYED) || (flag!=CAF_SELECTED))
01298 {
01299
01300 if (IsBitmapName(fn) && (CamArtProvider::GetBitmapFlags(fn) & flag))
01301 {
01302
01303 wxString ugfn=MakeBitmapString(GetBitmapBaseName(fn),
01304 CamArtProvider::MakeBitmapFlagString((CamArtFlags)
01305 (CamArtProvider::GetBitmapFlags(fn) &
01306 ~flag)),
01307 GetBitmapExtension(fn));
01308 Found = TRUE;
01309
01310
01311
01312
01313 #ifdef _DEBUG
01314 static INT32 recursion=0;
01315 recursion++;
01316 ERROR3IF(recursion>16,"Too much recursion in CamResource::GetCachedBitmap");
01317 #endif
01318 GetCachedBitmap(ugfn.c_str());
01319 #ifdef _DEBUG
01320 recursion--;
01321 #endif
01322 }
01323 }
01324 }
01325 if (!Found)
01326 return NULL;
01327
01328 i=pBitmapHash->find(pName);
01329 if (i==pBitmapHash->end())
01330 return NULL;
01331 }
01332
01333 if (!i->second)
01334 {
01335
01336
01337 wxImage * pBitmap = new wxImage;
01338 if (!pBitmap) return NULL;
01339
01340 if (!LoadwxImage(*pBitmap, pName))
01341 {
01342 ERROR3_PF((_T("Could not load bitmap %s"), pName));
01343 delete pBitmap;
01344 return NULL;
01345 }
01346
01347
01348 i->second=pBitmap;
01349
01350
01351 MakeVariantBitmaps(&i);
01352
01353 return pBitmap;
01354 }
01355 return i->second;
01356 }
01357
01358
01359
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375 BOOL CamResource::LoadBitmaps()
01376 {
01377 TRACET(_T("LoadBitmaps() called"));
01378 wxString ExternalRes = GetResourceFilePath(wxString(_T("")), TRUE);
01379 wxString InternalRes = GetResourceFilePath(wxString(_T("")), FALSE);
01380 TRACET(_T("LoadBitmaps() adding External bitmaps"));
01381 if (!AddBitmaps(ExternalRes)) return FALSE;
01382 TRACET(_T("LoadBitmaps() adding Internal bitmaps"));
01383 if (InternalRes != ExternalRes)
01384 if (!AddBitmaps(InternalRes)) return FALSE;
01385 TRACET(_T("LoadBitmaps() making grey copies"));
01386 MakeVariantBitmaps();
01387 TRACET(_T("LoadBitmaps() done"));
01388 return TRUE;
01389 }
01390
01391 #endif
01392
01393
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409 BOOL CamResource::Init()
01410 {
01411 void * pFile=NULL;
01412 UINT32 Length=0;
01413
01414 TRACET(_T("CamResource::Init() called"));
01415
01416 pHash = new (ResIDToString);
01417 if (!pHash) return FALSE;
01418 pHash->clear();
01419
01420 pObjectNameHash = new (ResIDToString);
01421 if (!pObjectNameHash) return FALSE;
01422 pObjectNameHash->clear();
01423
01424 #if !defined(EXCLUDE_FROM_XARLIB)
01425 pBitmapHash = new (ResourceStringToBitmap);
01426 if (!pBitmapHash) return FALSE;
01427 pBitmapHash->clear();
01428 #endif
01429
01430
01431 CamResourceRemember * pRem = pFirstRemember;
01432 pFirstRemember = NULL;
01433 while (pRem)
01434 {
01435 if (pRem->text)
01436 {
01437
01438
01439 GetResourceID(pRem->text);
01440
01441 free (pRem->text);
01442 }
01443 CamResourceRemember * pORem = pRem;
01444 pRem = pRem->next;
01445 delete pORem;
01446 }
01447
01448
01449 wxXmlResource::Get()->InitAllHandlers();
01450 #if !defined(EXCLUDE_FROM_XARLIB)
01451 wxXmlResource::Get()->AddHandler(new wxCamArtControlXmlHandler);
01452 wxXmlResource::Get()->AddHandler(new wxCamDrawControlXmlHandler);
01453 #ifdef wxXTRA_XH_ODCOMBO
01454 wxXmlResource::Get()->AddHandler(new wxOwnerDrawnComboBoxXmlHandler);
01455
01456 #endif
01457 #ifdef wxXTRA_XH_SLIDERCOMBO
01458 wxXmlResource::Get()->AddHandler(new wxSliderComboXmlHandler);
01459 #endif
01460 #if WXXTRA_TREEBOOK
01461 wxXmlResource::Get()->AddHandler(new wxTreebookXmlHandler);
01462 #endif
01463 wxXmlResource::Get()->AddHandler(new wxGridComboXmlHandler);
01464 #endif
01465
01466 if (!pwxFileSystem) pwxFileSystem = new wxFileSystem;
01467 if (!pwxFileSystem)
01468 {
01469 TRACE(_T("Failed to allocate file system"));
01470 return FALSE;
01471 }
01472
01473
01474
01475 {
01476 wxMemoryFSHandler::AddFile(_T("XRC_resource/dummy_file"), _T("dummy one"));
01477 wxFSFile *f = pwxFileSystem->OpenFile(_T("memory:XRC_resource/dummy_file"));
01478 wxMemoryFSHandler::RemoveFile(_T("XRC_resource/dummy_file"));
01479 if (f) delete f;
01480 else wxFileSystem::AddHandler(new wxMemoryFSHandler);
01481 }
01482
01483 TRACET(_T("CamResource::Init() added MemoryFSHandler"));
01484
01485 wxFileSystem::AddHandler(new wxZipFSHandler);
01486
01487 TRACET(_T("CamResource::Init() added Zip handler, now doing AddFile() on resources"));
01488
01489 GetBinaryFileInfo(&pFile, &Length);
01490
01491
01492
01493 wxMemoryFSHandler::AddFile(_T("resources"), pFile, Length);
01494
01495 wxXmlResource::Get()->SetFlags(wxXRC_NO_RELOADING);
01496
01497 #if !defined(EXCLUDE_FROM_XARLIB)
01498
01499 BitmapExtensions.Add(_T("png"));
01500 BitmapExtensions.Add(_T("cur"));
01501 #endif
01502
01503
01504 m_pLocale = new wxLocale();
01505 if (!m_pLocale) return FALSE;
01506 m_pLocale->Init(wxLANGUAGE_DEFAULT, wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING);
01507 m_pLocale->AddCatalogLookupPathPrefix(GetResourceFilePath(_T("")));
01508 m_pLocale->AddCatalog(_T("XaraLX"));
01509
01510 #if !defined(EXCLUDE_FROM_XARLIB)
01511 TRACET(_T("CamResource::Init() launching splash screen"));
01512 if (!Splash()) return FALSE;
01513 #endif
01514
01515 #ifdef XML_STRINGS
01516 TRACET(_T("CamResource::Init() now loading internal resources, calling InitXmlResource"));
01517
01518
01519 if (!InitXmlResource()) return FALSE;
01520
01521 wxYield();
01522
01523 TRACET(_T("CamResource::Init() starting to load string table dialog"));
01524
01525
01526 wxDialog * pStringTable = wxXmlResource::Get()->LoadDialog(NULL, _T("STRINGTABLE"));
01527 if (!pStringTable)
01528 {
01529
01530 wxMessageBox(_T("Could not load resources: Failed to locate string table"), _T("Resource loading error"));
01531 return FALSE;
01532 }
01533 wxYield();
01534
01535 TRACET(_T("CamResource::Init() starting to process string table"));
01536
01537
01538 ProcessWindowAndChildren(pStringTable);
01539
01540 wxYield();
01541
01542 TRACET(_T("CamResource::Init() and deleting the dialog"));
01543
01544 delete pStringTable;
01545 #else
01546
01547 TRACET(_T("CamResource::Init() now loading internal resources, calling ReadStringTableFile()"));
01548 if (!ReadStringTableFile())
01549 {
01550
01551 wxMessageBox(_T("Could not load resources: Failed to locate string table"), _T("Resource loading error"));
01552 return FALSE;
01553 }
01554
01555 #endif
01556
01557 TRACET(_T("CamResource::Init() done processing string table, starting to load bitmaps"));
01558
01559 wxYield();
01560
01561 #if !defined(EXCLUDE_FROM_XARLIB)
01562
01563 if (!LoadBitmaps())
01564 return FALSE;
01565
01566 TRACET(_T("CamResource::Init() done processing bitmaps, starting to load toolbar images"));
01567
01568 wxYield();
01569
01570 #if 0
01571 LoadwxImage(imageBevelTool, _T("lbeveltool32.png") );
01572 LoadwxImage(imageBezTool, _T("lbeztool32.png") );
01573 LoadwxImage(imageBlendTool, _T("lblendtool32.png") );
01574 LoadwxImage(imageContourTool, _T("lcontourtool32.png") );
01575 LoadwxImage(imageElipTool, _T("leliptool32.png") );
01576 LoadwxImage(imageFHandTool, _T("lfhandtool32.png") );
01577 LoadwxImage(imageGradTool, _T("lgradtool32.png") );
01578 LoadwxImage(imageLiveEffectTool, _T("lliveeffecttool32.png") );
01579 LoadwxImage(imageMouldTool, _T("lmouldtool32.png") );
01580 LoadwxImage(imagePenTool, _T("lpentool32.png") );
01581 LoadwxImage(imagePush, _T("lpushtool32.png") );
01582 LoadwxImage(imageRectTool, _T("lrecttool32.png") );
01583 LoadwxImage(imageRegShapeTool, _T("lregshapetool32.png") );
01584 LoadwxImage(imageSelTool, _T("lselrtool32.png") );
01585 LoadwxImage(imageShadrwTool, _T("lsoftshadowtool32.png") );
01586 LoadwxImage(imageSlicetool, _T("lslicetool32.png") );
01587 LoadwxImage(imageTextTool, _T("ltexttool32.png") );
01588 LoadwxImage(imageTransTool, _T("ltransptool32.png") );
01589 LoadwxImage(imageZoomTool, _T("lzoomtool32.png") );
01590
01591 TRACET(_T("CamResource::Init() Added images"));
01592
01593 wxYield();
01594 #endif
01595
01596 m_pHelpProvider = new wxHelpControllerHelpProvider;
01597 if (!m_pHelpProvider)
01598 return FALSE;
01599 wxHelpProvider::Set(m_pHelpProvider);
01600
01601 if (!wxXmlResource::Get()->Load(GetResourceFilePath(_T("dialogs.xrc"))))
01602 {
01603 TRACE(_T("Could not load dialogs.xrc"));
01604 return FALSE;
01605 }
01606
01607 TRACET(_T("CamResource::Init - loaded dialogs"));
01608
01609 wxYield();
01610 #endif
01611
01612 return TRUE;
01613 }
01614
01615
01616 #if !defined(EXCLUDE_FROM_XARLIB)
01617
01618
01619
01620
01621
01622
01623
01624
01625
01626
01627
01628
01629
01630
01631
01632
01633 void CamResource::DeleteBitmapHashEntries()
01634 {
01635 if (pBitmapHash)
01636 {
01637 ResourceStringToBitmap::iterator current;
01638
01639 while (!pBitmapHash->empty())
01640 {
01641 current = pBitmapHash->begin();
01642 wxImage * b=current->second;
01643 TCHAR * s=(TCHAR *)current->first;
01644 pBitmapHash->erase(current);
01645 if (b)
01646 delete b;
01647 free(s);
01648 }
01649
01650 pBitmapHash->clear();
01651 }
01652 }
01653 #endif // EXCLUDE_FROM_XARLIB
01654
01655
01656
01657
01658
01659
01660
01661
01662
01663
01664
01665
01666
01667
01668
01669
01670
01671
01672 BOOL CamResource::DeInit()
01673 {
01674 if (m_pHelpProvider)
01675 {
01676 wxHelpProvider::Set(NULL);
01677 delete m_pHelpProvider;
01678 m_pHelpProvider = NULL;
01679 }
01680
01681 if (pwxFileSystem)
01682 {
01683 delete (pwxFileSystem);
01684 pwxFileSystem = NULL;
01685 }
01686
01687 #if !defined(EXCLUDE_FROM_XARLIB)
01688 if (pBitmapHash)
01689 {
01690 DeleteBitmapHashEntries();
01691 delete pBitmapHash;
01692 pBitmapHash = NULL;
01693 }
01694 #endif // EXCLUDE_FROM_XARLIB
01695 if (pHash)
01696 {
01697 ResIDToString::iterator current;
01698
01699 while (!pHash->empty())
01700 {
01701 current = pHash->begin();
01702 ResourceString s=current->second;
01703 pHash->erase(current);
01704 free((void *)s);
01705 }
01706
01707 pHash->clear();
01708
01709 delete (pHash);
01710 pHash = NULL;
01711 }
01712
01713 if (pObjectNameHash)
01714 {
01715 ResIDToString::iterator current;
01716
01717 while (!pObjectNameHash->empty())
01718 {
01719 current = pObjectNameHash->begin();
01720 ResourceString s=current->second;
01721 pObjectNameHash->erase(current);
01722 free((void *)s);
01723 }
01724
01725 pObjectNameHash->clear();
01726
01727 delete (pObjectNameHash);
01728 pObjectNameHash = NULL;
01729 }
01730
01731 #if !defined(EXCLUDE_FROM_XARLIB)
01732 if (pSplashScreen)
01733 {
01734 delete (pSplashScreen);
01735 pSplashScreen = NULL;
01736 }
01737
01738 if (pSplashBitmap)
01739 {
01740 delete (pSplashBitmap);
01741 pSplashBitmap = NULL;
01742 }
01743 #endif // EXCLUDE_FROM_XARLIB
01744
01745 if (m_pLocale)
01746 {
01747 delete (m_pLocale);
01748 m_pLocale = NULL;
01749 }
01750
01751 return TRUE;
01752 }
01753
01754
01755 #if !defined(EXCLUDE_FROM_XARLIB)
01756
01757
01758
01759
01760
01761
01762
01763
01764
01765
01766
01767
01768
01769
01770
01771
01772
01773 BOOL CamResource::Splash()
01774 {
01775 TRACET(_T("CamResource::Splash() called"));
01776
01777 if (pSplashBitmap) delete pSplashBitmap;
01778 pSplashBitmap=NULL;
01779
01780
01781 pSplashBitmap = new wxBitmap();
01782 if (!pSplashBitmap) return FALSE;
01783
01784
01785
01786 if (!LoadwxBitmap(*pSplashBitmap, _T("startup-lx.png") ))
01787 {
01788 TRACE(_T("Cannot load splash bitmap - possible resource compilation error?"));
01789 return TRUE;
01790 }
01791
01792 if (!pSplashBitmap->Ok()) return FALSE;
01793
01794 pSplashScreen = new wxAdvSplashScreen(*pSplashBitmap,
01795 wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_NO_TIMEOUT,
01796 0, NULL, -1, wxDefaultPosition, wxDefaultSize,
01797 wxNO_BORDER
01798 #if 0 && !defined (_DEBUG)
01799 |wxSTAY_ON_TOP
01800 #endif
01801 );
01802 if (!pSplashScreen) return FALSE;
01803
01804 wxYield();
01805
01806 return TRUE;
01807 }
01808 #endif // EXCLUDE_FROM_XARLIB
01809
01810
01811
01812
01813
01814
01815
01816
01817
01818
01819
01820
01821
01822
01823
01824
01825
01826
01827 BOOL CamResource::DoneInit(BOOL CanYield )
01828 {
01829 TRACET(_T("CamResource::DoneInit() called"));
01830 #if !defined(EXCLUDE_FROM_XARLIB)
01831 if (pSplashScreen)
01832 {
01833 if (CanYield)
01834 ::wxYield();
01835 pSplashScreen->Destroy();
01836 pSplashScreen = NULL;
01837 if (CanYield)
01838 ::wxYield();
01839 }
01840 if (pSplashBitmap)
01841 {
01842 delete (pSplashBitmap);
01843 pSplashBitmap = NULL;
01844 }
01845 #endif // EXCLUDE_FROM_XARLIB
01846 return TRUE;
01847 }
01848
01849
01850
01851
01852
01853
01854
01855
01856
01857
01858
01859
01860
01861
01862
01863
01864
01865
01866
01867
01868
01869
01870
01871
01872
01873
01874
01875
01876
01877
01878
01879
01880
01881
01882
01883 CamResource::CamResource()
01884 {
01885 Size = 0;
01886 pMemory = NULL;
01887 pFile = NULL;
01888 pwxFSFile = NULL;
01889 return;
01890 }
01891
01892
01893
01894
01895
01896
01897
01898
01899
01900
01901
01902
01903
01904
01905
01906
01907
01908
01909 CamResource::~CamResource()
01910 {
01911 Close();
01912 }
01913
01914
01915
01916
01917
01918
01919
01920
01921
01922
01923
01924
01925
01926
01927
01928
01929
01930 void CamResource::Close()
01931 {
01932 if (pFile)
01933 {
01934 pFile->close();
01935 delete (pFile);
01936 pFile = NULL;
01937 }
01938
01939 if (pwxFSFile)
01940 {
01941 delete (pwxFSFile);
01942 pwxFSFile=NULL;
01943 }
01944
01945 if (pMemory) free(pMemory);
01946 pMemory = NULL;
01947
01948 Size = 0;
01949 }
01950
01951
01952
01953
01954
01955
01956
01957
01958
01959
01960
01961
01962
01963
01964
01965
01966
01967 CCLexFile * CamResource::Open( const TCHAR * pFileName, BOOL ErrorReporting, BOOL ExceptionThrowing)
01968 {
01969 Close();
01970
01971
01972
01973
01974
01975 wxFSFile * pTwxFSFile = pwxFileSystem->OpenFile(GetResourceFilePath(pFileName));
01976 if (!pTwxFSFile)
01977 {
01978 return NULL;
01979 }
01980
01981 wxInputStream * pStream = pTwxFSFile->GetStream();
01982 if (!pStream)
01983 {
01984 delete (pTwxFSFile);
01985 return NULL;
01986 }
01987
01988 UINT32 newsize=pStream->GetSize();
01989
01990 if (!newsize)
01991 {
01992 delete (pTwxFSFile);
01993 return NULL;
01994 }
01995
01996 void * newmem = malloc(newsize+4);
01997 if (!newmem)
01998 {
01999 delete (pTwxFSFile);
02000 return NULL;
02001 }
02002
02003 memset(newmem, 0, newsize);
02004 pStream->Read(newmem, newsize);
02005
02006 delete (pTwxFSFile);
02007
02008 CCMemFile * pMemFile=new CCMemFile (newmem, newsize, CCMemRead, ErrorReporting, ExceptionThrowing);
02009 if (!pMemFile)
02010 {
02011 free(newmem);
02012 return NULL;
02013 }
02014
02015
02016 pFile = pMemFile;
02017 Size = newsize;
02018 pMemory = newmem;
02019
02020 return (pFile);
02021 }
02022
02023
02024
02025
02026
02027
02028
02029
02030
02031
02032
02033
02034
02035
02036
02037
02038
02039
02040 CCLexFile * CamResource::Open( ResourceID ID, BOOL ErrorReporting, BOOL ExceptionThrowing)
02041 {
02042 return Open(GetText(ID), (BOOL) ErrorReporting, (BOOL) ExceptionThrowing);
02043 }
02044
02045
02046
02047
02048
02049
02050
02051
02052
02053
02054
02055
02056
02057
02058
02059
02060
02061 wxFSFile * CamResource::OpenwxFSFile( ResourceID ID )
02062 {
02063 return OpenwxFSFile(GetText(ID));
02064 }
02065
02066
02067
02068
02069
02070
02071
02072
02073
02074
02075
02076
02077
02078
02079
02080
02081
02082 wxFSFile * CamResource::OpenwxFSFile( const TCHAR * pFileName )
02083 {
02084 wxFSFile * pTwxFSFile = pwxFileSystem->OpenFile(GetResourceFilePath(pFileName));
02085 if (!pTwxFSFile)
02086 {
02087 return NULL;
02088 }
02089
02090 pwxFSFile=pTwxFSFile;
02091
02092 return pwxFSFile;
02093 }
02094
02095
02096 #if !defined(EXCLUDE_FROM_XARLIB)
02097
02098
02099
02100
02101
02102
02103
02104
02105
02106
02107
02108
02109
02110
02111
02112 void CamResource::MakeGreyImage (wxImage & rImage)
02113 {
02114
02115 INT32 x;
02116 INT32 y;
02117
02118 BOOL hasalpha = rImage.HasAlpha();
02119
02120
02121 if (!hasalpha) rImage.InitAlpha();
02122 rImage.SetMask(FALSE);
02123
02124 UINT8 * p = rImage.GetData();
02125 UINT8 * alpha = rImage.GetAlpha();
02126
02127 INT32 w=rImage.GetWidth();
02128 INT32 h=rImage.GetHeight();
02129
02130 ColourMatrix Whiten = ColourMatrix::Whiten();
02131 ColourMatrix Grey = ColourMatrix::Grey();
02132
02133
02134
02135 const INT32 size = w * h;
02136 INT32 m = size - 1;
02137 INT32 n = (size - 1) * 3;
02138
02139
02140 for (y = h-1; y>=0; y--) for (x = w-1 ; x>=0; x--)
02141 {
02142
02143 ColourVector togrey;
02144 togrey.SetRGBA (p[n], p[n+1], p[n+2], alpha[m]);
02145
02146 togrey=togrey.Apply(Grey);
02147
02148 ColourVector towhiten(0.0,0.0,0.0,0.0);
02149
02150
02151 if ((y>0) && (x>0))
02152 {
02153 towhiten.SetRGBA(p[n-(w+1)*3],
02154 p[n-(w+1)*3+1],
02155 p[n-(w+1)*3+2],
02156 alpha[m-(w+1)]);
02157 }
02158
02159 towhiten=towhiten.Apply(Whiten);
02160 ColourVector result = towhiten.ComposeOnTop(togrey);
02161
02162
02163 p[n]=result.GetR();
02164 p[n+1]=result.GetG();
02165 p[n+2]=result.GetB();
02166 alpha[m]=result.GetA();
02167
02168
02169 n-=3;
02170 m--;
02171 }
02172 }
02173
02174
02175
02176
02177
02178
02179
02180
02181
02182
02183
02184
02185
02186
02187
02188 void CamResource::MakeHotImage (wxImage & rImage)
02189 {
02190
02191 INT32 x;
02192 INT32 y;
02193 INT32 n=0;
02194 INT32 m=0;
02195
02196 BOOL hasalpha = rImage.HasAlpha();
02197
02198
02199 if (!hasalpha) rImage.InitAlpha();
02200 rImage.SetMask(FALSE);
02201
02202 UINT8 * p = rImage.GetData();
02203 UINT8 * alpha = rImage.GetAlpha();
02204
02205 INT32 w=rImage.GetWidth();
02206 INT32 h=rImage.GetHeight();
02207
02208 ColourMatrix Boost = ColourMatrix::Boost();
02209
02210
02211 for (y = 0; y<h; y++) for (x = 0 ; x<w; x++)
02212 {
02213
02214 ColourVector result;
02215 result.SetRGBA (p[n], p[n+1], p[n+2], alpha[m]);
02216
02217 result=result.Apply(Boost);
02218
02219 p[n]=result.GetR();
02220 p[n+1]=result.GetG();
02221 p[n+2]=result.GetB();
02222 alpha[m]=result.GetA();
02223
02224 n+=3;
02225 m++;
02226 }
02227
02228 }
02229
02230
02231
02232
02233
02234
02235
02236
02237
02238
02239
02240
02241
02242
02243
02244
02245
02246 BOOL CamResource::LoadwxImage (wxImage & rImage, const TCHAR * pFileName, BOOL Grey)
02247 {
02248 CamResource Resource;
02249 wxFSFile* f=Resource.OpenwxFSFile(pFileName);
02250 if (!f) return FALSE;
02251 wxInputStream * pStream=f->GetStream();
02252 if (!pStream) return FALSE;
02253 if (!rImage.LoadFile(*pStream, wxBITMAP_TYPE_ANY)) return FALSE;
02254
02255
02256 if (Grey) MakeGreyImage(rImage);
02257
02258 return TRUE;
02259 }
02260
02261
02262
02263
02264
02265
02266
02267
02268
02269
02270
02271
02272
02273
02274
02275
02276
02277 BOOL CamResource::LoadwxBitmap (wxBitmap & rBitmap, const TCHAR * pFileName, BOOL Grey)
02278 {
02279
02280 wxImage i;
02281 if (!LoadwxImage(i, pFileName)) return FALSE;
02282 wxBitmap b(i, -1);
02283 rBitmap = b;
02284 return TRUE;
02285 }
02286
02287 #endif // EXCLUDE_FROM_XARLIB
02288
02289
02290 #if 0
02291
02292
02293 m_strResourcePath = CamResource::GetResourcePath();
02294
02295
02296
02297
02298
02299 m_strResourcePath = argv[0];
02300 #if defined(__WXMSW__)
02301 m_strResourcePath = m_strResourcePath.BeforeLast( _T('\\') ) + _T("\\Resources\\");
02302 #else
02303 if( -1 == m_strResourcePath.Find('/') )
02304 m_strResourcePath = _T("./Resources/");
02305 else
02306 m_strResourcePath = m_strResourcePath.BeforeLast( _T('/') ) + _T("/Resources/");
02307 {
02308 wxString strRes( m_strResourcePath + _T("deffill.bmp") );
02309
02310 #if 0 == wxUSE_UNICODE
02311 FILE *fpResFile = _tfopen( (const TCHAR *)strRes.c_str(), "rb");
02312 #else
02313
02314
02315 size_t cchTmp = camWcstombs( NULL, strRes.c_str(), 0 ) + 1;
02316 PSTR pszTmp = PSTR( alloca( cchTmp ) );
02317 camWcstombs( pszTmp, strRes.c_str(), cchTmp );
02318
02319 FILE *fpResFile = fopen( pszTmp, "rb" );
02320 #endif
02321
02322 if( NULL == fpResFile )
02323 {
02324 wxMessageBox( _T("In order for the toolbar resources to be locatable "
02325 "you must either run the XaraLX executable from the current directory or "
02326 "specify the entire path to it."), _T("Resource loading error") );
02327
02328 return FALSE;
02329 }
02330
02331 fclose( fpResFile );
02332 }
02333 #endif
02334
02335 #endif