I love those special corner cases ...

I love those special corner cases ...

(PS: Can someone explain me where this link came in?)

procedure TCaretHighlighter.PresentCaretPosition;
var
lActiveForm : TCommonCustomForm;
lCaret : ICaret;
lCaretObj : TCustomCaret;
lCaretControl: IControl;
lCaretPos : TPointF;
lCaretSize : TSizeF;
lCaretRect : TRectF;
begin
lActiveForm := Screen.ActiveForm;

if true
{} and Assigned( lActiveForm )
{} and Assigned( lActiveForm.Focused )
{} and Supports( lActiveForm.Focused, ICaret, lCaret )
then
begin
lCaretObj := lCaret.GetObject( );
lCaretControl := lCaretObj.Control;

// *** ATTENTION ***
// Check for special corner cases

if lCaretControl.GetObject( ) is TCustomPresentedScrollBox
then // the Content is the REAL control of the caret ...
lCaretControl := TCustomPresentedScrollBox( lCaretControl.GetObject( ) ).Content;

// Caret position relative to form
lCaretPos := lActiveForm.ScreenToClient( lCaretControl.LocalToScreen( lCaretObj.Pos ) );
lCaretSize := lCaretObj.Size;

// Caret area
lCaretRect := TRectF.Create( lCaretPos, lCaretSize.cx + 1, lCaretSize.cy );

ShowCaretPosition( lActiveForm, lCaretRect );
end
else
HideCaretPosition( );
end;

... like hell!
http://Screen.Ac

Comments

  1. I'd guess there's something different about the "presented" control. (There are others, not just the scrollbox. Maybe you should special-case for TPresentedControl instead?) These implement a separation between data and UI and so perhaps they've been written to host their UI one level in, in Content?

    ReplyDelete
  2. David Millington The Content property is introduced in TCustomPresentedScrollBox and that is the one I need here.

    The docs for TCustomCaret tell a different story about the Control property:

    TCustomCaret.Pos:
    "Keeps the local floating-point coordinates of the TCustomCaret type object in the Control control."

    Ah, well that is what I need :o)

    TCustomCaret.Control:
    "The Create constructor retrieves this reference and initializes the Control property when the TCustomCaret object is created. The Create constructor retrieves this reference from the owner of the TCustomCaret object specified by the AOwner parameter in the call to Create."

    Oh, it is not ... :o(

    ReplyDelete

Post a Comment