merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / ui / control / curledit.cxx
blobbb9c97aaccd658236d172f500bf5196de85cb9c5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: curledit.cxx,v $
10 * $Revision: 1.14.52.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #ifndef _DBAUI_CURLEDIT_HXX_
35 #include "curledit.hxx"
36 #endif
37 #ifndef _SV_SVAPP_HXX
38 #include <vcl/svapp.hxx>
39 #endif
41 //.........................................................................
42 namespace dbaui
44 //.........................................................................
45 DBG_NAME(OConnectionURLEdit)
46 //=========================================================================
47 //= OConnectionURLEdit
48 //=========================================================================
49 OConnectionURLEdit::OConnectionURLEdit(Window* _pParent, const ResId& _rResId,BOOL _bShowPrefix)
50 :Edit(_pParent, _rResId)
51 ,m_pTypeCollection(NULL)
52 ,m_pForcedPrefix(NULL)
53 ,m_bShowPrefix(_bShowPrefix)
55 DBG_CTOR(OConnectionURLEdit ,NULL);
58 //-------------------------------------------------------------------------
59 OConnectionURLEdit::~OConnectionURLEdit()
61 DBG_DTOR(OConnectionURLEdit ,NULL);
62 // delete my sub controls
63 Edit* pSubEdit = GetSubEdit();
64 SetSubEdit(NULL);
65 delete pSubEdit;
66 delete m_pForcedPrefix;
69 //-------------------------------------------------------------------------
70 void OConnectionURLEdit::SetTextNoPrefix(const String& _rText)
72 DBG_ASSERT(GetSubEdit(), "OConnectionURLEdit::SetTextNoPrefix: have no current type, not changing the text!");
73 if (GetSubEdit())
74 GetSubEdit()->SetText(_rText);
77 //-------------------------------------------------------------------------
78 String OConnectionURLEdit::GetTextNoPrefix() const
80 if (GetSubEdit())
81 return GetSubEdit()->GetText();
82 return GetText();
85 //-------------------------------------------------------------------------
86 void OConnectionURLEdit::SetText(const String& _rStr)
88 Selection aNoSelection(0,0);
89 SetText(_rStr, aNoSelection);
92 //-------------------------------------------------------------------------
93 void OConnectionURLEdit::SetText(const String& _rStr, const Selection& /*_rNewSelection*/)
95 // create new sub controls, if necessary
96 if (!GetSubEdit())
97 SetSubEdit(new Edit(this, 0));
98 if ( !m_pForcedPrefix )
100 m_pForcedPrefix = new FixedText(this, WB_VCENTER);
102 // we use a gray background for the fixed text
103 StyleSettings aSystemStyle = Application::GetSettings().GetStyleSettings();
104 m_pForcedPrefix->SetBackground(Wallpaper(aSystemStyle.GetDialogColor()));
107 m_pForcedPrefix->Show(m_bShowPrefix);
109 sal_Bool bIsEmpty = 0 == _rStr.Len();
110 // calc the prefix
111 String sPrefix;
112 if (!bIsEmpty)
114 // determine the type of the new URL described by the new text
115 sPrefix = m_pTypeCollection->getPrefix(_rStr);
118 // the fixed text gets the prefix
119 if ( m_pForcedPrefix )
120 m_pForcedPrefix->SetText(sPrefix);
122 // both subs have to be resized according to the text len of the prefix
123 Size aMySize = GetSizePixel();
124 sal_Int32 nTextWidth = 0;
125 if ( m_pForcedPrefix && m_bShowPrefix)
127 nTextWidth = m_pForcedPrefix->GetTextWidth(sPrefix) + 2;
128 m_pForcedPrefix->SetPosSizePixel(Point(0, -2), Size(nTextWidth, aMySize.Height()));
130 GetSubEdit()->SetPosSizePixel(Point(nTextWidth, -2), Size(aMySize.Width() - nTextWidth - 4, aMySize.Height()));
131 // -2 because the edit has a frame which is 2 pixel wide ... should not be necessary, but I don't fully understand this ....
133 // show the sub controls (in case they were just created)
134 GetSubEdit()->Show();
136 // do the real SetTex
137 // Edit::SetText(bIsEmpty ? _rStr : m_pTypeCollection->cutPrefix(_rStr), _rNewSelection);
138 String sNewText( _rStr );
139 if ( !bIsEmpty )
140 sNewText = m_pTypeCollection->cutPrefix( _rStr );
141 Edit::SetText( sNewText );
144 //-------------------------------------------------------------------------
145 String OConnectionURLEdit::GetText() const
147 if ( m_pForcedPrefix )
148 return m_pForcedPrefix->GetText() += Edit::GetText();
149 return Edit::GetText();
151 // -----------------------------------------------------------------------------
152 void OConnectionURLEdit::ShowPrefix(BOOL _bShowPrefix)
154 m_bShowPrefix = _bShowPrefix;
155 if ( m_pForcedPrefix )
156 m_pForcedPrefix->Show(m_bShowPrefix);
158 //.........................................................................
159 } // namespace dbaui
160 //.........................................................................