uiaccelerator_plat/alf_core_toolkit_api/inc/uiacceltk/HuiCanvasVisual.h
changeset 0 15bf7259bb7c
child 3 d8a3531bc6b8
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     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".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   Definition of CHuiCanvasVisual.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef __HUICANVASVISUAL_H__
       
    21 #define __HUICANVASVISUAL_H__
       
    22 
       
    23 
       
    24 #include <gdi.h>
       
    25 #include <bitdraw.h>
       
    26 #include <e32base.h>
       
    27 #include <uiacceltk/HuiOwnedPointer.h>
       
    28 #include <uiacceltk/HuiLayout.h>    
       
    29 #include <uiacceltk/HuiDisplay.h>    
       
    30 
       
    31 
       
    32 /* Forward declarations. */
       
    33 class CHuiControl;
       
    34 class THuiCanvasDrawImageParams;
       
    35 class THuiCanvasTextParameters;
       
    36 class CHuiCanvasGc;
       
    37 class MHuiCanvasPainter;
       
    38 
       
    39  
       
    40 /** Public initial values for ws painter */	
       
    41 #define KHuiWsDefaultUserClipRect TRect(0,0,0,0)
       
    42 #define KHuiWsDefaultLastPrintPosition TPoint(0,0)
       
    43 #define KHuiWsDefaultPenColor KRgbBlack  
       
    44 #define KHuiWsDefaultPenStyle CGraphicsContext::ESolidPen  
       
    45 #define KHuiWsDefaultPenSize TSize(1,1)  
       
    46 #define KHuiWsDefaultDrawMode CGraphicsContext::EDrawModePEN  
       
    47 #define KHuiWsDefaultLinePosition TPoint(0,0)  
       
    48 #define KHuiWsDefaultOrigin TPoint(0,0)  
       
    49 #define KHuiWsDefaultBrushUsed EFalse  
       
    50 #define KHuiWsDefaultBrushColor KRgbWhite  
       
    51 #define KHuiWsDefaultBrushOrigin TPoint(0,0)  
       
    52 #define KHuiWsDefaultBrushStyle CGraphicsContext::ENullBrush  
       
    53 #define KHuiWsDefaultCharJustExcess 0  
       
    54 #define KHuiWsDefaultCharJustNum 0  
       
    55 #define KHuiWsDefaultWordJustExcess 0  
       
    56 #define KHuiWsDefaultWordJustNum 0  
       
    57 #define KHuiWsDefaultDitherOrigin TPoint(0,0)  
       
    58 #define KHuiWsDefaultDotLength 0  
       
    59 #define KHuiWsDefaultDotMask 0  
       
    60 #define KHuiWsDefaultDotParam 0  
       
    61 #define KHuiWsDefaultDotDirection 1  
       
    62 #define KHuiWsDefaultShadowMode CFbsDrawDevice::ENoShadow  
       
    63 #define KHuiWsDefaultStrikethrough EStrikethroughOff  
       
    64 #define KHuiWsDefaultUnderline EUnderlineOff  
       
    65 #define KHuiWsDefaultUserDisplayMode ENone  
       
    66 #define KHuiWsDefaultShadowColor KRgbGray
       
    67 #define KHuiWsDefaultFadeColor 0x80FFFFFF
       
    68 
       
    69 enum THuiCanvasPaintType
       
    70     {
       
    71     /** Transparent or semitransparent */
       
    72     EHuiCanvasPaintTypeTransparent,
       
    73     
       
    74     /** Fully opaque */
       
    75     EHuiCanvasPaintTypeOpaque            
       
    76     };
       
    77 
       
    78 NONSHARABLE_STRUCT (THuiCanvasPaintedArea)
       
    79     {
       
    80     /** Painted area in the canvas */
       
    81     THuiRealRect iPaintedRect;    
       
    82     
       
    83     /** Paint type of the area */
       
    84     TInt iPaintType;
       
    85     
       
    86     /** Reserved for future */
       
    87     TInt iFlags;
       
    88     };
       
    89 
       
    90 enum THuiCanvasFlags
       
    91     {
       
    92     /** Disables canvas from drawing the canvas content */
       
    93     EHuiCanvasFlagDisableCanvasContent    = 0x1,
       
    94     /** Disables canvas from drawing the canvas background (if set) */
       
    95     EHuiCanvasFlagDisableCanvasBackground = 0x2,
       
    96     /** Canvas is drawn with external fade effect */
       
    97     EHuiCanvasFlagExternalFade = 0x4,
       
    98     /** Canvas drawing is clipped to own and parent canvas intersection */
       
    99     EHuiCanvasFlagEnableCanvasClipping = 0x8,           
       
   100     /** External fade effect (if enabled) is extended to children */
       
   101     EHuiCanvasFlagExternalFadeToChildren = 0x10,    
       
   102     /** External fade effect (if enabled) is set to a parent (or grandparent) */
       
   103     EHuiCanvasFlagExternalFadeByParent = 0x40,    
       
   104     /** Effect is excluded from parent (or grandparent) effect (if it has effect which is applied to children) */
       
   105     EHuiCanvasFlagExcludeFromParentEffect = 0x80,
       
   106     /** Hint flag which is used for optimizations. Tells if fade effect(s) exist in visual tree */
       
   107     EHuiCanvasFlagExternalFadeExistsInsideVisualTree = 0x100 
       
   108     };
       
   109 
       
   110 /**
       
   111  * This class is used internally by the toolkit and thus should
       
   112  * not be used by the applications directly.
       
   113  */
       
   114 class CHuiCanvasVisual : public CHuiLayout
       
   115     {
       
   116 public:
       
   117 
       
   118     enum
       
   119         {
       
   120         /** @deprecated */
       
   121         ECommandBufferHui,
       
   122         /** @deprecated */
       
   123         ECommandBufferSgc    
       
   124         };
       
   125 	
       
   126 	enum
       
   127 	    {
       
   128 	    ECommandBufferAlf,
       
   129 	    ECommandBufferWs    
       
   130 	    };
       
   131 	    
       
   132     /* Constructors and destructor. */
       
   133 
       
   134     /**
       
   135      * Constructs and appends a new Canvas visual to the owner control.
       
   136      *
       
   137      * @param aOwnerControl  Control that will own the new visual.    
       
   138      * 
       
   139      * @param aCanvasType The enumerator describing the type of concrete Canvas
       
   140      * to be created.     
       
   141      *
       
   142      * @return  The new visual.
       
   143      */
       
   144     IMPORT_C static CHuiCanvasVisual* AddNewL(CHuiControl& aOwnerControl,
       
   145                                             CHuiLayout* aParentLayout = 0);
       
   146 
       
   147     /**
       
   148      * Constructor.
       
   149      */
       
   150     CHuiCanvasVisual(MHuiVisualOwner& aOwner);
       
   151 
       
   152     /**
       
   153      * Second-phase constructor.
       
   154      */
       
   155     void ConstructL();
       
   156 
       
   157     /**
       
   158      * Destructor.
       
   159      */
       
   160     ~CHuiCanvasVisual();
       
   161 
       
   162     /**
       
   163      * Sets buffer that contains canvas drawing commands. This
       
   164      * method clears previous buffer(s).
       
   165      *
       
   166      * @param aCommands Commanbuffer
       
   167      */
       
   168     IMPORT_C void SetCommandSetL( const TDesC8& aCommands );
       
   169 
       
   170     /**
       
   171      * Sets the type of commands in the buffer.
       
   172      *
       
   173      * @param aCommandType Type of the command buffer, either
       
   174      * ECommandBufferHui or ECommandBufferSgc. In the future
       
   175      * more command set types may be supported.
       
   176      *
       
   177      */
       
   178     IMPORT_C void SetCommandType( TInt aCommandType );
       
   179 
       
   180     /**
       
   181      * Clears buffer(s) that contains canvas drawing commands. 
       
   182      */
       
   183     IMPORT_C void ClearCommandSet();
       
   184     
       
   185     IMPORT_C void SetTrackCommandSet( TFileName& aFileName, TBool aTrack );
       
   186         
       
   187     /**
       
   188      * Adds buffer that contains more canvas drawing commands,
       
   189      * those will be executed after the buffers that has been
       
   190      * added previously.
       
   191      * @param aMoreCommands Commanbuffer
       
   192      */
       
   193     IMPORT_C void AddCommandSetL( const TDesC8& aMoreCommands );
       
   194 
       
   195     /**
       
   196      * Adds partial buffer that contains more canvas drawing commands. These
       
   197      * commands are appended to the commands set previously with this method
       
   198      * until param aLastPart has value ETrue. After that whole command set
       
   199      * will be added among possibly already existing command sets and
       
   200      * it will be drawable.
       
   201      * 
       
   202      * @param aMoreCommands Commanbuffer
       
   203      * @param aLastPart EFalse if there are more commands to be added into this
       
   204      * command set before it is wanted to be available for drawing. ETrue if
       
   205      * command set is ready and no more parts are expected.
       
   206      */
       
   207     IMPORT_C void AddPartialCommandSetL( const TDesC8& aMoreCommands, TBool aLastPart );
       
   208 
       
   209     /**
       
   210      * Clears internal cached texts and images.
       
   211      */
       
   212     IMPORT_C void ClearCache();
       
   213 
       
   214     /**
       
   215      * Prepares internal cached texts and images.
       
   216      */
       
   217     IMPORT_C void PrepareCache();
       
   218     
       
   219     /**
       
   220      * Sets the flag that tells the canvas to clear the background before
       
   221      * doing a refresh. 
       
   222      *
       
   223      * Note1: EClearWithSkinBackground is not (yet) supported.
       
   224      * Note2: EClearWithColor does not do alphablending, it just clears the area 
       
   225      * and writes alpha values to the rendering surface. 
       
   226      *
       
   227      * @param aClearBackground  Background clearing mode. 
       
   228      * @see SetBackgroundColor()
       
   229      */
       
   230     IMPORT_C void SetClearBackground(CHuiDisplay::TClearMode aClearBackground);
       
   231 
       
   232     /**
       
   233      * Sets the background color, if background clearing has
       
   234      * been enabled.
       
   235      *
       
   236      * @param aBackgroundColor  The color to set the background to.
       
   237      * @see SetClearBackgroundL()
       
   238      */
       
   239     IMPORT_C void SetBackgroundColor(const TRgb& aBackgroundColor);
       
   240     
       
   241     /**
       
   242      * Sets the items that specify how to clear display before display refresh.
       
   243      * Items may have overlapping rectangles, drawing order is same as item order
       
   244      * in the parameter array. But having lots of overlapping drawing 
       
   245      * causes negative performance impact.
       
   246      * 
       
   247      * This method is alternative to SetClearBackgroundL and SetBackgroundColor
       
   248      * methods.
       
   249      * 
       
   250      * @see SetBackgroundColor()
       
   251      * @see SetClearBackgroundL()
       
   252      * @param aItems Array of items that specify how to clear the background.
       
   253      */
       
   254     IMPORT_C void SetBackgroundItems(const RArray<THuiDisplayBackgroundItem>& aItems);
       
   255     
       
   256     /**
       
   257      * Returns the number of rectangular areas which contain something that is
       
   258      * drawn by the visual.
       
   259      *
       
   260      * @return number of painted areas.
       
   261      * @see PaintedArea()
       
   262      */
       
   263     IMPORT_C TInt PaintedAreaCount() const;
       
   264     
       
   265     /**
       
   266      * Returns information of the painted area at given index. 
       
   267      *
       
   268      * @param aIndex Index of the painted area.
       
   269      * @return Painted area info.
       
   270      * @see PaintedAreaCount()()
       
   271      */
       
   272     IMPORT_C THuiCanvasPaintedArea PaintedArea(TInt aIndex);
       
   273     
       
   274     /**
       
   275      * Draws content of the window in pixel format to the given bitmap. 
       
   276      * This method may not be supported in all commanbuffertype/renderer combinations.
       
   277      *
       
   278      * @param aTargetBuffer where content of the window is to be drawn. NULL if the drawing
       
   279      * is to be stopped.
       
   280      *
       
   281      * @return KErrNotSupported if the current renderer/painter does not support the
       
   282      * feature. Leave happens in other unexpected error situtations. 
       
   283      *         
       
   284      */
       
   285     IMPORT_C TInt SetCapturingBufferL(CFbsBitmap* aTargetBuffer);
       
   286     
       
   287     /**
       
   288      * Sets canvas flags
       
   289      * @param aCanvasFlags flags to be set
       
   290      *
       
   291      */
       
   292     IMPORT_C void SetCanvasFlags(TInt aCanvasFlags);
       
   293 
       
   294     /**
       
   295      * Clears canvas flags
       
   296      * @param aCanvasFlags flags to be cleared.
       
   297      *
       
   298      */
       
   299     IMPORT_C void ClearCanvasFlags(TInt aCanvasFlags);
       
   300 
       
   301     /**
       
   302      * Gets canvas flags
       
   303      * @return flags
       
   304      *
       
   305      */
       
   306     IMPORT_C TInt CanvasFlags();
       
   307 
       
   308     /**
       
   309      * Set external content visual to be drawn to the canvas visual.
       
   310      * Giving a NULL pointer as a parameter removes the external content.
       
   311      * @param aVisual the visual that is used as external content
       
   312      *
       
   313      */
       
   314 	IMPORT_C void SetExternalContentL(CHuiVisual* aVisual);
       
   315 
       
   316     /**
       
   317      * Return external content visual of the canvas visual.
       
   318      * NULL return value means there is no external content.
       
   319      * @return NULL or the visual that is used as external content
       
   320      */
       
   321     IMPORT_C CHuiVisual* ExternalContent();
       
   322 
       
   323     /**
       
   324      * Set parent canvas visual. Parent is used for determining clipping 
       
   325      * region incase canvasflag EHuiCanvasFlagEnableCanvasClipping is set.
       
   326      *
       
   327      * @param aParent Canvas visual which is used to determine effective 
       
   328      * clipregion.
       
   329      */
       
   330     IMPORT_C void SetParentCanvas(CHuiCanvasVisual* aParent);
       
   331     
       
   332     /**
       
   333      * Gets reference to canvas gc
       
   334      */
       
   335     CHuiCanvasGc& CanvasGc() const;
       
   336 
       
   337     IMPORT_C TBool IsBackgroundDrawingEnabled() const;
       
   338 
       
   339     const TRegion& ClipRegion() const;
       
   340     
       
   341     void AddChildCanvas(CHuiCanvasVisual* aChild);
       
   342 
       
   343     void RemoveChildCanvas(CHuiCanvasVisual* aChild);
       
   344         
       
   345     IMPORT_C TBool HasCommandBuffers(TBool aAskFromChildren = ETrue) const;
       
   346     
       
   347     // to handle background surface that may be set to the Window
       
   348 public:    
       
   349     
       
   350     IMPORT_C TBool LayerUsesAlphaFlag();
       
   351     IMPORT_C void SetLayerUsesAlphaFlag(TBool aEnabled);
       
   352     IMPORT_C TRect& LayerExtent(); 
       
   353     IMPORT_C void SetLayerExtent(TRect& aExtent); 
       
   354 
       
   355 public:
       
   356     
       
   357     void SetSize(const THuiRealSize& aSize, TInt aTransitionTime=0);    
       
   358     TBool ChildSize(TInt aOrdinal, TSize& aSize);    
       
   359     TBool ChildPos(TInt aOrdinal, TPoint& aPos);
       
   360     TInt ChildRect(TInt aOrdinal, THuiRealRect& aRect);        
       
   361 
       
   362     
       
   363 private:
       
   364     
       
   365     void HandleBuffer(TRect& aDisplayRect, TInt aAction, CHuiGc* aGc) const;        
       
   366 
       
   367     void SetCommandTypeL(TInt aCommandType);         
       
   368  
       
   369     TBool IsContentDrawingLayered() const;
       
   370     
       
   371     TBool IsContentDrawingEnabled() const;
       
   372 
       
   373     TBool IsExternalContentDrawingEnabled(TBool aIncludeChildren = EFalse) const;
       
   374     
       
   375     TBool IsCanvasClippingEnabled() const;
       
   376     
       
   377     TBool EffectActive() const;
       
   378     
       
   379 public: // From CHuiVisual
       
   380 
       
   381 	TBool PrepareDrawL();
       
   382 	
       
   383 	void Draw(CHuiGc& aGc) const;
       
   384 
       
   385  	/**
       
   386      * Draw the visual.
       
   387      */
       
   388     void DrawSelf(CHuiGc& aGc, const TRect& aDisplayRect) const;
       
   389 
       
   390     TBool Changed() const;
       
   391 
       
   392     IMPORT_C void SetChanged();
       
   393     
       
   394     IMPORT_C void ClearChanged();
       
   395 
       
   396     void ExpandRectWithContent(TRect& aRect) const;
       
   397     THuiRealPoint ConvertPoint(const THuiRealPoint& aPointInUnits) const;
       
   398     void ExpandRect(TRect& aRectToExpand, const TRect& aNewRect) const;
       
   399 
       
   400 public:    
       
   401     IMPORT_C void StoreRenderBufferL();
       
   402     void DrawStoredVisualRenderBuffer() const;
       
   403     void DrawStoredFullScreenRenderBuffer(CHuiGc& aGc) const;
       
   404     IMPORT_C void FreeRenderBuffer();
       
   405         
       
   406 private:
       
   407        
       
   408     THuiCanvasPaintedArea CanvasPaintedArea(TInt aIndex) const;
       
   409     
       
   410     void DrawChildren(CHuiGc& aGc) const;
       
   411     void DrawCanvasChildren(CHuiGc& aGc, TInt aIncludeCanvasFlags, TInt aExcludeCanvasFlags) const;
       
   412     TBool ChildTreeChanged(TInt aExcludeCanvasFlags) const;
       
   413     
       
   414 private: 
       
   415 
       
   416     struct THuiCanvasVisualData;
       
   417     THuiCanvasVisualData* iCanvasVisualData;
       
   418 
       
   419 
       
   420     };
       
   421 
       
   422 #endif  // __HUICANVASVISUAL_H__