trichview.com

trichview.support




Re: MoveCaretTo(X,Y) for use in drag/drop


Return to index


Author

Message

Sergey Tkachenko

Posted: 03/08/2002 12:26:49


Well, you are right.

That code activates editing in cell only if you move caret over some item

(text or image) in it.

This can be easily fixed.

You need to move code for checking for "ItemNo<0" aftter activating a cell

editor:


procedure TForm1.MoveCaretTo(X, Y: Integer);

var RVData: TCustomRVFormattedData;

    ItemNo, Offs: Integer;

begin

  inc(X, CurrentRV.HScrollPos);

  inc(Y, CurrentRV.VScrollPos*CurrentRV.VSmallStep);

  CurrentRV.RVData.GetItemAtEx(X,Y,RVData,ItemNo,Offs);

  if RVData is TRVTableCellData then begin

    TRVTableCellData(RVData).Edit;

    RVData := TCustomRVFormattedData(RVData.GetRVData);

  end;

  if ItemNo<0 then exit;

  RVData.SetSelectionBounds(ItemNo, Offs, ItemNo, Offs);

  RVData.Invalidate;

end;


However, there is a better solution.

You need to modify a source code (or you can wait for the update).

Find the declaration of TCustomRVFormattedData.GetItemAtEx in CRVFData.pas

Add an additional last parameter: Strict: Boolean;

And change implementation of this function to:


procedure TCustomRVFormattedData.GetItemAtEx(X,Y: Integer;

                                             var RVData:

TCustomRVFormattedData;

                                             var ItemNo, OffsetInItem:

Integer;

                                             Strict: Boolean);

var AX, AY, BX,BY: Integer;

begin

  RVData := Self;

  FindDrawItemForSel(X, Y, ItemNo, OffsetInItem, Strict);

  if ItemNo<>-1 then begin

    DrawItem2Item(ItemNo, OffsetInItem, ItemNo, OffsetInItem);

    GetItemCoords(ItemNo, AX, AY);

    dec(X,AX);

    dec(Y,AY);

    RVData :=

TCustomRVFormattedData(TCustomRVItemInfo(Items.Objects[ItemNo]).GetSubRVData

At(X,Y));

    if RVData=nil then

      RVData := Self

    else begin

      RVData.GetOriginEx(BX,BY);

      dec(X,BX-AX);

      dec(Y,BY-AY);

      RVData.GetItemAtEx(X,Y, RVData, ItemNo, OffsetInItem, Strict);

    end;

  end;

end;


If you pass True as a last new parameter, this function will work as before.

If you pass False, this function will work more appropriately for this

task - if mouse is to the left/right of the outermost item, it will return

outermost position in this item.





Powered by ABC Amber Outlook Express Converter