LCOV - code coverage report
Current view: top level - vcl/source/control - menubtn.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 106 0.0 %
Date: 2014-04-14 Functions: 0 17 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 <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           0 : void MenuButton::ImplInitMenuButtonData()
      30             : {
      31           0 :     mnDDStyle       = PUSHBUTTON_DROPDOWN_MENUBUTTON;
      32             : 
      33           0 :     mpMenuTimer     = NULL;
      34           0 :     mpMenu          = NULL;
      35           0 :     mpOwnMenu       = NULL;
      36           0 :     mnCurItemId     = 0;
      37           0 :     mnMenuMode      = 0;
      38           0 : }
      39             : 
      40           0 : void MenuButton::ImplInit( Window* pParent, WinBits nStyle )
      41             : {
      42           0 :     if ( !(nStyle & WB_NOTABSTOP) )
      43           0 :         nStyle |= WB_TABSTOP;
      44             : 
      45           0 :     PushButton::ImplInit( pParent, nStyle );
      46           0 :     EnableRTL( Application::GetSettings().GetLayoutRTL() );
      47           0 : }
      48             : 
      49           0 : void MenuButton::ImplExecuteMenu()
      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           0 : MenuButton::MenuButton( Window* pParent, WinBits nWinBits )
      77           0 :     : PushButton( WINDOW_MENUBUTTON )
      78             : {
      79           0 :     ImplInitMenuButtonData();
      80           0 :     ImplInit( pParent, nWinBits );
      81           0 : }
      82             : 
      83           0 : MenuButton::MenuButton( Window* pParent, const ResId& rResId )
      84           0 :     : PushButton( WINDOW_MENUBUTTON )
      85             : {
      86           0 :     ImplInitMenuButtonData();
      87           0 :     rResId.SetRT( RSC_MENUBUTTON );
      88           0 :     WinBits nStyle = ImplInitRes( rResId );
      89           0 :     ImplInit( pParent, nStyle );
      90           0 :     ImplLoadRes( rResId );
      91             : 
      92           0 :     if ( !(nStyle & WB_HIDE) )
      93           0 :         Show();
      94           0 : }
      95             : 
      96           0 : void MenuButton::ImplLoadRes( const ResId& rResId )
      97             : {
      98           0 :     Control::ImplLoadRes( rResId );
      99             : 
     100           0 :     sal_uLong nObjMask = ReadLongRes();
     101             : 
     102           0 :     if ( RSCMENUBUTTON_MENU & nObjMask )
     103             :     {
     104           0 :         mpOwnMenu = new PopupMenu( ResId( (RSHEADER_TYPE*)GetClassRes(), *rResId.GetResMgr() ) );
     105           0 :         SetPopupMenu( mpOwnMenu );
     106           0 :         IncrementRes( GetObjSizeRes( (RSHEADER_TYPE*)GetClassRes() ) );
     107             :     }
     108           0 : }
     109             : 
     110           0 : MenuButton::~MenuButton()
     111             : {
     112           0 :     delete mpMenuTimer;
     113           0 :     delete mpOwnMenu;
     114           0 : }
     115             : 
     116           0 : IMPL_LINK_NOARG(MenuButton, ImplMenuTimeoutHdl)
     117             : {
     118             :     // See if Button Tracking is still active, as it could've been cancelled earler
     119           0 :     if ( IsTracking() )
     120             :     {
     121           0 :         if ( !(GetStyle() & WB_NOPOINTERFOCUS) )
     122           0 :             GrabFocus();
     123           0 :         ImplExecuteMenu();
     124             :     }
     125             : 
     126           0 :     return 0;
     127             : }
     128             : 
     129           0 : void MenuButton::MouseButtonDown( const MouseEvent& rMEvt )
     130             : {
     131           0 :     bool bExecute = true;
     132           0 :     if ( mnMenuMode & MENUBUTTON_MENUMODE_TIMED )
     133             :     {
     134             :         // If the separated dropdown symbol is not hit, delay the popup execution
     135           0 :         if( mnDDStyle != PUSHBUTTON_DROPDOWN_MENUBUTTON || // no separator at all
     136           0 :             rMEvt.GetPosPixel().X() <= ImplGetSeparatorX() )
     137             :         {
     138           0 :             if ( !mpMenuTimer )
     139             :             {
     140           0 :                 mpMenuTimer = new Timer;
     141           0 :                 mpMenuTimer->SetTimeoutHdl( LINK( this, MenuButton, ImplMenuTimeoutHdl ) );
     142             :             }
     143             : 
     144           0 :             mpMenuTimer->SetTimeout( GetSettings().GetMouseSettings().GetActionDelay() );
     145           0 :             mpMenuTimer->Start();
     146             : 
     147           0 :             PushButton::MouseButtonDown( rMEvt );
     148           0 :             bExecute = false;
     149             :         }
     150             :     }
     151           0 :     if( bExecute )
     152             :     {
     153           0 :         if ( PushButton::ImplHitTestPushButton( this, rMEvt.GetPosPixel() ) )
     154             :         {
     155           0 :             if ( !(GetStyle() & WB_NOPOINTERFOCUS) )
     156           0 :                 GrabFocus();
     157           0 :             ImplExecuteMenu();
     158             :         }
     159             :     }
     160           0 : }
     161             : 
     162           0 : void MenuButton::KeyInput( const KeyEvent& rKEvt )
     163             : {
     164           0 :     KeyCode aKeyCode = rKEvt.GetKeyCode();
     165           0 :     sal_uInt16 nCode = aKeyCode.GetCode();
     166           0 :     if ( (nCode == KEY_DOWN) && aKeyCode.IsMod2() )
     167           0 :         ImplExecuteMenu();
     168           0 :     else if ( !(mnMenuMode & MENUBUTTON_MENUMODE_TIMED) &&
     169           0 :               !aKeyCode.GetModifier() &&
     170           0 :               ((nCode == KEY_RETURN) || (nCode == KEY_SPACE)) )
     171           0 :         ImplExecuteMenu();
     172             :     else
     173           0 :         PushButton::KeyInput( rKEvt );
     174           0 : }
     175             : 
     176           0 : void MenuButton::Activate()
     177             : {
     178           0 :     maActivateHdl.Call( this );
     179           0 : }
     180             : 
     181           0 : void MenuButton::Select()
     182             : {
     183           0 :     maSelectHdl.Call( this );
     184           0 : }
     185             : 
     186           0 : void MenuButton::SetMenuMode( sal_uInt16 nMode )
     187             : {
     188             :     // FIXME: It's better to not inline this for 5.1; in 6.0 we can make it inline, however
     189           0 :     mnMenuMode = nMode;
     190           0 : }
     191             : 
     192           0 : void MenuButton::SetPopupMenu( PopupMenu* pNewMenu )
     193             : {
     194           0 :     if (pNewMenu == mpMenu)
     195           0 :         return;
     196             : 
     197           0 :     mpMenu = pNewMenu;
     198             : }
     199             : 
     200             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10