javauis/lcdui_akn/lcdui/src/CMIDTextEditorEdwinCustomDraw.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 11 May 2010 16:07:20 +0300
branchRCL_3
changeset 24 0fd27995241b
parent 19 04becd199f91
child 25 9ac0a0a7da70
permissions -rw-r--r--
Revision: v2.1.24 Kit: 201019


/*
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Defines custom drawing for text editor edwin.
*
*/


// INTERNAL INCLUDES
#include "CMIDTextEditorEdwinCustomDraw.h"

// EXTERNAL INCLUDES
#include <j2me/jdebug.h>

// ---------------------------------------------------------------------------
// CMIDTextEditorEdwinCustomDraw::CMIDTextEditorEdwinCustomDraw
// ---------------------------------------------------------------------------
//
CMIDTextEditorEdwinCustomDraw::CMIDTextEditorEdwinCustomDraw(
    const MLafEnv& aLafEnv,
    const MFormCustomDraw& aParentDraw,
    const CMIDTextEditorEdwin& aEdwin) :
        CLafEdwinCustomDrawBase(aLafEnv, aEdwin),
        iEdwin(aEdwin), iParentDraw(aParentDraw)
{
    DEBUG("CMIDTextEditorEdwinCustomDraw::CMIDTextEditorEdwinCustomDraw");
}

// ---------------------------------------------------------------------------
// CMIDTextEditorEdwinCustomDraw::~CMIDTextEditorEdwinCustomDraw
// ---------------------------------------------------------------------------
//
CMIDTextEditorEdwinCustomDraw::~CMIDTextEditorEdwinCustomDraw()
{
    DEBUG("CMIDTextEditorEdwinCustomDraw::~CMIDTextEditorEdwinCustomDraw");
}

// ---------------------------------------------------------------------------
// CMIDTextEditorEdwinCustomDraw::DrawBackground
// (other items were commented in the header file)
// ---------------------------------------------------------------------------
//
void CMIDTextEditorEdwinCustomDraw::DrawBackground(
    const TParam& aParam,
    const TRgb& aBackground,
    TRect& aDrawn) const
{
    // Background drawing is not done by custom draw.

    // Check if CCoeControl::Draw() has been invoked for the editor window.
    // This guarantees that draw is not invoked all the time. Redraw
    // removes the issue with background transparency because if FEP tries
    // to draw the text without the CONE control framework, the editor gets
    // redrawn which guarantees that the text is not messed up due to
    // the editor's transparency.

    if (iEdwin.IsTransparent())
    {
        iEdwin.Redraw();
    }
    else
    {
        iParentDraw.DrawBackground(aParam, aBackground, aDrawn);
    }
}

// ---------------------------------------------------------------------------
// CMIDTextEditorEdwinCustomDraw::DrawLineGraphics
// (other items were commented in the header file)
// ---------------------------------------------------------------------------
//
void CMIDTextEditorEdwinCustomDraw::DrawLineGraphics(
    const TParam& aParam,
    const TLineInfo& aLineInfo) const
{
    iParentDraw.DrawLineGraphics(aParam, aLineInfo);
}

// ---------------------------------------------------------------------------
// CMIDTextEditorEdwinCustomDraw::DrawText
// (other items were commented in the header file)
// ---------------------------------------------------------------------------
//
void CMIDTextEditorEdwinCustomDraw::DrawText(
    const TParam& aParam,
    const TLineInfo& aLineInfo,
    const TCharFormat& aFormat,
    const TDesC& aText,
    const TPoint& aTextOrigin,
    TInt aExtraPixels) const
{
    // If transparency is enabled, check that if draw has not been invoked
    // yet and issue redraw in that case. This removes the issue with
    // transparency so that the old content does not cause corruption to
    // the new text drawn on top of the old content. Otherwise it is ok
    // to draw the text because opaque background draws on top of the old
    // content in the editor.

    if (iEdwin.IsTransparent() && !iEdwin.DrawOngoing())
    {
        iEdwin.Redraw();
        return;
    }

    iParentDraw.DrawText(
        aParam,
        aLineInfo,
        aFormat,
        aText,
        aTextOrigin,
        aExtraPixels);
}

#ifdef RD_JAVA_S60_RELEASE_9_2
// ---------------------------------------------------------------------------
// CMIDTextEditorEdwinCustomDraw::DrawText
// (other items were commented in the header file)
// ---------------------------------------------------------------------------
//
void CMIDTextEditorEdwinCustomDraw::DrawText(
    const TParam& aParam,
    const TLineInfo& aLineInfo,
    const TCharFormat& aFormat,
    const TDesC& aText,
    const TInt aStart,
    const TInt aEnd,
    const TPoint& aTextOrigin,
    TInt aExtraPixels) const
{
    // If transparency is enabled, check that if draw has not been invoked
    // yet and issue redraw in that case. This removes the issue with
    // transparency so that the old content does not cause corruption to
    // the new text drawn on top of the old content. Otherwise it is ok
    // to draw the text because opaque background draws on top of the old
    // content in the editor.

    if (iEdwin.IsTransparent() && !iEdwin.DrawOngoing())
    {
        iEdwin.Redraw();
        return;
    }

    iParentDraw.DrawText(
        aParam,
        aLineInfo,
        aFormat,
        aText,
        aStart,
        aEnd,
        aTextOrigin,
        aExtraPixels);
}
#endif

// ---------------------------------------------------------------------------
// CMIDTextEditorEdwinCustomDraw::SystemColor
// (other items were commented in the header file)
// ---------------------------------------------------------------------------
//
TRgb CMIDTextEditorEdwinCustomDraw::SystemColor(
    TUint aColorIndex,
    TRgb aDefaultColor) const
{
    TRgb ret;

    // Return custom highlight color if retrieved by the system.
    if (aColorIndex == TLogicalRgb::ESystemSelectionBackgroundIndex)
    {
        iEdwin.GetColor(EColorControlHighlightBackground, ret);
    }
    else
    {
        // Other colors use parent's SystemColor.
        ret = iParentDraw.SystemColor(aColorIndex, aDefaultColor);
    }

    return ret;
}

// End of file