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