예제 #1
0
/*
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/			
void CMyHelpContainer::ConstructL()
    {
    CreateWindowL();
    iBgContext = CAknsBasicBackgroundControlContext::NewL(KAknsIIDQsnBgAreaMain,TRect(0,0,1,1), ETrue);
    iMirroRed = AknLayoutUtils::LayoutMirrored();
    
	iEditor = new (ELeave) CEikRichTextEditor;
	iEditor->SetAknEditorFlags(EAknEditorFlagEnableScrollBars);
	iEditor->SetContainerWindowL(*this);
	iEditor->ConstructL(this,0,0,0);
	
	iEditor->CreateScrollBarFrameL();
	iEditor->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EAuto, CEikScrollBarFrame::EAuto);
	    
	TCharFormat		charFormat;	
    TCharFormatMask charFormatMask;	

	_LIT(KFontArial,"Arial");
	
	TRgb textcol;
	MAknsSkinInstance* skin = AknsUtils::SkinInstance();
	AknsUtils::GetCachedColor(skin,textcol,KAknsIIDQsnTextColors,EAknsCIQsnTextColorsCG6);
	
	charFormat.iFontSpec = AknLayoutUtils::FontFromId(EAknLogicalFontPrimaryFont)->FontSpecInTwips();
	charFormat.iFontPresentation.iTextColor = TLogicalRgb(textcol);;
	charFormatMask.SetAll();

	iParaformMe = CParaFormatLayer::NewL(); 
	iCharformMe = CCharFormatLayer::NewL(charFormat,charFormatMask); 
	iRichMessageMe  = CRichText::NewL(iParaformMe,iCharformMe);
	
	AddTextToEditorL();
	iEditor->SetDocumentContentL(*iRichMessageMe);
	iEditor->SetDocumentContentL(*iRichMessageMe);
	iEditor->SetCursorPosL(0,EFalse);
	
	iEditor->SetFocus(EFalse);
	iEditor->SetFocusing(ETrue);
	
	
	TRect MyRect(CEikonEnv::Static()->EikAppUi()->ClientRect());
	SetRect(MyRect);
	ActivateL();
	DrawNow();
	
	SizeChanged();
	iEditor->ClearSelectionL();	
	iEditor->MoveCursorL(TCursorPosition::EFPageUp, EFalse);
	iEditor->MoveCursorL(TCursorPosition::EFPageUp, EFalse);
	iEditor->MoveCursorL(TCursorPosition::EFPageUp, EFalse);
	iEditor->MoveCursorL(TCursorPosition::EFPageUp, EFalse);
	iEditor->MoveCursorL(TCursorPosition::EFPageUp, EFalse);
	iEditor->MoveCursorL(TCursorPosition::EFPageUp, EFalse);
	iEditor->MoveCursorL(TCursorPosition::EFPageUp, EFalse);
	iEditor->MoveCursorL(TCursorPosition::EFPageUp, EFalse);	
	iEditor->UpdateScrollBarsL();
	iEditor->DrawNow();
    }
예제 #2
0
/**
 * Constructs the text control with the complex fonts.
 */
