|
1 // Copyright (c) 1997-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 // source code for the message-window class |
|
15 // $Workfile: MSGWIN.CPP $ |
|
16 // $Revision: 1.7 $ |
|
17 // $Author: DougF $ |
|
18 // $Date: 07 Jul 1999 16:16:18 $ |
|
19 // |
|
20 // |
|
21 |
|
22 #include "CL_STD.H" |
|
23 |
|
24 // DMessageWindow |
|
25 |
|
26 DMessageWindow::DMessageWindow() |
|
27 { |
|
28 __DECLARE_NAME(_S("DMessageWindow")); |
|
29 iPlinthTlColor=KRgbWhite; |
|
30 iPlinthBrColor=KRgbGray; |
|
31 } |
|
32 |
|
33 DMessageWindow::~DMessageWindow() |
|
34 { |
|
35 CancelDisplay(); // copes with NULL pointers |
|
36 iFunctions->CloseFont(iFont); |
|
37 delete iTimer; |
|
38 } |
|
39 |
|
40 void DMessageWindow::StartDisplay() |
|
41 { |
|
42 __ASSERT_DEBUG(~iFlags&EFlagVisible, Panic(EClockServerPanicAlreadyVisible)); |
|
43 __ASSERT_DEBUG(!iTimer->IsActive(), Panic(EClockServerPanicTimerIsActive)); |
|
44 if (~iFlags&EFlagFlash) |
|
45 iFunctions->SetSync(MAnimGeneralFunctions::ESyncNone); |
|
46 else |
|
47 { |
|
48 iFunctions->SetSync(MAnimGeneralFunctions::ESyncFlash); |
|
49 iFlags|=EFlagFlashStateOn; |
|
50 } |
|
51 iWindowFunctions->SetVisible(ETrue); |
|
52 iFlags|=EFlagVisible; |
|
53 if (iDuration.Int()!=SMessageWindowCommandStartDisplayArgs::EIndefiniteDuration) |
|
54 { |
|
55 iTimer->SetAction(DMessageWindowTimer::EActionCancelDisplay); |
|
56 iTimer->After(iDuration); |
|
57 } |
|
58 } |
|
59 |
|
60 void DMessageWindow::CancelDisplay() |
|
61 { |
|
62 if (iTimer!=NULL) |
|
63 iTimer->Cancel(); |
|
64 if (iFunctions!=NULL) |
|
65 { |
|
66 iFunctions->SetSync(MAnimGeneralFunctions::ESyncNone); |
|
67 iWindowFunctions->SetVisible(EFalse); |
|
68 iFlags&=~EFlagVisible; |
|
69 } |
|
70 } |
|
71 |
|
72 void DMessageWindow::ConstructLP(const TUint8* aBytePtr, TBool) |
|
73 { |
|
74 SMessageWindowConstructorArgs* messageWindowArgs=(SMessageWindowConstructorArgs*)aBytePtr; |
|
75 aBytePtr+=sizeof(SMessageWindowConstructorArgs); |
|
76 iBaselineOffset=messageWindowArgs->iBaselineOffset; |
|
77 iFont=iFunctions->DuplicateFontL(messageWindowArgs->iFontHandle); |
|
78 iBackgroundColor=messageWindowArgs->iBackgroundColor; |
|
79 iTextColor=messageWindowArgs->iTextColor; |
|
80 iBorderColor=messageWindowArgs->iBorderColor; |
|
81 iTimer=DMessageWindowTimer::NewL(*this); |
|
82 CancelDisplay(); |
|
83 } |
|
84 |
|
85 TInt DMessageWindow::CommandReplyLP(TInt aOpcode, TAny* aArgs) |
|
86 { |
|
87 switch (aOpcode) |
|
88 { |
|
89 case EMessageWindowCommandStartDisplay: |
|
90 { |
|
91 SMessageWindowCommandStartDisplayArgs* messageWindowArgs=(SMessageWindowCommandStartDisplayArgs*)aArgs; |
|
92 TInt initialDelay=messageWindowArgs->iInitialDelay.Int(); |
|
93 TInt duration=messageWindowArgs->iDuration.Int(); |
|
94 __ASSERT_ALWAYS((initialDelay>=0) && ((duration==SMessageWindowCommandStartDisplayArgs::EIndefiniteDuration) || (duration>=0)),PanicClientFromServer()); |
|
95 if (messageWindowArgs->iFlash) |
|
96 iFlags|=EFlagFlash; |
|
97 else |
|
98 iFlags&=~EFlagFlash; |
|
99 iDuration=messageWindowArgs->iDuration; |
|
100 iText=messageWindowArgs->iText; |
|
101 if ((iFlags&EFlagVisible) || (initialDelay==0)) |
|
102 { |
|
103 CancelDisplay(); |
|
104 StartDisplay(); |
|
105 } |
|
106 else if (!iTimer->IsActive()) |
|
107 { |
|
108 iTimer->SetAction(DMessageWindowTimer::EActionStartDisplay); |
|
109 iTimer->After(messageWindowArgs->iInitialDelay); |
|
110 } |
|
111 } |
|
112 return KErrNone; |
|
113 case EMessageWindowCommandCancelDisplay: |
|
114 CancelDisplay(); |
|
115 return KErrNone; |
|
116 case EMessageWindowCommandGetBorders: |
|
117 { |
|
118 TMargins borders; |
|
119 borders.iLeft=EBorderWidthLeft; |
|
120 borders.iRight=EBorderWidthRight; |
|
121 borders.iTop=EBorderWidthTop; |
|
122 borders.iBottom=EBorderWidthBottom; |
|
123 const TInt error=iFunctions->Message()->Write(KIpcSlot, TPckgC<TMargins>(borders)); |
|
124 __ASSERT_ALWAYS(error==KErrNone, PanicClientFromServer()); |
|
125 } |
|
126 return KErrNone; |
|
127 case EMessageWindowCommandSetBackgroundColor: |
|
128 { |
|
129 SMessageWindowBackgroundColorArgs* messageWindowArgs=(SMessageWindowBackgroundColorArgs*)aArgs; |
|
130 iBackgroundColor = messageWindowArgs->iBackgroundColor; |
|
131 } |
|
132 return KErrNone; |
|
133 case EMessageWindowCommandSetTextColor: |
|
134 { |
|
135 SMessageWindowTextColorArgs* messageWindowArgs=(SMessageWindowTextColorArgs*)aArgs; |
|
136 iTextColor=messageWindowArgs->iTextColor; |
|
137 } |
|
138 return KErrNone; |
|
139 case EMessageWindowCommandSetBorderColor: |
|
140 { |
|
141 SMessageWindowBorderColorArgs* messageWindowArgs=(SMessageWindowBorderColorArgs*)aArgs; |
|
142 iBorderColor=messageWindowArgs->iBorderColor; |
|
143 } |
|
144 return KErrNone; |
|
145 case EMessageWindowCommandSetPlinthColor: |
|
146 { |
|
147 SMessageWindowPlinthColorArgs* messageWindowArgs=(SMessageWindowPlinthColorArgs*)aArgs; |
|
148 iPlinthTlColor=messageWindowArgs->iTlColor; |
|
149 iPlinthBrColor=messageWindowArgs->iBrColor; |
|
150 } |
|
151 return KErrNone; |
|
152 default: |
|
153 return DAnimWithUtils::CommandReplyLP(aOpcode, aArgs); |
|
154 } |
|
155 } |
|
156 |
|
157 void DMessageWindow::AnimateP(TDateTime*) |
|
158 { |
|
159 __ASSERT_DEBUG(iFlags&EFlagFlash,Panic(EClockServerPanicAnimatingNonFlashingMessageWindow)); |
|
160 if (iFunctions->FlashStateOn()) |
|
161 iFlags|=EFlagFlashStateOn; |
|
162 else |
|
163 iFlags&=~EFlagFlashStateOn; |
|
164 iWindowFunctions->ActivateGc(); |
|
165 TRect rect=Rect(); |
|
166 rect.iTl+=TPoint(EBorderWidthLeft, EBorderWidthTop); |
|
167 rect.iBr-=TPoint(EBorderWidthRight, EBorderWidthBottom); |
|
168 DrawTextPortionOfDisplay(rect); |
|
169 } |
|
170 |
|
171 void DMessageWindow::RedrawP() |
|
172 { |
|
173 TRect rect=Rect(); |
|
174 iGc->SetBrushStyle(CGraphicsContext::ENullBrush); |
|
175 iGc->SetPenStyle(CGraphicsContext::ESolidPen); |
|
176 // iGc->SetPenColor(KRgbBlack); |
|
177 iGc->SetPenColor(iBorderColor); |
|
178 iGc->SetPenSize(TSize(1, 1)); |
|
179 iGc->DrawRect(rect); |
|
180 rect.Shrink(1, 1); |
|
181 iGc->DrawRect(rect); |
|
182 rect.Shrink(1, 1); |
|
183 iGc->SetPenColor(iPlinthTlColor); |
|
184 iGc->DrawLine(rect.iTl, TPoint(rect.iTl.iX, rect.iBr.iY-1)); |
|
185 iGc->DrawLine(rect.iTl, TPoint(rect.iBr.iX-1, rect.iTl.iY)); |
|
186 iGc->SetPenColor(iPlinthBrColor); |
|
187 iGc->DrawLine(TPoint(rect.iBr.iX-1, rect.iTl.iY), TPoint(rect.iBr.iX-1, rect.iBr.iY)); |
|
188 iGc->DrawLine(TPoint(rect.iTl.iX, rect.iBr.iY-1), TPoint(rect.iBr.iX, rect.iBr.iY-1)); |
|
189 rect.Shrink(1, 1); |
|
190 iGc->DrawLine(TPoint(rect.iBr.iX-1, rect.iTl.iY), TPoint(rect.iBr.iX-1, rect.iBr.iY)); |
|
191 iGc->DrawLine(TPoint(rect.iTl.iX, rect.iBr.iY-1), TPoint(rect.iBr.iX, rect.iBr.iY-1)); |
|
192 rect.iBr-=TPoint(1, 1); |
|
193 DrawTextPortionOfDisplay(rect); |
|
194 } |
|
195 |
|
196 TRect DMessageWindow::Rect() const |
|
197 { |
|
198 return TRect(TPoint(0, 0), iWindowFunctions->WindowSize()); |
|
199 } |
|
200 |
|
201 void DMessageWindow::DrawTextPortionOfDisplay(const TRect& aRect) const |
|
202 { |
|
203 __ASSERT_DEBUG(TRect(aRect.iTl-TPoint(EBorderWidthLeft, EBorderWidthTop), |
|
204 aRect.iBr+TPoint(EBorderWidthRight, EBorderWidthBottom))==Rect(),Panic(EClockServerPanicBadRect)); |
|
205 iGc->SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
206 iGc->SetBrushColor(iBackgroundColor); |
|
207 if ((iFlags&EFlagFlash) && (~iFlags&EFlagFlashStateOn)) |
|
208 iGc->Clear(aRect); |
|
209 else |
|
210 { |
|
211 iGc->SetPenStyle(CGraphicsContext::ESolidPen); |
|
212 iGc->SetPenColor(iTextColor); |
|
213 iGc->UseFont(iFont); |
|
214 iGc->DrawText(iText, aRect, iBaselineOffset, CGraphicsContext::ECenter); |
|
215 } |
|
216 } |
|
217 |
|
218 // DMessageWindow::DMessageWindowTimer |
|
219 |
|
220 DMessageWindow::DMessageWindowTimer::DMessageWindowTimer(DMessageWindow& aOwner) |
|
221 :CTimer(EPriorityStandard), |
|
222 iOwner(aOwner) |
|
223 { |
|
224 __DECLARE_NAME(_S("DMessageWindowTimer")); |
|
225 CActiveScheduler::Add(this); |
|
226 } |
|
227 |
|
228 DMessageWindow::DMessageWindowTimer* DMessageWindow::DMessageWindowTimer::NewL(DMessageWindow& aOwner) |
|
229 { |
|
230 DMessageWindowTimer* timer=new(ELeave) DMessageWindowTimer(aOwner); |
|
231 CleanupStack::PushL(timer); |
|
232 timer->ConstructL(); |
|
233 CleanupStack::Pop(); |
|
234 return timer; |
|
235 } |
|
236 |
|
237 void DMessageWindow::DMessageWindowTimer::SetAction(TAction aAction) |
|
238 { |
|
239 iAction=aAction; |
|
240 } |
|
241 |
|
242 void DMessageWindow::DMessageWindowTimer::RunL() |
|
243 { |
|
244 switch (iAction) |
|
245 { |
|
246 case EActionStartDisplay: |
|
247 iOwner.StartDisplay(); |
|
248 break; |
|
249 case EActionCancelDisplay: |
|
250 iOwner.CancelDisplay(); |
|
251 break; |
|
252 #if defined(_DEBUG) |
|
253 default: |
|
254 Panic(EClockServerPanicBadMessageWindowTimerAction); |
|
255 break; |
|
256 #endif |
|
257 } |
|
258 } |
|
259 |