LCOV - code coverage report
Current view: top level - sd/source/ui/slidesorter/controller - SlsFocusManager.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 122 0.0 %
Date: 2014-04-14 Functions: 0 20 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "controller/SlsFocusManager.hxx"
      21             : 
      22             : #include "SlideSorter.hxx"
      23             : #include "PaneDockingWindow.hxx"
      24             : #include "controller/SlideSorterController.hxx"
      25             : #include "controller/SlsCurrentSlideManager.hxx"
      26             : #include "controller/SlsVisibleAreaManager.hxx"
      27             : #include "model/SlideSorterModel.hxx"
      28             : #include "model/SlsPageDescriptor.hxx"
      29             : #include "view/SlideSorterView.hxx"
      30             : #include "view/SlsLayouter.hxx"
      31             : #include <vcl/toolbox.hxx>
      32             : 
      33             : #include "Window.hxx"
      34             : #include "sdpage.hxx"
      35             : 
      36             : namespace sd { namespace slidesorter { namespace controller {
      37             : 
      38           0 : FocusManager::FocusManager (SlideSorter& rSlideSorter)
      39             :     : mrSlideSorter(rSlideSorter),
      40             :       mnPageIndex(0),
      41             :       mbPageIsFocused(false),
      42           0 :       mbIsVerticalWrapActive(false)
      43             : {
      44           0 :     if (mrSlideSorter.GetModel().GetPageCount() > 0)
      45           0 :         mnPageIndex = 0;
      46           0 : }
      47             : 
      48             : 
      49             : 
      50             : 
      51           0 : FocusManager::~FocusManager (void)
      52             : {
      53           0 : }
      54             : 
      55             : 
      56             : 
      57             : 
      58           0 : void FocusManager::MoveFocus (FocusMoveDirection eDirection)
      59             : {
      60           0 :     if (mnPageIndex >= 0 && mbPageIsFocused)
      61             :     {
      62           0 :         HideFocusIndicator (GetFocusedPageDescriptor());
      63             : 
      64           0 :         const sal_Int32 nColumnCount (mrSlideSorter.GetView().GetLayouter().GetColumnCount());
      65           0 :         const sal_Int32 nPageCount (mrSlideSorter.GetModel().GetPageCount());
      66           0 :         switch (eDirection)
      67             :         {
      68             :             case FMD_NONE:
      69             :                 // Nothing to be done.
      70           0 :                 break;
      71             : 
      72             :             case FMD_LEFT:
      73           0 :                 if (mnPageIndex > 0)
      74           0 :                     mnPageIndex -= 1;
      75           0 :                 else if (mbIsVerticalWrapActive)
      76           0 :                     mnPageIndex = nPageCount-1;
      77           0 :                 break;
      78             : 
      79             :             case FMD_RIGHT:
      80           0 :                 if (mnPageIndex < nPageCount-1)
      81           0 :                     mnPageIndex += 1;
      82           0 :                 else if (mbIsVerticalWrapActive)
      83           0 :                     mnPageIndex = 0;
      84           0 :                 break;
      85             : 
      86             :             case FMD_UP:
      87             :             {
      88           0 :                 const sal_Int32 nCandidate (mnPageIndex - nColumnCount);
      89           0 :                 if (nCandidate < 0)
      90             :                 {
      91           0 :                     if (mbIsVerticalWrapActive)
      92             :                     {
      93             :                         // Wrap arround to the bottom row or the one above
      94             :                         // and go to the correct column.
      95           0 :                         const sal_Int32 nLastIndex (nPageCount-1);
      96           0 :                         const sal_Int32 nLastColumn (nLastIndex % nColumnCount);
      97           0 :                         const sal_Int32 nCurrentColumn (mnPageIndex%nColumnCount);
      98           0 :                         if (nLastColumn >= nCurrentColumn)
      99             :                         {
     100             :                             // The last row contains the current column.
     101           0 :                             mnPageIndex = nLastIndex - (nLastColumn-nCurrentColumn);
     102             :                         }
     103             :                         else
     104             :                         {
     105             :                             // Only the second to last row contains the current column.
     106           0 :                             mnPageIndex = nLastIndex - nLastColumn
     107           0 :                                 - nColumnCount
     108           0 :                                 + nCurrentColumn;
     109             :                         }
     110             :                     }
     111             :                 }
     112             :                 else
     113             :                 {
     114             :                     // Move the focus the previous row.
     115           0 :                     mnPageIndex = nCandidate;
     116             :                 }
     117             :             }
     118           0 :             break;
     119             : 
     120             :             case FMD_DOWN:
     121             :             {
     122           0 :                 const sal_Int32 nCandidate (mnPageIndex + nColumnCount);
     123           0 :                 if (nCandidate >= nPageCount)
     124             :                 {
     125           0 :                     if (mbIsVerticalWrapActive)
     126             :                     {
     127             :                         // Wrap arround to the correct column.
     128           0 :                         mnPageIndex = mnPageIndex % nColumnCount;
     129             :                     }
     130             :                     else
     131             :                     {
     132             :                         // Do not move the focus.
     133             :                     }
     134             :                 }
     135             :                 else
     136             :                 {
     137             :                     // Move the focus to the next row.
     138           0 :                     mnPageIndex = nCandidate;
     139             :                 }
     140             :             }
     141           0 :             break;
     142             :         }
     143             : 
     144           0 :         if (mnPageIndex < 0)
     145             :         {
     146             :             OSL_ASSERT(mnPageIndex>=0);
     147           0 :             mnPageIndex = 0;
     148             :         }
     149           0 :         else if (mnPageIndex >= nPageCount)
     150             :         {
     151             :             OSL_ASSERT(mnPageIndex<nPageCount);
     152           0 :             mnPageIndex = nPageCount - 1;
     153             :         }
     154             : 
     155           0 :         if (mbPageIsFocused)
     156             :         {
     157           0 :             ShowFocusIndicator(GetFocusedPageDescriptor(), true);
     158             :         }
     159             :     }
     160           0 : }
     161             : 
     162             : 
     163             : 
     164             : 
     165           0 : void FocusManager::ShowFocus (const bool bScrollToFocus)
     166             : {
     167           0 :     mbPageIsFocused = true;
     168           0 :     ShowFocusIndicator(GetFocusedPageDescriptor(), bScrollToFocus);
     169           0 : }
     170             : 
     171             : 
     172             : 
     173             : 
     174           0 : void FocusManager::HideFocus (void)
     175             : {
     176           0 :     mbPageIsFocused = false;
     177           0 :     HideFocusIndicator(GetFocusedPageDescriptor());
     178           0 : }
     179             : 
     180             : 
     181             : 
     182             : 
     183           0 : bool FocusManager::ToggleFocus (void)
     184             : {
     185           0 :     if (mnPageIndex >= 0)
     186             :     {
     187           0 :         if (mbPageIsFocused)
     188           0 :             HideFocus ();
     189             :         else
     190           0 :             ShowFocus ();
     191             :     }
     192           0 :     return mbPageIsFocused;
     193             : }
     194             : 
     195             : 
     196             : 
     197             : 
     198           0 : bool FocusManager::HasFocus (void) const
     199             : {
     200           0 :     return mrSlideSorter.GetContentWindow()->HasFocus();
     201             : }
     202             : 
     203             : 
     204             : 
     205             : 
     206           0 : model::SharedPageDescriptor FocusManager::GetFocusedPageDescriptor (void) const
     207             : {
     208           0 :     return mrSlideSorter.GetModel().GetPageDescriptor(mnPageIndex);
     209             : }
     210             : 
     211             : 
     212             : 
     213             : 
     214           0 : sal_Int32 FocusManager::GetFocusedPageIndex (void) const
     215             : {
     216           0 :     return mnPageIndex;
     217             : }
     218             : 
     219             : 
     220           0 : void FocusManager::SetFocusedPage (const model::SharedPageDescriptor& rpDescriptor)
     221             : {
     222           0 :     if (rpDescriptor.get() != NULL)
     223             :     {
     224           0 :         FocusHider aFocusHider (*this);
     225           0 :         mnPageIndex = (rpDescriptor->GetPage()->GetPageNum()-1)/2;
     226             :     }
     227           0 : }
     228             : 
     229             : 
     230             : 
     231             : 
     232           0 : void FocusManager::SetFocusedPage (sal_Int32 nPageIndex)
     233             : {
     234           0 :     FocusHider aFocusHider (*this);
     235           0 :     mnPageIndex = nPageIndex;
     236           0 : }
     237             : 
     238             : 
     239             : 
     240             : 
     241           0 : void FocusManager::SetFocusedPageToCurrentPage (void)
     242             : {
     243           0 :     SetFocusedPage(mrSlideSorter.GetController().GetCurrentSlideManager()->GetCurrentSlide());
     244           0 : }
     245             : 
     246             : 
     247             : 
     248             : 
     249           0 : bool FocusManager::IsFocusShowing (void) const
     250             : {
     251           0 :     return HasFocus() && mbPageIsFocused;
     252             : }
     253             : 
     254             : 
     255             : 
     256             : 
     257           0 : void FocusManager::HideFocusIndicator (const model::SharedPageDescriptor& rpDescriptor)
     258             : {
     259           0 :     if (rpDescriptor.get() != NULL)
     260             :     {
     261           0 :         mrSlideSorter.GetView().SetState(rpDescriptor, model::PageDescriptor::ST_Focused, false);
     262             : 
     263             :         // Hide focus should also fire the focus event, Currently, only accessibility add the focus listener
     264           0 :         NotifyFocusChangeListeners();
     265             :     }
     266           0 : }
     267             : 
     268             : 
     269             : 
     270             : 
     271           0 : void FocusManager::ShowFocusIndicator (
     272             :     const model::SharedPageDescriptor& rpDescriptor,
     273             :     const bool bScrollToFocus)
     274             : {
     275           0 :     if (rpDescriptor.get() != NULL)
     276             :     {
     277           0 :         mrSlideSorter.GetView().SetState(rpDescriptor, model::PageDescriptor::ST_Focused, true);
     278             : 
     279           0 :         if (bScrollToFocus)
     280             :         {
     281             :             // Scroll the focused page object into the visible area and repaint
     282             :             // it, so that the focus indicator becomes visible.
     283           0 :             mrSlideSorter.GetController().GetVisibleAreaManager().RequestVisible(rpDescriptor,true);
     284             :         }
     285           0 :         mrSlideSorter.GetView().RequestRepaint(rpDescriptor);
     286             : 
     287           0 :         NotifyFocusChangeListeners();
     288             :     }
     289           0 : }
     290             : 
     291             : 
     292             : 
     293             : 
     294           0 : void FocusManager::AddFocusChangeListener (const Link& rListener)
     295             : {
     296           0 :     if (::std::find (maFocusChangeListeners.begin(), maFocusChangeListeners.end(), rListener)
     297           0 :         == maFocusChangeListeners.end())
     298             :     {
     299           0 :         maFocusChangeListeners.push_back (rListener);
     300             :     }
     301           0 : }
     302             : 
     303             : 
     304             : 
     305             : 
     306           0 : void FocusManager::RemoveFocusChangeListener (const Link& rListener)
     307             : {
     308             :     maFocusChangeListeners.erase (
     309           0 :         ::std::find (maFocusChangeListeners.begin(), maFocusChangeListeners.end(), rListener));
     310           0 : }
     311             : 
     312           0 : void FocusManager::NotifyFocusChangeListeners (void) const
     313             : {
     314             :     // Create a copy of the listener list to be safe when that is modified.
     315           0 :     ::std::vector<Link> aListeners (maFocusChangeListeners);
     316             : 
     317             :     // Tell the slection change listeners that the selection has changed.
     318           0 :     ::std::vector<Link>::iterator iListener (aListeners.begin());
     319           0 :     ::std::vector<Link>::iterator iEnd (aListeners.end());
     320           0 :     for (; iListener!=iEnd; ++iListener)
     321             :     {
     322           0 :         iListener->Call(NULL);
     323           0 :     }
     324           0 : }
     325             : 
     326             : 
     327             : 
     328             : 
     329           0 : FocusManager::FocusHider::FocusHider (FocusManager& rManager)
     330           0 : : mbFocusVisible(rManager.IsFocusShowing())
     331           0 : , mrManager(rManager)
     332             : {
     333           0 :     mrManager.HideFocus();
     334           0 : }
     335             : 
     336             : 
     337             : 
     338             : 
     339           0 : FocusManager::FocusHider::~FocusHider (void)
     340             : {
     341           0 :     if (mbFocusVisible)
     342           0 :         mrManager.ShowFocus();
     343           0 : }
     344             : 
     345             : } } } // end of namespace ::sd::slidesorter::controller
     346             : 
     347             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10