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 {
76 (void)rEventObject;
77 }
78
79
80
81
disposing(void)82 void SAL_CALL SidebarPanel::disposing (void)
83 {
84 if (mpPanel != NULL)
85 {
86 mpPanel->RemoveEventListener(LINK(this, SidebarPanel, HandleWindowEvent));
87 mpPanel = NULL;
88 }
89 }
90
91
92
93
getCanvas(void)94 cssu::Reference<css::rendering::XCanvas> SAL_CALL SidebarPanel::getCanvas (void)
95 {
96 if ( ! mxCanvas.is())
97 {
98 Sequence<Any> aArg (5);
99
100 // common: first any is VCL pointer to window (for VCL canvas)
101 aArg[0] = makeAny(reinterpret_cast<sal_Int64>(mpPanel));
102 aArg[1] = Any();
103 aArg[2] = makeAny(::com::sun::star::awt::Rectangle());
104 aArg[3] = makeAny(sal_False);
105 aArg[4] = makeAny(mpPanel->GetComponentInterface());
106
107 const ::comphelper::ComponentContext aComponentContext (::comphelper::getProcessServiceFactory());
108 mxCanvas = Reference<rendering::XCanvas>(
109 aComponentContext.createComponentWithArguments(
110 "com.sun.star.rendering.VCLCanvas",
111 aArg),
112 UNO_QUERY);
113 }
114
115 return mxCanvas;
116
117 }
118
119
120
121
getPositionOnScreen(void)122 awt::Point SAL_CALL SidebarPanel::getPositionOnScreen (void)
123 {
124 awt::Point aAwtPoint;
125
126 if (mpPanel != NULL)
127 {
128 ::vos::OGuard aGuard (Application::GetSolarMutex());
129
130 // mpPanel->GetPosPixel()
131 const Point aLocationOnScreen (mpPanel->OutputToAbsoluteScreenPixel(Point(0,0)));
132
133 aAwtPoint.X = aLocationOnScreen.X();
134 aAwtPoint.Y = aLocationOnScreen.Y();
135 }
136
137 return aAwtPoint;
138 }
139
140
141
142
getThemeProperties(void)143 Reference<beans::XPropertySet> SAL_CALL SidebarPanel::getThemeProperties (void)
144 {
145 return Theme::GetPropertySet();
146 }
147
148
149
150
IMPL_LINK(SidebarPanel,HandleWindowEvent,VclWindowEvent *,pEvent)151 IMPL_LINK(SidebarPanel, HandleWindowEvent, VclWindowEvent*, pEvent)
152 {
153 if (pEvent != NULL)
154 {
155 switch (pEvent->GetId())
156 {
157 case SFX_HINT_DYING:
158 dispose();
159 break;
160
161 default:
162 break;
163 }
164 }
165
166 return sal_True;
167 }
168
169
170
171 } } // end of namespace sfx2::sidebar
172