Re: [Pango] Calls to Pango::Layout without effect



Matthias Kaeppler wrote:

Hi there,

I have been trying for hours now, but I can't figure out how to use a Pango::Layout to ellipsize a long-winded filename. I looked at the Nautilus source code, and tried to reproduce each step using the pangomm equivalents, but still, no luck.

I am trying to do this in a dialog. Here is my code so far:

TransferOverwriteDialog::TransferOverwriteDialog(const Glib::ustring& filename)
    : Gtk::MessageDialog(
    MainWindow::instance(),
    "foo", // overwritten in body
    true, // use markup
    Gtk::MESSAGE_QUESTION,
    Gtk::BUTTONS_NONE,
    true), // modal
      check_button_(LABEL_REMEMBER_CHOICE),
      remember_choice_(false)
{
    using sigc::mem_fun;
    using namespace Pango;

    typedef Glib::RefPtr<Context> PangoContextPtr;
    typedef Glib::RefPtr<Layout>  PangoLayoutPtr;

    PangoContextPtr pango_context = get_pango_context();
    PangoLayoutPtr  pango_layout  = create_pango_layout(filename);

    pango_layout->set_single_paragraph_mode();
    pango_layout->set_ellipsize(ELLIPSIZE_END);

    Glib::ustring header_text =
    DIALOG_HEADER_XFER_OVERWRITE + pango_layout->get_text();

    set_markup(header_text);
    set_secondary_text(DIALOG_BODY_XFER_OVERWRITE);

    // <snip irrelevant stuff>
}

The text in the 'filename'-object will not get ellipsized, but just printed as is. I noticed that /nothing/ I apply to the layout text will get recognized. For example, I tried to replace 'filename' with some custom marked-up text, i.e. "<i>this is some italic test text</i>" and tried to render that, but again, the text is displayed as plain text (no italics).

On top of that, calls to set_width() seem to be ignored, too. Regardless what I set there, it has no effect whatsoever.

It looks as if every call I make to pango_layout doesn't have any effect. Any ideas what is wrong with my code?

Thanks in advance,
Matthias Kaeppler

_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Hey Matt:

I may be all wet here, but because the MessageDialog displays a lot of things such as a graphic indicating the type of MessageDialog, a separator bar graphic, a couple of buttons (at least) along with the message it displays, I'd say that the pango context (which you don't seem to be using) you're getting is *not* for the child widget that displays the message in the MessageDialog window. I'd also say that get a pango layout pointer you are creating using the Glib::ustring that you're passing to the constructor function is not going to affect the way the MessageDialog ultimately displays it. I believe that there is a child widget that displays that text, and it will probably have its own pango layout; hence, maybe you could somehow use Gtk::Container::get_children() and parse that list to find the GtkLabel that is ultimately displaying the message. Again, I'm guessing based on my cursory perusal of the MessageDialog header and source files for gtkmm-2.6.2.

Oh yeah, the Gtk::MessageDialog::set_secondary_text method has a second parameter that defaults to turning the use of markup text off.

Bob Caryl






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