javauis/eswt_akn/org.eclipse.ercp.swt.s60/native/src/swtcaptionedcontrol.cpp
branchRCL_3
changeset 60 6c158198356e
parent 46 4376525cdefb
equal deleted inserted replaced
59:e5618cc85d74 60:6c158198356e
   146     if (iDefaultFont)
   146     if (iDefaultFont)
   147     {
   147     {
   148         iDefaultFont->RemoveRef();
   148         iDefaultFont->RemoveRef();
   149         iDefaultFont = NULL;
   149         iDefaultFont = NULL;
   150     }
   150     }
   151 
       
   152     // Not Own
       
   153     iForegroundColor = NULL;
       
   154 }
   151 }
   155 
   152 
   156 // ---------------------------------------------------------------------------
   153 // ---------------------------------------------------------------------------
   157 // CSwtCaptionedControl::ConstructL
   154 // CSwtCaptionedControl::ConstructL
   158 // ---------------------------------------------------------------------------
   155 // ---------------------------------------------------------------------------
   173     iControl->SetContainerWindowL(*this); // Absolutely necessary
   170     iControl->SetContainerWindowL(*this); // Absolutely necessary
   174     iControl->SetMopParent(this); // Absolutely necessary
   171     iControl->SetMopParent(this); // Absolutely necessary
   175     iControl->SetFocusing(ETrue);
   172     iControl->SetFocusing(ETrue);
   176     iControl->ActivateL();
   173     iControl->ActivateL();
   177 
   174 
   178     SetDefaultForegroundL();
       
   179     SetBackground(this);    // Back will be drawn by ASwtControlBase::Draw
   175     SetBackground(this);    // Back will be drawn by ASwtControlBase::Draw
   180     ActivateL();
   176     ActivateL();
       
   177 
       
   178     UpdateTextColor();
   181 }
   179 }
   182 
   180 
   183 // ---------------------------------------------------------------------------
   181 // ---------------------------------------------------------------------------
   184 // CSwtCaptionedControl::Child
   182 // CSwtCaptionedControl::Child
   185 // ---------------------------------------------------------------------------
   183 // ---------------------------------------------------------------------------
   226 //
   224 //
   227 inline void CSwtCaptionedControl::SetChild(MSwtControl* aChild)
   225 inline void CSwtCaptionedControl::SetChild(MSwtControl* aChild)
   228 {
   226 {
   229     ASSERT(iControl);
   227     ASSERT(iControl);
   230     static_cast<CControlProxy*>(iControl)->iChild = aChild;
   228     static_cast<CControlProxy*>(iControl)->iChild = aChild;
   231 }
       
   232 
       
   233 // ---------------------------------------------------------------------------
       
   234 // CSwtCaptionedControl::SetEmphasis
       
   235 // ---------------------------------------------------------------------------
       
   236 //
       
   237 void CSwtCaptionedControl::SetEmphasis(TDrawNow /*aDrawNow*/)
       
   238 {
       
   239     // If foreground color has not been set then update according to focus
       
   240     if (!iForegroundColor)
       
   241     {
       
   242         TRAP_IGNORE(SetDefaultForegroundL());
       
   243     }
       
   244     Redraw();
       
   245 }
   229 }
   246 
   230 
   247 // ---------------------------------------------------------------------------
   231 // ---------------------------------------------------------------------------
   248 // CSwtCaptionedControl::ComputeInnerRect
   232 // CSwtCaptionedControl::ComputeInnerRect
   249 // ---------------------------------------------------------------------------
   233 // ---------------------------------------------------------------------------
   308     CEikCaptionedControl::SetSize(iInnerRect.Size());
   292     CEikCaptionedControl::SetSize(iInnerRect.Size());
   309 
   293 
   310     // Set our rect to its real value
   294     // Set our rect to its real value
   311     iPosition = realPosition;
   295     iPosition = realPosition;
   312     CEikCaptionedControl::SetSizeWithoutNotification(realSizeToSet);
   296     CEikCaptionedControl::SetSizeWithoutNotification(realSizeToSet);
   313 }
       
   314 
       
   315 // ---------------------------------------------------------------------------
       
   316 // CSwtCaptionedControl::SetDefaultForegroundL
       
   317 // ---------------------------------------------------------------------------
       
   318 //
       
   319 void CSwtCaptionedControl::SetDefaultForegroundL()
       
   320 {
       
   321     TRgb defaultColor;
       
   322     TAknsQsnTextColorsIndex colorIndex;
       
   323     if (iDisplay.UiUtils().NaviKeyInput() && IsFocusedOrChildIsFocused())
       
   324     {
       
   325         colorIndex = EAknsCIQsnTextColorsCG10;
       
   326     }
       
   327     else
       
   328     {
       
   329         colorIndex = EAknsCIQsnTextColorsCG6;
       
   330     }
       
   331     if (AknsUtils::GetCachedColor(AknsUtils::SkinInstance(), defaultColor,
       
   332                                   KAknsIIDQsnTextColors, colorIndex) == KErrNone)
       
   333     {
       
   334         OverrideColorL(EColorLabelText, defaultColor);
       
   335     }
       
   336 }
   297 }
   337 
   298 
   338 // ---------------------------------------------------------------------------
   299 // ---------------------------------------------------------------------------
   339 // CSwtCaptionedControl::GetRecursiveChildrenL
   300 // CSwtCaptionedControl::GetRecursiveChildrenL
   340 // ---------------------------------------------------------------------------
   301 // ---------------------------------------------------------------------------
   692 // CSwtCaptionedControl::SwtHandleResourceChangeL
   653 // CSwtCaptionedControl::SwtHandleResourceChangeL
   693 // ---------------------------------------------------------------------------
   654 // ---------------------------------------------------------------------------
   694 //
   655 //
   695 void CSwtCaptionedControl::SwtHandleResourceChangeL(TInt aType)
   656 void CSwtCaptionedControl::SwtHandleResourceChangeL(TInt aType)
   696 {
   657 {
   697     if (aType == KAknsMessageSkinChange || aType == KEikDynamicLayoutVariantSwitch)
       
   698     {
       
   699         if (!iForegroundColor)
       
   700         {
       
   701             SetDefaultForegroundL();
       
   702         }
       
   703     }
       
   704 
       
   705     CEikCaptionedControl::HandleResourceChange(aType);
   658     CEikCaptionedControl::HandleResourceChange(aType);
   706 
   659 
   707     CCoeControl* coeChild = CoeChild();
   660     CCoeControl* coeChild = CoeChild();
   708     if (coeChild)
   661     if (coeChild)
   709     {
   662     {
   749                     iTrailer->iMargin.iTop = captionRealFontHeight
   702                     iTrailer->iMargin.iTop = captionRealFontHeight
   750                                              - font->HeightInPixels();
   703                                              - font->HeightInPixels();
   751                 }
   704                 }
   752             }
   705             }
   753         }
   706         }
       
   707 
       
   708         if (aType == KAknsMessageSkinChange)
       
   709         {
       
   710             UpdateTextColor();
       
   711         }
   754     }
   712     }
   755 }
   713 }
   756 
   714 
   757 // ---------------------------------------------------------------------------
   715 // ---------------------------------------------------------------------------
   758 // CSwtCaptionedControl::SetForegroundL
   716 // CSwtCaptionedControl::SetForegroundL
   760 // ---------------------------------------------------------------------------
   718 // ---------------------------------------------------------------------------
   761 //
   719 //
   762 void CSwtCaptionedControl::SetForegroundL(const MSwtColor* aColor)
   720 void CSwtCaptionedControl::SetForegroundL(const MSwtColor* aColor)
   763 {
   721 {
   764     ASwtControlBase::DoSetForegroundL(aColor);
   722     ASwtControlBase::DoSetForegroundL(aColor);
   765     SetColorL(EColorLabelText, aColor);
   723     iCustomFg = aColor;
   766     if (!aColor)
   724     UpdateTextColor();
   767     {
       
   768         SetDefaultForegroundL();
       
   769     }
       
   770     iForegroundColor = aColor;
       
   771     Redraw();
   725     Redraw();
       
   726 }
       
   727 
       
   728 // ---------------------------------------------------------------------------
       
   729 // CSwtCaptionedControl::UpdateTextColor
       
   730 // From MSwtControl
       
   731 // ---------------------------------------------------------------------------
       
   732 //
       
   733 void CSwtCaptionedControl::UpdateTextColor()
       
   734 {
       
   735     TRgb color(0);
       
   736     TInt err(KErrNone);
       
   737 
       
   738     if (HasHighlight())
       
   739     {
       
   740         // Highlighted foreground color, overrides all others.
       
   741         err = AknsUtils::GetCachedColor(AknsUtils::SkinInstance()
       
   742                                         , color
       
   743                                         , KAknsIIDQsnTextColors
       
   744                                         , KHighlightedTextColor);
       
   745     }
       
   746     else if (iCustomFg)
       
   747     {
       
   748         // Custom foreground color, overrides the default.
       
   749         color = iCustomFg->RgbValue();
       
   750     }
       
   751     else
       
   752     {
       
   753         // Default foreground color.
       
   754         err = AknsUtils::GetCachedColor(AknsUtils::SkinInstance()
       
   755                                         , color
       
   756                                         , KAknsIIDQsnTextColors
       
   757                                         , KNonHighlightedTextColor);
       
   758     }
       
   759 
       
   760     if (err == KErrNone)
       
   761     {
       
   762         TRAP_IGNORE(OverrideColorL(EColorLabelText, color));
       
   763     }
       
   764 }
       
   765 
       
   766 // ---------------------------------------------------------------------------
       
   767 // CSwtCaptionedControl::HandleHighlightChange
       
   768 // From MSwtControl
       
   769 // ---------------------------------------------------------------------------
       
   770 //
       
   771 void CSwtCaptionedControl::HandleHighlightChange()
       
   772 {
       
   773     UpdateTextColor();
       
   774     MSwtControl* child = Child();
       
   775     if (child)
       
   776     {
       
   777         child->HandleHighlightChange();
       
   778     }
   772 }
   779 }
   773 
   780 
   774 // ---------------------------------------------------------------------------
   781 // ---------------------------------------------------------------------------
   775 // CSwtCaptionedControl::FocusChanged
   782 // CSwtCaptionedControl::FocusChanged
   776 // From CCoeControl
   783 // From CCoeControl
   777 // ---------------------------------------------------------------------------
   784 // ---------------------------------------------------------------------------
   778 //
   785 //
   779 void CSwtCaptionedControl::FocusChanged(TDrawNow aDrawNow)
   786 void CSwtCaptionedControl::FocusChanged(TDrawNow aDrawNow)
   780 {
   787 {
   781     HandleFocusChanged(aDrawNow);
   788     HandleFocusChanged(aDrawNow);
   782     SetEmphasis(aDrawNow);
       
   783 }
   789 }
   784 
   790 
   785 // ---------------------------------------------------------------------------
   791 // ---------------------------------------------------------------------------
   786 // CSwtCaptionedControl::SizeChanged
   792 // CSwtCaptionedControl::SizeChanged
   787 // From CCoeControl
   793 // From CCoeControl
  1628 // From MSwtComposite
  1634 // From MSwtComposite
  1629 // ---------------------------------------------------------------------------
  1635 // ---------------------------------------------------------------------------
  1630 //
  1636 //
  1631 void CSwtCaptionedControl::ChildFocusChanged(MSwtControl& aControl)
  1637 void CSwtCaptionedControl::ChildFocusChanged(MSwtControl& aControl)
  1632 {
  1638 {
  1633     SetEmphasis(ENoDrawNow);
       
  1634     GetParent()->ChildFocusChanged(aControl);
  1639     GetParent()->ChildFocusChanged(aControl);
  1635 }
  1640 }
  1636 
  1641 
  1637 // ---------------------------------------------------------------------------
  1642 // ---------------------------------------------------------------------------
  1638 // CSwtComposite::CountFocusableChildren
  1643 // CSwtComposite::CountFocusableChildren
  1814     {
  1819     {
  1815         iCaption->SetContainerWindowL(*this); // Absolutely necessary
  1820         iCaption->SetContainerWindowL(*this); // Absolutely necessary
  1816         iCaption->SetMopParent(this); // Absolutely necessary
  1821         iCaption->SetMopParent(this); // Absolutely necessary
  1817         iCaption->MakeVisible(IsVisible());
  1822         iCaption->MakeVisible(IsVisible());
  1818         iCaption->SetDimmed(IsDimmed());
  1823         iCaption->SetDimmed(IsDimmed());
  1819         SetEmphasis(ENoDrawNow);
       
  1820         if (AknLayoutUtils::LayoutMirrored())
  1824         if (AknLayoutUtils::LayoutMirrored())
  1821         {
  1825         {
  1822             iCaption->SetAlignment(EHRightVCenter);
  1826             iCaption->SetAlignment(EHRightVCenter);
  1823         }
  1827         }
  1824         else
  1828         else
  1839         TInt captionRealFontHeight;
  1843         TInt captionRealFontHeight;
  1840         if (RealFontHeight(captionRealFontHeight))
  1844         if (RealFontHeight(captionRealFontHeight))
  1841         {
  1845         {
  1842             iCaption->iMargin.iTop = captionRealFontHeight - font.HeightInPixels();
  1846             iCaption->iMargin.iTop = captionRealFontHeight - font.HeightInPixels();
  1843         }
  1847         }
       
  1848 
       
  1849         UpdateTextColor();
  1844     }
  1850     }
  1845 
  1851 
  1846     // We force a call to ( private ) SizeChanged to resize the components.
  1852     // We force a call to ( private ) SizeChanged to resize the components.
  1847     ResetMinimumSizes();
  1853     ResetMinimumSizes();
  1848     SetWidgetSize(iSize);
  1854     SetWidgetSize(iSize);
  1871     {
  1877     {
  1872         iTrailer->SetContainerWindowL(*this); // Absolutely necessary
  1878         iTrailer->SetContainerWindowL(*this); // Absolutely necessary
  1873         iTrailer->SetMopParent(this); // Absolutely necessary
  1879         iTrailer->SetMopParent(this); // Absolutely necessary
  1874         iTrailer->MakeVisible(IsVisible());
  1880         iTrailer->MakeVisible(IsVisible());
  1875         iTrailer->SetDimmed(IsDimmed());
  1881         iTrailer->SetDimmed(IsDimmed());
  1876         SetEmphasis(ENoDrawNow);
       
  1877         iTrailer->ActivateL();
  1882         iTrailer->ActivateL();
  1878     }
  1883     }
  1879 
  1884 
  1880     if (iTrailer)
  1885     if (iTrailer)
  1881     {
  1886     {
  1888         TInt captionRealFontHeight;
  1893         TInt captionRealFontHeight;
  1889         if (RealFontHeight(captionRealFontHeight))
  1894         if (RealFontHeight(captionRealFontHeight))
  1890         {
  1895         {
  1891             iTrailer->iMargin.iTop = captionRealFontHeight - font.HeightInPixels();
  1896             iTrailer->iMargin.iTop = captionRealFontHeight - font.HeightInPixels();
  1892         }
  1897         }
       
  1898 
       
  1899         UpdateTextColor();
  1893     }
  1900     }
  1894 
  1901 
  1895     // We force a call to ( private ) SizeChanged to resize the components.
  1902     // We force a call to ( private ) SizeChanged to resize the components.
  1896     ResetMinimumSizes();
  1903     ResetMinimumSizes();
  1897     SetWidgetSize(iSize);
  1904     SetWidgetSize(iSize);