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.
19 * @file FUiCtrlContextMenu.h
20 * @brief This is the header file for the %ContextMenu class.
22 * This header file contains the declarations of the %ContextMenu class and its helper classes.
25 #ifndef _FUI_CTRL_CONTEXT_MENU_H_
26 #define _FUI_CTRL_CONTEXT_MENU_H_
28 #include <FBaseObject.h>
29 #include <FBaseTypes.h>
30 #include <FBaseString.h>
31 #include <FGrpBitmap.h>
32 #include <FGrpRectangle.h>
33 #include <FUiWindow.h>
34 #include <FUiContainer.h>
35 #include <FUiIActionEventListener.h>
37 namespace Tizen { namespace Graphics
43 namespace Tizen { namespace Ui { namespace Controls
47 * @enum ContextMenuStyle
49 * Defines the %ContextMenu style.
55 CONTEXT_MENU_STYLE_LIST,/**< The style of the vertical list of image + text */
56 CONTEXT_MENU_STYLE_GRID,/**< The style of the grid of buttons */
57 CONTEXT_MENU_STYLE_ICON /**<@if OSPDEPREC @deprecated This enumeration field is deprecated because this style can be implemented using the CONTEXT_MENU_STYLE_GRID style @endif */
61 * @enum ContextMenuItemStatus
63 * Defines the possible states of the %ContextMenu control item.
67 enum ContextMenuItemStatus
69 CONTEXT_MENU_ITEM_STATUS_NORMAL, /**< The normal state */
70 CONTEXT_MENU_ITEM_STATUS_PRESSED, /**< The pressed state */
71 CONTEXT_MENU_ITEM_STATUS_HIGHLIGHTED /**< The highlighted state */
75 * @enum ContextMenuAnchorDirection
77 * Defines the direction of the %ContextMenu control.
81 enum ContextMenuAnchorDirection
83 CONTEXT_MENU_ANCHOR_DIRECTION_LEFTWARD, /**< The anchor arrow direction is leftward */
84 CONTEXT_MENU_ANCHOR_DIRECTION_RIGHTWARD,/**< The anchor arrow direction is rightward */
85 CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD, /**< The anchor arrow direction is upward */
86 CONTEXT_MENU_ANCHOR_DIRECTION_DOWNWARD, /**< The anchor arrow direction is downward */
87 CONTEXT_MENU_ANCHOR_DIRECTION_AUTO /**< The anchor arrow direction is auto */
92 * @brief This class defines the common behavior of a %ContextMenu control.
96 * The %ContextMenu class displays a special purpose window that is used to present users with context-sensitive options.
98 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/ui/implementing_contextmenus.htm">ContextMenu</a>.
100 * The following example demonstrates how to use the %ContextMenu class.
104 // Sample code for ContextMenuSample.h
106 class ContextMenuSample
107 : public Tizen::Ui::Controls::Form
108 , public Tizen::Ui::IActionEventListener
111 ContextMenuSample(void)
112 :__pContextMenu(null){}
114 bool Initialize(void);
115 void ShowContextMenu(bool show);
116 virtual result OnInitializing(void);
117 virtual result OnTerminating(void);
119 // IActionEventListener
120 virtual void OnActionPerformed(const Tizen::Ui::Control& source, int actionId);
123 static const int ID_CONTEXTMENU_ITEM1 = 101;
124 static const int ID_CONTEXTMENU_ITEM2 = 102;
125 static const int ID_BTN_SHOW_CONTEXTMENU = 103;
127 Tizen::Ui::Controls::ContextMenu *__pContextMenu;
134 // Sample code for ContextMenuSample.cpp
135 #include <FGraphics.h>
137 #include "ContextMenuSample.h"
139 using namespace Tizen::Graphics;
140 using namespace Tizen::Ui::Controls;
143 ContextMenuSample::Initialize(void)
145 Construct(FORM_STYLE_NORMAL);
150 ContextMenuSample::OnInitializing(void)
152 result r = E_SUCCESS;
154 // Creates an instance of ContextMenu
155 __pContextMenu = new ContextMenu();
156 __pContextMenu->Construct(Point(400, 150), CONTEXT_MENU_STYLE_LIST);
158 __pContextMenu->AddItem(L"Item1", ID_CONTEXTMENU_ITEM1);
159 __pContextMenu->AddItem(L"Item2", ID_CONTEXTMENU_ITEM2);
160 __pContextMenu->AddActionEventListener(*this);
162 // Creates an instance of Button to show the context menu
163 Button* pButton = new Button();
164 pButton->Construct(Rectangle(50, 50, 400, 100), L"Show ContextMenu");
165 pButton->SetActionId(ID_BTN_SHOW_CONTEXTMENU);
166 pButton->AddActionEventListener(*this);
168 // Adds the button to the form
169 AddControl(*pButton);
174 // Sets the anchor position of the context menu
176 ContextMenuSample::ShowContextMenu(bool show)
178 __pContextMenu->SetPosition(Point(300, 200));
180 // Change to desired show state
181 __pContextMenu->SetShowState(show);
183 //Calls Show() of the control
186 __pContextMenu->Show();
195 ContextMenuSample::OnTerminating(void)
197 result r = E_SUCCESS;
199 // Deallocates the __pContextMenu
200 delete __pContextMenu;
205 // IActionEventListener implementation
207 ContextMenuSample::OnActionPerformed(const Control& source, int actionId)
211 case ID_CONTEXTMENU_ITEM1:
216 case ID_CONTEXTMENU_ITEM2:
221 case ID_BTN_SHOW_CONTEXTMENU:
223 ShowContextMenu(true);
233 class _OSP_EXPORT_ ContextMenu
234 : public Tizen::Ui::Window
239 * The object is not fully constructed after this constructor is called. For full construction, the Construct() method must be called right after calling this constructor.
247 * This destructor overrides Tizen::Base::Object::~Object().
252 virtual ~ContextMenu(void);
255 * Initializes this instance of %ContextMenu with the specified parameters.
259 * @return An error code
260 * @param[in] point The x and y coordinates of the anchor of %ContextMenu
261 * @param[in] style The context menu style
262 * @exception E_SUCCESS The method is successful.
263 * @exception E_INVALID_STATE This instance has already been constructed.
264 * @exception E_SYSTEM A system error has occurred.
266 result Construct(const Tizen::Graphics::Point& point, ContextMenuStyle style);
269 * Initializes this instance of %ContextMenu with the specified parameters.
273 * @return An error code
274 * @param[in] point The x and y coordinates of the anchor of the %ContextMenu control
275 * @param[in] style The context menu style
276 * @param[in] direction The anchor arrow direction
277 * @exception E_SUCCESS The method is successful.
278 * @exception E_INVALID_STATE This instance has already been constructed.
279 * @exception E_SYSTEM A system error has occurred.
281 result Construct(const Tizen::Graphics::Point& point, ContextMenuStyle style, ContextMenuAnchorDirection direction);
284 * Adds a listener instance.
285 * The added listener can listen to events on the given context of the event dispatcher when they are fired.
289 * @param[in] listener The event listener to be added
291 void AddActionEventListener(Tizen::Ui::IActionEventListener& listener);
294 * Removes the specified listener instance.
295 * The removed listener cannot listen to events when they are fired.
299 * @param[in] listener The event listener to be removed
301 void RemoveActionEventListener(Tizen::Ui::IActionEventListener& listener);
306 * Appends the specified item at the end of the %ContextMenu control.
310 * @return An error code
311 * @param[in] normalBitmap The normal bitmap of the item
312 * @param[in] pPressedBitmap The pressed bitmap of the item
313 * @param[in] actionId The action ID for this item
314 * @exception E_SUCCESS The method is successful.
315 * @exception E_MAX_EXCEEDED The number of items has exceeded the maximum limit.
316 * @exception E_SYSTEM A system error has occurred.
317 * @remarks This method can only be used when the style of the context menu is CONTEXT_MENU_STYLE_GRID.
319 result AddItem(const Tizen::Graphics::Bitmap& normalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap, int actionId);
322 * Appends the specified item at the end of the %ContextMenu control.
326 * @return An error code
327 * @param[in] normalBitmap The normal bitmap of the item
328 * @param[in] pPressedBitmap The pressed bitmap of the item
329 * @param[in] pHighlightedBitmap The highlighted bitmap of the item
330 * @param[in] actionId The action ID for this item
331 * @exception E_SUCCESS The method is successful.
332 * @exception E_MAX_EXCEEDED The number of items has exceeded the maximum limit.
333 * @exception E_SYSTEM A system error has occurred.
334 * @remarks This method can only be used when the style of the context menu is CONTEXT_MENU_STYLE_GRID. @n
335 * When a user navigates the user interface using the directional keys, the selected UI control is highlighted and the control takes the
338 result AddItem(const Tizen::Graphics::Bitmap& normalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap, const Tizen::Graphics::Bitmap* pHighlightedBitmap, int actionId);
341 * Appends the specified item at the end of the %ContextMenu control.
345 * @return An error code
346 * @param[in] text The string of the item to be appended
347 * @param[in] actionId The specified action ID for this item
348 * @exception E_SUCCESS The method is successful.
349 * @exception E_MAX_EXCEEDED The number of items has exceeded the maximum limit.
350 * @exception E_SYSTEM A system error has occurred.
352 result AddItem(const Tizen::Base::String& text, int actionId);
355 * Appends the specified item at the end of the %ContextMenu control.
359 * @return An error code
360 * @param[in] text The string of the item to be appended
361 * @param[in] actionId The specified action ID for this item
362 * @param[in] normalBitmap The normal bitmap of the item
363 * @param[in] pPressedBitmap The pressed bitmap of the item
364 * @param[in] pHighlightedBitmap The highlighted bitmap of the item
365 * @exception E_SUCCESS The method is successful.
366 * @exception E_MAX_EXCEEDED The total number of items has exceeded the maximum limit.
367 * @exception E_SYSTEM A system error has occurred.
368 * @remarks This method can only be used when the style of the context menu is CONTEXT_MENU_STYLE_LIST.
370 result AddItem(const Tizen::Base::String& text, int actionId, const Tizen::Graphics::Bitmap& normalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap = null, const Tizen::Graphics::Bitmap* pHighlightedBitmap = null);
373 * Inserts the specified item at the given index of the %ContextMenu control.
377 * @return An error code
378 * @param[in] index The location
379 * @param[in] normalBitmap The normal bitmap of the item
380 * @param[in] pPressedBitmap The pressed bitmap of the item
381 * @param[in] actionId The specified action ID for this item
382 * @exception E_SUCCESS The method is successful.
383 * @exception E_MAX_EXCEEDED The number of items has exceeded the maximum limit.
384 * @exception E_OUT_OF_RANGE The specified @c index is less than @c 0 or greater than the number of items in %ContextMenu.
385 * @exception E_SYSTEM A system error has occurred.
386 * @remarks This method can only be used when the style of the context menu is CONTEXT_MENU_STYLE_GRID. @n
387 * The %ContextMenu control can have a maximum of 3 icons.
389 result InsertItemAt(int index, const Tizen::Graphics::Bitmap& normalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap, int actionId);
392 * Inserts the specified item at the given index of the %ContextMenu control.
396 * @return An error code
397 * @param[in] index The location
398 * @param[in] normalBitmap The normal bitmap of the item
399 * @param[in] pPressedBitmap The pressed bitmap of the item
400 * @param[in] pHighlightedBitmap The highlighted bitmap of the item
401 * @param[in] actionId The specified action ID for this item
402 * @exception E_SUCCESS The method is successful.
403 * @exception E_MAX_EXCEEDED The number of items has exceeded the maximum limit.
404 * @exception E_OUT_OF_RANGE The specified @c index is less than @c 0 or greater than the number of items in %ContextMenu.
405 * @exception E_SYSTEM A system error has occurred.
406 * @remarks This method can only be used when the style of the context menu is CONTEXT_MENU_STYLE_GRID. @n
407 * @remarks When a user navigates the user interface using the directional keys, the selected UI control is highlighted and the control takes the focus.
409 result InsertItemAt(int index, const Tizen::Graphics::Bitmap& normalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap, const Tizen::Graphics::Bitmap* pHighlightedBitmap, int actionId);
412 * Inserts the specified item at the given index of the %ContextMenu control.
416 * @return An error code
417 * @param[in] index The location
418 * @param[in] text The string of the item to set
419 * @param[in] actionId The specified action ID for this item
420 * @exception E_SUCCESS The method is successful.
421 * @exception E_MAX_EXCEEDED The number of items has exceeded the maximum limit.
422 * @exception E_OUT_OF_RANGE The specified @c index is less than @c 0 or greater than the number of items in %ContextMenu.
423 * @exception E_SYSTEM A system error has occurred.
425 result InsertItemAt(int index, const Tizen::Base::String& text, int actionId);
428 * Inserts the specified item at the given index of the %ContextMenu control.
432 * @return An error code
433 * @param[in] index The location
434 * @param[in] text The string of the item to set
435 * @param[in] actionId The specified action ID for this item
436 * @param[in] normalBitmap The normal bitmap of the item
437 * @param[in] pPressedBitmap The pressed bitmap of the item
438 * @param[in] pHighlightedBitmap The highlighted bitmap of the item
439 * @exception E_SUCCESS The method is successful.
440 * @exception E_MAX_EXCEEDED The number of items has exceeded the maximum limit.
441 * @exception E_OUT_OF_RANGE The specified @c index is less than @c 0 or greater than the number of items in %ContextMenu.
442 * @exception E_SYSTEM A system error has occurred.
443 * @remarks This method can only be used when the style of the context menu is CONTEXT_MENU_STYLE_LIST.
445 result InsertItemAt(int index, const Tizen::Base::String& text, int actionId, const Tizen::Graphics::Bitmap& normalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap = null, const Tizen::Graphics::Bitmap* pHighlightedBitmap = null);
448 * Sets the specified item at the given index of the %ContextMenu control.
452 * @return An error code
453 * @param[in] index The location
454 * @param[in] normalBitmap The normal bitmap of the item
455 * @param[in] pPressedBitmap The pressed bitmap of the item
456 * @param[in] actionId The action ID for this item
457 * @exception E_SUCCESS The method is successful.
458 * @exception E_OUT_OF_RANGE The specified @c index is less than @c 0 or greater than the number of items in %ContextMenu.
459 * @exception E_SYSTEM A system error has occurred.
460 * @remarks This method can only be used when the style of the context menu is CONTEXT_MENU_STYLE_GRID.
462 result SetItemAt(int index, const Tizen::Graphics::Bitmap& normalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap, int actionId);
465 * Sets the specified item at the given index of the %ContextMenu control.
469 * @return An error code
470 * @param[in] index The location
471 * @param[in] normalBitmap The normal bitmap of the item
472 * @param[in] pPressedBitmap The pressed bitmap of the item
473 * @param[in] pHighlightedBitmap The highlighted bitmap of the item
474 * @param[in] actionId The action ID for this item
475 * @exception E_SUCCESS The method is successful.
476 * @exception E_OUT_OF_RANGE The specified @c index is less than @c 0 or greater than the number of items in %ContextMenu.
477 * @exception E_SYSTEM A system error has occurred.
478 * @remarks This method can only be used when the style of the context menu is CONTEXT_MENU_STYLE_GRID. @n
479 * @remarks When a user navigates the user interface using the directional keys, @n
480 * the selected UI control is highlighted and the control takes the focus.
482 result SetItemAt(int index, const Tizen::Graphics::Bitmap& normalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap, const Tizen::Graphics::Bitmap* pHighlightedBitmap, int actionId);
485 * Sets the specified item at the given index of the %ContextMenu control.
489 * @return An error code
490 * @param[in] index The location
491 * @param[in] text The string of the item to set
492 * @param[in] actionId The action ID for this item
493 * @exception E_SUCCESS The method is successful.
494 * @exception E_OUT_OF_RANGE The specified @c index less than @c 0 or greater than the number of items in %ContextMenu.
495 * @exception E_SYSTEM A system error has occurred.
497 result SetItemAt(int index, const Tizen::Base::String& text, int actionId);
500 * Sets the specified item at the given index of the %ContextMenu control.
504 * @return An error code
505 * @param[in] index The location
506 * @param[in] text The string of the item to set
507 * @param[in] actionId The action ID for this item
508 * @param[in] normalBitmap The normal bitmap of the item
509 * @param[in] pPressedBitmap The pressed bitmap of the item
510 * @param[in] pHighlightedBitmap The highlighted bitmap of the item
511 * @exception E_SUCCESS The method is successful.
512 * @exception E_OUT_OF_RANGE The specified @c index less than @c 0 or greater than the number of items in %ContextMenu.
513 * @exception E_SYSTEM A system error has occurred.
514 * @remarks This method can only be used when the style of the context menu is CONTEXT_MENU_STYLE_LIST.
516 result SetItemAt(int index, const Tizen::Base::String& text, int actionId, const Tizen::Graphics::Bitmap& normalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap = null, const Tizen::Graphics::Bitmap* pHighlightedBitmap = null);
519 * Removes the item at the specified index from the %ContextMenu control.
523 * @return An error code
524 * @param[in] index The location
525 * @exception E_SUCCESS The method is successful.
526 * @exception E_SYSTEM A system error has occurred.
528 result RemoveItemAt(int index);
531 * Removes all items from the %ContextMenu control.
535 * @exception E_SUCCESS The method is successful.
536 * @exception E_SYSTEM A system error has occurred.
538 result RemoveAllItems(void);
541 * Gets the number of items of the %ContextMenu control.
545 * @return The number of items registered for %ContextMenu, @n
546 * else @c -1 if an error occurs
548 int GetItemCount(void) const;
551 * Gets the index of the item with the specified action ID.
555 * @return The index of the item, @n
556 * else @c -1 if an error occurs
557 * @param[in] actionId The action ID
559 int GetItemIndexFromActionId(int actionId) const;
562 * Gets the action ID of the item at the specified index.
566 * @return The action ID of the item, @n
567 * else @c -1 if the specified index is invalid
568 * @param[in] index The index of the item
570 int GetItemActionIdAt(int index) const;
573 * Gets the item text color of the %ContextMenu control for the specified status.
577 * @return The item text color, @n
578 * else RGBA (0,0,0,0) if an error occurs
579 * @param[in] status The item status
581 Tizen::Graphics::Color GetItemTextColor(ContextMenuItemStatus status) const;
584 * Sets the item text color of the %ContextMenu control for the specified status.
588 * @return An error code
589 * @param[in] status The item status
590 * @param[in] color The item text color to be set
591 * @exception E_SUCCESS The method is successful.
592 * @exception E_INVALID_ARG A specified input parameter is invalid.
593 * @exception E_SYSTEM A system error has occurred.
595 result SetItemTextColor(ContextMenuItemStatus status, const Tizen::Graphics::Color& color);
598 * Sets the position of the anchor.
602 * @return An error code
603 * @param[in] position The new position
604 * @exception E_SUCCESS The method is successful.
605 * @exception E_INVALID_STATE This instance is in an invalid state.
606 * @remarks The x and y coordinates of the anchor are defined in the coordinate space of its parent,
607 * which means that @c x and @c y must be defined relative to the top-left corner (0,0) of its parent.
609 result SetAnchorPosition(const Tizen::Graphics::Point& position);
612 * Gets the position of the anchor.
616 * @return The position of the anchor
617 * @remarks The coordinate of the anchor position is defined from the top-left corner of its parent Container.
619 Tizen::Graphics::Point GetAnchorPosition(void) const;
622 * Gets the color of the %ContextMenu control.
626 * @return The color of %ContextMenu control, @n
627 * else RGBA(0, 0, 0, 0) if an error occurs
630 Tizen::Graphics::Color GetColor(void) const;
633 * Sets the color of the %ContextMenu control.
637 * @return An error code
638 * @param[in] color The color to be set
639 * @exception E_SUCCESS The method is successful.
640 * @exception E_INVALID_STATE This instance is in an invalid state.
641 * @exception E_SYSTEM A system error has occurred.
644 result SetColor(const Tizen::Graphics::Color& color);
647 * Gets the item color for the specified status.
651 * @return The color of %ContextMenu control, @n
652 * else RGBA(0, 0, 0, 0) if an error occurs
653 * @param[in] status The menu item status
654 * @exception E_SUCCESS The method is successful.
655 * @exception E_INVALID_ARG The specified input parameter is invalid. @n
656 * The item color for CONTEXT_MENU_ITEM_STATUS_NORMAL is not supported.
657 * @exception E_INVALID_STATE This instance is in an invalid state.
658 * @exception E_SYSTEM A system error has occurred.
659 * @remarks The specific error code can be accessed using the GetLastResult() method. @n
660 * The item color for the CONTEXT_MENU_ITEM_STATUS_NORMAL status is always the same as the color of the %ContextMenu control.
661 * @see SetItemColor()
663 Tizen::Graphics::Color GetItemColor(ContextMenuItemStatus status) const;
666 * Sets the item color for the specified status.
670 * @return An error code
671 * @param[in] status The menu item status
672 * @param[in] color The color to be set
673 * @exception E_SUCCESS The method is successful.
674 * @exception E_INVALID_ARG The specified input parameter is invalid. @n
675 * The item color for CONTEXT_MENU_ITEM_STATUS_NORMAL is not supported.
676 * @exception E_INVALID_STATE This instance is in an invalid state.
677 * @exception E_SYSTEM A system error has occurred.
678 * @remarks The item color for the CONTEXT_MENU_ITEM_STATUS_NORMAL status is always the same as the color of the %ContextMenu control.
679 * @see GetItemColor()
681 result SetItemColor(ContextMenuItemStatus status, const Tizen::Graphics::Color& color);
684 * Gets maximum number of visible items.
688 * @return The maximum number of visible items, @n
689 * else @c -1 if an error occurs
690 * @see SetMaxVisibleItemsCount()
692 int GetMaxVisibleItemsCount(void) const;
695 * Sets maximum number of visible items.
699 * @return An error code
700 * @param[in] maxItemsCount The maximum number of the visible menu items
701 * @exception E_SUCCESS The method is successful.
702 * @exception E_OUT_OF_RANGE The specified @c parameter is out of possible range.
703 * @exception E_INVALID_STATE This instance is in an invalid state.
704 * @exception E_SYSTEM A system error has occurred.
705 * @remarks @c maxItemsCount should be greater than @c 0 and less than @c 8. The default value for
706 * the maximum number of the visible menu items is @c 4.
707 * @see GetMaxVisibleItemsCount()
709 result SetMaxVisibleItemsCount(int maxItemsCount);
712 friend class _ContextMenuImpl;
715 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
720 ContextMenu(const ContextMenu& rhs);
723 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
728 ContextMenu& operator =(const ContextMenu& rhs);
731 }}} // Tizen::Ui: Control
733 #endif // _FUI_CTRL_CONTEXT_MENU_H_