1.Fixed the order of control deletion
[apps/osp/Call.git] / src / CallButtonsPanel.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 /**
18  * @file        CallButtonsPanel.cpp
19  * @brief       Base class for all Call forms
20  */
21 #include "CallButtonsPanel.h"
22 #include "CallAppUtility.h"
23 #include "CallTypes.h"
24
25 using namespace Tizen::App;
26 using namespace Tizen::Base;
27 using namespace Tizen::Ui;
28 using namespace Tizen::Ui::Controls;
29 using namespace Tizen::Graphics;
30
31 //Constants - Scene name
32 const wchar_t* IDC_ADDJOINCALL_BUTTON = L"IDC_ADDJOINCALL_BUTTON";
33 const wchar_t* IDC_KEYPAD_BUTTON = L"IDC_KEYPAD_BUTTON";
34 const wchar_t* IDC_MUTE_BUTTON = L"IDC_MUTE_BUTTON";
35 const wchar_t* IDC_CONTACT_BUTTON = L"IDC_CONTACT_BUTTON";
36 const wchar_t* IDC_SPEAKER_BUTTON = L"IDC_SPEAKER_BUTTON";
37 const wchar_t* IDC_VOICECALL_BUTTON = L"IDC_VOICECALL_BUTTON";
38 const wchar_t* IDC_VIDEOCALL_BUTTON = L"IDC_VIDEOCALL_BUTTON";
39 const wchar_t* IDC_MSG_BUTTON = L"IDC_MSG_BUTTON";
40 const wchar_t* IDC_ENDCALL_BUTTON = L"IDC_ENDCALL_BUTTON";
41 const wchar_t* IDC_ADD_TO_CONTACT_BUTTON = L"IDC_ADD_TO_CONTACT_BUTTON";
42
43 //Button Dimensions
44 const int W_BG_BITMAP = 80;
45 const int H_BG_BITMAP = 80;
46 const int Y_BG_BITMAP_POS = 56;
47 const int IDI_TEXT_SIZE = 38;
48 const int IDI_VERTICAL_SPACE = 6;
49 const int W_VIEW_CONTACT_BITMAP = 50;
50 const int H__VIEW_CONTACT_BITMAP = 50;
51 const int Y_VIEW_CONTACT_BITMAP_POS = 14;
52 const int W_KEYPAD_BTN = 240;
53 const int H_KEYPAD_BTN = 250;
54
55 CallButtonsPanel::CallButtonsPanel(void)
56 {
57 }
58
59 CallButtonsPanel::~CallButtonsPanel(void)
60 {
61         //Empty Implementation
62 }
63
64 bool
65 CallButtonsPanel::ConstructPanel(IActionEventListener* pEventListener, FormType parentFormType)
66 {
67         if (pEventListener == null)
68         {
69                 return false;
70         }
71
72         result r = E_SUCCESS;
73
74         //set action listener & save form state
75         __pActionListener = pEventListener;
76         __parentFormType = parentFormType;
77
78         switch (__parentFormType)
79         {
80         case FORMTYPE_ENDCALL:
81                 r = Construct(IDL_END_CALL_PANEL);
82                 break;
83
84         default:
85                 r = Construct(IDL_CALL_PANEL);
86                 break;
87         }
88         TryCatch(r == E_SUCCESS, , "CallButtonsPanel::Initialise() resource not found");
89
90         return true;
91 CATCH:
92         return false;
93 }
94
95 result
96 CallButtonsPanel::OnInitializing(void)
97 {
98         result r = E_FAILURE;
99
100         RelativeLayout* pRelativeLayout = dynamic_cast<RelativeLayout*>(GetParent()->GetLandscapeLayoutN());
101         if (pRelativeLayout != null)
102         {
103                 pRelativeLayout->Update();
104                 delete pRelativeLayout;
105         }
106
107         pRelativeLayout = dynamic_cast<RelativeLayout*>(GetParent()->GetPortraitLayoutN());
108         if (pRelativeLayout != null)
109         {
110                 pRelativeLayout->Update();
111                 delete pRelativeLayout;
112         }
113
114         //set buttons as child controls
115         switch (__parentFormType)
116         {
117         case FORMTYPE_ENDCALL:
118                 r = ConstructEndCallPanel();
119                 break;
120
121         default:
122                 r = ConstructActiveCallPanel();
123                 break;
124         }
125
126         if (IsFailed(r))
127         {
128                 return r;
129         }
130         SetButtonPosition();
131         Draw();
132         Show();
133         return r;
134 }
135
136 result
137 CallButtonsPanel::OnTerminating(void)
138 {
139         //remove all child controls...
140 //      RemoveAllControls();
141         return E_SUCCESS;
142 }
143
144 void
145 CallButtonsPanel::SetSpeakerButtonState(CommandIds cmdId)
146 {
147         //Speaker
148         String speakerButtonId(IDC_SPEAKER_BUTTON);
149         Button* pButton = static_cast<Button*>(GetControl(speakerButtonId));
150         //Check if Button exist and needs to change state.
151         if(pButton == null || pButton->GetActionId() == cmdId)
152         {
153                 return;
154         }
155
156         String btnName = AppUtility::GetResourceString(IDS_SPEAKER_BTN_NAME);
157         AddKeyPadActionListener(speakerButtonId, cmdId);
158         switch (cmdId)
159         {
160                 case IDA_SPEAKER:
161                 {
162                         SetBitmapsToButton(speakerButtonId, btnName, IDB_SPEAKER_OFF_ICON, BTN_NORMAL);
163                         SetBitmapsToButton(speakerButtonId, btnName, IDB_SPEAKER_OFF_PRESS_ICON, BTN_PRESS);
164                         SetBitmapsToButton(speakerButtonId, btnName, IDB_SPEAKER_OFF_DIM_ICON, BTN_DIM);
165                 }
166                 break;
167
168                 case IDA_SPEAKER_OFF:
169                 {
170                         SetBitmapsToButton(speakerButtonId, btnName, IDB_SPEAKER_ON_ICON, BTN_NORMAL);
171                         SetBitmapsToButton(speakerButtonId, btnName, IDB_SPEAKER_ON_PRESS_ICON, BTN_PRESS);
172                         SetBitmapsToButton(speakerButtonId, btnName, IDB_SPEAKER_ON_DIM_ICON, BTN_DIM);
173                 }
174                 break;
175
176                 default:
177                 break;
178         }
179 }
180
181 void
182 CallButtonsPanel::SetMuteButtonState(CommandIds cmdId)
183 {
184         String muteButtonId(IDC_MUTE_BUTTON);
185         Button* pButton = static_cast<Button*>(GetControl(muteButtonId));
186         //Check if Button exist and needs to change state.
187         if(pButton == null || pButton->GetActionId() == cmdId)
188         {
189                 return;
190         }
191
192         String btnName = AppUtility::GetResourceString(IDS_MUTE_BTN_NAME);
193         AddKeyPadActionListener(muteButtonId, cmdId);
194         switch(cmdId)
195         {
196                 case IDA_UNMUTE:
197                 {
198                         SetBitmapsToButton(muteButtonId, btnName, IDB_MUTE_ON_ICON, BTN_NORMAL);
199                         SetBitmapsToButton(muteButtonId, btnName, IDB_MUTE_ON_PRESS_ICON, BTN_PRESS);
200                         SetBitmapsToButton(muteButtonId, btnName, IDB_MUTE_ON_DIM_ICON, BTN_DIM);
201                 }
202                 break;
203
204                 case IDA_MUTE:
205                 {
206                         SetBitmapsToButton(muteButtonId, btnName, IDB_MUTE_OFF_ICON, BTN_NORMAL);
207                         SetBitmapsToButton(muteButtonId, btnName, IDB_MUTE_OFF_PRESS_ICON, BTN_PRESS);
208                         SetBitmapsToButton(muteButtonId, btnName, IDB_MUTE_OFF_DIM_ICON, BTN_DIM);
209                 }
210                 break;
211
212                 default:
213                 break;
214         }
215 }
216
217 void
218 CallButtonsPanel::SetKeypadButtonState(CommandIds cmdId)
219 {
220         String keypadButtonId(IDC_KEYPAD_BUTTON);
221         Button* pButton = static_cast<Button*>(GetControl(keypadButtonId));
222         //Check if Button exist and needs to change state.
223         if(pButton == null || pButton->GetActionId() == cmdId)
224         {
225                 return;
226         }
227
228         String btnName = AppUtility::GetResourceString(IDS_KEYPAD_BTN_NAME);
229         AddKeyPadActionListener(keypadButtonId, cmdId);
230         switch (cmdId)
231         {
232         case IDA_CLOSE_NUMKEYPAD:
233         {
234                 SetBitmapsToButton(keypadButtonId, btnName, IDB_CLOSE_KEYPAD_ICON, BTN_NORMAL);
235                 SetBitmapsToButton(keypadButtonId, btnName, IDB_CLOSE_KEYPAD_PRESS_ICON, BTN_PRESS);
236                 SetBitmapsToButton(keypadButtonId, btnName, IDB_CLOSE_KEYPAD_DIM_ICON, BTN_DIM);
237         }
238         break;
239
240         case IDA_OPEN_NUMKEYPAD:
241         {
242                 SetBitmapsToButton(keypadButtonId, btnName, IDB_CLOSE_KEYPAD_ICON, BTN_NORMAL);
243                 SetBitmapsToButton(keypadButtonId, btnName, IDB_CLOSE_KEYPAD_PRESS_ICON, BTN_PRESS);
244                 SetBitmapsToButton(keypadButtonId, btnName, IDB_CLOSE_KEYPAD_DIM_ICON, BTN_DIM);
245         }
246         break;
247
248         default:
249         break;
250         }
251 }
252
253 result
254 CallButtonsPanel::AddBackgroundBitmap(void)
255 {
256         result r = E_FAILURE;
257
258         Rectangle panelRect = GetBounds();
259         //Set BackGround bitmap
260         Bitmap* pBgBitmap = null;
261         AppResource* pAppResource = AppResource::GetInstance();
262         if (pAppResource)
263         {
264                 pBgBitmap = pAppResource->GetBitmapN(IDB_BACKGROUND_BITMAP);
265                 if (pBgBitmap)
266                 {
267                         Label* pBackgroundLabel = new (std::nothrow) Label();
268                         pBackgroundLabel->Construct(Rectangle(0, 1, panelRect.width, panelRect.height), L"");
269                         pBackgroundLabel->SetBackgroundBitmap(*pBgBitmap);
270                         r = AddControl(*pBackgroundLabel);
271
272                         //always display in background
273                         SetControlAlwaysAtBottom(*pBackgroundLabel, true);
274
275                         delete pBgBitmap;
276                         pBgBitmap = null;
277                 }
278         }
279         return r;
280 }
281
282 result
283 CallButtonsPanel::ConstructEndCallPanel(void)
284 {
285         result r = E_SUCCESS;
286         Rectangle relativeCtrlRect = GetBounds();
287
288         //Voice Call
289         String voiceButtonId(IDC_VOICECALL_BUTTON);
290         String btnName = AppUtility::GetResourceString(IDS_VOICE_CALL_BTN_NAME);
291         SetBitmapsToButton(voiceButtonId, btnName, IDB_VOICE_CALL_ICON, BTN_NORMAL);
292         SetBitmapsToButton(voiceButtonId, btnName, IDB_VOICE_CALL_PRESS_ICON, BTN_PRESS);
293         SetBitmapsToButton(voiceButtonId, btnName, IDB_VOICE_CALL_DIM_ICON, BTN_DIM);
294         AddKeyPadActionListener(voiceButtonId, IDA_VOICE_CALL);
295
296         //Video Call
297         String videoButtonId(IDC_VIDEOCALL_BUTTON);
298         btnName = AppUtility::GetResourceString(IDS_VIDEO_CALL_BTN_NAME);
299         SetBitmapsToButton(videoButtonId, btnName, IDB_VIDEO_CALL_ICON, BTN_NORMAL);
300         SetBitmapsToButton(videoButtonId, btnName, IDB_VIDEO_CALL_PRESS_ICON, BTN_PRESS);
301         SetBitmapsToButton(videoButtonId, btnName, IDB_VIDEO_CALL_DIM_ICON, BTN_DIM);
302         AddKeyPadActionListener(videoButtonId, IDA_VIDEO_CALL);
303
304         //Message
305         String msgButtonId(IDC_MSG_BUTTON);
306         btnName = AppUtility::GetResourceString(IDS_MSG_BTN_NAME);
307         SetBitmapsToButton(msgButtonId, btnName, IDB_MESSAGE_ICON, BTN_NORMAL);
308         SetBitmapsToButton(msgButtonId, btnName, IDB_MESSAGE_PRESS_ICON, BTN_PRESS);
309         SetBitmapsToButton(msgButtonId, btnName, IDB_MESSAGE_DIM_ICON, BTN_DIM);
310         AddKeyPadActionListener(msgButtonId, IDA_MESSAGE);
311
312         Button* pButton = static_cast<Button*>(GetControl(IDC_ADD_TO_CONTACT_BUTTON));
313         if (pButton != null)
314         {
315                 AddKeyPadActionListener(IDC_ADD_TO_CONTACT_BUTTON,IDA_ADD_TO_CONTACTS);
316         }
317         //set initial show state to false. Correct state set on OnSceneActivatedN
318         SetViewContactButtonStatus(false);
319
320         return r;
321 }
322
323 void
324 CallButtonsPanel::SetViewContactButtonStatus(bool isAddToContactPresent)
325 {
326
327         //Present show View Contact else show Add to contact
328         if(isAddToContactPresent == false)
329         {
330                 SetViewContacBitmapToButton(IDC_ADD_TO_CONTACT_BUTTON,AppUtility::GetResourceString(IDS_VIEW_CONTACT),
331                                 IDB_VIEW_CONTACT_BG_ICON,IDB_VIEW_CONTACT_ICON,BTN_NORMAL);
332
333                 SetViewContacBitmapToButton(IDC_ADD_TO_CONTACT_BUTTON,AppUtility::GetResourceString(IDS_VIEW_CONTACT),
334                                 IDB_VIEW_CONTACT_BG_PRESS_ICON,IDB_VIEW_CONTACT_PRESS_ICON,BTN_PRESS);
335         }
336         else
337         {
338                 SetViewContacBitmapToButton(IDC_ADD_TO_CONTACT_BUTTON,AppUtility::GetResourceString(IDS_ADD_TO_CONTACTS),
339                                 IDB_VIEW_CONTACT_BG_ICON,IDB_VIEW_CONTACT_ICON,BTN_NORMAL);
340
341                 SetViewContacBitmapToButton(IDC_ADD_TO_CONTACT_BUTTON,AppUtility::GetResourceString(IDS_ADD_TO_CONTACTS),
342                                 IDB_VIEW_CONTACT_BG_PRESS_ICON,IDB_VIEW_CONTACT_PRESS_ICON,BTN_PRESS);
343         }
344
345 }
346
347 result
348 CallButtonsPanel::ConstructActiveCallPanel(void)
349 {
350         result r = E_SUCCESS;
351
352         //End Call
353         String endButtonId(IDC_ENDCALL_BUTTON);
354         String btnName = AppUtility::GetResourceString(IDS_ENDCALL_BTN_NAME);
355         SetBitmapsToButton(endButtonId, btnName, IDB_END_CALL_ICON, BTN_NORMAL);
356         SetBitmapsToButton(endButtonId, btnName, IDB_END_CALL_PRESS_ICON, BTN_PRESS);
357         SetBitmapsToButton(endButtonId, btnName, IDB_END_CALL_DIM_ICON, BTN_DIM);
358
359         //Add or Join call based on form state
360         String addJoinButtonId(IDC_ADDJOINCALL_BUTTON);
361         switch (__parentFormType)
362         {
363         case FORMTYPE_OUTGOINGCALL:
364         case FORMTYPE_ACTIVECALL:
365         case FORMTYPE_EMERGENCYOUTGOINGCALL:
366         case FORMTYPE_EMERGENCYACTIVECALL:
367         {
368                 //End call listener
369                 AddKeyPadActionListener(endButtonId, IDA_END_CALL);
370                 //Add Call
371                 btnName = AppUtility::GetResourceString(IDS_ADDCALL_BTN_NAME);
372                 SetBitmapsToButton(addJoinButtonId, btnName, IDB_ADD_CALL_ICON, BTN_NORMAL);
373                 SetBitmapsToButton(addJoinButtonId, btnName, IDB_ADD_CALL_PRESS_ICON, BTN_PRESS);
374                 SetBitmapsToButton(addJoinButtonId, btnName, IDB_ADD_CALL_DIM_ICON, BTN_DIM);
375                 AddKeyPadActionListener(addJoinButtonId, IDA_ADD_CALL);
376         }
377         break;
378
379         case FORMTYPE_ACTIVECONFCALL:
380         {
381                 //End call listener
382                 AddKeyPadActionListener(endButtonId, IDA_END_CONF_CALL);
383                 //Add Call
384                 btnName = AppUtility::GetResourceString(IDS_ADDCALL_BTN_NAME);
385                 SetBitmapsToButton(addJoinButtonId, btnName, IDB_ADD_CALL_ICON, BTN_NORMAL);
386                 SetBitmapsToButton(addJoinButtonId, btnName, IDB_ADD_CALL_PRESS_ICON, BTN_PRESS);
387                 SetBitmapsToButton(addJoinButtonId, btnName, IDB_ADD_CALL_DIM_ICON, BTN_DIM);
388                 AddKeyPadActionListener(addJoinButtonId, IDA_ADD_CALL);
389         }
390         break;
391
392         case FORMTYPE_MULTIPLECALLS:
393         {
394                 //End call listener
395                 AddKeyPadActionListener(endButtonId, IDA_END_CALL);
396                 //Join Call
397                 btnName = AppUtility::GetResourceString(IDS_JOINCALL_BTN_NAME);
398                 SetBitmapsToButton(addJoinButtonId, btnName, IDB_JOIN_CALL_ICON, BTN_NORMAL);
399                 SetBitmapsToButton(addJoinButtonId, btnName, IDB_JOIN_CALL_PRESS_ICON, BTN_PRESS);
400                 SetBitmapsToButton(addJoinButtonId, btnName, IDB_JOIN_CALL_DIM_ICON, BTN_DIM);
401                 AddKeyPadActionListener(addJoinButtonId, IDA_JOIN_CALL);
402         }
403         break;
404
405         default:
406                 break;
407         }
408
409         //Keypad is closed, by default
410         SetKeypadButtonState(IDA_OPEN_NUMKEYPAD);
411         //Speaker is off, by default
412         SetSpeakerButtonState(IDA_SPEAKER);
413         //Mute is off, by default
414         SetMuteButtonState(IDA_MUTE);
415         //Contact
416         String contactButtonId(IDC_CONTACT_BUTTON);
417         btnName = AppUtility::GetResourceString(IDS_CONTACT_BTN_NAME);
418         SetBitmapsToButton(contactButtonId, btnName, IDB_CONTACT_ICON, BTN_NORMAL);
419         SetBitmapsToButton(contactButtonId, btnName, IDB_CONTACT_PRESS_ICON, BTN_PRESS);
420         SetBitmapsToButton(contactButtonId, btnName, IDB_CONTACT_DIM_ICON, BTN_DIM);
421         AddKeyPadActionListener(contactButtonId, IDA_OPEN_CONTACTS);
422
423         //disable all keys except 'Speaker' keys while dialing outgoing call
424         if (__parentFormType == FORMTYPE_OUTGOINGCALL || __parentFormType == FORMTYPE_EMERGENCYOUTGOINGCALL
425                         || __parentFormType == FORMTYPE_EMERGENCYACTIVECALL)
426         {
427                 DisableKeysForOutgoingCall();
428         }
429
430         return r;
431 }
432
433 void
434 CallButtonsPanel::SetBitmapsToButton(const String& buttonId, const String& buttonName, const String& imgPath, ButtonState state)
435 {
436         Button* pButton = static_cast<Button*>(GetControl(buttonId));
437         if (pButton != null)
438         {
439                 //Fetch Bitmap from resource
440                 Bitmap* pBitmap = AppUtility::GetBitmapFromResourcesN(imgPath,
441                                 W_BG_BITMAP, H_BG_BITMAP);
442
443                 //Create a new canvas
444                 Canvas* pCanvas = new (std::nothrow) Canvas;
445                 pCanvas->Construct(Rectangle(0, 0, W_KEYPAD_BTN, H_KEYPAD_BTN));
446
447                 //Set Text to Canvas
448                 Point bitmapPos(0, 0);
449                 bitmapPos.SetPosition(((pCanvas->GetBounds().width - pBitmap->GetWidth()) / 2), Y_BG_BITMAP_POS);
450                 SetEnrichedTextToButton(buttonName, pCanvas, state, (bitmapPos.y + pBitmap->GetHeight() + IDI_VERTICAL_SPACE));
451
452                 //set normal bitmap to canvas
453                 pCanvas->DrawBitmap(Rectangle(bitmapPos, Dimension(pBitmap->GetWidth(), pBitmap->GetHeight())), *pBitmap);
454
455                 //Set the final Bitmap to Button
456                 Bitmap* pActualBgBmp = new (std::nothrow) Bitmap();
457                 pActualBgBmp->Construct(*pCanvas, pCanvas->GetBounds());
458                 //scale to button size
459                 pActualBgBmp->SetScalingQuality(BITMAP_SCALING_QUALITY_MID);
460                 pActualBgBmp->Scale(pButton->GetSize());
461
462                 switch (state)
463                 {
464                 case BTN_NORMAL:
465                 {
466                         pButton->SetNormalBackgroundBitmap(*pActualBgBmp);
467                 }
468                 break;
469
470                 case BTN_PRESS:
471                 {
472                         pButton->SetPressedBackgroundBitmap(*pActualBgBmp);
473                 }
474                 break;
475
476                 case BTN_DIM:
477                 {
478                         pButton->SetDisabledBitmap(Point(0, 0), *pActualBgBmp);
479                 }
480                 break;
481                 }
482                 pButton->Invalidate(true);
483
484                 delete pBitmap;
485                 delete pActualBgBmp;
486                 delete pCanvas;
487         }
488 }
489
490 void
491 CallButtonsPanel::SetViewContacBitmapToButton(const String& buttonId, const String& buttonName, const String& imgBackgroundPath,const String& imgPath, ButtonState state)
492 {
493         Button* pButton = static_cast<Button*>(GetControl(buttonId));
494         if (pButton != null)
495         {
496
497                 //Fetch Bitmap from resource
498                 Bitmap* pBitmap = AppUtility::GetBitmapFromResourcesN(imgPath,
499                                 W_VIEW_CONTACT_BITMAP, W_VIEW_CONTACT_BITMAP);
500
501                 //Create a new canvas
502                 Canvas* pCanvas = new (std::nothrow) Canvas;
503                 pCanvas->Construct(Rectangle(0, 0, pButton->GetBounds().width, pButton->GetBounds().height));
504
505                 // Draw background bitmap
506                 AppResource* pAppResource = AppResource::GetInstance();
507                 Bitmap* pBackGroundBitmap = pAppResource->GetBitmapN(imgBackgroundPath);
508                 if (pBackGroundBitmap->IsNinePatchedBitmap())
509                 {
510                         pCanvas->DrawNinePatchedBitmap(pCanvas->GetBounds(), *pBackGroundBitmap);
511                 }
512                 else
513                 {
514                         pCanvas->DrawBitmap(pCanvas->GetBounds(), *pBackGroundBitmap);
515                 }
516                 delete pBackGroundBitmap;
517                 //Set Text to Canvas
518                 Point bitmapPos(0, 0);
519                 bitmapPos.SetPosition(((pCanvas->GetBounds().width - pBitmap->GetWidth()) / 2), Y_VIEW_CONTACT_BITMAP_POS);
520                 SetEnrichedTextToButton(buttonName, pCanvas, state, (bitmapPos.y + pBitmap->GetHeight() + IDI_VERTICAL_SPACE));
521
522
523                 //set normal bitmap to canvas
524                 pCanvas->DrawBitmap(Rectangle(bitmapPos, Dimension(pBitmap->GetWidth(), pBitmap->GetHeight())), *pBitmap);
525
526                 //Set the final Bitmap to Button
527                 Bitmap* pActualBgBmp = new (std::nothrow) Bitmap();
528                 pActualBgBmp->Construct(*pCanvas, pCanvas->GetBounds());
529
530                 switch (state)
531                 {
532                         case BTN_NORMAL:
533                         {
534                                 pButton->SetNormalBackgroundBitmap(*pActualBgBmp);
535                         }
536                         break;
537
538                         case BTN_PRESS:
539                         {
540                                 pButton->SetPressedBackgroundBitmap(*pActualBgBmp);
541                         }
542                         break;
543
544                 }
545                 pButton->Invalidate(true);
546
547                 delete pBitmap;
548                 delete pActualBgBmp;
549                 delete pCanvas;
550         }
551 }
552
553 void
554 CallButtonsPanel::SetEnrichedTextToButton(const String& buttonName, Canvas* pCanvas, ButtonState state, int verticalPos)
555 {
556         //find text color
557         Color textColor(255, 255, 255);
558         switch (state)
559         {
560         case BTN_NORMAL:
561                 textColor.SetAlpha(255);
562                 break;
563
564         case BTN_PRESS:
565                 textColor.SetAlpha(127);
566                 break;
567
568         case BTN_DIM:
569                 textColor.SetAlpha(77);
570                 break;
571         }
572
573         Font font;
574         font.Construct(FONT_STYLE_PLAIN, IDI_TEXT_SIZE);
575         Dimension textDimension;
576         font.GetTextExtent(buttonName, buttonName.GetLength(), textDimension);
577         textDimension.height = textDimension.height + font.GetDescender();
578         TextElement* pTextElement = new (std::nothrow) TextElement();
579         pTextElement->Construct(buttonName);
580         pTextElement->SetTextColor(textColor);
581         pTextElement->SetFont(font);
582
583         EnrichedText* pEnrichedText = new (std::nothrow) EnrichedText();
584         pEnrichedText->Construct(textDimension);
585         pEnrichedText->Add(*pTextElement);
586
587         //Draw text
588         Point textPos(((pCanvas->GetBounds().width - pEnrichedText->GetWidth()) / 2), verticalPos);
589         pCanvas->DrawText(textPos, *pEnrichedText);
590
591         // Cleans up
592         pEnrichedText->RemoveAll(true);
593         delete pEnrichedText;
594 }
595
596 void
597 CallButtonsPanel::AddKeyPadActionListener(const String& buttonId, CommandIds cmdId)
598 {
599         Button* pButton = static_cast<Button*>(GetControl(buttonId));
600         if (pButton != null)
601         {
602                 pButton->SetActionId(cmdId);
603                 pButton->AddActionEventListener(*__pActionListener);
604         }
605 }
606
607 void
608 CallButtonsPanel::DisableKeysForOutgoingCall(void)
609 {
610         //add call
611         EnableAddCallButton(false);
612
613         //keypad
614         Button* pButton = static_cast<Button*>(GetControl(IDC_KEYPAD_BUTTON));
615         pButton->SetEnabled(false);
616
617         //mute
618         pButton = static_cast<Button*>(GetControl(IDC_MUTE_BUTTON));
619         pButton->SetEnabled(false);
620
621         //contact
622         pButton = static_cast<Button*>(GetControl(IDC_CONTACT_BUTTON));
623         pButton->SetEnabled(false);
624 }
625
626 void
627 CallButtonsPanel::SetEndCallPanelState(bool isEnabled)
628 {
629         //Voice Call
630         Button* pButton = static_cast<Button*>(GetControl(IDC_VOICECALL_BUTTON));
631         pButton->SetEnabled(isEnabled);
632
633         //Video Call
634         pButton = static_cast<Button*>(GetControl(IDC_VIDEOCALL_BUTTON));
635         pButton->SetEnabled(isEnabled);
636
637         //Message
638         pButton = static_cast<Button*>(GetControl(IDC_MSG_BUTTON));
639         pButton->SetEnabled(isEnabled);
640 }
641
642 void
643 CallButtonsPanel::EnableAddCallButton(bool enable)
644 {
645         //add call
646         Button* pButton = static_cast<Button*>(GetControl(IDC_ADDJOINCALL_BUTTON));
647         if(pButton != null && pButton->GetActionId() == IDA_ADD_CALL)
648         {
649                 pButton->SetEnabled(enable);
650                 pButton->Invalidate(true);
651         }
652 }
653
654 void
655 CallButtonsPanel::EnableJoinCallButton(bool enable)
656 {
657         //join call
658         Button* pButton = static_cast<Button*>(GetControl(IDC_ADDJOINCALL_BUTTON));
659         if(pButton != null && pButton->GetActionId() == IDA_JOIN_CALL)
660         {
661                 pButton->SetEnabled(enable);
662                 pButton->Invalidate(true);
663         }
664 }
665
666 void
667 CallButtonsPanel::SetButtonPosition(void)
668 {
669         switch (__parentFormType)
670                 {
671                 case FORMTYPE_ENDCALL:
672                 {
673                         //Voice Call
674                         Button* pButton = static_cast<Button*>(GetControl(IDC_VOICECALL_BUTTON));
675                         SetControlAlwaysOnTop(*pButton,true);
676
677                         //Video Call
678                         pButton = static_cast<Button*>(GetControl(IDC_VIDEOCALL_BUTTON));
679                         SetControlAlwaysOnTop(*pButton,true);
680
681                         //Message
682                         pButton = static_cast<Button*>(GetControl(IDC_MSG_BUTTON));
683                         SetControlAlwaysOnTop(*pButton,true);
684                 }
685                         break;
686
687                 default:
688                 {
689                         //keypad
690                         Button* pButton = static_cast<Button*>(GetControl(IDC_KEYPAD_BUTTON));
691                         SetControlAlwaysOnTop(*pButton,true);
692                         //mute
693                         pButton = static_cast<Button*>(GetControl(IDC_MUTE_BUTTON));
694                         SetControlAlwaysOnTop(*pButton,true);
695                         //contact
696                         pButton = static_cast<Button*>(GetControl(IDC_CONTACT_BUTTON));
697                         SetControlAlwaysOnTop(*pButton,true);
698                         //Add or Join call based on form state
699                         pButton = static_cast<Button*>(GetControl(IDC_ADDJOINCALL_BUTTON));
700                         SetControlAlwaysOnTop(*pButton,true);
701                         //End call
702                         pButton = static_cast<Button*>(GetControl(IDC_ENDCALL_BUTTON));
703                         SetControlAlwaysOnTop(*pButton,true);
704                         //Speaker
705                         pButton = static_cast<Button*>(GetControl(IDC_SPEAKER_BUTTON));
706                         SetControlAlwaysOnTop(*pButton,true);
707                 }
708                         break;
709                 }
710 }