xref: /trunk/main/sfx2/source/sidebar/Panel.cxx (revision b9e67834)
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 #include <tools/svborder.hxx>
31 
32 #include <com/sun/star/ui/XToolPanel.hpp>
33 
34 
35 using namespace css;
36 using namespace cssu;
37 
38 namespace {
39     static const char* VerticalStackLayouterName("vertical-stack");
40 }
41 
42 
43 namespace sfx2 { namespace sidebar {
44 
45 Panel::Panel (
46     const PanelDescriptor& rPanelDescriptor,
47     Window* pParentWindow,
48     const ::boost::function<void(void)>& rDeckLayoutTrigger)
49     : Window(pParentWindow),
50       msLayoutHint(rPanelDescriptor.msLayout),
51       mpTitleBar(new PanelTitleBar(rPanelDescriptor.msTitle, pParentWindow, this)),
52       mbIsTitleBarOptional(rPanelDescriptor.mbIsTitleBarOptional),
53       mxElement(),
54       mxVerticalStackLayoutElement(),
55       mbIsExpanded(true),
56       maDeckLayoutTrigger(rDeckLayoutTrigger)
57 {
58     SetBackground(Theme::GetPaint(Theme::Paint_PanelBackground).GetWallpaper());
59     AddEventListener(LINK(this,Panel,WindowEventHandler));
60 }
61 
62 
63 
64 
65 Panel::~Panel (void)
66 {
67 }
68 
69 
70 
71 
72 void Panel::Dispose (void)
73 {
74     mxVerticalStackLayoutElement = NULL;
75     {
76         Reference<lang::XComponent> xComponent (mxElement, UNO_QUERY);
77         mxElement = NULL;
78         if (xComponent.is())
79             xComponent->dispose();
80     }
81     {
82         Reference<lang::XComponent> xComponent (mxElementWindow, UNO_QUERY);
83         mxElementWindow = NULL;
84         if (xComponent.is())
85             xComponent->dispose();
86     }
87 }
88 
89 
90 
91 
92 const ::rtl::OUString& Panel::GetLayoutHint (void) const
93 {
94     return msLayoutHint;
95 }
96 
97 
98 
99 
100 TitleBar* Panel::GetTitleBar (void) const
101 {
102     return mpTitleBar;
103 }
104 
105 
106 
107 
108 bool Panel::IsTitleBarOptional (void) const
109 {
110     return mbIsTitleBarOptional;
111 }
112 
113 
114 
115 
116 void Panel::SetUIElement (const Reference<ui::XUIElement>& rxElement)
117 {
118     mxElement = rxElement;
119     if (mxElement.is())
120     {
121         Reference<ui::XToolPanel> xToolPanel(mxElement->getRealInterface(), UNO_QUERY);
122         if (xToolPanel.is())
123             mxElementWindow = xToolPanel->getWindow();
124 
125         if (msLayoutHint.equalsAscii(VerticalStackLayouterName))
126             mxVerticalStackLayoutElement.set(mxElement->getRealInterface(), UNO_QUERY);
127     }
128 }
129 
130 
131 
132 
133 void Panel::SetExpanded (const bool bIsExpanded)
134 {
135     if (mbIsExpanded != bIsExpanded)
136     {
137         mbIsExpanded = bIsExpanded;
138         maDeckLayoutTrigger();
139     }
140 }
141 
142 
143 
144 
145 bool Panel::IsExpanded (void) const
146 {
147     return mbIsExpanded;
148 }
149 
150 
151 
152 
153 void Panel::Paint (const Rectangle& rUpdateArea)
154 {
155     Window::Paint(rUpdateArea);
156 }
157 
158 
159 
160 
161 void Panel::SetPosSizePixel (
162     long nX,
163     long nY,
164     long nWidth,
165     long nHeight,
166     sal_uInt16 nFlags)
167 {
168     maBoundingBox = Rectangle(Point(nX,nY),Size(nWidth,nHeight));
169 
170     if ( ! IsReallyVisible())
171         return;
172 
173     Window::SetPosSizePixel(nX, nY, nWidth, nHeight, nFlags);
174 
175     if (mxElementWindow.is())
176         mxElementWindow->setPosSize(0, 0, nWidth, nHeight, nFlags);
177 }
178 
179 
180 
181 
182 void Panel::Activate (void)
183 {
184     Window::Activate();
185 }
186 
187 
188 
189 
190 
191 void Panel::DataChanged (const DataChangedEvent& rEvent)
192 {
193     (void)rEvent;
194     SetBackground(Theme::GetPaint(Theme::Paint_PanelBackground).GetWallpaper());
195 }
196 
197 
198 
199 
200 Reference<ui::XVerticalStackLayoutElement> Panel::GetVerticalStackElement (void) const
201 {
202     return mxVerticalStackLayoutElement;
203 }
204 
205 
206 
207 
208 IMPL_LINK(Panel, WindowEventHandler, VclWindowEvent*, pEvent)
209 {
210     if (pEvent != NULL)
211     {
212         switch (pEvent->GetId())
213         {
214             case VCLEVENT_WINDOW_SHOW:
215             case VCLEVENT_WINDOW_RESIZE:
216                 SetPosSizePixel(
217                     maBoundingBox.Left(),
218                     maBoundingBox.Top(),
219                     maBoundingBox.GetWidth(),
220                     maBoundingBox.GetHeight());
221                 break;
222 
223             default:
224                 break;
225         }
226     }
227 
228     return sal_True;
229 }
230 
231 
232 } } // end of namespace sfx2::sidebar
233