os/textandloc/fontservices/textshaperplugin/test/S60HindiDemo/src/MainViewcontainer.cpp
First public contribution.
2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * Series 60 version of Hindi Demo application
16 * Implementation of CMainViewContainer
23 #include <HindiDemo.rsg>
25 #include "MainViewcontainer.h"
29 #include <aknnotewrappers.h>
33 _LIT16(KNile1,"\x0915\x094D\x0937\x0924\x094D\x0930\x093F\x092F\x0020\x0909\x0926\x094D\x0926\x0947\x0936\x094D\x0020\x0915\x094D\x0937\x093F\x092A\x094D\x0930");
34 _LIT16(KNile2,"\x092d\x0942\x0930\x094d\x092d\x0941\x0935\x0903\x0020\x0938\x094d\x0935\x0903\x0020\x0924\x0924\x094d\x0938\x0935\x093f\x0924\x0941\x0930\x094d\x0935\x0930\x0947\x0923\x094d\x092f\x0902");
35 _LIT16(KNile3,"\x092d\x0930\x094d\x0917\x094b\x0020\x0926\x0947\x0935\x0938\x094d\x092f\x0020\x0927\x0940\x092e\x0939\x093f\x0020\x0927\x093f\x092f\x094b\x0020\x092f\x094b\x0928\x0903\x0020\x092a\x094d\x0930\x091a\x094b\x0926\x092f\x093e\x0924\x094d");
38 _LIT16(KNile4,"\x092f\x0924\x094d\x0930\x0020\x092f\x094b\x0917\x0947\x0936\x094d\x0935\x0930\x0020\x0915\x0943\x0937\x094d\x0923\x094b\x0020\x092f\x0924\x094d\x0930\x0020\x092a\x093e\x0930\x094d\x0925\x094b\x0020\x0927\x0930\x094d\x0928\x0941\x0927\x0930\x0903");
39 _LIT16(KNile5,"\x0924\x0924\x094d\x0930\x0020\x0936\x094d\x0930\x0940\x0930\x094d\x0935\x093f\x091c\x092f\x094b\x0020\x092d\x0942\x0924\x093f\x0930\x094d\x0927\x0941\x0935\x093e\x0020\x0928\x0940\x0924\x093f\x0930\x094d\x092e\x0924\x093f\x0930\x094d\x092e\x092e");
40 _LIT16(KNile6,"\x0915\x0941\x0924\x0938\x094d\x0924\x094d\x0935\x093e\x0020\x0915\x0936\x094d\x092e\x0932\x092e\x093f\x0926\x0902\x0020\x0935\x093f\x0936\x092e\x0947\x0020\x0938\x092e\x0941\x092a\x0938\x094d\x0925\x093f\x0924\x092e\x094d");
43 _LIT16(KNile7,"\x0905\x0928\x093e\x0930\x094d\x092f\x091c\x0941\x0937\x094d\x091f\x092e\x0938\x094d\x0935\x0930\x094d\x0917\x094d\x092f\x092e\x0915\x0940\x0930\x094d\x0924\x093f\x0915\x0930\x092e\x0930\x094d\x091c\x0941\x0928");
44 _LIT16(KNile8,"\x0915\x094d\x0932\x0948\x092c\x094d\x092f\x0902\x0020\x092e\x0020\x0938\x094d\x092e\x0020\x0917\x092e\x0903\x0020\x092a\x093e\x0930\x094d\x0925\x0928\x0948\x0924\x0924\x094d\x0924\x094d\x0935\x092f\x094d\x092f\x0941\x092a\x092a\x0926\x094d\x092f\x0924\x0947");
45 _LIT16(KNile9,"\x0915\x094d\x0937\x0941\x0926\x094d\x0930\x0902\x0020\x0939\x0943\x0926\x092f\x0926\x094c\x0930\x094d\x092c\x0932\x094d\x092f\x0902\x0020\x0924\x094d\x092f\x0915\x094d\x0924\x094d\x0935\x094b\x0924\x094d\x0924\x093f\x0937\x094d\x091f\x0020\x092a\x0930\x0902\x0924\x092a");
47 // test 4 - assorted sample data
48 _LIT16(KTest1,"\x091c\x092e\x094d\x0918\x0940\x0902\x091a\x094d\x092f\x0940\x0020\x0920\x094d\x0920\x094d\x0920\x094d\x0920\x094d");
49 _LIT16(KTest2,"'\x091A\x092A\x0940' '\x0915\x092E\x0932' '\x092D\x0930\x0924'");
50 _LIT16(KTest3,"\x091A\x092A\x42 \x0915\x092A\x42 \x0915\x092A\x44 \x0930\x094D\x0930\x094D\x0930\x094D\x0930\x093e\x0903\x0020");
52 CMainViewContainer* CMainViewContainer::NewL(const TRect& aRect)
54 CMainViewContainer* self = CMainViewContainer::NewLC(aRect);
55 CleanupStack::Pop(self);
59 CMainViewContainer* CMainViewContainer::NewLC(const TRect& aRect)
61 CMainViewContainer* self = new (ELeave) CMainViewContainer;
62 CleanupStack::PushL(self);
63 self->ConstructL(aRect);
67 CMainViewContainer::CMainViewContainer()
71 CMainViewContainer::~CMainViewContainer()
77 // -----------------------------------------------------------------------
78 // Routine that creates and initializes designed components
80 // -----------------------------------------------------------------------
81 void CMainViewContainer::InitComponentsL()
83 CEikStatusPane * sp = iEikonEnv->AppUiFactory()->StatusPane();
85 iContextPane = ( CAknContextPane * ) sp->ControlL( TUid::Uid( EEikStatusPaneUidContext ) );
86 TResourceReader reader;
87 iCoeEnv->CreateResourceReaderLC( reader, R_MAINVIEW_IAKNCONTEXTPANE1 );
88 iContextPane->SetFromResourceL( reader );
89 CleanupStack::PopAndDestroy();
92 iTitlePane = ( CAknTitlePane * ) sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) );
93 TResourceReader reader;
94 iCoeEnv->CreateResourceReaderLC( reader, R_MAINVIEW_IAKNTITLEPANE1 );
95 iTitlePane->SetFromResourceL( reader );
96 CleanupStack::PopAndDestroy();
98 iNaviPane = ( CAknNavigationControlContainer * ) sp->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) );
99 iEikonEnv->AppUiFactory()->StatusPane()->SwitchLayoutL( R_AVKON_STATUS_PANE_LAYOUT_USUAL );
100 iBackgroundColor = iEikonEnv->Color( EColorControlBackground );
103 // -----------------------------------------------------------------------
104 // Routine that cleans up designed components
106 // -----------------------------------------------------------------------
107 void CMainViewContainer::CleanupComponents()
109 delete iNaviDecorator;
112 void CMainViewContainer::ConstructL(const TRect& aRect)
124 void CMainViewContainer::Draw(const TRect& /* aRect */) const
126 CWindowGc& gc = SystemGc();
130 void CMainViewContainer::ChangeSample( TInt aSample)
139 void CMainViewContainer::ChangeFont()
142 int iNumTypefaces = iCoeEnv->ScreenDevice()->NumTypefaces();
143 if (iSelectedFont >= iNumTypefaces || iSelectedFont < 0)
147 void CMainViewContainer::ChangePreviousFont()
150 int iNumTypefaces = iCoeEnv->ScreenDevice()->NumTypefaces();
151 if (iSelectedFont >= iNumTypefaces || iSelectedFont < 0)
152 iSelectedFont = iNumTypefaces-1;
155 void CMainViewContainer::SetHindiFont( TFontSpec& aFontSpec )
157 iFontSpec = aFontSpec;
160 void CMainViewContainer::SetFontSize( TInt aFontSize )
162 iFontSize = aFontSize;
165 void CMainViewContainer::SetUnderLine( enum TFontUnderline aUnderLine )
167 iUnderLine = aUnderLine;
170 enum TFontUnderline CMainViewContainer::GetUnderLine()
175 TInt CMainViewContainer::GetFontSize()
180 TInt CMainViewContainer::GetSample()
185 void CMainViewContainer::DisplayAvailableFonts()
187 TBuf<500> listofFonts;
189 TInt iNumTypefaces = iCoeEnv->ScreenDevice()->NumTypefaces();
190 TTypefaceSupport myTypefaceSupport;
191 for(TInt i = 0; i < iNumTypefaces-1; i++)
193 // get the details of the next available typeface
194 iCoeEnv->ScreenDevice()->TypefaceSupport(myTypefaceSupport,i);
195 listofFonts.Append( myTypefaceSupport.iTypeface.iName.Des());
196 listofFonts.Append( _L("\n"));
199 CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
200 informationNote->ExecuteLD(listofFonts);
203 const TInt UnicodeZeroWidthNonJoiner = 0x200C;
205 /* Display Hindi without shaping by inserting a Unicode Zero Width Non Joiner
206 character bewteen each character
207 aInput the Hindi text to be displayed
208 aOutput the same text with the ZWNJ characters added, This buffer must be big enough
210 void CMainViewContainer::DisableShaping(const TDesC* aInput, TDes& aOutput ) const
213 for (TInt i = 0; i < aInput->Length(); i++ )
215 aOutput.Append( aInput->Mid(i,1) );
216 aOutput.Append( UnicodeZeroWidthNonJoiner );
220 void CMainViewContainer::DrawHindiText(CWindowGc& aGc) const
223 // start with test font
225 _LIT(KTestFontName,"DejaVu Sans Condensed");
226 TFontSpec testFontSpec(KTestFontName,100);
227 CGraphicsDevice* screenDevice=iCoeEnv->ScreenDevice();
228 screenDevice->GetNearestFontInTwips(testFont,testFontSpec);
230 // set the selected font
232 TBuf<200> textFontName;
234 TTypefaceSupport myTypefaceSupport;
235 screenDevice->TypefaceSupport(myTypefaceSupport,iSelectedFont);
237 textFontName.Copy(myTypefaceSupport.iTypeface.iName.Des());
239 TFontSpec indicFontSpec(textFontName,iFontSize);
240 screenDevice->GetNearestFontInTwips(IndicFont,indicFontSpec);
242 // set the required attributes
243 aGc.UseFont(testFont);
244 aGc.SetPenColor(KRgbBlack);
245 aGc.SetBrushColor(KRgbWhite);
246 aGc.CancelClippingRect();
247 aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
249 // Set the text drawing position & draw
250 TRect posRect(10,10, 600, 40);
254 textLine.Append(_L("Sample:"));
259 textLine.Append(_L("1 "));
262 textLine.Append(_L("2 "));
265 textLine.Append(_L("3 "));
268 textLine.Append(_L("test "));
271 textLine.Append(_L("what? "));
274 fontLine.Format(_L("font %d:"), iSelectedFont );
275 textLine.Append(fontLine);
276 textLine.Append(indicFontSpec.iTypeface.iName);
277 aGc.DrawText(textLine,posRect, 14);
279 TRect pos2rect(10,30, 600, 60);
280 textLine2.Format(_L("Size:%dpt black is not shaped, blue is"),iFontSize/20);
281 aGc.DrawText(textLine2, pos2rect, 14);
283 // Discard and destroy the test font
285 screenDevice->ReleaseFont(testFont);
287 // set the required attributes
288 aGc.UseFont(IndicFont);
289 aGc.SetPenColor(KRgbBlack);
290 aGc.SetBrushColor(KRgbWhite);
291 aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
292 aGc.CancelClippingRect();
293 aGc.SetUnderlineStyle(iUnderLine);
295 // some rectangles to fit the text in
296 const TInt baseLineOffset = 32;
298 const TInt start = 50;
299 TRect textRect( 10,start, 800, start+(gap) );
300 TRect textRect2(10,start+(gap), 800, start+(gap*2));
301 TRect textRect3(10,start+(gap*2), 800, start+(gap*3));
302 TRect textRect4(10,start+(gap*3), 800, start+(gap*4));
303 TRect textRect5(10,start+(gap*4), 800, start+(gap*5));
304 TRect textRect6(10,start+(gap*5), 800, start+(gap*6));
306 TBuf<200> textWithoutShaping;
308 // Draw some Hindi in a rectangle
314 // First draw in Black with shaping disabled
315 DisableShaping(&KNile1, textWithoutShaping );
316 aGc.SetPenColor(KRgbBlack);
317 aGc.DrawText(textWithoutShaping, textRect, baseLineOffset, CGraphicsContext::ELeft);
319 // Now in Blue with shaping
320 aGc.SetPenColor(KRgbBlue);
321 aGc.DrawText(KNile1, textRect2, baseLineOffset, CGraphicsContext::ELeft);
323 //--------------------------------------------------------------------------
324 // Without the Layout Engine
325 aGc.SetPenColor(KRgbBlack);
326 DisableShaping(&KNile2, textWithoutShaping );
327 aGc.DrawText(textWithoutShaping, textRect3, baseLineOffset, CGraphicsContext::ELeft);
329 aGc.SetPenColor(KRgbBlue);
330 aGc.DrawText(KNile2, textRect4, baseLineOffset, CGraphicsContext::ELeft);
331 //--------------------------------------------------------------------------
332 // Without the Layout Engine
333 DisableShaping(&KNile3, textWithoutShaping );
334 aGc.SetPenColor(KRgbBlack);
335 aGc.DrawText(textWithoutShaping, textRect5, baseLineOffset, CGraphicsContext::ELeft);
337 aGc.SetPenColor(KRgbBlue);
338 aGc.DrawText(KNile3, textRect6, baseLineOffset, CGraphicsContext::ELeft);
339 //--------------------------------------------------------------------------
343 DisableShaping(&KNile4, textWithoutShaping );
344 aGc.SetPenColor(KRgbBlack);
345 aGc.DrawText(textWithoutShaping, textRect, baseLineOffset, CGraphicsContext::ELeft);
347 aGc.SetPenColor(KRgbBlue);
348 aGc.DrawText(KNile4, textRect2, baseLineOffset, CGraphicsContext::ELeft);
350 //--------------------------------------------------------------------------
351 // Without the Layout Engine
352 DisableShaping(&KNile5, textWithoutShaping );
353 aGc.SetPenColor(KRgbBlack);
354 aGc.DrawText(textWithoutShaping, textRect3, baseLineOffset, CGraphicsContext::ELeft);
356 aGc.SetPenColor(KRgbBlue);
357 aGc.DrawText(KNile5, textRect4, baseLineOffset, CGraphicsContext::ELeft);
358 //--------------------------------------------------------------------------
359 // Without the Layout Engine
360 DisableShaping(&KNile6, textWithoutShaping );
361 aGc.SetPenColor(KRgbBlack);
362 aGc.DrawText(textWithoutShaping, textRect5, baseLineOffset, CGraphicsContext::ELeft);
364 aGc.SetPenColor(KRgbBlue);
365 aGc.DrawText(KNile6, textRect6, baseLineOffset, CGraphicsContext::ELeft);
366 //--------------------------------------------------------------------------
370 DisableShaping(&KNile7, textWithoutShaping );
371 aGc.SetPenColor(KRgbBlack);
372 aGc.DrawText(textWithoutShaping, textRect, baseLineOffset, CGraphicsContext::ELeft);
374 aGc.SetPenColor(KRgbBlue);
375 aGc.DrawText(KNile7, textRect2, baseLineOffset, CGraphicsContext::ELeft);
377 //--------------------------------------------------------------------------
378 // Without the Layout Engine
379 DisableShaping(&KNile8, textWithoutShaping );
380 aGc.SetPenColor(KRgbBlack);
381 aGc.DrawText(textWithoutShaping, textRect3, baseLineOffset, CGraphicsContext::ELeft);
383 aGc.SetPenColor(KRgbBlue);
384 aGc.DrawText(KNile8, textRect4, baseLineOffset, CGraphicsContext::ELeft);
385 //--------------------------------------------------------------------------
386 // Without the Layout Engine
387 DisableShaping(&KNile9, textWithoutShaping );
388 aGc.SetPenColor(KRgbBlack);
389 aGc.DrawText(textWithoutShaping, textRect5, baseLineOffset, CGraphicsContext::ELeft);
391 aGc.SetPenColor(KRgbBlue);
392 aGc.DrawText(KNile9, textRect6, 100, CGraphicsContext::ELeft);
393 //--------------------------------------------------------------------------
398 DisableShaping(&KTest1, textWithoutShaping );
399 aGc.DrawText(textWithoutShaping, textRect, baseLineOffset, CGraphicsContext::ELeft);
401 aGc.SetPenColor(KRgbBlue);
402 aGc.DrawText(KTest1, textRect2, baseLineOffset, CGraphicsContext::ELeft);
404 //--------------------------------------------------------------------------
405 // Without the Layout Engine
407 aGc.SetPenColor(KRgbBlack);
408 DisableShaping(&KTest2, textWithoutShaping );
409 aGc.DrawText(textWithoutShaping, textRect3, baseLineOffset, CGraphicsContext::ELeft);
410 // With the Layout Engine
412 aGc.SetPenColor(KRgbBlue);
413 aGc.DrawText(KTest2, textRect4, baseLineOffset, CGraphicsContext::ELeft);
414 //--------------------------------------------------------------------------
415 // Without the Layout Engine
417 aGc.SetPenColor(KRgbBlack);
418 DisableShaping(&KTest3, textWithoutShaping );
419 aGc.DrawText(textWithoutShaping, textRect5, baseLineOffset, CGraphicsContext::ELeft);
420 // With the Layout Engine
422 aGc.SetPenColor(KRgbBlue);
423 aGc.DrawText(KTest3, textRect6, baseLineOffset, CGraphicsContext::ELeft);
424 //--------------------------------------------------------------------------
429 // Discard and destroy the font
431 screenDevice->ReleaseFont(IndicFont);
436 // -----------------------------------------------------------------------
437 // Returns the number of controls in the control group.
438 // -----------------------------------------------------------------------
439 TInt CMainViewContainer::CountComponentControls() const
441 return iCtrlArray.Count();
444 // -----------------------------------------------------------------------
445 // Returns the component control identified by the given index
446 // -----------------------------------------------------------------------
447 CCoeControl* CMainViewContainer::ComponentControl(TInt aIndex) const
449 return (CCoeControl*)iCtrlArray[aIndex];
452 // -----------------------------------------------------------------------
453 // Method invoked by control framework to handle key events
454 // -----------------------------------------------------------------------
455 TKeyResponse CMainViewContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
457 if (HandleKeyEvents(aKeyEvent, aType))
458 return EKeyWasConsumed;
459 else if(iFocusedControl)
460 return iFocusedControl->OfferKeyEventL(aKeyEvent, aType);
462 return EKeyWasNotConsumed;
465 // -----------------------------------------------------------------------
466 // Method invoked to handle an event from an observed control
467 // -----------------------------------------------------------------------
468 void CMainViewContainer::HandleControlEventL(CCoeControl * aControl, TCoeEvent aEventType)
470 DispatchControlEvents(aControl, aEventType);
473 // -----------------------------------------------------------------------
474 // This method attemps to dispatch commands to individual handlers
476 // -----------------------------------------------------------------------
477 bool CMainViewContainer::DispatchViewCommandEvents(TInt aCommand)
480 _LIT(message,"Copyright (c) 2006 Symbian Software Ltd.\n All rights reserved.");
504 ChangePreviousFont();
507 DisplayAvailableFonts();
511 SetFontSize(GetFontSize() -20);
514 // increase font size
515 SetFontSize(GetFontSize() +20);
518 CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
519 informationNote->ExecuteLD(message);
522 // this command has not been processed by this view so..
529 // -----------------------------------------------------------------------
530 // Routine that attempts to dispatch Control Events
532 // -----------------------------------------------------------------------
533 void CMainViewContainer::DispatchControlEvents(CCoeControl * /* aControl */, TCoeEvent /* aEventType */)
537 // -----------------------------------------------------------------------
538 // Routine where you can handle key events
539 // -----------------------------------------------------------------------
540 bool CMainViewContainer::HandleKeyEvents(const TKeyEvent& aKeyEvent, TEventCode /* aType */)
542 switch (aKeyEvent.iCode)
545 // increase font size
546 SetFontSize(GetFontSize() +20);
549 // increase font size
550 SetFontSize(GetFontSize() -20);
554 ChangeSample(GetSample()-1);
558 ChangeSample(GetSample()+1);
561 if (GetUnderLine() == EUnderlineOff)
562 SetUnderLine ( EUnderlineOn );
564 SetUnderLine ( EUnderlineOff );
570 ChangePreviousFont();
580 // -----------------------------------------------------------------------
581 // Helper routine to manage Control Focus
582 // -----------------------------------------------------------------------
583 void CMainViewContainer::ChangeFocus(CCoeControl * aNewControl)
586 iFocusedControl->SetFocus(EFalse);
587 iFocusedControl = aNewControl;
589 iFocusedControl->SetFocus(ETrue);