2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
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.
18 * @file FUiCtrl_ContextMenuItem.cpp
19 * @brief This is the implementation file for the _ContextMenuItem class.
22 #include <FBaseSysLog.h>
23 #include <FGrp_BitmapImpl.h>
24 #include "FUi_ResourceManager.h"
25 #include "FUiCtrl_ContextMenuItem.h"
28 using namespace Tizen::Base;
29 using namespace Tizen::Graphics;
30 using namespace Tizen::Ui;
32 namespace Tizen { namespace Ui { namespace Controls
35 _ContextMenuItem::_ContextMenuItem(void)
36 : __type(CONTEXT_MENU_ITEM_DRAWING_TYPE_NONE)
40 , __parentScrollEnable(false)
43 , __size(Dimension(0, 0))
44 , __drawRect(Rectangle(0, 0, 0, 0))
45 , __pBitmapLabel(null)
47 , __pDividerLineLabel1(null)
48 , __pDividerLineLabel2(null)
50 __pBitmap[CONTEXT_MENU_ITEM_DRAWING_STATUS_NORMAL] = null;
51 __pBitmap[CONTEXT_MENU_ITEM_DRAWING_STATUS_PRESSED] = null;
52 __pBitmap[CONTEXT_MENU_ITEM_DRAWING_STATUS_HIGHLIGHTED] = null;
55 _ContextMenuItem::~_ContextMenuItem(void)
57 if (__pBitmap[CONTEXT_MENU_ITEM_DRAWING_STATUS_NORMAL] != null)
59 delete __pBitmap[CONTEXT_MENU_ITEM_DRAWING_STATUS_NORMAL];
60 __pBitmap[CONTEXT_MENU_ITEM_DRAWING_STATUS_NORMAL] = null;
63 if (__pBitmap[CONTEXT_MENU_ITEM_DRAWING_STATUS_PRESSED] != null)
65 delete __pBitmap[CONTEXT_MENU_ITEM_DRAWING_STATUS_PRESSED];
66 __pBitmap[CONTEXT_MENU_ITEM_DRAWING_STATUS_PRESSED] = null;
69 if (__pBitmap[CONTEXT_MENU_ITEM_DRAWING_STATUS_HIGHLIGHTED] != null)
71 delete __pBitmap[CONTEXT_MENU_ITEM_DRAWING_STATUS_HIGHLIGHTED];
72 __pBitmap[CONTEXT_MENU_ITEM_DRAWING_STATUS_HIGHLIGHTED] = null;
77 _ContextMenuItem::CreateContextMenuItemN(void)
81 _ContextMenuItem* pItem = null;
83 pItem = new (std::nothrow) _ContextMenuItem();
86 SetLastResult(E_OUT_OF_MEMORY);
90 pItem->AcquireHandle();
92 SetLastResult(E_SUCCESS);
97 _ContextMenuItem::SetBitmapLabel(_Label* pLabel)
99 __pBitmapLabel = pLabel;
103 _ContextMenuItem::SetTextLabel(_Label* pLabel)
105 __pTextLabel = pLabel;
110 _ContextMenuItem::SetType(ContextMenuItemDrawingType type)
115 ContextMenuItemDrawingType
116 _ContextMenuItem::GetType(void) const
122 _ContextMenuItem::SetActionId(int actionId)
124 __actionId = actionId;
128 _ContextMenuItem::GetActionId(void) const
134 _ContextMenuItem::SetDivider(bool drawDivider)
136 __divider = drawDivider;
139 _ContextMenuItem::GetDivider(void) const
145 _ContextMenuItem::SetTextSize(int size)
151 _ContextMenuItem::SetText(const Tizen::Base::String& text)
153 if (text.GetLength() <= 0)
155 return E_INVALID_ARG;
163 const Tizen::Base::String&
164 _ContextMenuItem::GetText(void) const
170 _ContextMenuItem::SetBitmap(ContextMenuItemDrawingStatus status, const Tizen::Graphics::Bitmap* pBitmap)
172 if (status < CONTEXT_MENU_ITEM_DRAWING_STATUS_NORMAL || status > CONTEXT_MENU_ITEM_DRAWING_STATUS_HIGHLIGHTED)
174 return E_INVALID_ARG;
177 SysTryReturn(NID_UI_CTRL, (status != CONTEXT_MENU_ITEM_DRAWING_STATUS_NORMAL || pBitmap != null), E_INVALID_ARG,
179 "[E_INVALID_ARG] The normal bitmap must not be null.");
181 Bitmap* pClonedBitmap = _BitmapImpl::CloneN(*pBitmap);
183 // If bitmap is in _ContextMenuItem, delete old one.
184 if (__pBitmap[status] != null)
186 delete __pBitmap[status];
187 __pBitmap[status] = null;
190 __pBitmap[status] = pClonedBitmap;
195 const Tizen::Graphics::Bitmap*
196 _ContextMenuItem::GetBitmap(ContextMenuItemDrawingStatus status) const
198 if (status < CONTEXT_MENU_ITEM_DRAWING_STATUS_NORMAL || status > CONTEXT_MENU_ITEM_DRAWING_STATUS_HIGHLIGHTED)
203 return __pBitmap[status];
207 _ContextMenuItem::SetSize(Tizen::Graphics::Dimension size)
212 Tizen::Graphics::Dimension
213 _ContextMenuItem::GetSize(void) const
219 _ContextMenuItem::SetDrawRect(Tizen::Graphics::Rectangle rect)
225 Tizen::Graphics::Rectangle
226 _ContextMenuItem::GetDrawRect(void) const
233 _ContextMenuItem::Release(void)
241 _ContextMenuItem::OnDraw(void)
248 _ContextMenuItem::DrawItem(void)
252 Color selectedBgColor;
253 GET_COLOR_CONFIG(CONTEXTMENU::ITEM_BG_PRESSED, selectedBgColor);
254 SetBackgroundColor(selectedBgColor);
258 SetBackgroundColor(Color(0, 0, 0, 0));
265 _ContextMenuItem::DrawItemDivider(void)
267 int leftMargin, rightMargin;
268 GET_SHAPE_CONFIG(CONTEXTMENU::LIST_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, leftMargin);
269 GET_SHAPE_CONFIG(CONTEXTMENU::LIST_RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, rightMargin);
270 if (__pDividerLineLabel1 == null)
272 __pDividerLineLabel1 = _Label::CreateLabelN();
273 SysTryReturnVoidResult(NID_UI_CTRL, __pDividerLineLabel1, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
275 Rectangle bounds = GetBounds();
277 __pDividerLineLabel1->SetBounds(Rectangle(leftMargin, bounds.height - 2, bounds.width - leftMargin - rightMargin, 1));
279 Color dividerLineColor;
280 GET_COLOR_CONFIG(CONTEXTMENU::LIST_ITEM_DIVIDER1, dividerLineColor);
281 __pDividerLineLabel1->SetBackgroundColor(dividerLineColor);
283 AttachChild(*__pDividerLineLabel1);
286 __pDividerLineLabel1->Invalidate();
288 if (__pDividerLineLabel2 == null)
290 __pDividerLineLabel2 = _Label::CreateLabelN();
291 SysTryReturnVoidResult(NID_UI_CTRL, __pDividerLineLabel2, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
293 Rectangle bounds = GetBounds();
295 __pDividerLineLabel2->SetBounds(Rectangle(leftMargin, bounds.height - 1, bounds.width - leftMargin - rightMargin, 1));
297 Color dividerLineColor;
298 GET_COLOR_CONFIG(CONTEXTMENU::LIST_ITEM_DIVIDER2, dividerLineColor);
299 __pDividerLineLabel2->SetBackgroundColor(dividerLineColor);
301 AttachChild(*__pDividerLineLabel2);
304 __pDividerLineLabel2->Invalidate();
307 _UiTouchEventDelivery
308 _ContextMenuItem::OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
310 return _UI_TOUCH_EVENT_DELIVERY_FORCED_YES;
313 _UiTouchEventDelivery
314 _ContextMenuItem::OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
316 return _UI_TOUCH_EVENT_DELIVERY_FORCED_YES;
319 _UiTouchEventDelivery
320 _ContextMenuItem::OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
322 return _UI_TOUCH_EVENT_DELIVERY_FORCED_YES;
326 _ContextMenuItem::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
336 _ContextMenuItem::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
346 _ContextMenuItem::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
350 if (__parentScrollEnable)
360 int oldSelected = __selected;
362 Rectangle bounds(0, 0, __size.width, __size.height);
363 if (bounds.Contains(touchinfo.GetCurrentPosition()))
372 if (oldSelected != __selected)
382 _ContextMenuItem::OnFontChanged(Tizen::Graphics::Font* pFont)
384 String fontName = _Control::GetFont();
386 if (__pTextLabel != null)
388 __pTextLabel->SetFont(fontName);
393 _ContextMenuItem::OnFontInfoRequested(unsigned long& style, int& size)
395 style = FONT_STYLE_PLAIN;
400 _ContextMenuItem::SetParentScrollEnable(bool enable)
402 __parentScrollEnable = enable;
406 _ContextMenuItem::GetParentScrollEnable() const
408 return __parentScrollEnable;
412 _ContextMenuItem::IsSelected() const
418 _ContextMenuItem::Reset()
424 }}} // Tizen::Ui::Controls