Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "textcontrolcombo.hxx"
21 :
22 :
23 0 : TextControlCombo::TextControlCombo( Window* _pParent, const ResId& _rResId,
24 : Control& _rCtrl, FixedText& _rFTbefore, FixedText& _rFTafter )
25 : :Window ( _pParent, _rResId )
26 : ,mrCtrl ( _rCtrl )
27 : ,mrFTbefore ( _rFTbefore )
28 0 : ,mrFTafter ( _rFTafter )
29 : {
30 0 : }
31 :
32 0 : TextControlCombo::~TextControlCombo()
33 : {
34 0 : }
35 :
36 0 : void TextControlCombo::Arrange( FixedText& _rFTcomplete, sal_Bool /*bShow*/ )
37 : {
38 0 : Point aBasePos( GetPosPixel() );
39 0 : Size aMetricVals( GetSizePixel() );
40 :
41 0 : long nTextHeight = _rFTcomplete.GetSizePixel().Height();
42 0 : long nCtrlHeight = mrCtrl.GetSizePixel().Height();
43 :
44 : // calc y positions / center vertical
45 0 : long nYFT = aBasePos.Y();
46 0 : long nYCtrl = nYFT;
47 0 : if( nCtrlHeight > nTextHeight )
48 0 : nYFT += aMetricVals.Height();
49 : else
50 0 : nYCtrl += aMetricVals.Height();
51 :
52 : // separate text parts
53 0 : const String aReplStr( RTL_CONSTASCII_USTRINGPARAM( "%POSITION_OF_CONTROL" ) );
54 0 : String aTxtBefore( _rFTcomplete.GetText() );
55 0 : String aTxtAfter;
56 0 : xub_StrLen nReplPos = aTxtBefore.Search( aReplStr );
57 0 : if( nReplPos != STRING_NOTFOUND )
58 : {
59 0 : xub_StrLen nStrStartAfter = nReplPos + aReplStr.Len();
60 0 : aTxtAfter = String( aTxtBefore, nStrStartAfter, aTxtBefore.Len() - nStrStartAfter );
61 0 : aTxtBefore.Erase( nReplPos );
62 : }
63 :
64 : // arrange and fill Fixed Texts
65 0 : long nX = aBasePos.X();
66 0 : long nWidth = GetTextWidth( aTxtBefore );
67 :
68 0 : mrFTbefore.SetText( aTxtBefore );
69 0 : mrFTbefore.setPosSizePixel( nX, nYFT, nWidth, nTextHeight );
70 :
71 0 : nX += nWidth;
72 0 : nX += aMetricVals.Width();
73 0 : mrCtrl.SetPosPixel( Point( nX, nYCtrl ) );
74 :
75 0 : nX += mrCtrl.GetSizePixel().Width();
76 0 : nX += aMetricVals.Width();
77 0 : mrFTafter.SetText( aTxtAfter );
78 0 : mrFTafter.setPosSizePixel( nX, nYFT, GetTextWidth( aTxtAfter ), nTextHeight );
79 :
80 0 : _rFTcomplete.Hide();
81 :
82 0 : Show();
83 :
84 0 : Window::Hide();
85 0 : }
86 :
87 0 : void TextControlCombo::Show( sal_Bool _bVisible, sal_uInt16 _nFlags )
88 : {
89 0 : mrCtrl.Show( _bVisible, _nFlags );
90 0 : mrFTbefore.Show( _bVisible, _nFlags );
91 0 : mrFTafter.Show( _bVisible, _nFlags );
92 0 : }
93 :
94 0 : void TextControlCombo::Enable( sal_Bool _bEnable, sal_Bool _bChild )
95 : {
96 0 : mrCtrl.Enable( _bEnable, _bChild );
97 0 : mrFTbefore.Enable( _bEnable, _bChild );
98 0 : mrFTafter.Enable( _bEnable, _bChild );
99 0 : }
100 :
101 :
102 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|