There are many tables(TRVTableItemInfo) in a rvf file,I want to change some tables' order ,Have u any better ways than cut/paste?
I want to change the table item's style such as changing the table's outline color/border when the mouse over or click the table area,can u give me some ideas or some codes?
Thank u:)
Change some tables' order(sequence)
-
- Site Admin
- Posts: 17522
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Change some tables' order(sequence)
1. Unless you implement something special in your code, user can reorder items only by cut&paste.
For reordering table rows, there is a "Sort" command in RichViewActions.
2. Changing table border color below the mouse pointer is not a standard feature.
You can change colors in OnMouseMove event.
Here is an example of changing border color to clRed below the mouse pointer.
The code assumes that it is called for RichViewEdit1
(there is one line that refers to it: RichViewEdit1.RefreshAll;)
The following fields must be added to the Form:
HighlightedTable: TRVTableItemInfo;
StoredBorderColor: TColor;
StoredBorderStyle: TRVTableBorderStyle;
For reordering table rows, there is a "Sort" command in RichViewActions.
2. Changing table border color below the mouse pointer is not a standard feature.
You can change colors in OnMouseMove event.
Here is an example of changing border color to clRed below the mouse pointer.
The code assumes that it is called for RichViewEdit1
(there is one line that refers to it: RichViewEdit1.RefreshAll;)
The following fields must be added to the Form:
HighlightedTable: TRVTableItemInfo;
StoredBorderColor: TColor;
StoredBorderStyle: TRVTableBorderStyle;
Code: Select all
// Sets undo recording off (if Value=0)/ on (if Value=-1)
procedure SetUndoLimit(Ctrl: TObject; Value: Integer);
begin
if Ctrl is TCustomRichViewEdit then
TCustomRichViewEdit(Ctrl).UndoLimit := Value;
end;
procedure TForm3.RichViewEdit1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
RVData: TCustomRVFormattedData;
Pt: TPoint;
ItemNo, Offs: Integer;
Table: TRVTableItemInfo;
Changed: Boolean;
begin
// getting table below the mouse pointer
Pt := TCustomRichViewEdit(Sender).ClientToDocument(Point(X, Y));
Table := nil;
TCustomRichViewEdit(Sender).GetItemAt(Pt.X, Pt.Y, RVData, ItemNo, Offs, False);
if RVData.GetItem(ItemNo) is TRVTableItemInfo then
Table := TRVTableItemInfo(RVData.GetItem(ItemNo))
else if RVData.GetSourceRVData is TRVTableCellData then
Table := TRVTableCellData(RVData.GetSourceRVData).GetTable;
// assigning HighlightedTable and changing its BorderColor
Changed := False;
if (HighlightedTable <> nil) and (HighlightedTable <> Table) then
begin
SetUndoLimit(Sender, 0);
HighlightedTable.BorderColor := StoredBorderColor;
HighlightedTable.BorderStyle := StoredBorderStyle;
SetUndoLimit(Sender, -1);
Changed := True;
end;
if (Table <> nil) and (HighlightedTable <> Table) then
begin
StoredBorderColor := Table.BorderColor;
StoredBorderStyle := Table.BorderStyle;
SetUndoLimit(Sender, 0);
Table.BorderStyle := rvtbColor;
Table.BorderColor := clRed;
SetUndoLimit(Sender, -1);
Changed := True;
end;
HighlightedTable := Table;
if Changed then
RichViewEdit1.RefreshAll;
end;
procedure TForm3.RichViewEdit1ItemAction(Sender: TCustomRichView;
ItemAction: TRVItemAction; Item: TCustomRVItemInfo;
var Text: TRVUnicodeString; RVData: TCustomRVData);
begin
case ItemAction of
rviaDestroying, rviaMovingToUndoList:
if Item = HighlightedTable then
HighlightedTable := nil;
end;
end;
Re: Change some tables' order(sequence)
Thanks a lot!
Re: Change some tables' order(sequence)
The onMouseMove event raise exception at "Pt := TCustomRichViewEdit(Sender).ClientToDocument(Point(X, Y));",My TSRichViewEdit is in a frame,maybe that's the reason for "access violation" exception? Trace the code step by step to the method" TCustomRichView.ClientToDocument", the first line can not pass:)
-
- Site Admin
- Posts: 17522
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Change some tables' order(sequence)
The code for ScaleRichView is a bit different.
For example, in OnMouseMove event, the Sender parameter is TSRichViewEdit, so typecasting it to TRichViewEdit leads to an exception.
Also, the methods for hit testing are different.
I'll create a code for ScaleRichView tomorrow.
For example, in OnMouseMove event, the Sender parameter is TSRichViewEdit, so typecasting it to TRichViewEdit leads to an exception.
Also, the methods for hit testing are different.
I'll create a code for ScaleRichView tomorrow.
-
- Site Admin
- Posts: 17522
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Change some tables' order(sequence)
Here is the code for ScaleRichView.
As you can see, it's almost the same, the difference is only in finding the item below the mouse pointer.
The following fields must be added to the Form:
HighlightedTable: TRVTableItemInfo;
StoredBorderColor: TColor;
StoredBorderStyle: TRVTableBorderStyle;
As you can see, it's almost the same, the difference is only in finding the item below the mouse pointer.
The following fields must be added to the Form:
HighlightedTable: TRVTableItemInfo;
StoredBorderColor: TColor;
StoredBorderStyle: TRVTableBorderStyle;
Code: Select all
// Sets undo recording off (if Value=0)/ on (if Value=-1)
procedure SetUndoLimit(Ctrl: TObject; Value: Integer);
begin
if Ctrl is TCustomRichViewEdit then
TCustomRichViewEdit(Ctrl).UndoLimit := Value;
end;
procedure TfrmMain.SRichViewEdit1MouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
var
pt: TPoint;
SRV: TSRichViewEdit;
RVData: TCustomRVFormattedData;
InPageArea, InLeftArea, InTextArea: Boolean;
ItemNo, Offs: Integer;
Table: TRVTableItemInfo;
Changed: Boolean;
begin
SRV := (Sender as TSRichViewEdit);
pt := SRV.ConvertSRVtoRV(Point(X, Y), InTextArea, InLeftArea, InPageArea);
if not InTextArea then
exit;
pt := SRV.ActiveEditor.ClientToDocument(pt);
SRV.ActiveEditor.GetItemAt(pt.X, pt.Y, RVData, ItemNo, Offs, False);
Table := nil;
if RVData.GetItem(ItemNo) is TRVTableItemInfo then
Table := TRVTableItemInfo(RVData.GetItem(ItemNo))
else if RVData.GetSourceRVData is TRVTableCellData then
Table := TRVTableCellData(RVData.GetSourceRVData).GetTable;
// assigning HighlightedTable and changing its BorderColor
Changed := False;
if (HighlightedTable <> nil) and (HighlightedTable <> Table) then
begin
SetUndoLimit(SRV.ActiveEditor, 0);
HighlightedTable.BorderColor := StoredBorderColor;
HighlightedTable.BorderStyle := StoredBorderStyle;
SetUndoLimit(SRV.ActiveEditor, -1);
Changed := True;
end;
if (Table <> nil) and (HighlightedTable <> Table) then
begin
StoredBorderColor := Table.BorderColor;
StoredBorderStyle := Table.BorderStyle;
SetUndoLimit(SRV.ActiveEditor, 0);
Table.BorderStyle := rvtbColor;
Table.BorderColor := clRed;
SetUndoLimit(SRV.ActiveEditor, -1);
Changed := True;
end;
HighlightedTable := Table;
if Changed then
SRV.ActiveEditor.Repaint;
end;
procedure TfrmMain.SRichViewEdit1ItemAction(Sender: TCustomRichView;
ItemAction: TRVItemAction; Item: TCustomRVItemInfo;
var Text: TRVUnicodeString; RVData: TCustomRVData);
begin
case ItemAction of
rviaDestroying, rviaMovingToUndoList:
if Item = HighlightedTable then
HighlightedTable := nil;
end;
end;