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_sd.hxx"
23
24 #include "framework/TaskPanelResource.hxx"
25
26 #include <vcl/window.hxx>
27 #include <toolkit/helper/vclunohelper.hxx>
28
29
30 using namespace css;
31 using namespace cssu;
32 using namespace cssdf;
33
34
35 namespace sd { namespace framework {
36
37 namespace {
GetWindowForResource(ViewShellBase & rViewShellBase,const cssu::Reference<cssdf::XResourceId> & rxResourceId)38 ::Window* GetWindowForResource (
39 ViewShellBase& rViewShellBase,
40 const cssu::Reference<cssdf::XResourceId>& rxResourceId)
41 {
42 ::Window* pWindow = NULL;
43 if (rxResourceId.is() && rxResourceId->getAnchor().is())
44 {
45 ::boost::shared_ptr<FrameworkHelper> pFrameworkHelper (FrameworkHelper::Instance(rViewShellBase));
46 Reference<awt::XWindow> xWindow (
47 pFrameworkHelper->GetPaneWindow(rxResourceId->getAnchor()->getAnchor()));
48 pWindow = VCLUnoHelper::GetWindow(xWindow);
49 }
50 return pWindow;
51 }
52 }
53
54
55
56
TaskPanelResource(sidebar::SidebarViewShell & rSidebarViewShell,sidebar::PanelId ePanelId,const Reference<XResourceId> & rxResourceId)57 TaskPanelResource::TaskPanelResource (
58 sidebar::SidebarViewShell& rSidebarViewShell,
59 sidebar::PanelId ePanelId,
60 const Reference<XResourceId>& rxResourceId)
61 : TaskPanelResourceInterfaceBase(m_aMutex),
62 mxResourceId(rxResourceId),
63 mpControl(rSidebarViewShell.CreatePanel(
64 GetWindowForResource(rSidebarViewShell.GetViewShellBase(), rxResourceId),
65 ePanelId))
66 {
67 if (mpControl.get() != NULL)
68 {
69 mpControl->Show();
70 mpControl->GetParent()->Show();
71 mpControl->AddEventListener(LINK(this,TaskPanelResource,WindowEventHandler));
72 }
73 }
74
75
76
77
~TaskPanelResource(void)78 TaskPanelResource::~TaskPanelResource (void)
79 {
80 mpControl.reset();
81 }
82
83
84
85
disposing()86 void SAL_CALL TaskPanelResource::disposing ()
87 {
88 mpControl.reset();
89 }
90
91
92
93
getResourceId()94 Reference<XResourceId> SAL_CALL TaskPanelResource::getResourceId ()
95 throw (css::uno::RuntimeException)
96 {
97 return mxResourceId;
98 }
99
100
101
102
isAnchorOnly(void)103 sal_Bool SAL_CALL TaskPanelResource::isAnchorOnly (void)
104 throw (RuntimeException)
105 {
106 return false;
107 }
108
109
110
111
GetControl(void) const112 ::Window* TaskPanelResource::GetControl (void) const
113 {
114 return mpControl.get();
115 }
116
117
118
119
IMPL_LINK(TaskPanelResource,WindowEventHandler,VclWindowEvent *,pEvent)120 IMPL_LINK(TaskPanelResource,WindowEventHandler,VclWindowEvent*,pEvent)
121 {
122 if (pEvent!=NULL && pEvent->GetId()==SFX_HINT_DYING)
123 {
124 // Somebody else deleted the window. Release our reference so
125 // that we do not delete it again.
126 mpControl.release();
127 return sal_True;
128 }
129 else
130 return sal_False;
131 }
132
133 } } // end of namespace sd::framework
134