Ejemplo n.º 1
0
void CWordAppUi::SetBulletL()
	{
	TParaFormatMask mask;
	CParaFormat* paraFormat = CParaFormat::NewLC();
	const TCursorSelection cursorSelection = iRichEd->TextView()->Selection();
	const TInt lower = cursorSelection.LowerPos();
	const TInt selectionLength = cursorSelection.Length();
	CRichText* text = Text();
	text->GetParaFormatL(paraFormat, mask, lower, selectionLength);
	delete paraFormat->iBullet;
	mask.ClearAll();
	mask.SetAttrib(EAttBullet);
	mask.SetAttrib(EAttIndent);
	if (((CEikButtonBase*)iEikonEnv->AppUiFactory()->ToolBand()->ControlById(EWordButtonBullets))->State() == CEikButtonBase::EClear)
		{
		paraFormat->iBullet = NULL;
		paraFormat->iIndentInTwips = 0;
		}
	else
		{
		TBullet* bullet = new(ELeave) TBullet;
		if (!iBullet)
			CreateDefaultBulletL();
		*bullet = *iBullet;
		paraFormat->iBullet = bullet;
		if (iBullet->iHangingIndent)
			paraFormat->iIndentInTwips = 283; // about 1/2cm - completely arbitrary value !!
		else
			paraFormat->iIndentInTwips = 0;
		}
	iRichEd->ApplyParaFormatL(paraFormat, mask);
	CleanupStack::PopAndDestroy();
	}
Ejemplo n.º 2
0
EXPORT_C void CGlobalText::GetParaFormatL(CParaFormat* aFormat,TParaFormatMask& aVaries,TInt /*aPos*/,TInt /*aLength*/,
										  CParaFormat::TParaFormatGetMode aMode) const
/** Gets the the global text object's effective paragraph formatting. Note that 
the position and length arguments are only used in the rich text implementation 
of this function.

@param aFormat Must not be NULL or a panic occurs. On return, contains the 
effective paragraph formatting for the global text object. 
@param aVaries On return, a bitmask indicating which paragraph format attributes 
vary over the range of characters selected. This is only relevant for rich 
text, so for global text returns a value of zero for all attributes. 
@param aPos This argument is not used for global text. 
@param aLength This argument is not used for global text. 
@param aMode The default, EAllAttributes indicates that values for all paragraph 
format attributes are written to aFormat. EFixedAttributes indicates that 
tabs, bullets and borders are not written to aFormat. */
	{
	iGlobalParaFormatLayer->SenseEffectiveL(aFormat,aMode);
	aVaries.ClearAll();
	}
Ejemplo n.º 3
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();
        }
    }