summaryrefslogtreecommitdiffstats
path: root/sdext/source/presenter/PresenterPaneBase.cxx
blob: aac8d082a97180cb67cb660d18583c800a3784cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include "PresenterPaneBase.hxx"
#include "PresenterController.hxx"
#include "PresenterPaintManager.hxx"
#include <com/sun/star/awt/PosSize.hpp>
#include <com/sun/star/awt/XWindow2.hpp>

using namespace css;
using namespace css::uno;
using namespace css::drawing::framework;

namespace sdext::presenter {

//===== PresenterPaneBase =====================================================

PresenterPaneBase::PresenterPaneBase (
    const Reference<XComponentContext>& rxContext,
    const ::rtl::Reference<PresenterController>& rpPresenterController)
    : PresenterPaneBaseInterfaceBase(m_aMutex),
      mpPresenterController(rpPresenterController),
      mxComponentContext(rxContext)
{
    if (mpPresenterController)
        mxPresenterHelper = mpPresenterController->GetPresenterHelper();
}

PresenterPaneBase::~PresenterPaneBase()
{
}

void PresenterPaneBase::disposing()
{
    if (mxBorderWindow.is())
    {
        mxBorderWindow->removeWindowListener(this);
        mxBorderWindow->removePaintListener(this);
    }

    {
        Reference<XComponent> xComponent (mxContentCanvas, UNO_QUERY);
        mxContentCanvas = nullptr;
        if (xComponent.is())
            xComponent->dispose();
    }

    {
        Reference<XComponent> xComponent = mxContentWindow;
        mxContentWindow = nullptr;
        if (xComponent.is())
            xComponent->dispose();
    }

    {
        Reference<XComponent> xComponent (mxBorderCanvas, UNO_QUERY);
        mxBorderCanvas = nullptr;
        if (xComponent.is())
            xComponent->dispose();
    }

    {
        Reference<XComponent> xComponent  = mxBorderWindow;
        mxBorderWindow = nullptr;
        if (xComponent.is())
            xComponent->dispose();
    }

    mxComponentContext = nullptr;
}

void PresenterPaneBase::SetTitle (const OUString& rsTitle)
{
    msTitle = rsTitle;

    OSL_ASSERT(mpPresenterController);
    OSL_ASSERT(mpPresenterController->GetPaintManager() != nullptr);

    mpPresenterController->GetPaintManager()->Invalidate(mxBorderWindow);
}

const OUString& PresenterPaneBase::GetTitle() const
{
    return msTitle;
}

const Reference<drawing::framework::XPaneBorderPainter>&
    PresenterPaneBase::GetPaneBorderPainter() const
{
    return mxBorderPainter;
}

//----- XInitialization -------------------------------------------------------

void SAL_CALL PresenterPaneBase::initialize (const Sequence<Any>& rArguments)
{
    ThrowIfDisposed();

    if ( ! mxComponentContext.is())
    {
        throw RuntimeException(
            "PresenterSpritePane: missing component context",
            static_cast<XWeak*>(this));
    }

    if (rArguments.getLength() != 5 && rArguments.getLength() != 6)
    {
        throw RuntimeException(
            "PresenterSpritePane: invalid number of arguments",
                static_cast<XWeak*>(this));
    }

    try
    {
        // Get the resource id from the first argument.
        if ( ! (rArguments[0] >>= mxPaneId))
        {
            throw lang::IllegalArgumentException(
                "PresenterPane: invalid pane id",
                static_cast<XWeak*>(this),
                0);
        }

        if ( ! (rArguments[1] >>= mxParentWindow))
        {
            throw lang::IllegalArgumentException(
                "PresenterPane: invalid parent window",
                static_cast<XWeak*>(this),
                1);
        }

        Reference<rendering::XSpriteCanvas> xParentCanvas;
        if ( ! (rArguments[2] >>= xParentCanvas))
        {
            throw lang::IllegalArgumentException(
                "PresenterPane: invalid parent canvas",
                static_cast<XWeak*>(this),
                2);
        }

        if ( ! (rArguments[3] >>= msTitle))
        {
            throw lang::IllegalArgumentException(
                "PresenterPane: invalid title",
                static_cast<XWeak*>(this),
                3);
        }

        if ( ! (rArguments[4] >>= mxBorderPainter))
        {
            throw lang::IllegalArgumentException(
                "PresenterPane: invalid border painter",
                static_cast<XWeak*>(this),
                4);
        }

        bool bIsWindowVisibleOnCreation (true);
        if (rArguments.getLength()>5 && ! (rArguments[5] >>= bIsWindowVisibleOnCreation))
        {
            throw lang::IllegalArgumentException(
                "PresenterPane: invalid window visibility flag",
                static_cast<XWeak*>(this),
                5);
        }

        CreateWindows(bIsWindowVisibleOnCreation);

        if (mxBorderWindow.is())
        {
            mxBorderWindow->addWindowListener(this);
            mxBorderWindow->addPaintListener(this);
        }

        CreateCanvases(xParentCanvas);

        // Raise new windows.
        ToTop();
    }
    catch (Exception&)
    {
        mxContentWindow = nullptr;
        mxComponentContext = nullptr;
        throw;
    }
}

//----- XResourceId -----------------------------------------------------------

Reference<XResourceId> SAL_CALL PresenterPaneBase::getResourceId()
{
    ThrowIfDisposed();
    return mxPaneId;
}

sal_Bool SAL_CALL PresenterPaneBase::isAnchorOnly()
{
    return true;
}

//----- XWindowListener -------------------------------------------------------

void SAL_CALL PresenterPaneBase::windowResized (const awt::WindowEvent&)
{
    ThrowIfDisposed();
}

void SAL_CALL PresenterPaneBase::windowMoved (const awt::WindowEvent&)
{
    ThrowIfDisposed();
}

void SAL_CALL PresenterPaneBase::windowShown (const lang::EventObject&)
{
    ThrowIfDisposed();
}

void SAL_CALL PresenterPaneBase::windowHidden (const lang::EventObject&)
{
    ThrowIfDisposed();
}

//----- lang::XEventListener --------------------------------------------------

void SAL_CALL PresenterPaneBase::disposing (const lang::EventObject& rEvent)
{
    if (rEvent.Source == mxBorderWindow)
    {
        mxBorderWindow = nullptr;
    }
}


void PresenterPaneBase::CreateWindows (
    const bool bIsWindowVisibleOnCreation)
{
    if (!(mxPresenterHelper.is() && mxParentWindow.is()))
        return;

    mxBorderWindow = mxPresenterHelper->createWindow(
        mxParentWindow,
        false,
        bIsWindowVisibleOnCreation,
        false,
        false);
    mxContentWindow = mxPresenterHelper->createWindow(
        mxBorderWindow,
        false,
        bIsWindowVisibleOnCreation,
        false,
        false);
}

const Reference<awt::XWindow>& PresenterPaneBase::GetBorderWindow() const
{
    return mxBorderWindow;
}

void PresenterPaneBase::ToTop()
{
    if (mxPresenterHelper.is())
        mxPresenterHelper->toTop(mxContentWindow);
}

void PresenterPaneBase::PaintBorder (const awt::Rectangle& rUpdateBox)
{
    OSL_ASSERT(mxPaneId.is());

    if (!(mxBorderPainter.is() && mxBorderWindow.is() && mxBorderCanvas.is()))
        return;

    awt::Rectangle aBorderBox (mxBorderWindow->getPosSize());
    awt::Rectangle aLocalBorderBox (0,0, aBorderBox.Width, aBorderBox.Height);

    //TODO: paint border background?

    mxBorderPainter->paintBorder(
            mxPaneId->getResourceURL(),
            mxBorderCanvas,
            aLocalBorderBox,
            rUpdateBox,
            msTitle);
}

void PresenterPaneBase::LayoutContextWindow()
{
    OSL_ASSERT(mxPaneId.is());
    OSL_ASSERT(mxBorderWindow.is());
    OSL_ASSERT(mxContentWindow.is());
    if (!(mxBorderPainter.is() && mxPaneId.is() && mxBorderWindow.is() && mxContentWindow.is()))
        return;

    const awt::Rectangle aBorderBox (mxBorderWindow->getPosSize());
    const awt::Rectangle aInnerBox (mxBorderPainter->removeBorder(
        mxPaneId->getResourceURL(),
        aBorderBox,
        drawing::framework::BorderType_TOTAL_BORDER));
    mxContentWindow->setPosSize(
        aInnerBox.X - aBorderBox.X,
        aInnerBox.Y - aBorderBox.Y,
        aInnerBox.Width,
        aInnerBox.Height,
        awt::PosSize::POSSIZE);
}

bool PresenterPaneBase::IsVisible() const
{
    Reference<awt::XWindow2> xWindow2 (mxBorderPainter, UNO_QUERY);
    if (xWindow2.is())
        return xWindow2->isVisible();

    return false;
}

void PresenterPaneBase::ThrowIfDisposed()
{
    if (rBHelper.bDisposed || rBHelper.bInDispose)
    {
        throw lang::DisposedException (
            "PresenterPane object has already been disposed",
            static_cast<uno::XWeak*>(this));
    }
}

} // end of namespace ::sdext::presenter

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */