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_sw.hxx" 30 31 32 #include "textcontrolcombo.hxx" 33 34 35 TextControlCombo::TextControlCombo( Window* _pParent, const ResId& _rResId, 36 Control& _rCtrl, FixedText& _rFTbefore, FixedText& _rFTafter ) 37 :Window ( _pParent, _rResId ) 38 ,mrCtrl ( _rCtrl ) 39 ,mrFTbefore ( _rFTbefore ) 40 ,mrFTafter ( _rFTafter ) 41 { 42 } 43 44 TextControlCombo::~TextControlCombo() 45 { 46 } 47 48 void TextControlCombo::Arrange( FixedText& _rFTcomplete, sal_Bool /*bShow*/ ) 49 { 50 Point aBasePos( GetPosPixel() ); 51 Size aMetricVals( GetSizePixel() ); 52 53 long nTextHeight = _rFTcomplete.GetSizePixel().Height(); 54 long nCtrlHeight = mrCtrl.GetSizePixel().Height(); 55 56 // calc y positions / center vertical 57 long nYFT = aBasePos.Y(); 58 long nYCtrl = nYFT; 59 if( nCtrlHeight > nTextHeight ) 60 nYFT += aMetricVals.Height(); 61 else 62 nYCtrl += aMetricVals.Height(); 63 64 // separate text parts 65 const String aReplStr( RTL_CONSTASCII_STRINGPARAM( "%POSITION_OF_CONTROL" ) ); 66 String aTxtBefore( _rFTcomplete.GetText() ); 67 String aTxtAfter; 68 xub_StrLen nReplPos = aTxtBefore.Search( aReplStr ); 69 if( nReplPos != STRING_NOTFOUND ) 70 { 71 xub_StrLen nStrStartAfter = nReplPos + aReplStr.Len(); 72 aTxtAfter = String( aTxtBefore, nStrStartAfter, aTxtBefore.Len() - nStrStartAfter ); 73 aTxtBefore.Erase( nReplPos ); 74 } 75 76 // arrange and fill Fixed Texts 77 long nX = aBasePos.X(); 78 long nWidth = GetTextWidth( aTxtBefore ); 79 80 mrFTbefore.SetText( aTxtBefore ); 81 mrFTbefore.SetPosSizePixel( nX, nYFT, nWidth, nTextHeight ); 82 83 nX += nWidth; 84 nX += aMetricVals.Width(); 85 mrCtrl.SetPosPixel( Point( nX, nYCtrl ) ); 86 87 nX += mrCtrl.GetSizePixel().Width(); 88 nX += aMetricVals.Width(); 89 mrFTafter.SetText( aTxtAfter ); 90 mrFTafter.SetPosSizePixel( nX, nYFT, GetTextWidth( aTxtAfter ), nTextHeight ); 91 92 _rFTcomplete.Hide(); 93 94 Show(); 95 96 Window::Hide(); 97 } 98 99 void TextControlCombo::Show( sal_Bool _bVisible, sal_uInt16 _nFlags ) 100 { 101 mrCtrl.Show( _bVisible, _nFlags ); 102 mrFTbefore.Show( _bVisible, _nFlags ); 103 mrFTafter.Show( _bVisible, _nFlags ); 104 } 105 106 void TextControlCombo::Enable( sal_Bool _bEnable, sal_Bool _bChild ) 107 { 108 mrCtrl.Enable( _bEnable, _bChild ); 109 mrFTbefore.Enable( _bEnable, _bChild ); 110 mrFTafter.Enable( _bEnable, _bChild ); 111 } 112 113 114