|
Packit |
1470ea |
|
|
Packit |
1470ea |
<page xmlns="http://projectmallard.org/1.0/" xmlns:its="http://www.w3.org/2005/11/its" xmlns:xi="http://www.w3.org/2001/XInclude" type="guide" style="task" id="textview.c" xml:lang="fr">
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<title type="text">TextView (C)</title>
|
|
Packit |
1470ea |
<link type="guide" xref="c#multiline"/>
|
|
Packit |
1470ea |
<revision version="0.1" date="2012-07-10" status="draft"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<credit type="author copyright">
|
|
Packit |
1470ea |
<name>Monica Kochofar</name>
|
|
Packit |
1470ea |
<email its:translate="no">monicakochofar@gmail.com</email>
|
|
Packit |
1470ea |
<years>2012</years>
|
|
Packit |
1470ea |
</credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<desc>L'élément graphique qui affiche un GtkTextBuffer</desc>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Luc Rebert,</mal:name>
|
|
Packit |
1470ea |
<mal:email>traduc@rebert.name</mal:email>
|
|
Packit |
1470ea |
<mal:years>2011</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Alain Lojewski,</mal:name>
|
|
Packit |
1470ea |
<mal:email>allomervan@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2011-2012</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Luc Pionchon</mal:name>
|
|
Packit |
1470ea |
<mal:email>pionchon.luc@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2011</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Bruno Brouard</mal:name>
|
|
Packit |
1470ea |
<mal:email>annoa.b@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2011-12</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Luis Menina</mal:name>
|
|
Packit |
1470ea |
<mal:email>liberforce@freeside.fr</mal:email>
|
|
Packit |
1470ea |
<mal:years>2014</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
</info>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<title>Élément graphique TextView</title>
|
|
Packit |
1470ea |
<note style="sidebar">En appuyant sur « Entrée », nous créons une nouvelle ligne.
|
|
Packit |
1470ea |
En appuyant encore de nombreuses fois sur « Entrée », d'autres lignes sont créées dans la fenêtre de taille par défaut, puis une barre de défilement verticale apparaît.
|
|
Packit |
1470ea |
Si nous écrivons une longue phrase, la césure se fait entre deux mots.
|
|
Packit |
1470ea |
Si nous avons un loooooooooooooooooooooooooooooooooooong mot, une barre de défilement horizontale apparaît. </note>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/textview.png"/>
|
|
Packit |
1470ea |
Ceci est un exemple de Gtk.TextView
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
#include <gtk/gtk.h>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
static void
|
|
Packit |
1470ea |
activate (GtkApplication *app,
|
|
Packit |
1470ea |
gpointer user_data)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
/* Declare variables */
|
|
Packit |
1470ea |
GtkWidget *window;
|
|
Packit |
1470ea |
GtkWidget *text_view;
|
|
Packit |
1470ea |
GtkWidget *scrolled_window;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
GtkTextBuffer *buffer;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Create a window with a title, and a default size */
|
|
Packit |
1470ea |
window = gtk_application_window_new (app);
|
|
Packit |
1470ea |
gtk_window_set_title (GTK_WINDOW (window), "TextView Example");
|
|
Packit |
1470ea |
gtk_window_set_default_size (GTK_WINDOW (window), 220, 200);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* The text buffer represents the text being edited */
|
|
Packit |
1470ea |
buffer = gtk_text_buffer_new (NULL);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Text view is a widget in which can display the text buffer.
|
|
Packit |
1470ea |
* The line wrapping is set to break lines in between words.
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
text_view = gtk_text_view_new_with_buffer (buffer);
|
|
Packit |
1470ea |
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view), GTK_WRAP_WORD);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Create the scrolled window. Usually NULL is passed for both parameters so
|
|
Packit |
1470ea |
* that it creates the horizontal/vertical adjustments automatically. Setting
|
|
Packit |
1470ea |
* the scrollbar policy to automatic allows the scrollbars to only show up
|
|
Packit |
1470ea |
* when needed.
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
|
Packit |
1470ea |
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
|
|
Packit |
1470ea |
GTK_POLICY_AUTOMATIC,
|
|
Packit |
1470ea |
GTK_POLICY_AUTOMATIC);
|
|
Packit |
1470ea |
/* The function directly below is used to add children to the scrolled window
|
|
Packit |
1470ea |
* with scrolling capabilities (e.g text_view), otherwise,
|
|
Packit |
1470ea |
* gtk_scrolled_window_add_with_viewport() would have been used
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
gtk_container_add (GTK_CONTAINER (scrolled_window),
|
|
Packit |
1470ea |
text_view);
|
|
Packit |
1470ea |
gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 5);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
gtk_container_add (GTK_CONTAINER (window), scrolled_window);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
gtk_widget_show_all (window);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
int
|
|
Packit |
1470ea |
main (int argc, char **argv)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
GtkApplication *app;
|
|
Packit |
1470ea |
int status;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
|
|
Packit |
1470ea |
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
|
|
Packit |
1470ea |
status = g_application_run (G_APPLICATION (app), argc, argv);
|
|
Packit |
1470ea |
g_object_unref (app);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
return status;
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
Dans cet exemple, les éléments suivants sont utilisés :
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/3.4/GtkApplication.html">GtkApplication</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/3.4/GtkWindow.html">GtkWindow</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/stable/GtkTextBuffer.html">GtkTextBuffer</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/stable/GtkTextView.html">GtkTextView</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/stable/GtkScrolledWindow.html">GtkScrolledWindow</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/stable/GtkContainer.html">GtkContainer</link> </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</page>
|