richmemo: implements gtk2 settextstyle range

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@965 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
skalogryz
2009-09-26 20:03:16 +00:00
parent da7140dead
commit 0993f43699

View File

@ -25,11 +25,11 @@ interface
uses
// Bindings
gtk2,
gtk2, glib2, gdk2, pango,
// FCL
Classes, SysUtils,
// LCL
LCLType, Controls,
LCLType, Controls, Graphics,
// Gtk2 widget
GtkDef,
GTKWinApiWindow, GtkGlobals, GtkProc, InterfaceBase,
@ -44,6 +44,7 @@ type
class procedure SetCallbacks(const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo);
published
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
class procedure SetTextAttributes(const AWinControl: TWinControl; TextStart, TextLen: Integer; const Params: TIntFontParams); override;
end;
implementation
@ -103,5 +104,56 @@ begin
SetCallbacks(Widget, WidgetInfo);
end;
class procedure TGtk2WSCustomRichMemo.SetTextAttributes(const AWinControl: TWinControl; TextStart, TextLen: Integer; const Params: TIntFontParams);
var
Widget, TextWidget: PGtkWidget;
list : PGList;
buffer : PGtkTextBuffer;
tag : Pointer;
istart : TGtkTextIter;
iend : TGtkTextIter;
gcolor : TGdkColor;
nm : string;
const
PangoUnderline : array [Boolean] of Integer = (PANGO_UNDERLINE_NONE, PANGO_UNDERLINE_SINGLE);
PangoBold : array [Boolean] of Integer = (PANGO_WEIGHT_NORMAL, PANGO_WEIGHT_BOLD);
PangoItalic : array [Boolean] of Integer = (PANGO_STYLE_NORMAL, PANGO_STYLE_ITALIC);
begin
Widget := PGtkWidget(PtrUInt(AWinControl.Handle));
list := gtk_container_get_children(PGtkContainer(Widget));
if not Assigned(list) then Exit;
TextWidget := PGtkWidget(list^.data);
if not Assigned(TextWidget) then Exit;
buffer := gtk_text_view_get_buffer (PGtkTextView(TextWidget));
if not Assigned(buffer) then Exit;
gcolor := TColortoTGDKColor(Params.Color);
nm := Params.Name;
if nm = '' then nm := #0;
tag := gtk_text_buffer_create_tag (buffer, nil,
'foreground-gdk', [@gcolor,
'size-set', gboolean(true),
'size-points', Double(Params.Size),
'underline-set', gboolean(True),
'underline', PangoUnderline[fsUnderline in Params.Style],
'weight-set', gboolean(True),
'weight', PangoBold[fsBold in Params.Style],
'style-set', gboolean(True),
'style', PangoItalic[fsItalic in Params.Style],
'strikethrough-set', gboolean(True),
'strikethrough ', gboolean(fsStrikeOut in Params.Style),
'familty-set', gboolean(true),
'family', @nm[1],
nil]);
gtk_text_buffer_get_iter_at_offset (buffer, @istart, TextStart);
gtk_text_buffer_get_iter_at_offset (buffer, @iend, TextStart+TextLen);
gtk_text_buffer_apply_tag(buffer, tag, @istart, @iend);
end;
end.