trichview.support
Re: Extend table by one row |
Author |
Message |
Sergey Tkachenko |
Posted: 09/24/2004 13:57:06 The code without error messages :) Main editor has name RichViewEdit1 procedure TForm3.RichViewEdit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); var rve,rvetop: TCustomRichViewEdit; table: TRVTableItemInfo; r,c: Integer; begin if (Key=VK_RETURN) and (Shift=[]) then begin if RichViewEdit1.SelectionExists then exit; if not RichViewEdit1.GetCurrentItemEx(TRVTableItemInfo, rve, TCustomRVItemInfo(table)) then exit; rvetop := table.GetEditedCell(r,c); // no edited cell? if rvetop=nil then exit; // last cell? if (r+table.Cells[r,c].RowSpan<table.Rows.Count) or (c+table.Cells[r,c].ColSpan<table.Rows[r].Count) then exit; // caret at the end of cell? if (rvetop.CurItemNo<rvetop.ItemCount-1) or (rvetop.OffsetInCurItem<rvetop.GetOffsAfterItem(rvetop.CurItemNo)) then exit; // we cannot add new row right here, because it will destroy Sender editor. // so using PostMessage PostMessage(Handle, WM_RVADDROW, 0, 0); Key := 0; end; if Key in [VK_SPACE, VK_RETURN] then begin rvActionsResource.rvActionInsertHyperlink1.DetectURL(RichViewEdit1); rvActionsResource.rvActionInsertHyperlink1.TerminateHyperlink(RichViewEdit1) ; end; end; // Constant > WM_USER const WM_RVADDROW = WM_USER+5; // In form declaration procedure WMRVAddRow(var Msg: TMessage); message WM_RVADDROW; procedure TForm3.WMRVAddRow(var Msg: TMessage); var rve: TCustomRichViewEdit; table: TRVTableItemInfo; ItemNo, Data: Integer; r,c: Integer; begin if not RichViewEdit1.GetCurrentItemEx(TRVTableItemInfo, rve, TCustomRVItemInfo(table)) then exit; ItemNo := table.GetMyItemNo; rve.BeginItemModify(ItemNo, Data); table.InsertRows(table.Rows.Count, 1, table.Rows.Count-1, False); rve.EndItemModify(ItemNo, Data); rve.Change; table.Rows.GetMainCell(table.Rows.Count-1, 0, r, c); table.EditCell(r,c); end; Note 1: this code does not allow adding new paragraph at the end of the last cell - it adds new row instead. May be it's better to use Ctrl+Enter? Note 2: yes, if Tab is used to move to another cell, it is not passed to OnKeyDown. May be it will be changed in future versions. |
Powered by ABC Amber Outlook Express Converter