home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / progs / CB / DATA.Z / MDIMAIN.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-21  |  6.8 KB  |  205 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4.  
  5. #include "mdimain.h"
  6. #include "mdichild.h"
  7. #include "about.h"
  8. //---------------------------------------------------------------------------
  9. #pragma resource "*.dfm"
  10. TMainForm *MainForm;
  11. //---------------------------------------------------------------------------
  12. __fastcall TMainForm::TMainForm(TComponent* Owner)
  13.   : TForm(Owner)
  14. {
  15. }
  16. //---------------------------------------------------------------------------
  17. void __fastcall TMainForm::Window2Click(TObject *Sender)
  18. {
  19.   Tile1->Enabled               = (ActiveMDIChild != NULL);
  20.   TileHorizontally1->Enabled   = (ActiveMDIChild != NULL);
  21.   Cascade1->Enabled            = (ActiveMDIChild != NULL);
  22.   ArrangeIcons1->Enabled       = (ActiveMDIChild != NULL);
  23.  
  24. }
  25. //---------------------------------------------------------------------
  26. void __fastcall TMainForm::Tile1Click(TObject *Sender)
  27. {
  28.   TileMode = tbHorizontal;
  29.   Tile();
  30. }
  31. //---------------------------------------------------------------------
  32. void __fastcall TMainForm::Exit1Click(TObject *Sender)
  33. {
  34.   Close();
  35. }
  36. //---------------------------------------------------------------------
  37. void __fastcall TMainForm::Save1Click(TObject *Sender)
  38. {
  39. //  with TMDIChildForm(ActiveMDIChild), SaveDialog1 do
  40.   TMDIChildForm* ch = (TMDIChildForm*) this->ActiveMDIChild;
  41.  
  42.     if (((ch->FileName.Length()) == 0) || (Sender == SaveAs1)) {
  43.       if (SaveDialog1->Execute())
  44.         ch->SaveFile(SaveDialog1->FileName);
  45.     }
  46.     else
  47.       ch->SaveFile(SaveDialog1->FileName);
  48. }
  49. //---------------------------------------------------------------------
  50. void __fastcall TMainForm::Paste1Click(TObject *Sender)
  51. {
  52.   if (ActiveMDIChild == NULL)
  53.     exit;
  54.  
  55. //  with TMDIChildForm(ActiveMDIChild)->OleContainer1 do
  56.  
  57.   TMDIChildForm* ch = (TMDIChildForm*) this->ActiveMDIChild;
  58.     if ((ch->OleContainer1->State == osEmpty) ||
  59.         (MessageDlg("Replace existing object?",
  60.                     mtConfirmation,
  61.                     TMsgDlgButtons() << mbOK << mbCancel,
  62.                     0) == mrOk)){
  63.         ch->OleContainer1->Paste();
  64.         CutButton->Enabled = True;
  65.         CopyButton->Enabled = True;
  66.     }
  67. }
  68. //---------------------------------------------------------------------
  69. void __fastcall TMainForm::Open1Click(TObject *Sender)
  70. {
  71. //  with OpenDialog1 do
  72.     if (OpenDialog1->Execute()){
  73. //      with TMDIChildForm->Create(Self) do
  74.         TMDIChildForm* ch = new TMDIChildForm(this);
  75.           ch->CreateFromFile(OpenDialog1->FileName, False);
  76.       CutButton->Enabled = True;
  77.       CopyButton->Enabled = True;
  78.     }
  79. }
  80. //---------------------------------------------------------------------
  81. void __fastcall TMainForm::New1Click(TObject *Sender)
  82. {
  83.   MDIChildForm = new TMDIChildForm(this);
  84. //  with MDIChildForm do
  85. //  begin
  86.     MDIChildForm->InsertObject1Click(Sender);
  87. //    with OleContainer1 do
  88.       if (MDIChildForm->OleContainer1->NewInserted)
  89.         MDIChildForm->OleContainer1->DoVerb(ovPrimary);
  90. //  end;
  91. }
  92. //---------------------------------------------------------------------
  93. void __fastcall TMainForm::FormCreate(TObject *Sender)
  94. {
  95.   Application->OnHint = ShowHint;
  96. }
  97. //---------------------------------------------------------------------
  98. void __fastcall TMainForm::LinkButtonClick(TObject *Sender)
  99. {
  100.   TMDIChildForm* MDIChild;
  101.  
  102.   if (ActiveMDIChild == NULL) {
  103.  
  104.     if (OpenDialog1->Execute()){
  105.  
  106.       MDIChild = new TMDIChildForm(this);
  107.       MDIChild->CreateFromFile(OpenDialog1->FileName, True);
  108.     }
  109.   }
  110.   else{
  111. //    with TMDIChildForm(ActiveMDIChild) do
  112.       MDIChild = (TMDIChildForm*) this->ActiveMDIChild;
  113.       if ((MDIChild->OleContainer1->State == osEmpty) ||
  114.           (MessageDlg("Replace existing object?",
  115.                       mtConfirmation,
  116.                       TMsgDlgButtons() << mbOK << mbCancel,
  117.                       0) == mrOk))
  118.         if (OpenDialog1->Execute())
  119.           MDIChild->CreateFromFile(OpenDialog1->FileName, True);
  120.   } //else
  121. }
  122. //---------------------------------------------------------------------
  123. void __fastcall TMainForm::File1Click(TObject *Sender)
  124. {
  125.   if (this->ActiveMDIChild != NULL){
  126. //    with TMDIChildForm(ActiveMDIChild)->OleContainer1 do
  127.       TMDIChildForm* ch = (TMDIChildForm*) this->ActiveMDIChild;
  128. //    begin
  129.       Save1->Enabled = ch->OleContainer1->Modified;
  130.       SaveAs1->Enabled = ch->OleContainer1->Modified;
  131. //    end
  132.   }
  133.   else {
  134. //  begin
  135.     Save1->Enabled = False;
  136.     SaveAs1->Enabled = False;
  137. //  end;
  138.   }
  139.   Close2->Enabled = this->ActiveMDIChild != NULL;
  140.   CloseAll1->Enabled = this->ActiveMDIChild != NULL;
  141.  
  142. }
  143. //---------------------------------------------------------------------
  144. void __fastcall TMainForm::CutButtonClick(TObject *Sender)
  145. {
  146.   if (ActiveMDIChild != NULL){
  147. //    with TMDIChildForm(ActiveMDIChild)->OleContainer1 do
  148.       TMDIChildForm* ch = (TMDIChildForm*) this->ActiveMDIChild;
  149. //    begin
  150.       ch->OleContainer1->Copy();
  151.       ch->OleContainer1->DestroyObject();
  152.       CutButton->Enabled = False;
  153.       CopyButton->Enabled = False;
  154.       PasteButton->Enabled = True;
  155.   }
  156. }
  157. //---------------------------------------------------------------------
  158. void __fastcall TMainForm::Copy1Click(TObject *Sender)
  159. {
  160.   if (this->ActiveMDIChild != NULL)
  161.     ((TMDIChildForm*)this->ActiveMDIChild)->OleContainer1->Copy();
  162. }
  163. //---------------------------------------------------------------------
  164. void __fastcall TMainForm::CloseAll1Click(TObject *Sender)
  165. {
  166.   Integer i;
  167.   for (i = 0; i < MDIChildCount; i++)
  168.       MDIChildren[i]->Close();
  169. }
  170. //---------------------------------------------------------------------
  171. void __fastcall TMainForm::Close1Click(TObject *Sender)
  172. {
  173.   if (ActiveMDIChild != NULL)
  174.     this->ActiveMDIChild->Close();
  175. }
  176. //---------------------------------------------------------------------
  177. void __fastcall TMainForm::Cascade1Click(TObject *Sender)
  178. {
  179.   Cascade();
  180. }
  181. //---------------------------------------------------------------------
  182. void __fastcall TMainForm::ArrangeIcons1Click(TObject *Sender)
  183. {
  184.   ArrangeIcons();
  185. }
  186. //---------------------------------------------------------------------
  187. void __fastcall TMainForm::About1Click(TObject *Sender)
  188. {
  189.   TAboutBox* AboutBox = new TAboutBox(this);
  190.   AboutBox->ShowModal();
  191.   AboutBox->Free();
  192. }
  193. //---------------------------------------------------------------------
  194. void __fastcall TMainForm::Object2Click(TObject *Sender)
  195. {
  196.   if ((this->ActiveMDIChild) != NULL)
  197.     ((TMDIChildForm*) this->ActiveMDIChild)->OleContainer1->ObjectPropertiesDialog();
  198. }
  199. //---------------------------------------------------------------------
  200. void __fastcall TMainForm::ShowHint(TObject *Sender)
  201. {
  202.   StatusBar->Panels->Items[0]->Text = Application->Hint;
  203. }
  204. //---------------------------------------------------------------------
  205.