Fixed Nabi Issues N_SE-56966,56735
[apps/osp/Internet.git] / src / IntFormFactory.cpp
1 //
2
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.1 (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 //!Internet
19 /*@file:  IntFormFactory.cpp
20  *@brief: FormFactory class helps in creating appropriate forms with a specified form ID.
21  *        It Should be derived from Tizen::Ui::Scenes::IFormFactory class
22  */
23
24 #include "IntAddBookmarkForm.h"
25 #include "IntArticleReaderForm.h"
26 #include "IntBookmarkListForm.h"
27 #include "IntBrightnessForm.h"
28 #include "IntCommonLib.h"
29 #include "IntCreateBookmarkFolderForm.h"
30 #include "IntEditBookmarkListForm.h"
31 #include "IntEditHistoryListForm.h"
32 #include "IntEditHomePageForm.h"
33 #include "IntHistoryListForm.h"
34 #include "IntMainForm.h"
35 #include "IntMultipleWindowForm.h"
36 #include "IntReaderFontSizeForm.h"
37 #include "IntFormFactory.h"
38 #include "IntSettingForm.h"
39
40 using namespace Tizen::App;
41 using namespace Tizen::Base;
42 using namespace Tizen::Base::Collection;
43 using namespace Tizen::Ui;
44 using namespace Tizen::Ui::Controls;
45 using namespace Tizen::Ui::Scenes;
46
47 const wchar_t* IDL_FORM_MAIN_VIEW_SCENE = L"FormMainMenu";
48 const wchar_t* IDL_FORM_BOOKMARK_LIST_SCENE = L"BooKmarkList";
49 const wchar_t* IDL_FORM_HISTORY_LIST_SCENE = L"HistoryList";
50 const wchar_t* IDL_FORM_EDIT_HISTORY_LIST_SCENE = L"EditHistoryList";
51 const wchar_t* IDL_FORM_SETTINGS_CLEAR_PRIVATE_DATA_SCENE = L"SettingsClearPrivateData";
52 const wchar_t* IDL_FORM_MULTIPLE_WINDOW_SCENE = L"MultipleWindow";
53 const wchar_t* IDL_FORM_SETTINGS_SCENE = L"Settings";
54 const wchar_t* IDL_FORM_ADD_BOOKMARK_SCENE = L"AddBookmark";
55 const wchar_t* IDL_FORM_ARTICLE_READER_SCENE = L"ArticleReader";
56 const wchar_t* IDL_FORM_EDIT_BOOKMARK_LIST_SCENE = L"EditBookmarkList";
57 const wchar_t* IDL_FORM_FIND_WORD_SCENE = L"FindWord";
58 const wchar_t* IDL_FORM_CREATE_BOOKMARK_FOLDER_SCENE = L"CreateBookmarkFolder";
59 const wchar_t* IDL_FORM_FONT_SIZE_SCENE = L"FontSize";
60 const wchar_t* IDL_FORM_EDIT_HOME_PAGE_SCENE = L"EditHomePage";
61 const wchar_t* IDL_FORM_BRIGHTNESS_SCENE = L"Brightness";
62
63
64 FormFactory::FormFactory(void)
65 {
66
67 }
68
69 FormFactory::~FormFactory(void)
70 {
71
72 }
73
74 Form*
75 FormFactory::CreateFormN(const String& formId, const SceneId& sceneId)
76 {
77         AppLog("FormFactory createForm");
78
79         Tizen::Ui::Controls::Form* pNewForm = null;
80         SceneManager* pSceneManager = SceneManager::GetInstance();
81
82         if ( pSceneManager == null)
83         {
84                 return null;
85         }
86
87         if (formId.Contains(IDL_FORM_MAIN_VIEW_SCENE) == true)
88         {
89                 MainForm* pForm = new(std::nothrow) MainForm();
90                 if (pForm == null)
91                 {
92                         return null;
93                 }
94                 pForm->Initialize();
95                 pSceneManager->AddSceneEventListener(sceneId, *pForm);
96                 pNewForm = pForm;
97         }
98         else if (formId == IDL_FORM_BOOKMARK_LIST_SCENE)
99         {
100                 BookmarkListForm* pForm = new(std::nothrow) BookmarkListForm();
101                 if (pForm == null)
102                 {
103                         return null;
104                 }
105                 pForm->Initialize();
106                 pNewForm = pForm;
107         }
108         else if (formId == IDL_FORM_HISTORY_LIST_SCENE)
109         {
110                 HistoryListForm* pForm = new(std::nothrow) HistoryListForm();
111                 if (pForm == null)
112                 {
113                         return null;
114                 }
115                 pForm->Initialize();
116                 pNewForm = pForm;
117         }
118         else if (formId == IDL_FORM_EDIT_HISTORY_LIST_SCENE)
119         {
120                 EditHistoryListForm* pForm = new(std::nothrow) EditHistoryListForm();
121                 if (pForm == null)
122                 {
123                         return null;
124                 }
125                 pForm->Initialize();
126                 pNewForm = pForm;
127         }
128
129         else if (formId == IDL_FORM_MULTIPLE_WINDOW_SCENE)
130         {
131                 MultipleWindowForm* pForm = new(std::nothrow) MultipleWindowForm();
132                 if (pForm == null)
133                 {
134                         return null;
135                 }
136                 pForm->Initialize();
137                 pNewForm = pForm;
138         }
139         else if (formId == IDL_FORM_SETTINGS_SCENE)
140         {
141                 SettingForm* pForm = new(std::nothrow) SettingForm();
142                 if (pForm == null)
143                 {
144                         return null;
145                 }
146                 pForm->Initialize();
147                 pNewForm = pForm;
148         }
149         else if (formId == IDL_FORM_ADD_BOOKMARK_SCENE)
150         {
151                 AddBookmarkForm* pForm = new(std::nothrow) AddBookmarkForm();
152                 if (pForm == null)
153                 {
154                         return null;
155                 }
156                 pForm->Initialize();
157                 pNewForm = pForm;
158         }
159         else if (formId == IDL_FORM_ARTICLE_READER_SCENE)
160         {
161                 ArticleReaderForm* pForm = new(std::nothrow) ArticleReaderForm();
162                 if (pForm == null)
163                 {
164                         return null;
165                 }
166                 pForm->Initialize();
167                 pNewForm = pForm;
168         }
169         else if (formId == IDL_FORM_EDIT_BOOKMARK_LIST_SCENE)
170         {
171                 EditBookmarkListForm* pForm = new(std::nothrow) EditBookmarkListForm();
172                 if (pForm == null)
173                 {
174                         return null;
175                 }
176                 pForm->Initialize();
177                 pNewForm = pForm;
178         }
179
180         else if (formId == IDL_FORM_CREATE_BOOKMARK_FOLDER_SCENE)
181         {
182                 CreateBookmarkFolderForm* pForm = new(std::nothrow) CreateBookmarkFolderForm();
183                 if (pForm == null)
184                 {
185                         return null;
186                 }
187                 pForm->Initialize();
188                 pNewForm = pForm;
189         }
190
191         else if (formId == IDL_FORM_FONT_SIZE_SCENE)
192         {
193                 ReaderFontSizeForm* pForm = new(std::nothrow) ReaderFontSizeForm();
194                 if (pForm == null)
195                 {
196                         return null;
197                 }
198                 pForm->Initialize();
199                 pNewForm = pForm;
200         }
201         else if (formId == IDL_FORM_EDIT_HOME_PAGE_SCENE)
202         {
203                 EditHomePageForm* pForm = new(std::nothrow) EditHomePageForm();
204                 if (pForm == null)
205                 {
206                         return null;
207                 }
208                 pForm->Initialize();
209                 pNewForm = pForm;
210         }
211         else if (formId == IDL_FORM_BRIGHTNESS_SCENE)
212         {
213                 BrightnessForm* pForm = new(std::nothrow) BrightnessForm();
214                 if (pForm == null)
215                 {
216                         return null;
217                 }
218                 pForm->Initialize();
219                 pNewForm = pForm;
220         }
221         AppLogDebug("FormFactory createForm exit");
222 //      pSceneManager->AddSceneEventListener(sceneId, *this);
223         return pNewForm;
224 }
225
226
227 void
228 FormFactory::SetFontSize(Container& container, int font)
229 {
230         IList* pControls = container.GetControls();
231         if(pControls == null)
232         {
233                 return;
234         }
235         for(int count = 0; count < pControls->GetCount(); count++)
236         {
237                 //Check if the control is again an container
238                 Container *pContainer = dynamic_cast<Container*>(pControls->GetAt(count));
239                 if(pContainer != null)
240                 {
241                         SetFontSize(*pContainer, font);
242                 }
243                 else //Check if it is a button
244                 {
245                         Button *pButton = dynamic_cast<Button*>(pControls->GetAt(count));
246                         if(pButton != null)
247                         {
248                                 pButton->SetTextSize(font);
249                         }
250                         else //Check if a label
251                         {
252                                 Label *pLabel = dynamic_cast<Label*>(pControls->GetAt(count));
253                                 if(pLabel != null)
254                                 {
255                                         pLabel->SetTextConfig(font, pLabel->GetTextStyle());
256                                 }
257                                 else //Check if a EditField
258                                 {
259                                         EditField *pEditField = dynamic_cast<EditField*>(pControls->GetAt(count));
260                                         if(pEditField != null)
261                                         {
262                                                 pEditField->SetTextSize(font);
263                                         }
264                                         else //Check if a EditArea
265                                         {
266                                                 EditArea *pEditArea = dynamic_cast<EditArea*>(pControls->GetAt(count));
267                                                 if(pEditArea != null)
268                                                 {
269                                                         pEditArea->SetTextSize(font);
270                                                 }
271                                                 else //Check if a ExpandableEditArea
272                                                 {
273                                                         ExpandableEditArea *pExpandableEditArea = dynamic_cast<ExpandableEditArea*>(pControls->GetAt(count));
274                                                         if(pExpandableEditArea != null)
275                                                         {
276                                                                 pExpandableEditArea->SetTextSize(font);
277                                                         }
278                                                         else //Check if a TextBox
279                                                         {
280                                                                 TextBox *pTextBox = dynamic_cast<TextBox*>(pControls->GetAt(count));
281                                                                 if(pTextBox != null)
282                                                                 {
283                                                                         pTextBox->SetTextSize(font);
284                                                                 }
285                                                                 else //Check if a SearchBar
286                                                                 {
287                                                                         SearchBar *pSearchBar = dynamic_cast<SearchBar*>(pControls->GetAt(count));
288                                                                         if(pSearchBar != null)
289                                                                         {
290                                                                                 pSearchBar->SetSearchFieldTextSize(font);
291                                                                         }
292                                                                         else //Check if a List
293                                                                         {
294
295                                                                         }
296                                                                 }
297                                                         }
298                                                 }
299                                         }
300                                 }
301                         }
302                 }
303         }
304 }
305
306 void
307 FormFactory::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
308 {
309         AppLog("FormFactory::OnSceneActivatedN");
310         Form *pForm = UiApp::GetInstance()->GetFrameAt(0)->GetCurrentForm();
311
312         if(pForm != null)
313         {
314                 String fontSizeStr = "";
315                 int fontSize = CommonUtil::GetFontSize();
316                 AppLog("Font sizeStr: %ls, fontsize:%d", fontSizeStr.GetPointer(), fontSize);
317                 SetFontSize(*pForm, fontSize);
318                 pForm->Invalidate(true);
319         }
320 }