File: tutorial-advanced.html

package info (click to toggle)
gtkspell3 3.0.6-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,232 kB
  • ctags: 389
  • sloc: sh: 11,590; ansic: 1,480; makefile: 183
file content (92 lines) | stat: -rw-r--r-- 4,269 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>GtkSpell Reference Manual: Advanced usage</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="index.html" title="GtkSpell Reference Manual">
<link rel="up" href="chapter-tutorial.html" title="GtkSpell Tutorial">
<link rel="prev" href="tutorial-lang.html" title="Error checking">
<link rel="next" href="tutorial-building.html" title="Building a program using GtkSpell">
<meta name="generator" content="GTK-Doc V1.20 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="10"><tr valign="middle">
<td width="100%" align="left" class="shortcuts"></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
<td><a accesskey="u" href="chapter-tutorial.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td>
<td><a accesskey="p" href="tutorial-lang.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
<td><a accesskey="n" href="tutorial-building.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
</tr></table>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="tutorial-advanced"></a>Advanced usage</h2></div></div></div>
<p>
For convenience, <code class="function">gtk_spell_checker_new()</code> is created as
<code class="classname">GInitiallyUnowned</code> and
<code class="function">gtk_spell_checker_attach()</code> will sink the floating
reference. <code class="function">gtk_spell_checker_attach()</code> also connects the
<code class="literal">destroy</code> signal of the passed-in
<code class="classname">GObject</code> to <code class="function">g_object_unref()</code> the
<code class="classname">GtkSpellChecker</code>, so in the most common use-case, you
need not worry about cleaning it up.

However, if you want to detach and later reattach the
<code class="classname">GtkSpellChecker</code> to a (possibly different)
<code class="classname">GtkTextView</code>, you must get a pointer to it with
<code class="function">gtk_spell_checker_get_from_text_view()</code>, call
<code class="function">g_object_ref()</code> on the resulting pointer, call
<code class="function">gtk_spell_checker_detach()</code> on it, call
<code class="function">gtk_spell_checker_attach()</code> with the new
<code class="classname">GtkTextView</code>, and finally call
<code class="function">g_object_unref()</code> to release the reference that you took at
the beginning, like this:
</p>
<pre class="programlisting">
GtkTextView* view = gtk_text_view_new ();
GtkSpellChecker* spell = gtk_spell_checker_new ();
gtk_spell_checker_set_language (spell, "en_US", NULL);
gtk_spell_checker_attach (GTK_TEXT_VIEW (view));
/* ... */
// Detach
g_object_ref (spell);
gtk_spell_checker_detach (spell);
/* ... */
// Reattach
gtk_spell_checker_attach (spell, GTK_TEXT_VIEW (view));
g_object_unref (spell);
</pre>
<p>

Alternatively, you can sink the <code class="classname">GtkSpellChecker</code>
immediately upon construction with <code class="function">g_object_ref_sink()</code>,
in which case you will retain the ownership of the
<code class="classname">GtkSpellChecker</code> throughout the lifetime of the program,
and you must remember to call <code class="function">g_object_unref()</code> when you
don't need it any more, like this:
</p>
<pre class="programlisting">
GtkTextView* view = gtk_text_view_new ();
GtkSpellChecker* spell = gtk_spell_checker_new ();
g_object_ref_sink (spell);
gtk_spell_checker_set_language (spell, "en_US", NULL);
gtk_spell_checker_attach (GTK_TEXT_VIEW (view));
/* ... */
// Detach
gtk_spell_checker_detach (spell);
/* ... */
// Reattach
gtk_spell_checker_attach (spell, GTK_TEXT_VIEW (view));
/* ... */
// End of life time
g_object_unref (spell);
</pre>
<p>
</p>
</div>
<div class="footer">
<hr>
          Generated by GTK-Doc V1.20</div>
</body>
</html>