⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 textwidget.html

📁 最新gtk中文资料集
💻 HTML
📖 第 1 页 / 共 2 页
字号:
</p><p>Because of this, iterators can't be used to preserve positions across buffermodifications. To preserve a position, the <a class="link" href="GtkTextMark.html" title="GtkTextMark"><span class="type">GtkTextMark</span></a> object is ideal. Youcan think of a mark as an invisible cursor or insertion point; it floats in the buffer, saving a position. If the text surrounding the mark is deleted, the mark remains in the position the text once occupied; if text is inserted at the mark, the mark ends up either to the left or to the right of the new text, depending on its <em class="firstterm">gravity</em>. The standard text cursor in left-to-right languages is a mark with right gravity, because it stays to the right of inserted text.</p><p>Like tags, marks can be either named or anonymous. There are two marks built-into <a class="link" href="GtkTextBuffer.html" title="GtkTextBuffer"><span class="type">GtkTextBuffer</span></a>; these are named <code class="literal">"insert"</code> and <code class="literal">"selection_bound"</code> and refer to the insertion point and the boundary of the selection which is not the insertion point, respectively. If no text is selected, these two marks will be in the same position. You can manipulate what is selected and where the cursor appears by moving these marks around.<sup>[<a name="id3561876" href="#ftn.id3561876" class="footnote">2</a>]</sup></p><p>Text buffers always contain at least one line, but may be empty (thatis, buffers can contain zero characters). The last line in the textbuffer never ends in a line separator (such as newline); the otherlines in the buffer always end in a line separator. Line separatorscount as characters when computing character counts and characteroffsets. Note that some Unicode line separators are represented with multiple bytes in UTF-8, and the two-character sequence "\r\n" is alsoconsidered a line separator.</p></div><div class="refsect1" lang="en"><a name="id3561913"></a><h2>Simple Example</h2><p>The simplest usage of <a class="link" href="GtkTextView.html" title="GtkTextView"><span class="type">GtkTextView</span></a>  might look like this:</p><div class="informalexample"><pre class="programlisting">  GtkWidget *view;  GtkTextBuffer *buffer;  view = gtk_text_view_new ();  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));  gtk_text_buffer_set_text (buffer, "Hello, this is some text", -1);  /* Now you might put the view in a container and display it on the   * screen; when the user edits the text, signals on the buffer   * will be emitted, such as "changed", "insert_text", and so on.   */</pre></div><p>In many cases it's also convenient to first create the buffer with <a class="link" href="GtkTextBuffer.html#gtk-text-buffer-new"><code class="function">gtk_text_buffer_new()</code></a>, then create a widget for that buffer with <a class="link" href="GtkTextView.html#gtk-text-view-new-with-buffer"><code class="function">gtk_text_view_new_with_buffer()</code></a>. Or you can change the buffer the widget displays after the widget is created with <a class="link" href="GtkTextView.html#gtk-text-view-set-buffer"><code class="function">gtk_text_view_set_buffer()</code></a>.</p></div><div class="refsect1" lang="en"><a name="id3561988"></a><h2>Example of Changing Text Attributes</h2><p>There are two ways to affect text attributes in <a class="link" href="GtkTextView.html" title="GtkTextView"><span class="type">GtkTextView</span></a>.You can change the default attributes for a given <a class="link" href="GtkTextView.html" title="GtkTextView"><span class="type">GtkTextView</span></a>, and you can apply tags that change the attributes for a region of text.  For text features that come from the theme &#8212; such as font and foreground color &#8212; use standard <a class="link" href="GtkWidget.html" title="GtkWidget"><span class="type">GtkWidget</span></a> functions such as <a class="link" href="GtkWidget.html#gtk-widget-modify-font"><code class="function">gtk_widget_modify_font()</code></a> or <a class="link" href="GtkWidget.html#gtk-widget-modify-text"><code class="function">gtk_widget_modify_text()</code></a>. For other attributes there are dedicated methods on <a class="link" href="GtkTextView.html" title="GtkTextView"><span class="type">GtkTextView</span></a> such as <a class="link" href="GtkTextView.html#gtk-text-view-set-tabs"><code class="function">gtk_text_view_set_tabs()</code></a>.</p><div class="informalexample"><pre class="programlisting">  GtkWidget *view;  GtkTextBuffer *buffer;  GtkTextIter start, end;  PangoFontDescription *font_desc;  GdkColor color;  GtkTextTag *tag;  view = gtk_text_view_new ();  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));  gtk_text_buffer_set_text (buffer, "Hello, this is some text", -1);  /* Change default font throughout the widget */  font_desc = pango_font_description_from_string ("Serif 15");  gtk_widget_modify_font (view, font_desc);  pango_font_description_free (font_desc);  /* Change default color throughout the widget */  gdk_color_parse ("green", &amp;color);  gtk_widget_modify_text (view, GTK_STATE_NORMAL, &amp;color);  /* Change left margin throughout the widget */  gtk_text_view_set_left_margin (GTK_TEXT_VIEW (view), 30);  /* Use a tag to change the color for just one part of the widget */  tag = gtk_text_buffer_create_tag (buffer, "blue_foreground",	   		            "foreground", "blue", NULL);    gtk_text_buffer_get_iter_at_offset (buffer, &amp;start, 7);  gtk_text_buffer_get_iter_at_offset (buffer, &amp;end, 12);  gtk_text_buffer_apply_tag (buffer, tag, &amp;start, &amp;end);</pre></div><p></p><p>The <span class="application">gtk-demo</span> application that comes withGTK+ contains more example code for <a class="link" href="GtkTextView.html" title="GtkTextView"><span class="type">GtkTextView</span></a>.</p></div><div class="footnotes"><br><hr width="100" align="left"><div class="footnote"><p><sup>[<a name="ftn.id3561876" href="#id3561876" class="para">2</a>] </sup>If you want to place the cursor in response to a user action, be sure to use<a class="link" href="GtkTextBuffer.html#gtk-text-buffer-place-cursor"><code class="function">gtk_text_buffer_place_cursor()</code></a>, which moves both at once without causing a temporary selection (moving one then the other temporarily selects the range in between the old and new positions).</p></div></div></div></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -