|
1 /* |
|
2 * Copyright (c) 2002 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: Implementation of Notepad/Template Editor. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "NpdEdwinBase.h" |
|
20 |
|
21 #include <AknUtils.h> |
|
22 #include <txtglobl.h> |
|
23 #include <barsread.h> |
|
24 |
|
25 #include <AknsUtils.h> |
|
26 #include <AknsDrawUtils.h> |
|
27 #include <AknsBasicBackgroundControlContext.h> |
|
28 #include <AknsFrameBackgroundControlContext.h> |
|
29 #include <applayout.cdl.h> |
|
30 #include <eikdialg.h> |
|
31 #include <skinlayout.cdl.h> |
|
32 #include <aknlayoutscalable_apps.cdl.h> |
|
33 #include <aknappui.h> |
|
34 #include <NpdLib.rsg> |
|
35 #ifdef RD_SCALABLE_UI_V2 |
|
36 #include <akntoolbar.h> |
|
37 #include <eikcolib.h> |
|
38 #endif |
|
39 |
|
40 #include "NpdEdwin.h" |
|
41 #include "NpdRichTextEditor.h" |
|
42 |
|
43 #include "NpdLibPanic.h" |
|
44 #include "NpdEdwinLines.h" |
|
45 |
|
46 |
|
47 // ============================ MEMBER FUNCTIONS =============================== |
|
48 |
|
49 // --------------------------------------------------------- |
|
50 // CNotepadEdwinBase::CNotepadEdwinBase() |
|
51 // Constructor |
|
52 // --------------------------------------------------------- |
|
53 // |
|
54 CNotepadEdwinBase::CNotepadEdwinBase() |
|
55 { |
|
56 iEdwinLines = NULL; |
|
57 iBgContext = NULL; |
|
58 iSkinContext = NULL; |
|
59 iIsFirstTimeDrawEditor = ETrue; |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------- |
|
63 // CNotepadEdwinBase::~CNotepadEdwinBase() |
|
64 // Destructor |
|
65 // --------------------------------------------------------- |
|
66 // |
|
67 CNotepadEdwinBase::~CNotepadEdwinBase() |
|
68 { |
|
69 if(iBgContext) |
|
70 { |
|
71 delete iBgContext; |
|
72 iBgContext = NULL; |
|
73 } |
|
74 if(iSkinContext) |
|
75 { |
|
76 delete iSkinContext; |
|
77 } |
|
78 } |
|
79 |
|
80 // --------------------------------------------------------- |
|
81 // CNotepadEdwinBase::Share(CEikEdwin* aEdwin, MNotepadEdwinExposer* aEdwinExposer) |
|
82 // Shares the edwin and its exposer |
|
83 // --------------------------------------------------------- |
|
84 // |
|
85 void CNotepadEdwinBase::Share(CEikEdwin* aEdwin, MNotepadEdwinExposer* aEdwinExposer) |
|
86 { |
|
87 iEdwin = aEdwin; |
|
88 iEdwinExposer = aEdwinExposer; |
|
89 } |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CNotepadEdwinBase::DoEditorLayoutL |
|
92 // Sets the layout of the Edwin and the scrollbar. |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 void CNotepadEdwinBase::DoEditorLayoutL() |
|
96 { |
|
97 if (!iBgContext) |
|
98 return; |
|
99 UpdateScrollLayout(); |
|
100 iBackgroundRect = iParent->Rect(); |
|
101 if(iEdwinLines != NULL) |
|
102 { |
|
103 AknLayoutUtils::LayoutControl( iEdwinLines, |
|
104 iBackgroundRect, 0, 0, 0, |
|
105 AknLayoutUtilsNoValue, |
|
106 AknLayoutUtilsNoValue, |
|
107 iBackgroundRect.Width(), |
|
108 iBackgroundRect.Height() ); |
|
109 } |
|
110 TAknLayoutRect mainNotesPane; |
|
111 TAknLayoutRect lineLayout; |
|
112 TRect tempMainPane; |
|
113 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,tempMainPane); |
|
114 TRect mainPane(TPoint(0, 0), tempMainPane.Size()); |
|
115 mainNotesPane.LayoutRect(mainPane, AknLayoutScalable_Apps::main_notes_pane().LayoutLine()); |
|
116 lineLayout.LayoutRect(mainNotesPane.Rect(),AknLayoutScalable_Apps::list_notes_pane().LayoutLine()); |
|
117 TAknLayoutScalableParameterLimits textLimits; |
|
118 TBool isShowToolbar = EFalse; |
|
119 #ifdef RD_SCALABLE_UI_V2 |
|
120 CEikAppUiFactory* appUiFactory |
|
121 = static_cast<CEikAppUiFactory*>( CEikonEnv::Static()->AppUiFactory() ); |
|
122 CAknToolbar* oldFixedToolbar = appUiFactory->CurrentFixedToolbar(); |
|
123 if ( oldFixedToolbar != NULL ) |
|
124 { |
|
125 isShowToolbar = oldFixedToolbar->IsShown(); |
|
126 } |
|
127 #endif |
|
128 if ( isShowToolbar ) |
|
129 { |
|
130 textLimits = AknLayoutScalable_Apps::list_notes_text_pane_ParamLimits(1); |
|
131 } |
|
132 else |
|
133 { |
|
134 textLimits =AknLayoutScalable_Apps::list_notes_text_pane_ParamLimits(); |
|
135 } |
|
136 RArray<TAknTextComponentLayout> layouts; |
|
137 for (TInt i = 0; i < textLimits.LastRow()+1 ; i++) |
|
138 { |
|
139 TAknWindowComponentLayout paneLayout = AknLayoutScalable_Apps::list_notes_text_pane(i); |
|
140 TAknTextComponentLayout textLayout = AknLayoutScalable_Apps::list_notes_text_pane_t1(); |
|
141 TAknTextComponentLayout composedTextLayout = TAknWindowComponentLayout::ComposeText(paneLayout, textLayout); |
|
142 layouts.AppendL(composedTextLayout); |
|
143 } |
|
144 TAknMultiLineTextLayout edwinLayout = |
|
145 TAknTextComponentLayout::Multiline( layouts ); |
|
146 AknLayoutUtils::LayoutEdwin(iEdwin, lineLayout.Rect(), edwinLayout, EAknsCIQsnTextColorsCG6); |
|
147 layouts.Reset(); |
|
148 |
|
149 // layout edwin overrides this value |
|
150 iEdwin->SetTextSkinColorIdL(EAknsCIQsnTextColorsCG34); |
|
151 |
|
152 // SetBackgroundColorL() contains modification to |
|
153 // Edwin's CParaFormat which was created by |
|
154 // AknLayoutUtils::LayoutEdwin(...), so iEditor->SetBackgroundColorL() |
|
155 // must be called after AknLayoutUtils::LayoutEdwin(...). |
|
156 // |
|
157 SetBackgroundColorL(); |
|
158 } |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // CNotepadEdwinBase::InitNotepadEditorL |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 void CNotepadEdwinBase::InitNotepadEditorL( |
|
165 CEikDialog* aParent, |
|
166 TBool aIsRichTextEditor, |
|
167 CNotepadEdwinLines* aEdwinLines) |
|
168 { |
|
169 iParent = aParent; |
|
170 iBackgroundRect = iParent->Rect(); |
|
171 iEdwinLines = aEdwinLines; |
|
172 iIsRichTextEditor = aIsRichTextEditor; |
|
173 if (!iBgContext) |
|
174 { |
|
175 iBgContext = CAknsFrameBackgroundControlContext::NewL( KAknsIIDQsnFrNotepad, iBackgroundRect, iBackgroundRect, EFalse ); |
|
176 } |
|
177 if(!iSkinContext) |
|
178 { |
|
179 iSkinContext = CAknsBasicBackgroundControlContext::NewL(KAknsIIDQsnBgAreaMain,iBackgroundRect,EFalse); |
|
180 } |
|
181 iBgContext->SetParentContext( iSkinContext ); |
|
182 DoEditorLayoutL(); |
|
183 |
|
184 // EdwinEvent is used for dynamically changing Laf bitmap |
|
185 // |
|
186 iEdwin->AddEdwinObserverL(this); |
|
187 |
|
188 iEdwin->SetAknEditorFlags(EAknEditorFlagUseSCTNumericCharmap |
|
189 | EAknEditorFlagEnablePictographInput |
|
190 | EAknEditorFlagAllowEntersWithScrollDown ); |
|
191 |
|
192 iEdwin->Text()->SetHasChanged(EFalse); |
|
193 SetAmountToFormat(iEdwin->Text()->DocumentLength()); // ensure switch to band formatting |
|
194 iEdwinExposer->CallSetCanDrawOutsideRect(); // Redraw after Chinese FEP |
|
195 } |
|
196 |
|
197 // --------------------------------------------------------- |
|
198 // CNotepadEdwinBase::SupplyMopObject(TTypeUid aId,TTypeUid::Ptr& ptr) |
|
199 // Gets an object whose type is encapsulated by |
|
200 // the specified TTypeUid object. |
|
201 // --------------------------------------------------------- |
|
202 // |
|
203 TBool CNotepadEdwinBase::SupplyMopObject(TTypeUid aId,TTypeUid::Ptr& ptr) |
|
204 { |
|
205 if(aId.iUid == MAknsControlContext::ETypeId) |
|
206 { |
|
207 ptr = MAknsControlContext::SupplyMopObject(aId, iSkinContext); |
|
208 return ETrue; |
|
209 } |
|
210 return EFalse; |
|
211 } |
|
212 |
|
213 // ----------------------------------------------------------------------------- |
|
214 // CNotepadEdwinBase::HandleEdwinEventL |
|
215 // from MEikEdwinObserver |
|
216 // ----------------------------------------------------------------------------- |
|
217 // |
|
218 void CNotepadEdwinBase::HandleEdwinEventL( |
|
219 CEikEdwin* /*aEdwin*/, |
|
220 TEdwinEvent aEventType ) |
|
221 { |
|
222 |
|
223 iTextLength = iEdwin->TextLength(); |
|
224 |
|
225 if ( aEventType == EEventFormatChanged ) |
|
226 { |
|
227 iEdwin->DrawNow(); |
|
228 } |
|
229 if ( aEventType == EEventTextUpdate ) |
|
230 { |
|
231 iEdwin->TextView()->DocPosToXyPosL( iEdwin->CursorPos(), iPointAtCursor ); |
|
232 iLineNumByYCoordinate = iPointAtCursor.iY; |
|
233 |
|
234 if ( !iIsFirstTimeDrawEditor ) |
|
235 { |
|
236 |
|
237 if ( iTextLength < iPreTextLength && iLineNumByYCoordinate < iPreLineNumByYCoordinate ) |
|
238 { |
|
239 iEdwin->NotifyNewFormatL(); |
|
240 iEdwin->DrawDeferred(); |
|
241 } |
|
242 } |
|
243 else |
|
244 { |
|
245 iIsFirstTimeDrawEditor = EFalse; |
|
246 } |
|
247 |
|
248 |
|
249 iPreLineNumByYCoordinate = iLineNumByYCoordinate; |
|
250 } |
|
251 |
|
252 iPreTextLength = iTextLength; |
|
253 } |
|
254 |
|
255 // ----------------------------------------------------------------------------- |
|
256 // CNotepadEdwinBase::SetBackgroundColorL |
|
257 // ----------------------------------------------------------------------------- |
|
258 // |
|
259 void CNotepadEdwinBase::SetBackgroundColorL() |
|
260 { |
|
261 TAknLayoutRect insiderect; |
|
262 TAknLayoutRect bgLayout; |
|
263 TAknLayoutRect mainNotesPane; |
|
264 TRect tempMainPane; |
|
265 TBool hasChanged; |
|
266 |
|
267 hasChanged = iEdwin->Text()->HasChanged(); |
|
268 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,tempMainPane); |
|
269 TRect mainPane(TPoint(0, 0), tempMainPane.Size()); |
|
270 mainNotesPane.LayoutRect(mainPane, AknLayoutScalable_Apps::main_notes_pane().LayoutLine()); |
|
271 bgLayout.LayoutRect(mainNotesPane.Rect(), AknLayoutScalable_Apps::bg_notes_pane().LayoutLine()); |
|
272 insiderect.LayoutRect(bgLayout.Rect(), AknLayoutScalable_Apps::notes_bg_pane_g1().LayoutLine()); |
|
273 TRgb bgcolor(insiderect.Color()); |
|
274 iEdwin->CEikEdwin::SetBackgroundColorL(bgcolor); |
|
275 iEdwinExposer->GetTextView().SetBackgroundColor(bgcolor); |
|
276 iEdwin->CEikEdwin::SetSkinBackgroundControlContextL(iBgContext); |
|
277 CGlobalText* text = STATIC_CAST(CGlobalText*, iEdwin->Text()); |
|
278 CParaFormat* paraFormat = CParaFormat::NewLC(); |
|
279 TParaFormatMask paraFormatMask; |
|
280 text->GetParaFormatL(paraFormat, paraFormatMask, |
|
281 0, text->DocumentLength()); |
|
282 paraFormat->iFillColor = bgcolor; |
|
283 paraFormatMask.SetAttrib(EAttFillColor); |
|
284 text->ApplyParaFormatL(paraFormat,paraFormatMask, |
|
285 0, text->DocumentLength()); |
|
286 if ( !hasChanged ) |
|
287 { |
|
288 iEdwin->Text()->SetHasChanged( EFalse ); |
|
289 } |
|
290 |
|
291 if(iIsRichTextEditor) |
|
292 { |
|
293 (STATIC_CAST(CEikRichTextEditor*,iEdwin))->ApplyParaFormatL(paraFormat,paraFormatMask); |
|
294 } |
|
295 CleanupStack::PopAndDestroy(); // paraFormat |
|
296 TResourceReader rr; |
|
297 iEdwinExposer->GetCoeEnv().CreateResourceReaderLC(rr, R_NOTEPAD_CURSOR_COLOR); |
|
298 TRgb cursorColor(AKN_LAF_COLOR(rr.ReadInt16())); |
|
299 CleanupStack::PopAndDestroy(); // rr |
|
300 iEdwinExposer->GetTextView().SetCursorXorColor( TRgb( cursorColor.Value() ^ bgcolor.Value() ) ); |
|
301 iEdwin->NotifyNewFormatL(); |
|
302 } |
|
303 |
|
304 // ----------------------------------------------------------------------------- |
|
305 // CNotepadEdwinBase::HandleResourceChange |
|
306 // ----------------------------------------------------------------------------- |
|
307 // |
|
308 void CNotepadEdwinBase::HandleResourceChange(TInt aType) |
|
309 { |
|
310 iEdwin->CEikEdwin::HandleResourceChange( aType ); |
|
311 switch(aType) |
|
312 { |
|
313 case KEikColorResourceChange: |
|
314 case KAknsMessageSkinChange: |
|
315 TInt ignore; |
|
316 TRAP(ignore, SetBackgroundColorL()); |
|
317 break; |
|
318 } |
|
319 if( aType == KAknsMessageSkinChange ) |
|
320 { |
|
321 UpdateScrollLayout(); |
|
322 } |
|
323 } |
|
324 |
|
325 // ----------------------------------------------------------------------------- |
|
326 // CNotepadEdwinBase::Draw |
|
327 // ----------------------------------------------------------------------------- |
|
328 // |
|
329 void CNotepadEdwinBase::Draw(const TRect& aRect) const |
|
330 { |
|
331 CWindowGc& gc = iEdwin->SystemGc(); |
|
332 TRect tempMainPane; |
|
333 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,tempMainPane); |
|
334 TRect mainPane(TPoint(0, 0), tempMainPane.Size()); |
|
335 if( iBgContext ) |
|
336 { |
|
337 TAknLayoutRect mainpaneSkinTl; |
|
338 TAknLayoutRect mainpaneSkinBr; |
|
339 mainpaneSkinTl.LayoutRect( mainPane, SkinLayout::Notepad_skin_element_placing_Line_2() ); // <CDL LAYOUT> |
|
340 mainpaneSkinBr.LayoutRect( mainPane, SkinLayout::Notepad_skin_element_placing_Line_5() ); // <CDL LAYOUT> |
|
341 TAknWindowLineLayout mainPaneSkinCenter = SkinLayout::Notepad_skin_element_placing_Line_1(); // <CDL LAYOUT> |
|
342 TAknLayoutRect mainPaneLayout; |
|
343 mainPaneLayout.LayoutRect(mainPane,mainPaneSkinCenter); |
|
344 TRect skinCenter( mainPaneLayout.Rect() ); |
|
345 TRect viewRect; |
|
346 viewRect.iTl= mainpaneSkinTl.Rect().iTl; |
|
347 viewRect.iBr = mainpaneSkinBr.Rect().iBr; |
|
348 |
|
349 if(iSkinContext) |
|
350 { |
|
351 iSkinContext->SetRect(iParent->Rect()); |
|
352 TRAP_IGNORE( iEdwin->CEikEdwin::SetSkinBackgroundControlContextL(iSkinContext) ); |
|
353 AknsDrawUtils::Background( AknsUtils::SkinInstance(), iSkinContext, iEdwin, gc, mainPane); |
|
354 } |
|
355 TRAP_IGNORE( iEdwin->CEikEdwin::SetSkinBackgroundControlContextL(iBgContext) ); |
|
356 iBgContext->SetFrameRects( viewRect, mainPaneLayout.Rect() ); |
|
357 AknsDrawUtils::Background( AknsUtils::SkinInstance(), iBgContext, iEdwin, gc, mainPane,KAknsDrawParamNoClearUnderImage); |
|
358 } |
|
359 iEdwin->CEikEdwin::Draw(aRect); |
|
360 } |
|
361 |
|
362 // --------------------------------------------------------- |
|
363 // CNotepadEdwinBase::UpdateScrollLayout() |
|
364 // Updates the scroll layout |
|
365 // --------------------------------------------------------- |
|
366 // |
|
367 void CNotepadEdwinBase::UpdateScrollLayout() |
|
368 { |
|
369 CEikScrollBarFrame* sbFrame = iEdwin->ScrollBarFrame(); |
|
370 TInt type = sbFrame->TypeOfVScrollBar(); |
|
371 if( type == CEikScrollBarFrame::EDoubleSpan ) |
|
372 { |
|
373 TAknLayoutRect mainNotesPane; |
|
374 TRect tempMainPane; |
|
375 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,tempMainPane); |
|
376 TRect mainPane(TPoint(0, 0), tempMainPane.Size()); |
|
377 TAknWindowLineLayout scrollPane = AknLayoutScalable_Apps::scroll_pane_cp05(0).LayoutLine(); |
|
378 mainNotesPane.LayoutRect(mainPane, AknLayoutScalable_Apps::main_notes_pane().LayoutLine()); |
|
379 AknLayoutUtils::LayoutVerticalScrollBar(sbFrame, mainNotesPane.Rect(), scrollPane); |
|
380 } |
|
381 } |
|
382 // End of File |