git-svn-id: https://192.168.0.254/svn/Componentes.Terceros.DevExpressVCL@21 05c56307-c608-d34a-929d-697000501d7a
382 lines
13 KiB
C++
382 lines
13 KiB
C++
//---------------------------------------------------------------------------
|
|
#include <vcl\vcl.h>
|
|
#pragma hdrstop
|
|
|
|
#include "Main.h"
|
|
//---------------------------------------------------------------------------
|
|
#pragma link "dxorgchr"
|
|
#pragma link "dxdborgc"
|
|
#pragma link "Grids"
|
|
#pragma resource "*.dfm"
|
|
TMainForm *MainForm;
|
|
bool FChange;
|
|
//---------------------------------------------------------------------------
|
|
__fastcall TMainForm::TMainForm(TComponent* Owner)
|
|
: TForm(Owner)
|
|
{
|
|
}
|
|
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TMainForm::DBGridDrawColumnCell(TObject *Sender,
|
|
const TRect &Rect, int DataCol, TColumn *Column, TGridDrawState State)
|
|
{
|
|
if (Column->FieldName == "COLOR") {
|
|
DBGrid->Canvas->Brush->Color = Table->FieldByName("COLOR")->AsInteger;
|
|
DBGrid->Canvas->FillRect(Rect);
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TMainForm::DBGridColEnter(TObject *Sender)
|
|
{
|
|
if (DBGrid->SelectedField->FieldName == "COLOR")
|
|
DBGrid->Options = DBGrid->Options << dgEditing;
|
|
else
|
|
DBGrid->Options = DBGrid->Options >> dgEditing;
|
|
DBGrid->Refresh();
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TMainForm::Exit1Click(TObject *Sender)
|
|
{
|
|
Close();
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TMainForm::AddNode1Click(TObject *Sender)
|
|
{
|
|
TdxOcNode *Node;
|
|
|
|
if (PC->ActivePage == tsDBTree) {
|
|
Table->DisableControls();
|
|
if (DBTree->Selected != NULL)
|
|
Node = DBTree->Insert(DBTree->Selected, NULL);
|
|
else Node = DBTree->Add(NULL, NULL);
|
|
Node->Text = "New topic";
|
|
Node->Color = clWhite;
|
|
Node->Shape = shRectangle;
|
|
DBTree->Selected = Node;
|
|
Table->EnableControls();
|
|
};
|
|
|
|
if (PC->ActivePage == tsTree) {
|
|
if (Tree->Selected != NULL)
|
|
Node = Tree->Insert(Tree->Selected, NULL);
|
|
else Node = Tree->Add(NULL, NULL);
|
|
Node->Text = "New topic";
|
|
Node->Color = clWhite;
|
|
Node->Shape = shRectangle;
|
|
Tree->Selected = Node;
|
|
};
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TMainForm::AddChildeNode1Click(TObject *Sender)
|
|
{
|
|
TdxOcNode *Node;
|
|
|
|
if (PC->ActivePage == tsTree) {
|
|
Table->DisableControls();
|
|
if (Tree->Selected != NULL)
|
|
Node = Tree->AddChild(Tree->Selected, NULL);
|
|
else Node = Tree->Add(NULL, NULL);
|
|
Node->Text = "New topic";
|
|
Node->Color = clWhite;
|
|
Node->Shape = shRectangle;
|
|
if (Tree->Selected != NULL) Tree->Selected->Expanded = true;
|
|
Tree->Selected = Node;
|
|
Table->EnableControls();
|
|
};
|
|
|
|
if (PC->ActivePage == tsDBTree) {
|
|
if (DBTree->Selected != NULL)
|
|
Node = DBTree->AddChild(DBTree->Selected, NULL);
|
|
else Node = DBTree->Add(NULL, NULL);
|
|
Node->Text = "New topic";
|
|
Node->Color = clWhite;
|
|
Node->Shape = shRectangle;
|
|
if (DBTree->Selected != NULL) DBTree->Selected->Expanded = true;
|
|
DBTree->Selected = Node;
|
|
};
|
|
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TMainForm::RenameNode1Click(TObject *Sender)
|
|
{
|
|
if (PC->ActivePage == tsTree)
|
|
if (Tree->Selected != NULL)
|
|
Tree->ShowEditor();
|
|
|
|
if (PC->ActivePage == tsDBTree)
|
|
if (DBTree->Selected != NULL)
|
|
DBTree->ShowEditor();
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TMainForm::DeleteNode1Click(TObject *Sender)
|
|
{
|
|
if (PC->ActivePage == tsTree)
|
|
if (Tree->Selected != NULL)
|
|
Tree->Delete(Tree->Selected);
|
|
|
|
if (PC->ActivePage == tsDBTree)
|
|
if (DBTree->Selected != NULL)
|
|
DBTree->Delete(DBTree->Selected);
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TMainForm::FormCreate(TObject *Sender)
|
|
{
|
|
Table->Close();
|
|
Table->DatabaseName = ExtractFilePath(Application->ExeName);
|
|
Table->Open();
|
|
DBTree->WidthFieldName = "Width";
|
|
DBTree->HeightFieldName = "Height";
|
|
PCChange(PC);
|
|
FChange = true;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TMainForm::PCChange(TObject *Sender)
|
|
{
|
|
if (PC->ActivePage == tsTree) {
|
|
ItZoom->Checked = Tree->Zoom;
|
|
ItRotated->Checked = Tree->Rotated;
|
|
ItAnimated->Checked = Tree->Options.Contains(ocAnimate);
|
|
It3D->Checked = Tree->Options.Contains(ocRect3D);
|
|
};
|
|
if (PC->ActivePage == tsDBTree) {
|
|
ItZoom->Checked = DBTree->Zoom;
|
|
ItRotated->Checked = DBTree->Rotated;
|
|
ItAnimated->Checked = DBTree->Options.Contains(ocAnimate);
|
|
It3D->Checked = DBTree->Options.Contains(ocRect3D);
|
|
};
|
|
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TMainForm::ItZoomClick(TObject *Sender)
|
|
{
|
|
((TMenuItem*)Sender)->Checked = ! ((TMenuItem*)Sender)->Checked;
|
|
if (PC->ActivePage == tsTree)
|
|
Tree->Zoom = ((TMenuItem*)Sender)->Checked;
|
|
if (PC->ActivePage == tsDBTree)
|
|
DBTree->Zoom = ((TMenuItem*)Sender)->Checked;
|
|
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TMainForm::ItRotatedClick(TObject *Sender)
|
|
{
|
|
((TMenuItem*)Sender)->Checked = ! ((TMenuItem*)Sender)->Checked;
|
|
if (PC->ActivePage == tsTree)
|
|
Tree->Rotated = ((TMenuItem*)Sender)->Checked;
|
|
if (PC->ActivePage == tsDBTree)
|
|
DBTree->Rotated = ((TMenuItem*)Sender)->Checked;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TMainForm::ItAnimatedClick(TObject *Sender)
|
|
{
|
|
((TMenuItem*)Sender)->Checked = ! ((TMenuItem*)Sender)->Checked;
|
|
if (PC->ActivePage == tsTree) {
|
|
if (((TMenuItem*)Sender)->Checked)
|
|
Tree->Options = Tree->Options << ocAnimate;
|
|
else
|
|
Tree->Options = Tree->Options >> ocAnimate;
|
|
Tree->Refresh();
|
|
};
|
|
if (PC->ActivePage == tsDBTree) {
|
|
if (((TMenuItem*)Sender)->Checked)
|
|
DBTree->Options = DBTree->Options << ocAnimate;
|
|
else
|
|
DBTree->Options = DBTree->Options >> ocAnimate;
|
|
DBTree->Refresh();
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TMainForm::It3DClick(TObject *Sender)
|
|
{
|
|
((TMenuItem*)Sender)->Checked = ! ((TMenuItem*)Sender)->Checked;
|
|
if (PC->ActivePage == tsTree) {
|
|
if (((TMenuItem*)Sender)->Checked)
|
|
Tree->Options = Tree->Options << ocRect3D;
|
|
else
|
|
Tree->Options = Tree->Options >> ocRect3D;
|
|
Tree->Refresh();
|
|
};
|
|
|
|
if (PC->ActivePage == tsDBTree) {
|
|
if (((TMenuItem*)Sender)->Checked)
|
|
DBTree->Options = DBTree->Options << ocRect3D;
|
|
else
|
|
DBTree->Options = DBTree->Options >> ocRect3D;
|
|
DBTree->Refresh();
|
|
};
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TMainForm::FullExpand1Click(TObject *Sender)
|
|
{
|
|
if (PC->ActivePage == tsTree)
|
|
Tree->FullExpand();
|
|
if (PC->ActivePage == tsDBTree)
|
|
DBTree->FullExpand();
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TMainForm::FullCollapse1Click(TObject *Sender)
|
|
{
|
|
if (PC->ActivePage == tsTree)
|
|
Tree->FullCollapse();
|
|
if (PC->ActivePage == tsDBTree)
|
|
DBTree->FullCollapse();
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TMainForm::DBTreeCreateNode(TObject *Sender, TdxOcNode *Node)
|
|
{
|
|
if (Table->FindField("Width")->AsInteger > 50)
|
|
Node->Width = Table->FindField("Width")->AsInteger;
|
|
if (Table->FindField("Height")->AsInteger > 50)
|
|
Node->Height = Table->FindField("Height")->AsInteger;
|
|
Node->Shape = GetShape(Table->FindField("Type")->AsString);
|
|
Node->Color = Table->FindField("Color")->AsInteger;
|
|
Node->ChildAlign = GetNodeAlign(Table->FindField("Align")->AsString);
|
|
Node->ImageAlign = GetImageAlign(Table->FindField("ImageAlign")->AsString);
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TMainForm::TableAfterInsert(TDataSet *DataSet)
|
|
{
|
|
Table->FindField("Height")->AsInteger = DBTree->DefaultNodeHeight;
|
|
Table->FindField("Width")->AsInteger = DBTree->DefaultNodeWidth;
|
|
Table->FindField("Type")->AsString = "Rectangle";
|
|
Table->FindField("Color")->AsInteger = clWhite;
|
|
Table->FindField("Image")->AsInteger = -1;
|
|
Table->FindField("ImageAlign")->AsString = "Left-Top";
|
|
Table->FindField("Align")->AsString = "Center";
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TMainForm::DBGridDblClick(TObject *Sender)
|
|
{
|
|
if (((TDBGrid*)Sender)->SelectedField->FieldName == "COLOR")
|
|
if (ColorDialog->Execute()) {
|
|
Table->Edit();
|
|
Table->FieldByName("COLOR")->AsInteger = ColorDialog->Color;
|
|
Table->Post();
|
|
DBTree->Selected->Color = ColorDialog->Color;
|
|
};
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TMainForm::DBGridKeyDown(TObject *Sender, WORD &Key,
|
|
TShiftState Shift)
|
|
{
|
|
if (Key == VK_RETURN) {
|
|
Key = 0;
|
|
DBGridDblClick(Sender);
|
|
};
|
|
if (Key == VK_DOWN) {
|
|
Key = 0;
|
|
((TDBGrid*)Sender)->DataSource->DataSet->Next();
|
|
};
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
TdxOcShape __fastcall TMainForm::GetShape(AnsiString ShapeName)
|
|
{
|
|
char* const ShapeArray[4] = {"Rectangle", "Round Rect", "Ellipse", "Diamond"};
|
|
|
|
for(int i=0; i<4; i++)
|
|
if (AnsiUpperCase(ShapeArray[i]) == AnsiUpperCase(ShapeName))
|
|
return((TdxOcShape(i)));
|
|
return((TdxOcShape(0)));
|
|
};
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TMainForm::TableTYPEChange(TField *Sender)
|
|
{
|
|
if (Table->State == dsEdit)
|
|
DBTree->Selected->Shape = GetShape(Sender->AsString);
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
TdxOcNodeAlign __fastcall TMainForm::GetNodeAlign(AnsiString AlignName)
|
|
{
|
|
char* const AlignArray[3] = {"Left", "Center", "Right"};
|
|
|
|
for(int i=0; i< 3; i++)
|
|
if (AnsiUpperCase(AlignArray[i]) == AnsiUpperCase(AlignName))
|
|
return(TdxOcNodeAlign(i));
|
|
return(TdxOcNodeAlign(0));
|
|
};
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TMainForm::TableALIGNChange(TField *Sender)
|
|
{
|
|
if (Table->State == dsEdit)
|
|
DBTree->Selected->ChildAlign = GetNodeAlign(Sender->AsString);
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
TdxOcImageAlign __fastcall TMainForm::GetImageAlign(AnsiString AlignName)
|
|
{
|
|
char* const AlignArray[13] = {
|
|
"None",
|
|
"Left-Top", "Left-Center", "Left-Bottom",
|
|
"Right-Top", "Right-Center", "Right-Bottom",
|
|
"Top-Left", "Top-Center", "Top-Right",
|
|
"Bottom-Left", "Bottom-Center", "Bottom-Right"
|
|
};
|
|
for(int i=0; i< 13; i++)
|
|
if (AnsiUpperCase(AlignArray[i]) == AnsiUpperCase(AlignName))
|
|
return(TdxOcImageAlign(i));
|
|
return(TdxOcImageAlign(0));
|
|
};
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TMainForm::TableIMAGEALIGNChange(TField *Sender)
|
|
{
|
|
if (Table->State == dsEdit)
|
|
DBTree->Selected->ImageAlign = GetImageAlign(Sender->AsString);
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TMainForm::Options1Click(TObject *Sender)
|
|
{
|
|
OptionsForm->ShowModal();
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TMainForm::TreeChanging(TObject *Sender, TdxOcNode *Node,
|
|
bool &Allow)
|
|
{
|
|
FChange = false;
|
|
NameEdit->Text = Node->Text;
|
|
seWidth->Text = IntToStr(Node->Width);
|
|
seHeight->Text = IntToStr(Node->Height);
|
|
if ((int)(Node->Shape) < cbShape->Items->Count)
|
|
cbShape->ItemIndex = (int)(Node->Shape);
|
|
seImageIndex->Text = IntToStr(Node->ImageIndex);
|
|
if ((int)(Node->ImageAlign) < cbImageAlignment->Items->Count)
|
|
cbImageAlignment->ItemIndex = (int)(Node->ImageAlign);
|
|
if ((int)(Node->ChildAlign) < cbAlign->Items->Count)
|
|
cbAlign->ItemIndex = (int)(Node->ChildAlign);
|
|
PColor->Color = Node->Color;
|
|
FChange = true;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TMainForm::NameEditChange(TObject *Sender)
|
|
{
|
|
if ((Tree->Selected != NULL) && FChange) {
|
|
Tree->Selected->Text = NameEdit->Text;
|
|
if (seWidth->Text != "")
|
|
Tree->Selected->Width = StrToInt(seWidth->Text);
|
|
if (seHeight->Text != "")
|
|
Tree->Selected->Height = StrToInt(seHeight->Text);
|
|
Tree->Selected->Shape = TdxOcShape(cbShape->ItemIndex);
|
|
if (seImageIndex->Text != "")
|
|
Tree->Selected->ImageIndex = StrToInt(seImageIndex->Text);
|
|
Tree->Selected->ImageAlign = TdxOcImageAlign(cbImageAlignment->ItemIndex);
|
|
Tree->Selected->ChildAlign = TdxOcNodeAlign(cbAlign->ItemIndex);
|
|
Tree->Selected->Color = PColor->Color;
|
|
};
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TMainForm::PColorClick(TObject *Sender)
|
|
{
|
|
if (ColorDialog->Execute()) {
|
|
PColor->Color = ColorDialog->Color;
|
|
NameEditChange(NULL);
|
|
};
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TMainForm::TreeCreateNode(TObject *Sender, TdxOcNode *Node)
|
|
{
|
|
Node->Shape = shRectangle;
|
|
Node->Color = clWhite;
|
|
Node->ChildAlign = caCenter;
|
|
Node->ImageAlign = iaLT;
|
|
}
|
|
//---------------------------------------------------------------------------
|