tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / vcl / inc / textlayout.hxx
blob4b1d8fd5d3d6b97a82e52d5bead42d27fbd1e7c6
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 #pragma once
22 #include <tools/long.hxx>
23 #include <vcl/outdev.hxx>
25 #include <memory>
26 #include <vector>
28 #include <com/sun/star/i18n/WordType.hpp>
29 #include <com/sun/star/i18n/XBreakIterator.hpp>
30 #include <com/sun/star/linguistic2/LinguServiceManager.hpp>
32 class Control;
34 namespace vcl
36 class VCL_DLLPUBLIC TextLayoutCommon
38 public:
39 virtual tools::Long GetTextWidth( const OUString& _rText, sal_Int32 _nStartIndex, sal_Int32 _nLength ) const = 0;
40 virtual void DrawText( const Point& _rStartPoint, const OUString& _rText, sal_Int32 _nStartIndex, sal_Int32 _nLength,
41 std::vector< tools::Rectangle >* _pVector, OUString* _pDisplayText ) = 0;
42 virtual tools::Long GetTextArray( const OUString& _rText, KernArray* _pDXArray, sal_Int32 _nStartIndex, sal_Int32 _nLength, bool bCaret = false ) const = 0;
43 virtual sal_Int32 GetTextBreak( const OUString& _rText, tools::Long _nMaxTextWidth, sal_Int32 _nStartIndex, sal_Int32 _nLength ) const = 0;
44 virtual bool DecomposeTextRectAction() const = 0;
46 SAL_DLLPRIVATE OUString GetEllipsisString(OUString const& rOrigStr, tools::Long nMaxWidth, DrawTextFlags nStyle);
48 std::tuple<sal_Int32, sal_Int32> BreakLine(const tools::Long nWidth, OUString const& rStr,
49 css::uno::Reference< css::linguistic2::XHyphenator > const& xHyph,
50 css::uno::Reference<css::i18n::XBreakIterator>& xBI,
51 const bool bHyphenate, const tools::Long nOrigLineWidth,
52 const sal_Int32 nPos, const sal_Int32 nLen);
54 SAL_DLLPRIVATE std::tuple<sal_Int32, sal_Int32> BreakLineSimple(const tools::Long nWidth, OUString const& rStr,
55 const sal_Int32 nPos, sal_Int32 nBreakPos, const tools::Long nOrigLineWidth);
57 SAL_DLLPRIVATE tools::Long GetTextLines(tools::Rectangle const& rRect, const tools::Long nTextHeight,
58 ImplMultiTextLineInfo& rLineInfo,
59 tools::Long nWidth, OUString const& rStr,
60 DrawTextFlags nStyle);
62 protected:
63 SAL_DLLPRIVATE ~TextLayoutCommon() COVERITY_NOEXCEPT_FALSE;
65 private:
66 SAL_DLLPRIVATE OUString GetCenterEllipsisString(std::u16string_view rOrigStr, sal_Int32 nIndex, tools::Long nMaxWidth);
67 SAL_DLLPRIVATE OUString GetEndEllipsisString(OUString const& rOrigStr, sal_Int32 nIndex, tools::Long nMaxWidth, bool bClipText);
68 SAL_DLLPRIVATE OUString GetNewsEllipsisString(OUString const& rOrigStr, tools::Long nMaxWidth, DrawTextFlags nStyle);
71 /** is an implementation of TextLayoutCommon which simply delegates its calls to the respective
72 methods of an OutputDevice instance, without any inbetween magic.
74 class VCL_DLLPUBLIC DefaultTextLayout final : public TextLayoutCommon
76 public:
77 DefaultTextLayout( OutputDevice& _rTargetDevice )
78 : m_rTargetDevice( _rTargetDevice )
81 virtual ~DefaultTextLayout();
83 // TextLayoutCommon overridables
84 SAL_DLLPRIVATE virtual tools::Long GetTextWidth( const OUString& _rText,
85 sal_Int32 _nStartIndex,
86 sal_Int32 _nLength ) const override;
88 virtual void DrawText( const Point& _rStartPoint,
89 const OUString& _rText,
90 sal_Int32 _nStartIndex,
91 sal_Int32 _nLength,
92 std::vector< tools::Rectangle >* _pVector,
93 OUString* _pDisplayText ) override;
95 SAL_DLLPRIVATE virtual tools::Long GetTextArray( const OUString& _rText,
96 KernArray* _pDXArray,
97 sal_Int32 _nStartIndex,
98 sal_Int32 _nLength,
99 bool bCaret = false ) const override;
101 SAL_DLLPRIVATE virtual sal_Int32 GetTextBreak( const OUString& _rText,
102 tools::Long _nMaxTextWidth,
103 sal_Int32 _nStartIndex,
104 sal_Int32 _nLength ) const override;
106 SAL_DLLPRIVATE virtual bool DecomposeTextRectAction() const override;
108 private:
109 OutputDevice& m_rTargetDevice;
112 class ReferenceDeviceTextLayout;
113 /** a class which allows rendering text of a Control onto a device, by taking into account the metrics of
114 a reference device.
116 class ControlTextRenderer final
118 public:
119 ControlTextRenderer( const Control& _rControl, OutputDevice& _rTargetDevice, OutputDevice& _rReferenceDevice );
120 ~ControlTextRenderer();
122 tools::Rectangle DrawText( const tools::Rectangle& _rRect,
123 const OUString& _rText, DrawTextFlags _nStyle,
124 std::vector< tools::Rectangle >* _pVector, OUString* _pDisplayText, const Size* i_pDeviceSize );
126 tools::Rectangle GetTextRect( const tools::Rectangle& _rRect,
127 const OUString& _rText, DrawTextFlags _nStyle, Size* o_pDeviceSize );
129 private:
130 ControlTextRenderer( const ControlTextRenderer& ) = delete;
131 ControlTextRenderer& operator=( const ControlTextRenderer& ) = delete;
133 private:
134 ::std::unique_ptr< ReferenceDeviceTextLayout > m_pImpl;
137 } // namespace vcl
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */