xref: /aoo41x/main/sfx2/source/sidebar/Panel.cxx (revision 8a1a651a)
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 "Panel.hxx"
25 #include "PanelTitleBar.hxx"
26 #include "PanelDescriptor.hxx"
27 #include "sfx2/sidebar/Theme.hxx"
28 #include "Paint.hxx"
29 #include "ResourceManager.hxx"
30 
31 #ifdef DEBUG
32 #include "sfx2/sidebar/Tools.hxx"
33 #include "Deck.hxx"
34 #endif
35 
36 #include <tools/svborder.hxx>
37 #include <toolkit/helper/vclunohelper.hxx>
38 
39 #include <com/sun/star/awt/XWindowPeer.hpp>
40 #include <com/sun/star/awt/PosSize.hpp>
41 #include <com/sun/star/ui/XToolPanel.hpp>
42 
43 #include <boost/bind.hpp>
44 
45 
46 using namespace css;
47 using namespace cssu;
48 
49 
50 
51 namespace sfx2 { namespace sidebar {
52 
53 Panel::Panel (
54     const PanelDescriptor& rPanelDescriptor,
55     Window* pParentWindow,
56     const bool bIsInitiallyExpanded,
57     const ::boost::function<void(void)>& rDeckLayoutTrigger,
58     const ::boost::function<Context(void)>& rContextAccess)
59     : Window(pParentWindow),
60       msPanelId(rPanelDescriptor.msId),
61       mpTitleBar(new PanelTitleBar(
62               rPanelDescriptor.msTitle,
63               pParentWindow,
64               this)),
65       mbIsTitleBarOptional(rPanelDescriptor.mbIsTitleBarOptional),
66       mxElement(),
67       mxPanelComponent(),
68       mbIsExpanded(bIsInitiallyExpanded),
69       maDeckLayoutTrigger(rDeckLayoutTrigger),
70       maContextAccess(rContextAccess)
71 {
72     SetBackground(Theme::GetPaint(Theme::Paint_PanelBackground).GetWallpaper());
73 
74 #ifdef DEBUG
75     SetText(A2S("Panel"));
76 #endif
77 }
78 
79 
80 
81 
82 Panel::~Panel (void)
83 {
84     Dispose();
85 }
86 
87 
88 
89 
90 void Panel::Dispose (void)
91 {
92     mxPanelComponent = NULL;
93 
94     if (mxElement.is())
95     {
96         Reference<lang::XComponent> xComponent (mxElement->getRealInterface(), UNO_QUERY);
97         if (xComponent.is())
98             xComponent->dispose();
99     }
100 
101     {
102         Reference<lang::XComponent> xComponent (mxElement, UNO_QUERY);
103         mxElement = NULL;
104         if (xComponent.is())
105             xComponent->dispose();
106     }
107 
108     {
109         Reference<lang::XComponent> xComponent (GetElementWindow(), UNO_QUERY);
110         if (xComponent.is())
111             xComponent->dispose();
112     }
113 
114     mpTitleBar.reset();
115 }
116 
117 
118 
119 
120 PanelTitleBar* Panel::GetTitleBar (void) const
121 {
122     return mpTitleBar.get();
123 }
124 
125 
126 
127 
128 bool Panel::IsTitleBarOptional (void) const
129 {
130     return mbIsTitleBarOptional;
131 }
132 
133 
134 
135 
136 void Panel::SetUIElement (const Reference<ui::XUIElement>& rxElement)
137 {
138     mxElement = rxElement;
139     if (mxElement.is())
140     {
141         mxPanelComponent.set(mxElement->getRealInterface(), UNO_QUERY);
142     }
143 }
144 
145 
146 
147 
148 void Panel::SetExpanded (const bool bIsExpanded)
149 {
150     if (mbIsExpanded != bIsExpanded)
151     {
152         mbIsExpanded = bIsExpanded;
153         maDeckLayoutTrigger();
154 
155         if (maContextAccess)
156             ResourceManager::Instance().StorePanelExpansionState(
157                 msPanelId,
158                 bIsExpanded,
159                 maContextAccess());
160     }
161 }
162 
163 
164 
165 
166 bool Panel::IsExpanded (void) const
167 {
168     return mbIsExpanded;
169 }
170 
171 
172 
173 
174 bool Panel::HasIdPredicate (const ::rtl::OUString& rsId) const
175 {
176     if (this == NULL)
177         return false;
178     else
179         return msPanelId.equals(rsId);
180 }
181 
182 
183 
184 
185 const ::rtl::OUString& Panel::GetId (void) const
186 {
187     return msPanelId;
188 }
189 
190 
191 
192 
193 void Panel::Paint (const Rectangle& rUpdateArea)
194 {
195     Window::Paint(rUpdateArea);
196 }
197 
198 
199 
200 
201 void Panel::Resize (void)
202 {
203     Window::Resize();
204 
205     // Forward new size to window of XUIElement.
206     Reference<awt::XWindow> xElementWindow (GetElementWindow());
207     if (xElementWindow.is())
208     {
209         const Size aSize (GetSizePixel());
210         xElementWindow->setPosSize(
211             0,
212             0,
213             aSize.Width(),
214             aSize.Height(),
215             awt::PosSize::POSSIZE);
216     }
217 }
218 
219 
220 
221 
222 void Panel::Activate (void)
223 {
224     Window::Activate();
225 }
226 
227 
228 
229 
230 
231 void Panel::DataChanged (const DataChangedEvent& rEvent)
232 {
233     (void)rEvent;
234     SetBackground(Theme::GetPaint(Theme::Paint_PanelBackground).GetWallpaper());
235 }
236 
237 
238 
239 
240 Reference<ui::XSidebarPanel> Panel::GetPanelComponent (void) const
241 {
242     return mxPanelComponent;
243 }
244 
245 
246 
247 
248 void Panel::PrintWindowTree (void)
249 {
250 #ifdef DEBUG
251     Window* pElementWindow = VCLUnoHelper::GetWindow(GetElementWindow());
252     if (pElementWindow != NULL)
253     {
254         OSL_TRACE("panel parent is %x", pElementWindow->GetParent());
255         Deck::PrintWindowSubTree(pElementWindow, 2);
256     }
257     else
258         OSL_TRACE("    panel is empty");
259 #endif
260 }
261 
262 
263 
264 
265 Reference<awt::XWindow> Panel::GetElementWindow (void)
266 {
267     if (mxElement.is())
268     {
269         Reference<ui::XToolPanel> xToolPanel(mxElement->getRealInterface(), UNO_QUERY);
270         if (xToolPanel.is())
271             return xToolPanel->getWindow();
272     }
273 
274     return NULL;
275 }
276 
277 
278 } } // end of namespace sfx2::sidebar
279