//--------------------------------------------------------------------------- #include #include #include #pragma hdrstop #include "LogData.h" #include "APTable_F.h" #include "MainImage.h" #include "APMenu_F.h" #include "Graphics.hpp" #include "Define.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "Grids" #pragma link "RzShellCtrls" #pragma link "RzTreeVw" #pragma link "StdCtrls" #pragma link "RzCmboBx" #pragma link "RzButton" #pragma link "RzPanel" #pragma link "RzEdit" #pragma resource "*.dfm" TAPTableForm *APTableForm; //--------------------------------------------------------------------------- __fastcall TAPTableForm::TAPTableForm(TComponent* Owner) : TForm(Owner) { /* SetSmallFont(Font); sbInsert->Caption = IDS_COMMON_SAVEAS; sbsave->Caption = IDS_COMMON_SAVEAS; sbOverwrite->Caption = IDS_COMMON_SAVE; sbDelete->Caption = IDS_COMMON_DELETE; sbRename->Caption = IDS_COMMON_RENAME; sbExit->Caption = IDS_COMMON_EXIT; */ rztbSaveAs->Caption = IDS_COMMON_SAVEAS; rztbSave->Caption = IDS_COMMON_SAVE; rztbDelete->Caption = IDS_COMMON_DELETE; rztbRename->Caption = IDS_COMMON_RENAME; rztbExit->Caption = IDS_COMMON_EXIT; } //--------------------------------------------------------------------------- void __fastcall TAPTableForm::FormCreate(TObject *Sender) { APTableView = true; // sbsave->Enabled = false; /* TIniFile *IniFile = new TIniFile(AppDataItem + "\\Main.ini"); if (IniFile) { DirectoryListBox->Directory = IniFile->ReadString("APTable", "DirectoryName", DirectoryTreatment); delete IniFile; } */ DirectoryListBox->SelectedPathName = DirectoryTreatment; DirName = DirectoryListBox->SelectedPathName; Data = new TList; bFree = false; if (!FileList) FileList = new TList; } //--------------------------------------------------------------------------- void __fastcall TAPTableForm::FormDestroy(TObject *Sender) { TIniFile *IniFile = new TIniFile(AppDataItem + "\\Main.ini"); if (IniFile) { IniFile->WriteString("APTable", "DirectoryName", DirName); delete IniFile; } ExitData(); delete Data; if (FileList){ ClearFileList(); delete FileList; FileList = NULL; } } //--------------------------------------------------------------------------- void __fastcall TAPTableForm::InitForm() { if (MainImageForm->iMainImage->uBitmap->BitsPerPixel == 8) { Edit1->Visible = true; RzToolbar1->Visible = true; if (RzSpacer1->Width != 72) RzSpacer1->Width = 72; } else { Edit1->Visible = false; RzToolbar1->Visible = false; if (RzSpacer1->Width == 72) RzSpacer1->Width += Edit1->Width; ClientHeight -= RzToolbar1->Height; } InitData(); } //--------------------------------------------------------------------------- void __fastcall TAPTableForm::InitData() { BEGIN_LOG("APTable_F"); TFileInfor *fi; HANDLE hFile = INVALID_HANDLE_VALUE; int ec; TTexVersion ver; TGraphicFileFormat gff; if (!FileList) FileList = new TList; GetFileList(DirName, String("*.apt")); if (Data) { ExitData(); for (int i=0; i< FileList->Count; i++) { fi = new TFileInfor; String *wTemp = (String *)FileList->Items[i]; String wPath = FullPathName(DirName, *wTemp); fi->Name = *wTemp; fi->Bitmap = new Graphics::TBitmap; if ((hFile = CreateFile(wPath.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) goto next; gff = FindExtension(ExtractFileExt(wPath)); if (LoadFromTexpiaTag(hFile, fi, gff, &ver) != EC_NONE) goto next; CloseHandle(hFile); Data->Add(fi); continue; next: if (hFile!=INVALID_HANDLE_VALUE) CloseHandle(hFile); if (fi) delete fi; } if (Data->Count>0) { DrawGrid->RowCount = ((Data->Count -1)/DrawGrid->ColCount)+1; } else { DrawGrid->RowCount = 0; } DrawGrid->Repaint(); } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TAPTableForm::ExitData() { BEGIN_LOG("APTable_F"); TFileInfor *fi; if (Data) { while (Data->Count>0) { fi = (TFileInfor *)Data->Last(); Data->Remove(fi); delete fi; } } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TAPTableForm::DrawGridDrawCell(TObject *Sender, int Col, int Row, TRect &Rect, TGridDrawState State) { BEGIN_LOG("APTable_F"); int n; TFileInfor *fi; TRect r; APTableView = true; //2001.3.28 lhskys a,s È®´ë Ãà¼Ò¸¦ À§Çؼ­... n = Row * DrawGrid->ColCount + Col; if (n < Data->Count) { fi = (TFileInfor *) Data->Items[n]; if (Col == DrawGrid->Col && Row==DrawGrid->Row) FileName = fi->Name; StretchBlt(DrawGrid->Canvas->Handle,Rect.Left+10,Rect.Top+5,80,100, fi->Bitmap->Canvas->Handle,0,0,int(80/((StrToInt(txtZoom->Text)+2)/3.0)), int(100/((StrToInt(txtZoom->Text)+2)/3.0)),SRCCOPY); r.Left = Rect.Left+5; r.Top = Rect.Top+110; r.Right = Rect.Left+85; r.Bottom = Rect.Top + 110 + DrawGrid->Canvas->TextHeight(fi->Name); //r.Bottom = Rect.Top + 110 + WideCanvasTextHeight(DrawGrid->Canvas, fi->Name); DrawGrid->Canvas->TextRect(r, Rect.Left+5, Rect.Top+110, fi->Name); //WideCanvasTextRect(DrawGrid->Canvas, r, Rect.Left+5, Rect.Top+110, fi->Name); } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TAPTableForm::sbFunctionClick(TObject *Sender) { BEGIN_LOG("APTable_F"); //TSpeedButton *sb = (TSpeedButton *) Sender; TRzToolButton *tb = (TRzToolButton *)Sender; Item = tb->Tag; /* sbsave->Enabled = false; switch (Item) { case 1: sbsave->Enabled = true; }*/ if(tb->Tag ==1 || tb->Tag == 4) Edit1->SetFocus(); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TAPTableForm::DrawGridDblClick(TObject *Sender) { BEGIN_LOG("APTable_F"); TPException ec = EC_NONE; int n = DrawGrid->ColCount * DrawGrid->Row + DrawGrid->Col; if (n >= FileList->Count) { END_LOG; return; } String *wTemp = (String *)FileList->Items[n];// FileListBox->Items->Strings[n]; String wfn = *wTemp; String wPath = FullPathName(DirName, wfn); if (MainImageForm->iMainImage->uBitmap->BitsPerPixel == 8) { switch (Item) { case 2: #ifdef TRIAL ShowMessage(IDS_TRIAL_NOT_SUPPORTED.c_str()); return; #endif MakeBackupFile(DirName, wfn); if ((ec = SaveToAPTFile(wPath)) != EC_NONE){ BackupFileRollback(DirName, wfn); EXCEPTION_MESSAGE_OK(ec); } //FileListBox->Update(); InitData(); DrawGrid->Repaint(); break; case 3: Delete_File(wfn); break; case 4: if (RenameFile(wPath, FullPathName(DirName, PasteExtension(Edit1->Text))) == false) EXCEPTION_MESSAGE_OK(EC_FILE_EXIST_ALREADY); //FileListBox->Update(); InitData(); DrawGrid->Repaint(); break; } } else { APMenuForm->InsertImage(wPath); Close(); } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TAPTableForm::Delete_File(String wfn) { BEGIN_LOG("APTable_F"); SHFILEOPSTRUCT shfile; String asFrom; Char *ucFrom = NULL; memset(&shfile, 0, sizeof(SHFILEOPSTRUCT)); shfile.hwnd = Handle; shfile.wFunc = FO_DELETE; asFrom = FullPathName(DirName, wfn); if ((ucFrom = (Char *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Char)*(asFrom.Length()+2))) == NULL) goto fail; _tcscpy(ucFrom, asFrom.c_str()); shfile.pFrom = ucFrom; shfile.fFlags = FOF_ALLOWUNDO ; SHFileOperation(&shfile); HeapFree(GetProcessHeap(), 0, ucFrom); InitData(); DrawGrid->Repaint(); END_LOG; return; fail: if (ucFrom) HeapFree(GetProcessHeap(), 0, ucFrom); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TAPTableForm::Edit1KeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { BEGIN_LOG("APTable_F"); String wfn, cmfn, cmfn2; bool same = false; TPException ec = EC_NONE; String *wTemp; String wPath; int n = 0; if (Key == VK_RETURN) { wfn = PasteExtension(Edit1->Text); wPath = FullPathName(DirName, wfn); switch (Item) { case 1: #ifdef TRIAL ShowMessage(IDS_TRIAL_NOT_SUPPORTED.c_str()); END_LOG; return; #endif for (int i = 0; i < FileList->Count; i++) { wTemp = (String *)FileList->Items[i]; cmfn = *wTemp; cmfn = WideLowerCase(cmfn); cmfn2 = WideLowerCase(wfn); if (cmfn == cmfn2) { int btn = EXCEPTION_MESSAGE2_OKCANCEL(EC_FILE_EXIST_ALREADY, (IDS_MESSAGE_REALLYFILESAVE).c_str()); if (btn == mrOk){ MakeBackupFile(DirName, wfn); if ((ec = SaveToAPTFile(wPath)) != EC_NONE){ BackupFileRollback(DirName, wfn); EXCEPTION_MESSAGE_OK(ec); } } same = true; break; } } if (same == false){ if ((ec = SaveToAPTFile(wPath)) != EC_NONE) EXCEPTION_MESSAGE_OK(ec); } break; case 4 : n = DrawGrid->ColCount * DrawGrid->Row + DrawGrid->Col; if (n >= FileList->Count) { END_LOG; return; } wTemp = (String *)FileList->Items[n]; String rfn = *wTemp; if (RenameFile(FullPathName(DirName, rfn), FullPathName(DirName,(PasteExtension(Edit1->Text)))) == false) EXCEPTION_MESSAGE_OK(EC_FILE_EXIST_ALREADY); break; } InitData(); DrawGrid->Repaint(); } END_LOG; } //--------------------------------------------------------------------------- String __fastcall TAPTableForm::PasteExtension(String FileName) { BEGIN_LOG("APTable_F"); Char *s; String wfn; int FileNameLength, last1, last2, last3, last4; char FileIndex1, FileIndex2, FileIndex3, FileIndex4; //=============================================================== FileNameLength = FileName.Length(); if(FileNameLength > 4){ last1 = FileNameLength-3; last2 = FileNameLength-2; last3 = FileNameLength-1; last4 = FileNameLength; FileIndex1 = '.'; FileIndex2 = 'a'; FileIndex3 = 'p'; FileIndex4 = 't'; 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) wfn = FileName + String(".apt"); else wfn = FileName; END_LOG; return wfn; } //--------------------------------------------------------------------- TPException __fastcall TAPTableForm::SaveToAPTFile(String wfn) { BEGIN_LOG("APTable_F"); TEXPIAFILEHEADER tpfh; TRect src; RGBQUAD rgb[256]; TTexpiaBitmap *tag = NULL;//, *tb = NULL; TPException ec = EC_NONE; TPItemImage *Image = MainImageForm->iMainImage; HANDLE hFile = INVALID_HANDLE_VALUE; try { if ((hFile = CreateFile(wfn.c_str(),GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { ec = EC_FILE_NOT_CREATE; SAVE_EXCEPTION(ec); goto fail; } tpfh.Version = TexVersion('P', 'T', TextileFileVersion); tpfh.CanvasInfor = MainImageForm->CanvasInfor; tpfh.BitsPerPixel = 8; tpfh.Compress = cmZLib; if(MainImageForm->WorkArea->Mask) src = MainImageForm->WorkArea->Range; else { src.Left = 0; src.Right = MainImageForm->iMainImage->uBitmap->Width; src.Top = 0; src.Bottom = MainImageForm->iMainImage->uBitmap->Height; } tpfh.CanvasInfor.DotsPerInch = tpfh.CanvasInfor.DotsPerInch; tpfh.CanvasInfor.SetSize(cstFree, src.Right-src.Left, src.Bottom-src.Top); // if ((tb = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } // if (Image->uBitmap->BitsPerPixel == 8) { // Image->uBitmap->GetColors(0, 256, rgb); // tb->Create(Image->uBitmap->Width, Image->uBitmap->Height, 8, rgb); // } else { // tb->Create(Image->uBitmap->Width, Image->uBitmap->Height, Image->uBitmap->BitsPerPixel); // } if ((tag = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } APMakeTexpiaTag(tag, Image->uBitmap, src); // Image->uBitmap->CopyToTexpia(tb, 0, 0, tb->Width, tb->Height, 0, 0, SRCCOPY); // if (MainImageForm->WorkArea && MainImageForm->WorkArea->Mask) { // if (!SaveToTexpiaFile(hFile, MainImageForm->Palette, tpfh, tag, tb, // &MainImageForm->WorkArea->Range)) { ec = EC_FILE_NOT_WRITE; SAVE_EXCEPTION(ec); goto fail; } // } else { // if (!SaveToTexpiaFile(hFile, MainImageForm->Palette, tpfh, tag, tb)) { // ec = EC_FILE_NOT_WRITE; SAVE_EXCEPTION(ec); goto fail; // } // } if (MainImageForm->WorkArea && MainImageForm->WorkArea->Mask) { if (!SaveToTexpiaFile(hFile, MainImageForm->Palette, tpfh, tag, Image->uBitmap, &MainImageForm->WorkArea->Range)) { ec = EC_FILE_NOT_WRITE; SAVE_EXCEPTION(ec); goto fail; } } else { if (!SaveToTexpiaFile(hFile, MainImageForm->Palette, tpfh, tag, Image->uBitmap)) { ec = EC_FILE_NOT_WRITE; SAVE_EXCEPTION(ec); goto fail; } } } catch (...){ SAVE_EXCEPTION(EC_NO_MESSAGE); goto fail; } CloseHandle(hFile); if (tag) { delete tag; tag = NULL; } // if (tb) { delete tb; tb = NULL; } END_LOG; return ec; fail: // if (tb) delete tb; if (tag) delete tag; if (hFile != INVALID_HANDLE_VALUE){ CloseHandle(hFile); DeleteFile(wfn.c_str()); //shin À߸øµÈ ÆÄÀÏÀ̹ǷΠÁö¿î´Ù } if (ec == EC_NONE) ec = EC_FILE_NOT_WRITE; END_LOG; return ec; } //--------------------------------------------------------------------------- void __fastcall TAPTableForm::Edit1DblClick(TObject *Sender) { Edit1->SelectAll(); Edit1->SetFocus(); } //--------------------------------------------------------------------------- void __fastcall TAPTableForm::Edit1Click(TObject *Sender) { Edit1->SetFocus(); } //--------------------------------------------------------------------------- void __fastcall TAPTableForm::DirectoryListBox_Change(TObject *Sender) { InitData(); DrawGrid->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TAPTableForm::APMakeTexpiaTag(TTexpiaBitmap *tag, TUnionBitmap *tb, TRect src) { BEGIN_LOG("APTable_F"); TCanvas *cv = NULL; double rx, ry; double lastx,lasty; int i,w, h, x, y, hh, ww, mw, mh, rtn; // HDC dcSrc = NULL; Byte *srcp, *srcpp, *dstp; TPException ec = EC_NONE; RGBQUAD rgb[256]; Byte *DP, *SP; if (tb->BitsPerPixel==8) { if (!(tag->Create(80, 100, 8, rgb))) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail;} tb->GetColors(0, 256, rgb); tag->PutColors(0, 256, rgb); } else { if (!(tag->Create(80, 100, 24))) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail;} } if ((cv = tag->CreateCanvas())==NULL) { ec = EC_RESOURCE_LACK; SAVE_EXCEPTION(ec); goto fail; } cv->Brush->Color = clWhite; cv->FillRect(Rect(0, 0, 80, 100)); rx = 80.0/(src.Right-src.Left); ry = 100.0/(src.Bottom-src.Top); SetStretchBltMode(cv->Handle, COLORONCOLOR); if (rx>ry) { w = (src.Right-src.Left)*ry; h = (src.Bottom-src.Top)*ry; ww = 80 / w; mw = 80 % w; lastx = double(mw) / double(w); for(i = 0; i < ww ; i++){ rtn = tb->UnionStretchBlt(cv->Handle, i*w, 0, w, h, src.Left, src.Top, src.Right-src.Left, src.Bottom-src.Top, SRCCOPY); } rtn = tb->UnionStretchBlt(cv->Handle, i*w, 0, int(w*lastx), h, src.Left, src.Top, int((src.Right-src.Left)*lastx), src.Bottom-src.Top, SRCCOPY); } else { w = (src.Right-src.Left)*rx; h = (src.Bottom-src.Top)*rx; hh = 100 / h; mh = 100 % h; lasty = double(mh) / double(h); for(i = 0; i < hh ; i++) { rtn = tb->UnionStretchBlt(cv->Handle,0,i*h,w,h , src.Left,src.Top, src.Right-src.Left, src.Bottom-src.Top, SRCCOPY); } rtn = tb->UnionStretchBlt(cv->Handle,0,i*h,w,int(h*lasty),src.Left, src.Top, src.Right-src.Left,int((src.Bottom-src.Top)*lasty),SRCCOPY); } tag->DeleteCanvas(cv); cv = NULL; if (!rtn) { tb->StartScanLine(); tag->StartScanLine(); if (tb->BitsPerPixel==8) { for (y=0; yGetScanLine(y*ry); dstp = tag->GetScanLine(y); for (x=0; xPutScanLine(y); } } else { for (y=0; yGetScanLine(y/ry); dstp = tag->GetScanLine(y); for (x=0; xPutScanLine(y); } } tb->StopScanLine(); tag->StopScanLine(); } END_LOG; return; fail : if (cv) tag->DeleteCanvas(cv); EXCEPTION_MESSAGE_OK(ec); } //--------------------------------------------------------------------------- void __fastcall TAPTableForm::sbZoomClick(TObject *Sender) { int i; i = StrToInt(txtZoom->Text); i++; txtZoom->Text = IntToStr(i); } //--------------------------------------------------------------------------- void __fastcall TAPTableForm::txtZoomChange(TObject *Sender) { DrawGrid->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TAPTableForm::sbZoomOutClick(TObject *Sender) { int i; i = StrToInt(txtZoom->Text); if(i <2) i =1; else i--; txtZoom->Text = IntToStr(i); } //--------------------------------------------------------------------------- void __fastcall TAPTableForm::FormClose(TObject *Sender, TCloseAction &Action) { if (bFree) Action = caFree; APTableView = false; } //--------------------------------------------------------------------------- void __fastcall TAPTableForm::sbsaveClick(TObject *Sender) { BEGIN_LOG("APTable_F"); #ifdef TRIAL ShowMessage(IDS_TRIAL_NOT_SUPPORTED.c_str()); END_LOG; return; #endif String wPath, wfn, cmfn, cmfn2; bool same = false; TPException ec = EC_NONE; switch (Item) { case 1: wfn = PasteExtension(Edit1->Text); wPath = FullPathName(DirName, wfn); for (int i = 0; i < FileList->Count; i++) { String *wTemp = (String *)FileList->Items[i]; cmfn = *wTemp; cmfn = WideLowerCase(cmfn); cmfn2 = WideLowerCase(wfn); if (cmfn == cmfn2) { int btn = EXCEPTION_MESSAGE2_OKCANCEL(EC_FILE_EXIST_ALREADY, (IDS_MESSAGE_REALLYFILESAVE).c_str()); if (btn == mrOk){ MakeBackupFile(DirName, wfn); if ((ec = SaveToAPTFile(wPath)) != EC_NONE){ BackupFileRollback(DirName, wfn); EXCEPTION_MESSAGE_OK(ec); } } same = true; break; } } if (same == false){ if ((ec = SaveToAPTFile(wPath)) != EC_NONE) EXCEPTION_MESSAGE_OK(ec); } break; } //FileListBox->Update(); InitData(); DrawGrid->Repaint(); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TAPTableForm::DirectoryListBoxChange(TObject *Sender, TTreeNode *Node) { BEGIN_LOG("APTable_F"); DirName = DirectoryListBox->SelectedPathName; InitData(); DrawGrid->Repaint(); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TAPTableForm::GetFileList(String Path, String Filter) { BEGIN_LOG("APTable_F"); HANDLE hSrch = INVALID_HANDLE_VALUE; WIN32_FIND_DATAW wfd; Char fname[MAX_PATH]; BOOL bResult=TRUE; ClearFileList(); if (Path == NULL || Path == "") { END_LOG; return; } String wPath = String(Path+"\\"+Filter); hSrch=FindFirstFile(wPath.c_str(),&wfd); if (hSrch != INVALID_HANDLE_VALUE){ while(bResult){ if (/*wfd.dwFileAttributes && */ !(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && !(wfd.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) && !(wfd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)){ //&& !(wfd.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY)){ String* filename = new String(wfd.cFileName); FileList->Add(filename); } bResult = FindNextFile(hSrch,&wfd); } } else { wPath = Path + String("\\*.*"); hSrch=FindFirstFile(wPath.c_str(),&wfd); if (hSrch != INVALID_HANDLE_VALUE){ while(bResult){ if (/*wfd.dwFileAttributes && */ !(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && !(wfd.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) && !(wfd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)){ //!(wfd.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY)){ if (SameText(ExtractFileExt(wfd.cFileName), ExtractFileExt(String(Filter)))){ String* filename = new String(wfd.cFileName); FileList->Add(filename); } } bResult = FindNextFile(hSrch,&wfd); } } } FindClose(hSrch); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TAPTableForm::ClearFileList() { BEGIN_LOG("APTable_F"); String* file = NULL; if (FileList) { while (FileList->Count > 0) { file = (String*) FileList->Last(); if (file) { FileList->Remove(file); delete file; file = NULL; } } } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TAPTableForm::rztbExitClick(TObject *Sender) { APTableView = false; Close(); } //---------------------------------------------------------------------------