Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include "SlideSorterService.hxx"
22 : #include "controller/SlideSorterController.hxx"
23 : #include "controller/SlsProperties.hxx"
24 : #include "controller/SlsCurrentSlideManager.hxx"
25 : #include "model/SlideSorterModel.hxx"
26 : #include "model/SlsPageDescriptor.hxx"
27 : #include "view/SlideSorterView.hxx"
28 : #include "view/SlsLayouter.hxx"
29 : #include "DrawController.hxx"
30 : #include <toolkit/helper/vclunohelper.hxx>
31 : #include <com/sun/star/beans/PropertyAttribute.hpp>
32 : #include <com/sun/star/lang/XUnoTunnel.hpp>
33 : #include <osl/mutex.hxx>
34 : #include <vcl/svapp.hxx>
35 : #include <cppuhelper/proptypehlp.hxx>
36 :
37 : using namespace ::com::sun::star;
38 : using namespace ::com::sun::star::uno;
39 : using namespace ::com::sun::star::drawing::framework;
40 : using ::sd::slidesorter::view::Layouter;
41 :
42 : namespace sd { namespace slidesorter {
43 :
44 : namespace {
45 : enum Properties
46 : {
47 : PropertyDocumentSlides,
48 : PropertyHighlightCurrentSlide,
49 : PropertyShowSelection,
50 : PropertyCenterSelection,
51 : PropertySuspendPreviewUpdatesDuringFullScreenPresentation,
52 : PropertyOrientationVertical
53 : };
54 : }
55 :
56 :
57 :
58 :
59 : //===== Service ===============================================================
60 :
61 0 : Reference<XInterface> SAL_CALL SlideSorterService_createInstance (
62 : const Reference<XComponentContext>& rxContext)
63 : {
64 0 : return Reference<XInterface>(static_cast<drawing::XDrawView*>(new SlideSorterService(rxContext)));
65 : }
66 :
67 :
68 :
69 :
70 10 : OUString SlideSorterService_getImplementationName (void) throw(RuntimeException)
71 : {
72 10 : return OUString("com.sun.star.comp.Draw.SlideSorter");
73 : }
74 :
75 :
76 :
77 :
78 0 : Sequence<OUString> SAL_CALL SlideSorterService_getSupportedServiceNames (void)
79 : throw (RuntimeException)
80 : {
81 0 : static const OUString sServiceName("com.sun.star.drawing.SlideSorter");
82 0 : return Sequence<OUString>(&sServiceName, 1);
83 : }
84 :
85 :
86 :
87 :
88 : //===== SlideSorterService ==========================================================
89 :
90 0 : SlideSorterService::SlideSorterService (const Reference<XComponentContext>& rxContext)
91 : : SlideSorterServiceInterfaceBase(m_aMutex),
92 : mpSlideSorter(),
93 0 : mxParentWindow()
94 : {
95 : (void)rxContext;
96 0 : }
97 :
98 :
99 :
100 :
101 0 : SlideSorterService::~SlideSorterService (void)
102 : {
103 0 : }
104 :
105 :
106 :
107 :
108 0 : void SAL_CALL SlideSorterService::disposing (void)
109 : {
110 0 : mpSlideSorter.reset();
111 :
112 0 : if (mxParentWindow.is())
113 : {
114 0 : mxParentWindow->removeWindowListener(this);
115 : }
116 0 : }
117 :
118 :
119 :
120 :
121 : //----- XInitialization -------------------------------------------------------
122 :
123 0 : void SAL_CALL SlideSorterService::initialize (const Sequence<Any>& rArguments)
124 : throw (Exception, RuntimeException)
125 : {
126 0 : ThrowIfDisposed();
127 :
128 0 : if (rArguments.getLength() == 3)
129 : {
130 : try
131 : {
132 0 : mxViewId = Reference<XResourceId>(rArguments[0], UNO_QUERY_THROW);
133 :
134 : // Get the XController.
135 0 : Reference<frame::XController> xController (rArguments[1], UNO_QUERY_THROW);
136 :
137 : // Tunnel through the controller to obtain a ViewShellBase.
138 0 : ViewShellBase* pBase = NULL;
139 0 : Reference<lang::XUnoTunnel> xTunnel (xController, UNO_QUERY_THROW);
140 : ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
141 0 : xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
142 0 : if (pController != NULL)
143 0 : pBase = pController->GetViewShellBase();
144 :
145 : // Get the parent window.
146 0 : mxParentWindow = Reference<awt::XWindow>(rArguments[2], UNO_QUERY_THROW);
147 0 : ::Window* pParentWindow = VCLUnoHelper::GetWindow(mxParentWindow);
148 :
149 0 : mxParentWindow->addWindowListener(this);
150 :
151 0 : if (pBase != NULL && pParentWindow!=NULL)
152 0 : mpSlideSorter = SlideSorter::CreateSlideSorter(
153 : *pBase,
154 : NULL,
155 0 : *pParentWindow);
156 :
157 0 : Resize();
158 : }
159 0 : catch (RuntimeException&)
160 : {
161 0 : throw;
162 : }
163 : }
164 : else
165 : {
166 : throw RuntimeException("SlideSorterService: invalid number of arguments",
167 0 : static_cast<drawing::XDrawView*>(this));
168 : }
169 0 : }
170 :
171 :
172 :
173 :
174 : //----- XView -----------------------------------------------------------------
175 :
176 0 : Reference<XResourceId> SAL_CALL SlideSorterService::getResourceId (void)
177 : throw (RuntimeException)
178 : {
179 0 : return mxViewId;
180 : }
181 :
182 :
183 :
184 :
185 0 : sal_Bool SAL_CALL SlideSorterService::isAnchorOnly (void)
186 : throw (RuntimeException)
187 : {
188 0 : return sal_False;
189 : }
190 :
191 :
192 :
193 :
194 : //----- XWindowListener -------------------------------------------------------
195 :
196 0 : void SAL_CALL SlideSorterService::windowResized (const awt::WindowEvent& rEvent)
197 : throw (RuntimeException)
198 : {
199 : (void)rEvent;
200 0 : ThrowIfDisposed();
201 :
202 0 : Resize();
203 0 : }
204 :
205 :
206 :
207 :
208 :
209 0 : void SAL_CALL SlideSorterService::windowMoved (const awt::WindowEvent& rEvent)
210 : throw (RuntimeException)
211 : {
212 : (void)rEvent;
213 0 : }
214 :
215 :
216 :
217 :
218 0 : void SAL_CALL SlideSorterService::windowShown (const lang::EventObject& rEvent)
219 : throw (RuntimeException)
220 : {
221 : (void)rEvent;
222 0 : ThrowIfDisposed();
223 0 : Resize();
224 0 : }
225 :
226 :
227 :
228 :
229 0 : void SAL_CALL SlideSorterService::windowHidden (const lang::EventObject& rEvent)
230 : throw (RuntimeException)
231 : {
232 : (void)rEvent;
233 0 : ThrowIfDisposed();
234 0 : }
235 :
236 :
237 :
238 :
239 : //----- lang::XEventListener --------------------------------------------------
240 :
241 0 : void SAL_CALL SlideSorterService::disposing (const lang::EventObject& rEvent)
242 : throw (RuntimeException)
243 : {
244 0 : if (rEvent.Source == mxParentWindow)
245 0 : mxParentWindow = NULL;
246 0 : }
247 :
248 :
249 :
250 :
251 : //----- XDrawView -------------------------------------------------------------
252 :
253 0 : void SAL_CALL SlideSorterService::setCurrentPage(const Reference<drawing::XDrawPage>& rxSlide)
254 : throw (RuntimeException)
255 : {
256 0 : ThrowIfDisposed();
257 0 : if (mpSlideSorter.get() != NULL)
258 0 : mpSlideSorter->GetController().GetCurrentSlideManager()->NotifyCurrentSlideChange(
259 0 : mpSlideSorter->GetModel().GetIndex(rxSlide));
260 0 : }
261 :
262 :
263 :
264 :
265 0 : Reference<drawing::XDrawPage> SAL_CALL SlideSorterService::getCurrentPage (void)
266 : throw (RuntimeException)
267 : {
268 0 : ThrowIfDisposed();
269 0 : if (mpSlideSorter.get() != NULL)
270 0 : return mpSlideSorter->GetController().GetCurrentSlideManager()->GetCurrentSlide()->GetXDrawPage();
271 : else
272 0 : return NULL;
273 : }
274 :
275 :
276 :
277 :
278 : //----- attributes ------------------------------------------------------------
279 :
280 :
281 0 : Reference<container::XIndexAccess> SAL_CALL SlideSorterService::getDocumentSlides (void)
282 : throw (RuntimeException)
283 : {
284 0 : return mpSlideSorter->GetModel().GetDocumentSlides();
285 : }
286 :
287 :
288 :
289 :
290 0 : void SAL_CALL SlideSorterService::setDocumentSlides (
291 : const Reference<container::XIndexAccess >& rxSlides)
292 : throw (RuntimeException)
293 : {
294 0 : ThrowIfDisposed();
295 0 : if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
296 0 : mpSlideSorter->GetController().SetDocumentSlides(rxSlides);
297 0 : }
298 :
299 :
300 :
301 :
302 0 : sal_Bool SAL_CALL SlideSorterService::getIsHighlightCurrentSlide (void)
303 : throw (RuntimeException)
304 : {
305 0 : ThrowIfDisposed();
306 0 : if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
307 0 : return false;
308 : else
309 0 : return mpSlideSorter->GetProperties()->IsHighlightCurrentSlide();
310 : }
311 :
312 :
313 :
314 :
315 0 : void SAL_CALL SlideSorterService::setIsHighlightCurrentSlide (sal_Bool bValue)
316 : throw (RuntimeException)
317 : {
318 0 : ThrowIfDisposed();
319 0 : if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
320 : {
321 0 : mpSlideSorter->GetProperties()->SetHighlightCurrentSlide(bValue);
322 0 : controller::SlideSorterController::ModelChangeLock aLock (mpSlideSorter->GetController());
323 0 : mpSlideSorter->GetController().HandleModelChange();
324 : }
325 0 : }
326 :
327 :
328 :
329 :
330 0 : sal_Bool SAL_CALL SlideSorterService::getIsShowSelection (void)
331 : throw (RuntimeException)
332 : {
333 0 : ThrowIfDisposed();
334 0 : if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
335 0 : return false;
336 : else
337 0 : return mpSlideSorter->GetProperties()->IsShowSelection();
338 : }
339 :
340 :
341 :
342 :
343 0 : void SAL_CALL SlideSorterService::setIsShowSelection (sal_Bool bValue)
344 : throw (RuntimeException)
345 : {
346 0 : ThrowIfDisposed();
347 0 : if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
348 0 : mpSlideSorter->GetProperties()->SetShowSelection(bValue);
349 0 : }
350 :
351 :
352 :
353 :
354 0 : sal_Bool SAL_CALL SlideSorterService::getIsShowFocus (void)
355 : throw (RuntimeException)
356 : {
357 0 : ThrowIfDisposed();
358 0 : if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
359 0 : return false;
360 : else
361 0 : return mpSlideSorter->GetProperties()->IsShowFocus();
362 : }
363 :
364 :
365 :
366 :
367 0 : void SAL_CALL SlideSorterService::setIsShowFocus (sal_Bool bValue)
368 : throw (RuntimeException)
369 : {
370 0 : ThrowIfDisposed();
371 0 : if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
372 0 : mpSlideSorter->GetProperties()->SetShowFocus(bValue);
373 0 : }
374 :
375 :
376 :
377 :
378 0 : sal_Bool SAL_CALL SlideSorterService::getIsCenterSelection (void)
379 : throw (RuntimeException)
380 : {
381 0 : ThrowIfDisposed();
382 0 : if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
383 0 : return false;
384 : else
385 0 : return mpSlideSorter->GetProperties()->IsCenterSelection();
386 : }
387 :
388 :
389 :
390 :
391 0 : void SAL_CALL SlideSorterService::setIsCenterSelection (sal_Bool bValue)
392 : throw (RuntimeException)
393 : {
394 0 : ThrowIfDisposed();
395 0 : if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
396 0 : mpSlideSorter->GetProperties()->SetCenterSelection(bValue);
397 0 : }
398 :
399 :
400 :
401 :
402 0 : sal_Bool SAL_CALL SlideSorterService::getIsSuspendPreviewUpdatesDuringFullScreenPresentation (void)
403 : throw (RuntimeException)
404 : {
405 0 : ThrowIfDisposed();
406 0 : if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
407 0 : return true;
408 : else
409 : return mpSlideSorter->GetProperties()
410 0 : ->IsSuspendPreviewUpdatesDuringFullScreenPresentation();
411 : }
412 :
413 :
414 :
415 :
416 0 : void SAL_CALL SlideSorterService::setIsSuspendPreviewUpdatesDuringFullScreenPresentation (
417 : sal_Bool bValue)
418 : throw (RuntimeException)
419 : {
420 0 : ThrowIfDisposed();
421 0 : if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
422 : mpSlideSorter->GetProperties()
423 0 : ->SetSuspendPreviewUpdatesDuringFullScreenPresentation(bValue);
424 0 : }
425 :
426 :
427 :
428 :
429 0 : sal_Bool SAL_CALL SlideSorterService::getIsOrientationVertical (void)
430 : throw (RuntimeException)
431 : {
432 0 : ThrowIfDisposed();
433 0 : if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
434 0 : return true;
435 : else
436 0 : return mpSlideSorter->GetView().GetOrientation() != Layouter::HORIZONTAL;
437 : }
438 :
439 :
440 :
441 :
442 0 : void SAL_CALL SlideSorterService::setIsOrientationVertical (sal_Bool bValue)
443 : throw (RuntimeException)
444 : {
445 0 : ThrowIfDisposed();
446 0 : if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
447 0 : mpSlideSorter->GetView().SetOrientation(bValue
448 : ? Layouter::GRID
449 0 : : Layouter::HORIZONTAL);
450 0 : }
451 :
452 :
453 :
454 :
455 0 : sal_Bool SAL_CALL SlideSorterService::getIsSmoothScrolling (void)
456 : throw (RuntimeException)
457 : {
458 0 : ThrowIfDisposed();
459 0 : if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
460 0 : return false;
461 : else
462 0 : return mpSlideSorter->GetProperties()->IsSmoothSelectionScrolling();
463 : }
464 :
465 :
466 :
467 :
468 0 : void SAL_CALL SlideSorterService::setIsSmoothScrolling (sal_Bool bValue)
469 : throw (RuntimeException)
470 : {
471 0 : ThrowIfDisposed();
472 0 : if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
473 0 : mpSlideSorter->GetProperties()->SetSmoothSelectionScrolling(bValue);
474 0 : }
475 :
476 :
477 :
478 :
479 0 : util::Color SAL_CALL SlideSorterService::getBackgroundColor (void)
480 : throw (RuntimeException)
481 : {
482 0 : ThrowIfDisposed();
483 0 : if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
484 0 : return util::Color();
485 : else
486 : return util::Color(
487 0 : mpSlideSorter->GetProperties()->GetBackgroundColor().GetColor());
488 : }
489 :
490 :
491 :
492 :
493 0 : void SAL_CALL SlideSorterService::setBackgroundColor (util::Color aBackgroundColor)
494 : throw (RuntimeException)
495 : {
496 0 : ThrowIfDisposed();
497 0 : if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
498 0 : mpSlideSorter->GetProperties()->SetBackgroundColor(Color(aBackgroundColor));
499 0 : }
500 :
501 :
502 :
503 :
504 0 : util::Color SAL_CALL SlideSorterService::getTextColor (void)
505 : throw (css::uno::RuntimeException)
506 : {
507 0 : ThrowIfDisposed();
508 0 : if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
509 0 : return util::Color();
510 : else
511 : return util::Color(
512 0 : mpSlideSorter->GetProperties()->GetTextColor().GetColor());
513 : }
514 :
515 :
516 :
517 :
518 0 : void SAL_CALL SlideSorterService::setTextColor (util::Color aTextColor)
519 : throw (RuntimeException)
520 : {
521 0 : ThrowIfDisposed();
522 0 : if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
523 0 : mpSlideSorter->GetProperties()->SetTextColor(Color(aTextColor));
524 0 : }
525 :
526 :
527 :
528 :
529 0 : util::Color SAL_CALL SlideSorterService::getSelectionColor (void)
530 : throw (RuntimeException)
531 : {
532 0 : ThrowIfDisposed();
533 0 : if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
534 0 : return util::Color();
535 : else
536 : return util::Color(
537 0 : mpSlideSorter->GetProperties()->GetSelectionColor().GetColor());
538 : }
539 :
540 :
541 :
542 :
543 0 : void SAL_CALL SlideSorterService::setSelectionColor (util::Color aSelectionColor)
544 : throw (RuntimeException)
545 : {
546 0 : ThrowIfDisposed();
547 0 : if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
548 0 : mpSlideSorter->GetProperties()->SetSelectionColor(Color(aSelectionColor));
549 0 : }
550 :
551 :
552 :
553 :
554 0 : util::Color SAL_CALL SlideSorterService::getHighlightColor (void)
555 : throw (RuntimeException)
556 : {
557 0 : ThrowIfDisposed();
558 0 : if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
559 0 : return util::Color();
560 : else
561 : return util::Color(
562 0 : mpSlideSorter->GetProperties()->GetHighlightColor().GetColor());
563 : }
564 :
565 :
566 :
567 :
568 0 : void SAL_CALL SlideSorterService::setHighlightColor (util::Color aHighlightColor)
569 : throw (RuntimeException)
570 : {
571 0 : ThrowIfDisposed();
572 0 : if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
573 0 : mpSlideSorter->GetProperties()->SetHighlightColor(Color(aHighlightColor));
574 0 : }
575 :
576 :
577 :
578 0 : sal_Bool SAL_CALL SlideSorterService::getIsUIReadOnly (void)
579 : throw (RuntimeException)
580 : {
581 0 : ThrowIfDisposed();
582 0 : if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
583 0 : return true;
584 : else
585 0 : return mpSlideSorter->GetProperties()->IsUIReadOnly();
586 : }
587 :
588 :
589 :
590 :
591 0 : void SAL_CALL SlideSorterService::setIsUIReadOnly (sal_Bool bIsUIReadOnly)
592 : throw (RuntimeException)
593 : {
594 0 : ThrowIfDisposed();
595 0 : if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
596 0 : mpSlideSorter->GetProperties()->SetUIReadOnly(bIsUIReadOnly);
597 0 : }
598 :
599 :
600 :
601 :
602 : //-----------------------------------------------------------------------------
603 :
604 0 : void SlideSorterService::Resize (void)
605 : {
606 0 : if (mxParentWindow.is())
607 : {
608 0 : awt::Rectangle aWindowBox = mxParentWindow->getPosSize();
609 : mpSlideSorter->ArrangeGUIElements(
610 : Point(0,0),
611 0 : Size(aWindowBox.Width, aWindowBox.Height));
612 : }
613 0 : }
614 :
615 :
616 :
617 :
618 0 : void SlideSorterService::ThrowIfDisposed (void)
619 : throw (::com::sun::star::lang::DisposedException)
620 : {
621 0 : if (SlideSorterServiceInterfaceBase::rBHelper.bDisposed || SlideSorterServiceInterfaceBase::rBHelper.bInDispose)
622 : {
623 : throw lang::DisposedException ("SlideSorterService object has already been disposed",
624 0 : static_cast<drawing::XDrawView*>(this));
625 : }
626 0 : }
627 :
628 :
629 33 : } } // end of namespace ::sd::presenter
630 :
631 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|