2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.1 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file CustomPageMarker.cpp
19 * @brief Keeps implementation of the CustomPageMarker
20 * implements CustomPageMarker class, which contains the top bubble's bar which indicates the page number
25 #include <FGraphics.h>
27 #include <FUiAnimations.h>
28 #include "HmApplicationUtils.h"
29 #include "HmCustomPageMarker.h"
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Graphics;
35 using namespace Tizen::Ui;
36 using namespace Tizen::Ui::Animations;
37 using namespace Tizen::Ui::Controls;
39 CustomPageMarker::CustomPageMarker(void)
40 : __pMarkerListener(null)
43 , __pBubbleLabels(null)
44 , __pBubbleBitmaps(null)
46 //No implementation needed
49 CustomPageMarker::~CustomPageMarker(void)
51 if (__pBubbleLabels != null)
53 __pBubbleLabels->RemoveAll(false); //the controls will be deleted using removeControl calls by framework
54 delete __pBubbleLabels;
57 if (__pBubbleBitmaps != null)
59 __pBubbleBitmaps->RemoveAll(true);
60 delete __pBubbleBitmaps;
65 CustomPageMarker::Construct(const Rectangle& controlRect, int bubbleCount)
69 int yPos = Y_MARKER_POSITION;
72 Bitmap* pUnselectedBitmap = null;
73 Bitmap* pSelectedBitmap = null;
74 __bubbleCount = bubbleCount;
76 r = Panel::Construct(controlRect, GROUP_STYLE_NONE);
77 TryCatch(r == E_SUCCESS, , "Panel::Construct failed with error %s", GetErrorMessage(r));
79 __pBubbleLabels = new (std::nothrow) ArrayList();
80 r = __pBubbleLabels->Construct();
81 TryCatch(r == E_SUCCESS, , "__pLabels->Construct(); failed with error %s", GetErrorMessage(r));
83 __pBubbleBitmaps = new (std::nothrow) ArrayList();
84 r = __pBubbleBitmaps->Construct();
85 pUnselectedBitmap = ApplicationUtils::GetResourceBitmapN(IDB_BUBBLE_TOP);
87 if (pUnselectedBitmap != null)
89 __pBubbleBitmaps->Add(pUnselectedBitmap);
92 for (int bubbleCountTemp = 1; bubbleCountTemp <= __bubbleCount; bubbleCountTemp++)
94 String bubbleName(IDB_SELECTED_BUBBLE_TOP);
95 bubbleName.Append(bubbleCountTemp);
96 bubbleName.Append(BITMAP_EXTENSION);
97 pSelectedBitmap = ApplicationUtils::GetResourceBitmapN(bubbleName);
99 if (pSelectedBitmap != null)
101 __pBubbleBitmaps->Add(pSelectedBitmap);
105 width = (controlRect.width);
106 xFactor = width - ((W_MARKER_LABEL * __bubbleCount) + (X_MARKER_LABEL_OFFSET * (__bubbleCount - 1)));
110 for (int bubbleCount = 1; bubbleCount <= __bubbleCount; bubbleCount++)
112 Label* pLabel = new (std::nothrow) Label();
114 labelName.Append(bubbleCount);
118 Rectangle labelRect(xPos, yPos, W_MARKER_LABEL, H_MARKER_LABEL);
119 pLabel->Construct(labelRect, L"");
120 pLabel->SetBackgroundBitmap(*static_cast<Bitmap*>(__pBubbleBitmaps->GetAt(0)));
121 pLabel->SetTextColor(Color::GetColor(COLOR_ID_BLACK));
122 pLabel->SetTextHorizontalAlignment(ALIGNMENT_CENTER);
123 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
124 pLabel->SetName(labelName);
125 pLabel->AddTouchEventListener(*this);
127 __pBubbleLabels->Add(pLabel);
128 xPos += W_MARKER_LABEL + X_MARKER_LABEL_OFFSET;
136 if (__pBubbleLabels != null)
138 delete __pBubbleLabels;
139 __pBubbleLabels = null;
145 CustomPageMarker::AddBubble(void)
147 result r = E_SUCCESS;
148 Rectangle controlRect = GetBounds();
152 int yPos = Y_MARKER_POSITION;
153 Label* pLabel = null;
157 width = (controlRect.width);
158 xFactor = width - ((W_MARKER_LABEL * __bubbleCount) + (X_MARKER_LABEL_OFFSET * (__bubbleCount - 1)));
162 for (int bubbleCount = 1; bubbleCount < __bubbleCount; bubbleCount++)
165 labelName.Append(bubbleCount);
166 Label* pLabel = static_cast<Label*>(GetControl(labelName));
170 Rectangle labelRect(xPos, yPos, W_MARKER_LABEL, H_MARKER_LABEL);
171 pLabel->SetBounds(labelRect);
172 xPos += (X_MARKER_LABEL_OFFSET + W_MARKER_LABEL);
176 pLabel = new (std::nothrow) Label();
177 labelName.Append(__bubbleCount);
181 String bubbleName(IDB_SELECTED_BUBBLE_TOP);
182 Bitmap* pNewBubbleBitmap = null;
183 Rectangle labelRect(xPos, yPos, W_MARKER_LABEL, H_MARKER_LABEL);
184 pLabel->Construct(labelRect, L"");
185 bubbleName.Append(__bubbleCount);
186 bubbleName.Append(BITMAP_EXTENSION);
187 pNewBubbleBitmap = ApplicationUtils::GetResourceBitmapN(bubbleName);
189 if (pNewBubbleBitmap != null)
191 __pBubbleBitmaps->Add(pNewBubbleBitmap);
194 pLabel->SetBackgroundBitmap(*static_cast<Bitmap*>(__pBubbleBitmaps->GetAt(0)));
195 pLabel->SetTextColor(Color::GetColor(COLOR_ID_BLACK));
196 pLabel->SetTextHorizontalAlignment(ALIGNMENT_CENTER);
197 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
198 pLabel->SetName(labelName);
199 pLabel->AddTouchEventListener(*this);
200 r = AddControl(pLabel);
201 __pBubbleLabels->Add(pLabel);
202 xPos += (W_MARKER_LABEL + X_MARKER_LABEL_OFFSET);
208 CustomPageMarker::GetBubbleCount(void)
210 return __bubbleCount;
214 CustomPageMarker::RemoveBubble(int bubbleNo)
216 result r = E_SUCCESS;
217 Label* pLabel = static_cast<Label*>(__pBubbleLabels->GetAt(bubbleNo - 1));
221 RemoveControl(bubbleNo - 1);
222 __pBubbleLabels->RemoveAt(bubbleNo - 1, false);
223 __pBubbleBitmaps->RemoveAt(bubbleNo, true);
225 for (int bubbleCount = bubbleNo; bubbleCount < __bubbleCount; bubbleCount++)
227 Label* pLabel = static_cast<Label*>(GetControl(bubbleCount));
231 Point curPos = pLabel->GetPosition();
232 curPos.x -= (W_MARKER_LABEL + X_MARKER_LABEL_OFFSET);
233 pLabel->SetPosition(curPos);
244 CustomPageMarker::SetPageMarkerEventListener(ICustomPageMarkerEventListener* pListner)
246 __pMarkerListener = pListner;
251 CustomPageMarker::SetSelectedBubble(int bubbleNumber)
253 TryReturnVoid(bubbleNumber != __selectedBubble, "Passed page is already being shown");
255 controlName.Append(bubbleNumber);
256 Label* pLabel = null;
258 if (__selectedBubble != 0)
261 controlName.Append(__selectedBubble);
262 Label* pLabel = static_cast<Label*>(GetControl(controlName));
266 Bitmap* pBitmapToBeSet = null;
267 pLabel->SetText(L"");
269 pBitmapToBeSet = static_cast<Bitmap*>(__pBubbleBitmaps->GetAt(0));
271 if (pBitmapToBeSet != null)
273 pLabel->SetBackgroundBitmap(*pBitmapToBeSet);
275 pLabel->RequestRedraw(true);
276 __selectedBubble = bubbleNumber;
280 pLabel = static_cast<Label*>(GetControl(controlName));
284 Bitmap* pBitmapToBeSet = null;
285 pBitmapToBeSet = static_cast<Bitmap*>(__pBubbleBitmaps->GetAt(bubbleNumber));
287 if (pBitmapToBeSet != null)
289 pLabel->SetBackgroundBitmap(*pBitmapToBeSet);
292 pLabel->RequestRedraw(true);
293 __selectedBubble = bubbleNumber;
300 CustomPageMarker::OnTouchReleased(const Control& source, const Point& currentPosition, const TouchEventInfo& touchInfo)
302 if (__pMarkerListener != null)
304 String controlName = source.GetName();
306 if (!controlName.IsEmpty())
308 int bubbleNumber = 0;
309 Integer::Parse(controlName, bubbleNumber);
310 __pMarkerListener->OnMarkerBubbleMoved(bubbleNumber);