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