windowing/windowserver/nga/graphicdrawer/graphicdrawer.cpp
changeset 0 5d03bc08d59c
child 121 d72fc2aace31
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2005-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 // WSGRAPHIC.CPP
       
    15 // The client-side representation of a WsGraphic artwork
       
    16 // 
       
    17 //
       
    18 
       
    19 #include "../SERVER/w32cmd.h"
       
    20 #include "Graphics/WSGRAPHICDRAWER.H"
       
    21 #include <Graphics/WSGRAPHICDRAWERINTERFACE.H>
       
    22 #include <s32mem.h>
       
    23 #include "panics.h"
       
    24 
       
    25 GLDEF_C void Panic(TWsGraphicDrawerPanic aPanic)
       
    26 	{
       
    27 	_LIT(KCategory,"WsGraphicDrawer");
       
    28 	User::Panic(KCategory,aPanic);
       
    29 	}
       
    30 
       
    31 //
       
    32 // TWservCrEvent implementation
       
    33 //
       
    34 EXPORT_C TWservCrEvent::TWservCrEvent(TUint32 aType): iType(aType), iInfo(0), iData(NULL), iWindow(NULL)
       
    35 	{
       
    36 	}
       
    37 
       
    38 EXPORT_C TWservCrEvent::TWservCrEvent(TUint32 aType, TUint32 aInfo): iType(aType), iInfo(aInfo), iData(NULL), iWindow(NULL)
       
    39 	{
       
    40 	}
       
    41 
       
    42 EXPORT_C TWservCrEvent::TWservCrEvent(TUint32 aType, TUint32 aInfo, TAny* aData): iType(aType), iInfo(aInfo), iData(aData), iWindow(NULL)
       
    43 	{
       
    44 	}
       
    45 
       
    46 EXPORT_C TWservCrEvent::TWservCrEvent(TUint32 aType, TUint32 aInfo, TAny* aData, MWsWindow* aWindow): iType(aType), iInfo(aInfo), iData(aData), iWindow(aWindow)
       
    47 	{
       
    48 	}
       
    49 
       
    50 EXPORT_C TUint32 TWservCrEvent::Type() const
       
    51 	{
       
    52 	return iType;
       
    53 	}
       
    54 
       
    55 EXPORT_C TInt TWservCrEvent::SizeMode() const
       
    56 	{
       
    57 	return iInfo;
       
    58 	}
       
    59 
       
    60 EXPORT_C const RRegion* TWservCrEvent::VisibleRegion() const
       
    61 	{
       
    62 	return reinterpret_cast<RRegion*>(iData);
       
    63 	}
       
    64 
       
    65 EXPORT_C TInt TWservCrEvent::ScreenNumber() const
       
    66 	{
       
    67 	return iInfo;	
       
    68 	}
       
    69 
       
    70 EXPORT_C CFbsBitGc::TGraphicsOrientation TWservCrEvent::Orientation() const
       
    71 	{
       
    72 	return *reinterpret_cast<CFbsBitGc::TGraphicsOrientation*>(iData);
       
    73 	}
       
    74 
       
    75 EXPORT_C const TRegion* TWservCrEvent::DrawingRegion() const
       
    76 	{
       
    77 	return reinterpret_cast<TRegion*>(iData);
       
    78 	}
       
    79 
       
    80 EXPORT_C TInt TWservCrEvent::WindowGroupIdentifier() const
       
    81 	{
       
    82 	return reinterpret_cast<TInt>(iData);
       
    83 	}
       
    84 
       
    85 EXPORT_C const TSurfaceId* TWservCrEvent::SurfaceId() const
       
    86 	{
       
    87 	return reinterpret_cast<const TSurfaceId*>(iData);
       
    88 	}
       
    89 
       
    90 EXPORT_C TBool TWservCrEvent::WasVisible() const
       
    91 	{
       
    92 	return iInfo;
       
    93 	}
       
    94 
       
    95 EXPORT_C MWsWindow * TWservCrEvent::Window() const
       
    96 	{
       
    97 	return iWindow;
       
    98 	}
       
    99 
       
   100 // CWsGraphicDrawer::CPimpl \\\\\\\\\\\\\\\\\\\\\\\\
       
   101 
       
   102 NONSHARABLE_STRUCT(CWsGraphicDrawer::CPimpl): public CBase
       
   103 /** @internalComponent
       
   104 	@released
       
   105 */	{
       
   106 	enum
       
   107 		{
       
   108 		EActive			= 0x01,
       
   109 		EIsPublic		= 0x02,
       
   110 		EInContains		= 0x04,
       
   111 		EInDraw			= 0x08,
       
   112 		EDrawn			= 0x10,
       
   113 		};
       
   114 	CPimpl(CWsGraphicDrawer& aGraphic,MWsGraphicDrawerEnvironment& aEnv,MWsClient& aOwner);
       
   115 	~CPimpl();
       
   116 	CWsGraphicDrawer& iGraphic;
       
   117 	MWsGraphicDrawerEnvironment& iEnv;
       
   118 	MWsClient& iOwner;
       
   119 	TGraphicDrawerId iId;
       
   120 	RArray<TUint> iSharedWith;
       
   121 	TUint iFlags;
       
   122 	MWsEventHandler* iEventHandler;
       
   123 	};
       
   124 
       
   125 CWsGraphicDrawer::CPimpl::CPimpl(CWsGraphicDrawer& aGraphic,MWsGraphicDrawerEnvironment& aEnv,MWsClient& aOwner):
       
   126 	iGraphic(aGraphic), iEnv(aEnv), iOwner(aOwner)
       
   127 	{
       
   128 	}
       
   129 
       
   130 CWsGraphicDrawer::CPimpl::~CPimpl()
       
   131 	{
       
   132 	iSharedWith.Close();
       
   133 	}
       
   134 
       
   135 // CWsGraphicDrawer \\\\\\\\\\\\\\\\\\\\\\\\
       
   136 
       
   137 EXPORT_C CWsGraphicDrawer::CWsGraphicDrawer()
       
   138 /** Constructor
       
   139 */	{
       
   140 	}
       
   141 
       
   142 EXPORT_C CWsGraphicDrawer::~CWsGraphicDrawer()
       
   143 /** Destructor
       
   144 */	{
       
   145 //	Invalidate(); // the client will now ask for the redraw 
       
   146 	delete iPimpl;
       
   147 
       
   148 	if(KNullUid != iDtor_ID_Key)
       
   149 		{
       
   150 		REComSession::DestroyedImplementation(iDtor_ID_Key);
       
   151 		}
       
   152 	}
       
   153 
       
   154 EXPORT_C void CWsGraphicDrawer::BaseConstructL(MWsGraphicDrawerEnvironment& aEnv,const TGraphicDrawerId& aId,MWsClient& aOwner)
       
   155 /** Completes construction of the baseclass. Derived drawers should call this from their ConstructL() implementations
       
   156 	@param aEnv the environment this drawer exists in
       
   157 	@param aId the ID of this drawer
       
   158 	@param aOwner the client session that owns this drawer
       
   159 	@param aData arbitrary data for constructing this instance, sent from the client.
       
   160 */	{
       
   161 	iPimpl = new(ELeave) CPimpl(*this,aEnv,aOwner);
       
   162 	iPimpl->iId = aId;
       
   163 	}
       
   164 
       
   165 EXPORT_C MWsGraphicDrawerEnvironment& CWsGraphicDrawer::Env()
       
   166 /** The environment this drawer exists in
       
   167 	@return the environment
       
   168 */	{
       
   169 	return iPimpl->iEnv;
       
   170 	}
       
   171 
       
   172 EXPORT_C const MWsGraphicDrawerEnvironment& CWsGraphicDrawer::Env() const
       
   173 /** The environment this drawer exists in
       
   174 	@return the environment
       
   175 */	{
       
   176 	return iPimpl->iEnv;
       
   177 	}
       
   178 
       
   179 EXPORT_C const TGraphicDrawerId& CWsGraphicDrawer::Id() const
       
   180 /** The ID of this graphic
       
   181 	@return the ID
       
   182 */	{
       
   183 	return iPimpl->iId;
       
   184 	}
       
   185 
       
   186 EXPORT_C const MWsClient& CWsGraphicDrawer::Owner() const
       
   187 /** Only the owner can delete, replace or send messages to this graphic.
       
   188 	The owner and any session sharing the owner's Secure ID can always
       
   189 	draw the graphic.
       
   190 	@return the Client session which created and owns this graphic.
       
   191 */	{
       
   192 	return iPimpl->iOwner;
       
   193 	}
       
   194 
       
   195 EXPORT_C TBool CWsGraphicDrawer::IsSharedWith(TSecureId aClientId) const
       
   196 /** tests whether the client is allowed to draw this graphic
       
   197 	Conditions include whether the client is the owner of this graphic,
       
   198 	whether the graphic is shared globally, or whether this graphic
       
   199 	has been explicitly shared with the client
       
   200 	@param aClientId the Secure ID of the client session's process
       
   201 	@return ETrue if the client can draw this graphic
       
   202 */	{
       
   203 	return ((iPimpl->iFlags & CPimpl::EIsPublic) ||
       
   204 		(0 <= iPimpl->iSharedWith.FindInOrder(aClientId.iId)) ||
       
   205 		(aClientId == iPimpl->iOwner.SecureId()));
       
   206 	}
       
   207 
       
   208 EXPORT_C TInt CWsGraphicDrawer::Share(TSecureId aClientId)
       
   209 /** Explicitly shares this graphic with client sessions with the specified Secure ID
       
   210 	@param aClientId the Secure ID of the client sessions to share with
       
   211 	@return KErrNone if the graphic was shared, else one of the system-wide error codes
       
   212 */	{
       
   213 	return iPimpl->iSharedWith.InsertInOrder(aClientId.iId);
       
   214 	}
       
   215 
       
   216 EXPORT_C TInt CWsGraphicDrawer::ShareGlobally()
       
   217 /** Share this drawer with all client sessions
       
   218 	Sharing globally trumps explicit shares
       
   219 	@return KErrNone if the graphic is globally shared, else one of the system-wide error codes
       
   220 */	{
       
   221 	iPimpl->iFlags |= CPimpl::EIsPublic;
       
   222 	return KErrNone;
       
   223 	}
       
   224 
       
   225 EXPORT_C TInt CWsGraphicDrawer::UnShareGlobally()
       
   226 /** Stop this drawer from being shared with all client sessions
       
   227 	A drawer that isn't shared explicitly is only available to clients it
       
   228 	has been explicitly shared with using Share()
       
   229 	@return KErrNone if the graphic is not globally shared, else one of the system-wide error codes
       
   230 */	{
       
   231 	iPimpl->iFlags &= ~CPimpl::EIsPublic;
       
   232 	return KErrNone;
       
   233 	}
       
   234 
       
   235 EXPORT_C TInt CWsGraphicDrawer::UnShare(TSecureId aClientId)
       
   236 /** Stop this drawer from being shared with all client sessions with the specific Secure ID
       
   237 	ShareGlobally() trumps explicit sharing
       
   238 	@param aClientId the Secure ID of the client sessions to not share with
       
   239 	@return KErrNone if the graphic is no longer shared, KErrNotFound if the graphic was not shared anyway, else one of the system-wide error codes
       
   240 */	{
       
   241 	const TInt idx = iPimpl->iSharedWith.FindInOrder(aClientId.iId);
       
   242 	if(0 <= idx)
       
   243 		{
       
   244 		iPimpl->iSharedWith.Remove(idx);
       
   245 		return KErrNone;
       
   246 		}
       
   247 	else
       
   248 		{
       
   249 		return idx;
       
   250 		}
       
   251 	}
       
   252 
       
   253 EXPORT_C void CWsGraphicDrawer::Draw(MWsGc& aGc,const TRect& aRect,const TDesC8& aData) const
       
   254 	{
       
   255 	// avoid infinite recursion
       
   256 	if(iPimpl->iFlags & CPimpl::EInDraw)
       
   257 		{
       
   258 		return;
       
   259 		}
       
   260 	// draw
       
   261 	iPimpl->iFlags |= (CPimpl::EInDraw | CPimpl::EDrawn);
       
   262 	DoDraw(aGc,aRect,aData); // implemented by derived classes
       
   263 	iPimpl->iFlags &= ~CPimpl::EInDraw;
       
   264 	}
       
   265 
       
   266 
       
   267 EXPORT_C TInt CWsGraphicDrawer::SendMessage(const TDesC8& aData)
       
   268 /** Sends this message to the client-side peer
       
   269 	@param aData the data to send
       
   270 	@return KErrNone if successful, else one of the System-wide error codes
       
   271 */	{
       
   272 	return iPimpl->iOwner.SendMessage(this,aData);
       
   273 	}
       
   274 
       
   275 EXPORT_C TInt CWsGraphicDrawer::SendMessage(CWsMessageData& aData)
       
   276 /** Sends this message to the client-side peer
       
   277 	@param aData the data to send
       
   278 	@return KErrNone if successful, else one of the System-wide error codes
       
   279 */	{
       
   280 	return iPimpl->iOwner.SendMessage(this,aData);
       
   281 	}
       
   282 
       
   283 EXPORT_C void CWsGraphicDrawer::Invalidate()
       
   284 	/** Schedules all potentially affected parts of the screen to repaint
       
   285 	Called by derived classes when their presentation changes (e.g. they
       
   286 	receive new artwork via a SendMessage())
       
   287 	Note: this is not a suitable method for animating a graphic.  For animation,
       
   288 	use MWsGc::Invalidate when the graphic is being drawn to schedule the next
       
   289 	animation frame instead.
       
   290 */	{
       
   291 	if(iPimpl && (iPimpl->iFlags & CPimpl::EDrawn))
       
   292 		{
       
   293 		iPimpl->iEnv.Invalidate(iPimpl->iId);
       
   294 		iPimpl->iFlags &= ~CPimpl::EDrawn;
       
   295 		}
       
   296 	}
       
   297 
       
   298 EXPORT_C TBool CWsGraphicDrawer::Contains(const TArray<TGraphicDrawerId>& aIds) const
       
   299 /** Tests whether this drawer is, or itself draws, any of the graphic drawers identified by the IDs.
       
   300 	Calls HasAsChild() on itself to determine if this graphic does itself contain
       
   301 	any of the IDs.  Derived classes which themselves draw other graphic drawers should
       
   302 	override HasAsChild().
       
   303 	@param aIds the (sorted in TGraphicDrawerId::Compare order) list of IDs
       
   304 	@return ETrue if this graphic is, or contains, any of the graphic drawers listed
       
   305 */	{
       
   306 	// avoid infinite recursion
       
   307 	if(iPimpl->iFlags & CPimpl::EInContains)
       
   308 		{
       
   309 		return EFalse;
       
   310 		}
       
   311 	// is it us?
       
   312 	const TInt count = aIds.Count();
       
   313 	for(TInt i=0; i<count; i++)
       
   314 		{
       
   315 		if(0 == aIds[i].Compare(iPimpl->iId))
       
   316 			{
       
   317 			return ETrue;
       
   318 			}
       
   319 		}
       
   320 	// is it a child of us?
       
   321 	iPimpl->iFlags |= CPimpl::EInContains;
       
   322 	const TBool ret = HasAsChild(aIds);
       
   323 	iPimpl->iFlags &= ~CPimpl::EInContains;
       
   324 	return ret;
       
   325 	}
       
   326 
       
   327 EXPORT_C TBool CWsGraphicDrawer::HasAsChild(const TArray<TGraphicDrawerId>& /*aIds*/) const
       
   328 /** Called by Contains() to determine if the graphic identified by Id is contained within the
       
   329 	other graphic drawers that this graphic drawer itself draws.
       
   330 	Derived classes which draw other drawers should override this method and call
       
   331 	Contains() on all graphics which they draw.
       
   332 	@param aIds a (sorted in TGraphicDrawerId::Compare order) list of the drawer IDs to see if this drawer draws
       
   333 	@return ETrue if this drawer draws any of those graphics
       
   334 */	{
       
   335 	return EFalse;
       
   336 	}
       
   337 
       
   338 EXPORT_C void CWsGraphicDrawer::HandleEvent(const TWservCrEvent& aEvent)
       
   339 	{
       
   340 	if (iPimpl->iEventHandler)
       
   341 		iPimpl->iEventHandler->DoHandleEvent(aEvent);
       
   342 	}
       
   343 
       
   344 EXPORT_C void CWsGraphicDrawer::SetEventHandler(MWsEventHandler* aHandler)
       
   345 	{
       
   346 	iPimpl->iEventHandler = aHandler;
       
   347 	}
       
   348 
       
   349 EXPORT_C TBool CWsGraphicDrawer::HasEventHandler() const
       
   350 	{
       
   351 	return iPimpl->iEventHandler!=NULL;
       
   352 	}