sl@0: /* sl@0: * Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "TCustomWrap.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "TCustomWrap.hrh" sl@0: #include sl@0: sl@0: // sl@0: // ---------------- CCustomWrapAppControl (a simple Edwin control) ----------- sl@0: sl@0: class CCustomWrapAppControl : public CCoeControl, public MCoeControlObserver sl@0: { sl@0: public: sl@0: ~CCustomWrapAppControl(); sl@0: void ConstructL(); sl@0: void SetCustomWrapOnL(); sl@0: void SetCustomWrapCustomL(); sl@0: void SetCustomWrapOffL(); sl@0: void ReformatL(); sl@0: sl@0: private: // framework sl@0: void Draw(const TRect& aRect) const; sl@0: TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType); sl@0: void HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType); // from the MCoeControlObserverInterface sl@0: // void ActivateL(); sl@0: virtual TInt CountComponentControls() const; sl@0: virtual CCoeControl* ComponentControl(TInt aIndex) const; sl@0: // the two functions above are needed in order for the control to work correctly. sl@0: sl@0: sl@0: private: sl@0: void CreateEdwinL(); sl@0: sl@0: sl@0: private: sl@0: CCoeControl* iFocusControl; // The control that is currently in focus. sl@0: CEikEdwin* iEdwin; // I still need a focus control, even if just one EikEdwin... sl@0: const MFormCustomWrap* iStandardCustomWrap; sl@0: TTestCustomWrap iCustomCustomWrap; sl@0: }; sl@0: sl@0: CCustomWrapAppControl::~CCustomWrapAppControl() sl@0: { sl@0: delete iEdwin; sl@0: } sl@0: sl@0: void CCustomWrapAppControl::ConstructL() sl@0: { sl@0: CreateWindowL(); sl@0: Window().SetShadowDisabled(ETrue); sl@0: CreateEdwinL(); sl@0: iStandardCustomWrap = iEdwin->TextLayout()->CustomWrap(); sl@0: iFocusControl=iEdwin; sl@0: SetExtentToWholeScreen(); sl@0: ActivateL(); sl@0: iFocusControl->SetFocus(ETrue); sl@0: } sl@0: sl@0: //void CCustomWrapAppControl::ActivateL() sl@0: // { sl@0: // CCoeControl::ActivateL(); sl@0: // iEdwin->ActivateL(); sl@0: // } sl@0: sl@0: void CCustomWrapAppControl::HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType) sl@0: { sl@0: if (aEventType==EEventRequestFocus) sl@0: { sl@0: iFocusControl=aControl; sl@0: iFocusControl->SetFocus(ETrue,EDrawNow); sl@0: } sl@0: } sl@0: sl@0: TInt CCustomWrapAppControl::CountComponentControls() const sl@0: { sl@0: return 1; sl@0: } sl@0: sl@0: CCoeControl* CCustomWrapAppControl::ComponentControl(TInt /*aIndex*/) const sl@0: { sl@0: return iEdwin; sl@0: } sl@0: sl@0: void CCustomWrapAppControl::CreateEdwinL() sl@0: { sl@0: const TSize screenSize(iCoeEnv->ScreenDevice()->SizeInPixels()); sl@0: // Rich text editor. sl@0: iEdwin=new(ELeave) CEikRichTextEditor; sl@0: STATIC_CAST(CEikRichTextEditor*,iEdwin)->ConstructL(this,0,0,0); sl@0: //STATIC_CAST(CEikRichTextEditor*,iEdwin)->ConstructL(this,0,0,EEikEdwinInclusiveSizeFixed); sl@0: iEdwin->SetObserver(this); sl@0: iEdwin->CreateScrollBarFrameL(); sl@0: iEdwin->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOn); sl@0: iEdwin->SetExtent(TPoint(screenSize.iWidth/5,screenSize.iHeight/8),TSize(screenSize.iWidth/3,screenSize.iHeight*3/5)); sl@0: } sl@0: sl@0: TKeyResponse CCustomWrapAppControl::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) sl@0: { sl@0: if (aType==EEventKey) sl@0: { sl@0: iEdwin->OfferKeyEventL(aKeyEvent, aType); sl@0: } sl@0: return(EKeyWasConsumed); sl@0: } sl@0: sl@0: void CCustomWrapAppControl::Draw(const TRect& aRect) const sl@0: { sl@0: CWindowGc& gc=SystemGc(); sl@0: gc.SetBrushStyle(CGraphicsContext::ESolidBrush); sl@0: gc.SetBrushColor(KRgbWhite); sl@0: gc.SetPenStyle(CGraphicsContext::ENullPen); sl@0: gc.DrawRect(aRect); sl@0: } sl@0: sl@0: sl@0: void CCustomWrapAppControl::SetCustomWrapOnL() sl@0: { sl@0: iEdwin->TextLayout()->SetCustomWrap(iStandardCustomWrap); sl@0: ReformatL(); sl@0: } sl@0: sl@0: void CCustomWrapAppControl::SetCustomWrapCustomL() sl@0: { sl@0: iEdwin->TextLayout()->SetCustomWrap(&iCustomCustomWrap); sl@0: ReformatL(); sl@0: } sl@0: sl@0: void CCustomWrapAppControl::SetCustomWrapOffL() sl@0: { sl@0: iEdwin->TextLayout()->SetCustomWrap(0); sl@0: ReformatL(); sl@0: } sl@0: sl@0: void CCustomWrapAppControl::ReformatL() sl@0: { sl@0: iEdwin->NotifyNewFormatL(); sl@0: } sl@0: sl@0: // sl@0: // ---------------------- CCustomWrapAppView definition ---------------- sl@0: // sl@0: sl@0: class CCustomWrapAppUi : public CEikAppUi sl@0: { sl@0: public: sl@0: void ConstructL(); sl@0: ~CCustomWrapAppUi(); sl@0: private: // from CEikAppUi -- framework sl@0: void HandleCommandL(TInt aCommand); sl@0: private: sl@0: CCustomWrapAppControl* iCustomWrapAppControl; sl@0: sl@0: }; sl@0: sl@0: void CCustomWrapAppUi::ConstructL() sl@0: { sl@0: BaseConstructL(); sl@0: iCustomWrapAppControl=new(ELeave) CCustomWrapAppControl; sl@0: iCustomWrapAppControl->ConstructL(); sl@0: AddToStackL(iCustomWrapAppControl); sl@0: } sl@0: sl@0: CCustomWrapAppUi::~CCustomWrapAppUi() sl@0: { sl@0: RemoveFromStack(iCustomWrapAppControl); sl@0: delete iCustomWrapAppControl; sl@0: } sl@0: sl@0: void CCustomWrapAppUi::HandleCommandL(TInt aCommand) sl@0: { sl@0: switch(aCommand) sl@0: { sl@0: case EAppCmdExit: sl@0: CBaActiveScheduler::Exit(); sl@0: break; sl@0: case EAppCmdWrap0: sl@0: iCustomWrapAppControl->SetCustomWrapOffL(); sl@0: break; sl@0: case EAppCmdWrap1: sl@0: iCustomWrapAppControl->SetCustomWrapOnL(); sl@0: break; sl@0: case EAppCmdWrap2: sl@0: iCustomWrapAppControl->SetCustomWrapCustomL(); sl@0: break; sl@0: default: sl@0: break; sl@0: } sl@0: } sl@0: sl@0: // sl@0: // --------------------- CCustomWrapAppDoc class Definition ------------ sl@0: // sl@0: sl@0: class CCustomWrapAppDoc : public CEikDocument sl@0: { sl@0: public: sl@0: CCustomWrapAppDoc(CEikApplication& aApp); sl@0: private: sl@0: CEikAppUi* CreateAppUiL(); sl@0: }; sl@0: sl@0: sl@0: CCustomWrapAppDoc::CCustomWrapAppDoc(CEikApplication& aApp):CEikDocument(aApp) sl@0: { sl@0: // Nothing else to do, just call the base class constructor sl@0: // sl@0: } sl@0: sl@0: CEikAppUi* CCustomWrapAppDoc::CreateAppUiL() sl@0: { sl@0: return new (ELeave) CCustomWrapAppUi; sl@0: } sl@0: // sl@0: // ------------------------------ CCustomWrapApp ----------------------- sl@0: // sl@0: sl@0: sl@0: const TUid KCustomWrapUid = {0x10005d2f}; sl@0: sl@0: class CCustomWrapApp : public CEikApplication sl@0: { sl@0: private: sl@0: CApaDocument* CreateDocumentL(); sl@0: TUid AppDllUid() const; sl@0: sl@0: }; sl@0: sl@0: TUid CCustomWrapApp::AppDllUid() const sl@0: { sl@0: return KCustomWrapUid; sl@0: } sl@0: sl@0: CApaDocument* CCustomWrapApp::CreateDocumentL() sl@0: { sl@0: return new (ELeave) CCustomWrapAppDoc(*this); sl@0: } sl@0: sl@0: sl@0: //////////////////////////////////////////////////////////////////////////////////////////// sl@0: // sl@0: sl@0: static CApaApplication* NewApplication() sl@0: { sl@0: return new CCustomWrapApp; sl@0: } sl@0: sl@0: TInt E32Main() sl@0: { sl@0: return EikStart::RunApplication(&NewApplication); sl@0: } sl@0: sl@0: