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 FUiCtrl_SplitPanelImpl.cpp
20 * @brief This is the implementation file for the _SplitPanelImpl class.
23 #include <FBaseInternalTypes.h>
24 #include <FApp_AppInfo.h>
25 #include <FBaseSysLog.h>
26 #include <FBase_LocalizedNumParser.h>
27 #include <FUiCtrlPanel.h>
28 #include <FUiCtrlScrollPanel.h>
29 #include <FUiCtrlForm.h>
30 #include "FUiCtrl_SplitPanelImpl.h"
31 #include "FUiCtrl_SplitPanel.h"
32 #include "FUi_UiBuilder.h"
33 #include "FUi_CoordinateSystemUtils.h"
35 using namespace Tizen::Base;
36 using namespace Tizen::Ui;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Base::Runtime;
39 using namespace Tizen::App;
41 namespace Tizen { namespace Ui { namespace Controls
45 _SplitPanelImpl::GetInstance(SplitPanel& pSplitPanel)
47 return static_cast<_SplitPanelImpl*> (pSplitPanel._pControlImpl);
50 const _SplitPanelImpl*
51 _SplitPanelImpl::GetInstance(const SplitPanel& pSplitPanel)
53 return static_cast<const _SplitPanelImpl*> (pSplitPanel._pControlImpl);
56 _SplitPanelImpl::_SplitPanelImpl(SplitPanel* pPublic, _SplitPanel* pCore)
57 : _ControlImpl(pPublic, pCore)
58 , __pSplitPanel(pCore)
59 , __pPublicSplitPanelEvent(null)
64 _SplitPanelImpl::~_SplitPanelImpl(void)
66 __pSplitPanel->RemoveSplitPanelEventListener(*this);
68 if(__pPublicSplitPanelEvent)
70 delete __pPublicSplitPanelEvent;
71 __pPublicSplitPanelEvent = null;
78 _SplitPanelImpl::CreateSplitPanelImplN(SplitPanel* pControl, const Rectangle& rect, SplitPanelDividerStyle splitPanelDividerStyle, SplitPanelDividerDirection splitPanelDividerDirection)
83 FloatRectangle rectF = _CoordinateSystemUtils::ConvertToFloat(rect);
85 _SplitPanel* pCore = _SplitPanel::CreateSplitPanelN(rectF, splitPanelDividerStyle, splitPanelDividerDirection);
86 SysTryReturn(NID_UI_CTRL, pCore != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
88 _SplitPanelImpl* pImpl = new (std::nothrow) _SplitPanelImpl(pControl, pCore);
89 r = _ControlImpl::CheckConstruction(pCore, pImpl);
90 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
96 _SplitPanelImpl::CreateSplitPanelImplFN(SplitPanel* pControl, const FloatRectangle& rect, SplitPanelDividerStyle splitPanelDividerStyle, SplitPanelDividerDirection splitPanelDividerDirection)
101 _SplitPanel* pCore = _SplitPanel::CreateSplitPanelN(rect, splitPanelDividerStyle, splitPanelDividerDirection);
102 SysTryReturn(NID_UI_CTRL, pCore != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
104 _SplitPanelImpl* pImpl = new (std::nothrow) _SplitPanelImpl(pControl, pCore);
105 r = _ControlImpl::CheckConstruction(pCore, pImpl);
106 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
112 _SplitPanelImpl::Initialize(const Rectangle& rect)
115 result r = E_SUCCESS;
117 FloatRectangle rectF = _CoordinateSystemUtils::ConvertToFloat(rect);
119 r = SetBounds(rectF);
120 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
122 __pPublicSplitPanelEvent = _PublicSplitPanelEvent::CreateInstanceN(GetPublic());
123 SysTryReturn(NID_UI_CTRL, __pPublicSplitPanelEvent, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
125 r = GetCore().AddSplitPanelEventListener(*this);
126 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
132 _SplitPanelImpl::InitializeF(const FloatRectangle& rect)
135 result r = E_SUCCESS;
138 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
140 __pPublicSplitPanelEvent = _PublicSplitPanelEvent::CreateInstanceN(GetPublic());
141 SysTryReturn(NID_UI_CTRL, __pPublicSplitPanelEvent, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
143 r = GetCore().AddSplitPanelEventListener(*this);
144 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
150 _SplitPanelImpl::GetPublicClassName(void) const
152 return "Tizen::Ui::Controls::SplitPanel";
156 _SplitPanelImpl::GetPublic(void) const
158 return static_cast <const SplitPanel&>(_ControlImpl::GetPublic());
162 _SplitPanelImpl::GetPublic(void)
164 return static_cast <SplitPanel&>(_ControlImpl::GetPublic());
168 _SplitPanelImpl::GetCore(void) const
170 return static_cast <const _SplitPanel&>(_ControlImpl::GetCore());
174 _SplitPanelImpl::GetCore(void)
176 return static_cast <_SplitPanel&>(_ControlImpl::GetCore());
180 _SplitPanelImpl::OnDividerPositionChanged(_SplitPanel& source, int position)
184 if (__pPublicSplitPanelEvent != null)
186 IEventArg* pEventArg = _PublicSplitPanelEvent::CreateSplitPanelEventArgN(SPLIT_PANEL_EVENT_DIVIDER_POSITION_CHANGE);
187 SysTryReturnVoidResult(NID_UI_CTRL, pEventArg, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
188 __pPublicSplitPanelEvent->Fire(*pEventArg);
193 _SplitPanelImpl::OnDividerDoublePressed(_SplitPanel& source)
197 if (__pPublicSplitPanelEvent != null)
199 IEventArg* pEventArg = _PublicSplitPanelEvent::CreateSplitPanelEventArgN(SPLIT_PANEL_EVENT_DIVIDER_DOUBLE_PRESSED);
200 SysTryReturnVoidResult(NID_UI_CTRL, pEventArg, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
201 __pPublicSplitPanelEvent->Fire(*pEventArg);
206 _SplitPanelImpl::AddSplitPanelEventListener(ISplitPanelEventListener& listener)
208 return __pPublicSplitPanelEvent->AddListener(listener);
212 _SplitPanelImpl::AddSplitPanelEventListener(ISplitPanelEventListenerF& listener)
214 return __pPublicSplitPanelEvent->AddListener(listener);
218 _SplitPanelImpl::RemoveSplitPanelEventListener(ISplitPanelEventListener& listener)
220 return __pPublicSplitPanelEvent->RemoveListener(listener);
224 _SplitPanelImpl::RemoveSplitPanelEventListener(ISplitPanelEventListenerF& listener)
226 return __pPublicSplitPanelEvent->RemoveListener(listener);
230 _SplitPanelImpl::SetPane(_ControlImpl* pControl, SplitPanelPaneOrder paneOrder)
232 result r = E_SUCCESS;
234 if (pControl == null)
236 r = GetCore().SetPane(null, paneOrder);
240 r = GetCore().SetPane(&(pControl->GetCore()), paneOrder);
243 SetLastResultReturn(r);
247 _SplitPanelImpl::GetPane(SplitPanelPaneOrder paneOrder) const
249 _Control* pControl = GetCore().GetPane(paneOrder);
250 if (pControl == null)
255 return static_cast<_ControlImpl*>(pControl->GetUserData());
259 _SplitPanelImpl::SetDividerPosition(int position)
261 float floatPosition = _CoordinateSystemUtils::ConvertToFloat(position);
262 result r = GetCore().SetDividerPosition(floatPosition);
263 SetLastResultReturn(r);
267 _SplitPanelImpl::SetDividerPosition(float position)
269 result r = GetCore().SetDividerPosition(position);
270 SetLastResultReturn(r);
274 _SplitPanelImpl::GetDividerPosition(void) const
277 int position = _CoordinateSystemUtils::ConvertToInteger(GetCore().GetDividerPosition());
282 _SplitPanelImpl::GetDividerPositionF(void) const
285 return GetCore().GetDividerPosition();
289 _SplitPanelImpl::SetMaximumDividerPosition(int position)
291 float floatPosition = _CoordinateSystemUtils::ConvertToFloat(position);
292 result r = GetCore().SetMaximumDividerPosition(floatPosition);
293 SetLastResultReturn(r);
297 _SplitPanelImpl::SetMaximumDividerPosition(float position)
299 result r = GetCore().SetMaximumDividerPosition(position);
300 SetLastResultReturn(r);
304 _SplitPanelImpl::GetMaximumDividerPosition(void) const
307 int maxPosition = _CoordinateSystemUtils::ConvertToInteger(GetCore().GetMaximumDividerPosition());
312 _SplitPanelImpl::GetMaximumDividerPositionF(void) const
315 return GetCore().GetMaximumDividerPosition();
319 _SplitPanelImpl::SetMinimumDividerPosition(int position)
321 int floatPosition = _CoordinateSystemUtils::ConvertToFloat(position);
322 result r = GetCore().SetMinimumDividerPosition(floatPosition);
323 SetLastResultReturn(r);
327 _SplitPanelImpl::SetMinimumDividerPosition(float position)
329 result r = GetCore().SetMinimumDividerPosition(position);
330 SetLastResultReturn(r);
334 _SplitPanelImpl::GetMinimumDividerPosition(void) const
337 int minPosition = _CoordinateSystemUtils::ConvertToInteger(GetCore().GetMinimumDividerPosition());
342 _SplitPanelImpl::GetMinimumDividerPositionF(void) const
345 return GetCore().GetMinimumDividerPosition();
349 _SplitPanelImpl::MaximizePane(SplitPanelPaneOrder paneOrder)
351 result r = GetCore().MaximizePane(paneOrder);
352 SetLastResultReturn(r);
356 _SplitPanelImpl::IsPaneMaximized(SplitPanelPaneOrder paneOrder) const
359 return GetCore().IsPaneMaximized(paneOrder);
363 _SplitPanelImpl::RestorePane(void)
365 result r = GetCore().RestorePane();
366 SetLastResultReturn(r);
369 class _SplitPanelMaker
370 : public _UiBuilderControlMaker
373 _SplitPanelMaker(_UiBuilder* uibuilder)
374 : _UiBuilderControlMaker(uibuilder)
376 __pTransform = uibuilder->GetTransformer();
378 virtual ~_SplitPanelMaker(void){};
379 static _UiBuilderControlMaker*
380 GetInstance(_UiBuilder* uibuilder)
382 _SplitPanelMaker* pSplitPanelMaker = new (std::nothrow) _SplitPanelMaker(uibuilder);
384 return pSplitPanelMaker;
389 Make(_UiBuilderControl* pControl)
392 _UiBuilderControlLayout* pControlProperty = null;
393 SplitPanel* pSplitPanel = null;
394 Tizen::Graphics::FloatRectangle rect;
395 Tizen::Base::String elementString;
396 Tizen::Base::String xmlLink;
397 float minDividerPosition = 0.0f;
398 float maxDividerPosition = 0.0f;
399 float dividerPosition = 0.0f;
400 float originalValue = 0.0f;
402 SplitPanelDividerStyle splitPanelDividerStyle = SPLIT_PANEL_DIVIDER_STYLE_MOVABLE;
403 SplitPanelDividerDirection splitPanelDividerDirection = SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL;
405 GetProperty(pControl, &pControlProperty);
407 if (pControlProperty == null)
412 pSplitPanel = new (std::nothrow) SplitPanel();
413 SysTryReturn(NID_UI_CTRL, pSplitPanel, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
415 rect = pControlProperty->GetRectF();
418 if (pControl->GetElement("dividerStyle", elementString) || pControl->GetElement("DividerStyle", elementString))
420 if (elementString.Equals(L"SPLIT_PANEL_DIVIDER_STYLE_FIXED", false))
422 splitPanelDividerStyle = SPLIT_PANEL_DIVIDER_STYLE_FIXED;
424 if (elementString.Equals(L"SPLIT_PANEL_DIVIDER_STYLE_MOVABLE", false))
426 splitPanelDividerStyle = SPLIT_PANEL_DIVIDER_STYLE_MOVABLE;
430 if (pControl->GetElement("dividerDirection", elementString) || pControl->GetElement("DividerDirection", elementString))
432 if (elementString.Equals(L"SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL", false))
434 splitPanelDividerDirection = SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL;
436 if (elementString.Equals(L"SPLIT_PANEL_DIVIDER_DIRECTION_HORIZONTAL", false))
438 splitPanelDividerDirection = SPLIT_PANEL_DIVIDER_DIRECTION_HORIZONTAL;
443 r = pSplitPanel->Construct(rect, splitPanelDividerStyle, splitPanelDividerDirection);
447 SysLog(NID_UI_CTRL, "Failed to create SplitPanel.");
454 if (pControl->GetElement("minDividerPosition", elementString))
456 minDividerPosition = _LocalizedNumParser::ToDouble(elementString, "C");
458 if (__pTransform != null)
460 originalValue = minDividerPosition;
461 minDividerPosition = __pTransform->Transform(originalValue);
464 pSplitPanel->SetMinimumDividerPosition(minDividerPosition);
467 if (pControl->GetElement("maxDividerPosition", elementString))
469 maxDividerPosition = _LocalizedNumParser::ToDouble(elementString, "C");
471 if (__pTransform != null)
473 originalValue = maxDividerPosition;
474 maxDividerPosition = __pTransform->Transform(originalValue);
477 pSplitPanel->SetMaximumDividerPosition(maxDividerPosition);
480 if (pControl->GetElement("dividerPosition", elementString))
482 dividerPosition = _LocalizedNumParser::ToDouble(elementString, "C");
484 if (__pTransform != null)
486 originalValue = dividerPosition;
487 dividerPosition = __pTransform->Transform(originalValue);
490 pSplitPanel->SetDividerPosition(dividerPosition);
494 if (pControl->GetElement("firstPane", elementString))
496 if (pControl->GetElement("firstPaneXmlLink", xmlLink))
498 if (elementString.Equals(L"panel", false))
500 Panel* pFirstPanel = new (std::nothrow) Panel();
501 pFirstPanel->Construct(xmlLink);
502 pSplitPanel->SetPane(pFirstPanel, SPLIT_PANEL_PANE_ORDER_FIRST);
504 else if (elementString.Equals(L"form", false))
506 Form* pFirstForm = new (std::nothrow) Form();
507 pFirstForm->Construct(xmlLink);
508 pSplitPanel->SetPane(pFirstForm, SPLIT_PANEL_PANE_ORDER_FIRST);
510 else if (elementString.Equals(L"scrollpanel", false))
512 ScrollPanel* pFirstScrollPanel = new (std::nothrow) ScrollPanel();
513 pFirstScrollPanel->Construct(xmlLink);
514 pSplitPanel->SetPane(pFirstScrollPanel, SPLIT_PANEL_PANE_ORDER_FIRST);
519 if (pControl->GetElement("secondPane", elementString))
521 if (pControl->GetElement("secondPaneXmlLink", xmlLink))
523 if (elementString.Equals(L"panel", false))
525 Panel* pFirstPanel = new (std::nothrow) Panel();
526 pFirstPanel->Construct(xmlLink);
527 pSplitPanel->SetPane(pFirstPanel, SPLIT_PANEL_PANE_ORDER_SECOND);
529 else if (elementString.Equals(L"form", false))
531 Form* pFirstForm = new (std::nothrow) Form();
532 pFirstForm->Construct(xmlLink);
533 pSplitPanel->SetPane(pFirstForm, SPLIT_PANEL_PANE_ORDER_SECOND);
535 else if (elementString.Equals(L"scrollpanel", false))
537 ScrollPanel* pFirstScrollPanel = new (std::nothrow) ScrollPanel();
538 pFirstScrollPanel->Construct(xmlLink);
539 pSplitPanel->SetPane(pFirstScrollPanel, SPLIT_PANEL_PANE_ORDER_SECOND);
547 _ICoordinateSystemTransformer* __pTransform;
548 }; // _SplitPanelMaker
550 _SplitPanelRegister::_SplitPanelRegister(void)
552 _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
553 pUiBuilderControlTableManager->RegisterControl(L"SplitPanel", _SplitPanelMaker::GetInstance);
555 _SplitPanelRegister::~_SplitPanelRegister(void)
557 _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
558 pUiBuilderControlTableManager->UnregisterControl(L"SplitPanel");
560 static _SplitPanelRegister SplitPanelRegisterToUIbuilder;
561 }}} // Tizen::Ui::Controls