|
1 /* |
|
2 * Copyright (c) 2009 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: MR Toolbar impl |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "cmrtoolbar.h" |
|
19 |
|
20 #include "esmrcommands.h" |
|
21 #include "cmrasynchcmd.h" |
|
22 #include <esmrgui.rsg> |
|
23 #include <eikenv.h> |
|
24 #include <eikcolib.h> |
|
25 #include <akntoolbar.h> |
|
26 #include <aknbutton.h> |
|
27 |
|
28 // LOCAL DEFINITIONS |
|
29 namespace // codescanner::namespace |
|
30 { |
|
31 const TInt KFirstItemIndex( 0 ); |
|
32 const TInt KSecondItemIndex( 1 ); |
|
33 const TInt KThirdItemIndex( 2 ); |
|
34 } |
|
35 |
|
36 // CLASS MEMBERS DEFINITIONS |
|
37 // --------------------------------------------------------------------------- |
|
38 // CMRToolbar::CMRToolbar |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 CMRToolbar::CMRToolbar() |
|
42 { |
|
43 // Do nothing |
|
44 } |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // CMRToolbar::NewL |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 CMRToolbar* CMRToolbar::NewL() |
|
51 { |
|
52 CMRToolbar* self = new ( ELeave ) CMRToolbar(); |
|
53 CleanupStack::PushL( self ); |
|
54 self->ConstructL(); |
|
55 CleanupStack::Pop( self ); |
|
56 return self; |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // CMRToolbar::~CMRToolbar |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 CMRToolbar::~CMRToolbar() |
|
64 { |
|
65 if( iToolbar ) |
|
66 { |
|
67 RemovePreviousItems(); |
|
68 delete iToolbar; |
|
69 } |
|
70 if( iPreviousToolbar ) |
|
71 { |
|
72 iPreviousToolbar->SetToolbarVisibility( iPreviousVisibility ); |
|
73 static_cast<CEikAppUiFactory*>( |
|
74 CEikonEnv::Static()->AppUiFactory() )->SetViewFixedToolbar( iPreviousToolbar );// codescanner::eikonenvstatic |
|
75 } |
|
76 |
|
77 iItemIdArray.Close(); |
|
78 delete iAsyncCmd; |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // CMRToolbar::ConstructL |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 void CMRToolbar::ConstructL() |
|
86 { |
|
87 // This does not guarantee that the iPreviousToolbar is constructed |
|
88 iPreviousToolbar = static_cast<CEikAppUiFactory*>( |
|
89 CEikonEnv::Static()->AppUiFactory() )->CurrentFixedToolbar();// codescanner::eikonenvstatic |
|
90 if ( iPreviousToolbar ) |
|
91 { |
|
92 iPreviousVisibility = iPreviousToolbar->IsShown(); |
|
93 iPreviousToolbar->SetToolbarVisibility( EFalse ); |
|
94 } |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // CMRToolbar::InitializeToolbar |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 void CMRToolbar::InitializeToolbarL( |
|
102 TToolbarContext aCntx, |
|
103 CAknToolbar* aNativeToolbar ) |
|
104 { |
|
105 if( aNativeToolbar ) |
|
106 { |
|
107 iToolbar = aNativeToolbar; |
|
108 } |
|
109 else |
|
110 { |
|
111 iToolbar = CAknToolbar::NewL( R_GLOBAL_TOOLBAR ); |
|
112 } |
|
113 |
|
114 iToolbar->SetToolbarObserver( this ); |
|
115 static_cast<CEikAppUiFactory*>( |
|
116 CEikonEnv::Static()->AppUiFactory() )->SetViewFixedToolbar( iToolbar );// codescanner::eikonenvstatic |
|
117 // Construct the correct toolbar for the context |
|
118 TInt error( KErrNone ); |
|
119 TRAP( error, ConstructToolbarL( aCntx ) ); |
|
120 if ( error != KErrNone ) |
|
121 { |
|
122 CEikonEnv::Static()->HandleError( error );// codescanner::eikonenvstatic |
|
123 } |
|
124 } |
|
125 |
|
126 // --------------------------------------------------------------------------- |
|
127 // CMRToolbar::SetObserver |
|
128 // --------------------------------------------------------------------------- |
|
129 // |
|
130 void CMRToolbar::ShowToolbar( TBool aShowToolbar ) |
|
131 { |
|
132 if( iToolbar ) |
|
133 { |
|
134 iToolbar->SetToolbarVisibility( aShowToolbar ); |
|
135 } |
|
136 } |
|
137 |
|
138 // --------------------------------------------------------------------------- |
|
139 // CMRToolbar::SetObserver |
|
140 // --------------------------------------------------------------------------- |
|
141 // |
|
142 void CMRToolbar::SetObserver( MAknToolbarObserver* aObserver ) |
|
143 { |
|
144 iObserver = aObserver; |
|
145 } |
|
146 |
|
147 // --------------------------------------------------------------------------- |
|
148 // CMRToolbar::ConstructToolbarL |
|
149 // --------------------------------------------------------------------------- |
|
150 // |
|
151 void CMRToolbar::ConstructToolbarL( TToolbarContext aCntx ) |
|
152 { |
|
153 RemovePreviousItems(); |
|
154 |
|
155 switch( aCntx ) |
|
156 { |
|
157 case EMRViewerFromMailApp: |
|
158 case EMRViewerAttendee: |
|
159 { |
|
160 iItemIdArray.Append( EESMRCmdAcceptMR ); |
|
161 iItemIdArray.Append( EESMRCmdTentativeMR ); |
|
162 iItemIdArray.Append( EESMRCmdDeclineMR ); |
|
163 |
|
164 ConstructButtonL( |
|
165 R_TOOLBAR_BUTTON_ACCEPT, |
|
166 KFirstItemIndex ); |
|
167 ConstructButtonL( |
|
168 R_TOOLBAR_BUTTON_TENTATIVE, |
|
169 KSecondItemIndex ); |
|
170 ConstructButtonL( |
|
171 R_TOOLBAR_BUTTON_DECLINE, |
|
172 KThirdItemIndex ); |
|
173 break; |
|
174 } |
|
175 default: |
|
176 break; |
|
177 } |
|
178 } |
|
179 |
|
180 // --------------------------------------------------------------------------- |
|
181 // CMRToolbar::ConstructButtonL |
|
182 // --------------------------------------------------------------------------- |
|
183 // |
|
184 void CMRToolbar::ConstructButtonL( TInt aResId, TInt aIndex ) |
|
185 { |
|
186 TInt flags( 0 ); |
|
187 CAknButton* newButton = |
|
188 CAknButton::NewL( aResId ); |
|
189 // Ownership of the button is taken right away, no need for CleanupStack |
|
190 iToolbar->AddItemL( |
|
191 newButton, EAknCtButton, iItemIdArray[aIndex], |
|
192 flags, aIndex ); |
|
193 } |
|
194 |
|
195 // --------------------------------------------------------------------------- |
|
196 // CMRToolbar::DynInitToolbarL |
|
197 // --------------------------------------------------------------------------- |
|
198 // |
|
199 void CMRToolbar::DynInitToolbarL ( TInt aResourceId, CAknToolbar *aToolbar ) |
|
200 { |
|
201 if( iObserver ) |
|
202 { |
|
203 iObserver->DynInitToolbarL( aResourceId, aToolbar ); |
|
204 } |
|
205 } |
|
206 |
|
207 // --------------------------------------------------------------------------- |
|
208 // CMRToolbar::OfferToolbarEventL |
|
209 // --------------------------------------------------------------------------- |
|
210 // |
|
211 void CMRToolbar::OfferToolbarEventL ( TInt aCommand ) |
|
212 { |
|
213 // Handle commands here |
|
214 if( iObserver ) |
|
215 { |
|
216 // Lazy init |
|
217 if( !iAsyncCmd ) |
|
218 { |
|
219 iAsyncCmd = CMRAsynchCmd::NewL(); |
|
220 } |
|
221 // This will notify observer asynchronously |
|
222 iAsyncCmd->NotifyObserver( aCommand, iObserver ); |
|
223 } |
|
224 } |
|
225 |
|
226 // --------------------------------------------------------------------------- |
|
227 // CMRToolbar::RemovePreviousItems |
|
228 // --------------------------------------------------------------------------- |
|
229 // |
|
230 void CMRToolbar::RemovePreviousItems() |
|
231 { |
|
232 TInt count( iItemIdArray.Count() ); |
|
233 for( TInt i = 0; i < count; ++i ) |
|
234 { |
|
235 iToolbar->RemoveItem( iItemIdArray[ i ] ); |
|
236 } |
|
237 iItemIdArray.Reset(); |
|
238 } |
|
239 |
|
240 // --------------------------------------------------------------------------- |
|
241 // CMRToolbar::Rect |
|
242 // --------------------------------------------------------------------------- |
|
243 // |
|
244 TRect CMRToolbar::Rect() |
|
245 { |
|
246 TRect rect( 0, 0, 0, 0 ); |
|
247 |
|
248 if( iToolbar && iToolbar->IsShown() ) |
|
249 { |
|
250 rect = iToolbar->Rect(); |
|
251 } |
|
252 |
|
253 return rect; |
|
254 } |
|
255 |
|
256 // End of file |