⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 propertyeditor.cpp

📁 delphi做的类似与属性编辑器一样的控件
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "PropertyEditor.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "VirtualTrees"
#pragma link "ThemeMgr"
#pragma link "VirtualTrees"
#pragma link "VirtualTrees"
#pragma link "VirtualTrees"
#pragma link "VirtualTrees"
#pragma resource "*.dfm"


TForm1 *Form1;
using  namespace WZZ_Editors_namespace;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
        PropertyLink = NULL;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::VST3Change(TBaseVirtualTree *Sender,
      PVirtualNode Node)
{
    // Start immediate editing as soon as another node gets focused.
    if(Node && (Node->Parent != Sender->RootNode) && (!Sender->TreeStates.Contains(tsIncrementalSearching)))
    {
      // We want to start editing the currently selected node. However it might well happen that this change event
      // here is caused by the node editor if another node is currently being edited. It causes trouble
      // to start a new edit operation if the last one is still in progress. So we post us a special message and
      // in the message handler we then can start editing the new node. This works because the posted message
      // is first executed *after* this event and the message, which triggered it is finished.
      PostMessage(this->Handle, WM_STARTEDITING, WPARAM(Node), 0);
    }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::VST3CreateEditor(TBaseVirtualTree *Sender,
      PVirtualNode Node, TColumnIndex Column, IVTEditLink *EditLink)
{
        if(PropertyLink==NULL)
                PropertyLink = new WZZ_Editors_namespace::TPropertyEditLink();
        PropertyLink->QueryInterface(__uuidof(IVTEditLink), (void**)EditLink);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::VST3Editing(TBaseVirtualTree *Sender,
      PVirtualNode Node, TColumnIndex Column, bool &Allowed)
{
    WZZ_Editors_namespace::PPropertyData Data;

    Data = (WZZ_Editors_namespace::TPropertyData*)Sender->GetNodeData(Node);
    Allowed = (Node->Parent != Sender->RootNode) && (Column == 1) && (Data->ValueType != WZZ_Editors_namespace::vtNone);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::VST3GetHint(TBaseVirtualTree *Sender,
      PVirtualNode Node, TColumnIndex Column,
      TVTTooltipLineBreakStyle &LineBreakStyle, WideString &HintText)
{
  // Add a dummy hint to the normal hint to demonstrate multiline hints.
  if ((Column == 0) && (Node->Parent != Sender->RootNode))
    HintText = WZZ_Editors_namespace::PropertyTexts[Node->Parent->Index][Node->Index][WZZ_Editors_namespace::ptkHint] + "\x0D" + "(Multiline hints are supported too).";

}
//---------------------------------------------------------------------------

void __fastcall TForm1::VST3GetImageIndex(TBaseVirtualTree *Sender,
      PVirtualNode Node, TVTImageKind Kind, TColumnIndex Column,
      bool &Ghosted, int &ImageIndex)
{
  WZZ_Editors_namespace::PPropertyData Data;

  if ((Kind == ikNormal||Kind == ikSelected) && (Column == 0))
  {
    if( Node->Parent == Sender->RootNode)
      ImageIndex = 12; // root nodes, this is an open folder
    else
    {
      Data = (WZZ_Editors_namespace::TPropertyData*)Sender->GetNodeData(Node);
      if( Data->ValueType != WZZ_Editors_namespace::vtNone)
        ImageIndex = 14;
      else
        ImageIndex = 13;
    }
  }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::VST3GetText(TBaseVirtualTree *Sender,
      PVirtualNode Node, TColumnIndex Column, TVSTTextType TextType,
      WideString &CellText)
{
  WZZ_Editors_namespace::PPropertyData Data;
  if(TextType == ttNormal)
  {
    switch( Column)
    {
    case  0:
        if( Node->Parent == Sender->RootNode)
        {
          // root nodes
          if (Node->Index == 0)
            CellText = "Description";
          else
            CellText = "Origin";
        }
        else
          CellText = WZZ_Editors_namespace::PropertyTexts[Node->Parent->Index][Node->Index][WZZ_Editors_namespace::ptkText];
        break;
    case  1:
          Data = (WZZ_Editors_namespace::TPropertyData*)Sender->GetNodeData(Node);
          CellText = Data->Value;

    }
  }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::VST3IncrementalSearch(TBaseVirtualTree *Sender,
      PVirtualNode Node, const WideString SearchText, int &Result)
{
  AnsiString S, PropText;
  // Note: This code requires a proper Unicode/WideString comparation routine which I did not want to link here for
  // size and clarity reasons. For now strings are (implicitely) converted to ANSI to make the comparation work.
  // Search is not case sensitive.
  S = SearchText;
  StatusBar->SimpleText ="Searching for: ";
  StatusBar->SimpleText +=S;

  if(Node->Parent == Sender->RootNode)
  {
    // root nodes
    if(Node->Index == 0)
      PropText = "Description";
    else
      PropText = "Origin";
  }
  else
  {
    PropText = WZZ_Editors_namespace::PropertyTexts[Node->Parent->Index][ Node->Index][ WZZ_Editors_namespace::ptkText];
  }

  // By using StrLIComp we can specify a maximum length to compare. This allows us to find also nodes
  // which match only partially. Don't forget to specify the shorter string length as search length.
  Result = StrLIComp(S.c_str(), PropText.c_str(), min(S.Length(), PropText.Length()));

}
//---------------------------------------------------------------------------

void __fastcall TForm1::VST3InitChildren(TBaseVirtualTree *Sender,
      PVirtualNode Node, DWORD &ChildCount)
{
  switch(Node->Index)
  {
  case  0:
      ChildCount = 13;
      break;
  case  1:
      ChildCount = 8;
  }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::VST3InitNode(TBaseVirtualTree *Sender,
      PVirtualNode ParentNode, PVirtualNode Node,
      TVirtualNodeInitStates &InitialStates)
{
  WZZ_Editors_namespace::PPropertyData Data;
  if(ParentNode == NULL)
    InitialStates << ivsHasChildren << ivsExpanded;
  else
  {
    Data = (WZZ_Editors_namespace::TPropertyData *)Sender->GetNodeData(Node);
    Data->ValueType = WZZ_Editors_namespace::ValueTypes[ParentNode->Index][ Node->Index];
    if( Data->ValueType == WZZ_Editors_namespace::vtDate)
      Data->Value = DateToStr(Now()).c_str();
    else
      Data->Value = WZZ_Editors_namespace::DefaultValue[ParentNode->Index][ Node->Index];
  }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::VST3PaintText(TBaseVirtualTree *Sender,
      const TCanvas *TargetCanvas, PVirtualNode Node, TColumnIndex Column,
      TVSTTextType TextType)
{
  WZZ_Editors_namespace::PPropertyData Data;

  // Make the root nodes underlined and draw changed nodes in bold style.
  if( Node->Parent == Sender->RootNode)
    TargetCanvas->Font->Style = TFontStyles()<< fsUnderline;
  else
  {
    Data = (WZZ_Editors_namespace::TPropertyData *)Sender->GetNodeData(Node);
    if( Data->Changed)
      TargetCanvas->Font->Style = TFontStyles()<<fsBold;
    else
      TargetCanvas->Font->Style.Clear();
  }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::VST3StateChange(TBaseVirtualTree *Sender,
      TVirtualTreeStates &Enter, TVirtualTreeStates &Leave)
{
  if (Enter.Contains(tsIncrementalSearching))
    // Note: Unicode will be converted to ANSI here, but for demonstration purposes we accept that for now.
    StatusBar->SimpleText ="Searching for: ";
    StatusBar->SimpleText += Sender->SearchBuffer;
  if (Leave.Contains(tsIncrementalSearching))
    StatusBar->SimpleText="";

//  if(ComponentState.Contains(csDestroying ))
//    StatusBar->SimpleText="Is Destroy...";
    //UpdateStateDisplay(Sender->TreeStates, Enter, Leave);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
        VST3->NodeDataSize = sizeof(WZZ_Editors_namespace::TPropertyData);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::VST3GetNodeDataSize(TBaseVirtualTree *Sender,
      int &NodeDataSize)
{
        NodeDataSize = sizeof(WZZ_Editors_namespace::TPropertyData);
}
//---------------------------------------------------------------------------


void __fastcall TForm1::WMStartEditing(TMessage & Msg)
{
        //TODO: Add your source code here
  PVirtualNode Node ;

  Node = (PVirtualNode)Pointer(Msg.WParam);
  // Note: the test whether a node can really be edited is done in the OnEditing event.
  VST3->EditNode(Node, 1);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -