Page 1 of 1

how to enable edit in party area?

Posted: Tue Nov 23, 2010 3:08 pm
by chuqingsheng
I uses richviewedit with table , enable user can edit in cell but user cannt edit out side table cell . how to ?

Posted: Tue Nov 23, 2010 5:13 pm
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\

Posted: Wed Nov 24, 2010 7:00 am
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?

Posted: Wed Nov 24, 2010 4:21 pm
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?

Posted: Thu Nov 25, 2010 11:25 am
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?

Posted: Thu Nov 25, 2010 11:42 am
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;

Posted: Thu Nov 25, 2010 3:45 pm
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;

Posted: Thu Nov 25, 2010 4:41 pm
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 ?

Posted: Thu Nov 25, 2010 5:06 pm
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.