//--------------------------------------------------------------------------- #include #include #include #pragma hdrstop #ifdef TEXTILE #include "Undo.h" #elif defined WEAVE #include "ColorChange_F.h" #endif #include "PalFileManager.h" #include "MainImage.h" #include "Palette.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "DIB256s" #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_PALFILEMANAGER StringTable[0] #define IDS_DIRECTORY StringTable[1] #define IDS_FILENAME StringTable[2] #define IDS_IFREAD StringTable[3] #define IDS_IFMERGE StringTable[4] #define IDS_IFSAVE StringTable[5] #define IDS_IFSAVEAS StringTable[6] #define IDS_IFDELETE StringTable[7] #define IDS_IFRENAME StringTable[8] #define IDS_INPUTFILENAME StringTable[9] //--------------------------------------------------------------------------- __fastcall TPFMForm::TPFMForm(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TPFMForm::FormCreate(TObject *Sender) { //========================================= StringTable.Create(DirectoryBin, Language, "PalFileManager"); SetSmallFont(Font); Caption = IDS_PALFILEMANAGER; SbRead->Caption = IDS_COMMON_READ; SbMerge->Caption = IDS_COMMON_MERGE; SbSave->Caption = IDS_COMMON_SAVE; SbSaveAs->Caption = IDS_COMMON_SAVEAS; SbRename->Caption = IDS_COMMON_RENAME; SbDelete->Caption = IDS_COMMON_DELETE; sbExit->Caption = IDS_COMMON_EXIT; Label1->Caption = IDS_COMMON_DRIVE; Label2->Caption = IDS_DIRECTORY; Label4->Caption = IDS_FILENAME; sbSv_as->Caption = IDS_COMMON_SAVE; //========================================= PFMDirectoryListBox->Directory = DirectoryColor; Palette = new TPalette; for (int i=0; i<256; i++) Palette->ColorData[i]->Copy(MainImageForm->Palette->ColorData[i]); Palette->UseColor = MainImageForm->Palette->UseColor; ReviewPalette->SetPalette(Palette); Item = 0; StatusBar1->Panels->Items[2]->Text = IDS_IFREAD; ReviewPalette->Repaint(); sbSv_as->Enabled = false; } //--------------------------------------------------------------------------- void __fastcall TPFMForm::FormClose(TObject *Sender, TCloseAction &Action) { delete Palette; } //--------------------------------------------------------------------------- void __fastcall TPFMForm::SbReadClick(TObject *Sender) { Item = 0; StatusBar1->Panels->Items[2]->Text = IDS_IFREAD; } //--------------------------------------------------------------------------- void __fastcall TPFMForm::SbMergeClick(TObject *Sender) { Item = 1; StatusBar1->Panels->Items[2]->Text = IDS_IFMERGE; } //--------------------------------------------------------------------------- void __fastcall TPFMForm::SbSaveClick(TObject *Sender) { Item = 2; StatusBar1->Panels->Items[2]->Text = IDS_IFSAVE; } //--------------------------------------------------------------------------- void __fastcall TPFMForm::SbSaveAsClick(TObject *Sender) { Item = 3; FileEdit->Clear(); FileEdit->SetFocus(); StatusBar1->Panels->Items[2]->Text = IDS_IFSAVEAS; } //--------------------------------------------------------------------------- void __fastcall TPFMForm::SbDeleteClick(TObject *Sender) { Item = 5; StatusBar1->Panels->Items[2]->Text = IDS_IFDELETE; } //--------------------------------------------------------------------------- void __fastcall TPFMForm::SbRenameClick(TObject *Sender) { Item = 4; StatusBar1->Panels->Items[2]->Text = IDS_IFRENAME; } //--------------------------------------------------------------------------- void __fastcall TPFMForm::sbExitClick(TObject *Sender) { ModalResult = mrOk; } //--------------------------------------------------------------------------- void __fastcall TPFMForm::PFMFileListBoxDblClick(TObject *Sender) { #ifdef TEXTILE MainImageForm->UndoSave(UK_PALETTE);//by jeegeo #endif PChar s; AnsiString Name; switch (Item) { case 0: //read if (PFMFileListBox->FileName=="") return; PaletteForm->DIB256Palette->LoadFromFile(PFMFileListBox->FileName.c_str()); #if defined(WEAVE) if (ColorChangeForm) ::RepaintColorChange(); else ::RepaintYarnColor(); #elif defined (PILE) ::RepaintYarnColor(); #elif defined(KNIT) #ifndef dogtest MainImageForm->RepaintKnitColor(); #endif #else ::RepaintColor(); #endif break; case 1: //Merge MergeMethod(); SbRead->Down = true; Item = 0; break; case 2: //Save SaveMethod(FileEdit->Text); SbRead->Down = true; Item = 0; break; case 4: //Rename Name = ""; if (InputQuery(IDS_COMMON_RENAME, IDS_COMMON_INPUTNAME, Name)) { s = AnsiStrScan((PChar)Name.c_str(), '.'); if (s==NULL) Name = Name+".fcr"; RenameFile(PFMFileListBox->FileName, Name); PFMFileListBox->Update(); } SbRead->Down = true; Item = 0; break; case 5: //Delete if (PFMFileListBox->FileName=="") return; Delete_File(PFMFileListBox->FileName); PFMFileListBox->Update(); SbRead->Down = true; Item = 0; break; } } //--------------------------------------------------------------------------- void __fastcall TPFMForm::sbSv_asClick(TObject *Sender) { PChar s; if (Item==3) { if (FileEdit->Text!="") { s = AnsiStrScan((PChar)FileEdit->Text.c_str(), '.'); if (s==NULL) FileEdit->Text = FileEdit->Text+".fcr"; PaletteForm->DIB256Palette->SaveToFile(FileEdit->Text.c_str()); } else { Sysutils::Beep(); MessageDlg(IDS_MESSAGE_INPUTFILE, mtWarning, TMsgDlgButtons()<Update(); } sbSv_as->Enabled = false; SbRead->Down = true; Item = 0; //k3dogs 1->0 } //--------------------------------------------------------------------------- void __fastcall TPFMForm::FileEditChange(TObject *Sender) { if (Item==3) { if (strlen(PChar(FileEdit->Text.c_str()))>0) sbSv_as->Enabled = true; else sbSv_as->Enabled = false; } } //--------------------------------------------------------------------------- void __fastcall TPFMForm::MergeMethod() { int i, s, n; TPalette *Userpal; if (PFMFileListBox->FileName=="") return; Userpal = new TPalette; Userpal->LoadFromFile(PFMFileListBox->FileName.c_str()); s = PaletteForm->DIB256Palette->Palette->UseColor; n = 251-PaletteForm->DIB256Palette->Palette->UseColor; for (i=1; iDIB256Palette->Palette->ColorData[s+i] = Userpal->ColorData[i+1]; #if defined(WEAVE) if (ColorChangeForm) ::RepaintColorChange(); else ::RepaintYarnColor(); #else ::RepaintColor(); #endif delete Userpal; } //--------------------------------------------------------------------------- void __fastcall TPFMForm::SaveMethod(AnsiString Name) { PChar s; if (PFMFileListBox->FileName=="") return; if (Name!="") { s = AnsiStrScan((PChar)Name.c_str(), '.'); if (s==NULL) Name = Name+".fcr"; PaletteForm->DIB256Palette->SaveToFile(Name.c_str()); } else { Sysutils::Beep(); MessageDlg(IDS_MESSAGE_INPUTFILE, mtWarning, TMsgDlgButtons()<Update(); } //--------------------------------------------------------------------------- void __fastcall TPFMForm::FileEditKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { if (Key == VK_RETURN) sbSv_asClick(sbSv_as); } //--------------------------------------------------------------------------- void __fastcall TPFMForm::PFMFileListBoxClick(TObject *Sender) { if (PFMFileListBox->ItemIndex != -1) ReviewPalette->LoadFromFile(PFMFileListBox->FileName.c_str()); ReviewPalette->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TPFMForm::ReviewPaletteMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { int i = ReviewPalette->CursorIndex; StatusBar1->Panels->Items[0]->Text = i-1; StatusBar1->Panels->Items[1]->Text = Format("%d - %d - %d", OPENARRAY(TVarRec, (255-Palette->ColorData[i]->RGB.rgbRed, 255-Palette->ColorData[i]->RGB.rgbGreen, 255-Palette->ColorData[i]->RGB.rgbBlue))); } //--------------------------------------------------------------------------- void __fastcall TPFMForm::Delete_File(AnsiString FileName) { SHFILEOPSTRUCT shfile; char *ucFrom = NULL; memset(&shfile, 0, sizeof(SHFILEOPSTRUCT)); shfile.hwnd = Handle; shfile.wFunc = FO_DELETE; if ((ucFrom = (char *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, FileName.Length()+2)) == NULL) goto fail; strcpy(ucFrom, FileName.c_str()); shfile.pFrom = ucFrom; shfile.fFlags = FOF_ALLOWUNDO ; SHFileOperation(&shfile); HeapFree(GetProcessHeap(), 0, ucFrom); return; fail: EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //---------------------------------------------------------------------------