|
1 /* |
|
2 * Copyright (c) 2008-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: Visual list manager |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 /** |
|
22 * @internal reviewed 04/07/2007 by M Byrne |
|
23 */ |
|
24 |
|
25 #include <coemain.h> |
|
26 |
|
27 #include <alf/alfimagevisual.h> |
|
28 #include <alf/alfanchorlayout.h> |
|
29 #include <alf/alfenv.h> |
|
30 #include <alf/alfbrush.h> |
|
31 #include <alf/alfcontrolgroup.h> |
|
32 |
|
33 #include <glxlog.h> |
|
34 #include <glxtracer.h> |
|
35 |
|
36 #include "mglxmedialist.h" |
|
37 |
|
38 #include "mglxvisuallistobserver.h" |
|
39 #include "glxitemvisual.h" |
|
40 #include "glxvisuallistcontrol.h" |
|
41 #include "glxvisuallistmanager.h" |
|
42 |
|
43 /** |
|
44 * CGlxVlmTls |
|
45 * |
|
46 * Global object stored in TLS. |
|
47 * Owns the only instance of a Visual List Manager. |
|
48 */ |
|
49 struct CGlxVlmTls |
|
50 { |
|
51 CGlxVlmTls(CGlxVisualListManager* aListManager) |
|
52 { |
|
53 iListManager = aListManager; |
|
54 iReferenceCount = 0; |
|
55 } |
|
56 |
|
57 CGlxVisualListManager* iListManager; |
|
58 TInt iReferenceCount; |
|
59 }; |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // ManagerL |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 EXPORT_C CGlxVisualListManager* CGlxVisualListManager::ManagerL() |
|
66 { |
|
67 TRACER("CGlxVisualListManager::ManagerL"); |
|
68 GLX_LOG_INFO("CGlxVisualListManager::ManagerL"); |
|
69 CGlxVlmTls* tls = reinterpret_cast<CGlxVlmTls*>(Dll::Tls()); |
|
70 |
|
71 // Create tls struct if does not exist |
|
72 if (tls == NULL) |
|
73 { |
|
74 // Create list manager instance |
|
75 CGlxVisualListManager* lm = new (ELeave) CGlxVisualListManager(); |
|
76 CleanupStack::PushL(lm); |
|
77 tls = new (ELeave) CGlxVlmTls(lm); |
|
78 |
|
79 // MUST NOT LEAVE AFTER THIS POINT |
|
80 CleanupStack::Pop(lm); |
|
81 |
|
82 Dll::SetTls( reinterpret_cast<TAny*>(tls)); |
|
83 } |
|
84 |
|
85 // Add user |
|
86 tls->iReferenceCount++; |
|
87 |
|
88 return tls->iListManager; |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // Close |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 EXPORT_C void CGlxVisualListManager::Close() |
|
96 { |
|
97 |
|
98 TRACER("CGlxVisualListManager::Close"); |
|
99 GLX_LOG_INFO("CGlxVisualListManager::Close"); |
|
100 CGlxVlmTls* tls = reinterpret_cast<CGlxVlmTls*>(Dll::Tls()); |
|
101 __ASSERT_DEBUG(tls != NULL, Panic(EGlxPanicLogicError)); |
|
102 __ASSERT_DEBUG(tls->iReferenceCount > 0, Panic(EGlxPanicLogicError)); // There's nothign to close |
|
103 |
|
104 if (tls != NULL) |
|
105 { |
|
106 tls->iReferenceCount--; |
|
107 |
|
108 // Delete the tls pointer and list manager instance if this was the |
|
109 // last reference |
|
110 if (tls->iReferenceCount == 0) |
|
111 { |
|
112 delete tls->iListManager; |
|
113 delete tls; |
|
114 Dll::SetTls(NULL); |
|
115 } |
|
116 } |
|
117 } |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // Constructor |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 CGlxVisualListManager::CGlxVisualListManager() |
|
124 { |
|
125 // No implementation |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // Destructor |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 CGlxVisualListManager::~CGlxVisualListManager() |
|
133 { |
|
134 iVisualLists.Close(); |
|
135 } |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // AllocListL |
|
139 // ----------------------------------------------------------------------------- |
|
140 // |
|
141 EXPORT_C MGlxVisualList* CGlxVisualListManager::AllocListL( |
|
142 MGlxMediaList& aMediaList, CAlfEnv& aEnv, CAlfDisplay& aDisplay, |
|
143 CAlfImageVisual::TScaleMode aThumbnailScaleMode ) |
|
144 { |
|
145 TRACER("CGlxVisualListManager::AllocListL"); |
|
146 GLX_LOG_INFO("CGlxVisualListManager::AllocListL"); |
|
147 __ASSERT_DEBUG( &aMediaList, Panic(EGlxPanicNullPointer)); |
|
148 |
|
149 CGlxVisualListControl* lc = CGlxVisualListControl::NewLC(aMediaList, |
|
150 aEnv, aDisplay, aThumbnailScaleMode); |
|
151 iVisualLists.AppendL(lc); |
|
152 lc->AddReference(); // Add first user |
|
153 CleanupStack::Pop(lc); |
|
154 return lc; |
|
155 } |
|
156 |
|
157 // ----------------------------------------------------------------------------- |
|
158 // ListL |
|
159 // ----------------------------------------------------------------------------- |
|
160 // |
|
161 EXPORT_C MGlxVisualList* CGlxVisualListManager::ListL( |
|
162 MGlxMediaList& aItemList, |
|
163 CAlfEnv& aEnv, CAlfDisplay& aDisplay, |
|
164 CAlfImageVisual::TScaleMode aThumbnailScaleMode) |
|
165 { |
|
166 TRACER("CGlxVisualListManager::ListL"); |
|
167 GLX_LOG_INFO("CGlxVisualListManager::ListL"); |
|
168 __ASSERT_DEBUG( &aItemList, Panic(EGlxPanicNullPointer) ); |
|
169 |
|
170 // Try to find an existing visual list with the same media list |
|
171 MGlxVisualList* visList = NULL; |
|
172 |
|
173 // search in existing list |
|
174 TInt listCount = iVisualLists.Count(); |
|
175 for ( TInt i = 0; i < listCount; i++ ) |
|
176 { |
|
177 if ( &iVisualLists[i]->MediaList() == &aItemList |
|
178 && iVisualLists[i]->ThumbnailScaleMode() == aThumbnailScaleMode) |
|
179 { |
|
180 visList = iVisualLists[i]; |
|
181 iVisualLists[i]->AddReference(); |
|
182 break; |
|
183 } |
|
184 } |
|
185 |
|
186 // if not found allocate a new one |
|
187 if ( !visList ) |
|
188 { |
|
189 visList = AllocListL(aItemList, aEnv, aDisplay, aThumbnailScaleMode); |
|
190 } |
|
191 |
|
192 return visList; |
|
193 } |
|
194 |
|
195 // ----------------------------------------------------------------------------- |
|
196 // Removes a reference to the list, an deletes it if no more references remain |
|
197 // ----------------------------------------------------------------------------- |
|
198 // |
|
199 EXPORT_C void CGlxVisualListManager::ReleaseList(MGlxVisualList* aList) |
|
200 { |
|
201 TRACER("CGlxVisualListManager::ReleaseList"); |
|
202 GLX_LOG_INFO("CGlxVisualListManager::ReleaseList"); |
|
203 if (aList == NULL) |
|
204 { |
|
205 return; |
|
206 } |
|
207 |
|
208 TGlxVisualListId id = aList->Id(); |
|
209 TInt count = iVisualLists.Count(); |
|
210 for (TInt i = 0; i < count; i++) |
|
211 { |
|
212 CGlxVisualListControl* list = iVisualLists[i]; |
|
213 if (list->Id() == id) |
|
214 { |
|
215 TInt refsLeft = list->RemoveReference(); |
|
216 if (refsLeft == 0) |
|
217 { |
|
218 // No users left, delete |
|
219 delete list; |
|
220 iVisualLists.Remove(i); |
|
221 } |
|
222 break; |
|
223 } |
|
224 } |
|
225 } |
|
226 |
|
227 |