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 23 24 #include "precompiled_svtools.hxx" 25 26 #include "svtools/toolpanel/tablayouter.hxx" 27 #include "svtools/toolpanel/toolpaneldeck.hxx" 28 #include "svtools/toolpanel/paneltabbar.hxx" 29 #include "svtaccessiblefactory.hxx" 30 31 #include <tools/gen.hxx> 32 #include <tools/diagnose_ex.h> 33 34 //........................................................................ 35 namespace svt 36 { 37 //........................................................................ 38 39 using ::com::sun::star::uno::Reference; 40 using ::com::sun::star::accessibility::XAccessible; 41 42 //==================================================================== 43 //= TabDeckLayouter_Data 44 //==================================================================== 45 struct TabDeckLayouter_Data 46 { 47 TabAlignment eAlignment; 48 IToolPanelDeck& rPanels; 49 ::std::auto_ptr< PanelTabBar > pTabBar; 50 AccessibleFactoryAccess aAccessibleFactory; 51 TabDeckLayouter_Datasvt::TabDeckLayouter_Data52 TabDeckLayouter_Data( Window& i_rParent, IToolPanelDeck& i_rPanels, 53 const TabAlignment i_eAlignment, const TabItemContent i_eItemContent ) 54 :eAlignment( i_eAlignment ) 55 ,rPanels( i_rPanels ) 56 ,pTabBar( new PanelTabBar( i_rParent, i_rPanels, i_eAlignment, i_eItemContent ) ) 57 { 58 pTabBar->Show(); 59 } 60 }; 61 62 //==================================================================== 63 //= helper 64 //==================================================================== 65 namespace 66 { lcl_isVerticalTabBar(const TabAlignment i_eAlignment)67 static bool lcl_isVerticalTabBar( const TabAlignment i_eAlignment ) 68 { 69 return ( i_eAlignment == TABS_RIGHT ) 70 || ( i_eAlignment == TABS_LEFT ); 71 } 72 lcl_checkDisposed(const TabDeckLayouter_Data & i_rData)73 static bool lcl_checkDisposed( const TabDeckLayouter_Data& i_rData ) 74 { 75 if ( !i_rData.pTabBar.get() ) 76 { 77 OSL_ENSURE( false, "lcl_checkDisposed: already disposed!" ); 78 return true; 79 } 80 return false; 81 } 82 } 83 84 //==================================================================== 85 //= TabDeckLayouter 86 //==================================================================== 87 //-------------------------------------------------------------------- TabDeckLayouter(Window & i_rParent,IToolPanelDeck & i_rPanels,const TabAlignment i_eAlignment,const TabItemContent i_eItemContent)88 TabDeckLayouter::TabDeckLayouter( Window& i_rParent, IToolPanelDeck& i_rPanels, 89 const TabAlignment i_eAlignment, const TabItemContent i_eItemContent ) 90 :m_pData( new TabDeckLayouter_Data( i_rParent, i_rPanels, i_eAlignment, i_eItemContent ) ) 91 { 92 } 93 94 //-------------------------------------------------------------------- ~TabDeckLayouter()95 TabDeckLayouter::~TabDeckLayouter() 96 { 97 } 98 99 //-------------------------------------------------------------------- IMPLEMENT_IREFERENCE(TabDeckLayouter)100 IMPLEMENT_IREFERENCE( TabDeckLayouter ) 101 102 //-------------------------------------------------------------------- 103 TabItemContent TabDeckLayouter::GetTabItemContent() const 104 { 105 if ( lcl_checkDisposed( *m_pData ) ) 106 return TABITEM_IMAGE_AND_TEXT; 107 return m_pData->pTabBar->GetTabItemContent(); 108 } 109 110 //-------------------------------------------------------------------- SetTabItemContent(const TabItemContent & i_eItemContent)111 void TabDeckLayouter::SetTabItemContent( const TabItemContent& i_eItemContent ) 112 { 113 if ( lcl_checkDisposed( *m_pData ) ) 114 return; 115 m_pData->pTabBar->SetTabItemContent( i_eItemContent ); 116 } 117 118 //-------------------------------------------------------------------- GetTabAlignment() const119 TabAlignment TabDeckLayouter::GetTabAlignment() const 120 { 121 if ( lcl_checkDisposed( *m_pData ) ) 122 return TABS_RIGHT; 123 return m_pData->eAlignment; 124 } 125 126 //-------------------------------------------------------------------- GetFocusedPanelItem() const127 ::boost::optional< size_t > TabDeckLayouter::GetFocusedPanelItem() const 128 { 129 if ( lcl_checkDisposed( *m_pData ) ) 130 return ::boost::optional< size_t >(); 131 return m_pData->pTabBar->GetFocusedPanelItem(); 132 } 133 134 //-------------------------------------------------------------------- FocusPanelItem(const size_t i_nItemPos)135 void TabDeckLayouter::FocusPanelItem( const size_t i_nItemPos ) 136 { 137 if ( lcl_checkDisposed( *m_pData ) ) 138 return; 139 m_pData->pTabBar->FocusPanelItem( i_nItemPos ); 140 } 141 142 //-------------------------------------------------------------------- IsPanelSelectorEnabled() const143 bool TabDeckLayouter::IsPanelSelectorEnabled() const 144 { 145 if ( lcl_checkDisposed( *m_pData ) ) 146 return false; 147 return m_pData->pTabBar->IsEnabled(); 148 } 149 150 //-------------------------------------------------------------------- IsPanelSelectorVisible() const151 bool TabDeckLayouter::IsPanelSelectorVisible() const 152 { 153 if ( lcl_checkDisposed( *m_pData ) ) 154 return false; 155 return m_pData->pTabBar->IsVisible(); 156 } 157 158 //-------------------------------------------------------------------- GetItemScreenRect(const size_t i_nItemPos) const159 Rectangle TabDeckLayouter::GetItemScreenRect( const size_t i_nItemPos ) const 160 { 161 if ( lcl_checkDisposed( *m_pData ) ) 162 return Rectangle(); 163 return m_pData->pTabBar->GetItemScreenRect( i_nItemPos ); 164 } 165 166 //-------------------------------------------------------------------- Layout(const Rectangle & i_rDeckPlayground)167 Rectangle TabDeckLayouter::Layout( const Rectangle& i_rDeckPlayground ) 168 { 169 if ( lcl_checkDisposed( *m_pData ) ) 170 return i_rDeckPlayground; 171 172 const Size aPreferredSize( m_pData->pTabBar->GetOptimalSize( WINDOWSIZE_PREFERRED ) ); 173 if ( lcl_isVerticalTabBar( m_pData->eAlignment ) ) 174 { 175 Size aTabBarSize = ( aPreferredSize.Width() < i_rDeckPlayground.GetWidth() ) 176 ? aPreferredSize 177 : m_pData->pTabBar->GetOptimalSize( WINDOWSIZE_MINIMUM ); 178 aTabBarSize.Height() = i_rDeckPlayground.GetHeight(); 179 180 Rectangle aPanelRect( i_rDeckPlayground ); 181 if ( m_pData->eAlignment == TABS_RIGHT ) 182 { 183 aPanelRect.Right() -= aTabBarSize.Width(); 184 Point aTabBarTopLeft( aPanelRect.TopRight() ); 185 aTabBarTopLeft.X() += 1; 186 m_pData->pTabBar->SetPosSizePixel( aTabBarTopLeft, aTabBarSize ); 187 } 188 else 189 { 190 m_pData->pTabBar->SetPosSizePixel( aPanelRect.TopLeft(), aTabBarSize ); 191 aPanelRect.Left() += aTabBarSize.Width(); 192 } 193 if ( aPanelRect.Left() >= aPanelRect.Right() ) 194 aPanelRect = Rectangle(); 195 196 return aPanelRect; 197 } 198 199 Size aTabBarSize = ( aPreferredSize.Height() < i_rDeckPlayground.GetHeight() ) 200 ? aPreferredSize 201 : m_pData->pTabBar->GetOptimalSize( WINDOWSIZE_MINIMUM ); 202 aTabBarSize.Width() = i_rDeckPlayground.GetWidth(); 203 204 Rectangle aPanelRect( i_rDeckPlayground ); 205 if ( m_pData->eAlignment == TABS_TOP ) 206 { 207 m_pData->pTabBar->SetPosSizePixel( aPanelRect.TopLeft(), aTabBarSize ); 208 aPanelRect.Top() += aTabBarSize.Height(); 209 } 210 else 211 { 212 aPanelRect.Bottom() -= aTabBarSize.Height(); 213 Point aTabBarTopLeft( aPanelRect.BottomLeft() ); 214 aTabBarTopLeft.Y() -= 1; 215 m_pData->pTabBar->SetPosSizePixel( aTabBarTopLeft, aTabBarSize ); 216 } 217 if ( aPanelRect.Top() >= aPanelRect.Bottom() ) 218 aPanelRect = Rectangle(); 219 220 return aPanelRect; 221 } 222 223 //-------------------------------------------------------------------- Destroy()224 void TabDeckLayouter::Destroy() 225 { 226 m_pData->pTabBar.reset(); 227 } 228 229 //-------------------------------------------------------------------- SetFocusToPanelSelector()230 void TabDeckLayouter::SetFocusToPanelSelector() 231 { 232 if ( lcl_checkDisposed( *m_pData ) ) 233 return; 234 m_pData->pTabBar->GrabFocus(); 235 } 236 237 //-------------------------------------------------------------------- GetAccessibleChildCount() const238 size_t TabDeckLayouter::GetAccessibleChildCount() const 239 { 240 if ( lcl_checkDisposed( *m_pData ) ) 241 return 0; 242 243 return 1; 244 } 245 246 //-------------------------------------------------------------------- GetAccessibleChild(const size_t i_nChildIndex,const Reference<XAccessible> & i_rParentAccessible)247 Reference< XAccessible > TabDeckLayouter::GetAccessibleChild( const size_t i_nChildIndex, const Reference< XAccessible >& i_rParentAccessible ) 248 { 249 (void)i_nChildIndex; 250 (void)i_rParentAccessible; 251 if ( lcl_checkDisposed( *m_pData ) ) 252 return NULL; 253 254 return m_pData->pTabBar->GetAccessible( sal_True ); 255 } 256 257 //........................................................................ 258 } // namespace svt 259 //........................................................................ 260