xref: /trunk/main/sd/source/ui/framework/module/CenterViewFocusModule.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 "CenterViewFocusModule.hxx"
27 
28 #include "framework/ConfigurationController.hxx"
29 #include "framework/FrameworkHelper.hxx"
30 #include "framework/ViewShellWrapper.hxx"
31 
32 #include "DrawController.hxx"
33 #include "ViewShellBase.hxx"
34 #include "ViewShellManager.hxx"
35 #include "strings.hrc"
36 #include "sdresid.hxx"
37 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
38 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
39 
40 #include <toolkit/awt/vclxdevice.hxx>
41 #include <sfx2/viewfrm.hxx>
42 
43 using namespace ::com::sun::star;
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::drawing::framework;
46 
47 using ::rtl::OUString;
48 using ::sd::framework::FrameworkHelper;
49 
50 
51 namespace sd { namespace framework {
52 
53 //===== CenterViewFocusModule ====================================================
54 
CenterViewFocusModule(Reference<frame::XController> & rxController)55 CenterViewFocusModule::CenterViewFocusModule (Reference<frame::XController>& rxController)
56     : CenterViewFocusModuleInterfaceBase(MutexOwner::maMutex),
57       mbValid(false),
58       mxConfigurationController(),
59       mpBase(NULL),
60       mbNewViewCreated(false)
61 {
62     Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
63     if (xControllerManager.is())
64     {
65         mxConfigurationController = xControllerManager->getConfigurationController();
66 
67         // Tunnel through the controller to obtain a ViewShellBase.
68         Reference<lang::XUnoTunnel> xTunnel (rxController, UNO_QUERY);
69         if (xTunnel.is())
70         {
71             ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
72                 xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
73             if (pController != NULL)
74                 mpBase = pController->GetViewShellBase();
75         }
76 
77         // Check, if all required objects do exist.
78         if (mxConfigurationController.is() && mpBase!=NULL)
79         {
80             mbValid = true;
81         }
82     }
83 
84     if (mbValid)
85     {
86         mxConfigurationController->addConfigurationChangeListener(
87             this,
88             FrameworkHelper::msConfigurationUpdateEndEvent,
89             Any());
90         mxConfigurationController->addConfigurationChangeListener(
91             this,
92             FrameworkHelper::msResourceActivationEvent,
93             Any());
94     }
95 }
96 
97 
98 
99 
~CenterViewFocusModule(void)100 CenterViewFocusModule::~CenterViewFocusModule (void)
101 {
102 }
103 
104 
105 
106 
disposing(void)107 void SAL_CALL CenterViewFocusModule::disposing (void)
108 {
109     if (mxConfigurationController.is())
110         mxConfigurationController->removeConfigurationChangeListener(this);
111 
112     mbValid = false;
113     mxConfigurationController = NULL;
114     mpBase = NULL;
115 }
116 
117 
118 
119 
notifyConfigurationChange(const ConfigurationChangeEvent & rEvent)120 void SAL_CALL CenterViewFocusModule::notifyConfigurationChange (
121     const ConfigurationChangeEvent& rEvent)
122 {
123     if (mbValid)
124     {
125         if (rEvent.Type.equals(FrameworkHelper::msConfigurationUpdateEndEvent))
126         {
127             HandleNewView(rEvent.Configuration);
128         }
129         else if (rEvent.Type.equals(FrameworkHelper::msResourceActivationEvent))
130         {
131             if (rEvent.ResourceId->getResourceURL().match(FrameworkHelper::msViewURLPrefix))
132                 mbNewViewCreated = true;
133         }
134     }
135 }
136 
137 
138 
139 
HandleNewView(const Reference<XConfiguration> & rxConfiguration)140 void CenterViewFocusModule::HandleNewView (
141     const Reference<XConfiguration>& rxConfiguration)
142 {
143     if (mbNewViewCreated)
144     {
145         mbNewViewCreated = false;
146         // Make the center pane the active one.  Tunnel through the
147         // controller to obtain a ViewShell pointer.
148 
149         Sequence<Reference<XResourceId> > xViewIds (rxConfiguration->getResources(
150             FrameworkHelper::CreateResourceId(FrameworkHelper::msCenterPaneURL),
151             FrameworkHelper::msViewURLPrefix,
152             AnchorBindingMode_DIRECT));
153         Reference<XView> xView;
154         if (xViewIds.getLength() > 0)
155             xView = Reference<XView>(
156                 mxConfigurationController->getResource(xViewIds[0]),UNO_QUERY);
157         Reference<lang::XUnoTunnel> xTunnel (xView, UNO_QUERY);
158         if (xTunnel.is() && mpBase!=NULL)
159         {
160             ViewShellWrapper* pViewShellWrapper = reinterpret_cast<ViewShellWrapper*>(
161                 xTunnel->getSomething(ViewShellWrapper::getUnoTunnelId()));
162             if (pViewShellWrapper != NULL)
163             {
164                 ::boost::shared_ptr<ViewShell> pViewShell = pViewShellWrapper->GetViewShell();
165                 if (pViewShell.get() != NULL)
166                     mpBase->GetViewShellManager()->MoveToTop(*pViewShell);
167             }
168         }
169     }
170 }
171 
172 
173 
174 
disposing(const lang::EventObject & rEvent)175 void SAL_CALL CenterViewFocusModule::disposing (
176     const lang::EventObject& rEvent)
177 {
178     if (mxConfigurationController.is())
179         if (rEvent.Source == mxConfigurationController)
180         {
181             mbValid = false;
182             mxConfigurationController = NULL;
183             mpBase = NULL;
184         }
185 }
186 
187 
188 
189 } } // end of namespace sd::framework
190