21 #include <com/sun/star/frame/XController.hpp>
22 #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
23 #include <com/sun/star/table/XCellRange.hpp>
24 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
25 #include <com/sun/star/container/XNameAccess.hpp>
26 #include <com/sun/star/container/XIndexAccess.hpp>
27 #include <com/sun/star/lang/XUnoTunnel.hpp>
28 #include <com/sun/star/view/XSelectionSupplier.hpp>
43 uno::Reference< lang::XUnoTunnel > xTunnel( xModel, uno::UNO_QUERY_THROW );
51 return pDocShell? pDocShell->
GetView() :
nullptr;
54 uno::Reference< text::XTextViewCursor >
getXTextViewCursor(
const uno::Reference< frame::XModel >& xModel )
56 uno::Reference< frame::XController >
xController = xModel->getCurrentController();
57 uno::Reference< text::XTextViewCursorSupplier > xTextViewCursorSupp( xController, uno::UNO_QUERY_THROW );
58 uno::Reference< text::XTextViewCursor > xTextViewCursor = xTextViewCursorSupp->getViewCursor();
59 return xTextViewCursor;
64 uno::Reference< beans::XPropertySet > xCursorProps(
getXTextViewCursor( xModel ), uno::UNO_QUERY_THROW );
68 uno::Reference< style::XStyle >
getCurrentPageStyle(
const uno::Reference< frame::XModel >& xModel,
const uno::Reference< beans::XPropertySet >& xProps )
70 OUString aPageStyleName;
71 xProps->getPropertyValue(
"PageStyleName") >>= aPageStyleName;
72 uno::Reference< style::XStyleFamiliesSupplier > xSytleFamSupp( xModel, uno::UNO_QUERY_THROW );
73 uno::Reference< container::XNameAccess > xSytleFamNames( xSytleFamSupp->getStyleFamilies(), uno::UNO_SET_THROW );
74 uno::Reference< container::XNameAccess > xPageStyles( xSytleFamNames->getByName(
"PageStyles"), uno::UNO_QUERY_THROW );
75 uno::Reference< style::XStyle > xStyle( xPageStyles->getByName( aPageStyleName ), uno::UNO_QUERY_THROW );
80 sal_Int32
getPageCount(
const uno::Reference< frame::XModel>& xModel )
89 uno::Reference< style::XStyleFamiliesSupplier > xSytleFamSupp( xModel, uno::UNO_QUERY_THROW );
90 uno::Reference< container::XNameAccess > xSytleFamNames( xSytleFamSupp->getStyleFamilies(), uno::UNO_SET_THROW );
91 uno::Reference< container::XNameAccess > xParaStyles( xSytleFamNames->getByName(
"ParagraphStyles"), uno::UNO_QUERY_THROW );
92 uno::Reference< style::XStyle > xStyle( xParaStyles->getByName(
"Standard"), uno::UNO_QUERY_THROW );
100 uno::Reference< text::XTextRange > xTextRange;
101 uno::Reference< container::XEnumerationAccess > xParaAccess( xText, uno::UNO_QUERY_THROW );
102 uno::Reference< container::XEnumeration> xParaEnum = xParaAccess->createEnumeration();
103 if( xParaEnum->hasMoreElements() )
105 uno::Reference< lang::XServiceInfo > xServiceInfo( xParaEnum->nextElement(), uno::UNO_QUERY_THROW );
106 if( xServiceInfo->supportsService(
"com.sun.star.text.TextTable") )
108 uno::Reference< table::XCellRange > xCellRange( xServiceInfo, uno::UNO_QUERY_THROW );
109 uno::Reference< text::XText> xFirstCellText( xCellRange->getCellByPosition(0, 0), uno::UNO_QUERY_THROW );
110 xTextRange = xFirstCellText->getStart();
113 if( !xTextRange.is() )
114 xTextRange = xText->getStart();
118 uno::Reference< text::XText >
getCurrentXText(
const uno::Reference< frame::XModel >& xModel )
120 uno::Reference< text::XTextRange > xTextRange;
121 uno::Reference< text::XTextContent > xTextContent( xModel->getCurrentSelection(), uno::UNO_QUERY );
122 if( !xTextContent.is() )
124 uno::Reference< container::XIndexAccess > xIndexAccess( xModel->getCurrentSelection(), uno::UNO_QUERY );
125 if( xIndexAccess.is() )
127 xTextContent.set( xIndexAccess->getByIndex(0), uno::UNO_QUERY );
131 if( xTextContent.is() )
132 xTextRange = xTextContent->getAnchor();
134 if( !xTextRange.is() )
137 uno::Reference< text::XText > xText;
140 xText = xTextRange->getText();
142 catch (
const uno::RuntimeException&)
146 uno::Reference< beans::XPropertySet > xVCProps( xTextRange, uno::UNO_QUERY_THROW );
147 while( xVCProps->getPropertyValue(
"TextTable") >>= xTextContent )
149 xText = xTextContent->getAnchor()->getText();
150 xVCProps.set( xText->createTextCursor(), uno::UNO_QUERY_THROW );
154 throw uno::RuntimeException(
"no text selection" );
161 bool isObjectSelected =
false;
162 uno::Reference< text::XTextContent > xTextContent( xModel->getCurrentSelection(), uno::UNO_QUERY );
163 if( xTextContent.is() )
165 uno::Reference< text::XTextRange > xTextRange( xTextContent->getAnchor(), uno::UNO_SET_THROW );
166 uno::Reference< view::XSelectionSupplier > xSelectSupp( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
167 xSelectSupp->select( uno::makeAny( xTextRange ) );
168 isObjectSelected =
true;
170 return isObjectSelected;
uno::Reference< style::XStyle > getDefaultParagraphStyle(const uno::Reference< frame::XModel > &xModel)
Reference< XController > xController
uno::Reference< style::XStyle > getCurrentPageStyle(const uno::Reference< frame::XModel > &xModel)
uno::Reference< text::XTextViewCursor > getXTextViewCursor(const uno::Reference< frame::XModel > &xModel)
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
SwDoc * GetDoc()
returns Doc. But be careful!
SwView * getView(const uno::Reference< frame::XModel > &xModel)
bool gotoSelectedObjectAnchor(const uno::Reference< frame::XModel > &xModel)
sal_uInt16 GetPageCount() const
SwDocShell * GetDocShell()
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
sal_Int32 getPageCount(const uno::Reference< frame::XModel > &xModel)
SwDocShell * getDocShell(const uno::Reference< frame::XModel > &xModel)
virtual const SwViewShell * GetCurrentViewShell() const =0
Returns the layout set at the document.
uno::Reference< text::XText > getCurrentXText(const uno::Reference< frame::XModel > &xModel)
uno::Reference< text::XTextRange > getFirstObjectPosition(const uno::Reference< text::XText > &xText)
const SwView * GetView() const