Re: Pango text in a dialog



On Thu, 19 Feb 2004, Chris Hoefler wrote:

Well, a pango layout isn't a widget, so you can't pack it directly into
a container. Use gtk_paint_layout (GtkStyle).

So you have to render the layout.  Sounds good.  Taking that approach,
here's the test case I tried (rendering the layout into an hbox):

=== begin code snippet ===

   GtkWidget *dialog;
   gint button;
   PangoLayout *layout;
   GtkWidget *ptrh;
   GtkStyle *style;
   gint width, height;
   GdkRectangle gdk_rectangle;
   gchar text[] = "<span b>Test</span> case";

[snip]

/* get an hbox and attach to it a copy of the drawing area's style */

   ptrh = gtk_hbox_new (TRUE, 2);
   style = gtk_style_copy (drawing_area->style);
   style = gtk_style_attach (style, ptrh->window);

/* get the pango layout for the desired text */

   layout = gtk_widget_create_pango_layout (
               ptrh,
               text);

/* get the rectangular area needed by gtk_paint_layout */

   pango_layout_get_pixel_size (layout, &width, &height);
   gdk_rectangle.x = 0;
   gdk_rectangle.y = 0;
   gdk_rectangle.x = width;
   gdk_rectangle.x = height;

/* paint the layout into the hbox */

   gtk_paint_layout (
      ptrh->style,
      ptrh->window,
      GTK_STATE_NORMAL,
      TRUE,
      &gdk_rectangle,
      ptrh,
      "detail",
      0,0,
      layout);

   gtk_widget_show (ptrh);

/* pack the hbox into the dialog's vbox and run the dialog */

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

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

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

[snip]


=== end code snippet ===

Well, when the dialog runs its vbox is empty...all that comes up is the OK
button in the action area.  Expanding the dialog window confirms that the
vbox is indeed empty, and debug printf's confirm that the size of the text
in the layout (the width and height above) are as expected.

What am I doing wrong now?  Where should I render the layout if not into
an hbox?

Thanks for your help and patience...sure wish I could find good
documentation on this process.

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]