Blame platform-demos/de/textview.c.page

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="de">
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>Widget which displays a GtkTextBuffer</desc>
Packit 1470ea
  
Packit 1470ea
    <mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
Packit 1470ea
      <mal:name>Mario Blättermann</mal:name>
Packit 1470ea
      <mal:email>mario.blaettermann@gmail.com</mal:email>
Packit 1470ea
      <mal:years>2011, 2013</mal:years>
Packit 1470ea
    </mal:credit>
Packit 1470ea
  </info>
Packit 1470ea
Packit 1470ea
  <title>TextView-Widget</title>
Packit 1470ea
<note style="sidebar">

If we press "enter", we have a new line.

Packit 1470ea
     

If we press "enter" more times then there are lines in the default sized window, then a vertical scrollbar appears.

Packit 1470ea
     

If we write a long sentence, the text will wrap breaking lines between words.

Packit 1470ea
     

If we have a loooooooooooooooooooooooooooooooooooong (that was long) word, a* horizontal scrollbar will appear.

</note>
Packit 1470ea
Packit 1470ea
  <media type="image" mime="image/png" src="media/textview.png"/>
Packit 1470ea
    

This is an example of 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

Packit 1470ea
  In this sample we used the following:
Packit 1470ea

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>