|
1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Window redraw code, three sorts of redrawing are supported |
|
15 // This class deals with drawing from backup bitmap |
|
16 // |
|
17 // |
|
18 |
|
19 #include "backedupwindow.h" |
|
20 #include "server.h" |
|
21 #include "gc.h" |
|
22 #include "wstop.h" |
|
23 #include "ANIM.H" |
|
24 #include "EVQUEUE.H" |
|
25 #include <s32mem.h> |
|
26 #include <gdi.h> |
|
27 #include "panics.h" |
|
28 #include "inifile.h" |
|
29 #include "rootwin.h" |
|
30 #include "EVENT.H" |
|
31 #include "playbackgc.h" |
|
32 |
|
33 CFbsBitGc *CWsBackedUpWindow::iBitGc=NULL; |
|
34 |
|
35 CWsBackedUpWindow::CWsBackedUpWindow(CWsWindow *aWin, TDisplayMode aDisplayMode) : CWsWindowRedraw(aWin), iDisplayMode(aDisplayMode) |
|
36 {} |
|
37 |
|
38 void CWsBackedUpWindow::StaticInitL() |
|
39 { |
|
40 iBitGc=CFbsBitGc::NewL(); |
|
41 } |
|
42 |
|
43 void CWsBackedUpWindow::StaticDestroy() |
|
44 { |
|
45 delete iBitGc; |
|
46 iBitGc = 0; |
|
47 } |
|
48 |
|
49 void CWsBackedUpWindow::ActivateGc() |
|
50 { |
|
51 iBitGc->Activate(iBitmapDevice); |
|
52 iBitGc->Reset(); |
|
53 iBitGc->SetBrushColor(BackColor()); |
|
54 } |
|
55 |
|
56 TBool CWsBackedUpWindow::DrawCommand(CWsGc*,const TAny*) |
|
57 { |
|
58 Screen()->AddRedrawRegion(iWsWin->VisibleRegion()); |
|
59 return ETrue; |
|
60 } |
|
61 |
|
62 void CWsBackedUpWindow::ConstructL() |
|
63 { |
|
64 iDisplayMode=iWsWin->DisplayMode(); |
|
65 TSize size=iWsWin->Size(); |
|
66 iBitmap=new(ELeave) CFbsBitmap(); |
|
67 User::LeaveIfError(iBitmap->Create(size, iDisplayMode)); |
|
68 iBitmapDevice=CFbsBitmapDevice::NewL(iBitmap); |
|
69 SetSizeInTwips(); |
|
70 // |
|
71 ActivateGc(); |
|
72 iBitGc->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha); |
|
73 iBitGc->Clear(TRect(size)); |
|
74 iBitGc->SetDrawMode(CGraphicsContext::EDrawModePEN); |
|
75 WS_ASSERT_DEBUG(iWsWin->WinType()==EWinTypeClient,EWsPanicWindowType); |
|
76 } |
|
77 |
|
78 void CWsBackedUpWindow::PrepareForResizeL(const TSize &aSize, TSize &aOldSize) |
|
79 { |
|
80 aOldSize=iBitmapDevice->SizeInPixels(); |
|
81 if (aOldSize!=aSize) |
|
82 { |
|
83 User::LeaveIfError(iBitmapDevice->Resize(aSize)); |
|
84 SetSizeInTwips(); |
|
85 } |
|
86 } |
|
87 |
|
88 void CWsBackedUpWindow::Resize(const TSize &aSize, const TSize &aOldSize) |
|
89 { |
|
90 ActivateGc(); |
|
91 iBitGc->SetClippingRegion(NULL); |
|
92 iBitGc->Clear(TRect(aOldSize.iWidth, 0, aSize.iWidth, aOldSize.iHeight)); |
|
93 iBitGc->Clear(TRect(0, aOldSize.iHeight,aSize.iWidth, aSize.iHeight)); |
|
94 |
|
95 static_cast<CWsClientWindow *>(iWsWin)->ReactivateGcs(); |
|
96 } |
|
97 |
|
98 CWsBackedUpWindow::~CWsBackedUpWindow() |
|
99 { |
|
100 delete iBitmapDevice; |
|
101 delete iBitmap; |
|
102 } |
|
103 |
|
104 TBool CWsBackedUpWindow::CommandL(TInt aOpcode, TWsWinCmdUnion &aCmd) |
|
105 { |
|
106 switch(aOpcode) |
|
107 { |
|
108 case EWsWinOpUpdateBackupBitmap: |
|
109 break; |
|
110 case EWsWinOpMaintainBackup: |
|
111 break; |
|
112 case EWsWinOpBitmapHandle: |
|
113 SetReply(iBitmap->Handle()); |
|
114 break; |
|
115 case EWsWinOpUpdateScreen: |
|
116 { |
|
117 // Andy - shouldn't this use the base area? Or don't we allow funny shaped |
|
118 // backup windows? |
|
119 TRegionFix<1> fixRegion(iWsWin->AbsRect()); |
|
120 Screen()->AddRedrawRegion(fixRegion); |
|
121 } |
|
122 break; |
|
123 case EWsWinOpUpdateScreenRegion: |
|
124 { |
|
125 TRegionFix<1> fixRegion(iWsWin->AbsRect()); |
|
126 RWsRegion *clientRegion=NULL; |
|
127 TRAPD(err,clientRegion=GetRegionFromClientL(iWsWin->WsOwner(), *aCmd.Int)); |
|
128 if (err==KErrNone) |
|
129 { |
|
130 clientRegion->Offset(iWsWin->Origin()); |
|
131 clientRegion->ClipRect(iWsWin->AbsRect()); |
|
132 Screen()->AddRedrawRegion(*static_cast<TRegion*>(clientRegion)); |
|
133 clientRegion->Destroy(); |
|
134 } |
|
135 else |
|
136 { |
|
137 Screen()->AddRedrawRegion(fixRegion); |
|
138 } |
|
139 } |
|
140 break; |
|
141 default: |
|
142 return(EFalse); |
|
143 } |
|
144 return(ETrue); |
|
145 } |
|
146 |
|
147 CWsBackedUpWindow *CWsBackedUpWindow::Backup() const |
|
148 { |
|
149 return((CWsBackedUpWindow *)this); |
|
150 } |
|
151 |
|
152 CFbsDevice* CWsBackedUpWindow::OutputDevice() const |
|
153 { |
|
154 return iBitmapDevice; |
|
155 } |
|
156 |
|
157 TRgb CWsBackedUpWindow::BackColor() const |
|
158 { |
|
159 return(iWsWin->RootWindow()->DefaultBackgroundColor()); |
|
160 } |
|
161 |
|
162 void CWsBackedUpWindow::Scroll(const TRect &aClipRect, const TPoint &aOffset,const TRect &aRect) |
|
163 { |
|
164 TRect winBorder=TRect(iWsWin->Size()); |
|
165 TRect clipRect=aClipRect; |
|
166 TRect srcRect = aRect; |
|
167 clipRect.Intersection(winBorder); |
|
168 if (!clipRect.IsEmpty()) |
|
169 { // If we have to do something (a visible part will change) |
|
170 srcRect.Intersection(clipRect); |
|
171 |
|
172 STACK_REGION regionToClear; |
|
173 regionToClear.AddRect(aRect); |
|
174 regionToClear.SubRect(srcRect); |
|
175 regionToClear.Offset(aOffset); |
|
176 |
|
177 ActivateGc(); |
|
178 iBitGc->SetClippingRect(clipRect); |
|
179 iBitGc->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha); |
|
180 iBitGc->CopyRect(aOffset,srcRect); |
|
181 for (TInt k=0;k<regionToClear.Count();k++) |
|
182 { |
|
183 iBitGc->Clear(regionToClear[k]); |
|
184 } |
|
185 iBitGc->SetClippingRect(winBorder); |
|
186 iBitGc->SetDrawMode(CGraphicsContext::EDrawModePEN); |
|
187 TRegionFix<1> fixRegion(iWsWin->AbsRect()); |
|
188 Screen()->AddRedrawRegion(fixRegion); |
|
189 regionToClear.Close(); |
|
190 } |
|
191 } |
|
192 |
|
193 TBool CWsBackedUpWindow::NeedsRedraw() const |
|
194 { |
|
195 return(EFalse); |
|
196 } |
|
197 |
|
198 TBool CWsBackedUpWindow::GetRedrawRect(TRect &) const |
|
199 { |
|
200 return(EFalse); |
|
201 } |
|
202 |
|
203 void CWsBackedUpWindow::SetSizeInTwips() |
|
204 { |
|
205 TSize size=iBitmap->SizeInPixels(); |
|
206 size.iWidth=Screen()->ScreenDevice()->HorizontalPixelsToTwips(size.iWidth); |
|
207 size.iHeight=Screen()->ScreenDevice()->VerticalPixelsToTwips(size.iHeight); |
|
208 iBitmap->SetSizeInTwips(size); |
|
209 } |
|
210 |
|
211 void CWsBackedUpWindow::DrawWindow() |
|
212 { |
|
213 CFbsBitGc& gc = CPlaybackGc::Instance()->BitGc(); |
|
214 gc.SetUserDisplayMode(iWsWin->DisplayMode()); |
|
215 gc.SetOrigin(iWsWin->Origin()); |
|
216 gc.SetClippingRegion(iGlobalRedrawRegion); |
|
217 gc.BitBlt(TPoint(0,0), iBitmap); |
|
218 } |