xref: /aoo41x/main/sfx2/source/sidebar/Panel.cxx (revision 008fe6ae)
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 
Panel(const PanelDescriptor & rPanelDescriptor,Window * pParentWindow,const bool bIsInitiallyExpanded,const::boost::function<void (void)> & rDeckLayoutTrigger,const::boost::function<Context (void)> & rContextAccess)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 
~Panel(void)82 Panel::~Panel (void)
83 {
84     Dispose();
85 }
86 
87 
88 
89 
Dispose(void)90 void Panel::Dispose (void)
91 {
92     mxPanelComponent = NULL;
93 
94     {
95         Reference<lang::XComponent> xComponent (mxElement, UNO_QUERY);
96         mxElement = NULL;
97         if (xComponent.is())
98             xComponent->dispose();
99     }
100 
101     {
102         Reference<lang::XComponent> xComponent (GetElementWindow(), UNO_QUERY);
103         if (xComponent.is())
104             xComponent->dispose();
105     }
106 
107     mpTitleBar.reset();
108 }
109 
110 
111 
112 
GetTitleBar(void) const113 PanelTitleBar* Panel::GetTitleBar (void) const
114 {
115     return mpTitleBar.get();
116 }
117 
118 
119 
120 
IsTitleBarOptional(void) const121 bool Panel::IsTitleBarOptional (void) const
122 {
123     return mbIsTitleBarOptional;
124 }
125 
126 
127 
128 
SetUIElement(const Reference<ui::XUIElement> & rxElement)129 void Panel::SetUIElement (const Reference<ui::XUIElement>& rxElement)
130 {
131     mxElement = rxElement;
132     if (mxElement.is())
133     {
134         mxPanelComponent.set(mxElement->getRealInterface(), UNO_QUERY);
135     }
136 }
137 
138 
139 
140 
SetExpanded(const bool bIsExpanded)141 void Panel::SetExpanded (const bool bIsExpanded)
142 {
143     if (mbIsExpanded != bIsExpanded)
144     {
145         mbIsExpanded = bIsExpanded;
146         maDeckLayoutTrigger();
147 
148         if (maContextAccess)
149             ResourceManager::Instance().StorePanelExpansionState(
150                 msPanelId,
151                 bIsExpanded,
152                 maContextAccess());
153     }
154 }
155 
156 
157 
158 
IsExpanded(void) const159 bool Panel::IsExpanded (void) const
160 {
161     return mbIsExpanded;
162 }
163 
164 
165 
166 
HasIdPredicate(const::rtl::OUString & rsId) const167 bool Panel::HasIdPredicate (const ::rtl::OUString& rsId) const
168 {
169     if (this == NULL)
170         return false;
171     else
172         return msPanelId.equals(rsId);
173 }
174 
175 
176 
177 
GetId(void) const178 const ::rtl::OUString& Panel::GetId (void) const
179 {
180     return msPanelId;
181 }
182 
183 
184 
185 
Paint(const Rectangle & rUpdateArea)186 void Panel::Paint (const Rectangle& rUpdateArea)
187 {
188     Window::Paint(rUpdateArea);
189 }
190 
191 
192 
193 
Resize(void)194 void Panel::Resize (void)
195 {
196     Window::Resize();
197 
198     // Forward new size to window of XUIElement.
199     Reference<awt::XWindow> xElementWindow (GetElementWindow());
200     if (xElementWindow.is())
201     {
202         const Size aSize (GetSizePixel());
203         xElementWindow->setPosSize(
204             0,
205             0,
206             aSize.Width(),
207             aSize.Height(),
208             awt::PosSize::POSSIZE);
209     }
210 }
211 
212 
213 
214 
Activate(void)215 void Panel::Activate (void)
216 {
217     Window::Activate();
218 }
219 
220 
221 
222 
223 
DataChanged(const DataChangedEvent & rEvent)224 void Panel::DataChanged (const DataChangedEvent& rEvent)
225 {
226     (void)rEvent;
227     SetBackground(Theme::GetPaint(Theme::Paint_PanelBackground).GetWallpaper());
228 }
229 
230 
231 
232 
GetPanelComponent(void) const233 Reference<ui::XSidebarPanel> Panel::GetPanelComponent (void) const
234 {
235     return mxPanelComponent;
236 }
237 
238 
239 
240 
PrintWindowTree(void)241 void Panel::PrintWindowTree (void)
242 {
243 #ifdef DEBUG
244     Window* pElementWindow = VCLUnoHelper::GetWindow(GetElementWindow());
245     if (pElementWindow != NULL)
246     {
247         OSL_TRACE("panel parent is %x", pElementWindow->GetParent());
248         Deck::PrintWindowSubTree(pElementWindow, 2);
249     }
250     else
251         OSL_TRACE("    panel is empty");
252 #endif
253 }
254 
255 
256 
257 
GetElementWindow(void)258 Reference<awt::XWindow> Panel::GetElementWindow (void)
259 {
260     if (mxElement.is())
261     {
262         Reference<ui::XToolPanel> xToolPanel(mxElement->getRealInterface(), UNO_QUERY);
263         if (xToolPanel.is())
264             return xToolPanel->getWindow();
265     }
266 
267     return NULL;
268 }
269 
270 
271 } } // end of namespace sfx2::sidebar
272