Re: how to justify text in a GtkTextView



I have attached a snapshot of your test program. Looks centered to me. I'm using Gtk 2.4.10.

Boncek, John wrote:

I don't know what that could be.  This is a very simple trial program, to
put a GtkTextView in a scrolled window with justification.

My version of GTK is 2.2.4, as listed by pkg-config.

Here's the entire program, some of which was pieced together from various
online examples:

#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>


int main( int   argc,
         char *argv[] )
{

   GtkWidget *window;
   GtkWidget *vbox;
   GtkWidget *button;

   gtk_init (&argc, &argv);

   // create a new window
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_widget_set_size_request (GTK_WIDGET (window), 300, 300);
   gtk_window_set_title (GTK_WINDOW (window), "GTK Text View");
   g_signal_connect (G_OBJECT (window), "destroy",
                     G_CALLBACK (gtk_main_quit), NULL);
   g_signal_connect_swapped (G_OBJECT (window), "delete_event",
G_CALLBACK (gtk_widget_destroy), G_OBJECT (window));

        // create VBox
   vbox = gtk_vbox_new (FALSE, 0);
   gtk_container_add (GTK_CONTAINER (window), vbox);
   gtk_widget_show (vbox);

        /* create a new scrolled window. */
        GtkWidget *             scrolled_window         =
gtk_scrolled_window_new (NULL, NULL);
        /* the policy is one of GTK_POLICY AUTOMATIC, or
GTK_POLICY_ALWAYS.
        * GTK_POLICY_AUTOMATIC will automatically decide whether you need
        * scrollbars, whereas GTK_POLICY_ALWAYS will always leave the
scrollbars
        * there. The first one is the horizontal scrollbar, the second,
        * the vertical. */
        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW
(scrolled_window),
        
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
        gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE,
0);
   gtk_widget_show (scrolled_window);

        // create TextView
        GtkTextView *           view;
        GtkTextBuffer *         buffer;
        view = GTK_TEXT_VIEW(gtk_text_view_new());
        buffer = gtk_text_view_get_buffer(view);
        gtk_text_view_set_justification (view, GTK_JUSTIFY_CENTER);
        gtk_text_buffer_set_text (buffer, "some initial text", -1);
        
//      GtkTextIter             start;
//      GtkTextIter             end;
//
//      gtk_text_buffer_get_start_iter(buffer, &(start));
//      gtk_text_buffer_get_end_iter(buffer, &(end));
//      gtk_text_buffer_remove_all_tags (buffer, &(start), &(end));

        gtk_container_add(GTK_CONTAINER (scrolled_window), (GtkWidget
*)(view)); gtk_widget_show((GtkWidget *)(view));

        // create Close button
   button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
   g_signal_connect_swapped (G_OBJECT (button), "clicked",
                              G_CALLBACK (gtk_widget_destroy),
                              G_OBJECT (window));
   gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
   GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
   gtk_widget_grab_default (button);
   gtk_widget_show (button);
gtk_widget_show (window);

   gtk_main();

   return 0;
}

-----Original Message-----
From: Paolo Costabel [mailto:paolo zebradevelopment com]
Sent: Monday, January 31, 2005 5:42 PM
To: Boncek, John
Cc: gtk-app-devel-list gnome org
Subject: Re: how to justify text in a GtkTextView


Hmm, works fine here. Are you doing something after insterting the text that could affect the justification?

Boncek, John wrote:

Thanks for your suggestion, which I just tried.  No difference.

-----Original Message-----
From: Paolo Costabel [mailto:paolo zebradevelopment com]
Sent: Monday, January 31, 2005 4:10 PM
To: Boncek, John
Cc: gtk-app-devel-list gnome org
Subject: Re: how to justify text in a GtkTextView


Do

gtk_text_buffer_set_text

after
gtk_text_view_set_justification

Boncek, John wrote:



I can't get text justification to work.  Am I missing something?  Here
is
a code snippet:

        // create TextView
        GtkTextView *           view;
        GtkTextBuffer *         buffer;
        view = GTK_TEXT_VIEW(gtk_text_view_new());
        buffer = gtk_text_view_get_buffer(view);
        gtk_text_buffer_set_text (buffer, "some initial text", -1);
        
//      GtkTextIter             start;
//      GtkTextIter             end;
//
//      gtk_text_buffer_get_start_iter(buffer, &(start));
//      gtk_text_buffer_get_end_iter(buffer, &(end));
//      gtk_text_buffer_remove_all_tags (buffer, &(start), &(end));
        gtk_text_view_set_justification (view, GTK_JUSTIFY_CENTER);

The text window appears, displays the initial text, and accepts keyboard
input, etc.  But it comes up left-justified regardless.  I tried
GTK_JUSTIFY_RIGHT also.  I also tried turning off any tags in case any
tags are created by default, as indicated in the currently-commented
section, since the documentation says the justification can be
overridden
by a tag.
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list










[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]