60
|
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: Splits layout chain by visual
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
#include "glxlayoutsplitter.h"
|
|
22 |
|
|
23 |
#include <alf/alfvisual.h>
|
|
24 |
#include <mglxvisuallist.h>
|
|
25 |
#include <glxpanic.h> // Panic codes
|
|
26 |
|
|
27 |
// -----------------------------------------------------------------------------
|
|
28 |
// Constructor
|
|
29 |
// -----------------------------------------------------------------------------
|
|
30 |
EXPORT_C TGlxLayoutSplitter::TGlxLayoutSplitter()
|
|
31 |
: iDefaultLayout( NULL ),
|
|
32 |
iVisualList( NULL )
|
|
33 |
{
|
|
34 |
__DEBUG_ONLY( _iName = _L("TGlxLayoutSplitter") );
|
|
35 |
}
|
|
36 |
|
|
37 |
// -----------------------------------------------------------------------------
|
|
38 |
// Destructor
|
|
39 |
// -----------------------------------------------------------------------------
|
|
40 |
EXPORT_C TGlxLayoutSplitter::~TGlxLayoutSplitter()
|
|
41 |
{
|
|
42 |
Reset();
|
|
43 |
}
|
|
44 |
|
|
45 |
// -----------------------------------------------------------------------------
|
|
46 |
// Tells the splitter what is the visual list object
|
|
47 |
// -----------------------------------------------------------------------------
|
|
48 |
EXPORT_C void TGlxLayoutSplitter::SetVisualListL(
|
|
49 |
MGlxVisualList* aVisualList )
|
|
50 |
{
|
|
51 |
__ASSERT_DEBUG(
|
|
52 |
aVisualList, Panic( EGlxPanicNullVisualList ) );
|
|
53 |
iVisualList = aVisualList;
|
|
54 |
iVisualList->AddObserverL( this );
|
|
55 |
}
|
|
56 |
|
|
57 |
// -----------------------------------------------------------------------------
|
|
58 |
// SetLayoutL
|
|
59 |
// -----------------------------------------------------------------------------
|
|
60 |
EXPORT_C void TGlxLayoutSplitter::SetLayoutL(
|
|
61 |
MGlxLayout* aLayout, const CAlfVisual* aVisual )
|
|
62 |
{
|
|
63 |
// Call SetVisualListL first
|
|
64 |
__ASSERT_DEBUG( iVisualList, Panic( EGlxPanicNullVisualList ) );
|
|
65 |
// search if there already is a layout for this visual
|
|
66 |
__DEBUG_ONLY( TLayout temp;temp.iVisual = aVisual; );
|
|
67 |
__ASSERT_DEBUG(
|
|
68 |
iLayouts.Find( temp, TLayout::Match ) == KErrNotFound,
|
|
69 |
Panic( EGlxPanicAlreadyAdded ) );
|
|
70 |
|
|
71 |
// create layout struct
|
|
72 |
TLayout newLayoutStruct;
|
|
73 |
newLayoutStruct.iLayout = aLayout;
|
|
74 |
newLayoutStruct.iVisual = aVisual;
|
|
75 |
// append to the array
|
|
76 |
iLayouts.AppendL( newLayoutStruct );
|
|
77 |
}
|
|
78 |
|
|
79 |
// -----------------------------------------------------------------------------
|
|
80 |
// Removes an existing layout
|
|
81 |
// -----------------------------------------------------------------------------
|
|
82 |
EXPORT_C void TGlxLayoutSplitter::RemoveLayout(
|
|
83 |
const CAlfVisual* aVisual )
|
|
84 |
{
|
|
85 |
TInt index = LayoutIndex( aVisual );
|
|
86 |
if( index != KErrNotFound )
|
|
87 |
{
|
|
88 |
iLayouts.Remove( index );
|
|
89 |
}
|
|
90 |
// NOTE: it is ok to try to remove a layout from visual when there was none
|
|
91 |
}
|
|
92 |
|
|
93 |
// -----------------------------------------------------------------------------
|
|
94 |
// Sets layout to be used when for visuals which don't have a specific layout
|
|
95 |
// -----------------------------------------------------------------------------
|
|
96 |
EXPORT_C void TGlxLayoutSplitter::SetDefaultLayout(
|
|
97 |
MGlxLayout* aLayout )
|
|
98 |
{
|
|
99 |
iDefaultLayout = aLayout;
|
|
100 |
}
|
|
101 |
|
|
102 |
// -----------------------------------------------------------------------------
|
|
103 |
// Reset
|
|
104 |
// Remove all layouts and remove association with visual list.
|
|
105 |
// -----------------------------------------------------------------------------
|
|
106 |
EXPORT_C void TGlxLayoutSplitter::Reset()
|
|
107 |
{
|
|
108 |
// Remove all layouts
|
|
109 |
iLayouts.Close();
|
|
110 |
|
|
111 |
if( iVisualList )
|
|
112 |
{
|
|
113 |
iVisualList->RemoveObserver( this );
|
|
114 |
iVisualList = NULL;
|
|
115 |
}
|
|
116 |
}
|
|
117 |
|
|
118 |
// -----------------------------------------------------------------------------
|
|
119 |
// DoSetLayoutValues
|
|
120 |
// -----------------------------------------------------------------------------
|
|
121 |
void TGlxLayoutSplitter::DoSetLayoutValues(
|
|
122 |
TGlxLayoutInfo& aInfo )
|
|
123 |
{
|
|
124 |
// Call SetVisualListL to avoid this assert
|
|
125 |
__ASSERT_DEBUG( iVisualList, Panic( EGlxPanicNullVisualList ) );
|
|
126 |
|
|
127 |
// Does a layout exist for the visual
|
|
128 |
// If yes, use the specific layout. If not, use default layout.
|
|
129 |
MGlxLayout* layout = Layout( &aInfo.Visual() );
|
|
130 |
// if layout was found
|
|
131 |
if( layout )
|
|
132 |
{
|
|
133 |
// return its value
|
|
134 |
return layout->SetLayoutValues( aInfo );
|
|
135 |
}
|
|
136 |
// otherwise return the default layout value
|
|
137 |
else if( iDefaultLayout )
|
|
138 |
{
|
|
139 |
return iDefaultLayout->SetLayoutValues( aInfo );
|
|
140 |
}
|
|
141 |
// nothing to do, no layout for the visual nor default
|
|
142 |
}
|
|
143 |
|
|
144 |
// -----------------------------------------------------------------------------
|
|
145 |
// HandleVisualAddedL
|
|
146 |
// -----------------------------------------------------------------------------
|
|
147 |
void TGlxLayoutSplitter::HandleVisualAddedL(
|
|
148 |
CAlfVisual* /*aVisual*/, TInt /*aIndex*/, MGlxVisualList* /*aList*/)
|
|
149 |
{
|
|
150 |
// Do nothing
|
|
151 |
}
|
|
152 |
|
|
153 |
// -----------------------------------------------------------------------------
|
|
154 |
// HandleVisualRemoved
|
|
155 |
// Remove the layout associated with the visual, if any.
|
|
156 |
// -----------------------------------------------------------------------------
|
|
157 |
void TGlxLayoutSplitter::HandleVisualRemoved(
|
|
158 |
const CAlfVisual* aVisual, MGlxVisualList* /*aList*/ )
|
|
159 |
{
|
|
160 |
// Try to find a layout struct with the provided visual, and remove
|
|
161 |
// it if found
|
|
162 |
TInt index = LayoutIndex( aVisual );
|
|
163 |
if( index != KErrNotFound )
|
|
164 |
{
|
|
165 |
iLayouts.Remove( index );
|
|
166 |
}
|
|
167 |
}
|
|
168 |
|
|
169 |
// -----------------------------------------------------------------------------
|
|
170 |
// HandleFocusChangedL
|
|
171 |
// -----------------------------------------------------------------------------
|
|
172 |
void TGlxLayoutSplitter::HandleFocusChangedL(
|
|
173 |
TInt /*aFocusIndex*/,
|
|
174 |
TReal32 /*aItemsPerSecond*/,
|
|
175 |
MGlxVisualList* /*aList*/,
|
|
176 |
NGlxListDefs::TFocusChangeType /*aType*/ )
|
|
177 |
{
|
|
178 |
// Do nothing
|
|
179 |
}
|
|
180 |
|
|
181 |
// -----------------------------------------------------------------------------
|
|
182 |
// HandleSizeChanged
|
|
183 |
// -----------------------------------------------------------------------------
|
|
184 |
void TGlxLayoutSplitter::HandleSizeChanged(
|
|
185 |
const TSize& /*aSize*/, MGlxVisualList* /*aList*/ )
|
|
186 |
{
|
|
187 |
// Do nothing
|
|
188 |
}
|
|
189 |
|
|
190 |
// -----------------------------------------------------------------------------
|
|
191 |
// Returns the layout associated with the aInIndex, or NULL if not found
|
|
192 |
// -----------------------------------------------------------------------------
|
|
193 |
MGlxLayout* TGlxLayoutSplitter::Layout(
|
|
194 |
const CAlfVisual* aVisual ) const
|
|
195 |
{
|
|
196 |
// Find the layout that is intended for this visual
|
|
197 |
TInt index = LayoutIndex( aVisual );
|
|
198 |
if( index != KErrNotFound )
|
|
199 |
{
|
|
200 |
return iLayouts[ index ].iLayout;
|
|
201 |
}
|
|
202 |
return NULL;
|
|
203 |
}
|
|
204 |
|
|
205 |
// -----------------------------------------------------------------------------
|
|
206 |
// Returns layout struct index or KErrNotFound
|
|
207 |
// -----------------------------------------------------------------------------
|
|
208 |
TInt TGlxLayoutSplitter::LayoutIndex(
|
|
209 |
const CAlfVisual* aVisual ) const
|
|
210 |
{
|
|
211 |
// search if there already is a layout for this visual
|
|
212 |
TLayout temp;
|
|
213 |
temp.iVisual = aVisual;
|
|
214 |
return iLayouts.Find( temp, TLayout::Match );
|
|
215 |
}
|
|
216 |
|
|
217 |
// -----------------------------------------------------------------------------
|
|
218 |
// TGlxLayoutSplitter::Match
|
|
219 |
// -----------------------------------------------------------------------------
|
|
220 |
TBool TGlxLayoutSplitter::TLayout::Match(
|
|
221 |
const TLayout& aLhs, const TLayout& aRhs )
|
|
222 |
{
|
|
223 |
// return true if the visuals are same
|
|
224 |
return aLhs.iVisual == aRhs.iVisual;
|
|
225 |
}
|
|
226 |
|