1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
29 //........................................................................
32 //........................................................................
34 using ::com::sun::star::uno::Reference
;
35 using ::com::sun::star::accessibility::XAccessible
;
37 //====================================================================
38 //= TabDeckLayouter_Data
39 //====================================================================
40 struct TabDeckLayouter_Data
42 TabAlignment eAlignment
;
43 IToolPanelDeck
& rPanels
;
44 ::std::auto_ptr
< PanelTabBar
> pTabBar
;
45 AccessibleFactoryAccess aAccessibleFactory
;
47 TabDeckLayouter_Data( Window
& i_rParent
, IToolPanelDeck
& i_rPanels
,
48 const TabAlignment i_eAlignment
, const TabItemContent i_eItemContent
)
49 :eAlignment( i_eAlignment
)
51 ,pTabBar( new PanelTabBar( i_rParent
, i_rPanels
, i_eAlignment
, i_eItemContent
) )
57 //====================================================================
59 //====================================================================
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!" );
79 //====================================================================
81 //====================================================================
82 //--------------------------------------------------------------------
83 TabDeckLayouter::TabDeckLayouter( 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
) )
89 //--------------------------------------------------------------------
90 TabDeckLayouter::~TabDeckLayouter()
94 //--------------------------------------------------------------------
95 IMPLEMENT_IREFERENCE( TabDeckLayouter
)
97 //--------------------------------------------------------------------
98 TabItemContent
TabDeckLayouter::GetTabItemContent() const
100 if ( lcl_checkDisposed( *m_pData
) )
101 return TABITEM_IMAGE_AND_TEXT
;
102 return m_pData
->pTabBar
->GetTabItemContent();
105 //--------------------------------------------------------------------
106 void TabDeckLayouter::SetTabItemContent( const TabItemContent
& i_eItemContent
)
108 if ( lcl_checkDisposed( *m_pData
) )
110 m_pData
->pTabBar
->SetTabItemContent( i_eItemContent
);
113 //--------------------------------------------------------------------
114 TabAlignment
TabDeckLayouter::GetTabAlignment() const
116 if ( lcl_checkDisposed( *m_pData
) )
118 return m_pData
->eAlignment
;
121 //--------------------------------------------------------------------
122 Rectangle
TabDeckLayouter::Layout( const Rectangle
& i_rDeckPlayground
)
124 if ( lcl_checkDisposed( *m_pData
) )
125 return i_rDeckPlayground
;
127 const Size
aPreferredSize(m_pData
->pTabBar
->GetOptimalSize());
128 if ( lcl_isVerticalTabBar( m_pData
->eAlignment
) )
130 Size
aTabBarSize(aPreferredSize
.Width(), i_rDeckPlayground
.GetHeight());
132 Rectangle
aPanelRect( i_rDeckPlayground
);
133 if ( m_pData
->eAlignment
== TABS_RIGHT
)
135 aPanelRect
.Right() -= aTabBarSize
.Width();
136 Point
aTabBarTopLeft( aPanelRect
.TopRight() );
137 aTabBarTopLeft
.X() += 1;
138 m_pData
->pTabBar
->SetPosSizePixel( aTabBarTopLeft
, aTabBarSize
);
142 m_pData
->pTabBar
->SetPosSizePixel( aPanelRect
.TopLeft(), aTabBarSize
);
143 aPanelRect
.Left() += aTabBarSize
.Width();
145 if ( aPanelRect
.Left() >= aPanelRect
.Right() )
146 aPanelRect
= Rectangle();
151 Size
aTabBarSize(i_rDeckPlayground
.GetWidth(), aPreferredSize
.Height());
153 Rectangle
aPanelRect( i_rDeckPlayground
);
154 if ( m_pData
->eAlignment
== TABS_TOP
)
156 m_pData
->pTabBar
->SetPosSizePixel( aPanelRect
.TopLeft(), aTabBarSize
);
157 aPanelRect
.Top() += aTabBarSize
.Height();
161 aPanelRect
.Bottom() -= aTabBarSize
.Height();
162 Point
aTabBarTopLeft( aPanelRect
.BottomLeft() );
163 aTabBarTopLeft
.Y() -= 1;
164 m_pData
->pTabBar
->SetPosSizePixel( aTabBarTopLeft
, aTabBarSize
);
166 if ( aPanelRect
.Top() >= aPanelRect
.Bottom() )
167 aPanelRect
= Rectangle();
172 //--------------------------------------------------------------------
173 void TabDeckLayouter::Destroy()
175 m_pData
->pTabBar
.reset();
178 //--------------------------------------------------------------------
179 void TabDeckLayouter::SetFocusToPanelSelector()
181 if ( lcl_checkDisposed( *m_pData
) )
183 m_pData
->pTabBar
->GrabFocus();
186 //--------------------------------------------------------------------
187 size_t TabDeckLayouter::GetAccessibleChildCount() const
189 if ( lcl_checkDisposed( *m_pData
) )
195 //--------------------------------------------------------------------
196 Reference
< XAccessible
> TabDeckLayouter::GetAccessibleChild( const size_t i_nChildIndex
, const Reference
< XAccessible
>& i_rParentAccessible
)
199 (void)i_rParentAccessible
;
200 if ( lcl_checkDisposed( *m_pData
) )
203 return m_pData
->pTabBar
->GetAccessible( sal_True
);
206 //........................................................................
208 //........................................................................
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */