home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 May / VPR9705A.ISO / VPR_DATA / PROGRAM / CBTRIAL / SETUP / DATA.Z / FMXWIN.CPP < prev    next >
C/C++ Source or Header  |  1997-02-14  |  11KB  |  297 lines

  1. //----------------------------------------------------------------------------
  2. //Borland C++Builder
  3. //Copyright (c) 1987, 1997 Borland International Inc. All Rights Reserved.
  4. //----------------------------------------------------------------------------
  5. //---------------------------------------------------------------------------
  6. #include <vcl\vcl.h>
  7. #pragma hdrstop
  8. #include <ctype.h>
  9. #include <process.h>
  10.  
  11. #include "fmxUtils.h"
  12. #include "FAttrdlg.h"
  13. #include "fchngdlg.h"
  14. #include "fmxwin.h"
  15. //---------------------------------------------------------------------------
  16. #pragma link "sampreg"
  17. #pragma resource "*.dfm"
  18. TFormMain *FormMain;
  19. //---------------------------------------------------------------------------
  20. __fastcall TFormMain::TFormMain(TComponent* Owner)
  21.     : TForm(Owner)
  22. {
  23. }
  24. //---------------------------------------------------------------------------
  25. void __fastcall TFormMain::Exit1Click(TObject *Sender)
  26. {
  27.   Close();
  28. }
  29. //---------------------------------------------------------------------
  30. #pragma warn -sig
  31. void __fastcall TFormMain::Properties1Click(TObject *Sender)
  32. {
  33.  
  34.   unsigned short  Attributes;
  35.   unsigned short  NewAttributes;
  36.  
  37.   FileAttrDlg->FileDirName->Caption = FileList->Items->Strings[FileList->ItemIndex];
  38.   FileAttrDlg->FilePathName->Caption = FileList->Directory;
  39.   FileAttrDlg->ChangeDate->Caption = DateTimeToStr(FileDateTime(FileList->FileName));
  40.   Attributes = FileGetAttr(FileList->Items->Strings[FileList->ItemIndex]);
  41.   FileAttrDlg->ReadOnly->Checked = Attributes & faReadOnly;
  42.   FileAttrDlg->Archive->Checked = Attributes & faArchive;
  43.   FileAttrDlg->System->Checked = Attributes & faSysFile;
  44.   FileAttrDlg->Hidden->Checked = Attributes & faHidden;
  45.   if (FileAttrDlg->ShowModal()!= mrCancel){
  46.      NewAttributes = Attributes;
  47.      if (FileAttrDlg->ReadOnly->Checked)
  48.        NewAttributes = NewAttributes | faReadOnly;
  49.      else
  50.         NewAttributes = NewAttributes & ~faReadOnly;
  51.  
  52.      if (FileAttrDlg->Archive->Checked)
  53.        NewAttributes = NewAttributes | faArchive;
  54.      else
  55.        NewAttributes = NewAttributes & ~faArchive;
  56.  
  57.      if (FileAttrDlg->System->Checked)
  58.        NewAttributes = NewAttributes | faSysFile;
  59.      else
  60.        NewAttributes = NewAttributes & ~faSysFile;
  61.  
  62.      if (FileAttrDlg->Hidden->Checked)
  63.        NewAttributes = NewAttributes | faHidden;
  64.      else
  65.        NewAttributes = NewAttributes  & ~faHidden;
  66.      if (NewAttributes != Attributes)
  67.        FileSetAttr(FileAttrDlg->FileDirName->Caption, NewAttributes);
  68.   }
  69. }
  70. #pragma warn .sig
  71.  
  72. //---------------------------------------------------------------------
  73. void __fastcall TFormMain::DirectoryOutlineChange(TObject *Sender)
  74. {
  75.   FileList->Directory = DirectoryOutline->Directory;
  76.   DirectoryPanel->Caption=DirectoryOutline->Directory;
  77. }
  78. //---------------------------------------------------------------------
  79. void __fastcall TFormMain::DirectoryOutlineDragDrop(TObject *Sender,
  80.                                                     TObject *Source,
  81.                                                     int X, int Y)
  82. {
  83.   if (dynamic_cast<TFileListBox *> (Source)!=0)
  84.     ConfirmChange("Move", FileList->FileName,
  85.     DirectoryOutline ->Items[DirectoryOutline ->GetItem(X, Y)]->FullPath);
  86. }
  87. //---------------------------------------------------------------------
  88. void __fastcall TFormMain::DirectoryOutlineDragOver(TObject *Sender,
  89.                                                     TObject *Source,
  90.                                                     int X, int Y,
  91.                                                     TDragState State,
  92.                                                     bool &Accept)
  93. {
  94.   if (dynamic_cast<TFileListBox *> (Source))
  95.       Accept = True;
  96. }
  97.  
  98. //---------------------------------------------------------------------
  99. #pragma warn -stv
  100. void __fastcall TFormMain::ConfirmChange(const AnsiString ACaption,
  101.                                          AnsiString FromFile,
  102.                                          AnsiString ToFile)
  103. {
  104.   char buffer[700];
  105.   sprintf(buffer,"%s %s to %s?",ACaption, FromFile, ToFile);
  106.   if(MessageDlg(buffer,
  107.                 mtConfirmation,
  108.                 TMsgDlgButtons() << mbYes << mbNo,
  109.                 0) == mrYes){
  110.       {
  111.         if (ACaption == "Move")
  112.           MoveFile(FromFile, ToFile);
  113.         else if (ACaption == "Copy")
  114.           CopyFile(FromFile, ToFile);
  115.         else if (ACaption =="Rename")
  116.           RenameFile(FromFile, ToFile);
  117.       }
  118.      FileList->Update();
  119.    }
  120. }
  121. #pragma warn .stv
  122.  
  123. //---------------------------------------------------------------------
  124. void __fastcall TFormMain::FormCreate(TObject *Sender)
  125. {
  126.   static char * Drive_Letter[]={"a:\\","b:\\","c:\\","d:\\","e:\\","f:\\",
  127.       "g:\\","h:\\","i:\\","j:\\","k:\\","l:\\","m:\\","n:\\","o:\\","p:\\",
  128.       "q:\\","r:\\","s:\\","t:\\","u:\\","v:\\","w:\\","x:\\","y:\\","z:\\"};
  129.  
  130.   int  AddedIndex;
  131.      for(int x =0; x <= 25; x++ )
  132.       {
  133.         switch(GetDriveType(Drive_Letter[x]))
  134.           {
  135.               case DRIVE_REMOVABLE:
  136.                 AddedIndex=DriveTabSet->Tabs->AddObject(String(Drive_Letter[x]),
  137.                 Floppy->Picture->Graphic);
  138.               break;
  139.               case DRIVE_FIXED:
  140.                 AddedIndex=DriveTabSet->Tabs->AddObject(String(Drive_Letter[x]),
  141.                 Fixed->Picture->Graphic);
  142.               break;
  143.               case DRIVE_REMOTE:
  144.                 AddedIndex=DriveTabSet->Tabs->AddObject(String(Drive_Letter[x]),
  145.                 Network->Picture->Graphic);
  146.               break;
  147.               case DRIVE_CDROM:
  148.                 AddedIndex=DriveTabSet->Tabs->AddObject(Drive_Letter[x],
  149.                 Floppy->Picture->Graphic);
  150.               break;
  151.               case DRIVE_RAMDISK:
  152.                 AddedIndex=DriveTabSet->Tabs->AddObject(Drive_Letter[x],
  153.                 Floppy->Picture->Graphic);
  154.               break;
  155.             }
  156.  
  157.           if (toupper(*Drive_Letter[x]) == FileList->Drive)
  158.               DriveTabSet->TabIndex = AddedIndex;
  159.  
  160.        }
  161. }
  162.  
  163. //---------------------------------------------------------------------
  164. #pragma warn -stv
  165. void __fastcall TFormMain::FileListChange(TObject *Sender)
  166. {
  167.   AnsiString TheFileName;
  168.     if(FileList->ItemIndex>=0){
  169.         char buffer[255];
  170.         TheFileName =FileList->Items->Strings[FileList->ItemIndex];
  171.         sprintf(buffer,
  172.                 "%s  %d bytes",
  173.                 TheFileName,
  174.                 GetFileSize(TheFileName));
  175.         FilePanel->Caption = buffer;
  176.  
  177.         if (GetFileAttributes(TheFileName.c_str()) & FILE_ATTRIBUTE_DIRECTORY)
  178.           FileSelected = false;
  179.         else
  180.           FileSelected = true;
  181.     }
  182.     else {
  183.          FilePanel->Caption="";
  184.          FileSelected = false;
  185.     }
  186. }
  187. #pragma warn .stv
  188.  
  189. //---------------------------------------------------------------------
  190. void __fastcall TFormMain::FileListEndDrag(TObject *Sender,TObject *Target,
  191.                                            Integer X, Integer Y)
  192.  
  193. {
  194.    if (Target != NULL)
  195.    FileList->Update();
  196. }
  197. //---------------------------------------------------------------------
  198. void __fastcall TFormMain::FileListMouseDown(TObject *Sender,
  199.      TMouseButton Button, TShiftState Shift, Integer X, Integer Y)
  200. {
  201.   if(Button==mbLeft)
  202.     {
  203.       if (dynamic_cast<TFileListBox *>(Sender)!=0)
  204.            {
  205.              if(dynamic_cast<TFileListBox *>(Sender)->ItemAtPos(Point(X,Y),
  206.                             True) >=0)
  207.               dynamic_cast<TFileListBox *>(Sender)->BeginDrag(False);
  208.            }
  209.     }
  210. }
  211. //---------------------------------------------------------------------
  212. void __fastcall TFormMain::DriveTabSetClick(TObject *Sender)
  213. {
  214.   DirectoryOutline->Drive= *((DriveTabSet->Tabs->Strings
  215.                              [DriveTabSet->TabIndex]).c_str());
  216. }
  217. //---------------------------------------------------------------------
  218. void __fastcall TFormMain::DriveTabSetDrawTab(TObject *Sender,
  219.                                               TCanvas *TabCanvas,
  220.                                               TRect &R, Integer Index,
  221.                                               Boolean Selected)
  222. {
  223.   Graphics::TBitmap *Bitmap;
  224.   Bitmap = (Graphics::TBitmap *) (DriveTabSet->Tabs->Objects[Index]);
  225.   TabCanvas->Draw(R.Left, R.Top + 4, Bitmap);
  226.   TabCanvas->TextOut(R.Left + 2 + Bitmap->Width, R.Top + 2,
  227.               DriveTabSet->Tabs->Strings[Index].SubString(1,1));
  228.  
  229. }
  230. //---------------------------------------------------------------------
  231. void __fastcall TFormMain::DriveTabSetMeasureTab(TObject *Sender,
  232.                  Integer Index, Integer &TabWidth)
  233. {
  234.   int BitmapWidth;
  235.   BitmapWidth = ((Graphics::TBitmap *)
  236.                 (DriveTabSet->Tabs->Objects[Index]))->Width;
  237.   TabWidth=TabWidth+2+BitmapWidth;
  238. }
  239. //---------------------------------------------------------------------
  240. void __fastcall TFormMain::File1Click(TObject *Sender)
  241. {
  242.     Open1->Enabled = FileSelected;
  243.     Delete1->Enabled = FileSelected;
  244.     Copy1->Enabled = FileSelected;
  245.     Move1->Enabled = FileSelected;
  246.     Rename1->Enabled = FileSelected;
  247.     Properties1->Enabled = FileSelected;
  248. }
  249. //---------------------------------------------------------------------
  250. void __fastcall TFormMain::Delete1Click(TObject *Sender)
  251. {
  252.   if(MessageDlg("Delete" + FileList->FileName + "?",
  253.                 mtConfirmation,
  254.                 TMsgDlgButtons() << mbYes << mbNo, 0) == mrYes){
  255.     if(DeleteFile(FileList->FileName.c_str()))
  256.       FileList->Items->Delete(FileList->ItemIndex);
  257.   }
  258. }
  259. //---------------------------------------------------------------------
  260. void __fastcall TFormMain::Open1Click(TObject *Sender)
  261. {
  262.   if (HasAttr(FileList->FileName, faDirectory))
  263.     DirectoryOutline->Directory = FileList->FileName;
  264.   else
  265.     ExecuteFile(FileList->FileName," ", DirectoryOutline->Directory, SW_SHOW);
  266.  }
  267. //---------------------------------------------------------------------
  268. void __fastcall TFormMain::FileChange(TObject *Sender)
  269. {
  270.   if (dynamic_cast<TMenuItem *>(Sender) == Move1 )
  271.     ChangeDlg->Caption = "Move" ;
  272.   else if (dynamic_cast<TMenuItem *>(Sender) == Copy1)
  273.     ChangeDlg->Caption = "Copy";
  274.   else if (dynamic_cast<TMenuItem *>(Sender) == Rename1)
  275.     ChangeDlg->Caption = "Rename";
  276.   else
  277.     _c_exit();
  278.  
  279.   ChangeDlg->CurrentDir->Caption = DirectoryOutline->Directory;
  280.   ChangeDlg->FromFileName->Text = FileList->FileName;
  281.   ChangeDlg->ToFileName->Text = "";
  282.  
  283.   if ((ChangeDlg->ShowModal() != mrCancel) &&
  284.      (ChangeDlg->ToFileName->Text != ""))
  285.  
  286.     ConfirmChange(ChangeDlg->Caption,
  287.                   ChangeDlg->FromFileName->Text,
  288.                   ChangeDlg->ToFileName->Text);
  289.  
  290. }
  291.  
  292. void __fastcall TFormMain::FileListDblClick(TObject *Sender)
  293. {
  294.   Open1Click(Sender);
  295. }
  296. //---------------------------------------------------------------------
  297.