uiacceltk/hitchcock/coretoolkit/src/HuiBrushArray.cpp
changeset 0 15bf7259bb7c
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:   ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "uiacceltk/HuiBrushArray.h"
       
    21 #include "uiacceltk/HuiVisual.h"
       
    22 #include "uiacceltk/HuiGc.h"
       
    23 #include "uiacceltk/HuiPanic.h"
       
    24 
       
    25 
       
    26 EXPORT_C CHuiBrushArray* CHuiBrushArray::NewL()
       
    27     {
       
    28     CHuiBrushArray* self = NewLC();
       
    29     CleanupStack::Pop(self);
       
    30     return self;
       
    31     }
       
    32     
       
    33     
       
    34 EXPORT_C CHuiBrushArray* CHuiBrushArray::NewLC()
       
    35     {
       
    36     CHuiBrushArray* self = new (ELeave) CHuiBrushArray();
       
    37     CleanupStack::PushL(self);
       
    38     return self;
       
    39     }
       
    40 
       
    41 
       
    42 CHuiBrushArray::CHuiBrushArray()
       
    43     {
       
    44     }
       
    45     
       
    46   
       
    47 EXPORT_C CHuiBrushArray::~CHuiBrushArray()
       
    48     {
       
    49     Reset();
       
    50     }
       
    51   
       
    52     
       
    53 EXPORT_C void CHuiBrushArray::Reset()
       
    54     {
       
    55     iElements.ResetAndDestroy();
       
    56     }
       
    57 
       
    58 
       
    59 EXPORT_C void CHuiBrushArray::AppendL(CHuiBrush* aBrush, THuiOwnership aOwnership)
       
    60     {
       
    61     if (!aBrush) // RArrayElement can't handle null ptr correctly in all cases
       
    62         {
       
    63         User::Leave(KErrArgument);
       
    64         }
       
    65         
       
    66     RArrayElement* element = new (ELeave) RArrayElement();
       
    67     CleanupStack::PushL(element);
       
    68     User::LeaveIfError(iElements.Append(element));
       
    69     CleanupStack::Pop(element);
       
    70     
       
    71     element->Set(aBrush, aOwnership);
       
    72     }
       
    73 
       
    74 
       
    75 EXPORT_C void CHuiBrushArray::InsertL(TInt aPos, CHuiBrush* aBrush, 
       
    76                                       THuiOwnership aOwnership)
       
    77     {
       
    78     if (!aBrush) // RArrayElement can't handle null ptr correctly in all cases
       
    79         {
       
    80         User::Leave(KErrArgument);
       
    81         }
       
    82 
       
    83     RArrayElement* element = new (ELeave) RArrayElement();
       
    84     CleanupStack::PushL(element);
       
    85     User::LeaveIfError(iElements.Insert(element, aPos));
       
    86     CleanupStack::Pop(element);
       
    87     
       
    88     element->Set(aBrush, aOwnership);
       
    89     }
       
    90 
       
    91 
       
    92 EXPORT_C void CHuiBrushArray::Remove(TInt aPos)
       
    93     {
       
    94     if ( aPos >= Count() )
       
    95         {
       
    96         // if does not exist, just return
       
    97         return;
       
    98         }
       
    99     delete iElements[aPos];
       
   100     iElements.Remove(aPos);
       
   101     }
       
   102 
       
   103 
       
   104 EXPORT_C TInt CHuiBrushArray::Count() const
       
   105     {
       
   106     return iElements.Count();
       
   107     }
       
   108     
       
   109     
       
   110 EXPORT_C CHuiBrush& CHuiBrushArray::operator [] (TInt aPos)
       
   111     {
       
   112     return iElements[aPos]->Ref();
       
   113     }
       
   114     
       
   115     
       
   116 EXPORT_C CHuiBrush& CHuiBrushArray::At(TInt aPos)
       
   117     {
       
   118     return iElements[aPos]->Ref();
       
   119     }
       
   120 
       
   121 
       
   122 EXPORT_C void CHuiBrushArray::Draw(THuiBrushLayer aLayer, CHuiGc& aGc, 
       
   123                                    const MHuiBrushGuide& aGuide) const
       
   124     {
       
   125     TInt layerBrushCount = LayerBrushCount(aLayer);
       
   126     TInt depth = 0;
       
   127 
       
   128     if(!layerBrushCount)
       
   129         {
       
   130         // Nothing on this layer.
       
   131         return;
       
   132         }
       
   133 
       
   134     if(aLayer == EHuiBrushLayerBackground)
       
   135         {
       
   136         depth = -layerBrushCount - 1;
       
   137         }
       
   138     
       
   139     for(TInt i = 0; i < Count(); ++i)
       
   140         {
       
   141         CHuiBrush& brush = iElements[i]->Ref();
       
   142         
       
   143         if(brush.Layer() == aLayer)
       
   144             {
       
   145             // Polygon depth offset to avoid Z-conflicts.
       
   146             if(aLayer == EHuiBrushLayerBackground || 
       
   147                aLayer == EHuiBrushLayerForeground)
       
   148                 {
       
   149                 ++depth;                
       
   150                 }
       
   151             aGc.SetDepthOffset(-depth);
       
   152             
       
   153             brush.BeginDraw(aGc, aGuide);
       
   154             brush.Draw(aGc, aGuide);
       
   155             brush.EndDraw(aGc, aGuide);
       
   156             }
       
   157         }
       
   158         
       
   159     // Reset depth offset back to zero.
       
   160     aGc.SetDepthOffset(0);    
       
   161     }
       
   162 
       
   163 
       
   164 EXPORT_C TInt CHuiBrushArray::LayerBrushCount(THuiBrushLayer aLayer) const
       
   165     {
       
   166     TInt count = 0;
       
   167     
       
   168     for(TInt i = 0; i < Count(); ++i)
       
   169         {
       
   170         if(iElements[i]->Ref().Layer() == aLayer)
       
   171             {
       
   172             ++count;
       
   173             }
       
   174         }    
       
   175     
       
   176     return count;
       
   177     }
       
   178 EXPORT_C TInt CHuiBrushArray::BrushWithTypeCount(TInt aBrushType) const
       
   179     {
       
   180     TInt count = 0;
       
   181     TInt num = Count();
       
   182     for(TInt i=0;i<num;i++)
       
   183         {
       
   184         if (iElements[i]->Ref().Type2()==aBrushType)
       
   185             {
       
   186             count++;
       
   187             }
       
   188         }
       
   189     return count;
       
   190     }
       
   191 EXPORT_C CHuiBrush *CHuiBrushArray::BrushWithTypeAt(TInt aBrushType, TInt aIndex)
       
   192     {
       
   193     TInt count = 0;
       
   194     TInt num = Count();
       
   195     for(TInt i=0;i<num;i++)
       
   196         {
       
   197         if (iElements[i]->Ref().Type2()==aBrushType)
       
   198             {
       
   199             if (count == aIndex)
       
   200                 {
       
   201                 return &iElements[i]->Ref();
       
   202                 }
       
   203             count++;
       
   204             }
       
   205         }
       
   206     return 0;    
       
   207     }
       
   208     
       
   209     
       
   210 TBool CHuiBrushArray::Changed() const
       
   211     {
       
   212     for(TInt i = 0; i < iElements.Count(); ++i)
       
   213         {
       
   214         if(iElements[i]->Ref().Changed())
       
   215             {
       
   216             return ETrue;
       
   217             }
       
   218         }
       
   219     return EFalse;
       
   220     }
       
   221     
       
   222     
       
   223 void CHuiBrushArray::ClearChanged()
       
   224     {
       
   225     for(TInt i = 0; i < Count(); ++i)
       
   226         {
       
   227         iElements[i]->Ref().ClearChanged();
       
   228         }
       
   229     }
       
   230     
       
   231     
       
   232 void CHuiBrushArray::ExpandVisualRect(TRect& aRect) const
       
   233     {
       
   234     TRect original = aRect;
       
   235     
       
   236     for(TInt i = 0; i < Count(); ++i)
       
   237         {
       
   238         CHuiBrush& brush = iElements[i]->Ref();
       
   239 
       
   240         // If the drawing of the brush is clipped to visual contents,
       
   241         // there is no need to expand the rectangle.
       
   242         if(!brush.ClipToVisual())
       
   243             {
       
   244             TRect expanded = original;
       
   245             brush.ExpandVisualRect(expanded);
       
   246             aRect.BoundingRect(expanded);
       
   247             }
       
   248         }
       
   249     }
       
   250 
       
   251 
       
   252 void CHuiBrushArray::ActivateBrushGuide(const CHuiVisual* aNewGuide) const
       
   253     {
       
   254     for(TInt i = 0; i < Count(); ++i)
       
   255         {
       
   256         CHuiBrush& brush = iElements[i]->Ref();
       
   257         brush.ActivateBrushGuide(aNewGuide);
       
   258         }        
       
   259     }