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 "SlsHideSlideFunction.hxx"
27 
28 #include "SlideSorter.hxx"
29 #include "model/SlsPageEnumerationProvider.hxx"
30 #include "model/SlsPageDescriptor.hxx"
31 #include "view/SlideSorterView.hxx"
32 
33 #include "app.hrc"
34 #include "drawdoc.hxx"
35 #include "sdpage.hxx"
36 #include "ViewShell.hxx"
37 
38 #include <sfx2/viewfrm.hxx>
39 #include <sfx2/bindings.hxx>
40 #include <sfx2/request.hxx>
41 #include <svx/svxids.hrc>
42 
43 namespace sd { namespace slidesorter { namespace controller {
44 
45 TYPEINIT1(HideSlideFunction, SlideFunction);
46 
HideSlideFunction(SlideSorter & rSlideSorter,SfxRequest & rRequest)47 HideSlideFunction::HideSlideFunction (
48     SlideSorter& rSlideSorter,
49     SfxRequest& rRequest)
50     : SlideFunction( rSlideSorter, rRequest),
51       mrSlideSorter(rSlideSorter)
52 {
53 }
54 
55 
56 
57 
~HideSlideFunction(void)58 HideSlideFunction::~HideSlideFunction (void)
59 {
60 }
61 
62 
63 
64 
Create(SlideSorter & rSlideSorter,SfxRequest & rRequest)65 FunctionReference HideSlideFunction::Create (
66     SlideSorter& rSlideSorter,
67     SfxRequest& rRequest )
68 {
69 	FunctionReference xFunc( new HideSlideFunction( rSlideSorter, rRequest ) );
70 	xFunc->DoExecute(rRequest);
71 	return xFunc;
72 }
73 
74 
75 
76 
DoExecute(SfxRequest & rRequest)77 void HideSlideFunction::DoExecute (SfxRequest& rRequest)
78 {
79 	SlideFunction::DoExecute(rRequest);
80 
81     model::PageEnumeration aSelectedPages (
82         model::PageEnumerationProvider::CreateSelectedPagesEnumeration(mrSlideSorter.GetModel()));
83 
84     ExclusionState eState (UNDEFINED);
85 
86     switch (rRequest.GetSlot())
87 	{
88 		case SID_HIDE_SLIDE:
89             eState = EXCLUDED;
90             break;
91 
92         case SID_SHOW_SLIDE:
93             eState = INCLUDED;
94             break;
95 
96         default:
97             eState = UNDEFINED;
98             break;
99     }
100 
101     if (eState != UNDEFINED)
102     {
103         // Set status at the selected pages.
104         aSelectedPages.Rewind ();
105         while (aSelectedPages.HasMoreElements())
106         {
107             model::SharedPageDescriptor pDescriptor (aSelectedPages.GetNextElement());
108             static_cast<view::SlideSorterView*>(mpView)->SetState(
109                 pDescriptor,
110                 model::PageDescriptor::ST_Excluded,
111                 eState==EXCLUDED);
112         }
113     }
114 
115 	SfxBindings& rBindings = mpViewShell->GetViewFrame()->GetBindings();
116 	rBindings.Invalidate (SID_PRESENTATION);
117 	rBindings.Invalidate (SID_REHEARSE_TIMINGS);
118 	rBindings.Invalidate (SID_HIDE_SLIDE);
119 	rBindings.Invalidate (SID_SHOW_SLIDE);
120 	mpDoc->SetChanged();
121 }
122 
123 
124 
125 
GetExclusionState(model::PageEnumeration & rPageSet)126 HideSlideFunction::ExclusionState HideSlideFunction::GetExclusionState (
127     model::PageEnumeration& rPageSet)
128 {
129     ExclusionState eState (UNDEFINED);
130 	sal_Bool bState;
131 
132     // Get toggle state of the selected pages.
133     while (rPageSet.HasMoreElements() && eState!=MIXED)
134     {
135         bState = rPageSet.GetNextElement()->GetPage()->IsExcluded();
136         switch (eState)
137         {
138             case UNDEFINED:
139                 // Use the first selected page to set the inital value.
140                 eState = bState ? EXCLUDED : INCLUDED;
141                 break;
142 
143             case EXCLUDED:
144                 // The pages before where all not part of the show,
145                 // this one is.
146                 if ( ! bState)
147                     eState = MIXED;
148                 break;
149 
150             case INCLUDED:
151                 // The pages before where all part of the show,
152                 // this one is not.
153                 if (bState)
154                     eState = MIXED;
155                 break;
156 
157             case MIXED:
158             default:
159                 // No need to change anything.
160                 break;
161         }
162     }
163 
164     return eState;
165 }
166 
167 } } } // end of namespace ::sd::slidesorter::controller
168