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

RichEdit

开发平台:

Delphi

  1. // Properties:
  2. // rvoTagsArePChars is added in Options
  3. // rvoCtrlJumps is added in EditorOptions
  4. // "Allow adding styles dynamically" in the "Settings" in the context menu
  5. // This code is highly simplified.
  6. // RichViewActions use much more advanced code for inserting hyperlinks.
  7. //---------------------------------------------------------------------------
  8. #include <vclvcl.h>
  9. #include <shellapi.h>
  10. #pragma hdrstop
  11. #include "Unit1.h"
  12. #include "Unit2.h"
  13. //---------------------------------------------------------------------------
  14. #pragma link "RVEdit"
  15. #pragma link "RichView"
  16. #pragma link "RVScroll"
  17. #pragma link "RVStyle"
  18. #pragma resource "*.dfm"
  19. TForm1 *Form1;
  20. //---------------------------------------------------------------------------
  21. __fastcall TForm1::TForm1(TComponent* Owner)
  22. : TForm(Owner)
  23. {
  24. }
  25. //---------------------------------------------------------------------------
  26. void __fastcall TForm1::RichViewEdit1Select(TObject *Sender)
  27. {
  28.   SpeedButton1->Enabled = RichViewEdit1->SelectionExists() && ! RichViewEdit1->ReadOnly;
  29. }
  30. //---------------------------------------------------------------------------
  31. void TForm1::SetURLToSelection(const AnsiString URL)
  32. {
  33.   int StartNo, EndNo, StartOffs, EndOffs;
  34.   TCustomRichViewEdit* rve = RichViewEdit1->TopLevelEditor;
  35.   rve->GetSelectionBounds(StartNo, StartOffs, EndNo, EndOffs, true);
  36.   if (StartOffs >= rve->GetOffsAfterItem(StartNo))
  37.     StartNo++;
  38.   if (EndOffs <= rve->GetOffsBeforeItem(EndNo))
  39.     EndNo--;
  40.   rve->BeginUndoGroup(rvutTag);
  41.   rve->SetUndoGroupMode(true);
  42.   for (int i=StartNo; i<=EndNo; i++)
  43.     rve->SetItemTagEd(i, (int)StrNew(URL.c_str()));
  44.   rve->SetUndoGroupMode(false);
  45. }
  46. //---------------------------------------------------------------------------
  47. void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
  48. {
  49.   AnsiString URL = (char*)RichViewEdit1->GetCurrentTag();
  50.   if (URL.IsEmpty())
  51.     URL = "http://";
  52.   Form2->Edit1->Text = URL;
  53.   if (Form2->ShowModal()==mrOk)
  54.   {
  55.     RichViewEdit1->ApplyTextStyle(4);
  56.     URL = Form2->Edit1->Text;
  57.     SetURLToSelection(URL);
  58.   }
  59. }
  60. //---------------------------------------------------------------------------
  61. void __fastcall TForm1::RichViewEdit1Jump(TObject *Sender, int id)
  62. {
  63.   TCustomRVFormattedData* RVData;
  64.   int ItemNo;
  65.   RichViewEdit1->GetJumpPointLocation(id, RVData, ItemNo);
  66.   AnsiString URL = (char*)RVData->GetItemTag(ItemNo);
  67.   ShellExecute(0, "open", URL.c_str(), NULL, NULL, SW_SHOW);
  68. }
  69. //---------------------------------------------------------------------------
  70. void __fastcall TForm1::FormCreate(TObject *Sender)
  71. {
  72.   RichViewEdit1->Clear();
  73.   RichViewEdit1->AddNL("Select text and click the button",0,0);
  74.   RichViewEdit1->Format();
  75. }
  76. //---------------------------------------------------------------------------
  77. void __fastcall TForm1::CheckBox1Click(TObject *Sender)
  78. {
  79.   RichViewEdit1->ReadOnly = CheckBox1->Checked;
  80.   if (CheckBox1->Checked)
  81.     RichViewEdit1->Color = clBtnFace;
  82.   else
  83.     RichViewEdit1->Color = clWindow;
  84.   RichViewEdit1Select(Sender);
  85.   RichViewEdit1->SetFocus();
  86. }
  87. //---------------------------------------------------------------------------