LCOV - code coverage report
Current view: top level - vcl/source/control - menubtn.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 31 89 34.8 %
Date: 2014-11-03 Functions: 9 17 52.9 %
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 <tools/rc.h>
      21             : #include <vcl/decoview.hxx>
      22             : #include <vcl/event.hxx>
      23             : #include <vcl/menu.hxx>
      24             : #include <vcl/timer.hxx>
      25             : #include <vcl/menubtn.hxx>
      26             : #include <vcl/svapp.hxx>
      27             : #include <vcl/settings.hxx>
      28             : 
      29        1404 : void MenuButton::ImplInitMenuButtonData()
      30             : {
      31        1404 :     mnDDStyle       = PUSHBUTTON_DROPDOWN_MENUBUTTON;
      32             : 
      33        1404 :     mpMenuTimer     = NULL;
      34        1404 :     mpMenu          = NULL;
      35        1404 :     mpOwnMenu       = NULL;
      36        1404 :     mnCurItemId     = 0;
      37        1404 :     mnMenuMode      = 0;
      38        1404 : }
      39             : 
      40        1404 : void MenuButton::ImplInit( vcl::Window* pParent, WinBits nStyle )
      41             : {
      42        1404 :     if ( !(nStyle & WB_NOTABSTOP) )
      43        1404 :         nStyle |= WB_TABSTOP;
      44             : 
      45        1404 :     PushButton::ImplInit( pParent, nStyle );
      46        1404 :     EnableRTL( Application::GetSettings().GetLayoutRTL() );
      47        1404 : }
      48             : 
      49           0 : void MenuButton::ExecuteMenu()
      50             : {
      51           0 :     Activate();
      52             : 
      53           0 :     if ( mpMenu )
      54             :     {
      55           0 :         Point aPos( 0, 1 );
      56           0 :         Size aSize = GetSizePixel();
      57           0 :         Rectangle aRect( aPos, aSize );
      58           0 :         SetPressed( true );
      59           0 :         EndSelection();
      60           0 :         mnCurItemId = mpMenu->Execute( this, aRect, POPUPMENU_EXECUTE_DOWN );
      61           0 :         SetPressed( false );
      62           0 :         if ( mnCurItemId )
      63             :         {
      64           0 :             Select();
      65           0 :             mnCurItemId = 0;
      66             :         }
      67             :     }
      68           0 : }
      69             : 
      70           0 : OString MenuButton::GetCurItemIdent() const
      71             : {
      72           0 :     return (mnCurItemId && mpMenu) ?
      73           0 :         mpMenu->GetItemIdent(mnCurItemId) : OString();
      74             : }
      75             : 
      76        1404 : MenuButton::MenuButton( vcl::Window* pParent, WinBits nWinBits )
      77        1404 :     : PushButton( WINDOW_MENUBUTTON )
      78             : {
      79        1404 :     ImplInitMenuButtonData();
      80        1404 :     ImplInit( pParent, nWinBits );
      81        1404 : }
      82             : 
      83        3654 : MenuButton::~MenuButton()
      84             : {
      85        1404 :     delete mpMenuTimer;
      86        1404 :     delete mpOwnMenu;
      87        2250 : }
      88             : 
      89           0 : IMPL_LINK_NOARG(MenuButton, ImplMenuTimeoutHdl)
      90             : {
      91             :     // See if Button Tracking is still active, as it could've been cancelled earler
      92           0 :     if ( IsTracking() )
      93             :     {
      94           0 :         if ( !(GetStyle() & WB_NOPOINTERFOCUS) )
      95           0 :             GrabFocus();
      96           0 :         ExecuteMenu();
      97             :     }
      98             : 
      99           0 :     return 0;
     100             : }
     101             : 
     102           0 : void MenuButton::MouseButtonDown( const MouseEvent& rMEvt )
     103             : {
     104           0 :     bool bExecute = true;
     105           0 :     if ( mnMenuMode & MENUBUTTON_MENUMODE_TIMED )
     106             :     {
     107             :         // If the separated dropdown symbol is not hit, delay the popup execution
     108           0 :         if( mnDDStyle != PUSHBUTTON_DROPDOWN_MENUBUTTON || // no separator at all
     109           0 :             rMEvt.GetPosPixel().X() <= ImplGetSeparatorX() )
     110             :         {
     111           0 :             if ( !mpMenuTimer )
     112             :             {
     113           0 :                 mpMenuTimer = new Timer;
     114           0 :                 mpMenuTimer->SetTimeoutHdl( LINK( this, MenuButton, ImplMenuTimeoutHdl ) );
     115             :             }
     116             : 
     117           0 :             mpMenuTimer->SetTimeout( GetSettings().GetMouseSettings().GetActionDelay() );
     118           0 :             mpMenuTimer->Start();
     119             : 
     120           0 :             PushButton::MouseButtonDown( rMEvt );
     121           0 :             bExecute = false;
     122             :         }
     123             :     }
     124           0 :     if( bExecute )
     125             :     {
     126           0 :         if ( PushButton::ImplHitTestPushButton( this, rMEvt.GetPosPixel() ) )
     127             :         {
     128           0 :             if ( !(GetStyle() & WB_NOPOINTERFOCUS) )
     129           0 :                 GrabFocus();
     130           0 :             ExecuteMenu();
     131             :         }
     132             :     }
     133           0 : }
     134             : 
     135           0 : void MenuButton::KeyInput( const KeyEvent& rKEvt )
     136             : {
     137           0 :     vcl::KeyCode aKeyCode = rKEvt.GetKeyCode();
     138           0 :     sal_uInt16 nCode = aKeyCode.GetCode();
     139           0 :     if ( (nCode == KEY_DOWN) && aKeyCode.IsMod2() )
     140           0 :         ExecuteMenu();
     141           0 :     else if ( !(mnMenuMode & MENUBUTTON_MENUMODE_TIMED) &&
     142           0 :               !aKeyCode.GetModifier() &&
     143           0 :               ((nCode == KEY_RETURN) || (nCode == KEY_SPACE)) )
     144           0 :         ExecuteMenu();
     145             :     else
     146           0 :         PushButton::KeyInput( rKEvt );
     147           0 : }
     148             : 
     149           0 : void MenuButton::Activate()
     150             : {
     151           0 :     maActivateHdl.Call( this );
     152           0 : }
     153             : 
     154           0 : void MenuButton::Select()
     155             : {
     156           0 :     maSelectHdl.Call( this );
     157           0 : }
     158             : 
     159           2 : void MenuButton::SetMenuMode( sal_uInt16 nMode )
     160             : {
     161             :     // FIXME: It's better to not inline this for 5.1; in 6.0 we can make it inline, however
     162           2 :     mnMenuMode = nMode;
     163           2 : }
     164             : 
     165        1404 : void MenuButton::SetPopupMenu( PopupMenu* pNewMenu )
     166             : {
     167        1404 :     if (pNewMenu == mpMenu)
     168        1404 :         return;
     169             : 
     170        1404 :     mpMenu = pNewMenu;
     171        1233 : }
     172             : 
     173             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10