xref: /AOO41X/main/sd/source/ui/slidesorter/controller/SlsSelectionObserver.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "precompiled_sd.hxx"
29 
30 #include "SlideSorter.hxx"
31 #include "controller/SlideSorterController.hxx"
32 #include "controller/SlsSelectionManager.hxx"
33 #include "controller/SlsSelectionObserver.hxx"
34 #include "controller/SlsPageSelector.hxx"
35 #include "controller/SlsFocusManager.hxx"
36 #include "model/SlideSorterModel.hxx"
37 #include "model/SlsPageDescriptor.hxx"
38 #include <svx/svdmodel.hxx>
39 #include "drawdoc.hxx"
40 
41 
42 namespace sd { namespace slidesorter { namespace controller {
43 
44 SelectionObserver::Context::Context (SlideSorter& rSlideSorter)
45     : mpSelectionObserver(
46         rSlideSorter.GetController().GetSelectionManager()->GetSelectionObserver())
47 {
48     if (mpSelectionObserver)
49         mpSelectionObserver->StartObservation();
50 }
51 
52 
53 
54 
55 SelectionObserver::Context::~Context(void)
56 {
57     if (mpSelectionObserver)
58         mpSelectionObserver->EndObservation();
59 }
60 
61 
62 
63 
64 void SelectionObserver::Context::Abort(void)
65 {
66     if (mpSelectionObserver)
67     {
68         mpSelectionObserver->AbortObservation();
69         mpSelectionObserver.reset();
70     }
71 }
72 
73 
74 
75 
76 //===== SelectionObserver =====================================================
77 
78 SelectionObserver::SelectionObserver (SlideSorter& rSlideSorter)
79     : mrSlideSorter(rSlideSorter),
80       mpDocument(mrSlideSorter.GetModel().GetDocument()),
81       mbIsOvservationActive(false),
82       maInsertedPages(),
83       maDeletedPages()
84 {
85 }
86 
87 
88 
89 
90 SelectionObserver::~SelectionObserver (void)
91 {
92 }
93 
94 
95 
96 
97 void SelectionObserver::NotifyPageEvent (const SdrPage* pSdrPage)
98 {
99     if ( ! mbIsOvservationActive)
100         return;
101 
102     const SdPage* pPage = dynamic_cast<const SdPage*>(pSdrPage);
103     if (pPage == NULL)
104         return;
105 
106     if (pPage->IsInserted())
107         maInsertedPages.push_back(pPage);
108     else
109     {
110         ::std::vector<const SdPage*>::iterator iPage(
111             ::std::find(maInsertedPages.begin(), maInsertedPages.end(), pPage));
112         if (iPage != maInsertedPages.end())
113             maInsertedPages.erase(iPage);
114 
115         maDeletedPages.push_back(pPage->GetPageNum());
116     }
117 }
118 
119 
120 
121 void SelectionObserver::StartObservation (void)
122 {
123     OSL_ASSERT(!mbIsOvservationActive);
124     maInsertedPages.clear();
125     maDeletedPages.clear();
126     mbIsOvservationActive = true;
127 }
128 
129 
130 
131 
132 void SelectionObserver::AbortObservation (void)
133 {
134     OSL_ASSERT(mbIsOvservationActive);
135     mbIsOvservationActive = false;
136     maInsertedPages.clear();
137     maDeletedPages.clear();
138 }
139 
140 
141 
142 
143 void SelectionObserver::EndObservation (void)
144 {
145     OSL_ASSERT(mbIsOvservationActive);
146     mbIsOvservationActive = false;
147 
148     PageSelector& rSelector (mrSlideSorter.GetController().GetPageSelector());
149     PageSelector::UpdateLock aUpdateLock (mrSlideSorter);
150     rSelector.DeselectAllPages();
151     if ( ! maInsertedPages.empty())
152     {
153         // Select the inserted pages.
154         for (::std::vector<const SdPage*>::const_iterator
155                  iPage(maInsertedPages.begin()),
156                  iEnd(maInsertedPages.end());
157              iPage!=iEnd;
158              ++iPage)
159         {
160             rSelector.SelectPage(*iPage);
161         }
162         maInsertedPages.clear();
163     }
164     maDeletedPages.clear();
165 
166     aUpdateLock.Release();
167     mrSlideSorter.GetController().GetFocusManager().SetFocusedPageToCurrentPage();
168 
169 }
170 
171 
172 
173 } } } // end of namespace ::sd::slidesorter::controller
174