diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/FbTk/FbWindow.cc | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/src/FbTk/FbWindow.cc b/src/FbTk/FbWindow.cc index 450ca32..3dce5b8 100644 --- a/src/FbTk/FbWindow.cc +++ b/src/FbTk/FbWindow.cc | |||
@@ -461,47 +461,64 @@ void FbWindow::reparent(const FbWindow &parent, int x, int y, bool continuing) { | |||
461 | if (continuing) // we will continue managing this window after reparent | 461 | if (continuing) // we will continue managing this window after reparent |
462 | updateGeometry(); | 462 | updateGeometry(); |
463 | } | 463 | } |
464 | 464 | struct TextPropPtr { | |
465 | TextPropPtr(XTextProperty& prop):m_prop(prop) {} | ||
466 | ~TextPropPtr() { | ||
467 | if (m_prop.value != 0) { | ||
468 | XFree(m_prop.value); | ||
469 | m_prop.value = 0; | ||
470 | } | ||
471 | } | ||
472 | XTextProperty& m_prop; | ||
473 | }; | ||
465 | std::string FbWindow::textProperty(Atom property) const { | 474 | std::string FbWindow::textProperty(Atom property) const { |
466 | XTextProperty text_prop; | 475 | XTextProperty text_prop; |
476 | TextPropPtr helper(text_prop); | ||
467 | char ** stringlist = 0; | 477 | char ** stringlist = 0; |
468 | int count = 0; | 478 | int count = 0; |
469 | std::string ret; | 479 | std::string ret; |
470 | 480 | ||
471 | static Atom m_utf8string = XInternAtom(display(), "UTF8_STRING", False); | 481 | static Atom m_utf8string = XInternAtom(display(), "UTF8_STRING", False); |
472 | 482 | ||
473 | if (XGetTextProperty(display(), window(), &text_prop, property) == 0) | 483 | if (XGetTextProperty(display(), window(), &text_prop, property) == 0) { |
474 | return ""; | 484 | return ""; |
485 | } | ||
475 | 486 | ||
476 | if (text_prop.value == 0 || text_prop.nitems == 0) | 487 | if (text_prop.value == 0 || text_prop.nitems == 0) { |
477 | return ""; | 488 | return ""; |
489 | } | ||
478 | 490 | ||
479 | if (text_prop.encoding == XA_STRING) { | 491 | if (text_prop.encoding == XA_STRING) { |
480 | if (XTextPropertyToStringList(&text_prop, &stringlist, &count) == 0 || count == 0) | 492 | if (XTextPropertyToStringList(&text_prop, &stringlist, &count) == 0 || count == 0) { |
481 | return ""; | 493 | return ""; |
494 | } | ||
482 | ret = FbStringUtil::XStrToFb(stringlist[0]); | 495 | ret = FbStringUtil::XStrToFb(stringlist[0]); |
483 | } else if (text_prop.encoding == m_utf8string && text_prop.format == 8) { | 496 | } else if (text_prop.encoding == m_utf8string && text_prop.format == 8) { |
484 | #ifdef X_HAVE_UTF8_STRING | 497 | #ifdef X_HAVE_UTF8_STRING |
485 | Xutf8TextPropertyToTextList(display(), &text_prop, &stringlist, &count); | 498 | Xutf8TextPropertyToTextList(display(), &text_prop, &stringlist, &count); |
486 | if (count == 0 || stringlist == 0) | 499 | if (count == 0 || stringlist == 0) { |
487 | return ""; | 500 | return ""; |
501 | } | ||
488 | #else | 502 | #else |
489 | if (XTextPropertyToStringList(&text_prop, &stringlist, &count) == 0 || count == 0 || stringlist == 0) | 503 | if (XTextPropertyToStringList(&text_prop, &stringlist, &count) == 0 || count == 0 || stringlist == 0) { |
490 | return ""; | 504 | return ""; |
505 | } | ||
491 | #endif | 506 | #endif |
492 | ret = stringlist[0]; | 507 | ret = stringlist[0]; |
493 | } else { | 508 | } else { |
494 | // still returns a "StringList" despite the different name | 509 | // still returns a "StringList" despite the different name |
495 | XmbTextPropertyToTextList(display(), &text_prop, &stringlist, &count); | 510 | XmbTextPropertyToTextList(display(), &text_prop, &stringlist, &count); |
496 | if (count == 0 || stringlist == 0) | 511 | if (count == 0 || stringlist == 0) { |
497 | return ""; | 512 | return ""; |
498 | 513 | } | |
499 | ret = FbStringUtil::LocaleStrToFb(stringlist[0]); | 514 | ret = FbStringUtil::LocaleStrToFb(stringlist[0]); |
500 | } | 515 | } |
501 | 516 | ||
502 | // they all use stringlist | 517 | // they all use stringlist |
503 | if (stringlist) | 518 | if (stringlist) { |
504 | XFreeStringList(stringlist); | 519 | XFreeStringList(stringlist); |
520 | } | ||
521 | |||
505 | return ret; | 522 | return ret; |
506 | } | 523 | } |
507 | 524 | ||