1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "PresenterPaneBase.hxx"
21 #include "PresenterController.hxx"
22 #include "PresenterPaintManager.hxx"
23 #include <com/sun/star/awt/PosSize.hpp>
24 #include <com/sun/star/awt/XWindow2.hpp>
28 using namespace css::uno
;
29 using namespace css::drawing::framework
;
31 namespace sdext::presenter
{
33 //===== PresenterPaneBase =====================================================
35 PresenterPaneBase::PresenterPaneBase (
36 const Reference
<XComponentContext
>& rxContext
,
37 ::rtl::Reference
<PresenterController
> xPresenterController
)
38 : PresenterPaneBaseInterfaceBase(m_aMutex
),
39 mpPresenterController(std::move(xPresenterController
)),
40 mxComponentContext(rxContext
)
42 if (mpPresenterController
)
43 mxPresenterHelper
= mpPresenterController
->GetPresenterHelper();
46 PresenterPaneBase::~PresenterPaneBase()
50 void PresenterPaneBase::disposing()
52 if (mxBorderWindow
.is())
54 mxBorderWindow
->removeWindowListener(this);
55 mxBorderWindow
->removePaintListener(this);
59 Reference
<XComponent
> xComponent (mxContentCanvas
, UNO_QUERY
);
60 mxContentCanvas
= nullptr;
62 xComponent
->dispose();
66 Reference
<XComponent
> xComponent
= mxContentWindow
;
67 mxContentWindow
= nullptr;
69 xComponent
->dispose();
73 Reference
<XComponent
> xComponent (mxBorderCanvas
, UNO_QUERY
);
74 mxBorderCanvas
= nullptr;
76 xComponent
->dispose();
80 Reference
<XComponent
> xComponent
= mxBorderWindow
;
81 mxBorderWindow
= nullptr;
83 xComponent
->dispose();
86 mxComponentContext
= nullptr;
89 void PresenterPaneBase::SetTitle (const OUString
& rsTitle
)
93 OSL_ASSERT(mpPresenterController
);
94 OSL_ASSERT(mpPresenterController
->GetPaintManager() != nullptr);
96 mpPresenterController
->GetPaintManager()->Invalidate(mxBorderWindow
);
99 const OUString
& PresenterPaneBase::GetTitle() const
104 const Reference
<drawing::framework::XPaneBorderPainter
>&
105 PresenterPaneBase::GetPaneBorderPainter() const
107 return mxBorderPainter
;
110 //----- XInitialization -------------------------------------------------------
112 void SAL_CALL
PresenterPaneBase::initialize (const Sequence
<Any
>& rArguments
)
116 if ( ! mxComponentContext
.is())
118 throw RuntimeException(
119 "PresenterSpritePane: missing component context",
120 static_cast<XWeak
*>(this));
123 if (rArguments
.getLength() != 5 && rArguments
.getLength() != 6)
125 throw RuntimeException(
126 "PresenterSpritePane: invalid number of arguments",
127 static_cast<XWeak
*>(this));
132 // Get the resource id from the first argument.
133 if ( ! (rArguments
[0] >>= mxPaneId
))
135 throw lang::IllegalArgumentException(
136 "PresenterPane: invalid pane id",
137 static_cast<XWeak
*>(this),
141 if ( ! (rArguments
[1] >>= mxParentWindow
))
143 throw lang::IllegalArgumentException(
144 "PresenterPane: invalid parent window",
145 static_cast<XWeak
*>(this),
149 Reference
<rendering::XSpriteCanvas
> xParentCanvas
;
150 if ( ! (rArguments
[2] >>= xParentCanvas
))
152 throw lang::IllegalArgumentException(
153 "PresenterPane: invalid parent canvas",
154 static_cast<XWeak
*>(this),
158 if ( ! (rArguments
[3] >>= msTitle
))
160 throw lang::IllegalArgumentException(
161 "PresenterPane: invalid title",
162 static_cast<XWeak
*>(this),
166 if ( ! (rArguments
[4] >>= mxBorderPainter
))
168 throw lang::IllegalArgumentException(
169 "PresenterPane: invalid border painter",
170 static_cast<XWeak
*>(this),
174 bool bIsWindowVisibleOnCreation (true);
175 if (rArguments
.getLength()>5 && ! (rArguments
[5] >>= bIsWindowVisibleOnCreation
))
177 throw lang::IllegalArgumentException(
178 "PresenterPane: invalid window visibility flag",
179 static_cast<XWeak
*>(this),
183 CreateWindows(bIsWindowVisibleOnCreation
);
185 if (mxBorderWindow
.is())
187 mxBorderWindow
->addWindowListener(this);
188 mxBorderWindow
->addPaintListener(this);
191 CreateCanvases(xParentCanvas
);
193 // Raise new windows.
198 mxContentWindow
= nullptr;
199 mxComponentContext
= nullptr;
204 //----- XResourceId -----------------------------------------------------------
206 Reference
<XResourceId
> SAL_CALL
PresenterPaneBase::getResourceId()
212 sal_Bool SAL_CALL
PresenterPaneBase::isAnchorOnly()
217 //----- XWindowListener -------------------------------------------------------
219 void SAL_CALL
PresenterPaneBase::windowResized (const awt::WindowEvent
&)
224 void SAL_CALL
PresenterPaneBase::windowMoved (const awt::WindowEvent
&)
229 void SAL_CALL
PresenterPaneBase::windowShown (const lang::EventObject
&)
234 void SAL_CALL
PresenterPaneBase::windowHidden (const lang::EventObject
&)
239 //----- lang::XEventListener --------------------------------------------------
241 void SAL_CALL
PresenterPaneBase::disposing (const lang::EventObject
& rEvent
)
243 if (rEvent
.Source
== mxBorderWindow
)
245 mxBorderWindow
= nullptr;
250 void PresenterPaneBase::CreateWindows (
251 const bool bIsWindowVisibleOnCreation
)
253 if (!(mxPresenterHelper
.is() && mxParentWindow
.is()))
256 mxBorderWindow
= mxPresenterHelper
->createWindow(
259 bIsWindowVisibleOnCreation
,
262 mxContentWindow
= mxPresenterHelper
->createWindow(
265 bIsWindowVisibleOnCreation
,
270 const Reference
<awt::XWindow
>& PresenterPaneBase::GetBorderWindow() const
272 return mxBorderWindow
;
275 void PresenterPaneBase::ToTop()
277 if (mxPresenterHelper
.is())
278 mxPresenterHelper
->toTop(mxContentWindow
);
281 void PresenterPaneBase::PaintBorder (const awt::Rectangle
& rUpdateBox
)
283 OSL_ASSERT(mxPaneId
.is());
285 if (!(mxBorderPainter
.is() && mxBorderWindow
.is() && mxBorderCanvas
.is()))
288 awt::Rectangle
aBorderBox (mxBorderWindow
->getPosSize());
289 awt::Rectangle
aLocalBorderBox (0,0, aBorderBox
.Width
, aBorderBox
.Height
);
291 //TODO: paint border background?
293 mxBorderPainter
->paintBorder(
294 mxPaneId
->getResourceURL(),
301 void PresenterPaneBase::LayoutContextWindow()
303 OSL_ASSERT(mxPaneId
.is());
304 OSL_ASSERT(mxBorderWindow
.is());
305 OSL_ASSERT(mxContentWindow
.is());
306 if (!(mxBorderPainter
.is() && mxPaneId
.is() && mxBorderWindow
.is() && mxContentWindow
.is()))
309 const awt::Rectangle
aBorderBox (mxBorderWindow
->getPosSize());
310 const awt::Rectangle
aInnerBox (mxBorderPainter
->removeBorder(
311 mxPaneId
->getResourceURL(),
313 drawing::framework::BorderType_TOTAL_BORDER
));
314 mxContentWindow
->setPosSize(
315 aInnerBox
.X
- aBorderBox
.X
,
316 aInnerBox
.Y
- aBorderBox
.Y
,
319 awt::PosSize::POSSIZE
);
322 bool PresenterPaneBase::IsVisible() const
324 Reference
<awt::XWindow2
> xWindow2 (mxBorderPainter
, UNO_QUERY
);
326 return xWindow2
->isVisible();
331 void PresenterPaneBase::ThrowIfDisposed()
333 if (rBHelper
.bDisposed
|| rBHelper
.bInDispose
)
335 throw lang::DisposedException (
336 "PresenterPane object has already been disposed",
337 static_cast<uno::XWeak
*>(this));
341 } // end of namespace ::sdext::presenter
343 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */