trichview.com

trichview.support




Re: Which standard action to select font size?


Return to index


Author

Message

Sergey Tkachenko

Posted: 04/22/2004 11:57:54


> However, I can't seem to figure out which units I need to add to the uses

> clause to get this to work . . . since I don't have the source, could you

> let me know which units to add?


These lines are copied from the ActionTest demo,

http://www.trichview.com/resources/actions/richviewactions.zip

Unit3.pas

This ZIP includes the complete source code for RichViewActions: both for the

actions themselves and for the demo.


Briefly, this code is executed from inside OnClick and OnExit events of

combobox for selecting font size. This demo has two comboboxes - for font

names and font sizes.

The combobox for font names updates the combobox for font sizes and applies

the font name (using the same TrvActionFontEx). The combobox for font sizes

applies the font size.

These comboboxes are special comboboxes - components included in

RichViewActions.

TRVFontComboBox - very simple component, a combobox filled with the

available font names.

TRVFontSizeComboBox is automatically filled with font sizes available for

the specified font (or with a set of predefined font sizes for TrueType

fonts)


The complete code is below


// Current font is changed. Updating the combo-boxes.

// RichViewEdit1.OnCurTextStyleChanged

procedure TForm3.RichViewEdit1CurTextStyleChanged(Sender: TObject);

var CurStyle: TFontInfo;

begin

  UpdatingCombos := True;

  try

    CurStyle := RVStyle1.TextStyles[RichViewEdit1.CurTextStyleNo];

    cmbFont.Text := CurStyle.FontName;

    cmbFont.OnClick(Sender);

    cmbFontSize.Text := IntToStr(CurStyle.Size);

  finally

    UpdatingCombos := False;

  end;

end;


// Applying the font name

// cmbFont.OnClick and OnExit

procedure TForm3.cmbFontClick(Sender: TObject);

var FontName: String;

begin

  if cmbFont.ItemIndex<0 then

    FontName := cmbFont.Text

  else

    FontName := cmbFont.Items[cmbFont.ItemIndex];

  cmbFontSize.FontName := FontName;

  if UpdatingCombos then

    exit;

  if cmbFont.ItemIndex<0 then

    cmbFont.ItemIndex := cmbFont.Items.IndexOf(FontName);

  if cmbFont.ItemIndex<0 then begin

      Beep

    end

  else

    with rvActionsResource.rvActionFontEx1 do begin

      UserInterface := False;

      ValidProperties := [rvfimFontName];

      Font.Name := FontName;

      Execute;

      UserInterface := True;

    end;

  RichViewEdit1.SetFocus;

end;


// Changing the font size

// cmbFontSize.OnClick and OnExit

procedure TForm3.cmbFontSizeClick(Sender: TObject);

var FontSize: Integer;

begin

  if UpdatingCombos then

    exit;

  try

    FontSize := StrToInt(cmbFontSize.Text);

    with rvActionsResource.rvActionFontEx1 do begin

      UserInterface := False;

      ValidProperties := [rvfimSize];

      Font.Size := FontSize;

      Execute;

      UserInterface := True;

    end;

  except

    Beep;

  end;

  RichViewEdit1.SetFocus;

end;


// cmbFontSize.OnKeyPress

procedure TForm3.cmbKeyPress(Sender: TObject; var Key: Char);

begin

  if Key=#13 then begin

    Key := #0;

    TComboBox(Sender).OnClick(Sender);

  end;

end;





Powered by ABC Amber Outlook Express Converter