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

📄 unit1.cpp

📁 TRichView/RichView 是一套地道的Delphi/C++Builder控件
💻 CPP
📖 第 1 页 / 共 4 页
字号:
}
//---------------------------------------------------------------------------
// You should manually update palette info when user changes color mode
// without restarting Windows
void __fastcall TForm1::WMDisplayChange(TMessage &Message)
{
  RichViewEdit1->UpdatePaletteInfo();
  RVPrint1->UpdatePaletteInfo();
}
//---------------------------------------------------------------------------
// Event: OnJump (when user clicks hypertext item with pressed Ctrl key
void __fastcall TForm1::RichViewEdit1Jump(TObject *Sender, int id)
{
  // NOTE: OnJump is called after the caret is repositioned to clicked item
  // But warning: a clicked event is not necessarily an active item
  // (when clicking on left part of picture or left part of first character in text item,
  // caret moves before item and previous item becomes active!)
  TCustomRVFormattedData* RVData;
  int ItemNo;
  RichViewEdit1->GetJumpPointLocation(id, RVData, ItemNo);
  AnsiString s =  GetTagStr(RVData->GetItemTag(ItemNo));
  Application->MessageBox(Format("Tag of clicked hyperlink is '%s'",
    ARRAYOFCONST((s.c_str()))).c_str(), "Hypertext Click", MB_OK | MB_ICONINFORMATION);

}
//---------------------------------------------------------------------------
// Event: OnRVMouseMove (when user moves mouse above hypertext item with pressed Ctrl key
void __fastcall TForm1::RichViewEdit1RVMouseMove(TObject *Sender, int id)
{
  TCustomRVFormattedData* RVData;
  int ItemNo;
  if (id==-1)
    StatusBar1->SimpleText = "";
  else
  {
    RichViewEdit1->GetJumpPointLocation(id, RVData, ItemNo);
    AnsiString s =  GetTagStr(RVData->GetItemTag(ItemNo));
    StatusBar1->SimpleText = Format("Tag of clicked hyperlink is '%s'", ARRAYOFCONST((s.c_str())));
  }
}
//======================================================================
// Main menu : "Lists"
//======================================================================
// Lists | Apply
void __fastcall TForm1::mitApplyListsClick(TObject *Sender)
{
  /* See more demos about list styles in Demos\CBuilder\Assorted\ListStyles\ */
  if (RVStyle1->ListStyles->Count==0 ||
      RVStyle1->ListStyles->Items[0]->Levels->Count==0)
  {
    Application->MessageBox("Default list style is not defined", "", 0);
    return;
  }
  RichViewEdit1->ApplyListStyle(0, 0, 1, false, false);
}
//---------------------------------------------------------------------------
// Lists | Remove
void __fastcall TForm1::mitRemoveListsClick(TObject *Sender)
{
  RichViewEdit1->RemoveLists(false);
}
//======================================================================
// Main menu : "Table"
//======================================================================
// Table | Insert Table Example 1
void __fastcall TForm1::mitInserttable1Click(TObject *Sender)
{
  TRVTableItemInfo* table = new TRVTableItemInfo(4,3, RichViewEdit1->RVData);

  table->BorderStyle      = rvtbRaisedColor;
  table->CellBorderStyle  = rvtbLoweredColor;
  table->BorderLightColor = (TColor)0x00FAF1C9;
  table->BorderColor      = (TColor)0x00A98E10;
  table->CellBorderLightColor = (TColor)0x00FAF1C9;
  table->CellBorderColor  = (TColor)0x00A98E10;
  table->Color            = (TColor)0x00EAC724;
  table->BorderWidth      = 5;
  table->CellBorderWidth  = 2;
  table->CellPadding      = 5;
  table->CellVSpacing     = 1;
  table->CellHSpacing     = 1;
  table->BorderVSpacing   = 1;
  table->BorderHSpacing   = 1;

  for (int r = 0; r<table->Rows->Count; r++)
    for (int c = 0; c<table->Rows->Items[r]->Count; c++)
      table->Cells[r][c]->BestWidth = 100;

  table->MergeCells(0,0,3,1, false);
  table->MergeCells(1,0,1,3, false);
  TRVTableCellData* Cell = table->Cells[0][0];
  Cell->Color = clInfoBk;
  Cell->Clear();
  Cell->AddBulletEx("",0,il,2);
  Cell->AddNL(" Example 1 ",1,-1);
  Cell->AddBulletEx("",0,il,-1);
  Cell->AddNL("All cells have 100 pixels width, width of table itself is calculated basing on width of cells.",0,0);

  if (RichViewEdit1->InsertItem("", table))
  {
  }
}
//---------------------------------------------------------------------------
// Table | Insert Table Example 2
void __fastcall TForm1::mitInsertTable2Click(TObject *Sender)
{
  TRVTableItemInfo* table = new TRVTableItemInfo(10,6, RichViewEdit1->RVData);

  table->Color     = clWhite;
  table->BestWidth = -90;
  table->BorderStyle      = rvtbRaisedColor;
  table->CellBorderStyle  = rvtbLoweredColor;
  table->BorderLightColor = clWhite;
  table->BorderColor      = clBlack;
  table->CellBorderLightColor = clWhite;
  table->CellBorderColor  = clBlack;

  table->BorderWidth     = 2;
  table->BorderVSpacing  = 0;
  table->BorderHSpacing  = 0;
  table->CellBorderWidth = 2;
  table->CellPadding     = 3;
  table->CellVSpacing    = 0;
  table->CellHSpacing    = 0;
  table->Cells[0][0]->BestWidth = -16;
  table->Cells[0][1]->BestWidth = -16;
  table->Cells[0][2]->BestWidth = -16;
  table->Cells[0][3]->BestWidth = -16;
  table->Cells[0][4]->BestWidth = -16;
  table->Cells[0][5]->BestWidth = -16;
  table->MergeCells(2,0,2,8, false);

  TRVTableCellData* Cell = table->Cells[2][0];
  Cell->Clear();
  Cell->AddNL("Another example.",0,0);
  TButton* btn = new TButton((TComponent*)NULL);
  btn->Caption = "With button inside";
  btn->Width   = 150;
  btn->OnClick = OnControlClick;
  Cell->AddControlEx("",btn,2,rvvaBaseline);
  Cell->SetItemExtraIntProperty(Cell->ItemCount-1, rvepResizable, 1);
  Cell->AddNL("Width of table = 90% of document width. Widths of cells = 16%",0,0);

  if (RichViewEdit1->InsertItem("", table))
  {
  }
}
//---------------------------------------------------------------------------
// Table | Insert Table Example 3
void __fastcall TForm1::mitInsertTable3Click(TObject *Sender)
{
  TRVTableItemInfo* table = new TRVTableItemInfo(5,6, RichViewEdit1->RVData);

  table->Color            = (TColor)0x00A5CCE7;
  table->BorderStyle      = rvtbColor;
  table->CellBorderStyle  = rvtbColor;
  table->BorderColor      = (TColor)0x002E1234;
  table->CellBorderColor  = (TColor)0x002E1234;

  table->BorderWidth     = 2;
  table->BorderVSpacing  = 2;
  table->BorderHSpacing  = 2;
  table->CellBorderWidth = 1;
  table->CellPadding     = 3;
  table->CellVSpacing    = 0;
  table->CellHSpacing    = 0;
  table->BestWidth       = 400;

  int r,c;

  for (c = 0; c<table->Rows->Items[0]->Count; c++)
   table->Cells[0][c]->Color = (TColor)0x00A5E1F8;

  for (r = 1; r<table->Rows->Count; r++)
   table->Cells[r][0]->Color = (TColor)0x00A5E1F8;

  for (r = 1; r<table->Rows->Count; r++)
    for (c = 1; c<table->Rows->Items[r]->Count; c++)
    {
      table->Cells[r][c]->Color = (TColor)0x007AB4DA;
      if (c>1)
        table->Cells[r][c]->VisibleBorders->Left = false;
      if (c<table->Rows->Items[r]->Count-1)
        table->Cells[r][c]->VisibleBorders->Right = false;
    }

  RichViewEdit1->InsertText("Third example: width of table = 400 pixels, widths of cells - unspecified.", false);
  if (RichViewEdit1->InsertItem("", table))
  {
  }
}
//---------------------------------------------------------------------------
// Table | Insert Table Example 4
void __fastcall TForm1::mitInsertTable4Click(TObject *Sender)
{
  TRVTableItemInfo* table = new TRVTableItemInfo(3,3, RichViewEdit1->RVData);

  table->Color           = clNone;
  table->BorderStyle     = rvtbColor;
  table->CellBorderStyle = rvtbColor;

  table->BorderWidth     = 1;
  table->BorderVSpacing  = 2;
  table->BorderHSpacing  = 2;
  table->CellBorderWidth = 1;
  table->CellPadding     = 3;
  table->CellVSpacing    = 5;
  table->CellHSpacing    = 5;
  table->VRuleWidth      = 1;
  table->HRuleWidth      = 1;
  for (int r=0; r<table->Rows->Count; r++)
    for (int c=0; c<table->Rows->Items[r]->Count; c++)
    {
      table->Cells[r][c]->BestWidth = 40;
      table->Cells[r][c]->Clear();
      table->Cells[r][c]->AddFmt("%d,%d",ARRAYOFCONST((r,c)),0,0);
      table->Cells[r][c]->Color = clWhite;
    }
  RichViewEdit1->InsertText("Transparent table with rules", false);
  if (RichViewEdit1->InsertItem("", table))
  {
  }
}
//---------------------------------------------------------------------------
// Table submenu popups
void __fastcall TForm1::mpdTableClick(TObject *Sender)
{
  TCustomRichViewEdit* rve;
  TCustomRVItemInfo* item;
  if (!RichViewEdit1->GetCurrentItemEx(__classid(TRVTableItemInfo), rve, item))
  {
    mitRowsAbove->Enabled         = false;
    mitRowsBelow->Enabled         = false;
    mitColsLeft->Enabled          = false;
    mitColsRight->Enabled         = false;
    mitDelRows->Enabled           = false;
    mitDelColumns->Enabled        = false;
    mitMergeCells->Enabled        = false;
    mitUmRows->Enabled            = false;
    mitUmCols->Enabled            = false;
    mitUmRowsandCols->Enabled     = false;
    mitSplitVertically->Enabled   = false;
    mitSplitHorizontally->Enabled = false;
    return;
  }
  TRVTableItemInfo* table = (TRVTableItemInfo*)item;
  int r,c,cs,rs;
  bool Selected = table->GetNormalizedSelectionBounds(true,r,c,cs,rs);
  mitRowsAbove->Enabled         = Selected;
  mitRowsBelow->Enabled         = Selected;
  mitColsLeft->Enabled          = Selected;
  mitColsRight->Enabled         = Selected;
  mitDelRows->Enabled           = Selected;
  mitDelColumns->Enabled        = Selected;
  mitMergeCells->Enabled        = table->CanMergeSelectedCells(true);
  bool SelectionRectangular = Selected &&
                          (table->CanMergeSelectedCells(true) ||
                           table->GetEditedCell(r,c));
  mitSplitVertically->Enabled   = SelectionRectangular;
  mitSplitHorizontally->Enabled = SelectionRectangular;
  mitUmRows->Enabled            = SelectionRectangular;
  mitUmCols->Enabled            = SelectionRectangular;
  mitUmRowsandCols->Enabled     = SelectionRectangular;
}
//---------------------------------------------------------------------------
// Table | All other commands
void __fastcall TForm1::mitCellOperation(TObject *Sender)
{
  TCustomRVItemInfo* item;
  TCustomRichViewEdit* rve;
  int r,c,cs,rs;
  if (!RichViewEdit1->CanChange() ||
      !RichViewEdit1->GetCurrentItemEx(__classid(TRVTableItemInfo), rve, item))
    return;
  TRVTableItemInfo* table = (TRVTableItemInfo*)item;
  int ItemNo = rve->GetItemNo(table);
  int Data;
  rve->BeginItemModify(ItemNo, Data);
  switch (((TMenuItem*)Sender)->Tag)
  {
    case 1:
      table->InsertRowsAbove(1);
      break;
    case 2:
      table->InsertRowsBelow(1);
      break;
    case 3:
      table->InsertColsLeft(1);
      break;
    case 4:
      table->InsertColsRight(1);
      break;
    case 5:
      {
        table->GetNormalizedSelectionBounds(true,r,c,cs,rs);
        if (rs==table->Rows->Count)
        {
          // deleting whole table
          rve->SetSelectionBounds(ItemNo,0,ItemNo,1);
          rve->DeleteSelection();
          return;
        }
        rve->BeginUndoGroup(rvutModifyItem);
        rve->SetUndoGroupMode(true);
        table->DeleteSelectedRows();
        // it's possible all-NULL rows/cols appear after deleting
        table->DeleteEmptyRows();
        table->DeleteEmptyCols();
        rve->SetUndoGroupMode(false);
        break;
      }
    case 6:
      {
        table->GetNormalizedSelectionBounds(true,r,c,cs,rs);
        if (cs==table->Rows->Items[0]->Count)
        {
          // deleting whole table
          rve->SetSelectionBounds(ItemNo,0,ItemNo,1);
          rve->DeleteSelection();
          return;
        }
        rve->BeginUndoGroup(rvutModifyItem);
        rve->SetUndoGroupMode(true);
        table->DeleteSelectedCols();
        // it's possible all-NULL rows/cols appear after deleting
        table->DeleteEmptyRows();
        table->DeleteEmptyCols();
        rve->SetUndoGroupMode(false);
        break;
      }
    case 7:
      {
        // 3 methods: MergeSelectedCells, DeleteEmptyRows, DeleteEmptyCols
        // must be undone as one action.
        // So using BeginUndoGroup - SetUndoGroupMode(true) - ... - SetUndoGroupMode(false)
        rve->BeginUndoGroup(rvutModifyItem);
        rve->SetUndoGroupMode(true);
        table->MergeSelectedCells(true);
        table->DeleteEmptyRows();
        table->DeleteEmptyCols();
        rve->SetUndoGroupMode(false);
        // table.MergeSelectedCells(False) will not allow to create empty columns
        // or rows
        break;
      }
    case 8:
      table->UnmergeSelectedCells(true, false);
      break;
    case 9:
      table->UnmergeSelectedCells(false, true);
      break;
    case 10:
      table->UnmergeSelectedCells(true, true);
      break;
    case 11:
      {
        AnsiString s = "2";
        if (InputQuery("Split Vertically","Columns (in each selected cell):",s))
          table->SplitSelectedCellsVertically(StrToIntDef(s,0));
        break;
      }
    case 12:
      {
        AnsiString s = "2";
        if (InputQuery("Split Horizontally","Rows (in each selected cell):",s))
          table->SplitSelectedCellsHorizontally(StrToIntDef(s,0));
        break;
      }
  }
  rve->EndItemModify(ItemNo, Data);
  rve->Change();
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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