home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / borland / cb / setup / cbuilder / data.z / MDICHILD.CPP < prev    next >
C/C++ Source or Header  |  1997-02-28  |  8KB  |  200 lines

  1. //----------------------------------------------------------------------------
  2. //Borland C++Builder
  3. //Copyright (c) 1987, 1997 Borland International Inc. All Rights Reserved.
  4. //----------------------------------------------------------------------------
  5. //---------------------------------------------------------------------------
  6. #include <vcl.h>
  7. #pragma hdrstop
  8.  
  9. #include "mdichild.h"
  10. #include "mdimain.h"
  11. //---------------------------------------------------------------------------
  12. #pragma resource "*.dfm"
  13. TMDIChildForm *MDIChildForm;
  14. //---------------------------------------------------------------------------
  15. __fastcall TMDIChildForm::TMDIChildForm(TComponent* Owner)
  16.     : TForm(Owner)
  17. {
  18. }
  19. //---------------------------------------------------------------------------
  20. void __fastcall TMDIChildForm::DeleteObject1Click(TObject *Sender)
  21. {
  22.   if ((OleContainer1->State == osEmpty) ||
  23.       (MessageDlg("Replace existing object?",
  24.                    mtConfirmation,
  25.                    TMsgDlgButtons() << mbOK << mbCancel,
  26.                    0) == mrOk)) {
  27.     OleContainer1->DestroyObject();
  28.     LocalMenu->Tag = 0;
  29.     while (LocalMenu->Items->Count != 4)
  30.       delete LocalMenu->Items->Items[0];
  31.   }
  32.   MainForm->SaveButton->Enabled = OleContainer1->State != osEmpty;
  33. }
  34. //---------------------------------------------------------------------------
  35. void __fastcall TMDIChildForm::Copy1Click(TObject *Sender)
  36. {
  37.   OleContainer1->Copy();
  38.   MainForm->PasteButton->Enabled = True;
  39. }
  40. //---------------------------------------------------------------------------
  41. void __fastcall TMDIChildForm::CopyObject1Click(TObject *Sender)
  42. {
  43.   OleContainer1->Copy();
  44.   MainForm->PasteButton->Enabled = True;
  45. }
  46. //---------------------------------------------------------------------------
  47. void __fastcall TMDIChildForm::Cut1Click(TObject *Sender)
  48. {
  49.   OleContainer1->Copy();
  50.   OleContainer1->DestroyObject();
  51.   MainForm->CutButton->Enabled = False;
  52.   MainForm->CopyButton->Enabled = False;
  53.   MainForm->PasteButton->Enabled = True;
  54.   FFileName = "";
  55. }
  56. //---------------------------------------------------------------------------
  57. void __fastcall TMDIChildForm::Edit1Click(TObject *Sender)
  58. {
  59.     Cut1->Enabled = OleContainer1->State != osEmpty;
  60.     Copy1->Enabled = OleContainer1->State != osEmpty;
  61.     Paste1->Enabled = OleContainer1->CanPaste;
  62.     PasteSpecial1->Enabled = OleContainer1->CanPaste;
  63.     Object2->Enabled = OleContainer1->State != osEmpty;
  64.     CLear1->Enabled = OleContainer1->State != osEmpty;
  65. }
  66. //---------------------------------------------------------------------------
  67. void __fastcall TMDIChildForm::InsertObject1Click(TObject *Sender)
  68. {
  69.   if ((OleContainer1->State == osEmpty) ||
  70.       (MessageDlg("Delete current OLE object?",
  71.                    mtConfirmation,
  72.                    TMsgDlgButtons() << mbOK << mbCancel,
  73.                    0) == mrOk))
  74.     if (OleContainer1->InsertObjectDialog()){
  75.       MainForm->CutButton->Enabled = True;
  76.       MainForm->CopyButton->Enabled = True;
  77.       MainForm->SaveButton->Enabled = OleContainer1->Modified;
  78.     }
  79. }
  80. //---------------------------------------------------------------------------
  81. void __fastcall TMDIChildForm::LocalMenuPopup(TObject *Sender)
  82. {
  83.   int i;
  84.  
  85.   CopyObject1->Enabled = OleContainer1->State != osEmpty;
  86.   DeleteObject1->Enabled = OleContainer1->State != osEmpty;
  87.   Properties1->Enabled = OleContainer1->State != osEmpty;
  88.   if (LocalMenu->Tag > 0)
  89.     exit;
  90.   if ((OleContainer1->State != osEmpty) && (OleContainer1->ObjectVerbs->Count > 0)){
  91.     LocalMenu->Items->Insert(0, NewLine());
  92.     for (i = 0; i < OleContainer1->ObjectVerbs->Count; i++)
  93.       LocalMenu->Items->Insert(i, NewItem(OleContainer1->ObjectVerbs->Names[i],
  94.                                           0, false, true, OnClick, 0, ""));
  95.     LocalMenu->Tag = 1;
  96.   } //if
  97. }
  98. //---------------------------------------------------------------------------
  99. void __fastcall TMDIChildForm::FormActivate(TObject *Sender)
  100. {
  101.     MainForm->CopyButton->Enabled = OleContainer1->State != osEmpty;
  102.     MainForm->CutButton->Enabled = OleContainer1->State != osEmpty;
  103.     MainForm->PasteButton->Enabled = OleContainer1->CanPaste;
  104.     MainForm->SaveButton->Enabled = OleContainer1->Modified;
  105. }
  106. //---------------------------------------------------------------------------
  107. void __fastcall TMDIChildForm::FormClose(TObject *Sender, TCloseAction &Action)
  108. {
  109.   Action = caFree;
  110.     MainForm->CutButton->Enabled = False;
  111.     MainForm->CopyButton->Enabled = False;
  112.     MainForm->PasteButton->Enabled = False;
  113.     MainForm->SaveButton->Enabled = False;
  114. }
  115. //---------------------------------------------------------------------------
  116. void __fastcall TMDIChildForm::FormCloseQuery(TObject *Sender, bool &CanClose)
  117. {
  118.   CanClose = True;
  119.   if (OleContainer1->Modified)
  120.     switch (MessageDlg("Would you like to save changes to the object?",
  121.                        mtConfirmation,
  122.                        TMsgDlgButtons() << mbYes <<  mbNo << mbCancel,
  123.                        0)){
  124.       case mrYes:
  125.           MainForm->Save1Click(Sender);
  126.           if (OleContainer1->Modified)
  127.             CanClose = False;
  128.           break;
  129.       case mrCancel:
  130.           CanClose = False;
  131.           break;
  132.     }
  133. }
  134. //---------------------------------------------------------------------------
  135. void __fastcall TMDIChildForm::FormCreate(TObject *Sender)
  136. {
  137.   FFileName = "";
  138.   FSaved = False;
  139. }
  140. //---------------------------------------------------------------------------
  141. void __fastcall TMDIChildForm::Properties1Click(TObject *Sender)
  142. {
  143.   OleContainer1->ObjectPropertiesDialog();
  144. }
  145. //---------------------------------------------------------------------------
  146. void __fastcall TMDIChildForm::OleContainer1Activate(TObject *Sender)
  147. {
  148.   OleContainer1->Modified = True;
  149. }
  150. //---------------------------------------------------------------------------
  151. void __fastcall TMDIChildForm::Paste1Click(TObject *Sender)
  152. {
  153.   if ((OleContainer1->State == osEmpty) ||
  154.       (MessageDlg("Delete current OLE object?",
  155.                    mtConfirmation,
  156.                    TMsgDlgButtons() << mbOK << mbCancel,
  157.                    0) == mrOk))
  158.     OleContainer1->Paste();
  159.   MainForm->SaveButton->Enabled = OleContainer1->Modified;
  160. }
  161. //---------------------------------------------------------------------------
  162. void __fastcall TMDIChildForm::PasteSpecial1Click(TObject *Sender)
  163. {
  164.  if ((OleContainer1->State == osEmpty) ||
  165.        (MessageDlg("Delete current OLE object?",
  166.                    mtConfirmation,
  167.                    TMsgDlgButtons() << mbOK << mbCancel,
  168.                    0) == mrOk)){
  169.     if (OleContainer1->PasteSpecialDialog()){
  170.       MainForm->CutButton->Enabled = True;
  171.       MainForm->CopyButton->Enabled = True;
  172.       MainForm->PasteButton->Enabled = OleContainer1->CanPaste;
  173.     }
  174.   }
  175. }
  176. //---------------------------------------------------------------------------
  177. void __fastcall TMDIChildForm::VerbClick(TObject *Sender)
  178. {
  179.   OleContainer1->DoVerb(OleContainer1->ObjectVerbs->IndexOf(dynamic_cast<TMenuItem*>(Sender)->Caption));
  180. }
  181. //---------------------------------------------------------------------
  182. void __fastcall TMDIChildForm::CreateFromFile( AnsiString FileName, bool Linked)
  183. {
  184.   if (Linked)
  185.     OleContainer1->CreateLinkToFile(FileName, False);
  186.   else
  187.     OleContainer1->CreateObjectFromFile(FileName, False);
  188.   Caption = FileName;
  189.   FFileName = FileName;
  190. }
  191. //---------------------------------------------------------------------
  192. void __fastcall TMDIChildForm::SaveFile( AnsiString FileName)
  193. {
  194.   OleContainer1->SaveToFile(FileName);
  195.   FFileName = FileName;
  196.   Caption = FFileName;
  197.   OleContainer1->Modified = False;
  198. }
  199. //---------------------------------------------------------------------------
  200.