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 "precompiled_sfx2.hxx"
23 
24 #include "SidebarPanel.hxx"
25 
26 #include "Panel.hxx"
27 #include "sfx2/sidebar/Theme.hxx"
28 
29 #include <vos/mutex.hxx>
30 #include <vcl/svapp.hxx>
31 #include <svl/smplhint.hxx>
32 #include <comphelper/componentcontext.hxx>
33 #include <comphelper/processfactory.hxx>
34 #include <com/sun/star/awt/XWindowPeer.hpp>
35 
36 
37 using namespace css;
38 using namespace cssu;
39 
40 namespace sfx2 { namespace sidebar {
41 
Create(Panel * pPanel)42 Reference<css::ui::XSidebarPanel> SidebarPanel::Create (Panel* pPanel)
43 {
44     return Reference<css::ui::XSidebarPanel>(new SidebarPanel(pPanel));
45 }
46 
47 
48 
49 
SidebarPanel(Panel * pPanel)50 SidebarPanel::SidebarPanel(Panel* pPanel)
51     : SidebarPanelInterfaceBase(m_aMutex),
52       mpPanel(pPanel),
53       mxCanvas()
54 {
55     if (mpPanel != NULL)
56         mpPanel->AddEventListener(LINK(this, SidebarPanel, HandleWindowEvent));
57     else
58     {
59         mpPanel = NULL;
60         dispose();
61     }
62 }
63 
64 
65 
66 
~SidebarPanel(void)67 SidebarPanel::~SidebarPanel (void)
68 {
69 }
70 
71 
72 
73 
disposing(const css::lang::EventObject & rEventObject)74 void SAL_CALL SidebarPanel::disposing (const css::lang::EventObject& rEventObject)
75     throw(cssu::RuntimeException)
76 {
77     (void)rEventObject;
78 }
79 
80 
81 
82 
disposing(void)83 void SAL_CALL SidebarPanel::disposing (void)
84 {
85     if (mpPanel != NULL)
86     {
87         mpPanel->RemoveEventListener(LINK(this, SidebarPanel, HandleWindowEvent));
88         mpPanel = NULL;
89     }
90 }
91 
92 
93 
94 
getCanvas(void)95 cssu::Reference<css::rendering::XCanvas> SAL_CALL SidebarPanel::getCanvas (void)
96     throw (cssu::RuntimeException)
97 {
98     if ( ! mxCanvas.is())
99     {
100         Sequence<Any> aArg (5);
101 
102         // common: first any is VCL pointer to window (for VCL canvas)
103         aArg[0] = makeAny(reinterpret_cast<sal_Int64>(mpPanel));
104         aArg[1] = Any();
105         aArg[2] = makeAny(::com::sun::star::awt::Rectangle());
106         aArg[3] = makeAny(sal_False);
107         aArg[4] = makeAny(mpPanel->GetComponentInterface());
108 
109         const ::comphelper::ComponentContext aComponentContext (::comphelper::getProcessServiceFactory());
110         mxCanvas = Reference<rendering::XCanvas>(
111             aComponentContext.createComponentWithArguments(
112                 "com.sun.star.rendering.VCLCanvas",
113                 aArg),
114             UNO_QUERY);
115     }
116 
117     return mxCanvas;
118 
119 }
120 
121 
122 
123 
getPositionOnScreen(void)124 awt::Point SAL_CALL SidebarPanel::getPositionOnScreen (void)
125     throw (cssu::RuntimeException)
126 {
127     awt::Point aAwtPoint;
128 
129     if (mpPanel != NULL)
130     {
131         ::vos::OGuard aGuard (Application::GetSolarMutex());
132 
133         //        mpPanel->GetPosPixel()
134         const Point aLocationOnScreen (mpPanel->OutputToAbsoluteScreenPixel(Point(0,0)));
135 
136         aAwtPoint.X = aLocationOnScreen.X();
137         aAwtPoint.Y = aLocationOnScreen.Y();
138     }
139 
140     return aAwtPoint;
141 }
142 
143 
144 
145 
getThemeProperties(void)146 Reference<beans::XPropertySet> SAL_CALL SidebarPanel::getThemeProperties (void)
147     throw (RuntimeException)
148 {
149     return Theme::GetPropertySet();
150 }
151 
152 
153 
154 
IMPL_LINK(SidebarPanel,HandleWindowEvent,VclWindowEvent *,pEvent)155 IMPL_LINK(SidebarPanel, HandleWindowEvent, VclWindowEvent*, pEvent)
156 {
157     if (pEvent != NULL)
158     {
159         switch (pEvent->GetId())
160         {
161             case SFX_HINT_DYING:
162                 dispose();
163                 break;
164 
165             default:
166                 break;
167         }
168     }
169 
170     return sal_True;
171 }
172 
173 
174 
175 } } // end of namespace sfx2::sidebar
176