[gtkada] Tags and Text Colours?
chris.danx
chris.danx at ntlworld.com
Thu Jun 5 01:01:25 CEST 2003
Hi,
How do you work with tags? I know gtkada has no binding to create_tag
because of multiple args, however all the examples on how to work with
this use this function. What I don't understand is how when the tag is
applied it actually does anything. The following code is a partially
converted version of the example given at
http://inti.sourceforge.net/tutorial/libinti/textwidget.html
I also can't find a method/subroutine matching gtk_widget_modify_text in
Gtk. How do you change the colour of the text? All code is given at
the bottom but this is the relevant section...
procedure Initialize (Window : access Txt_View_Window_Record'Class) is
begin
Gtk.Window.Initialize (Window, Window_TopLevel);
Set_Title (Window, "Text_View Example");
Gtk_New (Window.View);
Add (Window, Window.View);
-- get buffer associated with View and
-- put some text in it.
--
Window.Buffer := Get_Buffer(Window.View);
Set_Text (Window.Buffer, "Hello, this is some text");
-- change font
--
Window.PFont := Pango.Font.From_String ("Serif 15");
Modify_Font (Window.View, Window.PFont);
Set_Left_Margin (Window.View, 30);
declare
Green : Gdk_Color;
Tag : Gtk_Text_Tag;
Start : Gtk_Text_Iter;
Finish : Gtk_Text_Iter;
begin
-- change text colour??? how???
--
-- Modify_Text (Window.View, Normal, Green);
Gtk_New (Tag, "blue");
Add (Get_Tag_Table(Window.Buffer), Tag);
Get_Iter_At_Offset (Window.Buffer, Start, 7);
Get_Iter_At_Offset (Window.Buffer, Finish, 12);
Apply_Tag (Window.Buffer, Tag, Start, Finish);
end;
Show (Window.View);
end Initialize;
Thanks,
Chris
-- txtview.adb
--
with Text_View_Window; use Text_View_Window;
with Gtk.Main; use Gtk.Main;
procedure TxtView is
Window : Txt_View_Window;
begin
Gtk.Main.Init;
Gtk_New(Window);
Show(Window);
Gtk.Main.Main;
end TxtView;
-- text_view_window.ads
--
with Gtk.Window; use Gtk.Window;
with Gtk.Text_View; use Gtk.Text_View;
with Gtk.Text_Buffer; use Gtk.Text_Buffer;
with Pango.Font; use Pango.Font;
package Text_View_Window is
type Txt_View_Window_Record
is new Gtk.Window.Gtk_Window_Record with record
View : Gtk_Text_View;
Buffer : Gtk_Text_Buffer;
PFont : Pango_Font_Description;
end record;
type Txt_View_Window is access all Txt_View_Window_Record'Class;
procedure Gtk_New (Window : out Txt_View_Window);
procedure Initialize (Window : access Txt_View_Window_Record'Class);
end Text_View_Window;
-- text_view_window.adb
--
with Gdk.Color; use Gdk.Color;
with Gtk.Enums; use Gtk.Enums;
with Gtk.Text_Iter; use Gtk.Text_Iter;
with Gtk.Text_Tag; use Gtk.Text_Tag;
with Gtk.Text_Tag_Table; use Gtk.Text_Tag_Table;
package body Text_View_Window is
procedure Gtk_New (Window : out Txt_View_Window) is
begin
Window := new Txt_View_Window_Record;
Text_View_Window.Initialize (Window);
end Gtk_New;
procedure Initialize (Window : access Txt_View_Window_Record'Class) is
begin
Gtk.Window.Initialize (Window, Window_TopLevel);
Set_Title (Window, "Text_View Example");
Gtk_New (Window.View);
Add (Window, Window.View);
-- get buffer associated with View and
-- put some text in it.
--
Window.Buffer := Get_Buffer(Window.View);
Set_Text (Window.Buffer, "Hello, this is some text");
-- change font
--
Window.PFont := Pango.Font.From_String ("Serif 15");
Modify_Font (Window.View, Window.PFont);
Set_Left_Margin (Window.View, 30);
declare
Green : Gdk_Color;
Tag : Gtk_Text_Tag;
Start : Gtk_Text_Iter;
Finish : Gtk_Text_Iter;
begin
-- change text colour
--
Modify_Text (Window.View, Normal, Green);
Gtk_New (Tag, "blue");
Add (Get_Tag_Table(Window.Buffer), Tag);
Get_Iter_At_Offset (Window.Buffer, Start, 7);
Get_Iter_At_Offset (Window.Buffer, Finish, 12);
Apply_Tag (Window.Buffer, Tag, Start, Finish);
end;
Show (Window.View);
end Initialize;
end Text_View_Window;
More information about the gtkada
mailing list