1  /**************************************************************
2   *
3   * Licensed to the Apache Software Foundation (ASF) under one
4   * or more contributor license agreements.  See the NOTICE file
5   * distributed with this work for additional information
6   * regarding copyright ownership.  The ASF licenses this file
7   * to you under the Apache License, Version 2.0 (the
8   * "License"); you may not use this file except in compliance
9   * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   *
20   *************************************************************/
21  
22  
23  
24  #include "precompiled_sd.hxx"
25  
26  #include "SlideSorter.hxx"
27  #include "controller/SlideSorterController.hxx"
28  #include "controller/SlsSelectionManager.hxx"
29  #include "controller/SlsSelectionObserver.hxx"
30  #include "controller/SlsPageSelector.hxx"
31  #include "controller/SlsFocusManager.hxx"
32  #include "model/SlideSorterModel.hxx"
33  #include "model/SlsPageDescriptor.hxx"
34  #include <svx/svdmodel.hxx>
35  #include "drawdoc.hxx"
36  
37  
38  namespace sd { namespace slidesorter { namespace controller {
39  
Context(SlideSorter & rSlideSorter)40  SelectionObserver::Context::Context (SlideSorter& rSlideSorter)
41      : mpSelectionObserver(
42          rSlideSorter.GetController().GetSelectionManager()->GetSelectionObserver())
43  {
44      if (mpSelectionObserver)
45          mpSelectionObserver->StartObservation();
46  }
47  
48  
49  
50  
~Context(void)51  SelectionObserver::Context::~Context(void)
52  {
53      if (mpSelectionObserver)
54          mpSelectionObserver->EndObservation();
55  }
56  
57  
58  
59  
Abort(void)60  void SelectionObserver::Context::Abort(void)
61  {
62      if (mpSelectionObserver)
63      {
64          mpSelectionObserver->AbortObservation();
65          mpSelectionObserver.reset();
66      }
67  }
68  
69  
70  
71  
72  //===== SelectionObserver =====================================================
73  
SelectionObserver(SlideSorter & rSlideSorter)74  SelectionObserver::SelectionObserver (SlideSorter& rSlideSorter)
75      : mrSlideSorter(rSlideSorter),
76        mpDocument(mrSlideSorter.GetModel().GetDocument()),
77        mbIsOvservationActive(false),
78        maInsertedPages(),
79        maDeletedPages()
80  {
81  }
82  
83  
84  
85  
~SelectionObserver(void)86  SelectionObserver::~SelectionObserver (void)
87  {
88  }
89  
90  
91  
92  
NotifyPageEvent(const SdrPage * pSdrPage)93  void SelectionObserver::NotifyPageEvent (const SdrPage* pSdrPage)
94  {
95      if ( ! mbIsOvservationActive)
96          return;
97  
98      const SdPage* pPage = dynamic_cast<const SdPage*>(pSdrPage);
99      if (pPage == NULL)
100          return;
101  
102      if (pPage->IsInserted())
103          maInsertedPages.push_back(pPage);
104      else
105      {
106          ::std::vector<const SdPage*>::iterator iPage(
107              ::std::find(maInsertedPages.begin(), maInsertedPages.end(), pPage));
108          if (iPage != maInsertedPages.end())
109              maInsertedPages.erase(iPage);
110  
111          maDeletedPages.push_back(pPage->GetPageNum());
112      }
113  }
114  
115  
116  
StartObservation(void)117  void SelectionObserver::StartObservation (void)
118  {
119      OSL_ASSERT(!mbIsOvservationActive);
120      maInsertedPages.clear();
121      maDeletedPages.clear();
122      mbIsOvservationActive = true;
123  }
124  
125  
126  
127  
AbortObservation(void)128  void SelectionObserver::AbortObservation (void)
129  {
130      OSL_ASSERT(mbIsOvservationActive);
131      mbIsOvservationActive = false;
132      maInsertedPages.clear();
133      maDeletedPages.clear();
134  }
135  
136  
137  
138  
EndObservation(void)139  void SelectionObserver::EndObservation (void)
140  {
141      OSL_ASSERT(mbIsOvservationActive);
142      mbIsOvservationActive = false;
143  
144      PageSelector& rSelector (mrSlideSorter.GetController().GetPageSelector());
145      PageSelector::UpdateLock aUpdateLock (mrSlideSorter);
146      rSelector.DeselectAllPages();
147      if ( ! maInsertedPages.empty())
148      {
149          // Select the inserted pages.
150          for (::std::vector<const SdPage*>::const_iterator
151                   iPage(maInsertedPages.begin()),
152                   iEnd(maInsertedPages.end());
153               iPage!=iEnd;
154               ++iPage)
155          {
156              rSelector.SelectPage(*iPage);
157          }
158          maInsertedPages.clear();
159      }
160      maDeletedPages.clear();
161  
162      aUpdateLock.Release();
163      mrSlideSorter.GetController().GetFocusManager().SetFocusedPageToCurrentPage();
164  
165  }
166  
167  
168  
169  } } } // end of namespace ::sd::slidesorter::controller
170