1*96de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*96de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*96de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*96de5490SAndrew Rist  * distributed with this work for additional information
6*96de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*96de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*96de5490SAndrew Rist  * "License"); you may not use this file except in compliance
9*96de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*96de5490SAndrew Rist  *
11*96de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*96de5490SAndrew Rist  *
13*96de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*96de5490SAndrew Rist  * software distributed under the License is distributed on an
15*96de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*96de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
17*96de5490SAndrew Rist  * specific language governing permissions and limitations
18*96de5490SAndrew Rist  * under the License.
19*96de5490SAndrew Rist  *
20*96de5490SAndrew Rist  *************************************************************/
21*96de5490SAndrew Rist 
22*96de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifndef _DBAUI_CURLEDIT_HXX_
28cdf0e10cSrcweir #include "curledit.hxx"
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #ifndef _SV_SVAPP_HXX
31cdf0e10cSrcweir #include <vcl/svapp.hxx>
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir 
34cdf0e10cSrcweir //.........................................................................
35cdf0e10cSrcweir namespace dbaui
36cdf0e10cSrcweir {
37cdf0e10cSrcweir //.........................................................................
DBG_NAME(OConnectionURLEdit)38cdf0e10cSrcweir 	DBG_NAME(OConnectionURLEdit)
39cdf0e10cSrcweir //=========================================================================
40cdf0e10cSrcweir //= OConnectionURLEdit
41cdf0e10cSrcweir //=========================================================================
42cdf0e10cSrcweir OConnectionURLEdit::OConnectionURLEdit(Window* _pParent, const ResId& _rResId,sal_Bool _bShowPrefix)
43cdf0e10cSrcweir 	:Edit(_pParent, _rResId)
44cdf0e10cSrcweir     ,m_pTypeCollection(NULL)
45cdf0e10cSrcweir 	,m_pForcedPrefix(NULL)
46cdf0e10cSrcweir 	,m_bShowPrefix(_bShowPrefix)
47cdf0e10cSrcweir {
48cdf0e10cSrcweir 	DBG_CTOR(OConnectionURLEdit ,NULL);
49cdf0e10cSrcweir }
50cdf0e10cSrcweir 
51cdf0e10cSrcweir //-------------------------------------------------------------------------
~OConnectionURLEdit()52cdf0e10cSrcweir OConnectionURLEdit::~OConnectionURLEdit()
53cdf0e10cSrcweir {
54cdf0e10cSrcweir 	DBG_DTOR(OConnectionURLEdit ,NULL);
55cdf0e10cSrcweir 	// delete my sub controls
56cdf0e10cSrcweir 	Edit* pSubEdit = GetSubEdit();
57cdf0e10cSrcweir 	SetSubEdit(NULL);
58cdf0e10cSrcweir 	delete pSubEdit;
59cdf0e10cSrcweir 	delete m_pForcedPrefix;
60cdf0e10cSrcweir }
61cdf0e10cSrcweir 
62cdf0e10cSrcweir //-------------------------------------------------------------------------
SetTextNoPrefix(const String & _rText)63cdf0e10cSrcweir void OConnectionURLEdit::SetTextNoPrefix(const String& _rText)
64cdf0e10cSrcweir {
65cdf0e10cSrcweir 	DBG_ASSERT(GetSubEdit(), "OConnectionURLEdit::SetTextNoPrefix: have no current type, not changing the text!");
66cdf0e10cSrcweir 	if (GetSubEdit())
67cdf0e10cSrcweir 		GetSubEdit()->SetText(_rText);
68cdf0e10cSrcweir }
69cdf0e10cSrcweir 
70cdf0e10cSrcweir //-------------------------------------------------------------------------
GetTextNoPrefix() const71cdf0e10cSrcweir String OConnectionURLEdit::GetTextNoPrefix() const
72cdf0e10cSrcweir {
73cdf0e10cSrcweir 	if (GetSubEdit())
74cdf0e10cSrcweir 		return GetSubEdit()->GetText();
75cdf0e10cSrcweir 	return GetText();
76cdf0e10cSrcweir }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir //-------------------------------------------------------------------------
SetText(const String & _rStr)79cdf0e10cSrcweir void OConnectionURLEdit::SetText(const String& _rStr)
80cdf0e10cSrcweir {
81cdf0e10cSrcweir 	Selection aNoSelection(0,0);
82cdf0e10cSrcweir 	SetText(_rStr, aNoSelection);
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir //-------------------------------------------------------------------------
SetText(const String & _rStr,const Selection &)86cdf0e10cSrcweir void OConnectionURLEdit::SetText(const String& _rStr, const Selection& /*_rNewSelection*/)
87cdf0e10cSrcweir {
88cdf0e10cSrcweir 	// create new sub controls, if necessary
89cdf0e10cSrcweir 	if (!GetSubEdit())
90cdf0e10cSrcweir 		SetSubEdit(new Edit(this, 0));
91cdf0e10cSrcweir 	if ( !m_pForcedPrefix )
92cdf0e10cSrcweir 	{
93cdf0e10cSrcweir 		m_pForcedPrefix = new FixedText(this, WB_VCENTER);
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 		// we use a gray background for the fixed text
96cdf0e10cSrcweir 		StyleSettings aSystemStyle = Application::GetSettings().GetStyleSettings();
97cdf0e10cSrcweir 		m_pForcedPrefix->SetBackground(Wallpaper(aSystemStyle.GetDialogColor()));
98cdf0e10cSrcweir 	}
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 	m_pForcedPrefix->Show(m_bShowPrefix);
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 	sal_Bool bIsEmpty = 0 == _rStr.Len();
103cdf0e10cSrcweir 	// calc the prefix
104cdf0e10cSrcweir 	String sPrefix;
105cdf0e10cSrcweir 	if (!bIsEmpty)
106cdf0e10cSrcweir 	{
107cdf0e10cSrcweir 		// determine the type of the new URL described by the new text
108cdf0e10cSrcweir         sPrefix = m_pTypeCollection->getPrefix(_rStr);
109cdf0e10cSrcweir 	}
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 	// the fixed text gets the prefix
112cdf0e10cSrcweir 	if ( m_pForcedPrefix )
113cdf0e10cSrcweir 		m_pForcedPrefix->SetText(sPrefix);
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 	// both subs have to be resized according to the text len of the prefix
116cdf0e10cSrcweir 	Size aMySize = GetSizePixel();
117cdf0e10cSrcweir 	sal_Int32 nTextWidth = 0;
118cdf0e10cSrcweir 	if ( m_pForcedPrefix && m_bShowPrefix)
119cdf0e10cSrcweir 	{
120cdf0e10cSrcweir 		nTextWidth = m_pForcedPrefix->GetTextWidth(sPrefix) + 2;
121cdf0e10cSrcweir 		m_pForcedPrefix->SetPosSizePixel(Point(0, -2), Size(nTextWidth, aMySize.Height()));
122cdf0e10cSrcweir 	}
123cdf0e10cSrcweir 	GetSubEdit()->SetPosSizePixel(Point(nTextWidth, -2), Size(aMySize.Width() - nTextWidth - 4, aMySize.Height()));
124cdf0e10cSrcweir 		// -2 because the edit has a frame which is 2 pixel wide ... should not be necessary, but I don't fully understand this ....
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 	// show the sub controls (in case they were just created)
127cdf0e10cSrcweir 	GetSubEdit()->Show();
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 	// do the real SetTex
130cdf0e10cSrcweir //	Edit::SetText(bIsEmpty ? _rStr : m_pTypeCollection->cutPrefix(_rStr), _rNewSelection);
131cdf0e10cSrcweir 	String sNewText( _rStr );
132cdf0e10cSrcweir 	if ( !bIsEmpty )
133cdf0e10cSrcweir 		sNewText  = m_pTypeCollection->cutPrefix( _rStr );
134cdf0e10cSrcweir 	Edit::SetText( sNewText );
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir //-------------------------------------------------------------------------
GetText() const138cdf0e10cSrcweir String OConnectionURLEdit::GetText() const
139cdf0e10cSrcweir {
140cdf0e10cSrcweir 	if ( m_pForcedPrefix )
141cdf0e10cSrcweir 		return m_pForcedPrefix->GetText() += Edit::GetText();
142cdf0e10cSrcweir 	return Edit::GetText();
143cdf0e10cSrcweir }
144cdf0e10cSrcweir // -----------------------------------------------------------------------------
ShowPrefix(sal_Bool _bShowPrefix)145cdf0e10cSrcweir void OConnectionURLEdit::ShowPrefix(sal_Bool _bShowPrefix)
146cdf0e10cSrcweir {
147cdf0e10cSrcweir 	m_bShowPrefix = _bShowPrefix;
148cdf0e10cSrcweir 	if ( m_pForcedPrefix )
149cdf0e10cSrcweir 		m_pForcedPrefix->Show(m_bShowPrefix);
150cdf0e10cSrcweir }
151cdf0e10cSrcweir //.........................................................................
152cdf0e10cSrcweir }	// namespace dbaui
153cdf0e10cSrcweir //.........................................................................
154cdf0e10cSrcweir 
155