1 /* |
|
2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Utility class for keyboard handling |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // includes |
|
20 #include <w32std.h> |
|
21 #include <eikdef.h> |
|
22 #include <eikenv.h> |
|
23 #include <AknUtils.h> |
|
24 |
|
25 #include "mulkeyboardutility.h" |
|
26 |
|
27 const TUid KUidKeyBoardUtility = {0x02D811B8} ; |
|
28 |
|
29 CQwertySubscriber::CQwertySubscriber(TCallBack aCallBack, RProperty& aProperty) |
|
30 : CActive(EPriorityNormal), iCallBack(aCallBack), iProperty(aProperty) |
|
31 { |
|
32 CActiveScheduler::Add(this); |
|
33 } |
|
34 |
|
35 CQwertySubscriber::~CQwertySubscriber() |
|
36 { |
|
37 Cancel(); |
|
38 } |
|
39 |
|
40 void CQwertySubscriber::SubscribeL() |
|
41 { |
|
42 if (!IsActive()) |
|
43 { |
|
44 iProperty.Subscribe(iStatus); |
|
45 SetActive(); |
|
46 } |
|
47 } |
|
48 |
|
49 void CQwertySubscriber::StopSubscribe() |
|
50 { |
|
51 Cancel(); |
|
52 } |
|
53 |
|
54 void CQwertySubscriber::RunL() |
|
55 { |
|
56 if (iStatus.Int() == KErrNone) |
|
57 { |
|
58 iCallBack.CallBack(); |
|
59 SubscribeL(); |
|
60 } |
|
61 } |
|
62 |
|
63 void CQwertySubscriber::DoCancel() |
|
64 { |
|
65 iProperty.Cancel(); |
|
66 } |
|
67 |
|
68 CKeyBoardUtility* CKeyBoardUtility:: NewL() |
|
69 { |
|
70 CKeyBoardUtility* self = static_cast<CKeyBoardUtility*>( CCoeEnv::Static( KUidKeyBoardUtility ) ) ; |
|
71 if(!self) |
|
72 { |
|
73 self = new( ELeave ) CKeyBoardUtility() ; |
|
74 } |
|
75 return self ; |
|
76 } |
|
77 |
|
78 |
|
79 CKeyBoardUtility::CKeyBoardUtility():CCoeStatic(KUidKeyBoardUtility, CCoeStatic::EThread /*or EApp*/ ) |
|
80 { |
|
81 bQwerty = EFalse; |
|
82 User::LeaveIfError(iQwertyModeStatusProperty.Attach(KCRUidAvkon, KAknQwertyInputModeActive)); |
|
83 iQwertyModeStatusSubscriber = new (ELeave) CQwertySubscriber(TCallBack(QwertyModeChangeNotification, this), iQwertyModeStatusProperty); |
|
84 iQwertyModeStatusSubscriber->SubscribeL(); |
|
85 } |
|
86 |
|
87 CKeyBoardUtility::~CKeyBoardUtility() |
|
88 { |
|
89 |
|
90 // Qwerty Notify clean-up |
|
91 if (iQwertyModeStatusSubscriber) |
|
92 { |
|
93 iQwertyModeStatusSubscriber->StopSubscribe(); |
|
94 } |
|
95 iQwertyModeStatusProperty.Close(); |
|
96 delete iQwertyModeStatusSubscriber; |
|
97 } |
|
98 |
|
99 TInt CKeyBoardUtility::QwertyModeChangeNotification(TAny* aObj) |
|
100 { |
|
101 if (aObj != NULL) |
|
102 { |
|
103 static_cast<CKeyBoardUtility*>(aObj)->HandleQwertyModeChangeNotification(); |
|
104 return KErrNone; |
|
105 } |
|
106 else |
|
107 { |
|
108 return KErrArgument; |
|
109 } |
|
110 } |
|
111 |
|
112 void CKeyBoardUtility::HandleQwertyModeChangeNotification() |
|
113 { |
|
114 TInt value = 0; |
|
115 iQwertyModeStatusProperty.Get(value); |
|
116 if(value > 0) |
|
117 { |
|
118 bQwerty = ETrue; |
|
119 } |
|
120 else |
|
121 { |
|
122 bQwerty = EFalse; |
|
123 } |
|
124 } |
|
125 |
|
126 bool CKeyBoardUtility::IsQwerty() |
|
127 { |
|
128 TInt value = 0; |
|
129 iQwertyModeStatusProperty.Get(value); |
|
130 if(value > 0) |
|
131 { |
|
132 bQwerty = true; |
|
133 } |
|
134 else |
|
135 { |
|
136 bQwerty = false; |
|
137 } |
|
138 return bQwerty; |
|
139 } |
|