os/textandloc/textrendering/textformatting/test/src/TCustomWrap.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include "TCustomWrap.h"
sl@0
    20
#include <basched.h>
sl@0
    21
#include <coecntrl.h>
sl@0
    22
#include <coeccntx.h>
sl@0
    23
#include <coemain.h>
sl@0
    24
#include <e32keys.h>
sl@0
    25
#include <eikon.hrh>
sl@0
    26
#include <eikappui.h>
sl@0
    27
#include <eikapp.h>
sl@0
    28
#include <eikdoc.h>
sl@0
    29
#include <eikenv.h>
sl@0
    30
#include <eikrted.h>
sl@0
    31
#include <eikedwin.h>
sl@0
    32
#include <eikdef.h>
sl@0
    33
#include <eikstart.h>
sl@0
    34
#include <txtrich.h>
sl@0
    35
#include "TCustomWrap.hrh"
sl@0
    36
#include <tcustomwrap.rsg>
sl@0
    37
sl@0
    38
// 
sl@0
    39
// ---------------- CCustomWrapAppControl  (a simple Edwin control) -----------
sl@0
    40
sl@0
    41
class CCustomWrapAppControl : public CCoeControl, public MCoeControlObserver
sl@0
    42
	{
sl@0
    43
public:
sl@0
    44
	~CCustomWrapAppControl();
sl@0
    45
	void ConstructL();
sl@0
    46
	void SetCustomWrapOnL();
sl@0
    47
	void SetCustomWrapCustomL();
sl@0
    48
	void SetCustomWrapOffL();
sl@0
    49
	void ReformatL();
sl@0
    50
sl@0
    51
private: // framework
sl@0
    52
	void Draw(const TRect& aRect) const;
sl@0
    53
	TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
sl@0
    54
	void HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType); // from the MCoeControlObserverInterface
sl@0
    55
//	void ActivateL();
sl@0
    56
	virtual TInt CountComponentControls() const;
sl@0
    57
	virtual CCoeControl* ComponentControl(TInt aIndex) const;    
sl@0
    58
	// the two functions above are needed in order for the control to work correctly.
sl@0
    59
sl@0
    60
sl@0
    61
private:
sl@0
    62
	void CreateEdwinL();
sl@0
    63
	
sl@0
    64
sl@0
    65
private:
sl@0
    66
	CCoeControl* iFocusControl; // The control that is currently in focus. 
sl@0
    67
	CEikEdwin* iEdwin; // I still need a focus control, even if just one EikEdwin...
sl@0
    68
	const MFormCustomWrap* iStandardCustomWrap;
sl@0
    69
	TTestCustomWrap iCustomCustomWrap;
sl@0
    70
	};
sl@0
    71
sl@0
    72
CCustomWrapAppControl::~CCustomWrapAppControl()
sl@0
    73
	{
sl@0
    74
	delete iEdwin;
sl@0
    75
	}
sl@0
    76
sl@0
    77
void CCustomWrapAppControl::ConstructL()
sl@0
    78
	{
sl@0
    79
	CreateWindowL();
sl@0
    80
    Window().SetShadowDisabled(ETrue);
sl@0
    81
	CreateEdwinL();
sl@0
    82
	iStandardCustomWrap = iEdwin->TextLayout()->CustomWrap();
sl@0
    83
	iFocusControl=iEdwin;
sl@0
    84
	SetExtentToWholeScreen();
sl@0
    85
	ActivateL();
sl@0
    86
	iFocusControl->SetFocus(ETrue);
sl@0
    87
	}
sl@0
    88
sl@0
    89
//void CCustomWrapAppControl::ActivateL()
sl@0
    90
//	{
sl@0
    91
//	CCoeControl::ActivateL();
sl@0
    92
//	iEdwin->ActivateL();
sl@0
    93
//	}
sl@0
    94
sl@0
    95
void CCustomWrapAppControl::HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType)
sl@0
    96
	{
sl@0
    97
	if (aEventType==EEventRequestFocus)
sl@0
    98
		{
sl@0
    99
		iFocusControl=aControl;
sl@0
   100
		iFocusControl->SetFocus(ETrue,EDrawNow);
sl@0
   101
		}
sl@0
   102
	} 
sl@0
   103
sl@0
   104
