javauis/eswt_akn/org.eclipse.ercp.swt.s60/native/src/swtshell.cpp
branchRCL_3
changeset 60 6c158198356e
parent 46 4376525cdefb
equal deleted inserted replaced
59:e5618cc85d74 60:6c158198356e
   341     iFullTabList.Close();
   341     iFullTabList.Close();
   342     delete iTitleText;
   342     delete iTitleText;
   343     iTitleText = NULL;
   343     iTitleText = NULL;
   344 
   344 
   345     iFocusControl = NULL;
   345     iFocusControl = NULL;
       
   346     iPrevFocusControl = NULL;
   346     iFocusMemory = NULL;
   347     iFocusMemory = NULL;
   347     iDefaultCommand = NULL;
   348     iDefaultCommand = NULL;
   348     iControlGoingToStack= NULL;
   349     iControlGoingToStack= NULL;
   349     iControlGainingFocus= NULL;
   350     iControlGainingFocus= NULL;
   350     iTitleText = NULL;
   351     iTitleText = NULL;
  1564             // So remove the DefaultButton status on it.
  1565             // So remove the DefaultButton status on it.
  1565             SetFocusedDefaultButton(NULL);
  1566             SetFocusedDefaultButton(NULL);
  1566         }
  1567         }
  1567     }
  1568     }
  1568 
  1569 
  1569     iFocusControl = aControl;
  1570     DoSetFocusControl(aControl);
  1570 }
  1571 }
  1571 
  1572 
  1572 // ---------------------------------------------------------------------------
  1573 // ---------------------------------------------------------------------------
  1573 // CSwtShell::HasModalChild
  1574 // CSwtShell::HasModalChild
  1574 // From MSwtShell
  1575 // From MSwtShell
  1599 
  1600 
  1600         // Set the top level Shell title in the task list.
  1601         // Set the top level Shell title in the task list.
  1601         const TDesC* titleText = GetText();
  1602         const TDesC* titleText = GetText();
  1602 
  1603 
  1603         // Find a focus control
  1604         // Find a focus control
       
  1605         MSwtControl* newFocusControl = NULL;
       
  1606 
  1604         if (aSetFocus)
  1607         if (aSetFocus)
  1605         {
  1608         {
  1606             if (!iFocusMemory)
  1609             if (!iFocusMemory)
  1607             {
  1610             {
  1608                 // First focusable one in the tab list
  1611                 // First focusable one in the tab list
  1614                     for (TInt i=0; i<count; ++i)
  1617                     for (TInt i=0; i<count; ++i)
  1615                     {
  1618                     {
  1616                         MSwtControl* ctrl = (*tabList)[i];
  1619                         MSwtControl* ctrl = (*tabList)[i];
  1617                         if (ctrl->IsFocusable())
  1620                         if (ctrl->IsFocusable())
  1618                         {
  1621                         {
  1619                             iFocusControl = ctrl;
  1622                             newFocusControl = ctrl;
  1620                             break;
  1623                             break;
  1621                         }
  1624                         }
  1622                     }
  1625                     }
  1623                 }
  1626                 }
  1624             }
  1627             }
  1625             else if (!iFocusMemory->IsFocusable())
  1628             else if (!iFocusMemory->IsFocusable())
  1626             {
  1629             {
  1627                 iFocusControl = NULL;
  1630                 TRAP_IGNORE((newFocusControl = FindTraversalTargetL(
  1628                 TRAP_IGNORE((iFocusControl = FindTraversalTargetL(
  1631                                                    ESwtTraverseTabPrevious, *iFocusMemory)));
  1629                                                  ESwtTraverseTabPrevious, *iFocusMemory)));
       
  1630             }
  1632             }
  1631             else
  1633             else
  1632             {
  1634             {
  1633                 iFocusControl = iFocusMemory;
  1635                 newFocusControl = iFocusMemory;
  1634             }
  1636             }
  1635         }
  1637         }
  1636 
  1638 
  1637         iFocusMemory = NULL;
  1639         iFocusMemory = NULL;
  1638 
  1640 
  1639         TRAP_IGNORE(iDisplay.PostShellEventL(iPeer, ESwtEventActivate));
  1641         TRAP_IGNORE(iDisplay.PostShellEventL(iPeer, ESwtEventActivate));
  1640 
  1642 
  1641         if (iFocusControl)
  1643         if (newFocusControl)
  1642         {
  1644         {
  1643             // Give focus to the focus control
  1645             // Give focus to the focus control
  1644             ASSERT(!iFocusControl->IsShell());
  1646             ASSERT(!newFocusControl->IsShell());
  1645             CCoeControl& coeFocusCtrl = iFocusControl->CoeControl();
  1647             CCoeControl& coeFocusCtrl = newFocusControl->CoeControl();
  1646             if (!coeFocusCtrl.IsFocused())
  1648             if (!coeFocusCtrl.IsFocused())
  1647             {
  1649             {
  1648                 iFocusControl = NULL;
       
  1649                 // This will set iFocusControl to the correct value
  1650                 // This will set iFocusControl to the correct value
  1650                 coeFocusCtrl.SetFocus(ETrue);
  1651                 coeFocusCtrl.SetFocus(ETrue);
  1651                 ASSERT(&iFocusControl->CoeControl() == &coeFocusCtrl);
  1652                 ASSERT(&iFocusControl->CoeControl() == &coeFocusCtrl);
  1652             }
  1653             }
  1653             ASSERT(coeFocusCtrl.IsFocused());
  1654             ASSERT(coeFocusCtrl.IsFocused());
  1844 {
  1845 {
  1845     iControlGoingToStack = aControl;
  1846     iControlGoingToStack = aControl;
  1846 }
  1847 }
  1847 
  1848 
  1848 // ---------------------------------------------------------------------------
  1849 // ---------------------------------------------------------------------------
  1849 // CSwtShell::ControlGoingToStack
       
  1850 // From MSwtShell
       
  1851 // ---------------------------------------------------------------------------
       
  1852 //
       
  1853 MSwtControl* CSwtShell::ControlGoingToStack() const
       
  1854 {
       
  1855     return iControlGoingToStack;
       
  1856 }
       
  1857 
       
  1858 // ---------------------------------------------------------------------------
       
  1859 // CSwtShell::SetControlGainingFocus
  1850 // CSwtShell::SetControlGainingFocus
  1860 // From MSwtShell
  1851 // From MSwtShell
  1861 // ---------------------------------------------------------------------------
  1852 // ---------------------------------------------------------------------------
  1862 //
  1853 //
  1863 void CSwtShell::SetControlGainingFocus(MSwtControl* aControl)
  1854 void CSwtShell::SetControlGainingFocus(MSwtControl* aControl)
  1864 {
  1855 {
  1865     iControlGainingFocus = aControl;
  1856     iControlGainingFocus = aControl;
  1866 }
       
  1867 
       
  1868 // ---------------------------------------------------------------------------
       
  1869 // CSwtShell::ControlGainingFocus
       
  1870 // From MSwtShell
       
  1871 // ---------------------------------------------------------------------------
       
  1872 //
       
  1873 MSwtControl* CSwtShell::ControlGainingFocus() const
       
  1874 {
       
  1875     return iControlGainingFocus;
       
  1876 }
  1857 }
  1877 
  1858 
  1878 // ---------------------------------------------------------------------------
  1859 // ---------------------------------------------------------------------------
  1879 // CSwtUiUtils::DefaultBounds
  1860 // CSwtUiUtils::DefaultBounds
  1880 // From MSwtShell
  1861 // From MSwtShell
  1963 {
  1944 {
  1964     ASSERT(!iFocusControl || !iFocusControl->CoeControl().IsFocused());
  1945     ASSERT(!iFocusControl || !iFocusControl->CoeControl().IsFocused());
  1965 
  1946 
  1966     if (iFocusControl)
  1947     if (iFocusControl)
  1967     {
  1948     {
  1968         iFocusControl = NULL;
  1949         DoSetFocusControl(NULL);
  1969     }
  1950     }
  1970 
  1951 
  1971     iFocusMemory = aControl;
  1952     iFocusMemory = aControl;
  1972 }
  1953 }
  1973 
  1954 
  2146     {
  2127     {
  2147         Redraw();
  2128         Redraw();
  2148     }
  2129     }
  2149 }
  2130 }
  2150 
  2131 
  2151 
       
  2152 // ---------------------------------------------------------------------------
  2132 // ---------------------------------------------------------------------------
  2153 // CSwtShell::HandleStatusPaneSizeChange
  2133 // CSwtShell::HandleStatusPaneSizeChange
  2154 // From MEikStatusPaneObserver
  2134 // From MEikStatusPaneObserver
  2155 // ---------------------------------------------------------------------------
  2135 // ---------------------------------------------------------------------------
  2156 //
  2136 //
  2166 {
  2146 {
  2167 #ifdef RD_JAVA_S60_RELEASE_9_2
  2147 #ifdef RD_JAVA_S60_RELEASE_9_2
  2168     iDisplay.CoeEnv()->WsSession().Finish();
  2148     iDisplay.CoeEnv()->WsSession().Finish();
  2169 #endif
  2149 #endif
  2170 }
  2150 }
       
  2151 
       
  2152 // ---------------------------------------------------------------------------
       
  2153 // CSwtShell::UpdateHighlight
       
  2154 // ---------------------------------------------------------------------------
       
  2155 //
       
  2156 void CSwtShell::UpdateHighlight(TBool aDrawNow /*= EFalse*/)
       
  2157 {
       
  2158     // Turn off highlight for the previously focused control and its eventual
       
  2159     // nearest captioned control parent.
       
  2160     if (iPrevFocusControl)
       
  2161     {
       
  2162         MSwtCaptionedControl* captParent = iPrevFocusControl->GetNearestCaptionedControl(EFalse);
       
  2163         MSwtControl* captParentCtrl = NULL;
       
  2164         if (captParent)
       
  2165         {
       
  2166             MSwtComposite* captParentComp = captParent->Composite();
       
  2167             if (captParentComp)
       
  2168             {
       
  2169                 captParentCtrl = captParentComp->Control();
       
  2170                 DoSetHighlight(*captParentCtrl, EFalse);
       
  2171             }
       
  2172         }
       
  2173 
       
  2174         DoSetHighlight(*iPrevFocusControl, EFalse);
       
  2175 
       
  2176         if (aDrawNow)
       
  2177         {
       
  2178             if (captParentCtrl)
       
  2179                 captParentCtrl->Redraw();
       
  2180             else
       
  2181                 iPrevFocusControl->Redraw();
       
  2182         }
       
  2183         else
       
  2184         {
       
  2185             if (captParentCtrl)
       
  2186                 captParentCtrl->CoeControl().DrawDeferred();
       
  2187             else
       
  2188                 iPrevFocusControl->CoeControl().DrawDeferred();
       
  2189         }
       
  2190 
       
  2191         iPrevFocusControl = NULL;
       
  2192     }
       
  2193 
       
  2194     // Turn on highlight for the current focused control and its eventual
       
  2195     // nearest captioned control parent.
       
  2196     if (iFocusControl)
       
  2197     {
       
  2198         TBool ctrlHighlight = EFalse;
       
  2199         TBool captHighlight = EFalse;
       
  2200 
       
  2201         if (iFocusControl->Pressed())
       
  2202         {
       
  2203             // Always represent pressed state with highlight
       
  2204             TInt pressPolicy = iFocusControl->PressBackgroundPolicy();
       
  2205             ctrlHighlight = pressPolicy == EPressBackground;
       
  2206             captHighlight = pressPolicy == EPressBackground
       
  2207                             || pressPolicy == EEmbeddedPressBackground;
       
  2208         }
       
  2209         else
       
  2210         {
       
  2211             if (iDisplay.UiUtils().NaviKeyInput())
       
  2212             {
       
  2213                 TBool noOtherFocusableCtrls(CountFocusableChildren(1, iFocusControl) == 0);
       
  2214                 if (noOtherFocusableCtrls)
       
  2215                 {
       
  2216                     // No highlight if there's only one focusable control
       
  2217                     ctrlHighlight = EFalse;
       
  2218                     captHighlight = EFalse;
       
  2219                 }
       
  2220                 else
       
  2221                 {
       
  2222                     captHighlight = ETrue;
       
  2223                     ctrlHighlight = ETrue;
       
  2224 
       
  2225                     TInt policy = iFocusControl->FocusBackgroundPolicy();
       
  2226                     if ((policy == ENoFocusBackground)
       
  2227                             || (policy == EEmbeddedFocusBackground)
       
  2228                             || (policy ==ENoFocusBackgroundInCaptionedControl))
       
  2229                     {
       
  2230                         ctrlHighlight = EFalse;
       
  2231                     }
       
  2232                 }
       
  2233             }
       
  2234             else
       
  2235             {
       
  2236                 // No focus highlight with touch input
       
  2237                 ctrlHighlight = EFalse;
       
  2238                 captHighlight = EFalse;
       
  2239             }
       
  2240         }
       
  2241 
       
  2242         TBool directlyCaptioned(EFalse);
       
  2243         MSwtCaptionedControl* captParent = iFocusControl->GetNearestCaptionedControl(EFalse);
       
  2244         MSwtControl* captParentCtrl = NULL;
       
  2245         if (captParent)
       
  2246         {
       
  2247             MSwtComposite* captParentComp = captParent->Composite();
       
  2248             if (captParentComp)
       
  2249             {
       
  2250                 directlyCaptioned = iFocusControl->GetParent() == captParentComp;
       
  2251                 // When pressing, only the direct caption control gets "pressed" also.
       
  2252                 if (!directlyCaptioned && iFocusControl->Pressed())
       
  2253                     captHighlight = EFalse;
       
  2254                 captParentCtrl = captParentComp->Control();
       
  2255                 DoSetHighlight(*captParentCtrl, captHighlight);
       
  2256             }
       
  2257         }
       
  2258 
       
  2259         if (!directlyCaptioned)
       
  2260         {
       
  2261             DoSetHighlight(*iFocusControl, ctrlHighlight);
       
  2262         }
       
  2263 
       
  2264         if (aDrawNow)
       
  2265         {
       
  2266             if (captParentCtrl)
       
  2267                 captParentCtrl->Redraw();
       
  2268             else
       
  2269                 iFocusControl->Redraw();
       
  2270         }
       
  2271         else
       
  2272         {
       
  2273             if (captParentCtrl)
       
  2274                 captParentCtrl->CoeControl().DrawDeferred();
       
  2275             else
       
  2276                 iFocusControl->CoeControl().DrawDeferred();
       
  2277         }
       
  2278     }
       
  2279 }
       
  2280 
       
  2281 void CSwtShell::DoSetFocusControl(MSwtControl* aControl)
       
  2282 {
       
  2283     iPrevFocusControl = iFocusControl;
       
  2284 
       
  2285     // This must always be the only place to assign to iFocusControl!
       
  2286     iFocusControl = aControl;
       
  2287 }
       
  2288 
       
  2289 void CSwtShell::DoSetHighlight(MSwtControl& aControl, TBool aEnabled)
       
  2290 {
       
  2291     if (aControl.HasHighlight(EFalse) != aEnabled) // not checking parents
       
  2292     {
       
  2293         aControl.SetHighlight(aEnabled);
       
  2294     }
       
  2295 }
       
  2296 
       
  2297 void CSwtShell::ControlDisposing(const MSwtControl& aControl)
       
  2298 {
       
  2299     const MSwtControl* control = &aControl;
       
  2300 
       
  2301     if (control == iPrevFocusControl)
       
  2302         iPrevFocusControl = NULL;
       
  2303 
       
  2304     if (control == iControlGoingToStack)
       
  2305         iControlGoingToStack = NULL;
       
  2306 
       
  2307     if (control == iControlGainingFocus)
       
  2308         iControlGainingFocus = NULL;
       
  2309 
       
  2310     if (control== iFocusControl)
       
  2311         iFocusControl = NULL;
       
  2312 
       
  2313     if (control == iFocusMemory)
       
  2314         iFocusMemory = NULL;
       
  2315 
       
  2316     if (control == iUrgentPaintControl)
       
  2317         iUrgentPaintControl = NULL;
       
  2318 }