1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_chart2.hxx" 26 27 #include "res_TextSeparator.hxx" 28 #include "ResourceIds.hrc" 29 #include "Strings.hrc" 30 #include "ResId.hxx" 31 #include "macros.hxx" 32 33 #ifndef _SVT_CONTROLDIMS_HRC_ 34 #include <svtools/controldims.hrc> 35 #endif 36 37 //............................................................................. 38 namespace chart 39 { 40 //............................................................................. 41 42 TextSeparatorResources::TextSeparatorResources( Window* pWindow ) 43 : m_aFT_Separator( pWindow, pWindow->GetStyle() ) 44 , m_aLB_Separator( pWindow , SchResId( LB_TEXT_SEPARATOR ) ) 45 , m_aEntryMap() 46 , m_nDefaultPos(0) 47 { 48 m_aFT_Separator.SetText( String( SchResId( STR_TEXT_SEPARATOR )) ); 49 m_aFT_Separator.SetSizePixel( m_aFT_Separator.CalcMinimumSize() ); 50 51 m_aLB_Separator.SetDropDownLineCount(m_aLB_Separator.GetEntryCount()); 52 m_aLB_Separator.SetSizePixel( m_aLB_Separator.CalcMinimumSize() ); 53 54 m_aEntryMap[ C2U( " " ) ] = 0; 55 m_aEntryMap[ C2U( ", " ) ] = 1; 56 m_aEntryMap[ C2U( "; " ) ] = 2; 57 m_aEntryMap[ C2U( "\n" ) ] = 3; 58 59 m_aLB_Separator.SetAccessibleName(m_aFT_Separator.GetText()); 60 m_aLB_Separator.SetAccessibleRelationLabeledBy(&m_aFT_Separator); 61 } 62 TextSeparatorResources::~TextSeparatorResources() 63 { 64 } 65 void TextSeparatorResources::Show( bool bShow ) 66 { 67 m_aFT_Separator.Show( bShow ); 68 m_aLB_Separator.Show( bShow ); 69 } 70 void TextSeparatorResources::Enable( bool bEnable ) 71 { 72 m_aFT_Separator.Enable( bEnable ); 73 m_aLB_Separator.Enable( bEnable ); 74 } 75 void TextSeparatorResources::PositionBelowControl( const Window& rWindow ) 76 { 77 Point aPoint( rWindow.GetPosPixel() ); 78 Size aSize( rWindow.GetSizePixel() ); 79 aPoint.Y() += aSize.Height(); 80 Size aBigDistanceSize( rWindow.LogicToPixel( Size(0,RSC_SP_CTRL_Y), MapMode(MAP_APPFONT) ) ); 81 aPoint.Y() += aBigDistanceSize.Height(); 82 83 Size aDistanceSize( rWindow.LogicToPixel( Size(RSC_SP_CTRL_DESC_X, (RSC_CD_DROPDOWN_HEIGHT-RSC_CD_FIXEDTEXT_HEIGHT)/2), MapMode(MAP_APPFONT) ) ); 84 aPoint.Y() += aDistanceSize.Height(); 85 86 m_aFT_Separator.SetPosPixel( aPoint ); 87 m_aLB_Separator.SetPosPixel( Point( aPoint.X()+m_aFT_Separator.GetSizePixel().Width()+aDistanceSize.Width(), aPoint.Y()-aDistanceSize.Height()-1) ); 88 } 89 90 void TextSeparatorResources::AlignListBoxWidthAndXPos( long nWantedLeftBorder /*use -1 to indicate that this can be automatic*/ 91 , long nWantedRightBorder /*use -1 to indicate that this can be automatic*/ 92 , long nMinimumListBoxWidth /*use -1 to indicate that this can be automatic*/ ) 93 { 94 long nMinPossibleLeftBorder = m_aFT_Separator.GetPosPixel().X() + m_aFT_Separator.GetSizePixel().Width() + 1 ; 95 if( nWantedLeftBorder >= 0 && nWantedLeftBorder>nMinPossibleLeftBorder ) 96 { 97 Point aPos( m_aLB_Separator.GetPosPixel() ); 98 aPos.X() = nWantedLeftBorder; 99 m_aLB_Separator.SetPosPixel( aPos ); 100 } 101 102 long nMinPossibleRightBorder = m_aLB_Separator.GetPosPixel().X() + m_aLB_Separator.CalcMinimumSize().Width() - 1 ; 103 if( nWantedRightBorder < m_aLB_Separator.GetPosPixel().X() + nMinimumListBoxWidth ) 104 nWantedRightBorder = m_aLB_Separator.GetPosPixel().X() + nMinimumListBoxWidth; 105 106 if( nWantedRightBorder >= 0 && nWantedRightBorder > nMinPossibleRightBorder ) 107 { 108 Size aSize( m_aLB_Separator.GetSizePixel() ); 109 aSize.Width() = nWantedRightBorder-m_aLB_Separator.GetPosPixel().X(); 110 m_aLB_Separator.SetSizePixel(aSize); 111 } 112 } 113 114 Point TextSeparatorResources::GetCurrentListBoxPosition() const 115 { 116 return m_aLB_Separator.GetPosPixel(); 117 } 118 119 Size TextSeparatorResources::GetCurrentListBoxSize() const 120 { 121 return m_aLB_Separator.GetSizePixel(); 122 } 123 124 void TextSeparatorResources::SetValue( const rtl::OUString& rSeparator ) 125 { 126 ::std::map< ::rtl::OUString, sal_uInt16 >::iterator aIter( m_aEntryMap.find(rSeparator) ); 127 if( aIter == m_aEntryMap.end() ) 128 m_aLB_Separator.SelectEntryPos( m_nDefaultPos ); 129 else 130 m_aLB_Separator.SelectEntryPos( aIter->second ); 131 } 132 133 void TextSeparatorResources::SetDefault() 134 { 135 m_aLB_Separator.SelectEntryPos( m_nDefaultPos ); 136 } 137 138 rtl::OUString TextSeparatorResources::GetValue() const 139 { 140 sal_uInt16 nPos = m_aLB_Separator.GetSelectEntryPos(); 141 ::std::map< ::rtl::OUString, sal_uInt16 >::const_iterator aIter( m_aEntryMap.begin() ); 142 while( aIter != m_aEntryMap.end() ) 143 { 144 if(aIter->second==nPos ) 145 return aIter->first; 146 ++aIter; 147 } 148 return C2U( " " ); 149 } 150 151 //............................................................................. 152 } //namespace chart 153 //............................................................................. 154 155