Tizen 2.1 base
[framework/osp/uifw.git] / src / graphics / text / FGrp_TextTextLine.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /*
19  * @file        FGrp_TextTextLine.cpp
20  * @brief       This is the implementation file for TextLine class.
21  */
22
23 #include <new>
24 #include <FBaseSysLog.h>
25 #include "FGrp_CanvasImpl.h"
26 #include "FGrp_TextCommon.h"
27 #include "FGrp_TextTextComposite.h"
28 #include "FGrp_TextTextLine.h"
29
30 namespace Tizen { namespace Graphics
31 {
32
33 namespace _Text
34 {
35
36 TextLine::TextLine(TextComposite* pCompositeText)
37 {
38         __index = -1;
39         __textOffset = -1;
40         __textLength = -1;
41         __width = -1;
42         __height = -1;
43         __endType = -1;
44         __rect.x = 0;
45         __rect.y = 0;
46         __rect.height = 0;
47         __rect.width = 0;
48         __baseline = 0;
49         __pCompositeText = pCompositeText;
50
51         // For Sweep Info
52         __sweepComposeLineInfo.isValid = false;
53         __sweepComposeLineInfo.prevLineTextOffset = 0;
54         __sweepComposeLineInfo.prevLineTextLength = 0;
55         __sweepComposeLineInfo.prevLineWidth = 0;
56         __sweepComposeLineInfo.currentLineTextOffset = 0;
57         __sweepComposeLineInfo.currentLineTextLength = 0;
58         __sweepComposeLineInfo.currentLineWidth = 0;
59
60         __sweepIn = 0;
61         __sweepOut = 0;
62         __sweepType = 0;
63         __isKeyInputChanged = false;
64         __keyInputTextIndex = 0;
65         __keyInputTextLength = 0;
66 }
67
68 TextLine::~TextLine(void)
69 {
70
71 }
72
73 result
74 TextLine::GetRegion(int textIndex, int textLength, int& width, int& height) const
75 {
76         if (textIndex != 0 || textLength != __textLength)
77         {
78                 return __pCompositeText->GetRegion(textIndex + __textOffset, textIndex + textLength + __textOffset, width, height);
79
80         }
81
82         width = __width;
83         height = __height;
84
85         return E_SUCCESS;
86 }
87
88 int
89 TextLine::GetHeight(int textIndex) const
90 {
91         if (textIndex == -1)
92         {
93                 return __height;
94         }
95         else if (textIndex >= 0 && textIndex < __textLength)
96         {
97                 return __pCompositeText->GetHeight(textIndex + __textOffset);
98         }
99         else
100         {
101                 return -1;
102         }
103 }
104
105 result
106 TextLine::Draw(_CanvasImpl& canvasImpl, Rectangle& displayRect, int startTextIndex, int textLength, const TextObjectAlignment align,
107                                 const TextObjectActionType action)
108 {
109         SysTryReturn(NID_GRP
110                 , startTextIndex == 0  && textLength == __textLength && __pCompositeText != null
111                 , E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
112
113         return __pCompositeText->DrawLine(canvasImpl, this, displayRect, align, action);
114 }
115
116 result
117 TextLine::DrawPartial(_CanvasImpl& canvasImpl, int startTextIndex, int textLength, Rectangle& displayRect)
118 {
119         SysTryReturn(NID_GRP
120                 , __pCompositeText != null
121                 , E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
122
123         int textIndexAtLine = GetTextOffset() + startTextIndex;
124
125         return __pCompositeText->DrawPartial(canvasImpl, displayRect, textIndexAtLine, textLength);
126 }
127
128 TextLine*
129 TextLine::CopyN(void)
130 {
131         TextLine* pTextLine = null;
132
133         pTextLine = new (std::nothrow) TextLine(__pCompositeText);
134
135         SysTryReturn(NID_GRP
136                 , pTextLine
137                 , false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
138
139         pTextLine->__index = __index;
140         pTextLine->__textOffset = __textOffset;
141         pTextLine->__textLength = __textLength;
142         pTextLine->__width = __width;
143         pTextLine->__height = __height;
144         pTextLine->__endType = __endType;
145         pTextLine->__rect.x = __rect.x;
146         pTextLine->__rect.y = __rect.y;
147         pTextLine->__rect.height = __rect.height;
148         pTextLine->__rect.width = __rect.width;
149
150         return pTextLine;
151 }
152
153 Rectangle
154 TextLine::GetBounds(void) const
155 {
156         return __rect;
157 }
158
159
160 int
161 TextLine::GetTextLength(void) const
162 {
163         return __textLength;
164 }
165
166 void
167 TextLine::SetTextLength(int length)
168 {
169         __textLength = length;
170 }
171
172 void
173 TextLine::SetIndex(int index)
174 {
175         __index = index;
176 }
177
178 int
179 TextLine::GetIndex(void) const
180 {
181         return __index;
182 }
183
184 result
185 TextLine::SetTextOffset(int textOffset)
186 {
187         __textOffset = textOffset;
188
189         return E_SUCCESS;
190 }
191
192 int
193 TextLine::GetTextOffset(void) const
194 {
195         return __textOffset;
196 }
197
198 result
199 TextLine::SetBounds(const Rectangle& rect)
200 {
201         __rect = rect;
202
203         return E_SUCCESS;
204 }
205
206 void
207 TextLine::SetEndType(int endType)
208 {
209         __endType = endType;
210 }
211
212 int
213 TextLine::GetEndType(void) const
214 {
215         return __endType;
216 }
217
218 void
219 TextLine::SetRegion(int width, int height)
220 {
221         __width = width;
222         __height = height;
223 }
224
225 void
226 TextLine::SetBaseline(int baseline)
227 {
228         __baseline = baseline;
229 }
230
231 int
232 TextLine::GetBaseline(void) const
233 {
234         return __baseline;
235 }
236
237 int
238 TextLine::ForwardAnalyze(int startTextIndex, int textLength, int maxWidth, TextObjectWrapType wrap,
239                                                                         int& actualLength, int& width, int& height)
240 {
241         return -1;
242 }
243
244 result
245 TextLine::ResetSweepInfo(void)
246 {
247         __sweepComposeLineInfo.isValid = false;
248
249         return E_SUCCESS;
250 }
251
252 void
253 TextLine::SetSweepComposeInfo(TextObjectSweepComposeLineInfo& textSweepComposeLineInfo)
254 {
255         __sweepComposeLineInfo.isValid = textSweepComposeLineInfo.isValid;
256         __sweepComposeLineInfo.prevLineTextOffset = textSweepComposeLineInfo.prevLineTextOffset;
257         __sweepComposeLineInfo.prevLineTextLength = textSweepComposeLineInfo.prevLineTextLength;
258         __sweepComposeLineInfo.prevLineWidth = textSweepComposeLineInfo.prevLineWidth;
259         __sweepComposeLineInfo.currentLineTextOffset = textSweepComposeLineInfo.currentLineTextOffset;
260         __sweepComposeLineInfo.currentLineTextLength    = textSweepComposeLineInfo.currentLineTextLength;
261         __sweepComposeLineInfo.currentLineWidth = textSweepComposeLineInfo.currentLineWidth;
262 }
263
264 TextObjectSweepComposeLineInfo
265 TextLine::GetSweepComposeInfo(void) const
266 {
267         TextObjectSweepComposeLineInfo textSweepComposeLineInfo;
268
269         textSweepComposeLineInfo.isValid = __sweepComposeLineInfo.isValid;
270         textSweepComposeLineInfo.prevLineTextOffset = __sweepComposeLineInfo.prevLineTextOffset;
271         textSweepComposeLineInfo.prevLineTextLength = __sweepComposeLineInfo.prevLineTextLength;
272         textSweepComposeLineInfo.prevLineWidth = __sweepComposeLineInfo.prevLineWidth;
273         textSweepComposeLineInfo.currentLineTextOffset = __sweepComposeLineInfo.currentLineTextOffset;
274         textSweepComposeLineInfo.currentLineTextLength = __sweepComposeLineInfo.currentLineTextLength;
275         textSweepComposeLineInfo.currentLineWidth = __sweepComposeLineInfo.currentLineWidth;
276
277         return textSweepComposeLineInfo;
278 }
279
280 void
281 TextLine::SetSweepIn(int sweepIn)
282 {
283    __sweepIn = sweepIn;
284 }
285
286 int
287 TextLine::GetSweepIn(void) const
288 {
289    return __sweepIn;
290 }
291
292 void
293 TextLine::SetSweepOut(int sweepOut)
294 {
295    __sweepOut = sweepOut;
296 }
297
298 int
299 TextLine::GetSweepOut(void) const
300 {
301    return __sweepOut;
302 }
303
304 void
305 TextLine::SetKeyInputResult(int keyInputResult)
306 {
307    __sweepType = keyInputResult;
308 }
309
310 int
311 TextLine::GetKeyInputResult(void) const
312 {
313    return __sweepType;
314 }
315
316 void
317 TextLine::NotifyLineChanged(bool isChanged)
318 {
319    __isKeyInputChanged = isChanged;
320 }
321
322 bool
323 TextLine::isChanged(void) const
324 {
325    return __isKeyInputChanged;
326 }
327
328 void
329 TextLine::SetKeyInputOffset(int keyInputTextIndex)
330 {
331    __keyInputTextIndex = keyInputTextIndex;
332 }
333
334 int
335 TextLine::GetKeyInputOffset(void) const
336 {
337    return __keyInputTextIndex;
338 }
339
340 void
341 TextLine::SetKeyInputLength(int keyInputTextLength)
342 {
343    __keyInputTextLength = keyInputTextLength;
344 }
345
346 int
347 TextLine::GetKeyInputLength(void)
348 {
349    return __keyInputTextLength;
350 }
351
352 }}} // Tizen::Graphics::_Text