fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dbaccess / source / ui / control / curledit.cxx
blob483bd414a2109048b84d0571c46f800ec2279437
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "curledit.hxx"
21 #include <vcl/svapp.hxx>
22 #include <vcl/settings.hxx>
23 #include <vcl/builderfactory.hxx>
24 #include <osl/diagnose.h>
26 namespace dbaui
29 OConnectionURLEdit::OConnectionURLEdit(vcl::Window* _pParent, WinBits _nBits,bool _bShowPrefix)
30 :Edit(_pParent, _nBits)
31 ,m_pTypeCollection(NULL)
32 ,m_pForcedPrefix(NULL)
33 ,m_bShowPrefix(_bShowPrefix)
37 VCL_BUILDER_DECL_FACTORY(ConnectionURLEdit)
39 (void)rMap;
40 rRet = VclPtr<OConnectionURLEdit>::Create(pParent, WB_BORDER, false);
43 OConnectionURLEdit::~OConnectionURLEdit()
45 disposeOnce();
48 void OConnectionURLEdit::dispose()
50 SetSubEdit(nullptr);
51 m_pForcedPrefix.disposeAndClear();
52 Edit::dispose();
55 void OConnectionURLEdit::SetTextNoPrefix(const OUString& _rText)
57 OSL_ENSURE(GetSubEdit(), "OConnectionURLEdit::SetTextNoPrefix: have no current type, not changing the text!");
58 if (GetSubEdit())
59 GetSubEdit()->SetText(_rText);
62 OUString OConnectionURLEdit::GetTextNoPrefix() const
64 if (GetSubEdit())
65 return GetSubEdit()->GetText();
66 return GetText();
69 void OConnectionURLEdit::SetText(const OUString& _rStr)
71 Selection aNoSelection(0,0);
72 SetText(_rStr, aNoSelection);
75 void OConnectionURLEdit::Resize()
77 if (GetSubEdit())
79 Size aMySize = GetSizePixel();
80 sal_Int32 nTextWidth = 0;
81 if ( m_pForcedPrefix && m_bShowPrefix)
83 nTextWidth = m_pForcedPrefix->GetTextWidth(m_pForcedPrefix->GetText()) + 2;
84 m_pForcedPrefix->SetPosSizePixel(Point(0, -2), Size(nTextWidth, aMySize.Height()));
86 GetSubEdit()->SetPosSizePixel(Point(nTextWidth, -2), Size(aMySize.Width() - nTextWidth - 4, aMySize.Height()));
90 void OConnectionURLEdit::SetText(const OUString& _rStr, const Selection& /*_rNewSelection*/)
92 // create new sub controls, if necessary
93 if (!GetSubEdit())
94 SetSubEdit(VclPtr<Edit>::Create(this, 0));
95 if ( !m_pForcedPrefix )
97 m_pForcedPrefix = VclPtr<FixedText>::Create(this, WB_VCENTER);
99 // we use a gray background for the fixed text
100 StyleSettings aSystemStyle = Application::GetSettings().GetStyleSettings();
101 m_pForcedPrefix->SetBackground(Wallpaper(aSystemStyle.GetDialogColor()));
104 m_pForcedPrefix->Show(m_bShowPrefix);
106 bool bIsEmpty = _rStr.isEmpty();
107 // calc the prefix
108 OUString sPrefix;
109 if (!bIsEmpty)
111 // determine the type of the new URL described by the new text
112 sPrefix = m_pTypeCollection->getPrefix(_rStr);
115 // the fixed text gets the prefix
116 m_pForcedPrefix->SetText(sPrefix);
118 // both subs have to be resized according to the text len of the prefix
119 Size aMySize = GetSizePixel();
120 sal_Int32 nTextWidth = 0;
121 if ( m_pForcedPrefix && m_bShowPrefix)
123 nTextWidth = m_pForcedPrefix->GetTextWidth(sPrefix) + 2;
124 m_pForcedPrefix->SetPosSizePixel(Point(0, -2), Size(nTextWidth, aMySize.Height()));
126 GetSubEdit()->SetPosSizePixel(Point(nTextWidth, -2), Size(aMySize.Width() - nTextWidth - 4, aMySize.Height()));
127 // -2 because the edit has a frame which is 2 pixel wide ... should not be necessary, but I don't fully understand this ....
129 // show the sub controls (in case they were just created)
130 GetSubEdit()->Show();
132 // do the real SetTex
133 // Edit::SetText(bIsEmpty ? _rStr : m_pTypeCollection->cutPrefix(_rStr), _rNewSelection);
134 OUString sNewText( _rStr );
135 if ( !bIsEmpty )
136 sNewText = m_pTypeCollection->cutPrefix( _rStr );
137 Edit::SetText( sNewText );
140 OUString OConnectionURLEdit::GetText() const
142 if ( m_pForcedPrefix )
143 return m_pForcedPrefix->GetText() += Edit::GetText();
144 return Edit::GetText();
147 void OConnectionURLEdit::ShowPrefix(bool _bShowPrefix)
149 m_bShowPrefix = _bShowPrefix;
150 if ( m_pForcedPrefix )
151 m_pForcedPrefix->Show(m_bShowPrefix);
154 } // namespace dbaui
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */