|
1 /* |
|
2 * Copyright (c) 2003-2007 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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // CEikonEnv API used in CheckRequestedSize to obtain screen size |
|
20 #include <eikenv.h> |
|
21 |
|
22 #include "CMIDComponentFactory.h" |
|
23 #include "CMIDItem.h" |
|
24 // API related to command list |
|
25 #include "CMIDCommandList.h" |
|
26 #include "CMIDCommand.h" |
|
27 #include "CMIDUtils.h" |
|
28 // API related to form (iForm) |
|
29 #include "CMIDForm.h" |
|
30 // TlsStruct for retrieving menu handler from it |
|
31 // CMIDMenuHandler::GetInstance in NotifyFormAboutCommandChange |
|
32 #include "CMIDMenuHandler.h" |
|
33 #include "CMIDUIManager.h" |
|
34 |
|
35 /** If the application requests a preferred size for an item, |
|
36 then this size cannot be bigger than this factor times the screen |
|
37 width or height. This prevents OOM situations if applications require |
|
38 crazy sizes. Note: some items may further limit this maximum values, |
|
39 for example custom item does. @see CheckRequestedSize */ |
|
40 const TInt KMaxScreenSizeFactor = 10; |
|
41 |
|
42 void CMIDItem::ConstructL() |
|
43 // |
|
44 // Zero length descriptor created, even though when a label is set this will |
|
45 // be subsequently destroyed. This is to simplify code, i.e. don't need to check |
|
46 // for null. When all Items set their labels in their construction, then this won't |
|
47 // be necessary |
|
48 // |
|
49 { |
|
50 iCommandList = new(ELeave) CMIDCommandList(); |
|
51 iLabel = TPtrC().AllocL(); |
|
52 ASSERT(iUIManager); |
|
53 iMenuHandler = iUIManager->OpenMenuHandlerL(); |
|
54 } |
|
55 |
|
56 void CMIDItem::SetLabelL(const TDesC& aLabel) |
|
57 { |
|
58 delete iLabel; |
|
59 iLabel = NULL; |
|
60 iLabel = aLabel.AllocL(); |
|
61 } |
|
62 |
|
63 CMIDItem::CMIDItem(MMIDItem::TLayout aLayout, CMIDUIManager* aUIManager) |
|
64 :iLayout(aLayout), |
|
65 iDefaultCommand(NULL), |
|
66 iPreferredSize(-1,-1), |
|
67 iRequestedPreferredSize(-1, -1), |
|
68 iUIManager(aUIManager) |
|
69 { |
|
70 } |
|
71 |
|
72 CMIDItem::~CMIDItem() |
|
73 { |
|
74 delete iLabel; |
|
75 delete iCommandList; |
|
76 } |
|
77 |
|
78 void CMIDItem::AddCommandL(MMIDCommand* aCommand, TBool aFormNotification) |
|
79 { |
|
80 iCommandList->AddL(aCommand); |
|
81 if (iCommandList->Count() == 1) |
|
82 { |
|
83 SetFocusing(ETrue); |
|
84 if (iForm) |
|
85 { |
|
86 iForm->SetFocusedItemIfNone(this); |
|
87 } |
|
88 } |
|
89 if (aFormNotification) |
|
90 { |
|
91 NotifyFormAboutCommandChange(); |
|
92 } |
|
93 } |
|
94 |
|
95 void CMIDItem::RemoveCommand(MMIDCommand* aCommand, TBool aFormNotification) |
|
96 { |
|
97 iCommandList->Remove(aCommand); |
|
98 if (iCommandList->Count() == 0) |
|
99 { |
|
100 if ((iMMidItem->Type() == MMIDComponent::EImageItem) || |
|
101 (iMMidItem->Type() == MMIDComponent::ECustomItem) || |
|
102 (iMMidItem->Type() == MMIDComponent::EStringItem)) |
|
103 { |
|
104 SetFocusing(EFalse); |
|
105 if (iForm) |
|
106 { |
|
107 iForm->RemoveFocusIfFocused(this); |
|
108 } |
|
109 } |
|
110 if (iForm) |
|
111 { |
|
112 DrawDeferred(); //because these items change appearance when no cmds |
|
113 } |
|
114 } |
|
115 if (aFormNotification) |
|
116 { |
|
117 NotifyFormAboutCommandChange(); |
|
118 } |
|
119 } |
|
120 |
|
121 /** |
|
122 * Default implementation is empty. Subclasses provide meaningful implementations. |
|
123 **/ |
|
124 TBool CMIDItem::ProcessCommandL(CMIDCommand* /* aCommand */) |
|
125 { |
|
126 return ETrue; |
|
127 } |
|
128 |
|
129 CMIDUIManager* CMIDItem::GetUIManager() const |
|
130 { |
|
131 return iUIManager; |
|
132 } |
|
133 |
|
134 void CMIDItem::SetDefaultCommand(MMIDCommand* aCommand) |
|
135 { |
|
136 iDefaultCommand = static_cast<CMIDCommand*>(aCommand); |
|
137 NotifyFormAboutCommandChange(); |
|
138 } |
|
139 |
|
140 void CMIDItem::SetBuiltInMSKCommand(CMIDCommand* aCommand) |
|
141 { |
|
142 iBuiltInMSKCommand = aCommand; |
|
143 NotifyFormAboutCommandChange(); |
|
144 } |
|
145 |
|
146 CMIDCommand* CMIDItem::GetMSKCommand() const |
|
147 { |
|
148 CMIDCommand* mskCmd = iBuiltInMSKCommand ? iBuiltInMSKCommand : iDefaultCommand; |
|
149 return mskCmd; |
|
150 } |
|
151 |
|
152 void CMIDItem::NotifyFormAboutCommandChange() |
|
153 { |
|
154 if (iForm && iForm->IsCurrentItem(this)) |
|
155 { |
|
156 iForm->UpdateItemCommands(iCommandList, GetMSKCommand()); |
|
157 TRAP_IGNORE(iMenuHandler->UpdateMenuIfVisibleL()); |
|
158 } |
|
159 } |
|
160 |
|
161 void CMIDItem::SetPreferredSize(const TSize& aSize,const TSize& aMinimumSize) |
|
162 { |
|
163 iRequestedPreferredSize = CheckRequestedSize(aSize); |
|
164 |
|
165 // If aSize is less than aMinimumSize (per dimension), then the minimum size is used |
|
166 iPreferredSize.iHeight = Max(aSize.iHeight,aMinimumSize.iHeight); |
|
167 iPreferredSize.iWidth = Max(aSize.iWidth,aMinimumSize.iWidth); |
|
168 // Once the item has been added to a form, it's preferred size can be clipped |
|
169 // to the width of the form. |
|
170 if (iForm) |
|
171 { |
|
172 iPreferredSize.iWidth = Min(iForm->Width(),iPreferredSize.iWidth); |
|
173 } |
|
174 } |
|
175 |
|
176 void CMIDItem::SetForm(CMIDForm* aForm) |
|
177 { |
|
178 iForm = aForm; |
|
179 } |
|
180 |
|
181 /** If the specified height or width or the requested size are bigger that the |
|
182 screen height or width times KMaxScreenSizeFactor then return these limit values. |
|
183 Otherwise return the size unchanged. @see KMaxScreenSizeFactor */ |
|
184 TSize CMIDItem::CheckRequestedSize(const TSize& aRequestedSize) const |
|
185 { |
|
186 TSize size = aRequestedSize; |
|
187 const TSize screenSize = iEikonEnv->ScreenDevice()->SizeInPixels(); |
|
188 |
|
189 size.iWidth = size.iWidth < KMaxScreenSizeFactor * screenSize.iWidth ? |
|
190 size.iWidth : KMaxScreenSizeFactor * screenSize.iWidth; |
|
191 |
|
192 size.iHeight = size.iHeight < KMaxScreenSizeFactor * screenSize.iHeight ? |
|
193 size.iHeight : KMaxScreenSizeFactor * screenSize.iHeight; |
|
194 |
|
195 return size; |
|
196 } |
|
197 |
|
198 TPtrC CMIDItem::Label() const |
|
199 { |
|
200 return *iLabel; |
|
201 } |
|
202 |
|
203 void CMIDItem::SetLayoutL(MMIDItem::TLayout aLayout) |
|
204 { |
|
205 iLayout = aLayout; |
|
206 } |
|
207 |
|
208 TInt CMIDItem::Type() |
|
209 { |
|
210 if (iMMidItem) |
|
211 { |
|
212 return (TInt)(iMMidItem->Type()); |
|
213 } |
|
214 return 0; |
|
215 } |
|
216 |
|
217 MMIDItem::TLayout CMIDItem::Layout() const |
|
218 { |
|
219 return iLayout; |
|
220 } |
|
221 |
|
222 CMIDCommandList* CMIDItem::CommandList() const |
|
223 { |
|
224 return iCommandList; |
|
225 } |
|
226 |
|
227 CMIDCommand* CMIDItem::DefaultCommand() const |
|
228 { |
|
229 return iDefaultCommand; |
|
230 } |
|
231 |
|
232 CMIDForm* CMIDItem::Form() const |
|
233 { |
|
234 return iForm; |
|
235 } |
|
236 |
|
237 void CMIDItem::ItemAddedToFormL() |
|
238 { |
|
239 } |
|
240 |
|
241 void CMIDItem::ItemRemovedFromForm() |
|
242 { |
|
243 } |
|
244 |
|
245 void CMIDItem::HandleCurrentL(TBool /*aCurrent*/) |
|
246 { |
|
247 } |
|
248 |
|
249 void CMIDItem::NotifyScrollingCompleted() |
|
250 { |
|
251 } |
|
252 |
|
253 TSize CMIDItem::PreferredSize() |
|
254 { |
|
255 TInt height = Max(iPreferredSize.iHeight, MinimumSize().iHeight); |
|
256 TInt width = Max(iPreferredSize.iWidth, MinimumSize().iWidth); |
|
257 return TSize(width, height); |
|
258 } |
|
259 |
|
260 MMIDItem::TLayout CMIDItem::Layout() |
|
261 { |
|
262 return iLayout; |
|
263 } |
|
264 |
|
265 void CMIDItem::SetPreferredWidth(TInt aWidth) |
|
266 { |
|
267 iPreferredSize.iWidth = aWidth; |
|
268 } |
|
269 |
|
270 void CMIDItem::SetPreferredHeight(TInt aHeight) |
|
271 { |
|
272 iPreferredSize.iHeight = aHeight; |
|
273 } |
|
274 |
|
275 // End of File |