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