xref: /trunk/main/svx/source/sidebar/SelectionChangeHandler.cxx (revision 45c5a00162811bd03b87fcb4fe9996782f2b59ec)
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<rtl::OUString(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 {
62     if (maSelectionChangeCallback)
63     {
64         const EnumContext::Context eContext (
65             EnumContext::GetContextEnum(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 {
79 }
80 
81 
82 
83 
84 void SAL_CALL SelectionChangeHandler::disposing (void)
85 {
86     if (mbIsConnected)
87         Disconnect();
88 }
89 
90 
91 
92 
93 void SelectionChangeHandler::Connect (void)
94 {
95     uno::Reference<view::XSelectionSupplier> xSupplier (mxController, uno::UNO_QUERY);
96     if (xSupplier.is())
97     {
98         mbIsConnected = true;
99         xSupplier->addSelectionChangeListener(this);
100     }
101 }
102 
103 
104 
105 
106 void SelectionChangeHandler::Disconnect (void)
107 {
108     uno::Reference<view::XSelectionSupplier> xSupplier (mxController, uno::UNO_QUERY);
109     if (xSupplier.is())
110     {
111         mbIsConnected = false;
112         xSupplier->removeSelectionChangeListener(this);
113     }
114 }
115 
116 
117 } } // end of namespace svx::sidebar
118