LCOV - code coverage report
Current view: top level - svx/source/sidebar/tools - Popup.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 11 57 19.3 %
Date: 2015-06-13 12:38:46 Functions: 3 11 27.3 %
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        2328 : Popup::Popup (
      29             :     vcl::Window* pParent,
      30             :     const ::boost::function<PopupControl*(PopupContainer*)>& rControlCreator,
      31             :     const ::rtl::OUString& rsAccessibleName)
      32             :     : mxControl(),
      33             :       mpParent(pParent),
      34             :       maControlCreator(rControlCreator),
      35             :       maPopupModeEndCallback(),
      36             :       msAccessibleName(rsAccessibleName),
      37        2328 :       mxContainer()
      38             : {
      39             :     OSL_ASSERT(mpParent!=nullptr);
      40             :     OSL_ASSERT(maControlCreator);
      41        2328 : }
      42             : 
      43           1 : void Popup::dispose()
      44             : {
      45           1 :     mxControl.disposeAndClear();
      46           1 :     mxContainer.disposeAndClear();
      47           1 : }
      48             : 
      49           0 : Popup::~Popup()
      50             : {
      51           0 :     dispose();
      52           0 : }
      53             : 
      54           0 : void Popup::Show (ToolBox& rToolBox)
      55             : {
      56           0 :     rToolBox.SetItemDown(rToolBox.GetCurItemId(), true);
      57             : 
      58           0 :     ProvideContainerAndControl();
      59           0 :     if ( ! (mxContainer && mxControl))
      60             :     {
      61             :         OSL_ASSERT(mxContainer);
      62             :         OSL_ASSERT(mxControl);
      63           0 :         return;
      64             :     }
      65             : 
      66           0 :     if ( !mxContainer->IsInPopupMode() )
      67             :     {
      68           0 :         mxContainer->SetSizePixel(mxControl->GetOutputSizePixel());
      69             : 
      70           0 :         const Point aPos (rToolBox.GetParent()->OutputToScreenPixel(rToolBox.GetPosPixel()));
      71           0 :         const Size aSize (rToolBox.GetSizePixel());
      72           0 :         const Rectangle aRect (aPos, aSize);
      73             : 
      74           0 :         mxContainer->StartPopupMode(
      75             :             aRect,
      76           0 :             FloatWinPopupFlags::NoFocusClose|FloatWinPopupFlags::Down);
      77           0 :         mxContainer->SetPopupModeFlags(
      78           0 :             mxContainer->GetPopupModeFlags()
      79           0 :                 | FloatWinPopupFlags::NoAppFocusClose);
      80             : 
      81           0 :         mxControl->GetFocus();
      82             :     }
      83             : }
      84             : 
      85           0 : void Popup::Hide()
      86             : {
      87           0 :     if (mxContainer)
      88           0 :         if (mxContainer->IsInPopupMode())
      89           0 :             mxContainer->EndPopupMode();
      90           0 : }
      91             : 
      92         490 : void Popup::SetPopupModeEndHandler (const ::boost::function<void()>& rCallback)
      93             : {
      94         490 :     maPopupModeEndCallback = rCallback;
      95         490 :     if (mxContainer)
      96           0 :         mxContainer->SetPopupModeEndHdl(LINK(this, Popup, PopupModeEndHandler));
      97         490 : }
      98             : 
      99           0 : void Popup::ProvideContainerAndControl()
     100             : {
     101           0 :     if ( ! (mxContainer && mxControl)
     102           0 :          && mpParent != nullptr
     103           0 :          && maControlCreator)
     104             :     {
     105           0 :         CreateContainerAndControl();
     106             :     }
     107           0 : }
     108             : 
     109           0 : void Popup::CreateContainerAndControl()
     110             : {
     111             :     // Clean previous components, if any
     112           0 :     mxControl.disposeAndClear();
     113           0 :     mxContainer.disposeAndClear();
     114             : 
     115           0 :     mxContainer.set(VclPtr<PopupContainer>::Create(mpParent));
     116           0 :     mxContainer->SetAccessibleName(msAccessibleName);
     117           0 :     mxContainer->SetPopupModeEndHdl(LINK(this, Popup, PopupModeEndHandler));
     118           0 :     mxContainer->SetBorderStyle(mxContainer->GetBorderStyle() | WindowBorderStyle::MENU);
     119             : 
     120           0 :     mxControl.set(maControlCreator(mxContainer.get()));
     121           0 : }
     122             : 
     123           0 : IMPL_LINK_NOARG(Popup, PopupModeEndHandler)
     124             : {
     125           0 :     if (maPopupModeEndCallback)
     126           0 :         maPopupModeEndCallback();
     127             : 
     128             :     // Popup control is no longer needed and can be destroyed.
     129           0 :     mxControl.disposeAndClear();
     130           0 :     mxContainer.disposeAndClear();
     131             : 
     132           0 :     return 0;
     133             : }
     134             : 
     135             : 
     136             : 
     137             : } } // end of namespace svx::sidebar
     138             : 
     139             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11