trichview.com

trichview.support




Re: Emotion icon


Return to index


Author

Message

Sergey Tkachenko

Posted: 03/14/2004 13:43:09


Below is the modified example.


1) OnKeyPress


Replaces ':)', ':|' and ':(' with bullets.

Unlike the previous example, this one does it immediately when the user

types one of these codes.

I think it's better for emotions icons (the first example was originally

created for word autoreplace feature)


2) OnKeyDown


If there is no selection, and user presses Backspace key when the caret is

to the right of emotion icon, the icon is "disassembled" back to its text

code.



procedure TForm1.rve4KeyPress(Sender: TObject; var Key: Char);

var

  rve: TCustomRichViewEdit;

  ItemNo, Offs: Integer;

  s: String;


  function GetImageIndex(mouth: Char): Integer;

  begin

    case mouth of

      ')': Result := 0;

      '|': Result := 1;

      else Result := 2;

    end;

  end;


begin

  if not (Key in [')', '(', '|']) then

    exit;

  rve := (Sender as TCustomRichViewEdit).TopLevelEditor;

  ItemNo := rve.CurItemNo;

  if rve.GetItemStyle(ItemNo)<0 then

    exit;

  Offs := rve.OffsetInCurItem;

  s := rve.GetItemTextA(ItemNo);

  if (s='') or (Offs=1) then

    exit;

  if s[Offs-1]=':' then begin

    rve.SetSelectionBounds(ItemNo, Offs-1, ItemNo, Offs);

    rve.InsertBullet(GetImageIndex(Key), ImageList1);

    Key := #0;

  end;

end;


procedure TForm1.rve4KeyDown(Sender: TObject; var Key: Word;

  Shift: TShiftState);

var

  rve: TCustomRichViewEdit;

  ItemNo, Offs: Integer;


  function GetBulletImageIndex: Integer;

  var s: String;

      tag: Integer;

      il: TCustomImageList;

  begin

    rve.GetBulletInfo(ItemNo, s, Result, il, tag);

  end;


  function GetSmile(ImageIndex: Integer): String;

  begin

    case ImageIndex of

      0: Result := ':)';

      1: Result := ':|';

      else Result := ':(';

    end;

  end;


begin

  if Key<>VK_BACK then

    exit;

  rve := (Sender as TCustomRichViewEdit).TopLevelEditor;

  if rve.SelectionExists then

    exit;

  ItemNo := rve.CurItemNo;

  Offs := rve.OffsetInCurItem;

  if (rve.GetItemStyle(ItemNo)=rvsBullet) and (Offs=1) then begin

    Key := 0;

    rve.SetSelectionBounds(ItemNo, 0, ItemNo, 1);

    rve.InsertText(GetSmile(GetBulletImageIndex));

  end;

end;





Powered by ABC Amber Outlook Express Converter