2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.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
9 // http://www.apache.org/licenses/LICENSE-2.0/
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.
19 * @file FGrp_TextTextCutLink.cpp
20 * @brief This is the implementation file for TextCutLink class.
24 #include <FBaseSysLog.h>
25 #include "FGrp_TextCommon.h"
26 #include "FGrp_TextTextUtility.h"
27 #include "FGrp_TextTextElement.h"
28 #include "FGrp_TextTextSimple.h"
29 #include "FGrp_TextTextCutLink.h"
30 #include "FGrp_CanvasImpl.h"
31 #include "FGrp_CoordinateSystemUtils.h"
33 using namespace Tizen::Base::Utility;
37 const int DEFAULT_FONT_SIZE = 42;
40 namespace Tizen { namespace Graphics
46 TextCutLink::TextCutLink(bool isEditable, LinkType cutLinkType, const wchar_t* pText, int length, TextElementSourceType sourceType,
47 Font* pFont, const Color& foregroundColor, const Color& backgroundColor, const Color&
49 : TextSimple(pText, length, sourceType, pFont, foregroundColor, backgroundColor, outlineColor)
51 __linkType = cutLinkType;
52 __isEditable = isEditable;
55 _type = TEXT_ELEMENT_TYPE_CUTLINK;
56 __isColorDefined = false;
57 __linkColor = Color::GetColor(COLOR_ID_BLUE);
58 __linkSelectedColor = Color::GetColor(COLOR_ID_BLUE);
60 __pLinkFont = new (std::nothrow) Font();
61 __pLinkFont->Construct(FONT_STYLE_PLAIN, DEFAULT_FONT_SIZE);
64 TextCutLink::~TextCutLink(void)
74 TextCutLink::Draw(_CanvasImpl& canvasImpl, Rectangle& displayRect, int startTextIndex, int textLength, const TextObjectAlignment align,
75 const TextObjectActionType action)
77 SysTryReturn(NID_GRP, displayRect.x >= 0 && displayRect.y >= 0
78 , E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
80 return Draw(canvasImpl, displayRect, startTextIndex, textLength, align, action);
84 TextCutLink::Draw(_CanvasImpl& canvasImpl, FloatRectangle& displayRect, int startTextIndex, int textLength, const TextObjectAlignment align,
85 const TextObjectActionType action)
87 return TextSimple::Draw(canvasImpl, displayRect, startTextIndex, textLength, align, action);
91 TextCutLink::CloneN(TextComponentInfoValueType type, unsigned int value)
93 TextCutLink* pLinkElement = null;
95 pLinkElement = new (std::nothrow) TextCutLink(__isEditable, __linkType, _pText, _length,
96 TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL, _pFont, _foregroundColor, _backgroundColor, _outlineColor);
98 SysTryReturn(NID_GRP, pLinkElement, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
100 TextElement::CopyMembers(pLinkElement);
102 pLinkElement->__isEdited = __isEdited;
103 pLinkElement->SetValue(type, value);
109 TextCutLink::CopyN(int textStartIndex, int textLength)
111 const wchar_t* pText = null;
113 TextCutLink* pLinkElement = null;
115 SysTryReturn(NID_GRP, textStartIndex < _length, null, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
117 if (textStartIndex + textLength > _length)
119 textLength = _length - textStartIndex;
122 SysTryReturn(NID_GRP, textLength >= 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
124 pText = &_pText[_offset + textStartIndex];
126 pLinkElement = new (std::nothrow) TextCutLink(__isEditable, __linkType, pText, textLength, _sourceType,
127 _pFont, _foregroundColor, _backgroundColor, _outlineColor);
129 SysTryReturn(NID_GRP, pLinkElement, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
131 pLinkElement->_isBackgroundDrawingModeEnabled = _isBackgroundDrawingModeEnabled;
132 pLinkElement->__isEdited = __isEdited;
138 TextCutLink::SetValue(TextComponentInfoValueType type, unsigned int value)
142 case SET_CUTLINK_TYPE:
144 return E_INVALID_ARG;
146 case SET_CUTLINK_EDITABLE:
148 return E_INVALID_ARG;
150 case SET_CUTLINK_EDITING:
153 __isEdited = (bool) value;
156 return E_INVALID_ARG;
162 if (!__isEdited && type == SET_TEXT_OFFSET)
164 return E_INVALID_ARG;
167 return TextSimple::SetValue(type, value);
171 TextCutLink::GetValue(TextComponentInfoValueType type) const
175 case SET_CUTLINK_TYPE:
177 return (unsigned int) __linkType;
179 case SET_CUTLINK_EDITABLE:
181 return (unsigned int) __isEditable;
183 case SET_CUTLINK_EDITING:
185 return (unsigned int) __isEdited;
189 return TextSimple::GetValue(type);
194 TextCutLink::SetSelect(bool isSelected)
196 __isSelected = isSelected;
200 TextCutLink::GetSelect(void) const
206 TextCutLink::SetUserColor(const Color& color, const Color& colorInSelect)
208 __isColorDefined = true;
210 __linkSelectedColor = colorInSelect;
214 TextCutLink::ResetUserColor(void)
216 __isColorDefined = false;
220 TextCutLink::SetTextOffset(int offset)
222 SysTryReturn(NID_GRP, __isEdited == true, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
224 return TextSimple::SetTextOffset(offset);
228 TextCutLink::ChangeTextOffset(wchar_t* pText, int gap)
230 SysTryReturn(NID_GRP, __isEdited == true, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
232 return TextSimple::ChangeTextOffset(pText, gap);
236 TextCutLink::GetFont(void) const
240 return TextSimple::GetCurrentFont();
247 TextCutLink::GetCurrentFont(void) const
251 return TextSimple::GetCurrentFont();
258 TextCutLink::GetCurrentForegroundColor(void) const
262 return TextSimple::GetCurrentForegroundColor();
265 if (__isColorDefined)
269 return __linkSelectedColor;
277 return Color::GetColor(COLOR_ID_BLUE);
280 return Color::GetColor(COLOR_ID_BLUE);
284 TextCutLink::GetCurrentBackgroundColor(void) const
288 return TextSimple::GetCurrentBackgroundColor();
293 return Color::GetColor(COLOR_ID_WHITE);
296 return Color::GetColor(COLOR_ID_WHITE);
300 TextCutLink::GetCurrentOutlineColor(void) const
304 return TextSimple::GetCurrentOutlineColor();
307 return Color::GetColor(COLOR_ID_WHITE);
311 TextCutLink::GetEditable(void) const
317 TextCutLink::SetEditModeEnable(bool enable)
323 TextCutLink::IsEditModeEnable(void) const
328 Tizen::Base::Utility::LinkType
329 TextCutLink::GetCutLinkType(void) const
334 }}} // Tizen::Graphics::_Text