4b7c57b6465fb1724e1396502cf551622ad84eb2
[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.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
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         SetEndCallPanelState(false);
319
320         return r;
321 }
322
323 void
324 CallButtonsPanel::ShowViewContactButton(void)
325 {
326         //Present show View Contact else show Add to contact
327         SetViewContacBitmapToButton(IDC_ADD_TO_CONTACT_BUTTON,AppUtility::GetResourceString(IDS_VIEW_CONTACT),
328                         IDB_VIEW_CONTACT_BG_ICON,IDB_VIEW_CONTACT_ICON,BTN_NORMAL);
329
330         SetViewContacBitmapToButton(IDC_ADD_TO_CONTACT_BUTTON,AppUtility::GetResourceString(IDS_VIEW_CONTACT),
331                         IDB_VIEW_CONTACT_BG_PRESS_ICON,IDB_VIEW_CONTACT_PRESS_ICON,BTN_PRESS);
332 }
333
334 void
335 CallButtonsPanel::ShowAddContactButton(void)
336 {
337         //Present show View Contact else show Add to contact
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 result
346 CallButtonsPanel::ConstructActiveCallPanel(void)
347 {
348         result r = E_SUCCESS;
349
350         //End Call
351         String endButtonId(IDC_ENDCALL_BUTTON);
352         String btnName = AppUtility::GetResourceString(IDS_ENDCALL_BTN_NAME);
353         SetBitmapsToButton(endButtonId, btnName, IDB_END_CALL_ICON, BTN_NORMAL);
354         SetBitmapsToButton(endButtonId, btnName, IDB_END_CALL_PRESS_ICON, BTN_PRESS);
355         SetBitmapsToButton(endButtonId, btnName, IDB_END_CALL_DIM_ICON, BTN_DIM);
356
357         //Add or Join call based on form state
358         String addJoinButtonId(IDC_ADDJOINCALL_BUTTON);
359         switch (__parentFormType)
360         {
361         case FORMTYPE_OUTGOINGCALL:
362         case FORMTYPE_ACTIVECALL:
363         case FORMTYPE_EMERGENCYOUTGOINGCALL:
364         case FORMTYPE_EMERGENCYACTIVECALL:
365         {
366                 //End call listener
367                 AddKeyPadActionListener(endButtonId, IDA_END_CALL);
368                 //Add Call
369                 btnName = AppUtility::GetResourceString(IDS_ADDCALL_BTN_NAME);
370                 SetBitmapsToButton(addJoinButtonId, btnName, IDB_ADD_CALL_ICON, BTN_NORMAL);
371                 SetBitmapsToButton(addJoinButtonId, btnName, IDB_ADD_CALL_PRESS_ICON, BTN_PRESS);
372                 SetBitmapsToButton(addJoinButtonId, btnName, IDB_ADD_CALL_DIM_ICON, BTN_DIM);
373                 AddKeyPadActionListener(addJoinButtonId, IDA_ADD_CALL);
374         }
375         break;
376
377         case FORMTYPE_ACTIVECONFCALL:
378         {
379                 //End call listener
380                 AddKeyPadActionListener(endButtonId, IDA_END_CONF_CALL);
381                 //Add Call
382                 btnName = AppUtility::GetResourceString(IDS_ADDCALL_BTN_NAME);
383                 SetBitmapsToButton(addJoinButtonId, btnName, IDB_ADD_CALL_ICON, BTN_NORMAL);
384                 SetBitmapsToButton(addJoinButtonId, btnName, IDB_ADD_CALL_PRESS_ICON, BTN_PRESS);
385                 SetBitmapsToButton(addJoinButtonId, btnName, IDB_ADD_CALL_DIM_ICON, BTN_DIM);
386                 AddKeyPadActionListener(addJoinButtonId, IDA_ADD_CALL);
387         }
388         break;
389
390         case FORMTYPE_MULTIPLECALLS:
391         {
392                 //End call listener
393                 AddKeyPadActionListener(endButtonId, IDA_END_CALL);
394                 //Join Call
395                 btnName = AppUtility::GetResourceString(IDS_JOINCALL_BTN_NAME);
396                 SetBitmapsToButton(addJoinButtonId, btnName, IDB_JOIN_CALL_ICON, BTN_NORMAL);
397                 SetBitmapsToButton(addJoinButtonId, btnName, IDB_JOIN_CALL_PRESS_ICON, BTN_PRESS);
398                 SetBitmapsToButton(addJoinButtonId, btnName, IDB_JOIN_CALL_DIM_ICON, BTN_DIM);
399                 AddKeyPadActionListener(addJoinButtonId, IDA_JOIN_CALL);
400         }
401         break;
402
403         default:
404                 break;
405         }
406
407         //Keypad is closed, by default
408         SetKeypadButtonState(IDA_OPEN_NUMKEYPAD);
409         //Speaker is off, by default
410         SetSpeakerButtonState(IDA_SPEAKER);
411         //Mute is off, by default
412         SetMuteButtonState(IDA_MUTE);
413         //Contact
414         String contactButtonId(IDC_CONTACT_BUTTON);
415         btnName = AppUtility::GetResourceString(IDS_CONTACT_BTN_NAME);
416         SetBitmapsToButton(contactButtonId, btnName, IDB_CONTACT_ICON, BTN_NORMAL);
417         SetBitmapsToButton(contactButtonId, btnName, IDB_CONTACT_PRESS_ICON, BTN_PRESS);
418         SetBitmapsToButton(contactButtonId, btnName, IDB_CONTACT_DIM_ICON, BTN_DIM);
419         AddKeyPadActionListener(contactButtonId, IDA_OPEN_CONTACTS);
420
421         //disable all keys except 'Speaker' keys while dialing outgoing call
422         if (__parentFormType == FORMTYPE_OUTGOINGCALL || __parentFormType == FORMTYPE_EMERGENCYOUTGOINGCALL
423                         || __parentFormType == FORMTYPE_EMERGENCYACTIVECALL)
424         {
425                 DisableKeysForOutgoingCall();
426         }
427
428         return r;
429 }
430
431 void
432 CallButtonsPanel::SetBitmapsToButton(const String& buttonId, const String& buttonName, const String& imgPath, ButtonState state)
433 {
434         Button* pButton = static_cast<Button*>(GetControl(buttonId));
435         if (pButton != null)
436         {
437                 //Fetch Bitmap from resource
438                 Bitmap* pBitmap = AppUtility::GetBitmapFromResourcesN(imgPath,
439                                 W_BG_BITMAP, H_BG_BITMAP);
440
441                 //Create a new canvas
442                 Canvas* pCanvas = new (std::nothrow) Canvas;
443                 pCanvas->Construct(Rectangle(0, 0, pButton->GetWidth(), pButton->GetHeight()));
444
445                 //Set Text to Canvas
446                 Point bitmapPos(0, 0);
447                 bitmapPos.SetPosition(((pCanvas->GetBounds().width - pBitmap->GetWidth()) / 2), Y_BG_BITMAP_POS);
448                 SetEnrichedTextToButton(buttonName, pCanvas, state, (bitmapPos.y + pBitmap->GetHeight() + IDI_VERTICAL_SPACE));
449
450                 //set normal bitmap to canvas
451                 pCanvas->DrawBitmap(Rectangle(bitmapPos, Dimension(pBitmap->GetWidth(), pBitmap->GetHeight())), *pBitmap);
452
453                 //Set the final Bitmap to Button
454                 Bitmap* pActualBgBmp = new (std::nothrow) Bitmap();
455                 pActualBgBmp->Construct(*pCanvas, pCanvas->GetBounds());
456                 //scale to button size
457                 pActualBgBmp->SetScalingQuality(BITMAP_SCALING_QUALITY_MID);
458                 pActualBgBmp->Scale(pButton->GetSize());
459
460                 switch (state)
461                 {
462                 case BTN_NORMAL:
463                 {
464                         pButton->SetNormalBackgroundBitmap(*pActualBgBmp);
465                 }
466                 break;
467
468                 case BTN_PRESS:
469                 {
470                         pButton->SetPressedBackgroundBitmap(*pActualBgBmp);
471                 }
472                 break;
473
474                 case BTN_DIM:
475                 {
476                         pButton->SetDisabledBackgroundBitmap(*pActualBgBmp);
477                 }
478                 break;
479                 }
480                 pButton->Invalidate(true);
481
482                 delete pBitmap;
483                 delete pActualBgBmp;
484                 delete pCanvas;
485         }
486 }
487
488 void
489 CallButtonsPanel::SetViewContacBitmapToButton(const String& buttonId, const String& buttonName, const String& imgBackgroundPath,const String& imgPath, ButtonState state)
490 {
491         Button* pButton = static_cast<Button*>(GetControl(buttonId));
492         if (pButton != null)
493         {
494
495                 //Fetch Bitmap from resource
496                 Bitmap* pBitmap = AppUtility::GetBitmapFromResourcesN(imgPath,
497                                 W_VIEW_CONTACT_BITMAP, W_VIEW_CONTACT_BITMAP);
498
499                 //Create a new canvas
500                 Canvas* pCanvas = new (std::nothrow) Canvas;
501                 pCanvas->Construct(Rectangle(0, 0, pButton->GetBounds().width, pButton->GetBounds().height));
502
503                 // Draw background bitmap
504                 AppResource* pAppResource = AppResource::GetInstance();
505                 Bitmap* pBackGroundBitmap = pAppResource->GetBitmapN(imgBackgroundPath);
506                 if (pBackGroundBitmap->IsNinePatchedBitmap())
507                 {
508                         pCanvas->DrawNinePatchedBitmap(pCanvas->GetBounds(), *pBackGroundBitmap);
509                 }
510                 else
511                 {
512                         pCanvas->DrawBitmap(pCanvas->GetBounds(), *pBackGroundBitmap);
513                 }
514                 delete pBackGroundBitmap;
515                 //Set Text to Canvas
516                 Point bitmapPos(0, 0);
517                 bitmapPos.SetPosition(((pCanvas->GetBounds().width - pBitmap->GetWidth()) / 2), Y_VIEW_CONTACT_BITMAP_POS);
518                 SetEnrichedTextToButton(buttonName, pCanvas, state, (bitmapPos.y + pBitmap->GetHeight() + IDI_VERTICAL_SPACE));
519
520
521                 //set normal bitmap to canvas
522                 pCanvas->DrawBitmap(Rectangle(bitmapPos, Dimension(pBitmap->GetWidth(), pBitmap->GetHeight())), *pBitmap);
523
524                 //Set the final Bitmap to Button
525                 Bitmap* pActualBgBmp = new (std::nothrow) Bitmap();
526                 pActualBgBmp->Construct(*pCanvas, pCanvas->GetBounds());
527
528                 switch (state)
529                 {
530                         case BTN_NORMAL:
531                         {
532                                 pButton->SetNormalBackgroundBitmap(*pActualBgBmp);
533                         }
534                         break;
535
536                         case BTN_PRESS:
537                         {
538                                 pButton->SetPressedBackgroundBitmap(*pActualBgBmp);
539                         }
540                         break;
541
542                 }
543                 pButton->Invalidate(true);
544
545                 delete pBitmap;
546                 delete pActualBgBmp;
547                 delete pCanvas;
548         }
549 }
550
551 void
552 CallButtonsPanel::SetEnrichedTextToButton(const String& buttonName, Canvas* pCanvas, ButtonState state, int verticalPos)
553 {
554         //find text color
555         Color textColor(255, 255, 255);
556         switch (state)
557         {
558         case BTN_NORMAL:
559                 textColor.SetAlpha(255);
560                 break;
561
562         case BTN_PRESS:
563                 textColor.SetAlpha(127);
564                 break;
565
566         case BTN_DIM:
567                 textColor.SetAlpha(77);
568                 break;
569         }
570
571         Font font;
572         font.Construct(FONT_STYLE_PLAIN, IDI_TEXT_SIZE);
573         FloatDimension textDimension;
574         font.GetTextExtent(buttonName, buttonName.GetLength(), textDimension);
575         textDimension.height = textDimension.height + font.GetDescender();
576         TextElement* pTextElement = new (std::nothrow) TextElement();
577         pTextElement->Construct(buttonName);
578         pTextElement->SetTextColor(textColor);
579         pTextElement->SetFont(font);
580
581         EnrichedText* pEnrichedText = new (std::nothrow) EnrichedText();
582         pEnrichedText->Construct(textDimension);
583         pEnrichedText->Add(*pTextElement);
584
585         //Draw text
586         Point textPos(((pCanvas->GetBounds().width - pEnrichedText->GetWidth()) / 2), verticalPos);
587         pCanvas->DrawText(textPos, *pEnrichedText);
588
589         // Cleans up
590         pEnrichedText->RemoveAll(true);
591         delete pEnrichedText;
592 }
593
594 void
595 CallButtonsPanel::AddKeyPadActionListener(const String& buttonId, CommandIds cmdId)
596 {
597         Button* pButton = static_cast<Button*>(GetControl(buttonId));
598         if (pButton != null)
599         {
600                 pButton->SetActionId(cmdId);
601                 pButton->AddActionEventListener(*__pActionListener);
602         }
603 }
604
605 void
606 CallButtonsPanel::DisableKeysForOutgoingCall(void)
607 {
608         //add call
609         EnableAddCallButton(false);
610
611         //keypad
612         Button* pButton = static_cast<Button*>(GetControl(IDC_KEYPAD_BUTTON));
613         pButton->SetEnabled(false);
614
615         //mute
616         pButton = static_cast<Button*>(GetControl(IDC_MUTE_BUTTON));
617         pButton->SetEnabled(false);
618
619         //contact
620         pButton = static_cast<Button*>(GetControl(IDC_CONTACT_BUTTON));
621         pButton->SetEnabled(false);
622 }
623
624 void
625 CallButtonsPanel::ShowOrHideAddtoContactsButton(bool isEnabled)
626 {
627         Button* pButton = static_cast<Button*>(GetControl(IDC_ADD_TO_CONTACT_BUTTON));
628         pButton->SetShowState(isEnabled);
629 }
630
631 void
632 CallButtonsPanel::SetEndCallPanelState(bool isEnabled)
633 {
634         //Voice Call
635         Button* pButton = static_cast<Button*>(GetControl(IDC_VOICECALL_BUTTON));
636         pButton->SetEnabled(isEnabled);
637
638         //Video Call
639         pButton = static_cast<Button*>(GetControl(IDC_VIDEOCALL_BUTTON));
640         pButton->SetEnabled(isEnabled);
641
642         //Message
643         pButton = static_cast<Button*>(GetControl(IDC_MSG_BUTTON));
644         pButton->SetEnabled(isEnabled);
645
646         //AddToContact or Viewcontact button
647         pButton = static_cast<Button*>(GetControl(IDC_ADD_TO_CONTACT_BUTTON));
648         pButton->SetShowState(isEnabled);
649         pButton->SetEnabled(isEnabled);
650         /*pButton->Invalidate(true);*/
651 }
652
653 void
654 CallButtonsPanel::EnableAddCallButton(bool enable)
655 {
656         //add call
657         Button* pButton = static_cast<Button*>(GetControl(IDC_ADDJOINCALL_BUTTON));
658         if(pButton != null && pButton->GetActionId() == IDA_ADD_CALL)
659         {
660                 pButton->SetEnabled(enable);
661                 pButton->Invalidate(true);
662         }
663 }
664
665 void
666 CallButtonsPanel::EnableJoinCallButton(bool enable)
667 {
668         //join call
669         Button* pButton = static_cast<Button*>(GetControl(IDC_ADDJOINCALL_BUTTON));
670         if(pButton != null && pButton->GetActionId() == IDA_JOIN_CALL)
671         {
672                 pButton->SetEnabled(enable);
673                 pButton->Invalidate(true);
674         }
675 }
676
677 void
678 CallButtonsPanel::SetButtonPosition(void)
679 {
680         switch (__parentFormType)
681                 {
682                 case FORMTYPE_ENDCALL:
683                 {
684                         //Voice Call
685                         Button* pButton = static_cast<Button*>(GetControl(IDC_VOICECALL_BUTTON));
686                         SetControlAlwaysOnTop(*pButton,true);
687
688                         //Video Call
689                         pButton = static_cast<Button*>(GetControl(IDC_VIDEOCALL_BUTTON));
690                         SetControlAlwaysOnTop(*pButton,true);
691
692                         //Message
693                         pButton = static_cast<Button*>(GetControl(IDC_MSG_BUTTON));
694                         SetControlAlwaysOnTop(*pButton,true);
695                 }
696                         break;
697
698                 default:
699                 {
700                         //keypad
701                         Button* pButton = static_cast<Button*>(GetControl(IDC_KEYPAD_BUTTON));
702                         SetControlAlwaysOnTop(*pButton,true);
703                         //mute
704                         pButton = static_cast<Button*>(GetControl(IDC_MUTE_BUTTON));
705                         SetControlAlwaysOnTop(*pButton,true);
706                         //contact
707                         pButton = static_cast<Button*>(GetControl(IDC_CONTACT_BUTTON));
708                         SetControlAlwaysOnTop(*pButton,true);
709                         //Add or Join call based on form state
710                         pButton = static_cast<Button*>(GetControl(IDC_ADDJOINCALL_BUTTON));
711                         SetControlAlwaysOnTop(*pButton,true);
712                         //End call
713                         pButton = static_cast<Button*>(GetControl(IDC_ENDCALL_BUTTON));
714                         SetControlAlwaysOnTop(*pButton,true);
715                         //Speaker
716                         pButton = static_cast<Button*>(GetControl(IDC_SPEAKER_BUTTON));
717                         SetControlAlwaysOnTop(*pButton,true);
718                 }
719                         break;
720                 }
721 }