add patch
[framework/osp/uifw.git] / src / ui / inc / FUiCtrl_MessageBoxPresenter.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
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                FUiCtrl_MessageBoxPresenter.h
20  * @brief       This is the header file for the _MessageBoxPresenter class.
21  *
22  * This header file contains the declarations of the %_MessageBoxPresenter class.
23  */
24
25 #ifndef _FUI_CTRL_INTERNAL_MESSAGEBOX_PRESENTER_H_
26 #define _FUI_CTRL_INTERNAL_MESSAGEBOX_PRESENTER_H_
27
28
29 #include <FUiIActionEventListener.h>
30 #include "FUi_UiTouchEvent.h"
31 #include "FUiCtrl_PopupPresenter.h"
32
33 namespace Tizen { namespace Graphics { namespace _Text {
34         class TextObject;
35 }}} // Tizen::Graphics::_Text
36
37 namespace Tizen { namespace Ui { namespace Controls
38 {
39
40 class Button;
41 class _MessageBox;
42 class _Label;
43 class _Scroll;
44 class _ScrollPanel;
45
46 /**
47  * @class _MessageBoxPresenter
48  * @brief
49  * @since       2.0
50  *
51  *
52  *
53  *
54  */
55 class _MessageBoxPresenter
56         : public _PopupPresenter
57         , virtual public Tizen::Base::Runtime::IEventListener
58 {
59 // Lifecycle
60 public:
61         _MessageBoxPresenter(void);
62         virtual ~_MessageBoxPresenter(void);
63
64 // Operations
65 public:
66         result Initialize(_MessageBox& msgbox);
67
68         virtual void Draw(void);
69
70         virtual result ShowAndWait(int& modalResult);
71
72         result OnChangeLayout(_ControlOrientation orientation);
73
74         // get touch event from _MessageBox, for drawing scroll in TextObject
75         virtual bool OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo);
76         virtual bool OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo);
77         virtual bool OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo);
78
79         bool OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo);
80
81         void UpdateButtonString(void);
82
83         void InitializeAccessibilityElement(void);
84
85         bool OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element);
86 //Accessor
87 public:
88         float GetBodyTextHeight(void) const;
89         float GetBodyTextObjHeight(void) const;
90
91         Tizen::Graphics::FloatRectangle GetTextBounds(void) const;
92
93 protected:
94         virtual void ProcessEvent(void);
95         virtual _Popup* GetCore(void);
96 private:
97         _MessageBoxPresenter(const _MessageBoxPresenter& rhs);
98         _MessageBoxPresenter& operator =(const _MessageBoxPresenter& rhs);
99
100         result CreateButtons(void);
101         void FindButtonAndResult(const _ControlHandle handle);
102
103         float CalculateButtonAreaHeight(void);
104         Tizen::Graphics::FloatRectangle CalculateButtonPositionAndSize(int buttonIndex);
105
106         void SetReturnValue(MessageBoxModalResult rtn);
107         int GetReturnValue(void) const;
108
109         float GetLabelHeight(Tizen::Graphics::_Text::TextObject* textObject, wchar_t* text, int length, float fontSize, FloatRectangle bounds, bool isTitle);
110         float GetLeftRightLabelMargin(void);
111
112         void GetButtonString(void);
113
114 // Inner class
115 private:
116         class _MessageBoxButtonListener
117                 : public ITouchEventListener
118                 , public IKeyEventListener
119                 , virtual public Tizen::Base::Runtime::IEventListener
120         {
121 public:
122                 _MessageBoxButtonListener(void);
123                 virtual ~_MessageBoxButtonListener(void);
124
125                 _ControlHandle GetClickedButtonHandle(void) const;
126                 bool IsButtonClicked(void);
127                 void SetBeginModal(bool beginModal);
128                 bool GetBeginModal(void);
129
130 protected:
131                 virtual void OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition,
132                                                                                         const Tizen::Ui::TouchEventInfo& touchInfo);
133                 virtual void OnTouchLongPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition,
134                                                                                                         const Tizen::Ui::TouchEventInfo& touchInfo) {}
135                 virtual void OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition,
136                                                                                                 const Tizen::Ui::TouchEventInfo& touchInfo);
137                 virtual void OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition,
138                                                                                         const Tizen::Ui::TouchEventInfo& touchInfo);
139                 virtual void OnTouchDoublePressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition,
140                                                                                         const Tizen::Ui::TouchEventInfo& touchInfo) {}
141                 virtual void OnTouchFocusIn(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition,
142                                                                                         const Tizen::Ui::TouchEventInfo& touchInfo) {}
143                 virtual void OnTouchFocusOut(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition,
144                                                                                                 const Tizen::Ui::TouchEventInfo& touchInfo) {}
145                 virtual void OnKeyPressed(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode);
146                 virtual void OnKeyReleased(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode);
147                 virtual void OnKeyLongPressed(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode) {}
148
149 private:
150                 _ControlHandle __buttonHandle;
151
152                 bool __buttonPressFlag;
153                 bool __buttonReleaseState;
154                 bool __beginModal;
155
156                 Tizen::Graphics::FloatPoint __point;
157
158         }; // class _MessageBoxButtonListener
159
160
161 private:
162         enum
163         {
164                 MSGBOX_BUTTON_CLICKED = 0xFF,
165                 MSGBOX_BUTTON_CLOSE,
166                 MSGBOX_BUTTON_CANCEL
167         };
168
169 // Attributes
170 private:
171         _MessageBox* __pMessageBox;
172         _MessageBoxButtonListener* __pButtonListener;
173         MessageBoxModalResult __msgboxResult;
174
175         static const int MSGBOX_MAX_BUTTON_NUM = 3;
176
177         Tizen::Ui::Controls::Button* __pButtons[MSGBOX_MAX_BUTTON_NUM];
178         Tizen::Base::String __buttonText[MSGBOX_MAX_BUTTON_NUM];
179
180         Tizen::Graphics::_Text::TextObject* __pBodyTextObject;
181
182         Tizen::Graphics::FloatRectangle __textBounds;
183         Tizen::Graphics::FloatRectangle __titleBgBounds;
184         Tizen::Graphics::FloatRectangle __buttonBgBounds;
185
186
187         Tizen::Ui::Controls::_Label* __pLabel;
188         Tizen::Ui::Controls::_Scroll* __pScroll;
189         Tizen::Ui::Controls::_ScrollPanel* __pScrollPanel;
190
191         float __scrollPos;
192         int __buttonNum;
193         float __prevPositionY;
194         float __textObjHeight;
195
196         bool __touchPressFlag;
197         bool __scrollStart;
198         bool __btnClickFlag;
199         bool __bodyClickFlag;
200         bool __touchOutBounds;
201         bool __beginModal;
202
203 }; // _MessageBoxPresenter
204
205
206 }}} // Tizen::Ui::Controls
207
208 #endif  // _FUI_CTRL_INTERNAL_MESSAGEBOX_PRESENTER_H_