xref: /aoo42x/main/vcl/inc/textlayout.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ***********************************************************************/
27 
28 #ifndef VCL_TEXTLAYOUT_HXX
29 #define VCL_TEXTLAYOUT_HXX
30 
31 #include "vcl/outdev.hxx"
32 
33 #include <tools/solar.h>
34 #include <tools/string.hxx>
35 
36 #include <memory>
37 
38 class Control;
39 
40 //........................................................................
41 namespace vcl
42 {
43 //........................................................................
44 
45 	//====================================================================
46 	//= ITextLayout
47 	//====================================================================
48 	class SAL_NO_VTABLE ITextLayout
49 	{
50     public:
51         virtual long        GetTextWidth( const XubString& _rText, xub_StrLen _nStartIndex, xub_StrLen _nLength ) const = 0;
52         virtual void        DrawText( const Point& _rStartPoint, const XubString& _rText, xub_StrLen _nStartIndex, xub_StrLen _nLength,
53                                 MetricVector* _pVector, String* _pDisplayText ) = 0;
54         virtual bool        GetCaretPositions( const XubString& _rText, sal_Int32* _pCaretXArray, xub_StrLen _nStartIndex, xub_StrLen _nLength ) const = 0;
55         virtual xub_StrLen  GetTextBreak( const XubString& _rText, long _nMaxTextWidth, xub_StrLen _nStartIndex, xub_StrLen _nLength ) const = 0;
56         virtual bool        DecomposeTextRectAction() const = 0;
57 	};
58 
59 	//====================================================================
60 	//= DefaultTextLayout
61 	//====================================================================
62     /** is an implementation of the ITextLayout interface which simply delegates its calls to the respective
63         methods of an OutputDevice instance, without any inbetween magic.
64     */
65     class DefaultTextLayout : public ITextLayout
66     {
67     public:
68         DefaultTextLayout( OutputDevice& _rTargetDevice )
69             :m_rTargetDevice( _rTargetDevice )
70         {
71         }
72         virtual ~DefaultTextLayout();
73 
74         // ITextLayout overridables
75         virtual long        GetTextWidth(
76                                 const XubString& _rText,
77                                 xub_StrLen _nStartIndex,
78                                 xub_StrLen _nLength
79                             ) const;
80         virtual void        DrawText(
81                                 const Point& _rStartPoint,
82                                 const XubString& _rText,
83                                 xub_StrLen _nStartIndex,
84                                 xub_StrLen _nLength,
85                                 MetricVector* _pVector,
86                                 String* _pDisplayText
87                             );
88         virtual bool        GetCaretPositions(
89                                 const XubString& _rText,
90                                 sal_Int32* _pCaretXArray,
91                                 xub_StrLen _nStartIndex,
92                                 xub_StrLen _nLength
93                             ) const;
94         virtual xub_StrLen  GetTextBreak(
95                                 const XubString& _rText,
96                                 long _nMaxTextWidth,
97                                 xub_StrLen _nStartIndex,
98                                 xub_StrLen _nLength
99                             ) const;
100         virtual bool        DecomposeTextRectAction() const;
101 
102     private:
103         OutputDevice&   m_rTargetDevice;
104     };
105 
106 	//====================================================================
107 	//= ControlTextRenderer
108 	//====================================================================
109     class ReferenceDeviceTextLayout;
110     /** a class which allows rendering text of a Control onto a device, by taking into account the metrics of
111         a reference device.
112     */
113     class ControlTextRenderer
114     {
115     public:
116         ControlTextRenderer( const Control& _rControl, OutputDevice& _rTargetDevice, OutputDevice& _rReferenceDevice );
117         virtual ~ControlTextRenderer();
118 
119         Rectangle   DrawText( const Rectangle& _rRect,
120                               const XubString& _rText, sal_uInt16 _nStyle = 0,
121                               MetricVector* _pVector = NULL, String* _pDisplayText = NULL );
122 
123     private:
124         ControlTextRenderer();                                                  // never implemented
125         ControlTextRenderer( const ControlTextRenderer& );              // never implemented
126         ControlTextRenderer& operator=( const ControlTextRenderer& );   // never implemented
127 
128     private:
129         ::std::auto_ptr< ReferenceDeviceTextLayout >   m_pImpl;
130     };
131 
132 //........................................................................
133 } // namespace vcl
134 //........................................................................
135 
136 #endif // VCL_TEXTLAYOUT_HXX
137