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 #ifndef SD_SLIDESORTER_CONTROLLER_SELECTION_OBSERVER_HXX
25 #define SD_SLIDESORTER_CONTROLLER_SELECTION_OBSERVER_HXX
26 
27 #include <tools/gen.hxx>
28 #include <vector>
29 #include <boost/shared_ptr.hpp>
30 
31 namespace sd { namespace slidesorter {
32 class SlideSorter;
33 } }
34 
35 class SdDrawDocument;
36 class SdrPage;
37 
38 namespace sd { namespace slidesorter { namespace controller {
39 
40 /** Observe insertions and deletions of pages between calls to
41     StartObservation() and EndObservation().  When the later is called
42     the selection is set to just the newly inserted pages.
43 */
44 class SelectionObserver
45 {
46 public:
47     SelectionObserver (SlideSorter& rSlideSorter);
48     virtual ~SelectionObserver (void);
49 
50     void NotifyPageEvent (const SdrPage* pPage);
51     void StartObservation (void);
52     void AbortObservation (void);
53     void EndObservation (void);
54 
55     /** Use this little class instead of calling StartObservation and
56         EndObservation directly so that EndObservation is not forgotten or
57         omitted due to an exception or some break or return in the middle of
58         code.
59     */
60     class Context
61     {
62     public:
63         Context (SlideSorter& rSlideSorter);
64         ~Context(void);
65         void Abort (void);
66     private:
67         ::boost::shared_ptr<SelectionObserver> mpSelectionObserver;
68     };
69 
70 private:
71     SlideSorter& mrSlideSorter;
72     SdDrawDocument* mpDocument;
73     bool mbIsOvservationActive;
74 
75     ::std::vector<const SdPage*> maInsertedPages;
76     ::std::vector<sal_Int32> maDeletedPages;
77 };
78 
79 } } } // end of namespace ::sd::slidesorter::controller
80 
81 #endif
82