25 #include <com/sun/star/awt/XWindowPeer.hpp>
26 #include <com/sun/star/container/XNameAccess.hpp>
27 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
28 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
29 #include <com/sun/star/rendering/CompositeOperation.hpp>
30 #include <com/sun/star/rendering/TextDirection.hpp>
31 #include <com/sun/star/util/Color.hpp>
34 #include <string_view>
45 const sal_Int32 gnHorizontalGap (20);
47 const sal_Int32 gnVerticalButtonPadding (12);
54 std::u16string_view rsLine,
55 const css::uno::Reference<css::rendering::XCanvasFont>& rxFont);
62 void CalculateSize (
const css::uno::Reference<css::rendering::XCanvasFont>& rxFont);
65 class LineDescriptorList
69 const OUString& rsText,
70 const css::uno::Reference<css::rendering::XCanvasFont>& rxFont,
71 const sal_Int32 nMaximalWidth);
74 const css::uno::Reference<css::rendering::XCanvasFont>& rxFont,
75 const sal_Int32 nMaximalWidth);
78 const Reference<rendering::XCanvas>& rxCanvas,
79 const geometry::RealRectangle2D& rBBox,
80 const bool bFlushLeft,
81 const rendering::ViewState& rViewState,
82 rendering::RenderState& rRenderState,
83 const css::uno::Reference<css::rendering::XCanvasFont>& rxFont)
const;
84 double GetHeight()
const;
90 static void SplitText (
const OUString& rsText, vector<OUString>& rTextParts);
92 const vector<OUString>& rTextParts,
93 const css::uno::Reference<css::rendering::XCanvasFont>& rxFont,
94 const sal_Int32 nMaximalWidth);
101 const OUString& rsLeftText,
102 const OUString& rsRightText,
103 const css::uno::Reference<css::rendering::XCanvasFont>& rxFont,
104 const sal_Int32 nMaximalWidth);
105 Block(
const Block&) =
delete;
106 Block& operator=(
const Block&) =
delete;
108 const css::uno::Reference<css::rendering::XCanvasFont>& rxFont,
109 const sal_Int32 nMaximalWidth);
122 const Reference<XResourceId>& rxViewId,
123 const Reference<frame::XController>& rxController,
124 const ::rtl::Reference<PresenterController>& rpPresenterController)
141 Reference<XControllerManager> xCM (rxController, UNO_QUERY_THROW);
142 Reference<XConfigurationController> xCC (
143 xCM->getConfigurationController(), UNO_SET_THROW);
144 mxPane.set(xCC->getResource(rxViewId->getAnchor()), UNO_QUERY_THROW);
151 Reference<awt::XWindowPeer> xPeer (
mxWindow, UNO_QUERY);
153 xPeer->setBackground(util::Color(0xff000000));
199 xComponent->dispose();
204 mxWindow->removeWindowListener(
this);
205 mxWindow->removePaintListener(
this);
213 if (rEventObject.Source ==
mxCanvas)
217 else if (rEventObject.Source ==
mxWindow)
252 Paint(rEvent.UpdateRect);
262 const awt::Rectangle aWindowBox (
mxWindow->getPosSize());
267 awt::Rectangle(0,0,aWindowBox.Width,aWindowBox.Height),
272 rendering::ViewState aViewState(
273 geometry::AffineMatrix2D(1,0,0, 0,1,0),
276 rendering::RenderState aRenderState (
277 geometry::AffineMatrix2D(1,0,0, 0,1,0),
280 rendering::CompositeOperation::SOURCE);
300 sal_Int32 LeftX1 = gnHorizontalGap;
301 sal_Int32 LeftX2 = aWindowBox.Width/2 - gnHorizontalGap;
302 sal_Int32 RightX1 = aWindowBox.Width/2 + gnHorizontalGap;
303 sal_Int32 RightX2 = aWindowBox.Width - gnHorizontalGap;
308 LeftX1 = aWindowBox.Width/2 + gnHorizontalGap;
309 LeftX2 = aWindowBox.Width - gnHorizontalGap;
310 RightX1 = gnHorizontalGap;
311 RightX2 = aWindowBox.Width/2 - gnHorizontalGap;
313 const double nLeftHeight (
315 geometry::RealRectangle2D(
324 const double nRightHeight (
326 geometry::RealRectangle2D(
336 nY += ::std::max(nLeftHeight,nRightHeight);
339 Reference<rendering::XSpriteCanvas> xSpriteCanvas (
mxCanvas, UNO_QUERY);
340 if (xSpriteCanvas.is())
341 xSpriteCanvas->updateScreen(
false);
349 "/org.openoffice.Office.PresenterScreen/",
356 [
this](OUString
const&, uno::Reference<beans::XPropertySet>
const& xProps)
365 if ( ! rsProperties.is())
373 std::make_shared<Block>(
382 sal_Int32 nBestSize (6);
387 for (
int nLoopCount=0; nLoopCount<5; ++nLoopCount)
390 [](
const double& sum,
const std::shared_ptr<Block>& rxBlock) {
391 return sum + std::max(
392 rxBlock->maLeft.GetHeight(),
393 rxBlock->maRight.GetHeight());
397 if (nHeightDifference <= 0 && nHeightDifference > -50)
407 if (nScale > 1.0 && nScale < 1.05)
410 sal_Int32 nFontSizeGuess (sal_Int32(
mpFont->mnSize * nScale));
411 if (nHeightDifference<=0 && mpFont->
mnSize>nBestSize)
412 nBestSize =
mpFont->mnSize;
413 mpFont->mnSize = nFontSizeGuess;
422 if (nBestSize !=
mpFont->mnSize)
424 mpFont->mnSize = nBestSize;
459 xComponent->addEventListener(static_cast<awt::XPaintListener*>(
this));
471 const awt::Rectangle aWindowBox (
mxWindow->getPosSize());
479 aWindowBox.Width/2.0,
487 if (rBHelper.bDisposed || rBHelper.bInDispose)
489 throw lang::DisposedException (
490 "PresenterHelpView has been already disposed",
491 static_cast<uno::XWeak*>(
this));
499 LineDescriptor::LineDescriptor()
506 void LineDescriptor::AddPart (
507 std::u16string_view rsLine,
508 const css::uno::Reference<css::rendering::XCanvasFont>& rxFont)
512 CalculateSize(rxFont);
515 bool LineDescriptor::IsEmpty()
const
520 void LineDescriptor::CalculateSize (
521 const css::uno::Reference<css::rendering::XCanvasFont>& rxFont)
523 OSL_ASSERT(rxFont.is());
525 rendering::StringContext aContext (
msLine, 0,
msLine.getLength());
526 Reference<rendering::XTextLayout> xLayout (
527 rxFont->createTextLayout(aContext, rendering::TextDirection::WEAK_LEFT_TO_RIGHT, 0));
528 const geometry::RealRectangle2D aTextBBox (xLayout->queryTextBounds());
529 maSize = css::geometry::RealSize2D(aTextBBox.X2 - aTextBBox.X1, aTextBBox.Y2 - aTextBBox.Y1);
539 LineDescriptorList::LineDescriptorList (
540 const OUString& rsText,
541 const css::uno::Reference<css::rendering::XCanvasFont>& rxFont,
542 const sal_Int32 nMaximalWidth)
545 Update(rxFont, nMaximalWidth);
548 double LineDescriptorList::Paint(
549 const Reference<rendering::XCanvas>& rxCanvas,
550 const geometry::RealRectangle2D& rBBox,
551 const bool bFlushLeft,
552 const rendering::ViewState& rViewState,
553 rendering::RenderState& rRenderState,
554 const css::uno::Reference<css::rendering::XCanvasFont>& rxFont)
const
556 if ( ! rxCanvas.is())
559 double nY (rBBox.Y1);
568 nX = rBBox.X2 - rLine.maSize.Width;
572 nX=rBBox.X2 - rLine.maSize.Width;
576 rRenderState.AffineTransform.m02 = nX;
577 rRenderState.AffineTransform.m12 = nY + rLine.maSize.Height - rLine.mnVerticalOffset;
579 const rendering::StringContext aContext (rLine.msLine, 0, rLine.msLine.getLength());
580 Reference<rendering::XTextLayout> xLayout (
581 rxFont->createTextLayout(aContext, rendering::TextDirection::WEAK_LEFT_TO_RIGHT, 0));
582 rxCanvas->drawTextLayout (
587 nY += rLine.maSize.Height * 1.2;
590 return nY - rBBox.Y1;
593 double LineDescriptorList::GetHeight()
const
595 return std::accumulate(mpLineDescriptors->begin(), mpLineDescriptors->end(), double(0),
596 [](
const double& nHeight,
const LineDescriptor& rLine) {
597 return nHeight + rLine.maSize.Height * 1.2;
601 void LineDescriptorList::Update (
602 const css::uno::Reference<css::rendering::XCanvasFont>& rxFont,
603 const sal_Int32 nMaximalWidth)
605 vector<OUString> aTextParts;
606 SplitText(
msText, aTextParts);
607 FormatText(aTextParts, rxFont, nMaximalWidth);
610 void LineDescriptorList::SplitText (
611 const OUString& rsText,
612 vector<OUString>& rTextParts)
614 const char cQuote (
'\'');
615 const char cSeparator (
',');
618 sal_Int32 nStart (0);
619 sal_Int32
nLength (rsText.getLength());
620 bool bIsQuoted (
false);
621 while (nIndex < nLength)
623 const sal_Int32 nQuoteIndex (rsText.indexOf(cQuote, nIndex));
624 const sal_Int32 nSeparatorIndex (rsText.indexOf(cSeparator, nIndex));
625 if (nQuoteIndex>=0 && (nSeparatorIndex==-1 || nQuoteIndex<nSeparatorIndex))
627 bIsQuoted = !bIsQuoted;
632 const sal_Int32 nNextIndex = nSeparatorIndex;
637 else if ( ! bIsQuoted)
639 rTextParts.push_back(rsText.copy(nStart, nNextIndex-nStart));
640 nStart = nNextIndex + 1;
644 if (nStart < nLength)
645 rTextParts.push_back(rsText.copy(nStart, nLength-nStart));
648 void LineDescriptorList::FormatText (
649 const vector<OUString>& rTextParts,
650 const css::uno::Reference<css::rendering::XCanvasFont>& rxFont,
651 const sal_Int32 nMaximalWidth)
653 LineDescriptor aLineDescriptor;
655 mpLineDescriptors = std::make_shared<vector<LineDescriptor>>();
657 vector<OUString>::const_iterator iPart (rTextParts.begin());
658 vector<OUString>::const_iterator iEnd (rTextParts.end());
661 if (aLineDescriptor.IsEmpty())
665 rxFont, *iPart).Width > nMaximalWidth)
667 const char cSpace (
' ');
670 sal_Int32 nStart (0);
671 sal_Int32
nLength (iPart->getLength());
672 while (nIndex < nLength)
674 sal_Int32 nSpaceIndex (iPart->indexOf(cSpace, nIndex));
676 rxFont, iPart->copy(nStart, nSpaceIndex-nStart)).Width <= nMaximalWidth)
679 nSpaceIndex = iPart->indexOf(cSpace, nIndex+1);
683 rxFont, iPart->copy(nStart, nLength-nStart)).Width <= nMaximalWidth)
688 if (nIndex == nStart)
693 aLineDescriptor.AddPart(iPart->subView(nStart, nIndex-nStart), rxFont);
694 if (nIndex != nLength)
696 mpLineDescriptors->push_back(aLineDescriptor);
697 aLineDescriptor = LineDescriptor();
704 aLineDescriptor.AddPart(*iPart, rxFont);
708 rxFont, aLineDescriptor.msLine+
", "+*iPart).Width > nMaximalWidth)
710 aLineDescriptor.AddPart(u
",", rxFont);
711 mpLineDescriptors->push_back(aLineDescriptor);
712 aLineDescriptor = LineDescriptor();
717 aLineDescriptor.AddPart(OUString(
", "+*iPart), rxFont);
721 if ( ! aLineDescriptor.IsEmpty())
723 mpLineDescriptors->push_back(aLineDescriptor);
734 const OUString& rsLeftText,
735 const OUString& rsRightText,
736 const css::uno::Reference<css::rendering::XCanvasFont>& rxFont,
737 const sal_Int32 nMaximalWidth)
738 :
maLeft(rsLeftText, rxFont, nMaximalWidth),
739 maRight(rsRightText, rxFont, nMaximalWidth)
744 const css::uno::Reference<css::rendering::XCanvasFont>& rxFont,
745 const sal_Int32 nMaximalWidth)
747 maLeft.Update(rxFont, nMaximalWidth);
748 maRight.Update(rxFont, nMaximalWidth);
static void ForAll(const css::uno::Reference< css::container::XNameAccess > &rxContainer, const ::std::vector< OUString > &rArguments, const ItemProcessor &rProcessor)
Execute a functor for all elements of the given container.
Reference< rendering::XCanvas > mxCanvas
virtual css::uno::Reference< css::drawing::framework::XResourceId > SAL_CALL getResourceId() override
static css::uno::Any GetProperty(const css::uno::Reference< css::beans::XPropertySet > &rxProperties, const OUString &rsKey)
This method wraps a call to getPropertyValue() and returns an empty Any instead of throwing an except...
css::uno::Reference< css::drawing::framework::XResourceId > mxViewId
cppu::WeakComponentImplHelper< css::drawing::framework::XView, css::awt::XWindowListener, css::awt::XPaintListener > PresenterHelpViewInterfaceBase
css::uno::Reference< css::awt::XWindow > mxWindow
css::uno::Reference< css::drawing::framework::XPane > mxPane
void Paint(const css::awt::Rectangle &rRedrawArea)
This class gives access to the configuration.
LineDescriptorList maLeft
void CheckFontSize()
Find a font size, so that all text can be displayed at the same time.
PresenterHelpView(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const css::uno::Reference< css::drawing::framework::XResourceId > &rxViewId, const css::uno::Reference< css::frame::XController > &rxController, const ::rtl::Reference< PresenterController > &rpPresenterController)
std::shared_ptr< vector< LineDescriptor > > mpLineDescriptors
virtual void SAL_CALL windowShown(const css::lang::EventObject &rEvent) override
css::uno::Reference< css::uno::XComponentContext > mxComponentContext
virtual ~PresenterHelpView() override
css::uno::Reference< css::rendering::XCanvas > mxCanvas
std::unique_ptr< TextContainer > mpTextContainer
virtual sal_Bool SAL_CALL isAnchorOnly() override
LineDescriptorList maRight
css::uno::Any GetConfigurationNode(const OUString &rsPathToNode)
Return a configuration node below the root of the called object.
static bool GetLayoutRTL()
virtual void SAL_CALL windowPaint(const css::awt::PaintEvent &rEvent) override
static css::uno::Reference< css::rendering::XPolyPolygon2D > CreatePolygon(const css::awt::Rectangle &rBox, const css::uno::Reference< css::rendering::XGraphicDevice > &rxDevice)
void ProcessString(const css::uno::Reference< css::beans::XPropertySet > &rsProperties)
PresenterTheme::SharedFontDescriptor mpFont
rtl::Reference< PresenterController > mpPresenterController
::rtl::Reference< PresenterButton > mpCloseButton
static void SetDeviceColor(css::rendering::RenderState &rRenderState, const css::util::Color aColor)
static css::geometry::RealSize2D GetTextSize(const css::uno::Reference< css::rendering::XCanvasFont > &rxFont, const OUString &rsText)
virtual void SAL_CALL disposing() override
virtual void SAL_CALL windowResized(const css::awt::WindowEvent &rEvent) override
PresenterTheme::SharedFontDescriptor mpFont
::rtl::Reference< PresenterController > mpPresenterController
const double gnVerticalBorder(5)
geometry::RealSize2D maSize
virtual void SAL_CALL windowHidden(const css::lang::EventObject &rEvent) override
virtual void SAL_CALL windowMoved(const css::awt::WindowEvent &rEvent) override
css::uno::Reference< css::uno::XComponentContext > mxComponentContext