home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / progs / CB / DATA.Z / MDICHILD.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-29  |  7.3 KB  |  208 lines

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