Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
26 #include "windowgroup.h"
30 #include "../CLIENT/w32comm.h"
33 const TInt KEikSrvsSid=0x10003a4a;
35 static _LIT_SECURITY_POLICY_C1(KSecurityPolicy_WriteDeviceData,ECapabilityWriteDeviceData);
39 DWsScreenDevice::DWsScreenDevice(CWsClient* aOwner, TInt aDefaultScreenNumber, TUint aClientScreenDevicePointer)
40 : CWsScreenObject(aOwner, WS_HANDLE_SCREEN_DEVICE, CWsTop::Screen( aDefaultScreenNumber )),
41 iClientScreenDevicePointer(aClientScreenDevicePointer)
44 DWsScreenDevice::~DWsScreenDevice()
47 void DWsScreenDevice::CopyScreenToBitmapL(const TRect &aRect, TInt aHandle)
49 CFbsBitmap *bitmap=new(ELeave) CFbsBitmap();
50 CleanupStack::PushL(bitmap);
51 TInt ret = bitmap->Duplicate(aHandle);
52 if (ret == KErrNoMemory)
57 OwnerPanic(EWservPanicBitmap);
59 CFbsBitmapDevice *device=CFbsBitmapDevice::NewL(bitmap);
60 CleanupStack::PushL(device);
62 User::LeaveIfError(device->CreateContext(gc));
63 CleanupStack::PushL(gc); //Don't need to push this, but this is probably the eaiest way to delete it
64 gc->SetDrawMode( CGraphicsContext::EDrawModeWriteAlpha );
65 gc->BitBlt(TPoint(), *iScreen->ScreenGdi(), aRect);
66 CleanupStack::PopAndDestroy(3);
69 void DWsScreenDevice::CommandL(TInt aOpcode, const TAny *aCmdData)
75 case EWsSdOpGetNumScreenModes:
76 SetReply(iScreen->NumScreenSizeModes());
78 case EWsSdOpGetScreenMode:
79 SetReply(iScreen->ScreenSizeMode());
81 case EWsSdOpSetScreenMode:
83 if(!KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for CWsScreenDevice::SetScreenMode API")))
85 iWsOwner->PPanic(EWservPanicPermissionDenied);
87 SetScreenMode(*pData.Int);
90 case EWsSdOpSetModeRotation:
92 if(KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for CWsScreenDevice::SetModeRotation API")))
94 TClientPanic panic=iScreen->SetModeRotation(pData.SetScreenRotation->mode,pData.SetScreenRotation->rotation);
100 case EWsSdOpGetRotationList:
101 if (!iScreen->IsValidScreenSizeMode(*pData.Int))
102 OwnerPanic(EWservPanicScreenModeNumber);
103 SetReply(iScreen->ScreenSizeModeData(*pData.Int).iAlternativeRotations);
105 case EWsSdOpGetScreenModeSizeAndRotation:
106 GetScreenSizeAndRotationCmd(*pData.Int);
108 case EWsSdOpGetScreenModeSizeAndRotation2:
109 GetScreenSizeAndRotationCmd2(*pData.Int);
111 case EWsSdOpSetScreenSizeAndRotation:
112 SetScreenSizeAndRotation(*pData.PixelsTwipsAndRotation);
114 case EWsSdOpSetScreenSizeAndRotation2:
115 SetScreenSizeAndRotation(*pData.PixelsAndRotation);
117 case EWsSdOpGetDefaultScreenSizeAndRotation:
118 GetScreenSizeAndRotationCmd(iScreen->ScreenSizeMode());
120 case EWsSdOpGetDefaultScreenSizeAndRotation2:
121 GetScreenSizeAndRotationCmd2(iScreen->ScreenSizeMode());
123 case EWsSdOpGetScreenModeDisplayMode:
124 GetScreenModeDisplayMode(*pData.Int);
126 case EWsSdOpGetScreenModeScale:
127 GetScreenScale(*pData.Int);
129 case EWsSdOpGetCurrentScreenModeScale:
130 GetScreenScale(iScreen->ScreenSizeMode());
132 case EWsSdOpSetAppScreenMode:
133 SetAppScreenMode(*pData.Int);
135 case EWsSdOpGetCurrentScreenModeScaledOrigin:
136 CWsClient::ReplyPoint(iScreen->CurrentScreenModeScaledOrigin());
138 case EWsSdOpGetScreenModeScaledOrigin:
139 if (!iScreen->IsValidScreenSizeMode(*pData.Int))
140 OwnerPanic(EWservPanicScreenModeNumber);
141 CWsClient::ReplyPoint(iScreen->ScreenModeScaledOrigin(*pData.Int));
143 case EWsSdOpGetCurrentScreenModeAttributes:
144 GetCurrentScreenModeAttributes();
146 case EWsSdOpSetCurrentScreenModeAttributes:
147 if(!KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for CWsScreenDevice::SetCurrentScreenModeAttributes API, API should be used for test purposes only")))
149 iWsOwner->PPanic(EWservPanicPermissionDenied);
151 SetCurrentScreenModeAttributes(*pData.ScreenSizeMode);
153 case EWsSdOpSetScreenModeEnforcement:
155 if(!KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for CWsScreenDevice::SetScreenModeEnforcement API")))
157 iWsOwner->PPanic(EWservPanicPermissionDenied);
159 if (!iScreen->SetScreenModeEnforcement(*pData.Int))
160 OwnerPanic(EWservPanicScreenEnforcementMode);
163 case EWsSdOpScreenModeEnforcement:
164 SetReply(iScreen->SizeEnforcementMode());
166 case EWsSdOpGetDefaultScreenModeOrigin:
167 GetScreenModeOriginCmd(iScreen->ScreenSizeMode());
169 case EWsSdOpGetScreenModeOrigin:
170 GetScreenModeOriginCmd(*pData.Int);
175 iScreen->ScreenDevice()->GetPixel(rgb,*pData.Point);
176 SetReply(rgb.Internal());
179 case EWsSdOpGetScanLine:
180 iScreen->GetScanLine(pData.GetScanLine);
182 case EWsSdOpTwipsSize:
183 CWsClient::ReplySize(iAppScreenSizeInTwips);
185 case EWsSdOpPixelSize:
186 CWsClient::ReplySize(iAppScreenSizeInPixels);
188 case EWsSdOpHorizontalTwipsToPixels:
189 SetReply(iScreen->ScreenDevice()->HorizontalTwipsToPixels(*pData.UInt));
191 case EWsSdOpVerticalTwipsToPixels:
192 SetReply(iScreen->ScreenDevice()->VerticalTwipsToPixels(*pData.UInt));
194 case EWsSdOpHorizontalPixelsToTwips:
195 SetReply(iScreen->ScreenDevice()->HorizontalPixelsToTwips(*pData.UInt));
197 case EWsSdOpVerticalPixelsToTwips:
198 SetReply(iScreen->ScreenDevice()->VerticalPixelsToTwips(*pData.UInt));
200 case EWsSdOpPointerRect:
202 TMachineInfoV1Buf macInfo;
203 UserHal::MachineInfo(macInfo);
204 TRect rect(-macInfo().iOffsetToDisplayInPixels,macInfo().iXYInputSizeInPixels);
205 CWsClient::ReplyRect(rect);
210 // Mark any group windows associated with the screen device being deleted
211 CWsRootWindow* root=iScreen->RootWindow();
212 for (CWsWindowGroup* grp = root->Child(); grp; grp = grp->NextSibling())
214 if (grp->Device() == this)
217 grp->SetScreenDeviceDeleted();
219 grp->SetScreenDevice(NULL);
223 // Let our owner (CWsClient) know that a screen device is being deleted so it
224 // can check whether to reset its iPrimaryScreenDevice member or not
226 WsOwner()->NotifyScreenDeviceDeleted(this);
229 case EWsSdOpDisplayMode:
230 iScreen->ScreenGdi(); // To force display mode update if required
231 SetReply(iScreen->CurrentDisplayMode());
233 case EWsSdOpRectCompare:
235 // if (pData.RectCompare->flags&CWsScreenDevice::EIncludeSprite)
237 // SpriteManager()->IncrementProcessingSprites();
240 RWsTextCursor * cursor = 0;
241 if (!pData.RectCompare->flags&CWsScreenDevice::EIncludeTextCursor)
242 cursor = CWsTop::CurrentTextCursor();
246 SetReply(iScreen->ScreenDevice()->RectCompare(pData.RectCompare->rect1,*iScreen->ScreenDevice(),pData.RectCompare->rect2));
251 // if (pData.RectCompare->flags&CWsScreenDevice::EIncludeSprite)
253 // SpriteManager()->DecrementProcessingSprites();
257 case EWsSdOpCopyScreenToBitmap:
258 CopyScreenToBitmapL(TRect(iScreen->ScreenDevice()->SizeInPixels()),pData.CopyScreenToBitmap->handle);
260 case EWsSdOpCopyScreenToBitmap2:
261 CopyScreenToBitmapL(pData.CopyScreenToBitmap2->rect,pData.CopyScreenToBitmap2->handle);
263 case EWsSdOpPaletteAttributes:
267 iScreen->ScreenDevice()->PaletteAttributes(modifiable,numEntries);
269 numEntries|=EWsSdSetableBitFlag;
270 SetReply(numEntries);
273 case EWsSdOpSetPalette:
275 if(!KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for CWsScreenDevice::SetPalette API")))
277 User::Leave(KErrPermissionDenied);
282 case EWsSdOpGetPalette:
283 GetPalette(*pData.Int);
286 case EWsSdOpGetScreenNumber:
287 SetReply(iScreen->ScreenNumber());
289 case EWsSdOpGetScreenSizeModeList:
290 SetReply(iScreen->GetScreenSizeModeListL());
292 case EWsClOpSetBackLight:
295 if(Screen()->BackLightFlag() && iWsOwner->ClientMessage().SecureId()==KEikSrvsSid)
297 TWindowServerEvent::ProcessErrorMessages(TWsErrorMessage::EBackLight, err=HAL::Set(iScreen->ScreenNumber(),HALData::EBacklightState,*pData.Int));
302 User::Leave(KErrPermissionDenied);
307 OwnerPanic(EWservPanicOpcode);
313 void DWsScreenDevice::SetScreenMode(TInt aMode)
315 if (!iScreen->IsValidScreenSizeMode(aMode))
316 OwnerPanic(EWservPanicScreenModeNumber);
317 iScreen->doSetScreenMode(aMode);
320 TBool DWsScreenDevice::ScreenDeviceValidState() const
322 WS_ASSERT_DEBUG(iScreen->IsValidScreenSizeMode(iScreen->ScreenSizeMode()), EWsPanicInvalidScreenSizeMode);
323 const TSizeMode& currentMode=iScreen->ScreenSizeModeData();
325 // In all enforcement modes scale should match, so check scale first
326 if (currentMode.iScreenScale!=iAppScale)
332 if (iScreen->SizeEnforcementMode()!=ESizeEnforcementNone)
334 if (currentMode.iRotation!=iAppRotation)
336 else if (currentMode.iScreenSize!=iAppScreenSizeInPixels)
339 if (iScreen->SizeEnforcementMode()==ESizeEnforcementPixelsTwipsAndRotation)
341 if (currentMode.iScreenTwipsSize!=iAppScreenSizeInTwips)
348 void DWsScreenDevice::ConstructL()
350 // App specific construct
354 const TSizeMode& mode=iScreen->ScreenSizeModeData(iScreen->ScreenSizeMode());
355 iAppScreenSizeInPixels=mode.iScreenSize;
356 iAppScreenSizeInTwips=mode.iScreenTwipsSize;
357 iAppRotation=mode.iRotation;
358 iAppMode=iScreen->ScreenSizeMode();
359 iAppScale=mode.iScreenScale;
362 void DWsScreenDevice::SetScreenSizeAndRotation(const TPixelsTwipsAndRotation &aSar)
364 iAppScreenSizeInPixels=aSar.iPixelSize;
365 iAppScreenSizeInTwips=aSar.iTwipsSize;
366 iAppRotation=aSar.iRotation;
367 SetScreenDeviceValidStates(this);
370 void DWsScreenDevice::SetScreenSizeAndRotation(const TPixelsAndRotation &aSar)
372 iAppScreenSizeInPixels=aSar.iPixelSize;
373 iAppScreenSizeInTwips.iWidth=iScreen->ScreenDevice()->HorizontalPixelsToTwips(iAppScreenSizeInPixels.iWidth);
374 iAppScreenSizeInTwips.iHeight=iScreen->ScreenDevice()->VerticalPixelsToTwips(iAppScreenSizeInPixels.iHeight);
375 iAppRotation=aSar.iRotation;
376 SetScreenDeviceValidStates(this);
379 void DWsScreenDevice::GetScreenModeOriginCmd(TInt aMode)
381 if (!iScreen->IsValidScreenSizeMode(aMode))
382 OwnerPanic(EWservPanicScreenModeNumber);
383 CWsClient::ReplyPoint(iScreen->ScreenModeOrigin(aMode));
386 void DWsScreenDevice::GetCurrentScreenModeAttributes()
388 TSizeMode aModeData=iScreen->ScreenSizeModeData();
389 CWsClient::ReplyBuf(&aModeData,sizeof(aModeData));
392 void DWsScreenDevice::SetCurrentScreenModeAttributes(const TSizeMode &aModeData)
395 if (aModeData.iScreenScale.iWidth==0 || aModeData.iScreenScale.iHeight==0)
396 OwnerPanic(EWservPanicScreenModeNumber);
398 iScreen->SetCurrentScreenModeAttributes(aModeData);
401 void DWsScreenDevice::GetScreenSizeAndRotationCmd(TInt aMode)
403 if (!iScreen->IsValidScreenSizeMode(aMode))
404 OwnerPanic(EWservPanicScreenModeNumber);
405 TPixelsTwipsAndRotation sar;
406 iScreen->GetScreenSizeAndRotation(sar,aMode);
407 CWsClient::ReplyBuf(&sar, sizeof(sar));
410 void DWsScreenDevice::GetScreenSizeAndRotationCmd2(TInt aMode)
412 if (!iScreen->IsValidScreenSizeMode(aMode))
413 OwnerPanic(EWservPanicScreenModeNumber);
414 TPixelsAndRotation sar;
415 iScreen->GetScreenSizeAndRotation(sar,aMode);
416 CWsClient::ReplyBuf(&sar, sizeof(sar));
419 void DWsScreenDevice::GetScreenModeDisplayMode(const TInt aMode)
421 if (!iScreen->IsValidScreenSizeMode(aMode))
423 OwnerPanic(EWservPanicScreenModeNumber);
425 SetReply(STATIC_CAST(TInt,iScreen->DefaultDisplayMode(aMode)));
428 void DWsScreenDevice::GetScreenScale(TInt aMode)
430 if (!iScreen->IsValidScreenSizeMode(aMode))
432 OwnerPanic(EWservPanicScreenModeNumber);
434 CWsClient::ReplySize(iScreen->GetScreenScale(aMode));
437 void DWsScreenDevice::SetAppScreenMode(TInt aMode)
439 if (!iScreen->IsValidScreenSizeMode(aMode))
441 OwnerPanic(EWservPanicScreenModeNumber);
443 const TSizeMode& sizeMode=iScreen->ScreenSizeModeData(aMode);
444 iAppScreenSizeInPixels=sizeMode.iScreenSize;
445 iAppScreenSizeInTwips=sizeMode.iScreenTwipsSize;
447 iAppScale=sizeMode.iScreenScale;
448 iAppRotation=sizeMode.iRotation;
449 CWsWindowGroup::SetScreenDeviceValidStates(this);
452 #define ROTATION_TO_FLAG(x) 1<<x
454 void DWsScreenDevice::SetScreenDeviceValidStates(const DWsScreenDevice *aDevice)
456 TInt modes=iScreen->NumScreenSizeModes();
458 for (mode=0;mode<modes;++mode)
460 if (!iScreen->IsValidScreenSizeMode(mode))
462 const TSizeMode& sizeMode=iScreen->ScreenSizeModeData(mode);
463 if (iAppScreenSizeInPixels==sizeMode.iScreenSize && ROTATION_TO_FLAG(iAppRotation)&sizeMode.iAlternativeRotations)
466 iAppScale=sizeMode.iScreenScale;
470 CWsWindowGroup::SetScreenDeviceValidStates(aDevice);
473 void DWsScreenDevice::NewOrientation(TInt aMode,CFbsBitGc::TGraphicsOrientation aRotation)
476 iAppRotation=aRotation;
479 void DWsScreenDevice::SetPaletteL()
481 const TInt size=iWsOwner->ClientMessage().GetDesLength(KRemoteBufferMessageSlot);
482 TInt numEntries=size/sizeof(TRgb);
483 CPalette* palette=CPalette::NewL(numEntries);
484 CleanupStack::PushL(palette);
485 TPtr8 paletteData(NULL,0);
486 palette->GetDataPtr(0,numEntries,paletteData);
487 iWsOwner->RemoteReadL(paletteData,0);
488 SetReply(iScreen->ScreenDevice()->SetCustomPalette(palette));
489 iScreen->Update((RWsRegion&)RootWindow()->WindowArea());
490 CleanupStack::PopAndDestroy(palette);
493 void DWsScreenDevice::GetPalette(TInt aNumColors)
496 TInt ret=iScreen->ScreenDevice()->GetPalette(palette);
499 ret=palette->Entries();
507 TPtr8 paletteData(NULL,0);
508 palette->GetDataPtr(0,ret,paletteData);
509 CWsClient::ReplyBuf(paletteData);
514 TUint DWsScreenDevice::ClientDevicePointer()
516 return iClientScreenDevicePointer;