Update contrib.
2 * Copyright (c) 2001-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.
19 #include "TCustomWrap.h"
35 #include "TCustomWrap.hrh"
36 #include <tcustomwrap.rsg>
39 // ---------------- CCustomWrapAppControl (a simple Edwin control) -----------
41 class CCustomWrapAppControl : public CCoeControl, public MCoeControlObserver
44 ~CCustomWrapAppControl();
46 void SetCustomWrapOnL();
47 void SetCustomWrapCustomL();
48 void SetCustomWrapOffL();
52 void Draw(const TRect& aRect) const;
53 TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
54 void HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType); // from the MCoeControlObserverInterface
56 virtual TInt CountComponentControls() const;
57 virtual CCoeControl* ComponentControl(TInt aIndex) const;
58 // the two functions above are needed in order for the control to work correctly.
66 CCoeControl* iFocusControl; // The control that is currently in focus.
67 CEikEdwin* iEdwin; // I still need a focus control, even if just one EikEdwin...
68 const MFormCustomWrap* iStandardCustomWrap;
69 TTestCustomWrap iCustomCustomWrap;
72 CCustomWrapAppControl::~CCustomWrapAppControl()
77 void CCustomWrapAppControl::ConstructL()
80 Window().SetShadowDisabled(ETrue);
82 iStandardCustomWrap = iEdwin->TextLayout()->CustomWrap();
84 SetExtentToWholeScreen();
86 iFocusControl->SetFocus(ETrue);
89 //void CCustomWrapAppControl::ActivateL()
91 // CCoeControl::ActivateL();
92 // iEdwin->ActivateL();
95 void CCustomWrapAppControl::HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType)
97 if (aEventType==EEventRequestFocus)
99 iFocusControl=aControl;
100 iFocusControl->SetFocus(ETrue,EDrawNow);
104 TInt CCustomWrapAppControl::CountComponentControls() const
109 CCoeControl* CCustomWrapAppControl::ComponentControl(TInt /*aIndex*/) const
114 void CCustomWrapAppControl::CreateEdwinL()
116 const TSize screenSize(iCoeEnv->ScreenDevice()->SizeInPixels());
118 iEdwin=new(ELeave) CEikRichTextEditor;
119 STATIC_CAST(CEikRichTextEditor*,iEdwin)->ConstructL(this,0,0,0);
120 //STATIC_CAST(CEikRichTextEditor*,iEdwin)->ConstructL(this,0,0,EEikEdwinInclusiveSizeFixed);
121 iEdwin->SetObserver(this);
122 iEdwin->CreateScrollBarFrameL();
123 iEdwin->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOn);
124 iEdwin->SetExtent(TPoint(screenSize.iWidth/5,screenSize.iHeight/8),TSize(screenSize.iWidth/3,screenSize.iHeight*3/5));
127 TKeyResponse CCustomWrapAppControl::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
129 if (aType==EEventKey)
131 iEdwin->OfferKeyEventL(aKeyEvent, aType);
133 return(EKeyWasConsumed);
136 void CCustomWrapAppControl::Draw(const TRect& aRect) const
138 CWindowGc& gc=SystemGc();
139 gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
140 gc.SetBrushColor(KRgbWhite);
141 gc.SetPenStyle(CGraphicsContext::ENullPen);
146 void CCustomWrapAppControl::SetCustomWrapOnL()
148 iEdwin->TextLayout()->SetCustomWrap(iStandardCustomWrap);
152 void CCustomWrapAppControl::SetCustomWrapCustomL()
154 iEdwin->TextLayout()->SetCustomWrap(&iCustomCustomWrap);
158 void CCustomWrapAppControl::SetCustomWrapOffL()
160 iEdwin->TextLayout()->SetCustomWrap(0);
164 void CCustomWrapAppControl::ReformatL()
166 iEdwin->NotifyNewFormatL();
170 // ---------------------- CCustomWrapAppView definition ----------------
173 class CCustomWrapAppUi : public CEikAppUi
178 private: // from CEikAppUi -- framework
179 void HandleCommandL(TInt aCommand);
181 CCustomWrapAppControl* iCustomWrapAppControl;
185 void CCustomWrapAppUi::ConstructL()
188 iCustomWrapAppControl=new(ELeave) CCustomWrapAppControl;
189 iCustomWrapAppControl->ConstructL();
190 AddToStackL(iCustomWrapAppControl);
193 CCustomWrapAppUi::~CCustomWrapAppUi()
195 RemoveFromStack(iCustomWrapAppControl);
196 delete iCustomWrapAppControl;
199 void CCustomWrapAppUi::HandleCommandL(TInt aCommand)
204 CBaActiveScheduler::Exit();
207 iCustomWrapAppControl->SetCustomWrapOffL();
210 iCustomWrapAppControl->SetCustomWrapOnL();
213 iCustomWrapAppControl->SetCustomWrapCustomL();
221 // --------------------- CCustomWrapAppDoc class Definition ------------
224 class CCustomWrapAppDoc : public CEikDocument
227 CCustomWrapAppDoc(CEikApplication& aApp);
229 CEikAppUi* CreateAppUiL();
233 CCustomWrapAppDoc::CCustomWrapAppDoc(CEikApplication& aApp):CEikDocument(aApp)
235 // Nothing else to do, just call the base class constructor
239 CEikAppUi* CCustomWrapAppDoc::CreateAppUiL()
241 return new (ELeave) CCustomWrapAppUi;
244 // ------------------------------ CCustomWrapApp -----------------------
248 const TUid KCustomWrapUid = {0x10005d2f};
250 class CCustomWrapApp : public CEikApplication
253 CApaDocument* CreateDocumentL();
254 TUid AppDllUid() const;
258 TUid CCustomWrapApp::AppDllUid() const
260 return KCustomWrapUid;
263 CApaDocument* CCustomWrapApp::CreateDocumentL()
265 return new (ELeave) CCustomWrapAppDoc(*this);
269 ////////////////////////////////////////////////////////////////////////////////////////////
272 static CApaApplication* NewApplication()
274 return new CCustomWrapApp;
279 return EikStart::RunApplication(&NewApplication);