void CComplexFontsControl::ConstructL(const CCoeControl* aParent)
    {
    User::LeaveIfError(iSemaphore.OpenGlobal(KSemaphore));
    if (aParent)
        {
        SetContainerWindowL(*aParent);
        }
    else
        {
        CreateWindowL();
        }
    // Create text object, text view and layout.
    iParaFormatLayer = CParaFormatLayer::NewL(); 
    iCharFormatLayer = CCharFormatLayer::NewL();
    // Create an empty rich text object
    iRichText = CRichText::NewL(iParaFormatLayer, iCharFormatLayer);
    
    iScreen = new(ELeave) CWsScreenDevice(ControlEnv()->WsSession());
    User::LeaveIfError(iScreen->Construct()); // default screen used
    
    TPixelsAndRotation pixelsAndRotation;
    iScreen->GetDefaultScreenSizeAndRotation(pixelsAndRotation);
    
    // Create the text layout, (required by text view),
    // with the text object and a wrap width (=width of view rect)
    iLayout = CTextLayout::NewL(iRichText,pixelsAndRotation.iPixelSize.iWidth);
    
    // Create text view
    iTextView = CTextView::NewL(iLayout, pixelsAndRotation.iPixelSize,
            iScreen, iScreen, &Window(), 0, // no window group
            &iCoeEnv->WsSession()); // new view
        
    SetRect(TRect(TPoint(0, 0), pixelsAndRotation.iPixelSize));

    // load up text
    iRichText->InsertL(0, KComplexFontsText);

    // break up into paragraphs for CRichText by replacing \n characters in original text
    // with CEditableText::EParagraphDelimiter
    TPtrC complexFontsTextPtr(KComplexFontsText);
    TInt eos = complexFontsTextPtr.Length();
    for (TInt paragraphBreakLocation = 0; paragraphBreakLocation < eos; paragraphBreakLocation++)
        {
        if (complexFontsTextPtr[paragraphBreakLocation] == '\n')
            {
            iRichText->DeleteL(paragraphBreakLocation, 1);
            iRichText->InsertL(paragraphBreakLocation, CEditableText::EParagraphDelimiter);
            }
        }
    
    TCharFormat charFormat;
    TCharFormatMask charFormatMask;
    // format the first paragraph "Class RWindow" as orange and a bit bigger than the body
    charFormat.iFontPresentation.iTextColor= TLogicalRgb(TRgb(0x0099ff));
    charFormatMask.SetAttrib(EAttColor);
    charFormat.iFontSpec.iHeight = KHeaderFontSize; 
    charFormatMask.SetAttrib(EAttFontHeight);
    
    TInt headerLength = 0;
    TInt headerStart = iRichText->CharPosOfParagraph(headerLength, KHeadingParagraph);
    iRichText->ApplyCharFormatL(charFormat, charFormatMask, headerStart, headerLength);
    charFormatMask.ClearAll();

    // format "Class" as Sans Serif
    charFormat.iFontSpec.iTypeface.iName = KNokiaSeries60Font;
    charFormatMask.SetAttrib(EAttFontTypeface);
    iRichText->ApplyCharFormatL(charFormat, charFormatMask, headerStart, 5);
    charFormatMask.ClearAll();

    // make the rest of the text smaller  
    charFormat.iFontSpec.iHeight = KBodyFontSize;
    charFormatMask.SetAttrib(EAttFontHeight);
    TInt textLength = iRichText->DocumentLength();
    iRichText->ApplyCharFormatL(charFormat, charFormatMask, headerLength, textLength - headerLength);
    charFormatMask.ClearAll();

    TParaFormatMask paraFormatMask;
    // crunch main body a bit closer together to show more on the little screen
    // and indent left margin 
    iParaFormat.iLineSpacingInTwips = KBodyLineSpacing;
    paraFormatMask.SetAttrib(EAttLineSpacing);
    iParaFormat.iLineSpacingControl = CParaFormat::ELineSpacingExactlyInPixels;
    paraFormatMask.SetAttrib(EAttLineSpacingControl);
    iParaFormat.iLeftMarginInTwips = KBodyIndent;
    paraFormatMask.SetAttrib(EAttLeftMargin);
    iRichText->ApplyParaFormatL(&iParaFormat, paraFormatMask, headerLength, textLength - headerLength);
    paraFormatMask.ClearAll();

    TInt length = 0;
    TInt start = 0;
    
    // put a grey background on "class RWindow : public RDrawableWindow;"
    start = iRichText->CharPosOfParagraph(length, KClassParagraph);
    iParaFormat.iFillColor = TLogicalRgb(TRgb(0xdddddd));
    paraFormatMask.SetAttrib(EAttFillColor);
    iRichText->ApplyParaFormatL(&iParaFormat, paraFormatMask, start, length);
    paraFormatMask.ClearAll();
    
    // make "Description" and "Derivation" subheadings bold
    charFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
    charFormatMask.SetAttrib(EAttFontStrokeWeight);
    start = iRichText->CharPosOfParagraph(length, KDescriptionHeading);
    iRichText->ApplyCharFormatL(charFormat, charFormatMask, start, length);
    start = iRichText->CharPosOfParagraph(length, KDerivationHeading);
    iRichText->ApplyCharFormatL(charFormat, charFormatMask, start, length);
    charFormatMask.ClearAll();
    
    // all the paragraphs between and including "Description" and "Derivation" are in sans serif 
    // (the default CRichText font is serif)
    TInt paragraphNumber = 0;

    charFormat.iFontSpec.iTypeface.iName = KNokiaSeries60Font;
    charFormatMask.SetAttrib(EAttFontTypeface);
    for (paragraphNumber = KDescriptionHeading; paragraphNumber <= KDerivationHeading; paragraphNumber++)
        {
        start = iRichText->CharPosOfParagraph(length, paragraphNumber);
        iRichText->ApplyCharFormatL(charFormat, charFormatMask, start, length);
        }
    charFormatMask.ClearAll();
    
    // for each line in the "Derivation" section
    //  progressively indent left margin
    //  make class name blue underlined (it starts two characters after the 
    //    beginning of each paragraph and goes to the space before the '-')
    //  make descriptive text sans serif (from the '-' to the end of the paragraph)
    paraFormatMask.SetAttrib(EAttLeftMargin);
    charFormat.iFontPresentation.iTextColor= TLogicalRgb(TRgb(0xA27316));
    charFormat.iFontPresentation.iUnderline = EUnderlineOn;
    for (paragraphNumber = KFirstDerivation; paragraphNumber <= KLastDerivation; paragraphNumber++)
        {
        iParaFormat.iLeftMarginInTwips = (paragraphNumber - KFirstDerivation + 2)*KBodyIndent;
        start = iRichText->CharPosOfParagraph(length, paragraphNumber);
        iRichText->ApplyParaFormatL(&iParaFormat, paraFormatMask, start, length);
        TInt dash = 0;
        for (dash = start; dash < start + length; dash++)
            {
            if (complexFontsTextPtr[dash] == '-')
                {
                break;
                }
            }
        charFormatMask.SetAttrib(EAttColor);
        charFormatMask.SetAttrib(EAttFontUnderline);
        TInt classNameLength = (dash - 1) - (start + 2);
        iRichText->ApplyCharFormatL(charFormat, charFormatMask, start + 2, classNameLength);
        charFormatMask.ClearAll();
        charFormatMask.SetAttrib(EAttFontTypeface);
        TInt descriptionLength = length - classNameLength - 4;
        iRichText->ApplyCharFormatL(charFormat, charFormatMask, dash, descriptionLength);
        charFormatMask.ClearAll();
        }
    paraFormatMask.ClearAll();
    
    if (!aParent)
        {
        ActivateL();
        }
    }