xref: /trunk/main/sfx2/source/sidebar/Panel.cxx (revision ff12d537)
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 "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     const sidebar::Paint aPaint (Theme::GetPanelBackground());
59     switch(aPaint.GetType())
60     {
61         case Paint::NoPaint:
62         default:
63             SetBackground();
64             break;
65 
66         case Paint::ColorPaint:
67         {
68             const Color aColor (aPaint.GetColor());
69             SetBackground(Wallpaper(aColor));
70             break;
71         }
72         case Paint::GradientPaint:
73             SetBackground(Wallpaper(aPaint.GetGradient()));
74             break;
75     }
76 }
77 
78 
79 
80 
81 Panel::~Panel (void)
82 {
83 }
84 
85 
86 
87 
88 void Panel::Dispose (void)
89 {
90     mxVerticalStackLayoutElement = NULL;
91     {
92         Reference<lang::XComponent> xComponent (mxElement, UNO_QUERY);
93         mxElement = NULL;
94         if (xComponent.is())
95             xComponent->dispose();
96     }
97     {
98         Reference<lang::XComponent> xComponent (mxElementWindow, UNO_QUERY);
99         mxElementWindow = NULL;
100         if (xComponent.is())
101             xComponent->dispose();
102     }
103 }
104 
105 
106 
107 
108 const ::rtl::OUString& Panel::GetLayoutHint (void) const
109 {
110     return msLayoutHint;
111 }
112 
113 
114 
115 
116 TitleBar* Panel::GetTitleBar (void) const
117 {
118     return mpTitleBar;
119 }
120 
121 
122 
123 
124 bool Panel::IsTitleBarOptional (void) const
125 {
126     return mbIsTitleBarOptional;
127 }
128 
129 
130 
131 
132 void Panel::SetUIElement (const Reference<ui::XUIElement>& rxElement)
133 {
134     mxElement = rxElement;
135     if (mxElement.is())
136     {
137         Reference<ui::XToolPanel> xToolPanel(mxElement->getRealInterface(), UNO_QUERY);
138         if (xToolPanel.is())
139         {
140             mxElementWindow = xToolPanel->getWindow();
141             Reference<awt::XWindowPeer> xPeer (mxElementWindow, UNO_QUERY);
142             if (xPeer.is())
143                 xPeer->setBackground(0x00000000);
144         }
145 
146         if (msLayoutHint.equalsAscii(VerticalStackLayouterName))
147             mxVerticalStackLayoutElement.set(mxElement->getRealInterface(), UNO_QUERY);
148     }
149 }
150 
151 
152 
153 
154 void Panel::SetExpanded (const bool bIsExpanded)
155 {
156     if (mbIsExpanded != bIsExpanded)
157     {
158         mbIsExpanded = bIsExpanded;
159         maDeckLayoutTrigger();
160     }
161 }
162 
163 
164 
165 
166 bool Panel::IsExpanded (void) const
167 {
168     return mbIsExpanded;
169 }
170 
171 
172 
173 
174 void Panel::Paint (const Rectangle& rUpdateArea)
175 {
176     Window::Paint(rUpdateArea);
177 }
178 
179 
180 
181 
182 void Panel::SetPosSizePixel (
183     long nX,
184     long nY,
185     long nWidth,
186     long nHeight,
187     sal_uInt16 nFlags)
188 {
189     Window::SetPosSizePixel(nX, nY, nWidth, nHeight, nFlags);
190 
191     if (mxElementWindow.is())
192         mxElementWindow->setPosSize(0, 0, nWidth, nHeight, nFlags);
193 }
194 
195 
196 
197 
198 Reference<ui::XVerticalStackLayoutElement> Panel::GetVerticalStackElement (void) const
199 {
200     return mxVerticalStackLayoutElement;
201 }
202 
203 
204 } } // end of namespace sfx2::sidebar
205