xref: /trunk/main/sfx2/source/sidebar/Panel.cxx (revision 7a32b0c8)
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 void Panel::Paint (const Rectangle& rUpdateArea)
184 {
185     Window::Paint(rUpdateArea);
186 }
187 
188 
189 
190 
191 void Panel::Resize (void)
192 {
193     Window::Resize();
194 
195     // Forward new size to window of XUIElement.
196     Reference<awt::XWindow> xElementWindow (GetElementWindow());
197     if (xElementWindow.is())
198     {
199         const Size aSize (GetSizePixel());
200         xElementWindow->setPosSize(
201             0,
202             0,
203             aSize.Width(),
204             aSize.Height(),
205             awt::PosSize::POSSIZE);
206     }
207 }
208 
209 
210 
211 
212 void Panel::Activate (void)
213 {
214     Window::Activate();
215 }
216 
217 
218 
219 
220 
221 void Panel::DataChanged (const DataChangedEvent& rEvent)
222 {
223     (void)rEvent;
224     SetBackground(Theme::GetPaint(Theme::Paint_PanelBackground).GetWallpaper());
225 }
226 
227 
228 
229 
230 Reference<ui::XSidebarPanel> Panel::GetPanelComponent (void) const
231 {
232     return mxPanelComponent;
233 }
234 
235 
236 
237 
238 void Panel::ShowMenu (void)
239 {
240     if (mxPanelComponent.is())
241         mxPanelComponent->showMenu();
242 }
243 
244 
245 
246 void Panel::PrintWindowTree (void)
247 {
248 #ifdef DEBUG
249     Window* pElementWindow = VCLUnoHelper::GetWindow(GetElementWindow());
250     if (pElementWindow != NULL)
251     {
252         OSL_TRACE("panel parent is %x", pElementWindow->GetParent());
253         Deck::PrintWindowSubTree(pElementWindow, 2);
254     }
255     else
256         OSL_TRACE("    panel is empty");
257 #endif
258 }
259 
260 
261 
262 
263 Reference<awt::XWindow> Panel::GetElementWindow (void)
264 {
265     if (mxElement.is())
266     {
267         Reference<ui::XToolPanel> xToolPanel(mxElement->getRealInterface(), UNO_QUERY);
268         if (xToolPanel.is())
269             return xToolPanel->getWindow();
270     }
271 
272     return NULL;
273 }
274 
275 
276 } } // end of namespace sfx2::sidebar
277