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