1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef VCL_TEXTLAYOUT_HXX 25 #define VCL_TEXTLAYOUT_HXX 26 27 #include "vcl/outdev.hxx" 28 29 #include <tools/solar.h> 30 #include <tools/string.hxx> 31 32 #include <memory> 33 34 class Control; 35 36 //........................................................................ 37 namespace vcl 38 { 39 //........................................................................ 40 41 //==================================================================== 42 //= ITextLayout 43 //==================================================================== 44 class SAL_NO_VTABLE ITextLayout 45 { 46 public: 47 virtual long GetTextWidth( const XubString& _rText, xub_StrLen _nStartIndex, xub_StrLen _nLength ) const = 0; 48 virtual void DrawText( const Point& _rStartPoint, const XubString& _rText, xub_StrLen _nStartIndex, xub_StrLen _nLength, 49 MetricVector* _pVector, String* _pDisplayText ) = 0; 50 virtual bool GetCaretPositions( const XubString& _rText, sal_Int32* _pCaretXArray, xub_StrLen _nStartIndex, xub_StrLen _nLength ) const = 0; 51 virtual xub_StrLen GetTextBreak( const XubString& _rText, long _nMaxTextWidth, xub_StrLen _nStartIndex, xub_StrLen _nLength ) const = 0; 52 virtual bool DecomposeTextRectAction() const = 0; 53 }; 54 55 //==================================================================== 56 //= DefaultTextLayout 57 //==================================================================== 58 /** is an implementation of the ITextLayout interface which simply delegates its calls to the respective 59 methods of an OutputDevice instance, without any inbetween magic. 60 */ 61 class DefaultTextLayout : public ITextLayout 62 { 63 public: 64 DefaultTextLayout( OutputDevice& _rTargetDevice ) 65 :m_rTargetDevice( _rTargetDevice ) 66 { 67 } 68 virtual ~DefaultTextLayout(); 69 70 // ITextLayout overridables 71 virtual long GetTextWidth( 72 const XubString& _rText, 73 xub_StrLen _nStartIndex, 74 xub_StrLen _nLength 75 ) const; 76 virtual void DrawText( 77 const Point& _rStartPoint, 78 const XubString& _rText, 79 xub_StrLen _nStartIndex, 80 xub_StrLen _nLength, 81 MetricVector* _pVector, 82 String* _pDisplayText 83 ); 84 virtual bool GetCaretPositions( 85 const XubString& _rText, 86 sal_Int32* _pCaretXArray, 87 xub_StrLen _nStartIndex, 88 xub_StrLen _nLength 89 ) const; 90 virtual xub_StrLen GetTextBreak( 91 const XubString& _rText, 92 long _nMaxTextWidth, 93 xub_StrLen _nStartIndex, 94 xub_StrLen _nLength 95 ) const; 96 virtual bool DecomposeTextRectAction() const; 97 98 private: 99 OutputDevice& m_rTargetDevice; 100 }; 101 102 //==================================================================== 103 //= ControlTextRenderer 104 //==================================================================== 105 class ReferenceDeviceTextLayout; 106 /** a class which allows rendering text of a Control onto a device, by taking into account the metrics of 107 a reference device. 108 */ 109 class ControlTextRenderer 110 { 111 public: 112 ControlTextRenderer( const Control& _rControl, OutputDevice& _rTargetDevice, OutputDevice& _rReferenceDevice ); 113 virtual ~ControlTextRenderer(); 114 115 Rectangle DrawText( const Rectangle& _rRect, 116 const XubString& _rText, sal_uInt16 _nStyle = 0, 117 MetricVector* _pVector = NULL, String* _pDisplayText = NULL ); 118 119 private: 120 ControlTextRenderer(); // never implemented 121 ControlTextRenderer( const ControlTextRenderer& ); // never implemented 122 ControlTextRenderer& operator=( const ControlTextRenderer& ); // never implemented 123 124 private: 125 ::std::auto_ptr< ReferenceDeviceTextLayout > m_pImpl; 126 }; 127 128 //........................................................................ 129 } // namespace vcl 130 //........................................................................ 131 132 #endif // VCL_TEXTLAYOUT_HXX 133