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