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