From 2c9ce7d64e0f3a63c37967efe6e83c56ea653877 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Fri, 3 Dec 2004 18:00:30 +0000 Subject: [PATCH] * gtk/Gtk.metadata: Pass TextIters by ref almost everywhere. [Fixes #70187]. Kill two varargs warnings. * gtk/TextBuffer.custom: Update for that, and also implement InsertWithTagsByName * sample/GtkDemo/DemoHyperText.cs: * sample/GtkDemo/DemoTextView.cs: Remove kludges for broken TextIter handling. Also fix the i18n demo bits by translating the octal-encoded UTF-8 to hex-encoded UTF-16. svn path=/trunk/gtk-sharp/; revision=37039 --- ChangeLog | 13 +++ doc/ChangeLog | 5 + doc/en/Gtk/TextBuffer.xml | 85 ++++++++------ doc/en/Gtk/TextView.xml | 20 ++-- gtk/Gtk.metadata | 14 ++- gtk/TextBuffer.custom | 27 ++++- sample/GtkDemo/DemoHyperText.cs | 34 ++---- sample/GtkDemo/DemoTextView.cs | 194 ++++++++++++++------------------ 8 files changed, 207 insertions(+), 185 deletions(-) diff --git a/ChangeLog b/ChangeLog index d5870005d..be4044c6e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2004-12-03 Dan Winship + + * gtk/Gtk.metadata: Pass TextIters by ref almost everywhere. + [Fixes #70187]. Kill two varargs warnings. + + * gtk/TextBuffer.custom: Update for that, and also implement + InsertWithTagsByName + + * sample/GtkDemo/DemoHyperText.cs: + * sample/GtkDemo/DemoTextView.cs: Remove kludges for broken + TextIter handling. Also fix the i18n demo bits by translating the + octal-encoded UTF-8 to hex-encoded UTF-16. + 2004-12-03 Mike Kestner * gtk/Gtk.metadata : hide junk methods in Global. [Fixes #60895] diff --git a/doc/ChangeLog b/doc/ChangeLog index ec4a4aae4..63c0cc2dc 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,8 @@ +2004-12-03 Dan Winship + + * en/Gtk/TextBuffer.xml: + * en/Gtk/TextView.xml: update for TextIter pass-by-ref changes + 2004-12-02 Shane Landrum * en/Gtk/EntryCompletionMatchFunc.xml diff --git a/doc/en/Gtk/TextBuffer.xml b/doc/en/Gtk/TextBuffer.xml index af449af02..7aaa4c6fc 100644 --- a/doc/en/Gtk/TextBuffer.xml +++ b/doc/en/Gtk/TextBuffer.xml @@ -36,12 +36,8 @@ - Clears the contents in the current buffer - - - This is a convenience call to . - - + Clears the contents of the buffer + @@ -177,13 +173,13 @@ - + Method System.Void - + @@ -252,14 +248,14 @@ - + Method System.Void - + @@ -342,13 +338,13 @@ - + Method Gtk.TextChildAnchor - + @@ -393,13 +389,13 @@ - + Method System.Void - + @@ -477,14 +473,14 @@ - + Method System.Boolean - - + + @@ -520,14 +516,14 @@ - + Method System.Void - - + + @@ -542,8 +538,8 @@ actually fires off the event, and the default handler of that signal deletes the text. Because the buffer is modified, all outstanding iterators become - invalid after calling this function; however, the start - and end will be re-initialized to point to the location + invalid after calling this function; however, + and will be re-initialized to point to the location where text was deleted. @@ -705,13 +701,13 @@ - + Method System.Boolean - + @@ -804,13 +800,13 @@ - + Method System.Void - + @@ -1231,13 +1227,13 @@ - + Method System.Void - + @@ -1271,13 +1267,13 @@ - + Method System.Boolean - + @@ -1646,21 +1642,40 @@ - + Method System.Void - + Inserts into buffer at , applying the list of to the newly-inserted text. - a - a - a + location to insert the text + text to insert + tags to apply to + Equivalent to calling , then on the inserted text; It is just a convenience function. + + + + + Method + + System.Void + + + + + + + + Inserts into buffer at , applying the list of tags with names to the newly-inserted text. + location to insert the text + text to insert + names of the tags to apply to Equivalent to calling , then on the inserted text; It is just a convenience function. diff --git a/doc/en/Gtk/TextView.xml b/doc/en/Gtk/TextView.xml index 61b0f2abe..9eb99d8ae 100644 --- a/doc/en/Gtk/TextView.xml +++ b/doc/en/Gtk/TextView.xml @@ -129,13 +129,13 @@ class TextViewSample - + Method System.Boolean - + Moves the given iter backward by one display (wrapped) line @@ -227,13 +227,13 @@ class TextViewSample - + Method System.Boolean - + Moves forward to the next display line end @@ -292,13 +292,13 @@ class TextViewSample - + Method System.Boolean - + Moves the given backward to the next display line start @@ -320,13 +320,13 @@ class TextViewSample - + Method System.Boolean - + Moves the given forward by one display (wrapped) line @@ -455,13 +455,13 @@ class TextViewSample - + Method System.Boolean - + diff --git a/gtk/Gtk.metadata b/gtk/Gtk.metadata index 15b0a5364..58c5cdfa6 100644 --- a/gtk/Gtk.metadata +++ b/gtk/Gtk.metadata @@ -251,26 +251,29 @@ 1 1 tag_table + ref ApplyTag DeleteMark out out GetInsertMark out + out out out - out out out out out 1 - 1 + 1 1 1 - 1 + 1 + 1 MoveMark RemoveTag + 1 TagApplied UserActionBegun UserActionEnded @@ -285,9 +288,14 @@ 1 TextEvent 1 + ref + ref + ref + ref out out out + ref ScrollAdjustmentsSet Toggle 1 diff --git a/gtk/TextBuffer.custom b/gtk/TextBuffer.custom index e649956fa..a812e6198 100644 --- a/gtk/TextBuffer.custom +++ b/gtk/TextBuffer.custom @@ -33,7 +33,8 @@ public string Text { public void Clear () { - Delete (StartIter, EndIter); + Gtk.TextIter start = StartIter, end = EndIter; + Delete (ref start, ref end); } // overload to paste clipboard contents at cursor editable by default. @@ -48,16 +49,16 @@ public void PasteClipboard (Gtk.Clipboard clipboard) [DllImport("libgtk-win32-2.0-0.dll")] static extern void gtk_text_buffer_insert (IntPtr raw, ref Gtk.TextIter iter, string text, int len); -public void Insert (Gtk.TextIter iter, string text) +public void Insert (ref Gtk.TextIter iter, string text) { gtk_text_buffer_insert (Handle, ref iter, text, -1); } -public void InsertWithTags (TextIter iter, string text, params TextTag[] tags) +public void InsertWithTags (ref TextIter iter, string text, params TextTag[] tags) { TextIter start; int offset = iter.Offset; - Insert (iter, text); + Insert (ref iter, text); start = GetIterAtOffset (offset); iter = GetIterAtOffset (offset + text.Length); @@ -66,6 +67,22 @@ public void InsertWithTags (TextIter iter, string text, params TextTag[] tags) this.ApplyTag (t, start, iter); } +public void InsertWithTagsByName (ref TextIter iter, string text, params string[] tagnames) +{ + TextIter start; + int offset = iter.Offset; + Insert (ref iter, text); + + start = GetIterAtOffset (offset); + iter = GetIterAtOffset (offset + text.Length); + + foreach (string tagname in tagnames) { + TextTag tag = TagTable.Lookup (tagname); + if (tag != null) + this.ApplyTag (tag, start, iter); + } +} + public void SetText (string text) { gtk_text_buffer_set_text (Handle, text, -1); @@ -74,7 +91,7 @@ public void SetText (string text) [DllImport("libgtk-win32-2.0-0.dll")] static extern bool gtk_text_buffer_insert_interactive(IntPtr raw, ref Gtk.TextIter iter, string text, int len, bool default_editable); -public bool InsertInteractive(Gtk.TextIter iter, string text, bool default_editable) +public bool InsertInteractive(ref Gtk.TextIter iter, string text, bool default_editable) { return gtk_text_buffer_insert_interactive(Handle, ref iter, text, -1, default_editable); } diff --git a/sample/GtkDemo/DemoHyperText.cs b/sample/GtkDemo/DemoHyperText.cs index 370d9d8a6..2441d1371 100644 --- a/sample/GtkDemo/DemoHyperText.cs +++ b/sample/GtkDemo/DemoHyperText.cs @@ -13,7 +13,6 @@ namespace GtkDemo { bool hoveringOverLink = false; Gdk.Cursor handCursor, regularCursor; - TextIter lastIter; public DemoHyperText () : base ("HyperText") { @@ -48,7 +47,6 @@ namespace GtkDemo view.MotionNotifyEvent += new MotionNotifyEventHandler (OnMotionNotify); view.VisibilityNotifyEvent += new VisibilityNotifyEventHandler (OnVisibilityNotify); view.ButtonReleaseEvent += new ButtonReleaseEventHandler (OnButtonRelease); - view.Buffer.InsertText += new InsertTextHandler (OnTextInserted); ShowPage (view.Buffer, 1); return view; @@ -58,7 +56,7 @@ namespace GtkDemo // appearance of a hyperlink in a web browser: blue and underlined. // Additionally, attaches some data on the tag, to make it recognizable // as a link. - void InsertLink (TextBuffer buffer, TextIter iter, string text, int page) + void InsertLink (TextBuffer buffer, ref TextIter iter, string text, int page) { TextTag tag = new TextTag ("link"); tag.Foreground = "blue"; @@ -66,7 +64,7 @@ namespace GtkDemo tag.Data.Add ("page", page); buffer.TagTable.Add (tag); - buffer.InsertWithTags (iter, text, tag); + buffer.InsertWithTags (ref iter, text, tag); } // Fills the buffer with text and interspersed links. In any real @@ -78,32 +76,32 @@ namespace GtkDemo if (page == 1) { - buffer.Insert (iter, "Some text to show that simple "); - InsertLink (buffer, lastIter, "hypertext", 3); - buffer.Insert (lastIter, " can easily be realized with "); - InsertLink (buffer, lastIter, "tags", 2); - buffer.Insert (lastIter, "."); + buffer.Insert (ref iter, "Some text to show that simple "); + InsertLink (buffer, ref iter, "hypertext", 3); + buffer.Insert (ref iter, " can easily be realized with "); + InsertLink (buffer, ref iter, "tags", 2); + buffer.Insert (ref iter, "."); } else if (page == 2) { - buffer.Insert (iter, + buffer.Insert (ref iter, "A tag is an attribute that can be applied to some range of text. " + "For example, a tag might be called \"bold\" and make the text inside " + "the tag bold. However, the tag concept is more general than that; " + "tags don't have to affect appearance. They can instead affect the " + "behavior of mouse and key presses, \"lock\" a range of text so the " + "user can't edit it, or countless other things.\n"); - InsertLink (buffer, lastIter, "Go back", 1); + InsertLink (buffer, ref iter, "Go back", 1); } else if (page == 3) { TextTag tag = new TextTag ("bold"); tag.Weight = Pango.Weight.Bold; - buffer.InsertWithTags (iter, "hypertext:\n", tag); - buffer.Insert (lastIter, + buffer.InsertWithTags (ref iter, "hypertext:\n", tag); + buffer.Insert (ref iter, "machine-readable text that is not sequential but is organized" + "so that related items of information are connected.\n"); - InsertLink (buffer, lastIter, "Go back", 1); + InsertLink (buffer, ref iter, "Go back", 1); } } @@ -193,14 +191,6 @@ namespace GtkDemo SetCursorIfAppropriate (view, x, y); } - // When inserting text, iters are invalidated - // but the default handler provides us the iter - // at the end of inserted text - void OnTextInserted (object sender, InsertTextArgs a) - { - lastIter = a.Pos; - } - // Also update the cursor image if the window becomes visible // (e.g. when a window covering it got iconified). void OnVisibilityNotify (object sender, VisibilityNotifyEventArgs a) diff --git a/sample/GtkDemo/DemoTextView.cs b/sample/GtkDemo/DemoTextView.cs index 8f7e2fd65..2dca30545 100644 --- a/sample/GtkDemo/DemoTextView.cs +++ b/sample/GtkDemo/DemoTextView.cs @@ -264,139 +264,113 @@ namespace GtkDemo TextIter insertIter; insertIter = buffer.GetIterAtOffset (0); - buffer.Insert (insertIter, + buffer.Insert (ref insertIter, "The text widget can display text with all kinds of nifty attributes.It also supports multiple views of the same buffer; this demo is showing the same buffer in two places.\n\n"); - InsertWithTagsByName (buffer, "Font styles. ", new string[] {"heading"}); - Insert (buffer, "For example, you can have "); - InsertWithTagsByName (buffer, "italic", new string[] {"italic"}); - Insert (buffer, ", "); - InsertWithTagsByName (buffer, "bold", new string[] {"bold"}); - Insert (buffer, ", or "); - InsertWithTagsByName (buffer, "monospace (typewriter)", new string[] {"monospace"}); - Insert (buffer, ", or "); - InsertWithTagsByName (buffer, "big", new string[] {"big"}); - Insert (buffer, " text"); - Insert (buffer, + buffer.InsertWithTagsByName (ref insertIter, "Font styles. ", "heading"); + buffer.Insert (ref insertIter, "For example, you can have "); + buffer.InsertWithTagsByName (ref insertIter, "italic", "italic"); + buffer.Insert (ref insertIter, ", "); + buffer.InsertWithTagsByName (ref insertIter, "bold", "bold"); + buffer.Insert (ref insertIter, ", or "); + buffer.InsertWithTagsByName (ref insertIter, "monospace (typewriter)", "monospace"); + buffer.Insert (ref insertIter, ", or "); + buffer.InsertWithTagsByName (ref insertIter, "big", "big"); + buffer.Insert (ref insertIter, " text"); + buffer.Insert (ref insertIter, "It's best not to hardcode specific text sizes; you can use relative sizes as with CSS, such as "); - InsertWithTagsByName (buffer, "xx-small", new string[] {"xx-small"}); - Insert (buffer, ", or"); - InsertWithTagsByName (buffer, "x-large", new string[] {"x-large"}); - Insert (buffer, + buffer.InsertWithTagsByName (ref insertIter, "xx-small", "xx-small"); + buffer.Insert (ref insertIter, ", or"); + buffer.InsertWithTagsByName (ref insertIter, "x-large", "x-large"); + buffer.Insert (ref insertIter, " to ensure that your program properly adapts if the user changes the default font size.\n\n"); - InsertWithTagsByName (buffer, "Colors such as", new string[] {"heading"}); - InsertWithTagsByName (buffer, "a blue foreground", new string[] {"blue_foreground"}); - Insert (buffer, ", or "); - InsertWithTagsByName (buffer, "a red background", new string[] {"red_background"}); - Insert (buffer, " or even "); - // Change InsertWithTagsByName to work with 2 and 3 args - // InsertWithTagsByName ("a stippled red background", - // "red_background", - // "background_stipple"); - //Insert (buffer, ", or "); - //InsertWithTagsByName ("a stippled red background", - // "a stippled blue foreground on solid red background", -1, - // "blue_foreground", - // "red_background", - // "foreground_stipple") - Insert (buffer, " (select that to read it) can be used.\n\n"); - InsertWithTagsByName (buffer, "Underline, strikethrough, and rise. ", new string[] {"heading"}); - InsertWithTagsByName (buffer, "Strikethrough", new string[] {"strikethrough"}); - Insert (buffer, ", "); - InsertWithTagsByName (buffer, "underline", new string[] {"underline"}); - Insert (buffer, ", "); - InsertWithTagsByName (buffer, "double_underline", new string[] {"double_underline"}); - Insert (buffer, ", "); - InsertWithTagsByName (buffer, "superscript", new string[] {"superscript"}); - Insert (buffer, ", and "); - InsertWithTagsByName (buffer, "subscript", new string[] {"subscript"}); - Insert (buffer," are all supported.\n\n"); - InsertWithTagsByName (buffer, "Images. ", new string[] {"heading"}); - Insert (buffer,"The buffer can have images in it: "); + buffer.InsertWithTagsByName (ref insertIter, "Colors such as", "heading"); + buffer.InsertWithTagsByName (ref insertIter, "a blue foreground", "blue_foreground"); + buffer.Insert (ref insertIter, ", or "); + buffer.InsertWithTagsByName (ref insertIter, "a red background", "red_background"); + buffer.Insert (ref insertIter, " or even "); + buffer.InsertWithTagsByName (ref insertIter, "a stippled red background", + "red_background", + "background_stipple"); + buffer.Insert (ref insertIter, ", or "); + buffer.InsertWithTagsByName (ref insertIter, + "a stippled blue foreground on solid red background", + "blue_foreground", + "red_background", + "foreground_stipple"); + buffer.Insert (ref insertIter, " (select that to read it) can be used.\n\n"); + buffer.InsertWithTagsByName (ref insertIter, "Underline, strikethrough, and rise. ", "heading"); + buffer.InsertWithTagsByName (ref insertIter, "Strikethrough", "strikethrough"); + buffer.Insert (ref insertIter, ", "); + buffer.InsertWithTagsByName (ref insertIter, "underline", "underline"); + buffer.Insert (ref insertIter, ", "); + buffer.InsertWithTagsByName (ref insertIter, "double_underline", "double_underline"); + buffer.Insert (ref insertIter, ", "); + buffer.InsertWithTagsByName (ref insertIter, "superscript", "superscript"); + buffer.Insert (ref insertIter, ", and "); + buffer.InsertWithTagsByName (ref insertIter, "subscript", "subscript"); + buffer.Insert (ref insertIter, " are all supported.\n\n"); + buffer.InsertWithTagsByName (ref insertIter, "Images. ", "heading"); + buffer.Insert (ref insertIter, "The buffer can have images in it: "); insertIter = buffer.GetIterAtMark (buffer.InsertMark); - buffer.InsertPixbuf (insertIter, pixbuf); + buffer.InsertPixbuf (ref insertIter, pixbuf); insertIter = buffer.GetIterAtMark (buffer.InsertMark); - buffer.InsertPixbuf (insertIter, pixbuf); + buffer.InsertPixbuf (ref insertIter, pixbuf); insertIter = buffer.GetIterAtMark (buffer.InsertMark); - buffer.InsertPixbuf (insertIter, pixbuf); + buffer.InsertPixbuf (ref insertIter, pixbuf); - Insert (buffer, " for example.\n\n"); - InsertWithTagsByName (buffer, "Spacing. ", new string[] {"heading"}); - InsertWithTagsByName (buffer, "You can adjust the amount of space before each line.\n", new string[] {"big_gap_before_line", "wide_margins"}); - InsertWithTagsByName (buffer, "You can also adjust the amount of space after each line; this line has a whole lot of space after it.\n", new string[] {"big_gap_after_line", "wide_margins"}); - InsertWithTagsByName (buffer, "You can also adjust the amount of space between wrapped lines; this line has extra space between each wrapped line in the same paragraph. To show off wrapping, some filler text: the quick brown fox jumped over the lazy dog. Blah blah blah blah blah blah blah blah blah.\n", new string[] {"double_spaced_line", "wide_margins"}); - Insert (buffer, "Also note that those lines have extra-wide margins.\n\n"); - InsertWithTagsByName (buffer, "Editability. ", new string[] {"heading"}); - InsertWithTagsByName (buffer, "This line is 'locked down' and can't be edited by the user - just try it! You can't delete this line.\n\n", new string[] {"not_editable"}); - InsertWithTagsByName (buffer, "Wrapping. ", new string[] {"heading"}); - Insert (buffer,"This line (and most of the others in this buffer) is word-wrapped, using the proper Unicode algorithm. Word wrap should work in all scripts and languages that GTK+ supports. Let's make this a long paragraph to demonstrate: blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah\n\n"); - InsertWithTagsByName (buffer, "This line has character-based wrapping, and can wrap between any two character glyphs. Let's make this a long paragraph to demonstrate: blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah\n\n", new string[] {"char_wrap"}); - InsertWithTagsByName (buffer, "This line has all wrapping turned off, so it makes the horizontal scrollbar appear.\n\n\n", new string[] {"no_wrap"}); - InsertWithTagsByName (buffer, "Justification. ", new string[] {"heading"}); - InsertWithTagsByName (buffer, "\nThis line has center justification.\n", new string[] {"center"}); - InsertWithTagsByName (buffer, "This line has right justification.\n", new string[] {"right_justify"}); - InsertWithTagsByName (buffer, "\nThis line has big wide margins. Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.\n", new string[] {"wide_margins"}); - InsertWithTagsByName (buffer, "Internationalization. ", new string[] {"heading"}); + buffer.Insert (ref insertIter, " for example.\n\n"); + buffer.InsertWithTagsByName (ref insertIter, "Spacing. ", "heading"); + buffer.InsertWithTagsByName (ref insertIter, "You can adjust the amount of space before each line.\n", "big_gap_before_line", "wide_margins"); + buffer.InsertWithTagsByName (ref insertIter, "You can also adjust the amount of space after each line; this line has a whole lot of space after it.\n", "big_gap_after_line", "wide_margins"); + buffer.InsertWithTagsByName (ref insertIter, "You can also adjust the amount of space between wrapped lines; this line has extra space between each wrapped line in the same paragraph. To show off wrapping, some filler text: the quick brown fox jumped over the lazy dog. Blah blah blah blah blah blah blah blah blah.\n", "double_spaced_line", "wide_margins"); + buffer.Insert (ref insertIter, "Also note that those lines have extra-wide margins.\n\n"); + buffer.InsertWithTagsByName (ref insertIter, "Editability. ", "heading"); + buffer.InsertWithTagsByName (ref insertIter, "This line is 'locked down' and can't be edited by the user - just try it! You can't delete this line.\n\n", "not_editable"); + buffer.InsertWithTagsByName (ref insertIter, "Wrapping. ", "heading"); + buffer.Insert (ref insertIter, "This line (and most of the others in this buffer) is word-wrapped, using the proper Unicode algorithm. Word wrap should work in all scripts and languages that GTK+ supports. Let's make this a long paragraph to demonstrate: blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah\n\n"); + buffer.InsertWithTagsByName (ref insertIter, "This line has character-based wrapping, and can wrap between any two character glyphs. Let's make this a long paragraph to demonstrate: blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah\n\n", "char_wrap"); + buffer.InsertWithTagsByName (ref insertIter, "This line has all wrapping turned off, so it makes the horizontal scrollbar appear.\n\n\n", "no_wrap"); + buffer.InsertWithTagsByName (ref insertIter, "Justification. ", "heading"); + buffer.InsertWithTagsByName (ref insertIter, "\nThis line has center justification.\n", "center"); + buffer.InsertWithTagsByName (ref insertIter, "This line has right justification.\n", "right_justify"); + buffer.InsertWithTagsByName (ref insertIter, "\nThis line has big wide margins. Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.\n", "wide_margins"); + buffer.InsertWithTagsByName (ref insertIter, "Internationalization. ", "heading"); - //Insert (buffer, "You can put all sorts of Unicode text in the buffer.\n\nGerman (Deutsch S\303\274d) Gr\303\274\303\237 Gott\nGreek (\316\225\316\273\316\273\316\267\316\275\316\271\316\272\316\254) \316\223\316\265\316\271\316\254 \317\203\316\261\317\202\nHebrew \327\251\327\234\327\225\327\235\nJapanese (\346\227\245\346\234\254\350\252\236)\n\nThe widget properly handles bidirectional text, word wrapping, DOS/UNIX/Unicode paragraph separators, grapheme boundaries, and so on using the Pango internationalization framework.\n"); - Insert (buffer, "Here's a word-wrapped quote in a right-to-left language:\n"); + buffer.Insert (ref insertIter, "You can put all sorts of Unicode text in the buffer.\n\nGerman (Deutsch S\u00fcd) Gr\u00fc\u00df Gott\nGreek (\u0395\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac) \u0393\u03b5\u03b9\u03ac \u03c3\u03b1\u03c2\nHebrew \u05e9\u05dc\u05d5\u05dd\nJapanese (\u65e5\u672c\u8a9e)\n\nThe widget properly handles bidirectional text, word wrapping, DOS/UNIX/Unicode paragraph separators, grapheme boundaries, and so on using the Pango internationalization framework.\n"); + buffer.Insert (ref insertIter, "Here's a word-wrapped quote in a right-to-left language:\n"); - //InsertWithTagsByName (buffer, "\331\210\331\202\330\257 \330\250\330\257\330\243 \330\253\331\204\330\247\330\253 \331\205\331\206 \330\243\331\203\330\253\330\261 \330\247\331\204\331\205\330\244\330\263\330\263\330\247\330\252 \330\252\331\202\330\257\331\205\330\247 \331\201\331\212 \330\264\330\250\331\203\330\251 \330\247\331\203\330\263\331\212\331\210\331\206 \330\250\330\261\330\247\331\205\330\254\331\207\330\247 \331\203\331\205\331\206\330\270\331\205\330\247\330\252 \331\204\330\247 \330\252\330\263\330\271\331\211 \331\204\331\204\330\261\330\250\330\255\330\214 \330\253\331\205 \330\252\330\255\331\210\331\204\330\252 \331\201\331\212 \330\247\331\204\330\263\331\206\331\210\330\247\330\252 \330\247\331\204\330\256\331\205\330\263 \330\247\331\204\331\205\330\247\330\266\331\212\330\251 \330\245\331\204\331\211 \331\205\330\244\330\263\330\263\330\247\330\252 \331\205\330\247\331\204\331\212\330\251 \331\205\331\206\330\270\331\205\330\251\330\214 \331\210\330\250\330\247\330\252\330\252 \330\254\330\262\330\241\330\247 \331\205\331\206 \330\247\331\204\331\206\330\270\330\247\331\205 \330\247\331\204\331\205\330\247\331\204\331\212 \331\201\331\212 \330\250\331\204\330\257\330\247\331\206\331\207\330\247\330\214 \331\210\331\204\331\203\331\206\331\207\330\247 \330\252\330\252\330\256\330\265\330\265 \331\201\331\212 \330\256\330\257\331\205\330\251 \331\202\330\267\330\247\330\271 \330\247\331\204\331\205\330\264\330\261\331\210\330\271\330\247\330\252 \330\247\331\204\330\265\330\272\331\212\330\261\330\251. \331\210\330\243\330\255\330\257 \330\243\331\203\330\253\330\261 \331\207\330\260\331\207 \330\247\331\204\331\205\330\244\330\263\330\263\330\247\330\252 \331\206\330\254\330\247\330\255\330\247 \331\207\331\210 \302\273\330\250\330\247\331\206\331\203\331\210\330\263\331\210\331\204\302\253 \331\201\331\212 \330\250\331\210\331\204\331\212\331\201\331\212\330\247.\n\n", new string[] {"rtl_quote"}); - //InsertWithTagsByName (buffer, "\x2", new string[] {"rtl_quote"}); - Insert (buffer, "You can put widgets in the buffer: Here's a button: "); + buffer.InsertWithTagsByName (ref insertIter, "\u0648\u0642\u062f \u0628\u062f\u0623 \u062b\u0644\u0627\u062b \u0645\u0646 \u0623\u0643\u062b\u0631 \u0627\u0644\u0645\u0624\u0633\u0633\u0627\u062a \u062a\u0642\u062f\u0645\u0627 \u0641\u064a \u0634\u0628\u0643\u0629 \u0627\u0643\u0633\u064a\u0648\u0646 \u0628\u0631\u0627\u0645\u062c\u0647\u0627 \u0643\u0645\u0646\u0638\u0645\u0627\u062a \u0644\u0627 \u062a\u0633\u0639\u0649 \u0644\u0644\u0631\u0628\u062d\u060c \u062b\u0645 \u062a\u062d\u0648\u0644\u062a \u0641\u064a \u0627\u0644\u0633\u0646\u0648\u0627\u062a \u0627\u0644\u062e\u0645\u0633 \u0627\u0644\u0645\u0627\u0636\u064a\u0629 \u0625\u0644\u0649 \u0645\u0624\u0633\u0633\u0627\u062a \u0645\u0627\u0644\u064a\u0629 \u0645\u0646\u0638\u0645\u0629\u060c \u0648\u0628\u0627\u062a\u062a \u062c\u0632\u0621\u0627 \u0645\u0646 \u0627\u0644\u0646\u0638\u0627\u0645 \u0627\u0644\u0645\u0627\u0644\u064a \u0641\u064a \u0628\u0644\u062f\u0627\u0646\u0647\u0627\u060c \u0648\u0644\u0643\u0646\u0647\u0627 \u062a\u062a\u062e\u0635\u0635 \u0641\u064a \u062e\u062f\u0645\u0629 \u0642\u0637\u0627\u0639 \u0627\u0644\u0645\u0634\u0631\u0648\u0639\u0627\u062a \u0627\u0644\u0635\u063a\u064a\u0631\u0629\u002e \u0648\u0623\u062d\u062f \u0623\u0643\u062b\u0631 \u0647\u0630\u0647 \u0627\u0644\u0645\u0624\u0633\u0633\u0627\u062a \u0646\u062c\u0627\u062d\u0627 \u0647\u0648 \u00bb\u0628\u0627\u0646\u0643\u0648\u0633\u0648\u0644\u00ab \u0641\u064a \u0628\u0648\u0644\u064a\u0641\u064a\u0627.\n\n", "rtl_quote"); + + buffer.Insert (ref insertIter, "You can put widgets in the buffer: Here's a button: "); insertIter = buffer.GetIterAtMark(buffer.InsertMark); - buttonAnchor = buffer.CreateChildAnchor (insertIter); + buttonAnchor = buffer.CreateChildAnchor (ref insertIter); - Insert (buffer, "and a menu"); + buffer.Insert (ref insertIter, "and a menu"); insertIter = buffer.GetIterAtMark(buffer.InsertMark); - menuAnchor = buffer.CreateChildAnchor (insertIter); + menuAnchor = buffer.CreateChildAnchor (ref insertIter); - Insert (buffer, "and a scale"); + buffer.Insert (ref insertIter, "and a scale"); insertIter = buffer.GetIterAtMark(buffer.InsertMark); - scaleAnchor = buffer.CreateChildAnchor (insertIter); + scaleAnchor = buffer.CreateChildAnchor (ref insertIter); - Insert (buffer, "and an animation"); + buffer.Insert (ref insertIter, "and an animation"); insertIter = buffer.GetIterAtMark(buffer.InsertMark); - animationAnchor = buffer.CreateChildAnchor (insertIter); + animationAnchor = buffer.CreateChildAnchor (ref insertIter); - Insert (buffer, " finally a text entry: "); + buffer.Insert (ref insertIter, " finally a text entry: "); insertIter = buffer.GetIterAtMark(buffer.InsertMark); - entryAnchor = buffer.CreateChildAnchor (insertIter); + entryAnchor = buffer.CreateChildAnchor (ref insertIter); - Insert (buffer, "\n"); + buffer.Insert (ref insertIter, "\n"); - Insert (buffer, "\n\nThis demo doesn't demonstrate all the GtkTextBuffer features; it leaves out, for example: invisible/hidden text (doesn't work in GTK 2, but planned), tab stops, application-drawn areas on the sides of the widget for displaying breakpoints and such..."); - //Insert (buffer,); - //InsertWithTagsByName (buffer, , new string[] {}); + buffer.Insert (ref insertIter, "\n\nThis demo doesn't demonstrate all the GtkTextBuffer features; it leaves out, for example: invisible/hidden text (doesn't work in GTK 2, but planned), tab stops, application-drawn areas on the sides of the widget for displaying breakpoints and such..."); buffer.ApplyTag("word_wrap", buffer.StartIter, buffer.EndIter); } - private void InsertWithTagsByName (TextBuffer buffer , string insertText, string[] fontName) - { - TextIter insertIter, beginIter, endIter; - int begin, end; - - begin = buffer.CharCount; - insertIter = buffer.GetIterAtMark(buffer.InsertMark); - buffer.Insert (insertIter, insertText); - end = buffer.CharCount; - foreach (string fontItem in fontName) { - endIter = buffer.GetIterAtOffset (end); - beginIter = buffer.GetIterAtOffset (begin); - buffer.ApplyTag (fontItem, beginIter, endIter); - } - } - - private void Insert (TextBuffer buffer , string insertText) - { - TextIter insertIter; - insertIter = buffer.GetIterAtMark (buffer.InsertMark); - buffer.Insert (insertIter, insertText); - } - private void WindowDelete (object o, DeleteEventArgs args) { this.Hide (); @@ -431,10 +405,10 @@ namespace GtkDemo TextIter insertIter; TextBuffer bufferCB = new TextBuffer (null); - Insert (bufferCB, "This buffer is shared by a set of nested text views.\n Nested view:\n"); - insertIter = bufferCB.GetIterAtMark(bufferCB.InsertMark); - TextChildAnchor anchor = bufferCB.CreateChildAnchor (insertIter); - Insert (bufferCB, "\nDon't do this in real applications, please.\n"); + insertIter = bufferCB.GetIterAtOffset (0); + bufferCB.Insert (ref insertIter, "This buffer is shared by a set of nested text views.\n Nested view:\n"); + TextChildAnchor anchor = bufferCB.CreateChildAnchor (ref insertIter); + bufferCB.Insert (ref insertIter, "\nDon't do this in real applications, please.\n"); TextView viewCB = new TextView (bufferCB); RecursiveAttach (0, viewCB, anchor);