Pango text in a dialog



Hello,

Another part of the application I'm porting from gtk 1.2 to gtk 2.x
involves displaying multiple paragraphs of text in a dialog attached to a
drawing area.  This looks like another good place to use pango and its
markup capabilities.  Here's a sample code fragment that tries to display
one pango-marked-up paragraph:

=== begin code fragment ===

   GtkWidget *dialog;
   gint button;
   PangoLayout *layout;
   GtkWidget *ptrh;
   gchar text[] = "<span b>Item 1</span>:  text for item 1";

   [snip]

   dialog = gtk_dialog_new_with_buttons (
               title,
               main_window,
               GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
               GTK_STOCK_OK,
               GTK_RESPONSE_ACCEPT,
               NULL);

/* put the sample text into a new pango layout */

   layout = gtk_widget_create_pango_layout (
               drawing_area,
               text);
   gtk_widget_show ((GtkWidget *) layout);

/* pack the layout into an hbox, then pack that hbox into the dialog's
vbox */

   ptrh = gtk_hbox_new (TRUE, 2);
   gtk_box_pack_start (GTK_BOX (ptrh),
      (GtkWidget *) layout,
      TRUE, TRUE, 2);

   gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
      ptrh,
      TRUE, TRUE, 2);
   g_object_unref(layout);

   button = gtk_dialog_run (GTK_DIALOG (dialog));
   gtk_widget_destroy (dialog);

   [snip]

=== end code fragment ===

Well, the only thing displayed is the OK button.  Clearly I'm missing
something.

So, how does one put one or more pango layouts into a dialog vbox?

Or does one need to render the layout(s) and then put the rendered thingy
into the vbox?  How do you do that?

Thanks,

Bryan


*---------------------------------------------------------------
* Bryan Brown      <*>              bbrown radix net
* http://www.radix.net/~bbrown
*---------------------------------------------------------------





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