TInt CCustomWrapAppControl::CountComponentControls() const
sl@0
   105
	{
sl@0
   106
	return 1;
sl@0
   107
	}
sl@0
   108
sl@0
   109
CCoeControl* CCustomWrapAppControl::ComponentControl(TInt /*aIndex*/) const
sl@0
   110
	{
sl@0
   111
	return iEdwin;
sl@0
   112
	}
sl@0
   113
sl@0
   114
void CCustomWrapAppControl::CreateEdwinL()
sl@0
   115
	{
sl@0
   116
	const TSize screenSize(iCoeEnv->ScreenDevice()->SizeInPixels());
sl@0
   117
	// Rich text editor.
sl@0
   118
	iEdwin=new(ELeave) CEikRichTextEditor;
sl@0
   119
	STATIC_CAST(CEikRichTextEditor*,iEdwin)->ConstructL(this,0,0,0);
sl@0
   120
	//STATIC_CAST(CEikRichTextEditor*,iEdwin)->ConstructL(this,0,0,EEikEdwinInclusiveSizeFixed);
sl@0
   121
	iEdwin->SetObserver(this);
sl@0
   122
	iEdwin->CreateScrollBarFrameL();
sl@0
   123
	iEdwin->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOn);
sl@0
   124
	iEdwin->SetExtent(TPoint(screenSize.iWidth/5,screenSize.iHeight/8),TSize(screenSize.iWidth/3,screenSize.iHeight*3/5));
sl@0
   125
	}
sl@0
   126
sl@0
   127
TKeyResponse CCustomWrapAppControl::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
sl@0
   128
	{
sl@0
   129
	if (aType==EEventKey)
sl@0
   130
		{
sl@0
   131
		iEdwin->OfferKeyEventL(aKeyEvent, aType);
sl@0
   132
		}
sl@0
   133
	return(EKeyWasConsumed);
sl@0
   134
	}
sl@0
   135
sl@0
   136
void CCustomWrapAppControl::Draw(const TRect& aRect) const
sl@0
   137
	{
sl@0
   138
	CWindowGc& gc=SystemGc();
sl@0
   139
	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
   140
	gc.SetBrushColor(KRgbWhite);
sl@0
   141
	gc.SetPenStyle(CGraphicsContext::ENullPen);
sl@0
   142
	gc.DrawRect(aRect);
sl@0
   143
	}
sl@0
   144
sl@0
   145
sl@0
   146
void CCustomWrapAppControl::SetCustomWrapOnL()
sl@0
   147
	{
sl@0
   148
	iEdwin->TextLayout()->SetCustomWrap(iStandardCustomWrap);
sl@0
   149
	ReformatL();
sl@0
   150
	}
sl@0
   151
sl@0
   152
void CCustomWrapAppControl::SetCustomWrapCustomL()
sl@0
   153
	{
sl@0
   154
	iEdwin->TextLayout()->SetCustomWrap(&iCustomCustomWrap);
sl@0
   155
	ReformatL();
sl@0
   156
	}
sl@0
   157
sl@0
   158
void CCustomWrapAppControl::SetCustomWrapOffL()
sl@0
   159
	{
sl@0
   160
	iEdwin->TextLayout()->SetCustomWrap(0);
sl@0
   161
	ReformatL();
sl@0
   162
	}
sl@0
   163
sl@0
   164
void CCustomWrapAppControl::ReformatL()
sl@0
   165
	{
sl@0
   166
	iEdwin->NotifyNewFormatL();
sl@0
   167
	}
sl@0
   168
sl@0
   169
// 
sl@0
   170
//  ---------------------- CCustomWrapAppView definition ---------------- 
sl@0
   171
//
sl@0
   172
sl@0
   173
class CCustomWrapAppUi : public CEikAppUi
sl@0
   174
	{
sl@0
   175
public:
sl@0
   176
	void ConstructL();
sl@0
   177
	~CCustomWrapAppUi();
sl@0
   178
private: // from CEikAppUi -- framework
sl@0
   179
	void HandleCommandL(TInt aCommand);
sl@0
   180
private: 
sl@0
   181
	CCustomWrapAppControl* iCustomWrapAppControl;
sl@0
   182
	
sl@0
   183
	};
sl@0
   184
sl@0
   185
