2010-10-14 08:27:31 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-06 12:12:33 +00: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-09-18 16:07:07 +00:00
|
|
|
|
2007-06-27 19:04:56 +00:00
|
|
|
#include <vcl/svapp.hxx>
|
|
|
|
#include <vcl/event.hxx>
|
|
|
|
#include <vcl/ctrl.hxx>
|
2017-08-04 11:17:06 +05:30
|
|
|
#include <vcl/floatwin.hxx>
|
2007-06-27 19:04:56 +00:00
|
|
|
#include <vcl/decoview.hxx>
|
2017-07-28 18:07:44 +05:30
|
|
|
#include <vcl/dialog.hxx>
|
2007-06-27 19:04:56 +00:00
|
|
|
#include <vcl/salnativewidgets.hxx>
|
2014-01-02 23:52:37 +01:00
|
|
|
#include <vcl/settings.hxx>
|
2017-03-20 00:52:12 +01:00
|
|
|
#include <vcl/uitest/logger.hxx>
|
2018-07-28 15:57:23 +02:00
|
|
|
#include <sal/log.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2011-01-24 16:34:14 +01:00
|
|
|
#include <textlayout.hxx>
|
|
|
|
#include <svdata.hxx>
|
|
|
|
#include <controldata.hxx>
|
|
|
|
|
2002-04-29 16:46:18 +00:00
|
|
|
using namespace vcl;
|
|
|
|
|
2006-06-19 18:15:52 +00:00
|
|
|
void Control::ImplInitControlData()
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2014-01-28 19:59:13 +01:00
|
|
|
mbHasControlFocus = false;
|
2015-07-08 18:02:50 +01:00
|
|
|
mbShowAccelerator = false;
|
2018-04-16 12:31:57 +02:00
|
|
|
mpControlData.reset(new ImplControlData);
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Control::Control( WindowType nType ) :
|
|
|
|
Window( nType )
|
|
|
|
{
|
2006-06-19 18:15:52 +00:00
|
|
|
ImplInitControlData();
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2014-09-23 11:20:40 +02:00
|
|
|
Control::Control( vcl::Window* pParent, WinBits nStyle ) :
|
2017-02-13 19:08:14 +02:00
|
|
|
Window( WindowType::CONTROL )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2006-06-19 18:15:52 +00:00
|
|
|
ImplInitControlData();
|
2015-11-10 10:28:29 +01:00
|
|
|
ImplInit( pParent, nStyle, nullptr );
|
2012-05-23 13:17:44 +01:00
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2002-04-29 16:46:18 +00:00
|
|
|
Control::~Control()
|
2015-01-12 11:38:12 +02:00
|
|
|
{
|
2015-03-10 09:07:06 +02:00
|
|
|
disposeOnce();
|
2015-01-12 11:38:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Control::dispose()
|
2002-04-29 16:46:18 +00:00
|
|
|
{
|
2018-04-16 12:31:57 +02:00
|
|
|
mpControlData.reset();
|
2015-01-12 11:38:12 +02:00
|
|
|
Window::dispose();
|
2002-04-29 16:46:18 +00:00
|
|
|
}
|
|
|
|
|
2014-03-23 18:51:13 +11:00
|
|
|
void Control::EnableRTL( bool bEnable )
|
|
|
|
{
|
|
|
|
// convenience: for controls also switch layout mode
|
2016-05-30 14:00:22 +02:00
|
|
|
SetLayoutMode( bEnable ? ComplexTextLayoutFlags::BiDiRtl | ComplexTextLayoutFlags::TextOriginLeft :
|
|
|
|
ComplexTextLayoutFlags::TextOriginLeft );
|
2015-05-23 19:44:15 +01:00
|
|
|
CompatStateChanged( StateChangedType::Mirroring );
|
2014-03-23 18:51:13 +11:00
|
|
|
OutputDevice::EnableRTL(bEnable);
|
|
|
|
}
|
|
|
|
|
2002-05-08 15:05:42 +00:00
|
|
|
void Control::Resize()
|
|
|
|
{
|
2009-09-14 12:09:22 +00:00
|
|
|
ImplClearLayoutData();
|
2002-05-08 15:05:42 +00:00
|
|
|
Window::Resize();
|
|
|
|
}
|
|
|
|
|
2002-04-29 16:46:18 +00:00
|
|
|
void Control::FillLayoutData() const
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-09-14 12:09:22 +00:00
|
|
|
void Control::CreateLayoutData() const
|
|
|
|
{
|
2016-06-12 20:11:20 +02:00
|
|
|
SAL_WARN_IF( mpControlData->mpLayoutData, "vcl", "Control::CreateLayoutData: should be called with non-existent layout data only!" );
|
2017-01-11 09:48:18 +02:00
|
|
|
mpControlData->mpLayoutData.reset( new vcl::ControlLayoutData );
|
2009-09-14 12:09:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Control::HasLayoutData() const
|
|
|
|
{
|
2015-11-10 10:28:29 +01:00
|
|
|
return mpControlData && mpControlData->mpLayoutData != nullptr;
|
2009-09-14 12:09:22 +00:00
|
|
|
}
|
|
|
|
|
2013-01-21 14:32:09 +01:00
|
|
|
void Control::SetText( const OUString& rStr )
|
2002-04-29 16:46:18 +00:00
|
|
|
{
|
2009-09-14 12:09:22 +00:00
|
|
|
ImplClearLayoutData();
|
2002-04-29 16:46:18 +00:00
|
|
|
Window::SetText( rStr );
|
|
|
|
}
|
|
|
|
|
2015-11-10 10:28:29 +01:00
|
|
|
ControlLayoutData::ControlLayoutData() : m_pParent( nullptr )
|
2015-03-09 14:29:30 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-03-30 20:27:55 +02:00
|
|
|
tools::Rectangle ControlLayoutData::GetCharacterBounds( long nIndex ) const
|
2002-05-16 10:52:50 +00:00
|
|
|
{
|
2018-01-12 20:10:40 +01:00
|
|
|
return (nIndex >= 0 && nIndex < static_cast<long>(m_aUnicodeBoundRects.size())) ? m_aUnicodeBoundRects[ nIndex ] : tools::Rectangle();
|
2002-05-16 10:52:50 +00:00
|
|
|
}
|
|
|
|
|
2017-03-30 20:27:55 +02:00
|
|
|
tools::Rectangle Control::GetCharacterBounds( long nIndex ) const
|
2002-04-29 16:46:18 +00:00
|
|
|
{
|
2009-09-14 12:09:22 +00:00
|
|
|
if( !HasLayoutData() )
|
2002-04-29 16:46:18 +00:00
|
|
|
FillLayoutData();
|
2017-03-30 20:27:55 +02:00
|
|
|
return mpControlData->mpLayoutData ? mpControlData->mpLayoutData->GetCharacterBounds( nIndex ) : tools::Rectangle();
|
2002-04-29 16:46:18 +00:00
|
|
|
}
|
|
|
|
|
2002-05-16 10:52:50 +00:00
|
|
|
long ControlLayoutData::GetIndexForPoint( const Point& rPoint ) const
|
2002-04-29 16:46:18 +00:00
|
|
|
{
|
|
|
|
long nIndex = -1;
|
2002-05-16 10:52:50 +00:00
|
|
|
for( long i = m_aUnicodeBoundRects.size()-1; i >= 0; i-- )
|
2002-04-29 16:46:18 +00:00
|
|
|
{
|
2012-05-31 11:42:12 +01:00
|
|
|
Point aTopLeft = m_aUnicodeBoundRects[i].TopLeft();
|
|
|
|
Point aBottomRight = m_aUnicodeBoundRects[i].BottomRight();
|
|
|
|
if (rPoint.X() >= aTopLeft.X() && rPoint.Y() >= aTopLeft.Y() &&
|
|
|
|
rPoint.X() <= aBottomRight.X() && rPoint.Y() <= aBottomRight.Y())
|
2002-04-29 16:46:18 +00:00
|
|
|
{
|
2002-05-16 10:52:50 +00:00
|
|
|
nIndex = i;
|
|
|
|
break;
|
2002-04-29 16:46:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nIndex;
|
|
|
|
}
|
|
|
|
|
2002-05-16 10:52:50 +00:00
|
|
|
long Control::GetIndexForPoint( const Point& rPoint ) const
|
2002-04-29 16:46:18 +00:00
|
|
|
{
|
2009-09-14 12:09:22 +00:00
|
|
|
if( ! HasLayoutData() )
|
2002-04-29 16:46:18 +00:00
|
|
|
FillLayoutData();
|
2009-09-14 12:09:22 +00:00
|
|
|
return mpControlData->mpLayoutData ? mpControlData->mpLayoutData->GetIndexForPoint( rPoint ) : -1;
|
2002-05-16 10:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
long ControlLayoutData::GetLineCount() const
|
|
|
|
{
|
|
|
|
long nLines = m_aLineIndices.size();
|
2013-02-06 16:19:18 +01:00
|
|
|
if( nLines == 0 && !m_aDisplayText.isEmpty() )
|
2002-05-16 10:52:50 +00:00
|
|
|
nLines = 1;
|
2002-04-29 16:46:18 +00:00
|
|
|
return nLines;
|
|
|
|
}
|
|
|
|
|
2002-05-16 10:52:50 +00:00
|
|
|
Pair ControlLayoutData::GetLineStartEnd( long nLine ) const
|
|
|
|
{
|
|
|
|
Pair aPair( -1, -1 );
|
|
|
|
|
|
|
|
int nDisplayLines = m_aLineIndices.size();
|
|
|
|
if( nLine >= 0 && nLine < nDisplayLines )
|
2002-04-29 16:46:18 +00:00
|
|
|
{
|
2002-05-16 10:52:50 +00:00
|
|
|
aPair.A() = m_aLineIndices[nLine];
|
2003-06-04 10:21:43 +00:00
|
|
|
if( nLine+1 < nDisplayLines )
|
2002-05-16 10:52:50 +00:00
|
|
|
aPair.B() = m_aLineIndices[nLine+1]-1;
|
|
|
|
else
|
2013-02-06 16:19:18 +01:00
|
|
|
aPair.B() = m_aDisplayText.getLength()-1;
|
2002-05-16 10:52:50 +00:00
|
|
|
}
|
2013-02-06 16:19:18 +01:00
|
|
|
else if( nLine == 0 && nDisplayLines == 0 && !m_aDisplayText.isEmpty() )
|
2002-05-16 10:52:50 +00:00
|
|
|
{
|
|
|
|
// special case for single line controls so the implementations
|
|
|
|
// in that case do not have to fill in the line indices
|
|
|
|
aPair.A() = 0;
|
2013-02-06 16:19:18 +01:00
|
|
|
aPair.B() = m_aDisplayText.getLength()-1;
|
2002-04-29 16:46:18 +00:00
|
|
|
}
|
|
|
|
return aPair;
|
|
|
|
}
|
|
|
|
|
2002-05-16 10:52:50 +00:00
|
|
|
Pair Control::GetLineStartEnd( long nLine ) const
|
|
|
|
{
|
2009-09-14 12:09:22 +00:00
|
|
|
if( !HasLayoutData() )
|
2002-05-16 10:52:50 +00:00
|
|
|
FillLayoutData();
|
2009-09-14 12:09:22 +00:00
|
|
|
return mpControlData->mpLayoutData ? mpControlData->mpLayoutData->GetLineStartEnd( nLine ) : Pair( -1, -1 );
|
2002-05-16 10:52:50 +00:00
|
|
|
}
|
|
|
|
|
2004-05-18 09:54:12 +00:00
|
|
|
long ControlLayoutData::ToRelativeLineIndex( long nIndex ) const
|
|
|
|
{
|
|
|
|
// is the index sensible at all ?
|
2013-02-06 16:19:18 +01:00
|
|
|
if( nIndex >= 0 && nIndex < m_aDisplayText.getLength() )
|
2004-05-18 09:54:12 +00:00
|
|
|
{
|
|
|
|
int nDisplayLines = m_aLineIndices.size();
|
|
|
|
// if only 1 line exists, then absolute and relative index are
|
|
|
|
// identical -> do nothing
|
|
|
|
if( nDisplayLines > 1 )
|
|
|
|
{
|
|
|
|
int nLine;
|
|
|
|
for( nLine = nDisplayLines-1; nLine >= 0; nLine-- )
|
|
|
|
{
|
|
|
|
if( m_aLineIndices[nLine] <= nIndex )
|
|
|
|
{
|
|
|
|
nIndex -= m_aLineIndices[nLine];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( nLine < 0 )
|
|
|
|
{
|
2016-06-12 20:11:20 +02:00
|
|
|
SAL_WARN_IF( nLine < 0, "vcl", "ToRelativeLineIndex failed" );
|
2004-05-18 09:54:12 +00:00
|
|
|
nIndex = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
nIndex = -1;
|
|
|
|
|
|
|
|
return nIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
long Control::ToRelativeLineIndex( long nIndex ) const
|
|
|
|
{
|
2009-09-14 12:09:22 +00:00
|
|
|
if( !HasLayoutData() )
|
2004-05-18 09:54:12 +00:00
|
|
|
FillLayoutData();
|
2009-09-14 12:09:22 +00:00
|
|
|
return mpControlData->mpLayoutData ? mpControlData->mpLayoutData->ToRelativeLineIndex( nIndex ) : -1;
|
2004-05-18 09:54:12 +00:00
|
|
|
}
|
|
|
|
|
2013-01-21 14:32:09 +01:00
|
|
|
OUString Control::GetDisplayText() const
|
2002-04-29 16:46:18 +00:00
|
|
|
{
|
2009-09-14 12:09:22 +00:00
|
|
|
if( !HasLayoutData() )
|
2002-04-29 16:46:18 +00:00
|
|
|
FillLayoutData();
|
2017-05-19 17:16:10 +02:00
|
|
|
return mpControlData->mpLayoutData ? mpControlData->mpLayoutData->m_aDisplayText : GetText();
|
2002-04-29 16:46:18 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 22:40:33 +01:00
|
|
|
bool Control::EventNotify( NotifyEvent& rNEvt )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2015-05-05 12:29:34 +02:00
|
|
|
// tdf#91081 if control is not valid, skip the emission - chaining to the parent
|
|
|
|
if (mpControlData)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2015-05-05 12:29:34 +02:00
|
|
|
if ( rNEvt.GetType() == MouseNotifyEvent::GETFOCUS )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2015-05-05 12:29:34 +02:00
|
|
|
if ( !mbHasControlFocus )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2015-05-05 12:29:34 +02:00
|
|
|
mbHasControlFocus = true;
|
2015-05-23 19:44:15 +01:00
|
|
|
CompatStateChanged( StateChangedType::ControlFocus );
|
2016-12-06 13:26:09 +02:00
|
|
|
if ( ImplCallEventListenersAndHandler( VclEventId::ControlGetFocus, [this] () { maGetFocusHdl.Call(*this); } ) )
|
2004-10-22 11:12:52 +00:00
|
|
|
// been destroyed within the handler
|
2014-01-17 16:40:50 +01:00
|
|
|
return true;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-05 12:29:34 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( rNEvt.GetType() == MouseNotifyEvent::LOSEFOCUS )
|
|
|
|
{
|
|
|
|
vcl::Window* pFocusWin = Application::GetFocusWindow();
|
|
|
|
if ( !pFocusWin || !ImplIsWindowOrChild( pFocusWin ) )
|
|
|
|
{
|
|
|
|
mbHasControlFocus = false;
|
2015-05-23 19:44:15 +01:00
|
|
|
CompatStateChanged( StateChangedType::ControlFocus );
|
2016-12-06 13:26:09 +02:00
|
|
|
if ( ImplCallEventListenersAndHandler( VclEventId::ControlLoseFocus, [this] () { maLoseFocusHdl.Call(*this); } ) )
|
2015-05-05 12:29:34 +02:00
|
|
|
// been destroyed within the handler
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
2016-11-24 22:40:33 +01:00
|
|
|
return Window::EventNotify( rNEvt );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
2002-04-29 16:46:18 +00:00
|
|
|
|
|
|
|
void Control::StateChanged( StateChangedType nStateChange )
|
|
|
|
{
|
2015-05-05 13:46:44 +02:00
|
|
|
if( nStateChange == StateChangedType::InitShow ||
|
|
|
|
nStateChange == StateChangedType::Visible ||
|
|
|
|
nStateChange == StateChangedType::Zoom ||
|
|
|
|
nStateChange == StateChangedType::ControlFont
|
2002-04-29 16:46:18 +00:00
|
|
|
)
|
|
|
|
{
|
2009-09-14 12:09:22 +00:00
|
|
|
ImplClearLayoutData();
|
2002-04-29 16:46:18 +00:00
|
|
|
}
|
|
|
|
Window::StateChanged( nStateChange );
|
|
|
|
}
|
2002-05-03 12:04:12 +00:00
|
|
|
|
|
|
|
void Control::AppendLayoutData( const Control& rSubControl ) const
|
|
|
|
{
|
2009-09-14 12:09:22 +00:00
|
|
|
if( !rSubControl.HasLayoutData() )
|
2002-05-03 12:04:12 +00:00
|
|
|
rSubControl.FillLayoutData();
|
2013-02-06 16:19:18 +01:00
|
|
|
if( !rSubControl.HasLayoutData() || rSubControl.mpControlData->mpLayoutData->m_aDisplayText.isEmpty() )
|
2002-05-03 12:04:12 +00:00
|
|
|
return;
|
|
|
|
|
2013-02-06 16:19:18 +01:00
|
|
|
long nCurrentIndex = mpControlData->mpLayoutData->m_aDisplayText.getLength();
|
|
|
|
mpControlData->mpLayoutData->m_aDisplayText += rSubControl.mpControlData->mpLayoutData->m_aDisplayText;
|
2009-09-14 12:09:22 +00:00
|
|
|
int nLines = rSubControl.mpControlData->mpLayoutData->m_aLineIndices.size();
|
2002-05-03 12:04:12 +00:00
|
|
|
int n;
|
2009-09-14 12:09:22 +00:00
|
|
|
mpControlData->mpLayoutData->m_aLineIndices.push_back( nCurrentIndex );
|
2002-05-03 12:04:12 +00:00
|
|
|
for( n = 1; n < nLines; n++ )
|
2009-09-14 12:09:22 +00:00
|
|
|
mpControlData->mpLayoutData->m_aLineIndices.push_back( rSubControl.mpControlData->mpLayoutData->m_aLineIndices[n] + nCurrentIndex );
|
|
|
|
int nRectangles = rSubControl.mpControlData->mpLayoutData->m_aUnicodeBoundRects.size();
|
2017-03-30 20:27:55 +02:00
|
|
|
tools::Rectangle aRel = const_cast<Control&>(rSubControl).GetWindowExtentsRelative( const_cast<Control*>(this) );
|
2002-05-03 12:04:12 +00:00
|
|
|
for( n = 0; n < nRectangles; n++ )
|
|
|
|
{
|
2017-03-30 20:27:55 +02:00
|
|
|
tools::Rectangle aRect = rSubControl.mpControlData->mpLayoutData->m_aUnicodeBoundRects[n];
|
2003-04-04 15:53:26 +00:00
|
|
|
aRect.Move( aRel.Left(), aRel.Top() );
|
2009-09-14 12:09:22 +00:00
|
|
|
mpControlData->mpLayoutData->m_aUnicodeBoundRects.push_back( aRect );
|
2002-05-03 12:04:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-04 13:55:50 +05:30
|
|
|
void Control::CallEventListeners( VclEventId nEvent, void* pData)
|
2004-10-22 11:12:52 +00:00
|
|
|
{
|
2015-05-08 12:20:18 +01:00
|
|
|
VclPtr<Control> xThis(this);
|
2017-03-20 00:52:12 +01:00
|
|
|
UITestLogger::getInstance().logAction(xThis, nEvent);
|
2004-10-22 11:12:52 +00:00
|
|
|
|
2018-07-04 13:55:50 +05:30
|
|
|
vcl::Window::CallEventListeners(nEvent, pData);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Control::ImplCallEventListenersAndHandler( VclEventId nEvent, std::function<void()> const & callHandler )
|
|
|
|
{
|
|
|
|
VclPtr<Control> xThis(this);
|
|
|
|
|
|
|
|
Control::CallEventListeners( nEvent );
|
2015-05-08 12:20:18 +01:00
|
|
|
|
|
|
|
if ( !xThis->IsDisposed() )
|
2004-10-22 11:12:52 +00:00
|
|
|
{
|
2015-09-10 15:22:28 +02:00
|
|
|
if (callHandler)
|
|
|
|
{
|
|
|
|
callHandler();
|
|
|
|
}
|
2004-10-22 11:12:52 +00:00
|
|
|
|
2015-05-08 12:20:18 +01:00
|
|
|
if ( !xThis->IsDisposed() )
|
2014-02-21 12:53:51 +01:00
|
|
|
return false;
|
2004-10-22 11:12:52 +00:00
|
|
|
}
|
2014-02-21 12:53:51 +01:00
|
|
|
return true;
|
2004-10-22 11:12:52 +00:00
|
|
|
}
|
|
|
|
|
2002-05-03 12:04:12 +00:00
|
|
|
void Control::SetLayoutDataParent( const Control* pParent ) const
|
|
|
|
{
|
2009-09-14 12:09:22 +00:00
|
|
|
if( HasLayoutData() )
|
|
|
|
mpControlData->mpLayoutData->m_pParent = pParent;
|
2002-05-03 12:04:12 +00:00
|
|
|
}
|
|
|
|
|
2004-05-18 09:54:12 +00:00
|
|
|
void Control::ImplClearLayoutData() const
|
2002-05-03 12:04:12 +00:00
|
|
|
{
|
2018-01-20 19:51:34 +02:00
|
|
|
if (mpControlData)
|
|
|
|
mpControlData->mpLayoutData.reset();
|
2002-05-03 12:04:12 +00:00
|
|
|
}
|
|
|
|
|
2017-03-30 20:27:55 +02:00
|
|
|
void Control::ImplDrawFrame( OutputDevice* pDev, tools::Rectangle& rRect )
|
2004-09-08 16:47:19 +00:00
|
|
|
{
|
|
|
|
// use a deco view to draw the frame
|
|
|
|
// However, since there happens a lot of magic there, we need to fake some (style) settings
|
|
|
|
// on the device
|
|
|
|
AllSettings aOriginalSettings( pDev->GetSettings() );
|
|
|
|
|
|
|
|
AllSettings aNewSettings( aOriginalSettings );
|
|
|
|
StyleSettings aStyle( aNewSettings.GetStyleSettings() );
|
|
|
|
|
|
|
|
// The *only known* clients of the Draw methods of the various VCL-controls are form controls:
|
|
|
|
// During print preview, and during printing, Draw is called. Thus, drawing always happens with a
|
|
|
|
// mono (colored) border
|
2015-05-20 14:46:54 +02:00
|
|
|
aStyle.SetOptions( aStyle.GetOptions() | StyleSettingsOptions::Mono );
|
2004-09-08 16:47:19 +00:00
|
|
|
aStyle.SetMonoColor( GetSettings().GetStyleSettings().GetMonoColor() );
|
|
|
|
|
|
|
|
aNewSettings.SetStyleSettings( aStyle );
|
2006-07-19 13:58:56 +00:00
|
|
|
// #i67023# do not call data changed listeners for this fake
|
|
|
|
// since they may understandably invalidate on settings changed
|
|
|
|
pDev->OutputDevice::SetSettings( aNewSettings );
|
2004-09-08 16:47:19 +00:00
|
|
|
|
|
|
|
DecorationView aDecoView( pDev );
|
2015-05-08 15:40:06 +02:00
|
|
|
rRect = aDecoView.DrawFrame( rRect, DrawFrameStyle::Out, DrawFrameFlags::WindowBorder );
|
2004-09-08 16:47:19 +00:00
|
|
|
|
2006-07-19 13:58:56 +00:00
|
|
|
pDev->OutputDevice::SetSettings( aOriginalSettings );
|
2004-09-08 16:47:19 +00:00
|
|
|
}
|
|
|
|
|
2015-07-08 18:02:50 +01:00
|
|
|
void Control::SetShowAccelerator(bool bVal)
|
|
|
|
{
|
|
|
|
mbShowAccelerator = bVal;
|
|
|
|
};
|
|
|
|
|
2002-05-03 12:04:12 +00:00
|
|
|
ControlLayoutData::~ControlLayoutData()
|
|
|
|
{
|
|
|
|
if( m_pParent )
|
2004-05-18 09:54:12 +00:00
|
|
|
m_pParent->ImplClearLayoutData();
|
2002-05-03 12:04:12 +00:00
|
|
|
}
|
2008-01-14 12:04:59 +00:00
|
|
|
|
2013-01-14 10:40:11 +00:00
|
|
|
Size Control::GetOptimalSize() const
|
|
|
|
{
|
|
|
|
return Size( GetTextWidth( GetText() ) + 2 * 12,
|
|
|
|
GetTextHeight() + 2 * 6 );
|
2008-01-14 12:04:59 +00:00
|
|
|
}
|
2009-09-14 12:09:22 +00:00
|
|
|
|
|
|
|
void Control::SetReferenceDevice( OutputDevice* _referenceDevice )
|
|
|
|
{
|
|
|
|
if ( mpControlData->mpReferenceDevice == _referenceDevice )
|
|
|
|
return;
|
|
|
|
|
|
|
|
mpControlData->mpReferenceDevice = _referenceDevice;
|
|
|
|
Invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
OutputDevice* Control::GetReferenceDevice() const
|
|
|
|
{
|
2018-07-12 10:22:33 +02:00
|
|
|
// tdf#118377 It can happen that mpReferenceDevice is already disposed and
|
|
|
|
// stays disposed (see task, even when Dialog is closed). I have no idea if
|
|
|
|
// this may be very bad - someone who knows more about lifetime of OutputDevice's
|
|
|
|
// will have to decide.
|
|
|
|
// To secure this, I changed all accesses to mpControlData->mpReferenceDevice to
|
|
|
|
// use Control::GetReferenceDevice() - only use mpControlData->mpReferenceDevice
|
|
|
|
// inside Control::SetReferenceDevice and Control::GetReferenceDevice().
|
|
|
|
// Control::GetReferenceDevice() will now reset mpReferenceDevice if it is already
|
|
|
|
// disposed. This way all usages will do a kind of 'test-and-get' call.
|
|
|
|
if(nullptr != mpControlData->mpReferenceDevice && mpControlData->mpReferenceDevice->isDisposed())
|
|
|
|
{
|
|
|
|
const_cast<Control*>(this)->SetReferenceDevice(nullptr);
|
|
|
|
}
|
|
|
|
|
2009-09-14 12:09:22 +00:00
|
|
|
return mpControlData->mpReferenceDevice;
|
|
|
|
}
|
|
|
|
|
2014-09-16 10:09:58 +02:00
|
|
|
const vcl::Font& Control::GetCanonicalFont( const StyleSettings& _rStyle ) const
|
2009-09-14 12:09:22 +00:00
|
|
|
{
|
|
|
|
return _rStyle.GetLabelFont();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Color& Control::GetCanonicalTextColor( const StyleSettings& _rStyle ) const
|
|
|
|
{
|
|
|
|
return _rStyle.GetLabelTextColor();
|
|
|
|
}
|
|
|
|
|
2015-05-17 22:56:46 +09:00
|
|
|
void Control::ApplySettings(vcl::RenderContext& rRenderContext)
|
|
|
|
{
|
|
|
|
const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
|
|
|
|
|
2018-02-12 11:14:09 +01:00
|
|
|
ApplyControlFont(rRenderContext, GetCanonicalFont(rStyleSettings));
|
2015-05-17 22:56:46 +09:00
|
|
|
|
2015-07-22 11:27:24 +02:00
|
|
|
ApplyControlForeground(rRenderContext, GetCanonicalTextColor(rStyleSettings));
|
|
|
|
rRenderContext.SetTextFillColor();
|
2015-05-17 22:56:46 +09:00
|
|
|
}
|
|
|
|
|
2017-04-24 12:54:28 +02:00
|
|
|
void Control::ImplInitSettings()
|
2009-09-14 12:09:22 +00:00
|
|
|
{
|
2015-05-22 17:51:44 +09:00
|
|
|
ApplySettings(*this);
|
2009-09-14 12:09:22 +00:00
|
|
|
}
|
|
|
|
|
2017-03-30 20:27:55 +02:00
|
|
|
tools::Rectangle Control::DrawControlText( OutputDevice& _rTargetDevice, const tools::Rectangle& rRect, const OUString& _rStr,
|
2017-01-18 17:17:09 +00:00
|
|
|
DrawTextFlags _nStyle, MetricVector* _pVector, OUString* _pDisplayText, const Size* i_pDeviceSize ) const
|
2009-09-14 12:09:22 +00:00
|
|
|
{
|
2015-07-08 18:02:50 +01:00
|
|
|
OUString rPStr = _rStr;
|
|
|
|
DrawTextFlags nPStyle = _nStyle;
|
|
|
|
|
|
|
|
bool accel = ImplGetSVData()->maNWFData.mbEnableAccel;
|
|
|
|
bool autoacc = ImplGetSVData()->maNWFData.mbAutoAccel;
|
|
|
|
|
|
|
|
if (!accel || (autoacc && !mbShowAccelerator))
|
|
|
|
{
|
|
|
|
rPStr = GetNonMnemonicString( _rStr );
|
|
|
|
nPStyle &= ~DrawTextFlags::HideMnemonic;
|
|
|
|
}
|
|
|
|
|
2018-07-12 10:22:33 +02:00
|
|
|
if( !GetReferenceDevice() || ( GetReferenceDevice() == &_rTargetDevice ) )
|
2009-09-14 12:09:22 +00:00
|
|
|
{
|
2017-03-30 20:27:55 +02:00
|
|
|
const tools::Rectangle aRet = _rTargetDevice.GetTextRect(rRect, rPStr, nPStyle);
|
2017-01-18 16:36:19 +00:00
|
|
|
_rTargetDevice.DrawText(aRet, rPStr, nPStyle, _pVector, _pDisplayText);
|
|
|
|
return aRet;
|
2009-09-14 12:09:22 +00:00
|
|
|
}
|
2017-01-18 16:36:19 +00:00
|
|
|
|
2018-07-12 10:22:33 +02:00
|
|
|
ControlTextRenderer aRenderer( *this, _rTargetDevice, *GetReferenceDevice() );
|
2017-01-18 17:17:09 +00:00
|
|
|
return aRenderer.DrawText(rRect, rPStr, nPStyle, _pVector, _pDisplayText, i_pDeviceSize);
|
|
|
|
}
|
|
|
|
|
2017-03-30 20:27:55 +02:00
|
|
|
tools::Rectangle Control::GetControlTextRect( OutputDevice& _rTargetDevice, const tools::Rectangle & rRect,
|
2017-01-18 17:17:09 +00:00
|
|
|
const OUString& _rStr, DrawTextFlags _nStyle, Size* o_pDeviceSize ) const
|
|
|
|
{
|
|
|
|
OUString rPStr = _rStr;
|
|
|
|
DrawTextFlags nPStyle = _nStyle;
|
|
|
|
|
|
|
|
bool accel = ImplGetSVData()->maNWFData.mbEnableAccel;
|
|
|
|
bool autoacc = ImplGetSVData()->maNWFData.mbAutoAccel;
|
|
|
|
|
|
|
|
if (!accel || (autoacc && !mbShowAccelerator))
|
|
|
|
{
|
|
|
|
rPStr = GetNonMnemonicString( _rStr );
|
|
|
|
nPStyle &= ~DrawTextFlags::HideMnemonic;
|
|
|
|
}
|
|
|
|
|
2018-07-12 10:22:33 +02:00
|
|
|
if ( !GetReferenceDevice() || ( GetReferenceDevice() == &_rTargetDevice ) )
|
2017-01-18 17:17:09 +00:00
|
|
|
{
|
2017-03-30 20:27:55 +02:00
|
|
|
tools::Rectangle aRet = _rTargetDevice.GetTextRect( rRect, rPStr, nPStyle );
|
2017-01-18 17:17:09 +00:00
|
|
|
if (o_pDeviceSize)
|
|
|
|
{
|
|
|
|
*o_pDeviceSize = aRet.GetSize();
|
|
|
|
}
|
|
|
|
return aRet;
|
|
|
|
}
|
|
|
|
|
2018-07-12 10:22:33 +02:00
|
|
|
ControlTextRenderer aRenderer( *this, _rTargetDevice, *GetReferenceDevice() );
|
2017-01-18 17:17:09 +00:00
|
|
|
return aRenderer.GetTextRect(rRect, rPStr, nPStyle, o_pDeviceSize);
|
2009-09-14 12:09:22 +00:00
|
|
|
}
|
2010-10-14 08:27:31 +02:00
|
|
|
|
2014-01-02 23:52:37 +01:00
|
|
|
Font
|
|
|
|
Control::GetUnzoomedControlPointFont() const
|
|
|
|
{
|
2015-05-17 22:56:46 +09:00
|
|
|
Font aFont(GetCanonicalFont(GetSettings().GetStyleSettings()));
|
|
|
|
if (IsControlFont())
|
|
|
|
aFont.Merge(GetControlFont());
|
2014-01-02 23:52:37 +01:00
|
|
|
return aFont;
|
|
|
|
}
|
|
|
|
|
2010-10-14 08:27:31 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|