//--------------------------------------------------------------------------- #include #pragma hdrstop #include "SheafManager.h" #include "Main.h" #include "View.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TSheafManagerForm *SheafManagerForm; //--------------------------------------------------------------------------- __fastcall TSheafManagerForm::TSheafManagerForm(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TSheafManagerForm::FormClose(TObject *Sender, TCloseAction &Action) { MainForm->Arrange(this); } //--------------------------------------------------------------------------- void __fastcall TSheafManagerForm::FormCreate(TObject *Sender) { Sheaf = NULL; Move = false; } //--------------------------------------------------------------------------- void __fastcall TSheafManagerForm::FormDestroy(TObject *Sender) { DeletePopupMenu(); if (Sheaf) delete Sheaf; } //--------------------------------------------------------------------------- void __fastcall TSheafManagerForm::TreeView1DblClick(TObject *Sender) { int index; TPDocSheet *dp = NULL; if (TreeView1->Selected->Level > 0) { MainForm->UpdateMenu(); dp = MainForm->FindOpenSheet(); if (dp) index = MainForm->FindIndex(dp); else index = 0; if (Sheaf->GetCount() > 1) { Sheaf->GetCommonData(index); Sheaf->SetCommonData(TreeView1->Selected->Index); } MainForm->AddSheet(Sheaf->GetSheet(TreeView1->Selected->Index)); if (ViewForm->Visible) ViewForm->ShowBitmap(); MainForm->TabControl1Resize(NULL); // MainForm->AddSheet ¿¡¼­ ÇØÁÜ.... } } //--------------------------------------------------------------------------- void __fastcall TSheafManagerForm::TreeView1MouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { TTreeNode *Item; int src, dst; if (Move) { Item = TreeView1->GetNodeAt(X, Y); if (Item != NULL && Item != TreeView1->TopItem) { src = TreeView1->Selected->Index; dst = Item->Index; if (src == dst) return; TreeView1->Selected->MoveTo(Item, naInsert); if (src < dst) { Sheaf->MoveSheet(src, dst-1); // TTreeViea--MoveTo, TList-->Move } else if (src > dst) { Sheaf->MoveSheet(src, dst); } Move = false; } } } //--------------------------------------------------------------------------- void __fastcall TSheafManagerForm::PopupMenu1Popup(TObject *Sender) { TMenuItem *NewItem; DeletePopupMenu(); NewItem = new TMenuItem(this); NewItem->Caption = "Add..."; NewItem->OnClick = MainForm->SheetAdd1Execute; PopupMenu1->Items->Add(NewItem); if (TreeView1->Selected) { if (TreeView1->Selected->Level > 0) { NewItem = new TMenuItem(this); NewItem->Caption = "Delete"; NewItem->OnClick = MainForm->SheetDelete1Execute; PopupMenu1->Items->Add(NewItem); if (TreeView1->Items->Count > 2) { // including root node, grater than 2 NewItem = new TMenuItem(this); NewItem->Caption = "Move"; NewItem->OnClick = MainForm->SheetMove1Execute; PopupMenu1->Items->Add(NewItem); } } } } //--------------------------------------------------------------------------- void __fastcall TSheafManagerForm::DeletePopupMenu() { TMenuItem *NewItem; while (PopupMenu1->Items->Count) { NewItem = PopupMenu1->Items->Items[0]; delete NewItem; } } //--------------------------------------------------------------------------- bool __fastcall TSheafManagerForm::CreateSheaf() { Sheaf = new TPDocSheaf; if (Sheaf == NULL) return false; TreeView1->Items->Add(NULL, "Sheaf1"); return true; } //--------------------------------------------------------------------------- void __fastcall TSheafManagerForm::DeleteSheaf() { if (Sheaf) { delete Sheaf; TreeView1->Items->Clear(); } } //--------------------------------------------------------------------- TPDocSheet *__fastcall TSheafManagerForm::AddSheet(AnsiString fn) { TPDocSheet *stp = NULL; TTreeNode *ChildNode = NULL; if ((stp = new TPDocSheet) == NULL) goto fail; if (!(stp->LoadFromFile(fn))) goto fail; ChildNode = TreeView1->Items->AddChild(TreeView1->Items->Item[0], stp->Title); Sheaf->AddSheet(stp); return stp; fail : if (ChildNode) TreeView1->Items->Delete(ChildNode); if (stp) delete stp; return NULL; } //--------------------------------------------------------------------- void __fastcall TSheafManagerForm::DeleteSheet(TTreeNode* Node) { TPDocSheet *stp = Sheaf->GetSheet(Node->Index); MainForm->DeleteSheet(stp); Sheaf->DeleteSheet(Node->Index); TreeView1->Items->Delete(Node); } //--------------------------------------------------------------------------- void __fastcall TSheafManagerForm::TreeView1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { MainForm->UpdateMenu(); MainForm->ReportDoc->Repaint(); } //---------------------------------------------------------------------------