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