Demo1Frm.cpp
上传用户:daoqigc
上传日期:2021-04-20
资源大小:2795k
文件大小:3k
源码类别:

RichEdit

开发平台:

Delphi

  1. //---------------------------------------------------------------------------
  2. #include <vclvcl.h>
  3. #pragma hdrstop
  4. #include "Demo1Frm.h"
  5. #include "MainFrm.h"
  6. //---------------------------------------------------------------------------
  7. #pragma link "RichView"
  8. #pragma link "RVScroll"
  9. #pragma resource "*.dfm"
  10. TfrmDemo1 *frmDemo1;
  11. //---------------------------------------------------------------------------
  12. __fastcall TfrmDemo1::TfrmDemo1(TComponent* Owner)
  13.     : TForm(Owner)
  14. {
  15. }
  16. //---------------------------------------------------------------------------
  17. void __fastcall TfrmDemo1::FormCreate(TObject *Sender)
  18. {
  19.   TSearchRec SearchRec;
  20.   lst->Items->BeginUpdate();
  21.   rv->AddNL("When you scroll this document to some file, corresponded item in "
  22.            "the left list box is highlighted.",sncomHeading,0);
  23.   rv->AddNL("Double-click on the listbox to scroll the document to the file.",
  24.            sncomHeading,0);
  25.   rv->AddNL("Right-click to show/hide 'checkpoints'.",
  26.            sncomHeading,0);
  27.   if (FindFirst(ExtractFilePath(Application->ExeName)+"*.cpp",
  28.                0,SearchRec) == 0)
  29.     do
  30.     {
  31.       lst->Items->Add(SearchRec.Name);
  32.       // Marking next added item with checkpoint
  33.       rv->AddNamedCheckpointEx(SearchRec.Name, True);
  34.       // Adding name of file
  35.       rv->AddNL(SearchRec.Name,sncomKeyword,3);
  36.       // Adding text from file.
  37.       // Last parameter = True, so all text will be loaded as one
  38.       // paragraph, and displayed in the single frame
  39.       rv->LoadText(ExtractFilePath(Application->ExeName)+SearchRec.Name, sncomNormal, 2, true);
  40.     } while (FindNext(SearchRec)==0);
  41.   FindClose(SearchRec);
  42.   lst->Items->EndUpdate();
  43.   rv->Format();
  44. }
  45. //---------------------------------------------------------------------------
  46. void __fastcall TfrmDemo1::rvCheckpointVisible(TCustomRichView *Sender,
  47.     TCheckpointData CheckpointData)
  48. {
  49.   if (!CheckpointData)
  50.     lst->ItemIndex = -1;
  51.   else
  52.     lst->ItemIndex = rv->GetCheckpointNo(CheckpointData);
  53. }
  54. //---------------------------------------------------------------------------
  55. void __fastcall TfrmDemo1::lstDblClick(TObject *Sender)
  56. {
  57.   if (lst->ItemIndex!=-1)
  58.     rv->ScrollTo(rv->GetCheckpointY(lst->ItemIndex));
  59. }
  60. //---------------------------------------------------------------------------
  61. void __fastcall TfrmDemo1::FormKeyDown(TObject *Sender, WORD &Key,
  62.     TShiftState Shift)
  63. {
  64.   if (Key==VK_ESCAPE)
  65.     Close();
  66. }
  67. //---------------------------------------------------------------------------
  68. void __fastcall TfrmDemo1::pmPopup(TObject *Sender)
  69. {
  70.   mitShowCP->Checked = rv->Options.Contains(rvoShowCheckpoints);
  71. }
  72. //---------------------------------------------------------------------------
  73. void __fastcall TfrmDemo1::mitShowCPClick(TObject *Sender)
  74. {
  75.   if (rv->Options.Contains(rvoShowCheckpoints))
  76.     rv->Options >> rvoShowCheckpoints;
  77.   else
  78.     rv->Options << rvoShowCheckpoints;
  79.   rv->Invalidate();
  80. }
  81. //---------------------------------------------------------------------------