//--------------------------------------------------------------------------- #include #pragma hdrstop #include #include "Define.h" #include "Windowlib_F.h" #include "MainImage.h" #include "Main.h" #include "MainMenu.h" #include "FullView.h" #include "Window.h" #include "Palette.h" #include "FileManager_F.h"//gabriel #include "VecDraw.h" //gabriel #include "LogData.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "RzButton" #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_WINDOW StringTable[0] #define IDS_NUMBER StringTable[1] #define IDS_READ StringTable[2] #define IDS_EXIT StringTable[3] #define IDS_DELETE StringTable[4] #define IDS_SAVE StringTable[5] #define IDS_NEW StringTable[6] #define IDS_FILE StringTable[7] #define IDS_DELALLINFO StringTable[8] TWindowLibForm *WindowLibForm; //--------------------------------------------------------------------------- __fastcall TWindowLibForm::TWindowLibForm(TComponent* Owner) : TForm(Owner) { BEGIN_LOG(""); hWnd = ((TWinControl *)Owner)->Handle; StringTable.Create(DirectoryItem, Language, "WindowLib"); SetSmallFont(Font); Caption = IDS_WINDOW; Label1->Caption = IDS_NUMBER; Read->Caption = IDS_READ; Exit->Caption = IDS_EXIT; delete1->Caption = IDS_DELETE; SpeedButton1->Hint = IDS_FILE; SpeedButton3->Hint = IDS_NEW; SpeedButton4->Hint = IDS_SAVE; WAPath = String(InstallPath + "\\Motive"); /* if(!DirectoryExists(WAPath)) CreateDir(WAPath); */ if(!DirectoryExists(WAPath.c_str())) CreateDirectory(WAPath.c_str(), NULL); Exit->Visible = false; WindowItemList = new TList; WindowAreaNotSaved = false; DefaultSaving = false; bLoadAutoSave = false; END_LOG; } //--------------------------------------------------------------------------- __fastcall TWindowLibForm::~TWindowLibForm()//gabriel { BEGIN_LOG(""); WDeleteAll(NULL); if (WindowItemList) delete WindowItemList; WindowItemList = NULL; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TWindowLibForm::DefaultSave()//gabriel: when exit { #ifdef TRIAL return; #endif BEGIN_LOG(""); //AnsiString path = FullPathName(InstallPath + "\\Motive", "Default.wal"); //AnsiString tpath = FullPathName(InstallPath + "\\Motive", "tDefault.wal"); String path = FullPathName(String(InstallPath + "\\Motive"), String("Default.wal")); String tpath = FullPathName(String(InstallPath + "\\Motive"), String("tDefault.wal")); if (totalWANum == 0) { END_LOG; return; } DefaultSaving = true; //Àӽà ÆÄÀÏÀ» ¸¸µé¾î ÀúÀå ÇÒ ¶§ ¿¡·¯°¡ ¹ß»ýÇϸé ÀÌÀü ÆÄÀÏ·Î º¹±¸ µÇµµ·Ï ¼öÁ¤ by david 080827 if (FileExists(path)) { CopyFile(path.c_str(), tpath.c_str(), false); DeleteFile(path); } if (SaveWALibraryFile(WAPath, "Default.wal", gffNON, cmNone) != EC_NONE) { //ÀúÀå ¿À·ù°¡ ¹ß»ýÇÏ¸é ÆÄÀÏÀ» Áö¿ìµµ·Ï ¼öÁ¤ by david 080827 if (FileExists(path)) { DeleteFile(path); if (FileExists(tpath)) RenameFile(tpath, path); } } if (FileExists(tpath)) DeleteFile(tpath); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TWindowLibForm::ReadClick(TObject *Sender) { BEGIN_LOG(""); if (!MainImageForm) { END_LOG; return; } // by maxleo21c (05.06.09) int n; if (MainImageForm == NULL) { END_LOG; return; } MainImageForm->WorkArea->PushUndo(); if (!WindowListView->Selected) { END_LOG; return; } if(MainMenuForm->Item != T_WIN) MainMenuForm->InitWindowForm(); if (WindowForm->rbSet->Checked) ResetBitmapRegion(); ExitItem(); n = WindowListView->Selected->Index; MainForm->sWork = n + 1; //AnsiString WFileName = WAPath + "\\" + MainForm->sWork + "wa.tex"; LoadWindowItem(); SetWindowWork(); MainForm->WReopenMove = true; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TWindowLibForm::UpdateItems() //gabriel { BEGIN_LOG(""); WindowListView->Items->Clear(); WindowImageList->Clear(); TListItem *pItem=NULL; int imgindex = 0; TPException ec = EC_NONE; int width, height, dpi; int WACount = 1; T_WAItem *wItem = NULL; AnsiString strwid, strhei; try { while (true) { if (WACount > WindowItemList->Count) break; wItem = (T_WAItem *)WindowItemList->Items[WACount-1]; Graphics::TBitmap *tag = new Graphics::TBitmap; tag->Width = 80; tag->Height = 100; tag->PixelFormat = pf24bit; tag->Canvas->Brush->Color = clWhite; tag->Canvas->FillRect(Rect(0,0,80,100)); HDC dc = wItem->tag->CreateDC(); BitBlt(tag->Canvas->Handle, 0, 0, 80, 100, dc, 0, 0, SRCCOPY); wItem->tag->DeleteDC(dc); WindowImageList->Add(tag, NULL); delete tag; pItem = WindowListView->Items->Add(); height = wItem->Height; width = wItem->Width; if(MainImageForm){ dpi = MainImageForm->CanvasInfor.DotsPerInch; switch (MainImageForm->CurrentUnit) { case uDot : strwid = AnsiString(width); strhei = AnsiString(height); break; case uInch : strwid = Format("%.2f", OPENARRAY(TVarRec, ((double)width / dpi))); strhei = Format("%.2f", OPENARRAY(TVarRec, ((double)height / dpi))); break; case uCm : strwid = Format("%.2f", OPENARRAY(TVarRec, ((double)width / dpi * 2.54))); strhei = Format("%.2f", OPENARRAY(TVarRec, ((double)height / dpi * 2.54))); break; } } pItem->Caption = strwid + "X" + strhei; pItem->ImageIndex = imgindex; imgindex++; WACount++; } } catch (TPException &TPe) { EXCEPTION_MESSAGE_OK(ec); } totalWANum = WACount - 1; Label1->Caption = IDS_NUMBER + IntToStr(totalWANum); END_LOG; return; } //--------------------------------------------------------------------------- void __fastcall TWindowLibForm::FormClose(TObject *Sender, TCloseAction &Action) { BEGIN_LOG(""); MainForm->WorkArea1->Checked = false; Visible = false; if (FOnUpdateMenu) FOnUpdateMenu(Sender); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TWindowLibForm::FormCreate(TObject *Sender) { BEGIN_LOG(""); UpdateItems(); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TWindowLibForm::ExitClick(TObject *Sender) { BEGIN_LOG(""); MainForm->WorkArea1->Checked = false; Visible = false; if (FOnUpdateMenu) FOnUpdateMenu(Sender); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TWindowLibForm::FormKeyDown(WORD &Key, TShiftState Shift) { BEGIN_LOG(""); if(Key == VK_DELETE) delete1Click(this); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TWindowLibForm::delete1Click(TObject *Sender) { BEGIN_LOG(""); if (!WindowListView->Selected) { END_LOG; return; } T_WAItem *tempItem; tempItem = (T_WAItem *) WindowItemList->Items[WindowListView->Selected->Index]; if (tempItem) delete tempItem; WindowItemList->Delete(WindowListView->Selected->Index); UpdateItems(); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TWindowLibForm::SetWindowWork() { BEGIN_LOG(""); int i, j; TCursor OldCursor; Byte *WBP=NULL, *MP=NULL; bool mbc = false, mmc = false; TTexpiaBitmap *tempBitmap = NULL; // convert by celberus HDC tempDC = NULL; // convert by celberus TPItemImage *Image = MainImageForm->iMainImage; OldCursor = Screen->Cursor; Screen->Cursor = crHourGlass; Image->SubEnabled = true; MainImageForm->window.size.x = MainImageForm->waWidth; MainImageForm->window.size.y = MainImageForm->waHeight; if (Image->uBitmap->BitsPerPixel==8) { MainImageForm->Palette->ToRGBQUAD(rgb, 256); mbc = Image->SubBitmap->Create(MainImageForm->waWidth, MainImageForm->waHeight, 8, rgb); if (mbc == false) goto fail; mmc = Image->SubMask->Create(MainImageForm->waWidth, MainImageForm->waHeight, 8, rgb); if (mmc == false) goto fail; Image->SubMask->UnionBitBlt(NULL,0,0,MainImageForm->window.size.x, MainImageForm->window.size.y,0,0,WHITENESS, true); // convert by celberus Image->SubBitmap->UnionBitBlt(NULL, 0, 0, MainImageForm->window.size.x, MainImageForm->window.size.y, 0, 0, WHITENESS, true); // convert by celberus tempBitmap = new TTexpiaBitmap; // if(!tempBitmap->Create(Image->SubBitmap->Width, Image->SubBitmap->Height, // Image->SubBitmap->BitsPerPixel, Image->SubBitmap->RGB)) goto fail; // tempDC = tempBitmap->CreateDC(); BitBlt(tempDC,0,0,MainImageForm->window.size.x, MainImageForm->window.size.y,NULL,0,0,WHITENESS); tempBitmap->DeleteDC(tempDC); if (!tempBitmap->StartScanLine()) goto fail; for (i=0; iwindow.size.y; i++) { WBP = tempBitmap->GetScanLine(i); for (j=0; jwindow.size.x; j++, WBP++) { *WBP =0xD0; } tempBitmap->PutScanLine(i); } tempBitmap->StopScanLine(); LoadFromFile(tempBitmap->Handle, WAPath + String("\\" + MainForm->sWork), false); //gabriel Image->WAOutlineBitmapRgn(tempBitmap, false); // tempDC = tempBitmap->CreateDC(); // if(tempDC == NULL) goto fail; // if(!Image->SubBitmap->UnionBitBlt(tempDC, 0, 0, tempBitmap->Width, tempBitmap->Height, 0, 0, SRCCOPY, true)) goto fail; // tempBitmap->DeleteDC(tempDC); // if (!Image->SubBitmap->StartScanLine()) goto fail; if (!Image->SubMask->StartScanLine()) goto fail; for (i=0; iwindow.size.y; i++) { WBP = Image->SubBitmap->GetScanLine(i); MP = Image->SubMask->GetScanLine(i); for (j=0; jwindow.size.x; j++, WBP++, MP++) { if (*WBP==0xD0) { *MP = 0xFF; } else { *MP = 0x00; } } Image->SubBitmap->PutScanLine(i); Image->SubMask->PutScanLine(i); } Image->SubBitmap->StopScanLine(); Image->SubMask->StopScanLine(); } else { PaletteForm->DIB256Palette->GetBGCOLORREF(24); mbc = Image->SubBitmap->Create(MainImageForm->waWidth, MainImageForm->waHeight, 24); if (mbc == false) goto fail; mmc = Image->SubMask->Create(MainImageForm->waWidth, MainImageForm->waHeight, 24); if (mmc == false) goto fail; Image->SubMask->UnionBitBlt(NULL, 0,0,MainImageForm->window.size.x, MainImageForm->window.size.y,0,0,WHITENESS, true); // convert by celberus Image->SubBitmap->UnionBitBlt(NULL, 0, 0, MainImageForm->window.size.x, MainImageForm->window.size.y, 0, 0, WHITENESS, true); // convert by celberus tempBitmap = new TTexpiaBitmap; // if(!tempBitmap->Create(Image->SubBitmap->Width, Image->SubBitmap->Height, // Image->SubBitmap->BitsPerPixel, Image->SubBitmap->RGB)) goto fail; // tempDC = tempBitmap->CreateDC(); BitBlt(tempDC,0,0,MainImageForm->window.size.x, MainImageForm->window.size.y,NULL,0,0,WHITENESS); tempBitmap->DeleteDC(tempDC); if (!tempBitmap->StartScanLine()) goto fail; for (i=0; iwindow.size.y; i++) { WBP = tempBitmap->GetScanLine(i); for (j=0; j<3*MainImageForm->window.size.x; j++, WBP++) { *WBP = (Byte)0xD0; } tempBitmap->PutScanLine(i); } tempBitmap->StopScanLine(); LoadFromFile(tempBitmap->Handle, WAPath + String("\\" + MainForm->sWork), false);//gabriel Image->WAOutlineBitmapRgn(tempBitmap, false); // tempDC = tempBitmap->CreateDC(); // if(tempDC == NULL) goto fail; // if(!Image->SubBitmap->UnionBitBlt(tempDC, 0, 0, tempBitmap->Width, tempBitmap->Height, 0, 0, SRCCOPY, true)) goto fail; // tempBitmap->DeleteDC(tempDC); // if (!Image->SubBitmap->StartScanLine()) goto fail; if (!Image->SubMask->StartScanLine()) goto fail; for (i=0; iwindow.size.y; i++) { WBP = Image->SubBitmap->GetScanLine(i); MP = Image->SubMask->GetScanLine(i); for (j=0; j<3*MainImageForm->window.size.x; j++, WBP++, MP++) { if (*WBP==0xD0) { *MP = 0xFF; } else { *MP = 0x00; } } Image->SubBitmap->PutScanLine(i); Image->SubMask->PutScanLine(i); } Image->SubBitmap->StopScanLine(); Image->SubMask->StopScanLine(); } Screen->Cursor = OldCursor; if(tempBitmap) delete tempBitmap; END_LOG; return; fail: if(tempBitmap) { // if(tempDC) tempBitmap->DeleteDC(tempDC); // delete tempBitmap; // } // convert by celberus EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TWindowLibForm::ExitItem() { WindowForm->workAreaMenu->Step = 0; MainImageForm->TempLabel->Visible = false; WindowForm->rzmtbtShape->Down = false; WindowForm->rzmtbtIrregular->Down = false; WindowForm->rzmtbtOutline->Down = false; } //--------------------------------------------------------------------------- void __fastcall TWindowLibForm::Save(TObject *Sender) { BEGIN_LOG(""); if(!MainImageForm->WorkArea->Mask) { END_LOG; return; } if (!bLoadAutoSave) { //óÀ½ ½ÇÇàÇØ¼­ default¸¦ ·ÎµåÇÑ ÀûÀÌ ¾ø´Ù¸é loadÇÑ´Ù. LoadDefaultData(); } //AnsiString OldName, OldWAName, NewName, NewWAName; int ExtIndex = 1 , cm = 2; // Tex ÆÄÀÏ Çü½Ä, ¾ÐÃà »ç¿ë pBITMAPHANDLE bh = MainImageForm->iMainImage->uBitmap->RgnBitmap->Handle; while(MainForm->ReOpen1->Count>10){ delete MainForm->ReOpen1->Items[MainForm->ReOpen1->Count-1]; } T_WAItem *WindowItem = new T_WAItem; MainForm->sWork = 1; WorkArea_SaveToFile (WindowItem, bh);//gabriel MainForm->WaSave = true; SaveToWindowBitmap(WindowItem, (TGraphicFileFormat)ExtIndex , (TCompressMethod)cm);//gabriel MainForm->WaSave = false; UpdateItems(); WindowAreaNotSaved = true; END_LOG; } //---------------------------------------------------------------------------- void __fastcall TWindowLibForm::WDeleteAll(TObject *Sender) { BEGIN_LOG(""); if (!WindowItemList->Count) { END_LOG; return; }//2005.05.23 #ifndef LOCK_USB if (WindowAreaNotSaved) { if (Application->MessageBox(IDS_DELALLINFO.c_str(), L"Information", MB_OKCANCEL) == 1) ; else { END_LOG; return; } } #endif T_WAItem *tempItem; for (int i = 0;i< WindowItemList->Count;) { tempItem = (T_WAItem *) WindowItemList->Items[0]; delete tempItem; WindowItemList->Delete(0); } UpdateItems(); WindowAreaNotSaved = false; END_LOG; } //---------------------------------------------------------------------------- void __fastcall TWindowLibForm::TEMPSaveClick(TObject *Sender) { BEGIN_LOG(""); pBITMAPHANDLE bh = MainImageForm->iMainImage->uBitmap->RgnBitmap->Handle; // convert by celberus MainImageForm->WorkArea->SaveToFile(bh, WAPath + String("\\temp.wa")); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TWindowLibForm::iMainImageMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { BEGIN_LOG(""); TCursor OldCursor; TPItemImage *Image = MainImageForm->iMainImage; int hw, hh, mx, my; TSize size; if(WindowForm->rbAddition->Checked)TEMPSaveClick(this); //ADD ¸¦ À§ÇØ ±×Àü ÀÛ¾÷±¸¿ª save size.cx = Image->SubBitmap->Width; size.cy = Image->SubBitmap->Height; hw = size.cx / 2.0; hh = size.cy / 2.0; //2·Î ³ª´©¾úÀ»¶§ ³ª¸ÓÁö °ªÀ» ó¸®ÇØÁÖ±â À§ÇØ...mx,my ¸¦ ÀÌ¿ë... mx = int(size.cx)%2; my = int(size.cy)%2; int x, y; pBITMAPHANDLE bh = MainImageForm->iMainImage->uBitmap->RgnBitmap->Handle; // convert by celberus LoadFromFile(bh, WAPath + String("\\" + MainForm->sWork), false); //gabriel Image->SubVisible = false; X = X - hw; Y = Y - hh; if(X<0 && Y<0){ X = 0; Y = 0; MainImageForm->WorkArea->Move (X - MainImageForm->WorkArea->Range.left, Y - MainImageForm->WorkArea->Range.top); }else if(X < 0 && Y + size.cy > Image->uBitmap->Height){ X = 0; Y = Image->uBitmap->Height - size.cy; MainImageForm->WorkArea->Move (X - MainImageForm->WorkArea->Range.left, Y - (MainImageForm->WorkArea->Range.bottom - size.cy)); }else if(X + size.cx > Image->uBitmap->Width && Y<0){ X = Image->uBitmap->Width - size.cx; Y = 0; MainImageForm->WorkArea->Move (X - (MainImageForm->WorkArea->Range.right - size.cx), Y - MainImageForm->WorkArea->Range.top); }else if(X + size.cx > Image->uBitmap->Width && Y + size.cy > Image->uBitmap->Height){ X = Image->uBitmap->Width - size.cx; Y = Image->uBitmap->Height - size.cy; MainImageForm->WorkArea->Move (X - (MainImageForm->WorkArea->Range.right - size.cx), Y - (MainImageForm->WorkArea->Range.bottom - size.cy)); }else if(X<0){ X = 0; MainImageForm->WorkArea->Move (X - MainImageForm->WorkArea->Range.left, Y - MainImageForm->WorkArea->Range.top - my); }else if(X + size.cx > Image->uBitmap->Width){ X = Image->uBitmap->Width - size.cx; MainImageForm->WorkArea->Move (X - (MainImageForm->WorkArea->Range.right - size.cx), Y - MainImageForm->WorkArea->Range.top - my); }else if(Y<0){ Y = 0; MainImageForm->WorkArea->Move (X - MainImageForm->WorkArea->Range.left - mx, Y - MainImageForm->WorkArea->Range.top); }else if(Y + size.cy > Image->uBitmap->Height){ Y = Image->uBitmap->Height - size.cy; MainImageForm->WorkArea->Move (X - MainImageForm->WorkArea->Range.left - mx, Y - (MainImageForm->WorkArea->Range.bottom - size.cy)); }else { MainImageForm->WorkArea->Move (X - MainImageForm->WorkArea->Range.left - mx, Y - MainImageForm->WorkArea->Range.top - my); } MainImageForm->WorkArea->Move (X - MainImageForm->WorkArea->Range.left, Y - MainImageForm->WorkArea->Range.top); Image->SubVisible = false; if(WindowForm->rbAddition->Checked){ //ÀÛ¾÷±¸¿ª ADD Çҽà save ÇØ ³õÀº°Í LOAD WAtemp(); TEMPSaveClick(this); //ADD ¸¦ À§ÇØ ±×Àü ÀÛ¾÷±¸¿ª save WAtemp(); } MainImageForm->WorkAreaChange(); MainForm->UpdateMenuItems(NULL); Screen->Cursor = OldCursor; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TWindowLibForm::WAtemp() //2001.6.5. by lhskys ÀÛ¾÷±¸¿ª save { BEGIN_LOG(""); MainImageForm->WATEMP = true; pBITMAPHANDLE bh = MainImageForm->iMainImage->uBitmap->RgnBitmap->Handle; // convert by celberus MainImageForm->WorkArea->LoadFromFile(bh, WAPath + String("\\temp.wa")); MainImageForm->WATEMP = false; END_LOG; } //----------------------------------------------------------------------------- void __fastcall TWindowLibForm::FormShow(TObject *Sender) { BEGIN_LOG(""); Width = 200; Height = 600; //Height = 740; if (!bLoadAutoSave) { //óÀ½ ½ÇÇàÇØ¼­ default¸¦ ·ÎµåÇÑ ÀûÀÌ ¾ø´Ù¸é loadÇÑ´Ù. LoadDefaultData(); } UpdateItems(); END_LOG; } //--------------------------------------------------------------------------- bool __fastcall TWindowLibForm::LoadDefaultData() { BEGIN_LOG(""); TCursor cur; cur = Screen->Cursor; Screen->Cursor = crHourGlass; //AnsiString path, tpath; String path, tpath; path = FullPathName(String(InstallPath + "\\Motive"), String("Default.wal")); tpath = String(InstallPath + "\\Motive\\Error" + DateToStr(Date()) + ".wal"); /* if (FileExists(path)) {//gabriel if (!MergeWALibraryFile(path, gffNON)) { RenameFile(path, tpath); } } */ if (FileExists(path)) {//gabriel if (!MergeWALibraryFile(path, gffNON)) { RenameFile(path, tpath); } } Screen->Cursor = cur; bLoadAutoSave = true; END_LOG; return true; } //--------------------------------------------------------------------------- //AnsiString __fastcall TWindowLibForm::getWAFileName(int number) String __fastcall TWindowLibForm::getWAFileName(int number) { return WAPath + String("\\") + String(number) + String("wa.tex"); } //--------------------------------------------------------------------------- //AnsiString __fastcall TWindowLibForm::getFileName(int number) String __fastcall TWindowLibForm::getFileName(int number) { return WAPath + String("\\") + String(number); } //--------------------------------------------------------------------------- //gabriel: added ...... void __fastcall TWindowLibForm::SpeedButton1Click(TObject *Sender) { BEGIN_LOG(""); FileManagerForm = new TFileManagerForm(this); FileManagerForm->Extension = 8; FileManagerForm->FilterComboBox->Filter = "Texpro Work Area Library File (*.wal)|*.wal"; FileManagerForm->OnRead = LoadWALibraryFile; FileManagerForm->OnFileName = WALFileName; FileManagerForm->OnSave = SaveWALibraryFile; FileManagerForm->OnMerge = MergeWALibraryFile; FileManagerForm->ShowModal(); delete FileManagerForm; UpdateItems(); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TWindowLibForm::SpeedButton3Click(TObject *Sender) { BEGIN_LOG(""); WDeleteAll(Sender); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TWindowLibForm::SpeedButton4Click(TObject *Sender) { BEGIN_LOG(""); if (!MainImageForm) { END_LOG; return; } // by maxleo21c (05.06.09) Save(Sender); END_LOG; } //--------------------------------------------------------------------------- TPException __fastcall TWindowLibForm::SaveToWindowBitmap(T_WAItem *WindowItem, TGraphicFileFormat Index, TCompressMethod cm) //gabriel { BEGIN_LOG(""); TEXPIAFILEHEADER tpfh; TRect src; RGBQUAD rgb[256], Btrgb[256]; TTexpiaBitmap *tag = NULL, *tb = NULL; HDC dcSrc = NULL, dcTmp = NULL; TPException ec = EC_NONE; bool layer; DWORD dwWrite; TUnionBitmap *ub = NULL, *BtTemp=NULL; // ºñÆ®¸Ê Àӽà ÀúÀå By GreenFish // convert by celberus TPLayer *lay=NULL; TPLayerImage *iTempImage; bool SaveVectorToBitmap=false; if (Index == gffTEX || Index == gffTFC #ifdef TRIAL || Index == gffTEX_TRIAL || Index == gffTFC_TRIAL #endif ) { tpfh.Version = TexVersion('P', 'T', TextileFileVersion); tpfh.CanvasInfor = MainImageForm->CanvasInfor; tpfh.CanvasInfor.Width=MainImageForm->iMainImage->uBitmap->Width; //abcdabcdabcd tpfh.CanvasInfor.Height=MainImageForm->iMainImage->uBitmap->Height; //abcdabcdabcd tpfh.BitsPerPixel = MainImageForm->iMainImage->uBitmap->BitsPerPixel; tpfh.Compress = cm; if (MainImageForm->WorkArea->Mask) { src = MainImageForm->WorkArea->Range; if ((BtTemp = new TUnionBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } MainImageForm->iMainImage->uBitmap->GetColors(0, 256, Btrgb); if (!BtTemp->Create(src.right-src.left, src.bottom-src.top, MainImageForm->iMainImage->uBitmap->BitsPerPixel, Btrgb)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } BtTemp->Copy(0,0,src.right-src.left,src.bottom-src.top,MainImageForm->iMainImage->uBitmap,src.left,src.top,SRCCOPY); // BtTemp ¿¡ ub¸¦ º¸°ü } if (MainImageForm->iMainImage->LayerList->Count > 1) { // ·¹À̾î ÀÖÀ»¶§ if (MainForm->MoSave == true){ // Motive save½Ã¿¡´Â ÇÑÀåÀÇ Layer¸¸ if ((ub = new TUnionBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (MainImageForm->iMainImage->uBitmap->BitsPerPixel == 8) { MainImageForm->iMainImage->uBitmap->GetColors(0, 256, rgb); if (!ub->Create(MainImageForm->iMainImage->uBitmap->Width, MainImageForm->iMainImage->uBitmap->Height, 8, rgb)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } else { if (!ub->Create(MainImageForm->iMainImage->uBitmap->Width, MainImageForm->iMainImage->uBitmap->Height, 24)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } lay=(TPLayer *) MainImageForm->iMainImage->LayerList->Items[MainImageForm->iMainImage->Index]; ub->Copy(lay->LBitmap, SRCCOPY); } else { // ÀÏ¹Ý FileSave½Ã¿¡´Â Àü Layer¸¦ ÇÕÃļ­ ÀúÀå if ((ub = MainImageForm->iMainImage->Composition()) == NULL) goto fail; } if (MainImageForm->WorkArea->Mask) { tpfh.CanvasInfor.DotsPerInch = tpfh.CanvasInfor.DotsPerInch; tpfh.CanvasInfor.SetSize(cstFree, src.Right-src.Left, src.Bottom-src.Top); Byte *mp, *bp; // ºÎºÐ ÀúÀå½Ã ÀÛ¾÷±¸¿ª¸¸ ÀúÀåÇϵµ·Ï By GreenFish if (!MainImageForm->WorkArea->Mask->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!ub->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (ub->BitsPerPixel == 8) { for (int y = src.top ,z = 0 ; y < src.bottom; y++, z++) { bp = ub->GetScanLine(y); mp = MainImageForm->WorkArea->Mask->GetScanLine(z); bp += src.left; for (int x = 0 ; x < src.right-src.left ; x++, mp++) { if (*mp) { if(MainForm->WaSave){ TColor TempC = clBlack;//Palette->ColorData[0]->Color; *(bp+x) = TempC;//0x00; //2001.8.23 by lhskys ÀÛ¾÷±¸¿ªsave º¸À̰Ô... } }else { if(MainForm->WaSave){ TColor TempW = clWhite;//Palette->ColorData[0]->Color; *(bp+x) = TempW;//0x00; }else *(bp+x) = 1; } } ub->PutScanLine(y); } MainImageForm->WorkArea->Mask->StopScanLine(); ub->StopScanLine(); } else { // Full Color TColor TempC = MainImageForm->Palette->ColorData[1]->Color; for (int y = src.top ,z = 0 ; y < src.bottom; y++, z++) { bp = ub->GetScanLine(y); mp = MainImageForm->WorkArea->Mask->GetScanLine(z); bp += src.left*3; for (int x = 0; x < src.right-src.left; x++, bp+=3) { if ((mp[x >> 3] & (0x80 >> (x & 7))) == 0) { if (MainForm->WaSave){ TColor TempW = clWhite; *bp = clWhite ; *(bp+1) = clWhite; *(bp+2) = clWhite; }else { *(bp+2) = TempC & 0xFF ; *(bp+1) = (TempC>>8) & 0xFF; *bp = (TempC>>16) & 0xFF; } }else if (MainForm->WaSave){ //2001.8.23 by lhskys ÀÛ¾÷±¸¿ªsave º¸À̰Ô... *bp = 0x00 ; *(bp+1) = 0x00; *(bp+2) = 0x00; } } ub->PutScanLine(y); } MainImageForm->WorkArea->Mask->StopScanLine(); ub->StopScanLine(); } } else { src.Left = 0; src.Top = 0; src.Right = ub->Width; src.Bottom = ub->Height; } //============= if ((tag = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } MakeTexpiaTag(tag, ub, src, 0); ////////////// if (MainImageForm->WorkArea && MainImageForm->WorkArea->Mask) { SaveToWindowItemList(WindowItem, MainImageForm->Palette, tpfh, tag, &MainImageForm->WorkArea->Range, layer);//gabriel } delete ub; } else { // Layer ¾øÀ»¶§ if (MainImageForm->WorkArea->Mask) { tpfh.CanvasInfor.DotsPerInch = tpfh.CanvasInfor.DotsPerInch; tpfh.CanvasInfor.SetSize(cstFree, src.Right-src.Left, src.Bottom-src.Top); Byte *mp=NULL, *bp=NULL; // ºÎºÐ ÀúÀå½Ã ÀÛ¾÷±¸¿ª ¾ÈÂʸ¸ ÀúÀåÇϵµ·Ï By GreenFish if (!MainImageForm->WorkArea->Mask->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!MainImageForm->iMainImage->uBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (MainImageForm->iMainImage->uBitmap->BitsPerPixel == 8) { for (int y = src.top ,z = 0 ; y < src.bottom; y++, z++) { bp = MainImageForm->iMainImage->uBitmap->GetScanLine(y); // mp = MainImageForm->WorkArea->Mask->GetScanLine(z); bp += src.left; for (int x = 0 ; x < src.right-src.left ; x++, mp++) { if (*mp) { if(MainForm->WaSave){ *(bp+x) = clBlack;//TempC;//0x00; //2001.8.23 by lhskys ÀÛ¾÷±¸¿ªsave º¸À̰Ô... } }else { if(MainForm->WaSave){ *(bp+x) = clWhite;//TempW;//0x00; }else *(bp+x) = 1; } } MainImageForm->iMainImage->uBitmap->PutScanLine(y); } MainImageForm->WorkArea->Mask->StopScanLine(); MainImageForm->iMainImage->uBitmap->StopScanLine(); }else { // Full Color TColor TempC = MainImageForm->Palette->Color[1]; for (int y = src.top ,z = 0 ; y < src.bottom; y++, z++) { bp = MainImageForm->iMainImage->uBitmap->GetScanLine(y); mp = MainImageForm->WorkArea->Mask->GetScanLine(z); bp += src.left*3; for (int x = 0; x < src.right-src.left; x++, bp+=3) { if ((mp[x >> 3] & (0x80 >> (x & 7))) == 0) { if (MainForm->WaSave){ TColor TempW = clWhite; *bp = clWhite ; *(bp+1) = clWhite; *(bp+2) = clWhite; }else { *(bp+2) = TempC & 0xFF ; *(bp+1) = (TempC>>8) & 0xFF; *bp = (TempC>>16) & 0xFF; } }else if (MainForm->WaSave){ //2001.8.23 by lhskys ÀÛ¾÷±¸¿ªsave º¸À̰Ô... *bp = 0x00 ; *(bp+1) = 0x00; *(bp+2) = 0x00; } } MainImageForm->iMainImage->uBitmap->PutScanLine(y); } MainImageForm->WorkArea->Mask->StopScanLine(); MainImageForm->iMainImage->uBitmap->StopScanLine(); } } else { src.Left = 0; src.Top = 0; src.Right = MainImageForm->iMainImage->uBitmap->Width; src.Bottom = MainImageForm->iMainImage->uBitmap->Height; } if ((tag = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } MakeTexpiaTag(tag, MainImageForm->iMainImage->uBitmap, src); if (!MainForm->MoSave && !MainForm->WaSave) { HDC dcTemp=NULL; if ((dcTemp = tag->CreateDC())==NULL) goto fail; VecDraw->TagDraw(dcTemp, tag->Width, tag->Height, src); tag->DeleteDC(dcTemp); dcTemp = NULL; } if (MainImageForm->WorkArea && MainImageForm->WorkArea->Mask) { SaveToWindowItemList(WindowItem, MainImageForm->Palette, tpfh, tag, &MainImageForm->WorkArea->Range, layer);//gabriel } layer = false; } delete tag; if (MainImageForm->WorkArea->Mask) { MainImageForm->iMainImage->uBitmap->Copy(src.left,src.top,src.right-src.left,src.bottom-src.top,BtTemp,0,0,SRCCOPY); // BtTemp ¿¡ ub¸¦ º¸°ü delete BtTemp; BtTemp = NULL; // º¸°üÇß´ø ºñÆ®¸ÊÀ» ´Ù½Ã tb·Î } } MainImageForm->Modify = false; //2002.10.22. by lhskys ÀúÀå½Ã¿¡ ´Ù½Ã ÀúÀå ¹¯Áö ¾Ê±â. END_LOG; return EC_NONE; fail: if (ub) delete ub; if (tb) { if (dcTmp) tb->DeleteDC(dcTmp); delete tb; } if (dcSrc) MainImageForm->iMainImage->uBitmap->DeleteDC(dcSrc); //speed-test if (tag) delete tag; if (ec == EC_NONE) { ec = EC_FILE_NOT_WRITE; SAVE_EXCEPTION(ec); } END_LOG; return ec; } //--------------------------------------------------------------------------- TPException __fastcall TWindowLibForm::WorkArea_SaveToFile(T_WAItem *WindowItem, pBITMAPHANDLE bh) { BEGIN_LOG(""); TPException ec = EC_NONE; RGNXFORM XForm; HRGN hrgnSrc; XForm.uViewPerspective = TOP_LEFT; XForm.nXScalarNum = 1; XForm.nXScalarDen = 1; XForm.nYScalarNum = 1; XForm.nYScalarDen = 1; XForm.nXOffset = 0; XForm.nYOffset = 0; L_GetBitmapRgnHandle(bh, &XForm, &hrgnSrc); DWORD dwWrite; WindowItem->dwBytes = GetRegionData(hrgnSrc, 0, NULL); WindowItem->buf = VirtualAlloc(NULL, WindowItem->dwBytes, MEM_COMMIT, PAGE_READWRITE); GetRegionData(hrgnSrc, WindowItem->dwBytes, (RGNDATA *) (WindowItem->buf)); DeleteObject(hrgnSrc); END_LOG; return ec; } //--------------------------------------------------------------------------- bool __fastcall TWindowLibForm::SaveToWindowItemList(T_WAItem *WindowItem, TPalette *pPalette, TEXPIAFILEHEADER &tpfh, TTexpiaBitmap *tag, RECT *rect, bool layer) { //gabriel BEGIN_LOG(""); //TCanvas *srcCanvas = NULL; //TRect tagRect(0,0,80,100); WindowItem->Width = tpfh.CanvasInfor.Width; WindowItem->Height = tpfh.CanvasInfor.Height; //srcCanvas = tag->CreateCanvas(); //WindowItem->tag->Canvas->CopyRect(tagRect, srcCanvas, tagRect); //tag->DeleteCanvas(srcCanvas); WindowItem->tag->Copy(tag, SRCCOPY); WindowItemList->Add(WindowItem); END_LOG; return true; } //--------------------------------------------------------------------------- void __fastcall TWindowLibForm::LoadWindowItem() { BEGIN_LOG(""); TPException ec = EC_NONE; TPalette *TempPalette = NULL; T_WAItem *WindowItem = (T_WAItem *)WindowItemList->Items[WindowListView->Selected->Index]; if (MainImageForm->TempBitmap) delete MainImageForm->TempBitmap; if ((MainImageForm->TempBitmap = new TUnionBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((TempPalette = new TPalette)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } MainImageForm->waWidth = WindowItem->Width; MainImageForm->waHeight = WindowItem->Height; delete MainImageForm->TempBitmap; delete TempPalette; MainImageForm->TempBitmap = NULL; TempPalette = NULL; END_LOG; return; fail: EXCEPTION_MESSAGE_OK(ec); END_LOG; } //--------------------------------------------------------------------------- //void __fastcall TWindowLibForm::LoadFromFile(pBITMAPHANDLE bh, AnsiString s, bool offset) void __fastcall TWindowLibForm::LoadFromFile(pBITMAPHANDLE bh, String s, bool offset) { BEGIN_LOG(""); RECT r; XFORM xForm; xForm.eM11 = 1.0F; xForm.eM12 = 0.0F; xForm.eM21 = 0.0F; xForm.eM22 = 1.0F; xForm.eDx = 0.0F; xForm.eDy = 0.0F; HRGN hrgnSrc, hrgnMax; DWORD dwRead; DWORD dwBytes; #ifdef TEXSTYLIST if(!MainForm->WReopenMove || !WindowForm->rbAddition->Checked){ if (L_BitmapHasRgn(bh)) L_FreeBitmapRgn(bh); } #else if (L_BitmapHasRgn(bh)) L_FreeBitmapRgn(bh); #endif T_WAItem *WindowItem = (T_WAItem *) WindowItemList->Items[WindowListView->Selected->Index]; hrgnSrc = ExtCreateRegion(&xForm, WindowItem->dwBytes, (RGNDATA *)WindowItem->buf); if(offset==false) { GetRgnBox(hrgnSrc,&r); OffsetRgn(hrgnSrc,-r.left,-r.top); } hrgnMax = CreateRectRgn(0, 0, MainImageForm->iMainImage->uBitmap->Width, MainImageForm->iMainImage->uBitmap->Height); CombineRgn(hrgnSrc, hrgnSrc, hrgnMax, RGN_AND); //qe ÀÛ¾÷±¸¿ªÀÌ MainImage³Ñ¾î°¡¸é ¾ÈµÇÁö.. MainImageForm->WorkArea->SetRegion(bh, hrgnSrc); DeleteObject(hrgnMax); DeleteObject(hrgnSrc); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TWindowLibForm::FormResize(TObject *Sender) { WindowListView->Height = WindowLibForm->ClientHeight - WindowListView->Top - 7; WindowListView->Width = WindowLibForm->ClientWidth - 7;//WindowLibForm->Width - 7; } //--------------------------------------------------------------------------- void __fastcall TWindowLibForm::RestrictSize(TMessage &Msg) { BEGIN_LOG(""); ((POINT far *) Msg.LParam)[3].x = 200; ((POINT far *) Msg.LParam)[3].y = 400; ((POINT far *) Msg.LParam)[4].x = 900; ((POINT far *) Msg.LParam)[4].y = 900; TForm::Dispatch(&Msg); END_LOG; } //--------------------------------------------------------------------------- //AnsiString __fastcall TWindowLibForm::WALFileName(AnsiString FileName, // TGraphicFileFormat ExtIndex) String __fastcall TWindowLibForm::WALFileName(String FileName, TGraphicFileFormat ExtIndex) { BEGIN_LOG(""); //PChar s; Char *s; int FileNameLength, last1, last2, last3, last4; //char FileIndex1, FileIndex2, FileIndex3, FileIndex4; Char FileIndex1, FileIndex2, FileIndex3, FileIndex4; //=============================================================== FileNameLength = FileName.Length(); if(FileNameLength > 4){ last1 = FileNameLength-3; last2 = FileNameLength-2; last3 = FileNameLength-1; last4 = FileNameLength; FileIndex1 = L'.'; FileIndex2 = L'w'; FileIndex3 = L'a'; FileIndex4 = L'l'; if((FileIndex1 == FileName[last1])&&(FileIndex2 == FileName[last2]) && (FileIndex3 == FileName[last3])&&(FileIndex4 == FileName[last4])){ s = L"PASS"; }else s=NULL; }else s=NULL; //=============================================================== // s = AnsiStrScan(FileName.c_str(), '.'); if (s==NULL) { //AnsiString fn; String fn; fn = FileName + String(".wal"); END_LOG; return fn; } else { END_LOG; return FileName; } END_LOG; } //--------------------------------------------------------------------------- TPException __fastcall TWindowLibForm::LoadWALibraryFile(TFMReadParameter rp, bool changeFileFormat) { BEGIN_LOG(""); WDeleteAll(NULL); if (MergeWALibraryFile(FullPathName(rp.DirName, rp.FileName), (TGraphicFileFormat)0)) { END_LOG; return EC_NONE; } else { END_LOG; return EC_MEMORY_LACK; } END_LOG; } //--------------------------------------------------------------------------- //bool __fastcall TWindowLibForm::MergeWALibraryFile(AnsiString FileName, TGraphicFileFormat ExtIndex) bool __fastcall TWindowLibForm::MergeWALibraryFile(String FileName, TGraphicFileFormat ExtIndex) { BEGIN_LOG(""); HANDLE hFile = INVALID_HANDLE_VALUE; TPException ec = EC_NONE; DWORD dwRead; WORD WindowCount, tagBitCount; T_WAItem *tempItem; int Version = 0; int width = 80, height = 100; Byte *t_ptr; TEXPIAFILEHEADER tpfh; if (!FileExists(FileName)) { ec = EC_FILE_NOT_EXIST; SAVE_EXCEPTION(ec); goto fail; } if ((hFile = CreateFile(FileName.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { ec = EC_FILE_NOT_CREATE; SAVE_EXCEPTION(ec); goto fail; } if (!ReadFile(hFile, &tpfh, sizeof(tpfh), &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } // 090527 upper version if (tpfh.Version.Texpia == 'P' && tpfh.Version.Method == 'T' && tpfh.Version.Number > TextileFileVersion) { ec = EC_FILE_NOT_OPEN_NEWERVERSION; goto fail; } if (tpfh.BitsPerPixel == 24 && tpfh.Version.Texpia == 'P' && tpfh.Version.Method == 'T' && tpfh.Version.Number == 300) { CloseHandle(hFile); END_LOG; return Load_OldVersion_WindowFile(FileName, ExtIndex); } if (SetFilePointer(hFile, 0, NULL, FILE_BEGIN)==0xFFFFFFFF) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } if (!ReadFile(hFile, &Version, sizeof(int), &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } //File Tag Image ºÎºÐÀº ½ºÅµÈù´Ù. if (SetFilePointer(hFile, sizeof(Byte) * (width * 4) * height, NULL, FILE_CURRENT)== 0xFFFFFFFF) goto fail; if (!ReadFile(hFile, &(WindowCount), sizeof(WindowCount), &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } for(int i=0; i < WindowCount; i++) { tempItem = new T_WAItem; if (!ReadFile(hFile, &tempItem->dwBytes, sizeof(tempItem->dwBytes), &dwRead, NULL)) goto fail; tempItem->buf = VirtualAlloc(NULL, tempItem->dwBytes, MEM_COMMIT, PAGE_READWRITE); if (!ReadFile(hFile, tempItem->buf, tempItem->dwBytes, &dwRead, NULL)) goto fail; if (!ReadFile(hFile, &tempItem->Width, sizeof(int), &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } if (!ReadFile(hFile, &tempItem->Height, sizeof(int), &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } //for (int y = 0; y < height; y++) { // t_ptr = (Byte *)tempItem->tag->ScanLine[y]; // if (!ReadFile(hFile, t_ptr, sizeof(Byte) * width * 4, &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } //} tempItem->tag->LoadFromTexpiaFile(hFile, cmNone); WindowItemList->Add(tempItem); } CloseHandle(hFile); UpdateItems(); WindowAreaNotSaved = true; END_LOG; return true; fail: if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); WDeleteAll(NULL); END_LOG; return false; } //--------------------------------------------------------------------------- //bool __fastcall TWindowLibForm::Load_OldVersion_WindowFile(AnsiString FileName, TGraphicFileFormat ExtIndex) bool __fastcall TWindowLibForm::Load_OldVersion_WindowFile(String FileName, TGraphicFileFormat ExtIndex) { BEGIN_LOG(""); HANDLE hFile = INVALID_HANDLE_VALUE; TPException ec = EC_NONE; DWORD dwRead; Byte buf[320] = {0}; int i; WORD WindowCount, tagBitCount; TPalette *tagpalette = NULL, *dummypalette = NULL; TEXPIAFILEHEADER tpfh; T_WAItem *tempItem = NULL; TPalette *t_Palette = NULL; TTexpiaBitmap *t_tag = NULL; TUnionBitmap *t_pBitmap = NULL; TCanvas *srcCanvas = NULL; TRect tagRect(0,0,80,100); Graphics::TBitmap *PreviewTag;//gabriel PreviewTag = new Graphics::TBitmap; PreviewTag->PixelFormat = pf24bit; PreviewTag->Width = 80; PreviewTag->Height = 100; PreviewTag->Canvas->Brush->Color = clWhite; PreviewTag->Canvas->FillRect(Rect(0,0,80,100)); if (!FileExists(FileName)) { ec = EC_FILE_NOT_EXIST; SAVE_EXCEPTION(ec); goto fail; } if ((hFile = CreateFile(FileName.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { ec = EC_FILE_NOT_CREATE; SAVE_EXCEPTION(ec); goto fail; } if (!ReadFile(hFile, &tpfh, sizeof(tpfh), &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } if (!ReadFile(hFile, &(WindowCount), sizeof(WindowCount), &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } if ((tagpalette = new TPalette) == NULL) goto fail; if (tpfh.Version.Number < 302) tagpalette->LoadFromFileHandle(hFile,1); else tagpalette->LoadFromFileHandle(hFile,2); if (tagpalette) delete tagpalette; if (!ReadFile(hFile, &tagBitCount, sizeof(tagBitCount), &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } for (i=0; i<100; i++) { if (!ReadFile(hFile, buf, 240, &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } memcpy(PreviewTag->ScanLine[i], buf, 240); } if (PreviewTag) delete PreviewTag; PreviewTag = NULL; for(i=0; idwBytes, sizeof(tempItem->dwBytes), &dwRead, NULL)) goto fail; tempItem->buf = VirtualAlloc(NULL, tempItem->dwBytes, MEM_COMMIT, PAGE_READWRITE); if (!ReadFile(hFile, tempItem->buf, tempItem->dwBytes, &dwRead, NULL)) goto fail; t_Palette = new TPalette; t_pBitmap = new TUnionBitmap; t_tag = new TTexpiaBitmap; if ((ec = LoadFromTexpiaFile(hFile, t_Palette, tpfh, t_pBitmap, ExtIndex, false, t_tag)) != EC_NONE){ tempItem->tag->Copy(t_tag, SRCCOPY); tempItem->Width = tpfh.CanvasInfor.Width; tempItem->Height = tpfh.CanvasInfor.Height; WindowItemList->Add(tempItem); } //srcCanvas = t_tag->CreateCanvas(); //tempItem->tag->Canvas->CopyRect(tagRect, srcCanvas, tagRect); //t_tag->DeleteCanvas(srcCanvas); delete t_Palette; t_Palette = NULL; delete t_pBitmap; t_pBitmap = NULL; delete t_tag; t_tag = NULL; } CloseHandle(hFile); UpdateItems(); WindowAreaNotSaved = true; END_LOG; return true; fail: if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); if (tagpalette) delete tagpalette; tagpalette = NULL; if (t_Palette) delete t_Palette; t_Palette = NULL; if (t_tag) delete t_tag; t_tag = NULL; if (t_pBitmap) delete t_pBitmap; t_pBitmap = NULL; WDeleteAll(NULL); END_LOG; return false; } //--------------------------------------------------------------------------- //TPException __fastcall TWindowLibForm::SaveWALibraryFile(AnsiString DirName, AnsiString FileName, // TGraphicFileFormat ExtIndex, TCompressMethod cm) TPException __fastcall TWindowLibForm::SaveWALibraryFile(String DirName, String FileName, TGraphicFileFormat ExtIndex, TCompressMethod cm) { BEGIN_LOG(""); HANDLE hFile = INVALID_HANDLE_VALUE; TPException ec = EC_NONE; DWORD dwWrite; Byte *ptr; T_WAItem *TempItem; bool SelectedSave; int Version = 100, width = 80, height = 100; WORD WACount, tagBitCount; Graphics::TBitmap* tag = new Graphics::TBitmap; tag->Width = 80; tag->Height = 100; tag->PixelFormat = pf24bit; tag->Canvas->Brush->Color = clWhite; tag->Canvas->FillRect(Rect(0,0,80,100)); if ((hFile = CreateFile(FullPathName(DirName, FileName).c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { ec = EC_FILE_NOT_CREATE; SAVE_EXCEPTION(ec); goto fail; } if (!WriteFile(hFile, &Version, sizeof(int), &dwWrite, NULL)) goto fail; if (WindowListView->Selected) SelectedSave = true;//if any item is selected, SelectedSave function is on. else SelectedSave = false; if (DefaultSaving) SelectedSave = false;//when Default save WACount = (WORD)WindowItemList->Count; for (int i = 0; i < WindowItemList->Count; i++) if (SelectedSave == true) if (WindowListView->Items->Item[i]->Selected == false) WACount--; if (SelectedSave) { MakeSelectedTag(tag); } else { MakeTagFile(tag); } for (int y = 0; y < height; y++) { ptr = (Byte *)tag->ScanLine[y]; if (!WriteFile(hFile, ptr, sizeof(Byte) * width * 4, &dwWrite, NULL)) { ec = EC_FILE_NOT_WRITE; SAVE_EXCEPTION(ec); goto fail; } } if (!WriteFile(hFile, &(WACount), sizeof(WACount), &dwWrite, NULL)) goto fail; for (int i = 0; i < WindowItemList->Count; i++) { TempItem = (T_WAItem *) WindowItemList->Items[i]; if (SelectedSave == true) if (WindowListView->Items->Item[i]->Selected == false) continue; if (!WriteFile(hFile, &TempItem->dwBytes, sizeof(TempItem->dwBytes), &dwWrite, NULL)) goto fail; if (!WriteFile(hFile, TempItem->buf, TempItem->dwBytes, &dwWrite, NULL)) goto fail; if (!WriteFile(hFile, &TempItem->Width, sizeof(int), &dwWrite, NULL)) { ec = EC_FILE_NOT_WRITE; SAVE_EXCEPTION(ec); goto fail; } if (!WriteFile(hFile, &TempItem->Height, sizeof(int), &dwWrite, NULL)) { ec = EC_FILE_NOT_WRITE; SAVE_EXCEPTION(ec); goto fail; } //for (int y = 0; y < height; y++) { // ptr = (Byte *)TempItem->tag->ScanLine[y]; // if (!WriteFile(hFile, ptr, sizeof(Byte) * width * 4, &dwWrite, NULL)) { ec = EC_FILE_NOT_WRITE; SAVE_EXCEPTION(ec); goto fail; } //} TempItem->tag->SaveToTexpiaFile(hFile, cmNone); } CloseHandle(hFile); WindowAreaNotSaved = false; if (tag) delete tag; END_LOG; return ec; fail: if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); if (ec == EC_NONE) { ec = EC_FILE_NOT_WRITE; SAVE_EXCEPTION(ec); } if (tag) delete tag; END_LOG; return ec; } //--------------------------------------------------------------------------- bool __fastcall TWindowLibForm::MakeTagFile(Graphics::TBitmap* tag) { BEGIN_LOG(""); int n, widn, hein, x_ac, y_ac; x_ac = 0; y_ac = 0; int count = WindowItemList->Count; n = ceil(sqrt(count)); if (!n) n=1; widn = 80/n; hein = 100/n; T_WAItem *tempWindow = NULL; TRect tagRect(0,0,80,100), destRect; TCanvas *canvas; for (int i = 0; i < count; i++) { tempWindow = (T_WAItem *) WindowItemList->Items[i]; destRect = Rect(x_ac,y_ac,x_ac+widn,y_ac+hein); canvas = tempWindow->tag->CreateCanvas(); tag->Canvas->CopyRect(destRect, canvas, tagRect); tempWindow->tag->DeleteCanvas(canvas); x_ac += widn; if (x_ac + widn > 80) { y_ac += hein; x_ac = 0; } } END_LOG; return true; } //--------------------------------------------------------------------------- bool __fastcall TWindowLibForm::MakeSelectedTag(Graphics::TBitmap* tag) { BEGIN_LOG(""); int n, widn, hein, x_ac, y_ac; x_ac = 0; y_ac = 0; n = ceil(sqrt(WindowListView->SelCount)); if (!n) n=1; widn = 80/n; hein = 100/n; T_WAItem *tempWindow = NULL; TItemStates selected = TItemStates() << isSelected; TListItem *Item = WindowListView->Selected; TRect tagRect(0,0,80,100), destRect; TCanvas *canvas; while (Item){ tempWindow = (T_WAItem *) WindowItemList->Items[Item->Index]; destRect = Rect(x_ac,y_ac,x_ac+widn,y_ac+hein); canvas = tempWindow->tag->CreateCanvas(); tag->Canvas->CopyRect(destRect, canvas, tagRect); tempWindow->tag->DeleteCanvas(canvas); x_ac += widn; if (x_ac + widn > 80) { y_ac += hein; x_ac = 0; } Item = WindowListView->GetNextItem(Item, sdAll, selected); } END_LOG; return true; } //--------------------------------------------------------------------------- void __fastcall TWindowLibForm::ChangeUnit() { int width, height, dpi; T_WAItem *wItem = NULL; AnsiString strwid, strhei; for (int i = 0; i < WindowItemList->Count; i++){ wItem = (T_WAItem *)WindowItemList->Items[i]; TListItem *pItem = WindowListView->Items->Item[i]; height = wItem->Height; width = wItem->Width; if(MainImageForm){ dpi = MainImageForm->CanvasInfor.DotsPerInch; switch (MainImageForm->CurrentUnit) { case uDot : strwid = AnsiString(width); strhei = AnsiString(height); break; case uInch : strwid = Format("%.2f", OPENARRAY(TVarRec, ((double)width / dpi))); strhei = Format("%.2f", OPENARRAY(TVarRec, ((double)height / dpi))); break; case uCm : strwid = Format("%.2f", OPENARRAY(TVarRec, ((double)width / dpi * 2.54))); strhei = Format("%.2f", OPENARRAY(TVarRec, ((double)height / dpi * 2.54))); break; } } pItem->Caption = strwid + "X" + strhei; } } //---------------------------------------------------------------------------