1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3*cdf0e10cSrcweir  *
4*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
5*cdf0e10cSrcweir  *
6*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
7*cdf0e10cSrcweir  *
8*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
9*cdf0e10cSrcweir  *
10*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
11*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
12*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
13*cdf0e10cSrcweir  *
14*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
15*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
18*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
19*cdf0e10cSrcweir  *
20*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
21*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
22*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
23*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
24*cdf0e10cSrcweir  *
25*cdf0e10cSrcweir ************************************************************************/
26*cdf0e10cSrcweir 
27*cdf0e10cSrcweir #include "precompiled_svtools.hxx"
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir #include "svtools/toolpanel/tablayouter.hxx"
30*cdf0e10cSrcweir #include "svtools/toolpanel/toolpaneldeck.hxx"
31*cdf0e10cSrcweir #include "svtools/toolpanel/paneltabbar.hxx"
32*cdf0e10cSrcweir #include "svtaccessiblefactory.hxx"
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include <tools/gen.hxx>
35*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir //........................................................................
38*cdf0e10cSrcweir namespace svt
39*cdf0e10cSrcweir {
40*cdf0e10cSrcweir //........................................................................
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir     using ::com::sun::star::uno::Reference;
43*cdf0e10cSrcweir     using ::com::sun::star::accessibility::XAccessible;
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir 	//====================================================================
46*cdf0e10cSrcweir 	//= TabDeckLayouter_Data
47*cdf0e10cSrcweir 	//====================================================================
48*cdf0e10cSrcweir     struct TabDeckLayouter_Data
49*cdf0e10cSrcweir     {
50*cdf0e10cSrcweir         TabAlignment                    eAlignment;
51*cdf0e10cSrcweir         IToolPanelDeck&                 rPanels;
52*cdf0e10cSrcweir         ::std::auto_ptr< PanelTabBar >  pTabBar;
53*cdf0e10cSrcweir         AccessibleFactoryAccess         aAccessibleFactory;
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir         TabDeckLayouter_Data( Window& i_rParent, IToolPanelDeck& i_rPanels,
56*cdf0e10cSrcweir                 const TabAlignment i_eAlignment, const TabItemContent i_eItemContent )
57*cdf0e10cSrcweir             :eAlignment( i_eAlignment )
58*cdf0e10cSrcweir             ,rPanels( i_rPanels )
59*cdf0e10cSrcweir             ,pTabBar( new PanelTabBar( i_rParent, i_rPanels, i_eAlignment, i_eItemContent ) )
60*cdf0e10cSrcweir         {
61*cdf0e10cSrcweir             pTabBar->Show();
62*cdf0e10cSrcweir         }
63*cdf0e10cSrcweir     };
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir 	//====================================================================
66*cdf0e10cSrcweir 	//= helper
67*cdf0e10cSrcweir 	//====================================================================
68*cdf0e10cSrcweir     namespace
69*cdf0e10cSrcweir     {
70*cdf0e10cSrcweir         static bool lcl_isVerticalTabBar( const TabAlignment i_eAlignment )
71*cdf0e10cSrcweir         {
72*cdf0e10cSrcweir             return  ( i_eAlignment == TABS_RIGHT )
73*cdf0e10cSrcweir                 ||  ( i_eAlignment == TABS_LEFT );
74*cdf0e10cSrcweir         }
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir         static bool lcl_checkDisposed( const TabDeckLayouter_Data& i_rData )
77*cdf0e10cSrcweir         {
78*cdf0e10cSrcweir             if ( !i_rData.pTabBar.get() )
79*cdf0e10cSrcweir             {
80*cdf0e10cSrcweir                 OSL_ENSURE( false, "lcl_checkDisposed: already disposed!" );
81*cdf0e10cSrcweir                 return true;
82*cdf0e10cSrcweir             }
83*cdf0e10cSrcweir             return false;
84*cdf0e10cSrcweir         }
85*cdf0e10cSrcweir     }
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir 	//====================================================================
88*cdf0e10cSrcweir 	//= TabDeckLayouter
89*cdf0e10cSrcweir 	//====================================================================
90*cdf0e10cSrcweir 	//--------------------------------------------------------------------
91*cdf0e10cSrcweir     TabDeckLayouter::TabDeckLayouter( Window& i_rParent, IToolPanelDeck& i_rPanels,
92*cdf0e10cSrcweir             const TabAlignment i_eAlignment, const TabItemContent i_eItemContent )
93*cdf0e10cSrcweir         :m_pData( new TabDeckLayouter_Data( i_rParent, i_rPanels, i_eAlignment, i_eItemContent ) )
94*cdf0e10cSrcweir     {
95*cdf0e10cSrcweir     }
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir 	//--------------------------------------------------------------------
98*cdf0e10cSrcweir     TabDeckLayouter::~TabDeckLayouter()
99*cdf0e10cSrcweir     {
100*cdf0e10cSrcweir     }
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir 	//--------------------------------------------------------------------
103*cdf0e10cSrcweir     IMPLEMENT_IREFERENCE( TabDeckLayouter )
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 	//--------------------------------------------------------------------
106*cdf0e10cSrcweir     TabItemContent TabDeckLayouter::GetTabItemContent() const
107*cdf0e10cSrcweir     {
108*cdf0e10cSrcweir         if ( lcl_checkDisposed( *m_pData ) )
109*cdf0e10cSrcweir             return TABITEM_IMAGE_AND_TEXT;
110*cdf0e10cSrcweir         return m_pData->pTabBar->GetTabItemContent();
111*cdf0e10cSrcweir     }
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir 	//--------------------------------------------------------------------
114*cdf0e10cSrcweir     void TabDeckLayouter::SetTabItemContent( const TabItemContent& i_eItemContent )
115*cdf0e10cSrcweir     {
116*cdf0e10cSrcweir         if ( lcl_checkDisposed( *m_pData ) )
117*cdf0e10cSrcweir             return;
118*cdf0e10cSrcweir         m_pData->pTabBar->SetTabItemContent( i_eItemContent );
119*cdf0e10cSrcweir     }
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir 	//--------------------------------------------------------------------
122*cdf0e10cSrcweir     TabAlignment TabDeckLayouter::GetTabAlignment() const
123*cdf0e10cSrcweir     {
124*cdf0e10cSrcweir         if ( lcl_checkDisposed( *m_pData ) )
125*cdf0e10cSrcweir             return TABS_RIGHT;
126*cdf0e10cSrcweir         return m_pData->eAlignment;
127*cdf0e10cSrcweir     }
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir 	//--------------------------------------------------------------------
130*cdf0e10cSrcweir     ::boost::optional< size_t > TabDeckLayouter::GetFocusedPanelItem() const
131*cdf0e10cSrcweir     {
132*cdf0e10cSrcweir         if ( lcl_checkDisposed( *m_pData ) )
133*cdf0e10cSrcweir             return ::boost::optional< size_t >();
134*cdf0e10cSrcweir         return m_pData->pTabBar->GetFocusedPanelItem();
135*cdf0e10cSrcweir     }
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir 	//--------------------------------------------------------------------
138*cdf0e10cSrcweir     void TabDeckLayouter::FocusPanelItem( const size_t i_nItemPos )
139*cdf0e10cSrcweir     {
140*cdf0e10cSrcweir         if ( lcl_checkDisposed( *m_pData ) )
141*cdf0e10cSrcweir             return;
142*cdf0e10cSrcweir         m_pData->pTabBar->FocusPanelItem( i_nItemPos );
143*cdf0e10cSrcweir     }
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir 	//--------------------------------------------------------------------
146*cdf0e10cSrcweir     bool TabDeckLayouter::IsPanelSelectorEnabled() const
147*cdf0e10cSrcweir     {
148*cdf0e10cSrcweir         if ( lcl_checkDisposed( *m_pData ) )
149*cdf0e10cSrcweir             return false;
150*cdf0e10cSrcweir         return m_pData->pTabBar->IsEnabled();
151*cdf0e10cSrcweir     }
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir 	//--------------------------------------------------------------------
154*cdf0e10cSrcweir     bool TabDeckLayouter::IsPanelSelectorVisible() const
155*cdf0e10cSrcweir     {
156*cdf0e10cSrcweir         if ( lcl_checkDisposed( *m_pData ) )
157*cdf0e10cSrcweir             return false;
158*cdf0e10cSrcweir         return m_pData->pTabBar->IsVisible();
159*cdf0e10cSrcweir     }
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 	//--------------------------------------------------------------------
162*cdf0e10cSrcweir     Rectangle TabDeckLayouter::GetItemScreenRect( const size_t i_nItemPos ) const
163*cdf0e10cSrcweir     {
164*cdf0e10cSrcweir         if ( lcl_checkDisposed( *m_pData ) )
165*cdf0e10cSrcweir             return Rectangle();
166*cdf0e10cSrcweir         return m_pData->pTabBar->GetItemScreenRect( i_nItemPos );
167*cdf0e10cSrcweir     }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir 	//--------------------------------------------------------------------
170*cdf0e10cSrcweir     Rectangle TabDeckLayouter::Layout( const Rectangle& i_rDeckPlayground )
171*cdf0e10cSrcweir     {
172*cdf0e10cSrcweir         if ( lcl_checkDisposed( *m_pData ) )
173*cdf0e10cSrcweir             return i_rDeckPlayground;
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir         const Size aPreferredSize( m_pData->pTabBar->GetOptimalSize( WINDOWSIZE_PREFERRED ) );
176*cdf0e10cSrcweir         if ( lcl_isVerticalTabBar( m_pData->eAlignment ) )
177*cdf0e10cSrcweir         {
178*cdf0e10cSrcweir             Size aTabBarSize =  ( aPreferredSize.Width() < i_rDeckPlayground.GetWidth() )
179*cdf0e10cSrcweir                             ?   aPreferredSize
180*cdf0e10cSrcweir                             :   m_pData->pTabBar->GetOptimalSize( WINDOWSIZE_MINIMUM );
181*cdf0e10cSrcweir             aTabBarSize.Height() = i_rDeckPlayground.GetHeight();
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir             Rectangle aPanelRect( i_rDeckPlayground );
184*cdf0e10cSrcweir             if ( m_pData->eAlignment == TABS_RIGHT )
185*cdf0e10cSrcweir             {
186*cdf0e10cSrcweir                 aPanelRect.Right() -= aTabBarSize.Width();
187*cdf0e10cSrcweir                 Point aTabBarTopLeft( aPanelRect.TopRight() );
188*cdf0e10cSrcweir                 aTabBarTopLeft.X() += 1;
189*cdf0e10cSrcweir                 m_pData->pTabBar->SetPosSizePixel( aTabBarTopLeft, aTabBarSize );
190*cdf0e10cSrcweir             }
191*cdf0e10cSrcweir             else
192*cdf0e10cSrcweir             {
193*cdf0e10cSrcweir                 m_pData->pTabBar->SetPosSizePixel( aPanelRect.TopLeft(), aTabBarSize );
194*cdf0e10cSrcweir                 aPanelRect.Left() += aTabBarSize.Width();
195*cdf0e10cSrcweir             }
196*cdf0e10cSrcweir             if ( aPanelRect.Left() >= aPanelRect.Right() )
197*cdf0e10cSrcweir                 aPanelRect = Rectangle();
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir             return aPanelRect;
200*cdf0e10cSrcweir         }
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir         Size aTabBarSize =  ( aPreferredSize.Height() < i_rDeckPlayground.GetHeight() )
203*cdf0e10cSrcweir                         ?   aPreferredSize
204*cdf0e10cSrcweir                         :   m_pData->pTabBar->GetOptimalSize( WINDOWSIZE_MINIMUM );
205*cdf0e10cSrcweir         aTabBarSize.Width() = i_rDeckPlayground.GetWidth();
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir         Rectangle aPanelRect( i_rDeckPlayground );
208*cdf0e10cSrcweir         if ( m_pData->eAlignment == TABS_TOP )
209*cdf0e10cSrcweir         {
210*cdf0e10cSrcweir             m_pData->pTabBar->SetPosSizePixel( aPanelRect.TopLeft(), aTabBarSize );
211*cdf0e10cSrcweir             aPanelRect.Top() += aTabBarSize.Height();
212*cdf0e10cSrcweir         }
213*cdf0e10cSrcweir         else
214*cdf0e10cSrcweir         {
215*cdf0e10cSrcweir             aPanelRect.Bottom() -= aTabBarSize.Height();
216*cdf0e10cSrcweir             Point aTabBarTopLeft( aPanelRect.BottomLeft() );
217*cdf0e10cSrcweir             aTabBarTopLeft.Y() -= 1;
218*cdf0e10cSrcweir             m_pData->pTabBar->SetPosSizePixel( aTabBarTopLeft, aTabBarSize );
219*cdf0e10cSrcweir         }
220*cdf0e10cSrcweir         if ( aPanelRect.Top() >= aPanelRect.Bottom() )
221*cdf0e10cSrcweir             aPanelRect = Rectangle();
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir         return aPanelRect;
224*cdf0e10cSrcweir     }
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir 	//--------------------------------------------------------------------
227*cdf0e10cSrcweir     void TabDeckLayouter::Destroy()
228*cdf0e10cSrcweir     {
229*cdf0e10cSrcweir         m_pData->pTabBar.reset();
230*cdf0e10cSrcweir     }
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir 	//--------------------------------------------------------------------
233*cdf0e10cSrcweir     void TabDeckLayouter::SetFocusToPanelSelector()
234*cdf0e10cSrcweir     {
235*cdf0e10cSrcweir         if ( lcl_checkDisposed( *m_pData ) )
236*cdf0e10cSrcweir             return;
237*cdf0e10cSrcweir         m_pData->pTabBar->GrabFocus();
238*cdf0e10cSrcweir     }
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir 	//--------------------------------------------------------------------
241*cdf0e10cSrcweir     size_t TabDeckLayouter::GetAccessibleChildCount() const
242*cdf0e10cSrcweir     {
243*cdf0e10cSrcweir         if ( lcl_checkDisposed( *m_pData ) )
244*cdf0e10cSrcweir             return 0;
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir         return 1;
247*cdf0e10cSrcweir     }
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir     //--------------------------------------------------------------------
250*cdf0e10cSrcweir     Reference< XAccessible > TabDeckLayouter::GetAccessibleChild( const size_t i_nChildIndex, const Reference< XAccessible >& i_rParentAccessible )
251*cdf0e10cSrcweir     {
252*cdf0e10cSrcweir         (void)i_nChildIndex;
253*cdf0e10cSrcweir         (void)i_rParentAccessible;
254*cdf0e10cSrcweir         if ( lcl_checkDisposed( *m_pData ) )
255*cdf0e10cSrcweir             return NULL;
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir         return m_pData->pTabBar->GetAccessible( sal_True );
258*cdf0e10cSrcweir     }
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir //........................................................................
261*cdf0e10cSrcweir } // namespace svt
262*cdf0e10cSrcweir //........................................................................
263