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