LCOV - code coverage report
Current view: top level - svx/source/sidebar/tools - Popup.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 12 53 22.6 %
Date: 2014-11-03 Functions: 5 12 41.7 %
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             : #include "svx/sidebar/Popup.hxx"
      20             : #include "svx/sidebar/PopupContainer.hxx"
      21             : #include "svx/sidebar/PopupControl.hxx"
      22             : 
      23             : #include <vcl/toolbox.hxx>
      24             : 
      25             : 
      26             : namespace svx { namespace sidebar {
      27             : 
      28        6658 : Popup::Popup (
      29             :     vcl::Window* pParent,
      30             :     const ::boost::function<PopupControl*(PopupContainer*)>& rControlCreator,
      31             :     const ::rtl::OUString& rsAccessibleName)
      32             :     : mpControl(),
      33             :       mpParent(pParent),
      34             :       maControlCreator(rControlCreator),
      35             :       maPopupModeEndCallback(),
      36             :       msAccessibleName(rsAccessibleName),
      37        6658 :       mpContainer()
      38             : {
      39             :     OSL_ASSERT(mpParent!=NULL);
      40             :     OSL_ASSERT(maControlCreator);
      41        6658 : }
      42             : 
      43             : 
      44             : 
      45             : 
      46       13316 : Popup::~Popup (void)
      47             : {
      48        6658 :     mpControl.reset();
      49        6658 :     mpContainer.reset();
      50        6658 : }
      51             : 
      52             : 
      53             : 
      54             : 
      55           0 : void Popup::Show (ToolBox& rToolBox)
      56             : {
      57           0 :     rToolBox.SetItemDown(rToolBox.GetCurItemId(), true);
      58             : 
      59           0 :     ProvideContainerAndControl();
      60           0 :     if ( ! (mpContainer && mpControl))
      61             :     {
      62             :         OSL_ASSERT(mpContainer);
      63             :         OSL_ASSERT(mpControl);
      64           0 :         return;
      65             :     }
      66             : 
      67           0 :     if ( !mpContainer->IsInPopupMode() )
      68             :     {
      69           0 :         mpContainer->SetSizePixel(mpControl->GetOutputSizePixel());
      70             : 
      71           0 :         const Point aPos (rToolBox.GetParent()->OutputToScreenPixel(rToolBox.GetPosPixel()));
      72           0 :         const Size aSize (rToolBox.GetSizePixel());
      73           0 :         const Rectangle aRect (aPos, aSize);
      74             : 
      75           0 :         mpContainer->StartPopupMode(
      76             :             aRect,
      77           0 :             FLOATWIN_POPUPMODE_NOFOCUSCLOSE|FLOATWIN_POPUPMODE_DOWN);
      78           0 :         mpContainer->SetPopupModeFlags(
      79           0 :             mpContainer->GetPopupModeFlags()
      80           0 :                 | FLOATWIN_POPUPMODE_NOAPPFOCUSCLOSE);
      81             : 
      82           0 :         mpControl->GetFocus();
      83             :     }
      84             : }
      85             : 
      86             : 
      87             : 
      88             : 
      89           0 : void Popup::Hide (void)
      90             : {
      91           0 :     if (mpContainer)
      92           0 :         if (mpContainer->IsInPopupMode())
      93           0 :             mpContainer->EndPopupMode();
      94           0 : }
      95             : 
      96             : 
      97             : 
      98             : 
      99        1476 : void Popup::SetPopupModeEndHandler (const ::boost::function<void(void)>& rCallback)
     100             : {
     101        1476 :     maPopupModeEndCallback = rCallback;
     102        1476 :     if (mpContainer)
     103           0 :         mpContainer->SetPopupModeEndHdl(LINK(this, Popup, PopupModeEndHandler));
     104        1476 : }
     105             : 
     106             : 
     107             : 
     108             : 
     109           0 : void Popup::ProvideContainerAndControl (void)
     110             : {
     111           0 :     if ( ! (mpContainer && mpControl)
     112           0 :         && mpParent!=NULL
     113           0 :         && maControlCreator)
     114             :     {
     115           0 :         CreateContainerAndControl();
     116             :     }
     117           0 : }
     118             : 
     119             : 
     120             : 
     121             : 
     122           0 : void Popup::CreateContainerAndControl (void)
     123             : {
     124           0 :     mpContainer.reset(new PopupContainer(mpParent));
     125           0 :     mpContainer->SetAccessibleName(msAccessibleName);
     126           0 :     mpContainer->SetPopupModeEndHdl(LINK(this, Popup, PopupModeEndHandler));
     127           0 :     mpContainer->SetBorderStyle(mpContainer->GetBorderStyle() | WindowBorderStyle::MENU);
     128             : 
     129           0 :     mpControl.reset(maControlCreator(mpContainer.get()));
     130           0 : }
     131             : 
     132             : 
     133             : 
     134             : 
     135           0 : IMPL_LINK(Popup, PopupModeEndHandler, void*, EMPTYARG)
     136             : {
     137           0 :     if (maPopupModeEndCallback)
     138           0 :         maPopupModeEndCallback();
     139             : 
     140             :     // Popup control is no longer needed and can be destroyed.
     141           0 :     mpControl.reset();
     142           0 :     mpContainer.reset();
     143             : 
     144           0 :     return 0;
     145             : }
     146             : 
     147             : 
     148             : 
     149         594 : } } // end of namespace svx::sidebar
     150             : 
     151             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10