|
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 |
}
|