Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <editeng/unoedhlp.hxx>
21 : #include <editeng/editdata.hxx>
22 : #include <editeng/editeng.hxx>
23 :
24 : //------------------------------------------------------------------------
25 :
26 0 : TYPEINIT1( SvxEditSourceHint, TextHint );
27 :
28 0 : SvxEditSourceHint::SvxEditSourceHint( sal_uLong _nId ) :
29 : TextHint( _nId ),
30 : mnStart( 0 ),
31 0 : mnEnd( 0 )
32 : {
33 0 : }
34 :
35 0 : SvxEditSourceHint::SvxEditSourceHint( sal_uLong _nId, sal_uLong nValue, sal_uLong nStart, sal_uLong nEnd ) :
36 : TextHint( _nId, nValue ),
37 : mnStart( nStart),
38 0 : mnEnd( nEnd )
39 : {
40 0 : }
41 :
42 0 : sal_uLong SvxEditSourceHint::GetValue() const
43 : {
44 0 : return TextHint::GetValue();
45 : }
46 :
47 0 : sal_uLong SvxEditSourceHint::GetStartValue() const
48 : {
49 0 : return mnStart;
50 : }
51 :
52 0 : sal_uLong SvxEditSourceHint::GetEndValue() const
53 : {
54 0 : return mnEnd;
55 : }
56 :
57 : //------------------------------------------------------------------------
58 :
59 0 : ::std::auto_ptr<SfxHint> SvxEditSourceHelper::EENotification2Hint( EENotify* aNotify )
60 : {
61 0 : if( aNotify )
62 : {
63 0 : switch( aNotify->eNotificationType )
64 : {
65 : case EE_NOTIFY_TEXTMODIFIED:
66 0 : return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_MODIFIED, aNotify->nParagraph ) );
67 :
68 : case EE_NOTIFY_PARAGRAPHINSERTED:
69 0 : return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_PARAINSERTED, aNotify->nParagraph ) );
70 :
71 : case EE_NOTIFY_PARAGRAPHREMOVED:
72 0 : return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_PARAREMOVED, aNotify->nParagraph ) );
73 :
74 : case EE_NOTIFY_PARAGRAPHSMOVED:
75 0 : return ::std::auto_ptr<SfxHint>( new SvxEditSourceHint( EDITSOURCE_HINT_PARASMOVED, aNotify->nParagraph, aNotify->nParam1, aNotify->nParam2 ) );
76 :
77 : case EE_NOTIFY_TEXTHEIGHTCHANGED:
78 0 : return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_TEXTHEIGHTCHANGED, aNotify->nParagraph ) );
79 :
80 : case EE_NOTIFY_TEXTVIEWSCROLLED:
81 0 : return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_VIEWSCROLLED ) );
82 :
83 : case EE_NOTIFY_TEXTVIEWSELECTIONCHANGED:
84 0 : return ::std::auto_ptr<SfxHint>( new SvxEditSourceHint( EDITSOURCE_HINT_SELECTIONCHANGED ) );
85 :
86 : case EE_NOTIFY_BLOCKNOTIFICATION_START:
87 0 : return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_BLOCKNOTIFICATION_START, 0 ) );
88 :
89 : case EE_NOTIFY_BLOCKNOTIFICATION_END:
90 0 : return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_BLOCKNOTIFICATION_END, 0 ) );
91 :
92 : case EE_NOTIFY_INPUT_START:
93 0 : return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_INPUT_START, 0 ) );
94 :
95 : case EE_NOTIFY_INPUT_END:
96 0 : return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_INPUT_END, 0 ) );
97 :
98 : default:
99 : OSL_FAIL( "SvxEditSourceHelper::EENotification2Hint unknown notification" );
100 0 : break;
101 : }
102 : }
103 :
104 0 : return ::std::auto_ptr<SfxHint>( new SfxHint() );
105 : }
106 :
107 0 : sal_Bool SvxEditSourceHelper::GetAttributeRun( sal_uInt16& nStartIndex, sal_uInt16& nEndIndex, const EditEngine& rEE, sal_uInt16 nPara, sal_uInt16 nIndex )
108 : {
109 0 : std::vector<EECharAttrib> aCharAttribs;
110 :
111 0 : rEE.GetCharAttribs( nPara, aCharAttribs );
112 :
113 : // find closest index in front of nIndex
114 : sal_uInt16 nCurrIndex;
115 0 : sal_Int32 nClosestStartIndex = 0;
116 0 : for(std::vector<EECharAttrib>::iterator i = aCharAttribs.begin(); i < aCharAttribs.end(); ++i)
117 : {
118 0 : nCurrIndex = i->nStart;
119 :
120 0 : if( nCurrIndex > nIndex )
121 0 : break; // aCharAttribs array is sorted in increasing order for nStart values
122 0 : else if( nCurrIndex > nClosestStartIndex )
123 : {
124 0 : nClosestStartIndex = nCurrIndex;
125 : }
126 : }
127 :
128 : // find closest index behind of nIndex
129 0 : sal_Int32 nClosestEndIndex = rEE.GetTextLen(nPara);
130 0 : for(std::vector<EECharAttrib>::iterator i = aCharAttribs.begin(); i < aCharAttribs.end(); ++i)
131 : {
132 0 : nCurrIndex = i->nEnd;
133 :
134 0 : if( nCurrIndex > nIndex && nCurrIndex < nClosestEndIndex )
135 0 : nClosestEndIndex = nCurrIndex;
136 : }
137 :
138 0 : nStartIndex = static_cast<sal_uInt16>( nClosestStartIndex );
139 0 : nEndIndex = static_cast<sal_uInt16>( nClosestEndIndex );
140 :
141 0 : return sal_True;
142 : }
143 :
144 0 : Point SvxEditSourceHelper::EEToUserSpace( const Point& rPoint, const Size& rEESize, bool bIsVertical )
145 : {
146 0 : return bIsVertical ? Point( -rPoint.Y() + rEESize.Height(), rPoint.X() ) : rPoint;
147 : }
148 :
149 0 : Point SvxEditSourceHelper::UserSpaceToEE( const Point& rPoint, const Size& rEESize, bool bIsVertical )
150 : {
151 0 : return bIsVertical ? Point( rPoint.Y(), -rPoint.X() + rEESize.Height() ) : rPoint;
152 : }
153 :
154 0 : Rectangle SvxEditSourceHelper::EEToUserSpace( const Rectangle& rRect, const Size& rEESize, bool bIsVertical )
155 : {
156 0 : return bIsVertical ? Rectangle( EEToUserSpace(rRect.BottomLeft(), rEESize, bIsVertical),
157 0 : EEToUserSpace(rRect.TopRight(), rEESize, bIsVertical) ) : rRect;
158 : }
159 :
160 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|