|
1 // screenmngr.cpp |
|
2 // |
|
3 // Copyright (c) 2009 - 2010 Accenture. All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of the "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 // Accenture - Initial contribution |
|
11 // |
|
12 |
|
13 #include <e32base.h> |
|
14 |
|
15 #include "screenmngr.h" |
|
16 #include "viewbase.h" |
|
17 |
|
18 const TInt KCmdWndMinHeight = 3; |
|
19 const TInt KCmdWndMinWidth = 20; |
|
20 const TInt KRM = 1000; //const multiplication to avoid inexact calculations on small numbers |
|
21 |
|
22 void CScreenManager::ResizeScreenL(const TWindow& aWindow) |
|
23 { |
|
24 if(aWindow.iHeight < KCmdWndMinHeight |
|
25 || aWindow.iWidth < KCmdWndMinWidth) |
|
26 User::Leave(KErrNotSupported); |
|
27 |
|
28 if(aWindow == iScreenWnd) |
|
29 return; |
|
30 |
|
31 //We need to leave one char on each side for the border around the console window, so the width/height is actually less by 2 |
|
32 iMainWnd.iX = iCmdWnd.iX = aWindow.iX; |
|
33 iMainWnd.iWidth = iCmdWnd.iWidth = aWindow.iWidth + KConsoleWidthCorrection; |
|
34 iMainWnd.iY = aWindow.iY; |
|
35 |
|
36 //Based on proportions of windows on the old screen calculate proportions on the new screen |
|
37 TInt newcmdh = 1; |
|
38 if(iScreenWnd.iHeight) |
|
39 { |
|
40 newcmdh = ((iCmdWnd.iHeight*KRM) * (aWindow.iHeight*KRM)) / iScreenWnd.iHeight*KRM*KRM; |
|
41 if(newcmdh >= aWindow.iHeight) |
|
42 newcmdh = aWindow.iHeight/2; |
|
43 } |
|
44 iCmdWnd.iHeight = newcmdh > 0 ? newcmdh : 1; |
|
45 iMainWnd.iHeight = aWindow.iHeight - iCmdWnd.iHeight + KConsoleWidthCorrection; |
|
46 iCmdWnd.iY = aWindow.iY + iMainWnd.iHeight; |
|
47 iScreenWnd = aWindow; |
|
48 |
|
49 if(iCurrentView) |
|
50 iCurrentView->ResizeL(iMainWnd); |
|
51 } |
|
52 |
|
53 const TWindow& CScreenManager::ResizeCommandWindowL(TInt aHeight) |
|
54 { |
|
55 if(aHeight == iCmdWnd.iHeight) |
|
56 return iCmdWnd; |
|
57 |
|
58 //resize the main and cmd windows |
|
59 if(aHeight > iScreenWnd.iHeight) |
|
60 aHeight = iScreenWnd.iHeight; |
|
61 |
|
62 iCmdWnd.iHeight = aHeight; |
|
63 iMainWnd.iHeight = iScreenWnd.iHeight - iCmdWnd.iHeight; |
|
64 iCmdWnd.iY = iScreenWnd.iY + iMainWnd.iHeight; |
|
65 |
|
66 if(iCurrentView) |
|
67 iCurrentView->ResizeL(iMainWnd); |
|
68 |
|
69 return iCmdWnd; |
|
70 } |
|
71 |
|
72 void CScreenManager::AddViewL(MViewController& aView) |
|
73 { |
|
74 //Here create a new window if necessary |
|
75 AttachViewL(aView); |
|
76 } |
|
77 |
|
78 void CScreenManager::AttachViewL(MViewController& aView) |
|
79 { |
|
80 if(iCurrentView) |
|
81 { |
|
82 iCurrentView->DeactivateL(); |
|
83 } |
|
84 |
|
85 iCurrentView = &aView; |
|
86 iCurrentView->RedrawL(iMainWnd); |
|
87 } |
|
88 |
|
89 void CScreenManager::UnsetCurrentView() |
|
90 { |
|
91 iCurrentView = NULL; |
|
92 } |
|
93 |
|
94 void CScreenManager::RefreshScreenL() |
|
95 { |
|
96 if (iCurrentView) iCurrentView->RedrawL(iMainWnd); |
|
97 } |