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 #include "svx/sidebar/SelectionChangeHandler.hxx"
23 #include "svx/sidebar/SelectionAnalyzer.hxx"
24 #include "svx/sidebar/ContextChangeEventMultiplexer.hxx"
25 #include "svx/svdmrkv.hxx"
26 
27 #include <sfx2/sidebar/EnumContext.hxx>
28 #include <sfx2/shell.hxx>
29 
30 
31 using namespace css;
32 using namespace cssu;
33 
34 using namespace sfx2::sidebar;
35 
36 namespace svx { namespace sidebar {
37 
38 SelectionChangeHandler::SelectionChangeHandler (
39     const boost::function<sfx2::sidebar::EnumContext::Context(void)>& rSelectionChangeCallback,
40     const Reference<frame::XController>& rxController,
41     const EnumContext::Context eDefaultContext)
42     : SelectionChangeHandlerInterfaceBase(m_aMutex),
43       maSelectionChangeCallback(rSelectionChangeCallback),
44       mxController(rxController),
45       meDefaultContext(eDefaultContext),
46       mbIsConnected(false)
47 {
48 }
49 
50 
51 
52 
53 SelectionChangeHandler::~SelectionChangeHandler (void)
54 {
55 }
56 
57 
58 
59 
60 void SAL_CALL SelectionChangeHandler::selectionChanged (const lang::EventObject&)
61     throw (uno::RuntimeException)
62 {
63     if (maSelectionChangeCallback)
64     {
65         const EnumContext::Context eContext (maSelectionChangeCallback());
66         ContextChangeEventMultiplexer::NotifyContextChange(
67             mxController,
68             eContext==EnumContext::Context_Unknown
69                 ? meDefaultContext
70                 : eContext);
71     }
72 }
73 
74 
75 
76 
77 void SAL_CALL SelectionChangeHandler::disposing (const lang::EventObject&)
78     throw (uno::RuntimeException)
79 {
80 }
81 
82 
83 
84 
85 void SAL_CALL SelectionChangeHandler::disposing (void)
86     throw (uno::RuntimeException)
87 {
88     if (mbIsConnected)
89         Disconnect();
90 }
91 
92 
93 
94 
95 void SelectionChangeHandler::Connect (void)
96 {
97     uno::Reference<view::XSelectionSupplier> xSupplier (mxController, uno::UNO_QUERY);
98     if (xSupplier.is())
99     {
100         mbIsConnected = true;
101         xSupplier->addSelectionChangeListener(this);
102     }
103 }
104 
105 
106 
107 
108 void SelectionChangeHandler::Disconnect (void)
109 {
110     uno::Reference<view::XSelectionSupplier> xSupplier (mxController, uno::UNO_QUERY);
111     if (xSupplier.is())
112     {
113         mbIsConnected = false;
114         xSupplier->removeSelectionChangeListener(this);
115     }
116 }
117 
118 
119 } } // end of namespace svx::sidebar
120