1 /* |
|
2 * Copyright (c) 2005-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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // Include Files |
|
20 |
|
21 #include "TWsGraphicShare.h" |
|
22 #include <e32base.h> |
|
23 #include <e32std.h> |
|
24 #include <w32stdgraphic.h> |
|
25 |
|
26 // Local Functions |
|
27 |
|
28 LOCAL_C void DrawSharedGraphicL(const TDesC& aSemName, TInt aScrNum, const TWsGraphicId& aId, const TRect& aDestRect, const TDesC8& aData) |
|
29 { |
|
30 // Construct & Initiate |
|
31 RWsSession ws; |
|
32 User::LeaveIfError(ws.Connect()); |
|
33 CleanupClosePushL(ws); |
|
34 |
|
35 CWsScreenDevice* screenDevice = new(ELeave) CWsScreenDevice(ws); |
|
36 CleanupStack::PushL(screenDevice); |
|
37 User::LeaveIfError(screenDevice->Construct(aScrNum)); |
|
38 |
|
39 TSize screenSize = screenDevice->SizeInPixels(); |
|
40 |
|
41 CWindowGc* gc = new(ELeave) CWindowGc(screenDevice); |
|
42 CleanupStack::PushL(gc); |
|
43 User::LeaveIfError(gc->Construct()); |
|
44 |
|
45 RWindowGroup winGroup(ws); |
|
46 CleanupClosePushL(winGroup); |
|
47 User::LeaveIfError(winGroup.Construct(1)); |
|
48 |
|
49 RWindow win(ws); |
|
50 CleanupClosePushL(win); |
|
51 TUint32 handle = 0x0F00; |
|
52 User::LeaveIfError(win.Construct(winGroup, handle)); |
|
53 win.SetBackgroundColor(TRgb(255, 255, 255)); |
|
54 win.SetPosition(TPoint(aDestRect.iTl.iX, aDestRect.iTl.iY)); |
|
55 win.SetSize(aDestRect.Size()); |
|
56 win.Activate(); |
|
57 |
|
58 // Draw |
|
59 gc->Activate(win); |
|
60 win.Invalidate(); |
|
61 win.BeginRedraw(); |
|
62 ws.Flush(); |
|
63 gc->DrawWsGraphic(aId, TRect(0,0,aDestRect.Width(),aDestRect.Height()), aData ); |
|
64 gc->Deactivate(); |
|
65 win.EndRedraw(); |
|
66 ws.Flush(); |
|
67 |
|
68 // Synchronize with master process |
|
69 RSemaphore semaphore; |
|
70 CleanupClosePushL(semaphore); |
|
71 User::LeaveIfError(semaphore.OpenGlobal(aSemName)); |
|
72 semaphore.Signal(); |
|
73 semaphore.Wait(); |
|
74 semaphore.Close(); |
|
75 |
|
76 // Deconstruct |
|
77 CleanupStack::PopAndDestroy(6); |
|
78 } |
|
79 |
|
80 LOCAL_C void MainL ( ) |
|
81 { |
|
82 TBuf<128> commandLine; |
|
83 TLex lex; |
|
84 TBuf<32> semName; |
|
85 TInt screenNumber = 0; |
|
86 TInt graphId; |
|
87 TInt left, top, right, bottom; |
|
88 |
|
89 // Read arguments from the command line |
|
90 // There is a space between two adjacent parameters |
|
91 // Commandline's format looks like that: |
|
92 // 'screenNumber' 'graphId' 'left' 'top' 'right' 'bottom' |
|
93 User::CommandLine(commandLine); |
|
94 commandLine.TrimLeft(); |
|
95 |
|
96 _LIT(KSpace, " "); |
|
97 TInt pos; |
|
98 // Get process name |
|
99 pos = commandLine.Find(KSpace); |
|
100 semName = commandLine.Left(pos); |
|
101 commandLine = commandLine.Mid(pos+1); |
|
102 |
|
103 // Get screen number |
|
104 pos = commandLine.Find(KSpace); |
|
105 lex = commandLine.Left(pos); |
|
106 lex.Val(screenNumber); |
|
107 commandLine = commandLine.Mid(pos+1); |
|
108 |
|
109 // Get gragaphic id |
|
110 pos = commandLine.Find(KSpace); |
|
111 lex = commandLine.Left(pos); |
|
112 lex.Val(graphId); |
|
113 commandLine = commandLine.Mid(pos+1); |
|
114 |
|
115 // Get coordinates |
|
116 pos = commandLine.Find(KSpace); |
|
117 lex = commandLine.Left(pos); |
|
118 lex.Val(left); |
|
119 commandLine = commandLine.Mid(pos+1); |
|
120 |
|
121 pos = commandLine.Find(KSpace); |
|
122 lex = commandLine.Left(pos); |
|
123 lex.Val(top); |
|
124 commandLine = commandLine.Mid(pos+1); |
|
125 |
|
126 pos = commandLine.Find(KSpace); |
|
127 lex = commandLine.Left(pos); |
|
128 lex.Val(right); |
|
129 commandLine = commandLine.Mid(pos+1); |
|
130 |
|
131 pos = commandLine.Find(KSpace); |
|
132 lex = commandLine.Left(pos); |
|
133 lex.Val(bottom); |
|
134 commandLine = commandLine.Mid(pos+1); |
|
135 |
|
136 // Get data |
|
137 TBuf8<32> data; |
|
138 data.Copy(commandLine); |
|
139 |
|
140 TWsGraphicId id(TUid::Uid(graphId)); |
|
141 TRect destRect(left, top, right, bottom); |
|
142 |
|
143 // Draw the graphic |
|
144 DrawSharedGraphicL(semName, screenNumber, id, destRect, data); |
|
145 } |
|
146 |
|
147 // Global Functions |
|
148 |
|
149 GLDEF_C TInt E32Main() |
|
150 { |
|
151 // Create cleanup stack |
|
152 __UHEAP_MARK; |
|
153 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
154 |
|
155 // Run application code inside TRAP harness, wait keypress when terminated |
|
156 TRAPD(error, MainL()); |
|
157 _LIT(KWsGraphicShareError, "WsGraphicShareError"); |
|
158 __ASSERT_ALWAYS(!error,User::Panic(KWsGraphicShareError,error)); |
|
159 |
|
160 delete cleanup; |
|
161 __UHEAP_MARKEND; |
|
162 return KErrNone; |
|
163 } |
|