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