|
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: Utility class for managing the screen size |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 /** |
|
21 * @internal reviewed 24/08/2007 by D Holland |
|
22 */ |
|
23 |
|
24 // CLASS HEADER |
|
25 #include "glxresolutionutility.h" |
|
26 |
|
27 // EXTERNAL INCLUDES |
|
28 #include <AknUtils.h> // for AknLayoutUtils |
|
29 |
|
30 // INTERNAL INCLUDES |
|
31 #include <glxsingletonstore.h> // for singletonstore |
|
32 #include "mglxresolutionchangeobserver.h" // for MGlxResolutionChangeObserver |
|
33 |
|
34 #include <glxpanic.h> |
|
35 |
|
36 //----------------------------------------------------------------------------- |
|
37 // CGlxResolutionUtility::InstanceL |
|
38 //----------------------------------------------------------------------------- |
|
39 // |
|
40 EXPORT_C CGlxResolutionUtility* CGlxResolutionUtility::InstanceL() |
|
41 { |
|
42 GLX_LOG_INFO("CGlxResolutionUtility::InstanceL"); |
|
43 CGlxResolutionUtility* self = CGlxSingletonStore::InstanceL( &NewL ); |
|
44 return self; |
|
45 } |
|
46 |
|
47 //----------------------------------------------------------------------------- |
|
48 // CGlxResolutionUtility::Close |
|
49 //----------------------------------------------------------------------------- |
|
50 // |
|
51 EXPORT_C void CGlxResolutionUtility::Close() |
|
52 { |
|
53 GLX_LOG_INFO("CGlxResolutionUtility::Close"); |
|
54 CGlxSingletonStore::Close( this ); |
|
55 } |
|
56 |
|
57 //----------------------------------------------------------------------------- |
|
58 // ScreenSize |
|
59 //----------------------------------------------------------------------------- |
|
60 // |
|
61 EXPORT_C TSize CGlxResolutionUtility::ScreenSize() const |
|
62 { |
|
63 GLX_LOG_INFO("CGlxResolutionUtility::ScreenSize"); |
|
64 return iScreenSize; |
|
65 } |
|
66 |
|
67 //----------------------------------------------------------------------------- |
|
68 // PixelsToPoss |
|
69 //----------------------------------------------------------------------------- |
|
70 // |
|
71 EXPORT_C TReal32 CGlxResolutionUtility::PixelsToPoss( |
|
72 const TReal32& aPixelLen ) const |
|
73 { |
|
74 GLX_LOG_INFO("CGlxResolutionUtility::PixelsToPoss"); |
|
75 // Screen = 240 : 320 |
|
76 // POSS = .75 : 1 |
|
77 // aPixelLen= 240 |
|
78 // retVal = .75 |
|
79 return aPixelLen * iPixelToPossRatio; |
|
80 } |
|
81 |
|
82 //----------------------------------------------------------------------------- |
|
83 // PossToPixels |
|
84 //----------------------------------------------------------------------------- |
|
85 // |
|
86 EXPORT_C TReal32 CGlxResolutionUtility::PossToPixels( |
|
87 const TReal32& aPossLen ) const |
|
88 { |
|
89 GLX_LOG_INFO("CGlxResolutionUtility::PossToPixels"); |
|
90 // Screen = 240 : 320 |
|
91 // POSS = .75 : 1 |
|
92 // aLenPoss = .75 |
|
93 // retVal = 240 |
|
94 return aPossLen * iOnePossToPixelRatio; |
|
95 } |
|
96 |
|
97 |
|
98 |
|
99 //----------------------------------------------------------------------------- |
|
100 // AddObserverL. |
|
101 //----------------------------------------------------------------------------- |
|
102 // |
|
103 EXPORT_C void CGlxResolutionUtility::AddObserverL( |
|
104 MGlxResolutionChangeObserver& aObserver ) |
|
105 { |
|
106 GLX_LOG_INFO( "CGlxResolutionUtility::AddObserverL" ); |
|
107 if( KErrNotFound == iObserverList.Find( &aObserver ) ) |
|
108 { |
|
109 iObserverList.AppendL( &aObserver ); |
|
110 } |
|
111 } |
|
112 |
|
113 |
|
114 |
|
115 //----------------------------------------------------------------------------- |
|
116 // RemoveObserver |
|
117 //----------------------------------------------------------------------------- |
|
118 // |
|
119 EXPORT_C void CGlxResolutionUtility::RemoveObserver( |
|
120 MGlxResolutionChangeObserver& aObserver ) |
|
121 { |
|
122 GLX_LOG_INFO("CGlxResolutionUtility::RemoveObserver"); |
|
123 |
|
124 TInt index = iObserverList.Find( &aObserver ); |
|
125 if ( KErrNotFound != index ) |
|
126 { |
|
127 iObserverList.Remove( index ); |
|
128 } |
|
129 } |
|
130 |
|
131 //----------------------------------------------------------------------------- |
|
132 // HandleScreenSizeChanged |
|
133 //----------------------------------------------------------------------------- |
|
134 // |
|
135 void CGlxResolutionUtility::SetScreenSizeL( TSize aScreenSize ) |
|
136 { |
|
137 GLX_LOG_INFO("CGlxResolutionUtility::HandleScreenSizeChanged"); |
|
138 |
|
139 if( iScreenSize != aScreenSize ) |
|
140 { |
|
141 // "Percentage Of Screen Size". A unit of measurement, in which 1.0 |
|
142 // is as long as the longer edge of the screen. |
|
143 iOnePossToPixelRatio = |
|
144 ( aScreenSize.iHeight > aScreenSize.iWidth ) ? |
|
145 aScreenSize.iHeight : aScreenSize.iWidth; |
|
146 // calculate the multiplier |
|
147 iPixelToPossRatio = 1.0 / iOnePossToPixelRatio; |
|
148 iScreenSize = aScreenSize; |
|
149 |
|
150 // Notify observers of a change in the screen resolution |
|
151 TInt ii = iObserverList.Count(); |
|
152 while ( ii-- > 0 ) |
|
153 { |
|
154 iObserverList[ ii ]->HandleResolutionChangedL(); |
|
155 } |
|
156 } |
|
157 } |
|
158 |
|
159 //----------------------------------------------------------------------------- |
|
160 // NewL |
|
161 //----------------------------------------------------------------------------- |
|
162 // |
|
163 CGlxResolutionUtility* CGlxResolutionUtility::NewL() |
|
164 { |
|
165 GLX_LOG_INFO("CGlxResolutionUtility::NewL"); |
|
166 CGlxResolutionUtility* self = new( ELeave ) CGlxResolutionUtility; |
|
167 self->ConstructL(); |
|
168 return self; |
|
169 } |
|
170 |
|
171 //----------------------------------------------------------------------------- |
|
172 // ~CGlxResolutionUtility |
|
173 //----------------------------------------------------------------------------- |
|
174 // |
|
175 CGlxResolutionUtility::CGlxResolutionUtility() |
|
176 { |
|
177 // Do Nothing |
|
178 } |
|
179 |
|
180 //----------------------------------------------------------------------------- |
|
181 // ConstructL |
|
182 //----------------------------------------------------------------------------- |
|
183 // |
|
184 void CGlxResolutionUtility::ConstructL() |
|
185 { |
|
186 // set the initial screen size |
|
187 // ask avkon for the full screen size |
|
188 TRect screen; |
|
189 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EScreen, screen ); |
|
190 // set the initial size |
|
191 SetScreenSizeL( screen.Size() ); |
|
192 } |
|
193 |
|
194 |
|
195 //----------------------------------------------------------------------------- |
|
196 // ~CGlxResolutionUtility |
|
197 //----------------------------------------------------------------------------- |
|
198 // |
|
199 CGlxResolutionUtility::~CGlxResolutionUtility() |
|
200 { |
|
201 GLX_LOG_INFO("CGlxResolutionUtility::~CGlxResolutionUtility"); |
|
202 // Close the observer array |
|
203 iObserverList.Close(); |
|
204 } |