xref: /AOO41X/main/svx/source/sidebar/SelectionChangeHandler.cxx (revision 5d39f272d9084beebffa455156ddd8913c39a8d6)
1*5d39f272SZheng Fan /**************************************************************
2*5d39f272SZheng Fan  *
3*5d39f272SZheng Fan  * Licensed to the Apache Software Foundation (ASF) under one
4*5d39f272SZheng Fan  * or more contributor license agreements.  See the NOTICE file
5*5d39f272SZheng Fan  * distributed with this work for additional information
6*5d39f272SZheng Fan  * regarding copyright ownership.  The ASF licenses this file
7*5d39f272SZheng Fan  * to you under the Apache License, Version 2.0 (the
8*5d39f272SZheng Fan  * "License"); you may not use this file except in compliance
9*5d39f272SZheng Fan  * with the License.  You may obtain a copy of the License at
10*5d39f272SZheng Fan  *
11*5d39f272SZheng Fan  *   http://www.apache.org/licenses/LICENSE-2.0
12*5d39f272SZheng Fan  *
13*5d39f272SZheng Fan  * Unless required by applicable law or agreed to in writing,
14*5d39f272SZheng Fan  * software distributed under the License is distributed on an
15*5d39f272SZheng Fan  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5d39f272SZheng Fan  * KIND, either express or implied.  See the License for the
17*5d39f272SZheng Fan  * specific language governing permissions and limitations
18*5d39f272SZheng Fan  * under the License.
19*5d39f272SZheng Fan  *
20*5d39f272SZheng Fan  *************************************************************/
21*5d39f272SZheng Fan 
22*5d39f272SZheng Fan #include "svx/sidebar/SelectionChangeHandler.hxx"
23*5d39f272SZheng Fan #include "svx/sidebar/SelectionAnalyzer.hxx"
24*5d39f272SZheng Fan #include "svx/sidebar/ContextChangeEventMultiplexer.hxx"
25*5d39f272SZheng Fan #include "svx/svdmrkv.hxx"
26*5d39f272SZheng Fan 
27*5d39f272SZheng Fan #include <sfx2/sidebar/EnumContext.hxx>
28*5d39f272SZheng Fan #include <sfx2/shell.hxx>
29*5d39f272SZheng Fan 
30*5d39f272SZheng Fan 
31*5d39f272SZheng Fan using namespace css;
32*5d39f272SZheng Fan using namespace cssu;
33*5d39f272SZheng Fan 
34*5d39f272SZheng Fan using namespace sfx2::sidebar;
35*5d39f272SZheng Fan 
36*5d39f272SZheng Fan namespace svx { namespace sidebar {
37*5d39f272SZheng Fan 
38*5d39f272SZheng Fan SelectionChangeHandler::SelectionChangeHandler (
39*5d39f272SZheng Fan     const boost::function<sfx2::sidebar::EnumContext::Context(void)>& rSelectionChangeCallback,
40*5d39f272SZheng Fan     const Reference<frame::XController>& rxController,
41*5d39f272SZheng Fan     const EnumContext::Context eDefaultContext)
42*5d39f272SZheng Fan     : SelectionChangeHandlerInterfaceBase(m_aMutex),
43*5d39f272SZheng Fan       maSelectionChangeCallback(rSelectionChangeCallback),
44*5d39f272SZheng Fan       mxController(rxController),
45*5d39f272SZheng Fan       meDefaultContext(eDefaultContext),
46*5d39f272SZheng Fan       mbIsConnected(false)
47*5d39f272SZheng Fan {
48*5d39f272SZheng Fan }
49*5d39f272SZheng Fan 
50*5d39f272SZheng Fan 
51*5d39f272SZheng Fan 
52*5d39f272SZheng Fan 
53*5d39f272SZheng Fan SelectionChangeHandler::~SelectionChangeHandler (void)
54*5d39f272SZheng Fan {
55*5d39f272SZheng Fan }
56*5d39f272SZheng Fan 
57*5d39f272SZheng Fan 
58*5d39f272SZheng Fan 
59*5d39f272SZheng Fan 
60*5d39f272SZheng Fan void SAL_CALL SelectionChangeHandler::selectionChanged (const lang::EventObject&)
61*5d39f272SZheng Fan     throw (uno::RuntimeException)
62*5d39f272SZheng Fan {
63*5d39f272SZheng Fan     if (maSelectionChangeCallback)
64*5d39f272SZheng Fan     {
65*5d39f272SZheng Fan         const EnumContext::Context eContext (maSelectionChangeCallback());
66*5d39f272SZheng Fan         ContextChangeEventMultiplexer::NotifyContextChange(
67*5d39f272SZheng Fan             mxController,
68*5d39f272SZheng Fan             eContext==EnumContext::Context_Unknown
69*5d39f272SZheng Fan                 ? meDefaultContext
70*5d39f272SZheng Fan                 : eContext);
71*5d39f272SZheng Fan     }
72*5d39f272SZheng Fan }
73*5d39f272SZheng Fan 
74*5d39f272SZheng Fan 
75*5d39f272SZheng Fan 
76*5d39f272SZheng Fan 
77*5d39f272SZheng Fan void SAL_CALL SelectionChangeHandler::disposing (const lang::EventObject&)
78*5d39f272SZheng Fan     throw (uno::RuntimeException)
79*5d39f272SZheng Fan {
80*5d39f272SZheng Fan }
81*5d39f272SZheng Fan 
82*5d39f272SZheng Fan 
83*5d39f272SZheng Fan 
84*5d39f272SZheng Fan 
85*5d39f272SZheng Fan void SAL_CALL SelectionChangeHandler::disposing (void)
86*5d39f272SZheng Fan     throw (uno::RuntimeException)
87*5d39f272SZheng Fan {
88*5d39f272SZheng Fan     if (mbIsConnected)
89*5d39f272SZheng Fan         Disconnect();
90*5d39f272SZheng Fan }
91*5d39f272SZheng Fan 
92*5d39f272SZheng Fan 
93*5d39f272SZheng Fan 
94*5d39f272SZheng Fan 
95*5d39f272SZheng Fan void SelectionChangeHandler::Connect (void)
96*5d39f272SZheng Fan {
97*5d39f272SZheng Fan     uno::Reference<view::XSelectionSupplier> xSupplier (mxController, uno::UNO_QUERY);
98*5d39f272SZheng Fan     if (xSupplier.is())
99*5d39f272SZheng Fan     {
100*5d39f272SZheng Fan         mbIsConnected = true;
101*5d39f272SZheng Fan         xSupplier->addSelectionChangeListener(this);
102*5d39f272SZheng Fan     }
103*5d39f272SZheng Fan }
104*5d39f272SZheng Fan 
105*5d39f272SZheng Fan 
106*5d39f272SZheng Fan 
107*5d39f272SZheng Fan 
108*5d39f272SZheng Fan void SelectionChangeHandler::Disconnect (void)
109*5d39f272SZheng Fan {
110*5d39f272SZheng Fan     uno::Reference<view::XSelectionSupplier> xSupplier (mxController, uno::UNO_QUERY);
111*5d39f272SZheng Fan     if (xSupplier.is())
112*5d39f272SZheng Fan     {
113*5d39f272SZheng Fan         mbIsConnected = false;
114*5d39f272SZheng Fan         xSupplier->removeSelectionChangeListener(this);
115*5d39f272SZheng Fan     }
116*5d39f272SZheng Fan }
117*5d39f272SZheng Fan 
118*5d39f272SZheng Fan 
119*5d39f272SZheng Fan } } // end of namespace svx::sidebar
120