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

Generated by: LCOV version 1.10