Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / inc / textlayout.hxx
blob6b86aafc422ada4c8cd0b6906961a1e668a76b6c
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 #ifndef INCLUDED_VCL_INC_TEXTLAYOUT_HXX
21 #define INCLUDED_VCL_INC_TEXTLAYOUT_HXX
23 #include <memory>
24 #include <rtl/ustring.hxx>
25 #include <vcl/outdev.hxx>
27 class Control;
29 namespace vcl
31 class SAL_NO_VTABLE ITextLayout
33 public:
34 virtual long GetTextWidth( const OUString& _rText, sal_Int32 _nStartIndex, sal_Int32 _nLength ) const = 0;
35 virtual void DrawText( const Point& _rStartPoint, const OUString& _rText, sal_Int32 _nStartIndex, sal_Int32 _nLength,
36 MetricVector* _pVector, OUString* _pDisplayText ) = 0;
37 virtual bool GetCaretPositions( const OUString& _rText, long* _pCaretXArray, sal_Int32 _nStartIndex, sal_Int32 _nLength ) const = 0;
38 virtual sal_Int32 GetTextBreak( const OUString& _rText, long _nMaxTextWidth, sal_Int32 _nStartIndex, sal_Int32 _nLength ) const = 0;
39 virtual bool DecomposeTextRectAction() const = 0;
41 protected:
42 ~ITextLayout() {}
45 /** is an implementation of the ITextLayout interface which simply delegates its calls to the respective
46 methods of an OutputDevice instance, without any inbetween magic.
48 class DefaultTextLayout : public ITextLayout
50 public:
51 DefaultTextLayout( OutputDevice& _rTargetDevice )
52 : m_rTargetDevice( _rTargetDevice )
55 virtual ~DefaultTextLayout();
57 // ITextLayout overridables
58 virtual long GetTextWidth( const OUString& _rText,
59 sal_Int32 _nStartIndex,
60 sal_Int32 _nLength ) const SAL_OVERRIDE;
62 virtual void DrawText( const Point& _rStartPoint,
63 const OUString& _rText,
64 sal_Int32 _nStartIndex,
65 sal_Int32 _nLength,
66 MetricVector* _pVector,
67 OUString* _pDisplayText ) SAL_OVERRIDE;
69 virtual bool GetCaretPositions( const OUString& _rText,
70 long* _pCaretXArray,
71 sal_Int32 _nStartIndex,
72 sal_Int32 _nLength ) const SAL_OVERRIDE;
74 virtual sal_Int32 GetTextBreak( const OUString& _rText,
75 long _nMaxTextWidth,
76 sal_Int32 _nStartIndex,
77 sal_Int32 _nLength ) const SAL_OVERRIDE;
79 virtual bool DecomposeTextRectAction() const SAL_OVERRIDE;
81 private:
82 OutputDevice& m_rTargetDevice;
85 class ReferenceDeviceTextLayout;
86 /** a class which allows rendering text of a Control onto a device, by taking into account the metrics of
87 a reference device.
89 class ControlTextRenderer
91 public:
92 ControlTextRenderer( const Control& _rControl, OutputDevice& _rTargetDevice, OutputDevice& _rReferenceDevice );
93 virtual ~ControlTextRenderer();
95 Rectangle DrawText( const Rectangle& _rRect,
96 const OUString& _rText, DrawTextFlags _nStyle = DrawTextFlags::NONE,
97 MetricVector* _pVector = NULL, OUString* _pDisplayText = NULL );
99 private:
100 ControlTextRenderer( const ControlTextRenderer& ) SAL_DELETED_FUNCTION;
101 ControlTextRenderer& operator=( const ControlTextRenderer& ) SAL_DELETED_FUNCTION;
103 private:
104 ::std::unique_ptr< ReferenceDeviceTextLayout > m_pImpl;
107 } // namespace vcl
109 #endif // INCLUDED_VCL_INC_TEXTLAYOUT_HXX
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */