Bump version to 5.0-14
[LibreOffice.git] / svtools / source / toolpanel / tablayouter.cxx
blob5c83f285bc99128b8665cb5bc09a8b1151cf1c62
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <svtools/toolpanel/tablayouter.hxx>
22 #include <svtools/toolpanel/toolpaneldeck.hxx>
23 #include <svtools/toolpanel/paneltabbar.hxx>
24 #include "svtaccessiblefactory.hxx"
26 #include <tools/gen.hxx>
27 #include <tools/diagnose_ex.h>
30 namespace svt
34 using ::com::sun::star::uno::Reference;
35 using ::com::sun::star::accessibility::XAccessible;
38 //= TabDeckLayouter_Data
40 struct TabDeckLayouter_Data
42 TabAlignment eAlignment;
43 IToolPanelDeck& rPanels;
44 VclPtr< PanelTabBar > pTabBar;
45 AccessibleFactoryAccess aAccessibleFactory;
47 TabDeckLayouter_Data( vcl::Window& i_rParent, IToolPanelDeck& i_rPanels,
48 const TabAlignment i_eAlignment, const TabItemContent i_eItemContent )
49 :eAlignment( i_eAlignment )
50 ,rPanels( i_rPanels )
51 ,pTabBar( VclPtr<PanelTabBar>::Create( i_rParent, i_rPanels, i_eAlignment, i_eItemContent ) )
53 pTabBar->Show();
58 //= helper
60 namespace
62 static bool lcl_isVerticalTabBar( const TabAlignment i_eAlignment )
64 return ( i_eAlignment == TABS_RIGHT )
65 || ( i_eAlignment == TABS_LEFT );
68 static bool lcl_checkDisposed( const TabDeckLayouter_Data& i_rData )
70 if ( !i_rData.pTabBar.get() )
72 OSL_FAIL( "lcl_checkDisposed: already disposed!" );
73 return true;
75 return false;
80 //= TabDeckLayouter
83 TabDeckLayouter::TabDeckLayouter( vcl::Window& i_rParent, IToolPanelDeck& i_rPanels,
84 const TabAlignment i_eAlignment, const TabItemContent i_eItemContent )
85 :m_pData( new TabDeckLayouter_Data( i_rParent, i_rPanels, i_eAlignment, i_eItemContent ) )
90 TabDeckLayouter::~TabDeckLayouter()
95 TabItemContent TabDeckLayouter::GetTabItemContent() const
97 if ( lcl_checkDisposed( *m_pData ) )
98 return TABITEM_IMAGE_AND_TEXT;
99 return m_pData->pTabBar->GetTabItemContent();
103 void TabDeckLayouter::SetTabItemContent( const TabItemContent& i_eItemContent )
105 if ( lcl_checkDisposed( *m_pData ) )
106 return;
107 m_pData->pTabBar->SetTabItemContent( i_eItemContent );
111 TabAlignment TabDeckLayouter::GetTabAlignment() const
113 if ( lcl_checkDisposed( *m_pData ) )
114 return TABS_RIGHT;
115 return m_pData->eAlignment;
119 Rectangle TabDeckLayouter::Layout( const Rectangle& i_rDeckPlayground )
121 if ( lcl_checkDisposed( *m_pData ) )
122 return i_rDeckPlayground;
124 const Size aPreferredSize(m_pData->pTabBar->GetOptimalSize());
125 if ( lcl_isVerticalTabBar( m_pData->eAlignment ) )
127 Size aTabBarSize(aPreferredSize.Width(), i_rDeckPlayground.GetHeight());
129 Rectangle aPanelRect( i_rDeckPlayground );
130 if ( m_pData->eAlignment == TABS_RIGHT )
132 aPanelRect.Right() -= aTabBarSize.Width();
133 Point aTabBarTopLeft( aPanelRect.TopRight() );
134 aTabBarTopLeft.X() += 1;
135 m_pData->pTabBar->SetPosSizePixel( aTabBarTopLeft, aTabBarSize );
137 else
139 m_pData->pTabBar->SetPosSizePixel( aPanelRect.TopLeft(), aTabBarSize );
140 aPanelRect.Left() += aTabBarSize.Width();
142 if ( aPanelRect.Left() >= aPanelRect.Right() )
143 aPanelRect = Rectangle();
145 return aPanelRect;
148 Size aTabBarSize(i_rDeckPlayground.GetWidth(), aPreferredSize.Height());
150 Rectangle aPanelRect( i_rDeckPlayground );
151 if ( m_pData->eAlignment == TABS_TOP )
153 m_pData->pTabBar->SetPosSizePixel( aPanelRect.TopLeft(), aTabBarSize );
154 aPanelRect.Top() += aTabBarSize.Height();
156 else
158 aPanelRect.Bottom() -= aTabBarSize.Height();
159 Point aTabBarTopLeft( aPanelRect.BottomLeft() );
160 aTabBarTopLeft.Y() -= 1;
161 m_pData->pTabBar->SetPosSizePixel( aTabBarTopLeft, aTabBarSize );
163 if ( aPanelRect.Top() >= aPanelRect.Bottom() )
164 aPanelRect = Rectangle();
166 return aPanelRect;
170 void TabDeckLayouter::Destroy()
172 m_pData->pTabBar.reset();
176 void TabDeckLayouter::SetFocusToPanelSelector()
178 if ( lcl_checkDisposed( *m_pData ) )
179 return;
180 m_pData->pTabBar->GrabFocus();
184 size_t TabDeckLayouter::GetAccessibleChildCount() const
186 if ( lcl_checkDisposed( *m_pData ) )
187 return 0;
189 return 1;
193 Reference< XAccessible > TabDeckLayouter::GetAccessibleChild( const size_t i_nChildIndex, const Reference< XAccessible >& i_rParentAccessible )
195 (void)i_nChildIndex;
196 (void)i_rParentAccessible;
197 if ( lcl_checkDisposed( *m_pData ) )
198 return NULL;
200 return m_pData->pTabBar->GetAccessible( true );
204 } // namespace svt
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */