how to enable edit in party area?

General TRichView support forum. Please post your questions here
Post Reply
chuqingsheng
Posts: 38
Joined: Sat Nov 06, 2010 5:12 am

how to enable edit in party area?

Post by chuqingsheng »

I uses richviewedit with table , enable user can edit in cell but user cannt edit out side table cell . how to ?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

When inserting a table, you can use a paragraph style with [rvpaoReadOnly, rvpaoStyleProtect, rvpaoDoNotWantReturns] included in Options.
See the example in Assorted\Fields\Spreadsheet\
chuqingsheng
Posts: 38
Joined: Sat Nov 06, 2010 5:12 am

Post by chuqingsheng »

Sergey , Thanks your help.

I mean User can edit content the table ,but can't edit, insert content in out of table.

I use OnKeyPress and OnPaste of RichViewEdit. and use a varible

Code: Select all


var
FCurrInTable :Boolean;


procedure TfrmAppMain.rveKeyPress(Sender: TObject; var Key: Char);
var Item: TCustomRVItemInfo;
RV: TCustomRichViewEdit;
begin
rve.GetCurrentItemEx(TRVTableItemInfo, RV, Item);
FCurrInTable := Item is TRVTableItemInfo;

if not FCurrInTable then Key :=#0;


end;

procedure TfrmAppMain.rvePaste(Sender: TCustomRichViewEdit;
var Item: TCustomRVItemInfo;
RV: TCustomRichViewEdit;
begin
rve.GetCurrentItemEx(TRVTableItemInfo, RV, Item);
FCurrInTable := Item is TRVTableItemInfo;


DoDefault := FCurrInTable;
end;



but the caret is at before table or after table only (on same line) , those does'nt work.

How to detect the caret position only before or after a table?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

The caret is inside table cell, if rve.InplaceEditor<>nil.

But all this code is not necessary.
If you protect the paragraph used for the table, the user will not be able to enter text outside the table.

How do you insert this table?
chuqingsheng
Posts: 38
Joined: Sat Nov 06, 2010 5:12 am

Post by chuqingsheng »

Sergey Tkachenko wrote:The caret is inside table cell, if rve.InplaceEditor<>nil.

But all this code is not necessary.
If you protect the paragraph used for the table, the user will not be able to enter text outside the table.

How do you insert this table?

Yes,
I need user cann't insert anything at out of table. but I need user can press a button to call my program code to insert something. how to do?
chuqingsheng
Posts: 38
Joined: Sat Nov 06, 2010 5:12 am

Post by chuqingsheng »

Thank Sergey again.

this code working fine.

Code: Select all

procedure TfrmAppMain.rveKeyPress(Sender: TObject; var Key: Char);
var Item: TCustomRVItemInfo;
  RV: TCustomRichViewEdit;
begin
  rve.GetCurrentItemEx(TRVTableItemInfo, RV, Item);
  FCurrInTable := Item is TRVTableItemInfo;

  if (rve.InplaceEditor = nil) and (FCurrInTable) then
  begin
    Key := #0;
    Exit;
  end;

  if not FCurrInTable then Key := #0;
end;

procedure TfrmAppMain.rvePaste(Sender: TCustomRichViewEdit;
  var DoDefault: Boolean);
var Item: TCustomRVItemInfo;
  RV: TCustomRichViewEdit;
begin
  rve.GetCurrentItemEx(TRVTableItemInfo, RV, Item);
  FCurrInTable := Item is TRVTableItemInfo;


  if (rve.InplaceEditor = nil) and (FCurrInTable) then
  begin
    DoDefault := False;
    Exit;
  end;

  DoDefault := FCurrInTable;

end;
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Can you explain why do you choose a complex solution using events instead of simple solution using a paragraph protection?

If you still want to use events, OnKeyPress and OnPaste are not enough.
If you did not turn off drag&drop (i.e. if rve.AcceptDragDropFormats property is not empty), it is still possible to insert outside this table using a drag&drop.
You can either forbid accepting drag&drop by removing all values from rve.AcceptDragDropFormats, or use OnOleDragOver and OnOleDrop events:

Code: Select all

procedure TForm3.RichViewEdit1OleDragOver(Sender: TCustomRichView;
  Shift: TShiftState; X, Y: Integer;
  PossibleDropEffects: TRVOleDropEffects;
  var DropEffect: TRVOleDropEffect);
var RVData: TCustomRVFormattedData;
   ItemNo, Offs: Integer;
   P: TPoint;
begin
  P := Sender.ClientToDocument(Point(X, Y));
  Sender.GetItemAt(P.X, P.Y, RVData, ItemNo, Offs, False);
  if RVData=Sender.RVData then
    DropEffect := rvdeNone;
end;

procedure TForm3.RichViewEdit1OleDrop(Sender: TCustomRichView;
  const DataObject: IDataObject; Shift: TShiftState; X, Y: Integer;
  PossibleDropEffects: TRVOleDropEffects; var DropEffect: TRVOleDropEffect;
  var DoDefault: Boolean);
var RVData: TCustomRVFormattedData;
   ItemNo, Offs: Integer;
   P: TPoint;
begin
  P := Sender.ClientToDocument(Point(X, Y));
  Sender.GetItemAt(P.X, P.Y, RVData, ItemNo, Offs, False);
  if RVData=Sender.RVData then begin
    DropEffect := rvdeNone;
    DoDefault := False;
  end;
end;
chuqingsheng
Posts: 38
Joined: Sat Nov 06, 2010 5:12 am

Post by chuqingsheng »

I want user cannot modify the content outside of table, but my program can insert , modify the content outside of table , if use your previous suggestion , my program cannot insert something outside of table.

I have found the issue of my complex solution about drag
&drop. Thank you for your kindy suggestion.
by the way, have any other simple method ?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Simply use my suggestions from the previous post.
Either remove all values from AcceptDragDropFormats to disallow drag&drop completely, or add the code I posted in OnOleDragOver and OnOleDrop events.
Post Reply