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_dbaccess.hxx"
30 
31 #ifndef _DBAUI_CURLEDIT_HXX_
32 #include "curledit.hxx"
33 #endif
34 #ifndef _SV_SVAPP_HXX
35 #include <vcl/svapp.hxx>
36 #endif
37 
38 //.........................................................................
39 namespace dbaui
40 {
41 //.........................................................................
42 	DBG_NAME(OConnectionURLEdit)
43 //=========================================================================
44 //= OConnectionURLEdit
45 //=========================================================================
46 OConnectionURLEdit::OConnectionURLEdit(Window* _pParent, const ResId& _rResId,sal_Bool _bShowPrefix)
47 	:Edit(_pParent, _rResId)
48     ,m_pTypeCollection(NULL)
49 	,m_pForcedPrefix(NULL)
50 	,m_bShowPrefix(_bShowPrefix)
51 {
52 	DBG_CTOR(OConnectionURLEdit ,NULL);
53 }
54 
55 //-------------------------------------------------------------------------
56 OConnectionURLEdit::~OConnectionURLEdit()
57 {
58 	DBG_DTOR(OConnectionURLEdit ,NULL);
59 	// delete my sub controls
60 	Edit* pSubEdit = GetSubEdit();
61 	SetSubEdit(NULL);
62 	delete pSubEdit;
63 	delete m_pForcedPrefix;
64 }
65 
66 //-------------------------------------------------------------------------
67 void OConnectionURLEdit::SetTextNoPrefix(const String& _rText)
68 {
69 	DBG_ASSERT(GetSubEdit(), "OConnectionURLEdit::SetTextNoPrefix: have no current type, not changing the text!");
70 	if (GetSubEdit())
71 		GetSubEdit()->SetText(_rText);
72 }
73 
74 //-------------------------------------------------------------------------
75 String OConnectionURLEdit::GetTextNoPrefix() const
76 {
77 	if (GetSubEdit())
78 		return GetSubEdit()->GetText();
79 	return GetText();
80 }
81 
82 //-------------------------------------------------------------------------
83 void OConnectionURLEdit::SetText(const String& _rStr)
84 {
85 	Selection aNoSelection(0,0);
86 	SetText(_rStr, aNoSelection);
87 }
88 
89 //-------------------------------------------------------------------------
90 void OConnectionURLEdit::SetText(const String& _rStr, const Selection& /*_rNewSelection*/)
91 {
92 	// create new sub controls, if necessary
93 	if (!GetSubEdit())
94 		SetSubEdit(new Edit(this, 0));
95 	if ( !m_pForcedPrefix )
96 	{
97 		m_pForcedPrefix = new FixedText(this, WB_VCENTER);
98 
99 		// we use a gray background for the fixed text
100 		StyleSettings aSystemStyle = Application::GetSettings().GetStyleSettings();
101 		m_pForcedPrefix->SetBackground(Wallpaper(aSystemStyle.GetDialogColor()));
102 	}
103 
104 	m_pForcedPrefix->Show(m_bShowPrefix);
105 
106 	sal_Bool bIsEmpty = 0 == _rStr.Len();
107 	// calc the prefix
108 	String sPrefix;
109 	if (!bIsEmpty)
110 	{
111 		// determine the type of the new URL described by the new text
112         sPrefix = m_pTypeCollection->getPrefix(_rStr);
113 	}
114 
115 	// the fixed text gets the prefix
116 	if ( m_pForcedPrefix )
117 		m_pForcedPrefix->SetText(sPrefix);
118 
119 	// both subs have to be resized according to the text len of the prefix
120 	Size aMySize = GetSizePixel();
121 	sal_Int32 nTextWidth = 0;
122 	if ( m_pForcedPrefix && m_bShowPrefix)
123 	{
124 		nTextWidth = m_pForcedPrefix->GetTextWidth(sPrefix) + 2;
125 		m_pForcedPrefix->SetPosSizePixel(Point(0, -2), Size(nTextWidth, aMySize.Height()));
126 	}
127 	GetSubEdit()->SetPosSizePixel(Point(nTextWidth, -2), Size(aMySize.Width() - nTextWidth - 4, aMySize.Height()));
128 		// -2 because the edit has a frame which is 2 pixel wide ... should not be necessary, but I don't fully understand this ....
129 
130 	// show the sub controls (in case they were just created)
131 	GetSubEdit()->Show();
132 
133 	// do the real SetTex
134 //	Edit::SetText(bIsEmpty ? _rStr : m_pTypeCollection->cutPrefix(_rStr), _rNewSelection);
135 	String sNewText( _rStr );
136 	if ( !bIsEmpty )
137 		sNewText  = m_pTypeCollection->cutPrefix( _rStr );
138 	Edit::SetText( sNewText );
139 }
140 
141 //-------------------------------------------------------------------------
142 String OConnectionURLEdit::GetText() const
143 {
144 	if ( m_pForcedPrefix )
145 		return m_pForcedPrefix->GetText() += Edit::GetText();
146 	return Edit::GetText();
147 }
148 // -----------------------------------------------------------------------------
149 void OConnectionURLEdit::ShowPrefix(sal_Bool _bShowPrefix)
150 {
151 	m_bShowPrefix = _bShowPrefix;
152 	if ( m_pForcedPrefix )
153 		m_pForcedPrefix->Show(m_bShowPrefix);
154 }
155 //.........................................................................
156 }	// namespace dbaui
157 //.........................................................................
158 
159