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

📄 multiline.cpp

📁 VTMultiLineDemoCB6下载的都知道是什么用的
💻 CPP
字号:
//---------------------------------------------------------------------------
// This is a very simple and totally contrived demonstration of the use of the
//    Multiline feature of the VirtualStringTree component. Many thanks to
//    Mr. Mathias Thorell for his absolutely crucial bit. Any errors are
//    strictly my own.
//                         Lou Ayers (Sparky@amlink.co.uk)
//---------------------------------------------------------------------------
#include <vcl.h>
//---------------------------------------------------------------------------
#pragma hdrstop
//---------------------------------------------------------------------------
#include "MultiLine.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "VirtualTrees"
#pragma resource "*.dfm"
//---------------------------------------------------------------------------
TForm1 *Form1;
//=================================Main Form=================================
__fastcall TForm1::TForm1(TComponent* Owner):TForm(Owner) {
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender) {

   int NodeCountIndex, NodeCountMax = 25;
   PVirtualNode LastNode;
   ptrTestRec PtrTestName;
   AnsiString MultiNodeLabel = "The quick brown fox\x0D\x0A     Jumped over the\x0D\x0A          Lazy brown dog.";
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	vst->Clear();
   vst->Align = alClient;
   vst->TreeOptions->PaintOptions >> toShowTreeLines;
   Form1->Position = poScreenCenter;
   vst->TreeOptions->MiscOptions << toVariableNodeHeight;
   for (NodeCountIndex = 1; NodeCountIndex <= NodeCountMax; NodeCountIndex++) {
      LastNode = vst->AddChild(NULL);
      vst->MultiLine[LastNode] = TRUE;
      PtrTestName = (TestRec *) vst->GetNodeData(LastNode);
      PtrTestName->Node = LastNode;
      PtrTestName->NodeTitle = MultiNodeLabel;
   }
}

//=============================VirtualStringTree=============================

void __fastcall TForm1::vstGetNodeDataSize(TBaseVirtualTree *Sender,
      int &NodeDataSize) {
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   NodeDataSize = sizeof(TestRec);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::vstGetText(TBaseVirtualTree *Sender,
      PVirtualNode Node, TColumnIndex Column, TVSTTextType TextType,
      WideString &CellText) {

   ptrTestRec PtrTestName;
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   if (!Node) {
      return;
   }
   PtrTestName = (TestRec *) Sender->GetNodeData(Node);
   CellText = PtrTestName->NodeTitle;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::vstInitNode(TBaseVirtualTree *Sender,
      PVirtualNode ParentNode, PVirtualNode Node,
      TVirtualNodeInitStates &InitialStates) {

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   if (!Node) {
      return;
   }
   InitialStates = InitialStates << ivsMultiline;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::vstMeasureItem(TBaseVirtualTree *Sender,
      TCanvas *TargetCanvas, PVirtualNode Node, int &NodeHeight) {

   TVirtualStringTree *vstNu = dynamic_cast<TVirtualStringTree*>(Sender);
   WideString CellText;
   AnsiString str;
   AnsiString CRLF = "\x0D\x0A";
   register int i, Breaks;
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   if (!Node || !vstNu || !vstNu->OnGetText || !vstNu->MultiLine[Node]) {
      return;
   }
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Get the Node Text.
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   CellText = vstNu->DefaultText;
   vstNu->OnGetText(vstNu, Node, 0, ttNormal, CellText);
   str = CellText;
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Check the length and remove terminating CR/LF, if present, because since it
//    makes no sense to terminate the Node Text with CR/LF.
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   if (str.Length() < 2) {
      return;
   }
   if (str.SubString(str.Length() - 1, 2) == CRLF) {
      str = str.SubString(1, str.Length() - 2);
   }
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Count the number of CR/LFs. The Node Text is minimum 1 line; therefore
//    Breaks is set to 1 when starting the loop.
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   Breaks = 1;
   for (i = 1; i < str.Length() - 1; i++) {
      if ((str[i] == CRLF[1]) && (str[i + 1] == CRLF[2])) {
         Breaks++;
      }
   }
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Calculate the node height.
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   NodeHeight = vstNu->DefaultNodeHeight * Breaks;
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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