1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_chart2.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "res_TextSeparator.hxx"
32*cdf0e10cSrcweir #include "ResourceIds.hrc"
33*cdf0e10cSrcweir #include "Strings.hrc"
34*cdf0e10cSrcweir #include "ResId.hxx"
35*cdf0e10cSrcweir #include "macros.hxx"
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #ifndef _SVT_CONTROLDIMS_HRC_
38*cdf0e10cSrcweir #include <svtools/controldims.hrc>
39*cdf0e10cSrcweir #endif
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir //.............................................................................
42*cdf0e10cSrcweir namespace chart
43*cdf0e10cSrcweir {
44*cdf0e10cSrcweir //.............................................................................
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir TextSeparatorResources::TextSeparatorResources( Window* pWindow )
47*cdf0e10cSrcweir     : m_aFT_Separator( pWindow, pWindow->GetStyle() )
48*cdf0e10cSrcweir 	, m_aLB_Separator( pWindow , SchResId( LB_TEXT_SEPARATOR ) )
49*cdf0e10cSrcweir     , m_aEntryMap()
50*cdf0e10cSrcweir     , m_nDefaultPos(0)
51*cdf0e10cSrcweir {
52*cdf0e10cSrcweir     m_aFT_Separator.SetText( String( SchResId( STR_TEXT_SEPARATOR )) );
53*cdf0e10cSrcweir     m_aFT_Separator.SetSizePixel( m_aFT_Separator.CalcMinimumSize() );
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir     m_aLB_Separator.SetDropDownLineCount(m_aLB_Separator.GetEntryCount());
56*cdf0e10cSrcweir     m_aLB_Separator.SetSizePixel( m_aLB_Separator.CalcMinimumSize() );
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir     m_aEntryMap[ C2U( " " ) ] = 0;
59*cdf0e10cSrcweir     m_aEntryMap[ C2U( ", " ) ] = 1;
60*cdf0e10cSrcweir     m_aEntryMap[ C2U( "; " ) ] = 2;
61*cdf0e10cSrcweir     m_aEntryMap[ C2U( "\n" ) ] = 3;
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir     m_aLB_Separator.SetAccessibleName(m_aFT_Separator.GetText());
64*cdf0e10cSrcweir 	m_aLB_Separator.SetAccessibleRelationLabeledBy(&m_aFT_Separator);
65*cdf0e10cSrcweir }
66*cdf0e10cSrcweir TextSeparatorResources::~TextSeparatorResources()
67*cdf0e10cSrcweir {
68*cdf0e10cSrcweir }
69*cdf0e10cSrcweir void TextSeparatorResources::Show( bool bShow )
70*cdf0e10cSrcweir {
71*cdf0e10cSrcweir     m_aFT_Separator.Show( bShow );
72*cdf0e10cSrcweir     m_aLB_Separator.Show( bShow );
73*cdf0e10cSrcweir }
74*cdf0e10cSrcweir void TextSeparatorResources::Enable( bool bEnable )
75*cdf0e10cSrcweir {
76*cdf0e10cSrcweir     m_aFT_Separator.Enable( bEnable );
77*cdf0e10cSrcweir     m_aLB_Separator.Enable( bEnable );
78*cdf0e10cSrcweir }
79*cdf0e10cSrcweir void TextSeparatorResources::PositionBelowControl( const Window& rWindow )
80*cdf0e10cSrcweir {
81*cdf0e10cSrcweir     Point aPoint( rWindow.GetPosPixel() );
82*cdf0e10cSrcweir     Size aSize( rWindow.GetSizePixel() );
83*cdf0e10cSrcweir     aPoint.Y() += aSize.Height();
84*cdf0e10cSrcweir     Size aBigDistanceSize( rWindow.LogicToPixel( Size(0,RSC_SP_CTRL_Y), MapMode(MAP_APPFONT) ) );
85*cdf0e10cSrcweir     aPoint.Y() += aBigDistanceSize.Height();
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir     Size aDistanceSize( rWindow.LogicToPixel( Size(RSC_SP_CTRL_DESC_X, (RSC_CD_DROPDOWN_HEIGHT-RSC_CD_FIXEDTEXT_HEIGHT)/2), MapMode(MAP_APPFONT) ) );
88*cdf0e10cSrcweir     aPoint.Y() += aDistanceSize.Height();
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir     m_aFT_Separator.SetPosPixel( aPoint );
91*cdf0e10cSrcweir     m_aLB_Separator.SetPosPixel( Point( aPoint.X()+m_aFT_Separator.GetSizePixel().Width()+aDistanceSize.Width(), aPoint.Y()-aDistanceSize.Height()-1) );
92*cdf0e10cSrcweir }
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir void TextSeparatorResources::AlignListBoxWidthAndXPos( long nWantedLeftBorder /*use -1 to indicate that this can be automatic*/
95*cdf0e10cSrcweir                                                      , long nWantedRightBorder /*use -1 to indicate that this can be automatic*/
96*cdf0e10cSrcweir                                                      , long nMinimumListBoxWidth /*use -1 to indicate that this can be automatic*/ )
97*cdf0e10cSrcweir {
98*cdf0e10cSrcweir     long nMinPossibleLeftBorder = m_aFT_Separator.GetPosPixel().X() + m_aFT_Separator.GetSizePixel().Width() + 1 ;
99*cdf0e10cSrcweir     if( nWantedLeftBorder >= 0 && nWantedLeftBorder>nMinPossibleLeftBorder )
100*cdf0e10cSrcweir     {
101*cdf0e10cSrcweir         Point aPos( m_aLB_Separator.GetPosPixel() );
102*cdf0e10cSrcweir         aPos.X() = nWantedLeftBorder;
103*cdf0e10cSrcweir         m_aLB_Separator.SetPosPixel( aPos );
104*cdf0e10cSrcweir     }
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir     long nMinPossibleRightBorder = m_aLB_Separator.GetPosPixel().X() + m_aLB_Separator.CalcMinimumSize().Width() - 1 ;
107*cdf0e10cSrcweir     if( nWantedRightBorder < m_aLB_Separator.GetPosPixel().X() + nMinimumListBoxWidth )
108*cdf0e10cSrcweir         nWantedRightBorder = m_aLB_Separator.GetPosPixel().X() + nMinimumListBoxWidth;
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir     if( nWantedRightBorder >= 0 && nWantedRightBorder > nMinPossibleRightBorder )
111*cdf0e10cSrcweir     {
112*cdf0e10cSrcweir         Size aSize( m_aLB_Separator.GetSizePixel() );
113*cdf0e10cSrcweir         aSize.Width() = nWantedRightBorder-m_aLB_Separator.GetPosPixel().X();
114*cdf0e10cSrcweir         m_aLB_Separator.SetSizePixel(aSize);
115*cdf0e10cSrcweir     }
116*cdf0e10cSrcweir }
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir Point TextSeparatorResources::GetCurrentListBoxPosition() const
119*cdf0e10cSrcweir {
120*cdf0e10cSrcweir     return m_aLB_Separator.GetPosPixel();
121*cdf0e10cSrcweir }
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir Size TextSeparatorResources::GetCurrentListBoxSize() const
124*cdf0e10cSrcweir {
125*cdf0e10cSrcweir     return m_aLB_Separator.GetSizePixel();
126*cdf0e10cSrcweir }
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir void TextSeparatorResources::SetValue( const rtl::OUString& rSeparator )
129*cdf0e10cSrcweir {
130*cdf0e10cSrcweir     ::std::map< ::rtl::OUString, sal_uInt16 >::iterator aIter( m_aEntryMap.find(rSeparator) );
131*cdf0e10cSrcweir     if( aIter == m_aEntryMap.end() )
132*cdf0e10cSrcweir         m_aLB_Separator.SelectEntryPos( m_nDefaultPos );
133*cdf0e10cSrcweir     else
134*cdf0e10cSrcweir         m_aLB_Separator.SelectEntryPos( aIter->second );
135*cdf0e10cSrcweir }
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir void TextSeparatorResources::SetDefault()
138*cdf0e10cSrcweir {
139*cdf0e10cSrcweir     m_aLB_Separator.SelectEntryPos( m_nDefaultPos );
140*cdf0e10cSrcweir }
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir rtl::OUString TextSeparatorResources::GetValue() const
143*cdf0e10cSrcweir {
144*cdf0e10cSrcweir     sal_uInt16 nPos = m_aLB_Separator.GetSelectEntryPos();
145*cdf0e10cSrcweir     ::std::map< ::rtl::OUString, sal_uInt16 >::const_iterator aIter( m_aEntryMap.begin() );
146*cdf0e10cSrcweir     while( aIter != m_aEntryMap.end() )
147*cdf0e10cSrcweir     {
148*cdf0e10cSrcweir         if(aIter->second==nPos )
149*cdf0e10cSrcweir             return aIter->first;
150*cdf0e10cSrcweir         ++aIter;
151*cdf0e10cSrcweir     }
152*cdf0e10cSrcweir     return C2U( " " );
153*cdf0e10cSrcweir }
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir //.............................................................................
156*cdf0e10cSrcweir } //namespace chart
157*cdf0e10cSrcweir //.............................................................................
158*cdf0e10cSrcweir 
159