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

RichEdit

开发平台:

Delphi

  1. //---------------------------------------------------------------------------
  2. #include <vclvcl.h>
  3. #pragma hdrstop
  4. #include "Unit1.h"
  5. //---------------------------------------------------------------------------
  6. #pragma link "RVEdit"
  7. #pragma link "RichView"
  8. #pragma link "RVScroll"
  9. #pragma link "RVStyle"
  10. #pragma resource "*.dfm"
  11. TForm1 *Form1;
  12. //---------------------------------------------------------------------------
  13. __fastcall TForm1::TForm1(TComponent* Owner)
  14. : TForm(Owner)
  15. {
  16. }
  17. //---------------------------------------------------------------------------
  18. void __fastcall TForm1::RichViewEdit1DragOver(TObject *Sender, TObject *Source,
  19. int X, int Y, TDragState State, bool &Accept)
  20. {
  21.   Accept = Source->InheritsFrom(__classid(TImage));
  22.   // We cannot create/destroy inplace editors for cells just
  23.   // in OnDragOver, so we position caret in OnWMSetCaretPos
  24.   // We same technique should be used for OnMouseMove
  25.   if (Accept)
  26.     PostMessage(Handle, WM_SETCARETPOS, X,Y);
  27. }
  28. //---------------------------------------------------------------------------
  29. void TForm1::MoveCaretTo(int X, int Y)
  30. {
  31.   TCustomRVFormattedData* RVData;
  32.   int ItemNo, Offs;
  33.   X += RichViewEdit1->HScrollPos;
  34.   Y += RichViewEdit1->VScrollPos*RichViewEdit1->VSmallStep;
  35.   RichViewEdit1->GetItemAt(X,Y,RVData,ItemNo,Offs,false);
  36.   RVData = (TCustomRVFormattedData*)(RVData->Edit());
  37.   if (ItemNo<0)
  38.     return;
  39.   RVData->SetSelectionBounds(ItemNo, Offs, ItemNo, Offs);
  40.   RVData->Invalidate();
  41. }
  42. //---------------------------------------------------------------------------
  43. void __fastcall TForm1::RichViewEdit1DragDrop(TObject *Sender, TObject *Source,
  44. int X, int Y)
  45. {
  46.   // Dragging is finished. Inserting picture.
  47.   MoveCaretTo(X, Y);
  48.   Graphics::TBitmap* bmp = new Graphics::TBitmap;
  49.   bmp->Assign(((TImage*)Source)->Picture->Bitmap);
  50.   RichViewEdit1->InsertPicture("", bmp, rvvaBaseline);
  51. }
  52. //---------------------------------------------------------------------------
  53. void __fastcall TForm1::WMSetCaretPos(TMessage &Message)
  54. {
  55.   MoveCaretTo(Message.WParam, Message.LParam);
  56. }
  57. //---------------------------------------------------------------------------
  58. void __fastcall TForm1::FormCreate(TObject *Sender)
  59. {
  60.   RichViewEdit1->Clear();
  61.   RichViewEdit1->AddNL("This demo shows dragging TImage to TRichViewEdit using VCL drag&drop procedures.",2,0);
  62.   RichViewEdit1->AddNL("TRichViewEdit has its own drag&drop implementation: "
  63.     "you can drag inside TRichViewEdit, "
  64.     "from TRichViewEdit to another window/application, "
  65.     "from another window/application to TRichViewEdit.",2,0);
  66.   int i;
  67.   for (i=0; i<=5; i++)
  68.     RichViewEdit1->AddNL("Drag images from the right and drop them here",0,0);
  69.   TRVTableItemInfo* table = new TRVTableItemInfo(1,2, RichViewEdit1->RVData);
  70.   table->CellBorderWidth = 1;
  71.   table->BorderWidth     = 1;
  72.   table->Cells[0][0]->Clear();
  73.   table->Cells[0][0]->AddNL("Drag images from the right and drop them here",0,0);
  74.   table->Cells[0][1]->Clear();
  75.   table->Cells[0][1]->AddNL("Drag images from the right and drop them here",0,0);
  76.   RichViewEdit1->AddItem("", table);
  77.   for (i=0; i<50; i++)
  78.     RichViewEdit1->AddNL("Drag images from the right and drop them here",0,0);
  79.   RichViewEdit1->Format();
  80. }
  81. //---------------------------------------------------------------------------