home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / borland / cb / setup / cbuilder / data.z / MDIEDIT.CPP < prev    next >
C/C++ Source or Header  |  1997-02-28  |  6KB  |  197 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.  
  9. #include "MDIEdit.h"
  10. #include "MDIFrame.h"
  11. //---------------------------------------------------------------------------
  12. #pragma resource "*.dfm"
  13. TEditForm *EditForm;
  14.  
  15. //---------------------------------------------------------------------------
  16.  
  17. const AnsiString DefaultFileName = AnsiString("Untitled");
  18.  
  19. __fastcall TEditForm::TEditForm(TComponent* Owner)
  20.     : TForm(Owner)
  21. {
  22. }
  23. //---------------------------------------------------------------------------
  24. void __fastcall TEditForm::Open(const AnsiString AFileName)
  25. {
  26.    PathName = AFileName;
  27.    Caption = ExtractFileName(AFileName);
  28.    Editor->Lines->LoadFromFile(PathName);
  29.    Editor->SelStart = 0;
  30.    Editor->Modified = false;
  31. }
  32. void __fastcall TEditForm::New1Click(TObject *Sender)
  33. {
  34.   FrameForm->New1Click(Sender);
  35. }
  36. //---------------------------------------------------------------------
  37. void __fastcall TEditForm::Open1Click(TObject *Sender)
  38. {
  39.   FrameForm->Open1Click(Sender);
  40. }
  41. //---------------------------------------------------------------------
  42. void __fastcall TEditForm::Close1Click(TObject *Sender)
  43. {
  44.   Close();
  45. }
  46. //---------------------------------------------------------------------
  47. void __fastcall TEditForm::Exit1Click(TObject *Sender)
  48. {
  49.   FrameForm->Exit1Click(Sender);
  50. }
  51. //---------------------------------------------------------------------
  52. void __fastcall TEditForm::Save1Click(TObject *Sender)
  53. {
  54.   if(Caption == DefaultFileName){
  55.     Saveas1Click(Sender);
  56.   }
  57.   else{
  58.     Editor->Lines->SaveToFile(PathName);
  59.     Editor->Modified = false;
  60.   }
  61. }
  62. //---------------------------------------------------------------------
  63. void __fastcall TEditForm::Saveas1Click(TObject *Sender)
  64. {
  65.   SaveFileDialog->FileName = PathName;
  66.   if (SaveFileDialog->Execute() ){
  67.     PathName= SaveFileDialog->FileName;
  68.     Caption = ExtractFileName(PathName);
  69.     Save1Click(Sender);
  70.   }
  71. }
  72. //---------------------------------------------------------------------
  73. void __fastcall TEditForm::Print1Click(TObject *Sender)
  74. {
  75.   if (PrintDialog1->Execute()){
  76.     try {
  77.         Editor->Print(PathName);
  78.     }
  79.     catch(...){
  80.         Printer()->EndDoc();
  81.         throw;
  82.     }
  83.   }
  84. }
  85. //---------------------------------------------------------------------
  86. void __fastcall TEditForm::Printersetup1Click(TObject *Sender)
  87. {
  88.   PrinterSetupDialog1->Execute();
  89. }
  90. //---------------------------------------------------------------------
  91. void __fastcall TEditForm::Cut1Click(TObject *Sender)
  92. {
  93.   Editor->CutToClipboard();
  94. }
  95. //---------------------------------------------------------------------
  96. void __fastcall TEditForm::Copy1Click(TObject *Sender)
  97. {
  98.   Editor->CopyToClipboard();
  99. }
  100. //---------------------------------------------------------------------
  101. void __fastcall TEditForm::Paste1Click(TObject *Sender)
  102. {
  103.   Editor->PasteFromClipboard();
  104. }
  105. //---------------------------------------------------------------------
  106. void __fastcall TEditForm::Delete1Click(TObject *Sender)
  107. {
  108.   Editor->ClearSelection();
  109. }
  110. //---------------------------------------------------------------------
  111. void __fastcall TEditForm::Selectall1Click(TObject *Sender)
  112. {
  113.   Editor->SelectAll();
  114. }
  115. //---------------------------------------------------------------------
  116. void __fastcall TEditForm::Left1Click(TObject *Sender)
  117. {
  118.   Left1->Checked   = false;
  119.   Right1->Checked  = false;
  120.   Center1->Checked = false;
  121.  
  122.   if( dynamic_cast<TMenuItem *>(Sender) !=0)
  123.     dynamic_cast <TMenuItem *>(Sender) ->Checked = true;
  124.     {
  125.      if (Left1->Checked )
  126.        Editor->Paragraph->Alignment = taLeftJustify;
  127.      else if (Right1->Checked)
  128.        Editor->Paragraph->Alignment= taRightJustify;
  129.      else if (Center1->Checked)
  130.        Editor->Paragraph->Alignment = taCenter;
  131.     }
  132. }
  133. //---------------------------------------------------------------------
  134. void __fastcall TEditForm::Wordwrap1Click(TObject *Sender)
  135. {
  136.   Editor->WordWrap = !Editor->WordWrap; //toggle word wrapping
  137.     if (Editor->WordWrap)
  138.       Editor->ScrollBars = ssVertical;
  139.     else
  140.       Editor->ScrollBars = ssBoth;
  141.       Wordwrap1->Checked = Editor->WordWrap; // set menu item check
  142.  
  143. }
  144. //---------------------------------------------------------------------
  145. void __fastcall TEditForm::Font1Click(TObject *Sender)
  146. {
  147.   FontDialog1->Font= Editor->Font;
  148.  
  149.   if (FontDialog1->Execute())
  150.     Editor->SelAttributes->Assign(FontDialog1->Font);
  151. }
  152. //---------------------------------------------------------------------
  153. void __fastcall TEditForm::Edit1Click(TObject *Sender)
  154. {
  155.   bool HasSelection;
  156.   Paste1->Enabled = Clipboard()->HasFormat(CF_TEXT);
  157.   Paste2->Enabled = Paste1->Enabled;
  158.   HasSelection = Editor->SelLength > 0;
  159.   Cut1->Enabled = HasSelection;
  160.   Cut2->Enabled = HasSelection;
  161.   Copy1->Enabled = HasSelection;
  162.   Copy2->Enabled = HasSelection;
  163.   Delete1->Enabled = HasSelection;
  164. }
  165. //---------------------------------------------------------------------
  166. void __fastcall TEditForm::FormClose(TObject *Sender, TCloseAction &Action)
  167. {
  168. Action=caFree;
  169. }
  170. //---------------------------------------------------------------------
  171. void __fastcall TEditForm::FormCloseQuery(TObject *Sender,
  172.     bool &CanClose)
  173. {
  174.   char buffer[255];
  175.   if (Editor->Modified)
  176.     {
  177.       Set<TMsgDlgBtn,0,8> temp_set;
  178.       temp_set<< mbYes<<mbNo <<mbCancel;
  179.       sprintf(buffer,"Save changes to %s?",PathName.c_str());
  180.  
  181.       switch(MessageDlg(buffer, mtConfirmation,temp_set,0))
  182.       {
  183.         case mrYes:
  184.           Save1Click(this);
  185.         case mrCancel:
  186.           CanClose=false;
  187.       }
  188.  
  189.    }
  190. }
  191. //---------------------------------------------------------------------
  192. void __fastcall TEditForm::FormCreate(TObject *Sender)
  193. {
  194.    PathName = DefaultFileName;
  195. }
  196. //---------------------------------------------------------------------
  197.