/****************************************************************************** Header ******************************************************************************/ // $Header:$ /****************************************************************************** Include others ******************************************************************************/ //#include "sdkBeg.hpp" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // Required for this to be a free-standing executable. //#include "sdkEnd.hpp" #include /****************************************************************************** Using ******************************************************************************/ using namespace com::sun::star::beans; using namespace com::sun::star::container; using namespace com::sun::star::frame; using namespace com::sun::star::lang; using namespace com::sun::star::text; using namespace com::sun::star::uno; using namespace com::sun::star::util; using namespace com::sun::star::view; /****************************************************************************** ModifyBug ******************************************************************************/ class ModifyBug: public cppu::WeakImplHelper1 { protected: Reference savedXComponent; // needed for testing listener virtual void SAL_CALL modified(const com::sun::star::lang::EventObject& event) throw (com::sun::star::uno::RuntimeException); virtual void SAL_CALL disposing(const com::sun::star::lang::EventObject& event) throw (com::sun::star::uno::RuntimeException); Reference newXTextDocument(Reference desktop); public: ModifyBug() { } void run(); void getSelections(Reference xComponent); }; void SAL_CALL ModifyBug::disposing(const com::sun::star::lang::EventObject& event) throw (com::sun::star::uno::RuntimeException) { // TODO: remove listener } void ModifyBug::getSelections(Reference xComponent) { Reference xModel(xComponent, UNO_QUERY); Reference xController = xModel->getCurrentController(); Reference xSelectionSupplier(xController, UNO_QUERY); xSelectionSupplier->getSelection(); // Including this line makes it hang on return from function! } void SAL_CALL ModifyBug::modified(const com::sun::star::lang::EventObject& event) throw (com::sun::star::uno::RuntimeException) { getSelections(savedXComponent); } Reference ModifyBug::newXTextDocument(Reference desktop) { Reference xComponentLoader(desktop, UNO_QUERY); Reference document = xComponentLoader->loadComponentFromURL( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/swriter")), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_blank")), 0, Sequence()); Reference xTextDocument(document, UNO_QUERY); return xTextDocument; } void ModifyBug::run() { try { Reference xComponentContext(cppu::bootstrap()); Reference xMultiComponentFactory(xComponentContext->getServiceManager(), UNO_QUERY); Reference desktop = xMultiComponentFactory->createInstanceWithContext( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop")), xComponentContext); Reference xDesktop(desktop, UNO_QUERY); { Reference xTextDocument = newXTextDocument(desktop); Reference xText = xTextDocument->getText(); Reference xComponent(xTextDocument, UNO_QUERY); Reference xModifiable(xComponent, UNO_QUERY); Reference xModifyBroadcaster(xComponent, UNO_QUERY); savedXComponent = xComponent; xModifyBroadcaster->addModifyListener(this); getSelections(savedXComponent); // It (getSelection) can be called directly getSelections(savedXComponent); // and repeatedly xText->setString(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("hello"))); // It can _not_ be called indirectly xModifiable->setModified(sal_True); // It can't be called indirectly like this, either. xModifyBroadcaster->removeModifyListener(this); savedXComponent = Reference(); xTextDocument->dispose(); } xDesktop->terminate(); } catch (...) { std::cerr << "Exception..." << std::endl; } } SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) { ModifyBug modifyBug; modifyBug.run(); return 0; } /*****************************************************************************/