2010-10-12 15:59:03 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-14 17:39:53 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2000-10-05 08:59:38 +00:00
|
|
|
|
|
|
|
#include "curledit.hxx"
|
2000-10-18 15:00:47 +00:00
|
|
|
#include <vcl/svapp.hxx>
|
2014-01-02 23:52:37 +01:00
|
|
|
#include <vcl/settings.hxx>
|
2011-02-03 00:33:36 +01:00
|
|
|
#include <osl/diagnose.h>
|
2000-10-05 08:59:38 +00:00
|
|
|
|
|
|
|
namespace dbaui
|
|
|
|
{
|
|
|
|
|
2014-09-23 11:20:40 +02:00
|
|
|
OConnectionURLEdit::OConnectionURLEdit(vcl::Window* _pParent, WinBits _nBits,bool _bShowPrefix)
|
2014-07-27 13:56:58 +02:00
|
|
|
:Edit(_pParent, _nBits)
|
|
|
|
,m_pTypeCollection(NULL)
|
|
|
|
,m_pForcedPrefix(NULL)
|
|
|
|
,m_bShowPrefix(_bShowPrefix)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-09-23 11:20:40 +02:00
|
|
|
extern "C" SAL_DLLPUBLIC_EXPORT vcl::Window* SAL_CALL makeConnectionURLEdit(vcl::Window *pParent)
|
2014-07-27 13:56:58 +02:00
|
|
|
{
|
|
|
|
return new OConnectionURLEdit(pParent, WB_BORDER, false);
|
|
|
|
}
|
|
|
|
|
2000-10-05 08:59:38 +00:00
|
|
|
OConnectionURLEdit::~OConnectionURLEdit()
|
|
|
|
{
|
|
|
|
// delete my sub controls
|
|
|
|
Edit* pSubEdit = GetSubEdit();
|
|
|
|
SetSubEdit(NULL);
|
|
|
|
delete pSubEdit;
|
|
|
|
delete m_pForcedPrefix;
|
|
|
|
}
|
|
|
|
|
2013-09-26 12:17:53 +02:00
|
|
|
void OConnectionURLEdit::SetTextNoPrefix(const OUString& _rText)
|
2000-10-24 11:08:19 +00:00
|
|
|
{
|
2011-02-03 00:33:36 +01:00
|
|
|
OSL_ENSURE(GetSubEdit(), "OConnectionURLEdit::SetTextNoPrefix: have no current type, not changing the text!");
|
2000-10-24 11:08:19 +00:00
|
|
|
if (GetSubEdit())
|
|
|
|
GetSubEdit()->SetText(_rText);
|
|
|
|
}
|
|
|
|
|
2013-09-26 12:17:53 +02:00
|
|
|
OUString OConnectionURLEdit::GetTextNoPrefix() const
|
2000-10-24 11:08:19 +00:00
|
|
|
{
|
|
|
|
if (GetSubEdit())
|
|
|
|
return GetSubEdit()->GetText();
|
|
|
|
return GetText();
|
|
|
|
}
|
|
|
|
|
2013-01-21 14:32:09 +01:00
|
|
|
void OConnectionURLEdit::SetText(const OUString& _rStr)
|
2000-10-05 08:59:38 +00:00
|
|
|
{
|
|
|
|
Selection aNoSelection(0,0);
|
|
|
|
SetText(_rStr, aNoSelection);
|
|
|
|
}
|
|
|
|
|
2015-03-05 23:15:26 +01:00
|
|
|
void OConnectionURLEdit::Resize()
|
|
|
|
{
|
|
|
|
if (GetSubEdit())
|
|
|
|
{
|
|
|
|
Size aMySize = GetSizePixel();
|
|
|
|
sal_Int32 nTextWidth = 0;
|
|
|
|
if ( m_pForcedPrefix && m_bShowPrefix)
|
|
|
|
{
|
|
|
|
nTextWidth = m_pForcedPrefix->GetTextWidth(m_pForcedPrefix->GetText()) + 2;
|
|
|
|
m_pForcedPrefix->SetPosSizePixel(Point(0, -2), Size(nTextWidth, aMySize.Height()));
|
|
|
|
}
|
|
|
|
GetSubEdit()->SetPosSizePixel(Point(nTextWidth, -2), Size(aMySize.Width() - nTextWidth - 4, aMySize.Height()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-21 14:32:09 +01:00
|
|
|
void OConnectionURLEdit::SetText(const OUString& _rStr, const Selection& /*_rNewSelection*/)
|
2000-10-05 08:59:38 +00:00
|
|
|
{
|
|
|
|
// create new sub controls, if necessary
|
|
|
|
if (!GetSubEdit())
|
|
|
|
SetSubEdit(new Edit(this, 0));
|
2004-08-02 14:36:09 +00:00
|
|
|
if ( !m_pForcedPrefix )
|
2000-10-18 15:00:47 +00:00
|
|
|
{
|
|
|
|
m_pForcedPrefix = new FixedText(this, WB_VCENTER);
|
|
|
|
|
|
|
|
// we use a gray background for the fixed text
|
|
|
|
StyleSettings aSystemStyle = Application::GetSettings().GetStyleSettings();
|
|
|
|
m_pForcedPrefix->SetBackground(Wallpaper(aSystemStyle.GetDialogColor()));
|
|
|
|
}
|
2000-10-05 08:59:38 +00:00
|
|
|
|
2004-08-02 14:36:09 +00:00
|
|
|
m_pForcedPrefix->Show(m_bShowPrefix);
|
|
|
|
|
2014-04-17 11:16:55 +02:00
|
|
|
bool bIsEmpty = _rStr.isEmpty();
|
2000-10-05 08:59:38 +00:00
|
|
|
// calc the prefix
|
2013-09-26 12:17:53 +02:00
|
|
|
OUString sPrefix;
|
2000-10-05 08:59:38 +00:00
|
|
|
if (!bIsEmpty)
|
|
|
|
{
|
|
|
|
// determine the type of the new URL described by the new text
|
2009-07-03 12:24:35 +00:00
|
|
|
sPrefix = m_pTypeCollection->getPrefix(_rStr);
|
2000-10-05 08:59:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// the fixed text gets the prefix
|
2014-02-19 11:15:26 +02:00
|
|
|
m_pForcedPrefix->SetText(sPrefix);
|
2000-10-05 08:59:38 +00:00
|
|
|
|
|
|
|
// both subs have to be resized according to the text len of the prefix
|
|
|
|
Size aMySize = GetSizePixel();
|
2004-08-02 14:36:09 +00:00
|
|
|
sal_Int32 nTextWidth = 0;
|
|
|
|
if ( m_pForcedPrefix && m_bShowPrefix)
|
|
|
|
{
|
|
|
|
nTextWidth = m_pForcedPrefix->GetTextWidth(sPrefix) + 2;
|
|
|
|
m_pForcedPrefix->SetPosSizePixel(Point(0, -2), Size(nTextWidth, aMySize.Height()));
|
|
|
|
}
|
2000-10-05 08:59:38 +00:00
|
|
|
GetSubEdit()->SetPosSizePixel(Point(nTextWidth, -2), Size(aMySize.Width() - nTextWidth - 4, aMySize.Height()));
|
|
|
|
// -2 because the edit has a frame which is 2 pixel wide ... should not be necessary, but I don't fully understand this ....
|
|
|
|
|
|
|
|
// show the sub controls (in case they were just created)
|
|
|
|
GetSubEdit()->Show();
|
|
|
|
|
|
|
|
// do the real SetTex
|
2009-07-03 12:24:35 +00:00
|
|
|
// Edit::SetText(bIsEmpty ? _rStr : m_pTypeCollection->cutPrefix(_rStr), _rNewSelection);
|
2013-09-26 12:17:53 +02:00
|
|
|
OUString sNewText( _rStr );
|
2001-09-28 13:53:55 +00:00
|
|
|
if ( !bIsEmpty )
|
2009-07-03 12:24:35 +00:00
|
|
|
sNewText = m_pTypeCollection->cutPrefix( _rStr );
|
2001-09-28 13:53:55 +00:00
|
|
|
Edit::SetText( sNewText );
|
2000-10-05 08:59:38 +00:00
|
|
|
}
|
|
|
|
|
2013-01-21 14:32:09 +01:00
|
|
|
OUString OConnectionURLEdit::GetText() const
|
2000-10-05 08:59:38 +00:00
|
|
|
{
|
2004-08-02 14:36:09 +00:00
|
|
|
if ( m_pForcedPrefix )
|
2000-10-05 08:59:38 +00:00
|
|
|
return m_pForcedPrefix->GetText() += Edit::GetText();
|
|
|
|
return Edit::GetText();
|
|
|
|
}
|
2013-08-17 23:43:14 +02:00
|
|
|
|
2014-04-17 11:16:55 +02:00
|
|
|
void OConnectionURLEdit::ShowPrefix(bool _bShowPrefix)
|
2004-08-02 14:36:09 +00:00
|
|
|
{
|
|
|
|
m_bShowPrefix = _bShowPrefix;
|
|
|
|
if ( m_pForcedPrefix )
|
|
|
|
m_pForcedPrefix->Show(m_bShowPrefix);
|
|
|
|
}
|
2013-08-17 23:43:14 +02:00
|
|
|
|
2000-10-05 08:59:38 +00:00
|
|
|
} // namespace dbaui
|
|
|
|
|
2010-10-12 15:59:03 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|