javauis/eswt_akn/org.eclipse.ercp.swt.s60/native/src/swtcontrolbase.cpp
branchRCL_3
changeset 60 6c158198356e
parent 59 e5618cc85d74
equal deleted inserted replaced
59:e5618cc85d74 60:6c158198356e
    71                         CSwtLafFacade::EInputFieldSkinPlacingGeneralLine2, rect, 0).Rect().iBr;
    71                         CSwtLafFacade::EInputFieldSkinPlacingGeneralLine2, rect, 0).Rect().iBr;
    72     innerRect.iBr = CSwtLafFacade::GetLayoutRect(
    72     innerRect.iBr = CSwtLafFacade::GetLayoutRect(
    73                         CSwtLafFacade::EInputFieldSkinPlacingGeneralLine5, rect, 0).Rect().iTl;
    73                         CSwtLafFacade::EInputFieldSkinPlacingGeneralLine5, rect, 0).Rect().iTl;
    74 
    74 
    75     iFocusFrame = CAknsFrameBackgroundControlContext::NewL(
    75     iFocusFrame = CAknsFrameBackgroundControlContext::NewL(
    76 #ifdef RD_JAVA_S60_RELEASE_9_2
    76                       KAknsIIDQsnFrInput, rect, innerRect, EFalse /*parent absolute*/);
    77                       KAknsIIDQsnFrPopupPreview,
       
    78 #else
       
    79                       KAknsIIDQsnFrInput,
       
    80 #endif // RD_JAVA_S60_RELEASE_9_2
       
    81                       rect, innerRect, EFalse /*parent absolute*/);
       
    82 
    77 
    83     if (iBackgrdDefaultUsed)
    78     if (iBackgrdDefaultUsed)
    84     {
    79     {
    85         iFocusFrame->SetParentContext(SwtMopSupplyCtrlContext(EFalse));
    80         iFocusFrame->SetParentContext(SwtMopSupplyCtrlContext(EFalse));
    86     }
    81     }
    87 }
    82 }
    88 
    83 
    89 CAknsBasicBackgroundControlContext* ASwtControlBase::FocusBackgroundNow() const
    84 CAknsBasicBackgroundControlContext* ASwtControlBase::FocusBackgroundNow() const
    90 {
    85 {
    91 #ifdef RD_JAVA_S60_RELEASE_9_2
    86     if (HasHighlight(EFalse)) // not checking parents
    92     if (!iDisplay.UiUtils().NaviKeyInput() && !iPressed)
    87     {
       
    88         return iFocusFrame;
       
    89     }
       
    90     else
    93     {
    91     {
    94         return NULL;
    92         return NULL;
    95     }
    93     }
    96 #endif // RD_JAVA_S60_RELEASE_9_2
       
    97 
       
    98     // Pressed down state shows the highlight no matter what.
       
    99     if (!iPressed)
       
   100     {
       
   101         TInt policy = FocusBackgroundPolicy();
       
   102 
       
   103         // CaptionedControls that have a custom back color set provide a highlight with
       
   104         // no parent context and that can be a problem for semi transparent highligts.
       
   105         // The remedy for this is to let the child control draw its own highlight for
       
   106         // as long as the parent CaptionedControl has the custom background color set.
       
   107         if ((policy == ENoFocusBackground)
       
   108                 || (policy == EEmbeddedFocusBackground)
       
   109                 || (iParent && iParent->Control()->CaptionedControlInterface() && iParent->Control()->IsDefaultBackgroundUse())
       
   110                 || (policy == ECaptionedCtrlFocusBackground && !IsFocusedOrChildIsFocused())
       
   111                 || (policy == EDefaultFocusBackground && GetShell().FocusControl() != this)
       
   112                 || (GetShell().Composite()->CountFocusableChildren(1, this) == 0))
       
   113         {
       
   114             return NULL;
       
   115         }
       
   116     }
       
   117 
       
   118     // If we got here, it means we have to draw a focus background.
       
   119     if (!iFocusFrame)
       
   120     {
       
   121         TRAP_IGNORE(const_cast<ASwtControlBase*>(this)->CreateFocusBackgroundL());
       
   122     }
       
   123 
       
   124     return iFocusFrame;
       
   125 }
    94 }
   126 
    95 
   127 void ASwtControlBase::RedrawFocusBackground()
    96 void ASwtControlBase::RedrawFocusBackground()
   128 {
    97 {
   129     MSwtCaptionedControl* captCtrl = GetTopCaptionedControl();
    98     MSwtCaptionedControl* captCtrl = GetNearestCaptionedControl();
   130     if (captCtrl)
    99     if (captCtrl)
   131     {
   100     {
   132         captCtrl->Composite()->Control()->Redraw();
   101         captCtrl->Composite()->Control()->Redraw();
   133     }
   102     }
   134     else
   103     else
   464 
   433 
   465     MSwtShell& shell = GetShell();
   434     MSwtShell& shell = GetShell();
   466     MSwtControl* urgentPaintControl = shell.UrgentPaintControl();
   435     MSwtControl* urgentPaintControl = shell.UrgentPaintControl();
   467     if (urgentPaintControl)
   436     if (urgentPaintControl)
   468     {
   437     {
       
   438         // Redraw requests outside urgently painted controls are ignored.
   469         if (IsDescentOf(*urgentPaintControl))
   439         if (IsDescentOf(*urgentPaintControl))
   470         {
   440         {
   471             urgentPaintControl->PaintUrgently(aRect);
   441             urgentPaintControl->PaintUrgently(aRect);
   472         }
   442         }
   473     }
   443     }
   528     {
   498     {
   529         rect = ClipToVisibleRect(rect);
   499         rect = ClipToVisibleRect(rect);
   530     }
   500     }
   531 
   501 
   532     return rect;
   502     return rect;
       
   503 }
       
   504 
       
   505 EXPORT_C TBool ASwtControlBase::HasHighlight(TBool aIncludingParents /*= ETrue*/) const
       
   506 {
       
   507     TBool res = iHighlightEnabled;
       
   508     if (!res && aIncludingParents)
       
   509     {
       
   510         res = res || (iParent && iParent->Control()->HasHighlight(ETrue));
       
   511     }
       
   512     return res;
       
   513 }
       
   514 
       
   515 EXPORT_C void ASwtControlBase::SetHighlight(TBool aEnabled)
       
   516 {
       
   517     iHighlightEnabled = aEnabled;
       
   518 
       
   519     // Prepare the frame
       
   520     if (aEnabled && !iFocusFrame)
       
   521     {
       
   522         TRAP_IGNORE(const_cast<ASwtControlBase*>(this)->CreateFocusBackgroundL());
       
   523     }
       
   524 
       
   525     HandleHighlightChange();
       
   526 }
       
   527 
       
   528 EXPORT_C void ASwtControlBase::HandleHighlightChange()
       
   529 {
       
   530     // Do nothing here. Inherit where needed.
       
   531 }
       
   532 
       
   533 EXPORT_C void ASwtControlBase::PrepareForTraverse()
       
   534 {
       
   535     // Do nothing here. Inherit where needed.
   533 }
   536 }
   534 
   537 
   535 TRect ASwtControlBase::ClipToVisibleRect(const TRect& aRect) const
   538 TRect ASwtControlBase::ClipToVisibleRect(const TRect& aRect) const
   536 {
   539 {
   537     // WINDOW COORDINATES!
   540     // WINDOW COORDINATES!
   753 
   756 
   754     // Post the focus event
   757     // Post the focus event
   755     TSwtEventType type((focused) ? ESwtEventFocusIn : ESwtEventFocusOut);
   758     TSwtEventType type((focused) ? ESwtEventFocusIn : ESwtEventFocusOut);
   756     TRAP_IGNORE(iDisplay.PostFocusEventL(JavaPeer(), type));
   759     TRAP_IGNORE(iDisplay.PostFocusEventL(JavaPeer(), type));
   757 
   760 
   758     if (!(iCtrlFlags & MSwtControl::EFlagDoNotDraw))
       
   759     {
       
   760         Redraw();
       
   761     }
       
   762 
       
   763     if (focused)
   761     if (focused)
   764     {
   762     {
   765         // Add to ControlStack since the control becomes focused
   763         // Add to ControlStack since the control becomes focused
   766         TRAP_IGNORE(AddToControlStackL(ECoeStackPriorityDefault));
   764         TRAP_IGNORE(AddToControlStackL(ECoeStackPriorityDefault));
   767     }
   765     }
       
   766 
       
   767     shell.UpdateHighlight();
   768 }
   768 }
   769 
   769 
   770 TKeyResponse ASwtControlBase::OfferKeyEventToCommandAndMenuArrangersL(
   770 TKeyResponse ASwtControlBase::OfferKeyEventToCommandAndMenuArrangersL(
   771     const TKeyEvent& aKeyEvent,
   771     const TKeyEvent& aKeyEvent,
   772     TEventCode aType)
   772     TEventCode aType)
   859     case EKeyRightDownArrow:
   859     case EKeyRightDownArrow:
   860         return HandleDiagonalKeysL(aKeyEvent, aType, aTraversalDoIt, EKeyRightArrow,
   860         return HandleDiagonalKeysL(aKeyEvent, aType, aTraversalDoIt, EKeyRightArrow,
   861                                    EStdKeyRightArrow, EKeyDownArrow, EStdKeyDownArrow);
   861                                    EStdKeyRightArrow, EKeyDownArrow, EStdKeyDownArrow);
   862     }
   862     }
   863 
   863 
   864     if (aKeyEvent.iScanCode == EStdKeyDownArrow
       
   865             || aKeyEvent.iScanCode == EStdKeyUpArrow
       
   866             || aKeyEvent.iScanCode == EStdKeyRightArrow
       
   867             || aKeyEvent.iScanCode == EStdKeyLeftArrow)
       
   868     {
       
   869         iDisplay.UiUtils().SetNaviKeyInput(ETrue);
       
   870     }
       
   871 
       
   872     // Offer key event to command arranger first
   864     // Offer key event to command arranger first
   873     TKeyResponse keyResponse = OfferKeyEventToCommandAndMenuArrangersL(aKeyEvent, aType);
   865     TKeyResponse keyResponse = OfferKeyEventToCommandAndMenuArrangersL(aKeyEvent, aType);
   874     if (keyResponse == EKeyWasConsumed)
   866     if (keyResponse == EKeyWasConsumed)
   875     {
   867     {
   876         iTraverse = EFalse;
   868         iTraverse = EFalse;
  1090             return background;
  1082             return background;
  1091         }
  1083         }
  1092     }
  1084     }
  1093 
  1085 
  1094     MSwtComposite* parent = GetParent();
  1086     MSwtComposite* parent = GetParent();
       
  1087     TInt policy = FocusBackgroundPolicy();
  1095     if (IsDefaultBackgroundUse())
  1088     if (IsDefaultBackgroundUse())
  1096     {
  1089     {
  1097         background = aBeginSearchToThis ? GetControlContext() : NULL;
  1090         background = aBeginSearchToThis ? GetControlContext() : NULL;
  1098         while (!background && parent)
  1091         while (!background && parent)
  1099         {
  1092         {
       
  1093             // If policy is ENoFocusBackgroundInCaptionedControl, bypass the caption highlight.
       
  1094             if (policy == ENoFocusBackgroundInCaptionedControl
       
  1095                     && parent->Control()->CaptionedControlInterface())
       
  1096             {
       
  1097                 parent = parent->Control()->GetParent();
       
  1098                 ASSERT(parent);
       
  1099             }
       
  1100 
  1100             background = parent->Control()->GetControlContext();
  1101             background = parent->Control()->GetControlContext();
  1101 
  1102 
  1102             // If the parent is a Shell we stop on it.
  1103             // If the parent is a Shell we stop on it.
  1103             if (parent->Control()->IsShell())
  1104             if (parent->Control()->IsShell())
  1104             {
  1105             {
  1347         iFont = NULL;
  1348         iFont = NULL;
  1348     }
  1349     }
  1349 
  1350 
  1350     Invalidate(CoeControl().Rect());
  1351     Invalidate(CoeControl().Rect());
  1351 
  1352 
  1352     if (GetShell().ControlGoingToStack() == this)
       
  1353     {
       
  1354         GetShell().SetControlGoingToStack(NULL);
       
  1355     }
       
  1356     if (GetShell().ControlGainingFocus() == this)
       
  1357     {
       
  1358         GetShell().SetControlGainingFocus(NULL);
       
  1359     }
       
  1360     if (UiUtils().PointerCaptureControl() == this)
  1353     if (UiUtils().PointerCaptureControl() == this)
  1361     {
  1354     {
  1362         UiUtils().SetPointerCaptureControl(NULL);
  1355         UiUtils().SetPointerCaptureControl(NULL);
  1363     }
  1356     }
  1364     if (UiUtils().NextFocusedControl() == this)
  1357     if (UiUtils().NextFocusedControl() == this)
  1369     {
  1362     {
  1370         iDisplay.CancelLongTapAnimation();
  1363         iDisplay.CancelLongTapAnimation();
  1371     }
  1364     }
  1372 
  1365 
  1373     RemoveFromControlStack();
  1366     RemoveFromControlStack();
       
  1367 
       
  1368     GetShell().ControlDisposing(*this);
  1374 
  1369 
  1375     TSwtPeer peer(iPeer);
  1370     TSwtPeer peer(iPeer);
  1376     DoDelete();
  1371     DoDelete();
  1377     return peer;
  1372     return peer;
  1378 }
  1373 }
  1735 EXPORT_C TInt ASwtControlBase::FocusBackgroundPolicy() const
  1730 EXPORT_C TInt ASwtControlBase::FocusBackgroundPolicy() const
  1736 {
  1731 {
  1737     return EDefaultFocusBackground;
  1732     return EDefaultFocusBackground;
  1738 };
  1733 };
  1739 
  1734 
       
  1735 EXPORT_C TInt ASwtControlBase::PressBackgroundPolicy() const
       
  1736 {
       
  1737     return ENoPressBackground;
       
  1738 };
       
  1739 
  1740 EXPORT_C TBool ASwtControlBase::GetEnabled() const
  1740 EXPORT_C TBool ASwtControlBase::GetEnabled() const
  1741 {
  1741 {
  1742     return (CoeControl().IsDimmed()) ? EFalse : ETrue;
  1742     return (CoeControl().IsDimmed()) ? EFalse : ETrue;
  1743 }
  1743 }
  1744 
  1744 
  1761     return iBackgrdDefaultUsed;
  1761     return iBackgrdDefaultUsed;
  1762 }
  1762 }
  1763 
  1763 
  1764 EXPORT_C MAknsControlContext* ASwtControlBase::GetControlContext() const
  1764 EXPORT_C MAknsControlContext* ASwtControlBase::GetControlContext() const
  1765 {
  1765 {
  1766     // A focus highlight without parent context is no good since the highlight
  1766     if (CaptionedControlInterface())
  1767     // graphic may be semi transparent, so return CaptionedControl's highlight
       
  1768     // only if no back color has been set.
       
  1769     if (CaptionedControlInterface() && IsDefaultBackgroundUse())
       
  1770     {
  1767     {
  1771         return FocusBackgroundNow();
  1768         return FocusBackgroundNow();
  1772     }
  1769     }
  1773     else
  1770     else
  1774     {
  1771     {
  1888     MSwtShell* shell = const_cast<MSwtShell*>(ctrl->ShellInterface());
  1885     MSwtShell* shell = const_cast<MSwtShell*>(ctrl->ShellInterface());
  1889     ASSERT(shell);
  1886     ASSERT(shell);
  1890     return *shell;
  1887     return *shell;
  1891 }
  1888 }
  1892 
  1889 
  1893 EXPORT_C MSwtCaptionedControl* ASwtControlBase::GetTopCaptionedControl() const
  1890 EXPORT_C MSwtCaptionedControl* ASwtControlBase::GetNearestCaptionedControl(TBool aIncludeSelf /*= ETrue*/) const
  1894 {
  1891 {
  1895     MSwtCaptionedControl* res = NULL;
  1892     MSwtCaptionedControl* res = NULL;
  1896     const MSwtControl* ctrl = this;
  1893     const MSwtControl* ctrl = aIncludeSelf ? this : (GetParent() ? GetParent()->Control() : NULL);
  1897     while (ctrl)
  1894     while (ctrl)
  1898     {
  1895     {
  1899         if (ctrl->CaptionedControlInterface())
  1896         if (ctrl->CaptionedControlInterface())
  1900         {
  1897         {
  1901             res = ctrl->CaptionedControlInterface();
  1898             return ctrl->CaptionedControlInterface();
  1902         }
  1899         }
  1903         ctrl = ctrl->GetParent() ? ctrl->GetParent()->Control() : NULL;
  1900         ctrl = ctrl->GetParent() ? ctrl->GetParent()->Control() : NULL;
  1904     }
  1901     }
  1905     return res;
  1902     return res;
  1906 }
  1903 }