void CCustomWrapAppUi::ConstructL()
sl@0
   186
	{
sl@0
   187
	BaseConstructL();
sl@0
   188
	iCustomWrapAppControl=new(ELeave) CCustomWrapAppControl;
sl@0
   189
	iCustomWrapAppControl->ConstructL();
sl@0
   190
	AddToStackL(iCustomWrapAppControl);
sl@0
   191
	}
sl@0
   192
sl@0
   193
CCustomWrapAppUi::~CCustomWrapAppUi()
sl@0
   194
	{
sl@0
   195
	RemoveFromStack(iCustomWrapAppControl);
sl@0
   196
	delete iCustomWrapAppControl;
sl@0
   197
	}
sl@0
   198
sl@0
   199
void CCustomWrapAppUi::HandleCommandL(TInt aCommand)
sl@0
   200
	{
sl@0
   201
	switch(aCommand)
sl@0
   202
		{
sl@0
   203
		case EAppCmdExit:
sl@0
   204
			CBaActiveScheduler::Exit();
sl@0
   205
			break;
sl@0
   206
		case EAppCmdWrap0:
sl@0
   207
			iCustomWrapAppControl->SetCustomWrapOffL();
sl@0
   208
			break;
sl@0
   209
		case EAppCmdWrap1:
sl@0
   210
			iCustomWrapAppControl->SetCustomWrapOnL();
sl@0
   211
			break;
sl@0
   212
		case EAppCmdWrap2:
sl@0
   213
			iCustomWrapAppControl->SetCustomWrapCustomL();
sl@0
   214
			break;
sl@0
   215
		default:
sl@0
   216
			break;
sl@0
   217
		}
sl@0
   218
	} 
sl@0
   219
sl@0
   220
//
sl@0
   221
//  --------------------- CCustomWrapAppDoc class Definition ------------ 
sl@0
   222
//
sl@0
   223
sl@0
   224
class CCustomWrapAppDoc : public CEikDocument
sl@0
   225
	{
sl@0
   226
public:
sl@0
   227
	CCustomWrapAppDoc(CEikApplication& aApp);
sl@0
   228
private:
sl@0
   229
	CEikAppUi* CreateAppUiL();
sl@0
   230
	};
sl@0
   231
sl@0
   232
sl@0
   233
CCustomWrapAppDoc::CCustomWrapAppDoc(CEikApplication& aApp):CEikDocument(aApp)
sl@0
   234
	{
sl@0
   235
	// Nothing else to do, just call the base class constructor
sl@0
   236
	//
sl@0
   237
	}
sl@0
   238
sl@0
   239
CEikAppUi* CCustomWrapAppDoc::CreateAppUiL()
sl@0
   240
	{
sl@0
   241
	return new (ELeave) CCustomWrapAppUi;
sl@0
   242
	}
sl@0
   243
//
sl@0
   244
//  ------------------------------ CCustomWrapApp ----------------------- 
sl@0
   245
//
sl@0
   246
sl@0
   247
sl@0
   248
const TUid KCustomWrapUid = {0x10005d2f};
sl@0
   249
sl@0
   250
class CCustomWrapApp : public CEikApplication
sl@0
   251
	{
sl@0
   252
private:
sl@0
   253
	CApaDocument* CreateDocumentL();
sl@0
   254
	TUid AppDllUid() const;
sl@0
   255
sl@0
   256
	};
sl@0
   257
sl@0
   258
TUid CCustomWrapApp::AppDllUid() const 
sl@0
   259
	{
sl@0
   260
	return KCustomWrapUid;
sl@0
   261
	}
sl@0
   262
sl@0
   263
CApaDocument* CCustomWrapApp::CreateDocumentL()
sl@0
   264
	{
sl@0
   265
	return new (ELeave) CCustomWrapAppDoc(*this);
sl@0
   266
	}
sl@0
   267
sl@0
   268
sl@0
   269
////////////////////////////////////////////////////////////////////////////////////////////
sl@0
   270
//
sl@0
   271
sl@0
   272
	static CApaApplication* NewApplication()
sl@0
   273
		{
sl@0
   274
		return new CCustomWrapApp;
sl@0
   275
		}
sl@0
   276
sl@0
   277
	TInt E32Main()
sl@0
   278
		{
sl@0
   279
		return EikStart::RunApplication(&NewApplication);
sl@0
   280
		}
sl@0
   281
sl@0
   282